mirror of
https://github.com/go-shiori/shiori.git
synced 2025-10-08 20:55:58 +08:00
25 lines
597 B
Go
25 lines
597 B
Go
//go:build linux || windows || darwin || freebsd
|
|
// +build linux windows darwin freebsd
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/pkg/errors"
|
|
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
// OpenSQLiteDatabase creates and open connection to new SQLite3 database.
|
|
func OpenSQLiteDatabase(ctx context.Context, databasePath string) (sqliteDB *SQLiteDatabase, err error) {
|
|
// Open database
|
|
db, err := sqlx.ConnectContext(ctx, "sqlite", databasePath)
|
|
if err != nil {
|
|
return nil, errors.WithStack(err)
|
|
}
|
|
|
|
sqliteDB = &SQLiteDatabase{dbbase: dbbase{db}}
|
|
return sqliteDB, nil
|
|
}
|