fix(db): stabilize connection settings and explicitly define AppConfig table name

- Set SQL connection idle limit to 1 to reduce resource usage
- Explicitly define AppConfig table name to prevent GORM pluralization issues
This commit is contained in:
NeilClack
2026-06-26 22:49:51 -05:00
parent f03d56d7ad
commit 6fd5ec919c
3 changed files with 17 additions and 0 deletions
+1
View File
@@ -80,6 +80,7 @@ func Connect(dbpath string) (*gorm.DB, error) {
return nil, fmt.Errorf("could not get underlying sql.DB: %w", err) return nil, fmt.Errorf("could not get underlying sql.DB: %w", err)
} }
sqlDB.SetMaxOpenConns(1) sqlDB.SetMaxOpenConns(1)
sqlDB.SetMaxIdleConns(1)
// ── Pragmas ─────────────────────────────────────────────────────────── // ── Pragmas ───────────────────────────────────────────────────────────
pragmas := []string{ pragmas := []string{
+5
View File
@@ -19,6 +19,11 @@ type AppConfig struct {
FirstRun bool // Is this the first time the application has been run? FirstRun bool // Is this the first time the application has been run?
} }
// Explicit table name to avoid pluralization issues
func (AppConfig) TableName() string {
return "app_configs" // Use your ACTUAL table name (check with: sqlite3 database.sqlite ".tables")
}
type Log struct { type Log struct {
gorm.Model gorm.Model
Timestamp int64 Timestamp int64
+11
View File
@@ -0,0 +1,11 @@
package db
import "gorm.io/gorm"
func GetConfig(db *gorm.DB) (*AppConfig, error) {
var appConfig AppConfig
if err := db.First(&appConfig).Error; err != nil {
return nil, err
}
return &appConfig, nil
}