From 6fd5ec919c788de14c8bb4061c92c98e2639f284 Mon Sep 17 00:00:00 2001 From: NeilClack Date: Fri, 26 Jun 2026 22:49:51 -0500 Subject: [PATCH] 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 --- internal/db/DB.go | 1 + internal/db/Schema.go | 5 +++++ internal/db/queries.go | 11 +++++++++++ 3 files changed, 17 insertions(+) create mode 100644 internal/db/queries.go diff --git a/internal/db/DB.go b/internal/db/DB.go index e290f79..658820a 100644 --- a/internal/db/DB.go +++ b/internal/db/DB.go @@ -80,6 +80,7 @@ func Connect(dbpath string) (*gorm.DB, error) { return nil, fmt.Errorf("could not get underlying sql.DB: %w", err) } sqlDB.SetMaxOpenConns(1) + sqlDB.SetMaxIdleConns(1) // ── Pragmas ─────────────────────────────────────────────────────────── pragmas := []string{ diff --git a/internal/db/Schema.go b/internal/db/Schema.go index 0d7f6bb..22b349d 100644 --- a/internal/db/Schema.go +++ b/internal/db/Schema.go @@ -19,6 +19,11 @@ type AppConfig struct { 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 { gorm.Model Timestamp int64 diff --git a/internal/db/queries.go b/internal/db/queries.go new file mode 100644 index 0000000..1654dbd --- /dev/null +++ b/internal/db/queries.go @@ -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 +}