MCPcopy Index your code
hub / github.com/superfly/litefs / OpenSQLDB

Function OpenSQLDB

internal/testingutil/testingutil.go:59–87  ·  view source on GitHub ↗

OpenSQLDB opens a connection to a SQLite database.

(tb testing.TB, dsn string)

Source from the content-addressed store, hash-verified

57
58// OpenSQLDB opens a connection to a SQLite database.
59func OpenSQLDB(tb testing.TB, dsn string) *sql.DB {
60 tb.Helper()
61
62 db, err := sql.Open("sqlite3", dsn)
63 if err != nil {
64 tb.Fatal(err)
65 }
66
67 if *pageSize != 0 {
68 if _, err := db.Exec(fmt.Sprintf(`PRAGMA page_size = %d`, *pageSize)); err != nil {
69 tb.Fatal(err)
70 }
71 }
72
73 if _, err := db.Exec(`PRAGMA busy_timeout = 5000`); err != nil {
74 tb.Fatal(err)
75 }
76 if _, err := db.Exec(`PRAGMA journal_mode = ` + *journalMode); err != nil {
77 tb.Fatal(err)
78 }
79
80 tb.Cleanup(func() {
81 if err := db.Close(); err != nil {
82 tb.Fatal(err)
83 }
84 })
85
86 return db
87}
88
89// ReopenSQLDB closes the existing database connection and reopens it with the DSN.
90func ReopenSQLDB(tb testing.TB, db **sql.DB, dsn string) {

Calls 2

OpenMethod · 0.65
CloseMethod · 0.65