NB! Don't forget to call `db.Close()` at the end of the test.
()
| 748 | |
| 749 | // NB! Don't forget to call `db.Close()` at the end of the test. |
| 750 | func 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 |
no test coverage detected
searching dependent graphs…