db: Configure sqlite connection when open. Currently set synchronous to FULL

(did this work a long time ago now so commits are in weird order)
This commit is contained in:
IRHM
2026-06-27 23:33:54 +01:00
committed by momi
parent b8598ba404
commit 3eb2810a31
+22
View File
@@ -26,6 +26,8 @@ func New() (*gorm.DB, error) {
slog.Error("New: Opening database failed.")
return nil, err
}
if err := configure(db); err != nil {
slog.Error("New: Configuring connection failed!", "error", err)
return nil, err
}
// Perform auto migration.
@@ -60,3 +62,23 @@ func New() (*gorm.DB, error) {
}
return db, nil
}
// Configure our SQLite database connection.
// Some PRAGMAs need to be defined per-connection, so we do that here.
func configure(db *gorm.DB) error {
slog.Info("configure: Configuring connection.")
// Synchronous: https://sqlite.org/pragma.html#pragma_synchronous
// Configured to `FULL` because I'm slightly confused.
// `NORMAL` is recommended for most apps with WAL, but you
// lose "durability", which doesn't sound like a good thing to me...
// personally I'm okay with less performance for the best durability.
if res := db.Exec("PRAGMA synchronous=2"); res.Error != nil {
slog.Error("configure: Configuring synchronous failed!")
return res.Error
}
slog.Info("configure: Configured synchronous.")
return nil
}