2019-04-25 04:52:08 +07:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"github.com/clems4ever/authelia/logging"
|
|
|
|
_ "github.com/mattn/go-sqlite3" // Load the SQLite Driver used in the connection string.
|
|
|
|
)
|
|
|
|
|
2019-11-16 17:38:21 +07:00
|
|
|
// SQLiteProvider is a sqlite3 provider
|
2019-04-25 04:52:08 +07:00
|
|
|
type SQLiteProvider struct {
|
2019-11-16 17:38:21 +07:00
|
|
|
SQLProvider
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSQLiteProvider construct a sqlite provider.
|
|
|
|
func NewSQLiteProvider(path string) *SQLiteProvider {
|
|
|
|
db, err := sql.Open("sqlite3", path)
|
|
|
|
if err != nil {
|
2019-11-16 17:38:21 +07:00
|
|
|
logging.Logger().Fatalf("Unable to create SQLite database %s: %s", path, err)
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
2019-11-16 17:38:21 +07:00
|
|
|
provider := SQLiteProvider{}
|
|
|
|
if err := provider.initialize(db); err != nil {
|
|
|
|
logging.Logger().Fatalf("Unable to initialize SQLite database %s: %s", path, err)
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
2019-11-16 17:38:21 +07:00
|
|
|
return &provider
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|