mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add sqlite3-fk-wal mode matching litestream without disabling checkpointing
This commit is contained in:
parent
0a5167dfe5
commit
29609b87cf
2 changed files with 22 additions and 1 deletions
|
|
@ -40,7 +40,7 @@ func ParseDialect(engine string) (Dialect, error) {
|
|||
switch strings.ToLower(engine) {
|
||||
case "postgres", "postgresql":
|
||||
return Postgres, nil
|
||||
case "sqlite3", "sqlite", "litestream":
|
||||
case "sqlite3", "sqlite", "litestream", "sqlite3-fk-wal":
|
||||
return SQLite, nil
|
||||
default:
|
||||
return DialectUnknown, fmt.Errorf("unknown dialect '%s'", engine)
|
||||
|
|
|
|||
|
|
@ -31,4 +31,25 @@ func init() {
|
|||
return
|
||||
},
|
||||
})
|
||||
|
||||
sql.Register("sqlite3-fk-wal", &sqlite3.SQLiteDriver{
|
||||
ConnectHook: func(conn *sqlite3.SQLiteConn) (err error) {
|
||||
if err = conn.SetFileControlInt("main", sqlite3.SQLITE_FCNTL_PERSIST_WAL, 1); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = conn.Exec("PRAGMA foreign_keys = ON", []driver.Value{}); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = conn.Exec("PRAGMA journal_mode = WAL", []driver.Value{}); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = conn.Exec("PRAGMA synchronous = NORMAL", []driver.Value{}); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = conn.Exec("PRAGMA busy_timeout = 5000", []driver.Value{}); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue