Add sqlite3-fk-wal mode matching litestream without disabling checkpointing

This commit is contained in:
Tulir Asokan 2022-11-08 10:50:47 +02:00
commit 29609b87cf
2 changed files with 22 additions and 1 deletions

View file

@ -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)

View file

@ -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
},
})
}