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:
File diff suppressed because one or more lines are too long
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user