@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
@@ -22,11 +23,17 @@ func New(dbPath string) (*DB, error) {
|
||||
return nil, fmt.Errorf("create db directory: %w", err)
|
||||
}
|
||||
|
||||
conn, err := sql.Open("sqlite", dbPath+"?_foreign_keys=1")
|
||||
// Configure connection pool
|
||||
conn, err := sql.Open("sqlite", dbPath+"?_foreign_keys=1&_journal_mode=WAL")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open database: %w", err)
|
||||
}
|
||||
|
||||
// Set connection pool settings for better performance
|
||||
conn.SetMaxOpenConns(25) // Maximum number of open connections
|
||||
conn.SetMaxIdleConns(5) // Maximum number of idle connections
|
||||
conn.SetConnMaxLifetime(5 * time.Minute) // Maximum connection lifetime
|
||||
|
||||
db := &DB{DB: conn}
|
||||
|
||||
// Test connection
|
||||
|
||||
Reference in New Issue
Block a user