MCPcopy
hub / github.com/sqlc-dev/sqlc / CreateSQLiteDatabase

Function CreateSQLiteDatabase

internal/sqltest/sqlite.go:28–56  ·  view source on GitHub ↗
(t *testing.T, path string, migrations []string)

Source from the content-addressed store, hash-verified

26}
27
28func CreateSQLiteDatabase(t *testing.T, path string, migrations []string) (*sql.DB, func()) {
29 t.Helper()
30
31 t.Logf("open %s\n", path)
32 sdb, err := sql.Open("sqlite3", path)
33 if err != nil {
34 t.Fatal(err)
35 }
36
37 files, err := sqlpath.Glob(migrations)
38 if err != nil {
39 t.Fatal(err)
40 }
41 for _, f := range files {
42 blob, err := os.ReadFile(f)
43 if err != nil {
44 t.Fatal(err)
45 }
46 if _, err := sdb.Exec(string(blob)); err != nil {
47 t.Fatalf("%s: %s", filepath.Base(f), err)
48 }
49 }
50
51 return sdb, func() {
52 if _, err := os.Stat(path); err == nil {
53 os.Remove(path)
54 }
55 }
56}

Callers 2

TestExamplesVetFunction · 0.92
SQLiteFunction · 0.85

Calls 3

GlobFunction · 0.92
OpenMethod · 0.80
ExecMethod · 0.65

Tested by 1

TestExamplesVetFunction · 0.74