fix: check PRAGMA errors instead of silently ignoring

This commit is contained in:
2026-06-16 00:34:33 +02:00
committed by Milas Holsting
parent 0a483ad2a2
commit aa9375eff2

View File

@@ -18,7 +18,11 @@ func Open(dbFile string) (*sql.DB, error) {
return nil, fmt.Errorf("failed to open db: %w", err)
}
// WAL improves concurrency between readers and writers.
_, _ = db.ExecContext(context.Background(), "PRAGMA journal_mode=WAL;")
_, _ = db.ExecContext(context.Background(), "PRAGMA busy_timeout=5000;")
if _, err := db.ExecContext(context.Background(), "PRAGMA journal_mode=WAL;"); err != nil {
return nil, fmt.Errorf("failed to enable WAL mode: %w", err)
}
if _, err := db.ExecContext(context.Background(), "PRAGMA busy_timeout=5000;"); err != nil {
return nil, fmt.Errorf("failed to set busy timeout: %w", err)
}
return db, nil
}