MCPcopy Create free account
hub / github.com/compozy/agh / openSQLiteDatabaseOnce

Function openSQLiteDatabaseOnce

internal/store/sqlite.go:84–114  ·  view source on GitHub ↗
(
	ctx context.Context,
	path string,
	initialize func(context.Context, *sql.DB) error,
	extraPragmas ...string,
)

Source from the content-addressed store, hash-verified

82}
83
84func openSQLiteDatabaseOnce(
85 ctx context.Context,
86 path string,
87 initialize func(context.Context, *sql.DB) error,
88 extraPragmas ...string,
89) (*sql.DB, error) {
90 db, err := sql.Open(sqliteDriverName, sqliteDSN(path, extraPragmas...))
91 if err != nil {
92 return nil, fmt.Errorf("store: open sqlite database %q: %w", path, err)
93 }
94
95 db.SetMaxOpenConns(defaultMaxOpenConns)
96 db.SetMaxIdleConns(defaultMaxIdleConns)
97
98 if err := db.PingContext(ctx); err != nil {
99 closeQuietly(db)
100 return nil, fmt.Errorf("store: ping sqlite database %q: %w", path, err)
101 }
102 if err := configureSQLite(ctx, db); err != nil {
103 closeQuietly(db)
104 return nil, fmt.Errorf("store: configure sqlite database %q: %w", path, err)
105 }
106 if initialize != nil {
107 if err := initialize(ctx, db); err != nil {
108 closeQuietly(db)
109 return nil, fmt.Errorf("store: initialize sqlite database %q: %w", path, err)
110 }
111 }
112
113 return db, nil
114}
115
116func sqliteDSN(path string, extraPragmas ...string) string {
117 u := url.URL{

Callers 3

TestStoreSQLiteHelpersFunction · 0.85

Calls 4

closeQuietlyFunction · 0.85
configureSQLiteFunction · 0.85
initializeFunction · 0.85
sqliteDSNFunction · 0.70

Tested by 2

TestStoreSQLiteHelpersFunction · 0.68