fix(db): enable WAL mode, busy_timeout and single conn to avoid SQLITE_BUSY

This commit is contained in:
2026-07-07 00:58:02 -04:00
parent 24425b8b39
commit 047f0f5c09
2 changed files with 10 additions and 1 deletions
+9
View File
@@ -25,10 +25,19 @@ func Open(path string) (*DB, error) {
if err != nil {
return nil, fmt.Errorf("open sqlite: %w", err)
}
if _, err := conn.Exec(`PRAGMA journal_mode = WAL`); err != nil {
_ = conn.Close()
return nil, fmt.Errorf("set journal_mode: %w", err)
}
if _, err := conn.Exec(`PRAGMA busy_timeout = 5000`); err != nil {
_ = conn.Close()
return nil, fmt.Errorf("set busy_timeout: %w", err)
}
if _, err := conn.Exec(`PRAGMA foreign_keys = ON`); err != nil {
_ = conn.Close()
return nil, fmt.Errorf("enable foreign keys: %w", err)
}
conn.SetMaxOpenConns(1)
return &DB{conn: conn}, nil
}