Fix :memory: database connection pool issue (bd-b121)

- Add db.SetMaxOpenConns(1) for :memory: databases
- SQLite shared cache mode requires single connection
- Fixes 'no such table' errors in VC and other consumers
- See bd-b121 for full details

Amp-Thread-ID: https://ampcode.com/threads/T-bbbb8f17-5ac0-4125-9035-e5488d3ebab1
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-04 00:59:22 -08:00
parent 636d15e4c0
commit b1aec38b46
2 changed files with 11 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -48,6 +48,13 @@ func New(path string) (*SQLiteStorage, error) {
return nil, fmt.Errorf("failed to open database: %w", err)
}
// For :memory: databases, force single connection to ensure cache sharing works properly.
// SQLite's shared cache mode for in-memory databases only works reliably with one connection.
// Without this, different connections in the pool can't see each other's writes (bd-b121).
if path == ":memory:" {
db.SetMaxOpenConns(1)
}
// Test connection
if err := db.Ping(); err != nil {
return nil, fmt.Errorf("failed to ping database: %w", err)