alby-hub/db/sqlite-wrapper/driver.go
Roland 66a1be6d16
Fix: sqlite connection parameters, add migrations to delete orphaned records and change postgres transaction amount to bigint (#1462)
* fix: sqlite pragma statement not applying to all sqlite connections

* fix: add migration to delete orphaned records

* fix: migrate postgres transaction amount column to bigint

* chore: simplify migration, update comment

* fix: sqlite uri when running tests

* fix: check that breaks tests

* fix: db locking within transaction

* fix: sqlite3 driver wrapper to execute PRAGMAs on each new connection (#1464)

* fix: sqlite3 driver wrapper to execute PRAGMAs on each new connection

* chore: add test to check temp_store value

---------

Co-authored-by: Roland Bewick <roland.bewick@gmail.com>

---------

Co-authored-by: Roman D <roman@dmitrienko.com>
2025-07-06 17:45:46 +07:00

22 lines
633 B
Go

package sqlite_wrapper
import (
"database/sql"
"github.com/mattn/go-sqlite3"
)
const Sqlite3WrapperDriverName = "sqlite3_wrapper"
func init() {
// We need to set the temp_store setting on every connection, including
// those that are implicitly opened by Go's database/sql package.
// Unfortunately, this setting cannot be provided in the DSN; therefore
// we execute the PRAGMA statement in the sqlite3's connection hook.
sql.Register(Sqlite3WrapperDriverName, &sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
_, err := conn.Exec("PRAGMA temp_store = MEMORY", nil)
return err
},
})
}