Signed-off-by: kaedwen <kaedwen@heinrich.blue>
This commit is contained in:
3 files changed
+8
-11
No files matched your search
+6
-1
@@ -39,11 +39,16 @@ func New(dbPath string, logger *slog.Logger) (Database, error) {
|
||||
|
||||
// Open database
|
||||
// Note: Using modernc.org/sqlite (pure Go, no CGO) instead of mattn/go-sqlite3
|
||||
db, err := sql.Open("sqlite", dbPath+"?_pragma=busy_timeout(5000)")
|
||||
db, err := sql.Open("sqlite", dbPath+"?_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open database: %w", err)
|
||||
}
|
||||
|
||||
// Set connection pool limits to prevent "database is locked" errors
|
||||
db.SetMaxOpenConns(1) // SQLite works best with single writer
|
||||
db.SetMaxIdleConns(1)
|
||||
db.SetConnMaxLifetime(0) // connections don't expire
|
||||
|
||||
// Test connection
|
||||
if err := db.Ping(); err != nil {
|
||||
db.Close()
|
||||
|
||||
Reference in new issue
Block a user