MCPcopy Create free account
hub / github.com/astercloud/aster / New

Function New

pkg/session/sqlite/store.go:31–50  ·  view source on GitHub ↗

New creates a new SQLite session service. dbPath is the path to the SQLite database file. If the file doesn't exist, it will be created.

(dbPath string)

Source from the content-addressed store, hash-verified

29// dbPath is the path to the SQLite database file.
30// If the file doesn't exist, it will be created.
31func New(dbPath string) (*Service, error) {
32 db, err := sql.Open("sqlite3", dbPath+"?_journal_mode=WAL&_busy_timeout=5000")
33 if err != nil {
34 return nil, fmt.Errorf("open sqlite database: %w", err)
35 }
36
37 // Set connection pool settings for SQLite
38 db.SetMaxOpenConns(1) // SQLite only supports one writer
39 db.SetMaxIdleConns(1)
40 db.SetConnMaxLifetime(time.Hour)
41
42 s := &Service{db: db}
43
44 if err := s.migrate(); err != nil {
45 _ = db.Close() // Ignore close error, migration error is more important
46 return nil, fmt.Errorf("migrate database: %w", err)
47 }
48
49 return s, nil
50}
51
52// migrate creates the necessary tables if they don't exist.
53func (s *Service) migrate() error {

Callers 8

runSessionFunction · 0.92
mainFunction · 0.92
TestServiceFunction · 0.70
TestEventsFunction · 0.70
TestStateFunction · 0.70
TestDatabasePersistenceFunction · 0.70
TestEventFilteringFunction · 0.70
TestDatabaseFileCreationFunction · 0.70

Calls 2

migrateMethod · 0.95
CloseMethod · 0.65

Tested by 6

TestServiceFunction · 0.56
TestEventsFunction · 0.56
TestStateFunction · 0.56
TestDatabasePersistenceFunction · 0.56
TestEventFilteringFunction · 0.56
TestDatabaseFileCreationFunction · 0.56