MCPcopy
hub / github.com/pocketbase/pocketbase / createTestDB

Function createTestDB

tools/search/provider_test.go:750–776  ·  view source on GitHub ↗

NB! Don't forget to call `db.Close()` at the end of the test.

()

Source from the content-addressed store, hash-verified

748
749// NB! Don't forget to call `db.Close()` at the end of the test.
750func createTestDB() (*testDB, error) {
751 // using a shared cache to allow multiple connections access to
752 // the same in memory database https://www.sqlite.org/inmemorydb.html
753 sqlDB, err := sql.Open("sqlite", "file::memory:?cache=shared")
754 if err != nil {
755 return nil, err
756 }
757
758 db := testDB{DB: dbx.NewFromDB(sqlDB, "sqlite")}
759 db.CreateTable("test", map[string]string{
760 "id": "int default 0",
761 "test1": "int default 0",
762 "test2": "text default ''",
763 "test3": "text default ''",
764 strings.Repeat("a", MaxSortFieldLength): "text default ''",
765 strings.Repeat("b", MaxSortFieldLength+1): "text default ''",
766 }).Execute()
767 db.Insert("test", dbx.Params{"id": 1, "test1": 1, "test2": "test2.1"}).Execute()
768 db.Insert("test", dbx.Params{"id": 2, "test1": 2, "test2": "test2.2"}).Execute()
769 db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
770 db.mu.Lock()
771 defer db.mu.Unlock()
772 db.CalledQueries = append(db.CalledQueries, sql)
773 }
774
775 return &db, nil
776}
777
778// ---
779

Calls 4

ExecuteMethod · 0.80
CreateTableMethod · 0.80
InsertMethod · 0.80
OpenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…