2019-04-24 21:52:08 +00: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 10:38:21 +00:00
|
|
|
// SQLiteProvider is a sqlite3 provider
|
2019-04-24 21:52:08 +00:00
|
|
|
type SQLiteProvider struct {
|
2019-11-16 10:38:21 +00:00
|
|
|
SQLProvider
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSQLiteProvider construct a sqlite provider.
|
|
|
|
func NewSQLiteProvider(path string) *SQLiteProvider {
|
|
|
|
db, err := sql.Open("sqlite3", path)
|
|
|
|
if err != nil {
|
2019-11-16 10:38:21 +00:00
|
|
|
logging.Logger().Fatalf("Unable to create SQLite database %s: %s", path, err)
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
2019-11-16 10:38:21 +00:00
|
|
|
provider := SQLiteProvider{}
|
|
|
|
if err := provider.initialize(db); err != nil {
|
|
|
|
logging.Logger().Fatalf("Unable to initialize SQLite database %s: %s", path, err)
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
2019-11-16 10:38:21 +00:00
|
|
|
return &provider
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|