mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
744 B
Go
33 lines
744 B
Go
//go:build !memos_sqlcipher
|
|
|
|
package sqlite
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/usememos/memos/internal/profile"
|
|
|
|
// Import the pure-Go SQLite driver.
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
func openSQLiteDB(profile *profile.Profile) (*sql.DB, error) {
|
|
if profile.SQLiteEncryptionKey != "" {
|
|
return nil, errors.New("sqlite encryption key provided but binary is not built with SQLCipher support; rebuild with -tags memos_sqlcipher")
|
|
}
|
|
|
|
sqliteDB, err := sql.Open(sqliteModernDriver, profile.DSN)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "failed to open db with dsn: %s", profile.DSN)
|
|
}
|
|
|
|
if err := configureSQLiteConnection(sqliteDB); err != nil {
|
|
sqliteDB.Close()
|
|
return nil, err
|
|
}
|
|
|
|
return sqliteDB, nil
|
|
}
|