Documentation
¶
Overview ¶
Package sqlitetemplate gives tests a migrated SQLite database without migrating it for every test. A Template is migrated once per test binary, into an in-memory database kept open for the life of the binary, and CopyInto copies it into a test's own database with SQLite's online backup API. Migrating Studio's schema (models.InitModels) costs ~300 ms under -race; copying it costs a few milliseconds.
The package imports no Studio package, so models' own tests can use it. gorm keeps some state on the *gorm.DB handle rather than in the database (custom join models: models.RegisterJoinModels); a caller registers that on its handle after CopyInto.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a database migrated once, on first use, and copied from then on.
func (*Template) CopyInto ¶
CopyInto replaces the main database of dst with a copy of the template.
dst must keep its database on one connection (SetMaxOpenConns(1)): every connection to ":memory:" is a database of its own, so with a pool the copy would land in one connection's database and the others would stay empty.