From b1307c90410d6205fe87e33a9c3cbbc153e0de63 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sat, 27 May 2023 09:24:18 +0300 Subject: [PATCH] registered custom cgo sqlite driver --- core/db_cgo.go | 6 ++++-- tests/app.go | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/db_cgo.go b/core/db_cgo.go index c4e6303d..7c4f7abc 100644 --- a/core/db_cgo.go +++ b/core/db_cgo.go @@ -19,7 +19,7 @@ func init() { // Note 2: the busy_timeout pragma must be first because // the connection needs to be set to block on busy before WAL mode // is set in case it hasn't been already set by another connection. - sql.Register("sqlite3_with_connect_hook", + sql.Register("pb_sqlite3", &sqlite3.SQLiteDriver{ ConnectHook: func(conn *sqlite3.SQLiteConn) error { _, err := conn.Exec(` @@ -34,10 +34,12 @@ func init() { }, }, ) + + dbx.BuilderFuncMap["pb_sqlite3"] = dbx.BuilderFuncMap["sqlite3"] } func connectDB(dbPath string) (*dbx.DB, error) { - db, err := dbx.Open("sqlite3_with_connect_hook", dbPath) + db, err := dbx.Open("pb_sqlite3", dbPath) if err != nil { return nil, err } diff --git a/tests/app.go b/tests/app.go index 62fe61f1..39f9d945 100644 --- a/tests/app.go +++ b/tests/app.go @@ -105,6 +105,14 @@ func NewTestApp(optTestDataDir ...string) (*TestApp, error) { return nil, err } + // ensure that the Dao and DB configurations are properly loaded + if _, err := app.Dao().DB().NewQuery("Select 1").Execute(); err != nil { + return nil, err + } + if _, err := app.LogsDao().DB().NewQuery("Select 1").Execute(); err != nil { + return nil, err + } + // force disable request logs because the logs db call execute in a separate // go routine and it is possible to panic due to earlier api test completion. app.Settings().Logs.MaxDays = 0