Documentation
¶
Overview ¶
Package sqlite. sqlite.go - SQLite backend for dbtestkit. Uses an in-process, file-backed SQLite database instead of a Docker container — ideal for fast, hermetic tests that do not need a real network database.
Reset strategy: since SQLite has no equivalent of mysqldump streaming back into the same process, the fast path simply copies a pristine snapshot of the database file over the working file. The slow path runs the user's schema + data initializers, then snapshots the file as the pristine copy.
Index ¶
- func New() dbtestkit.DatabaseDriver
- type SQLiteDriver
- func (d *SQLiteDriver) Driver() dbtestkit.Driver
- func (d *SQLiteDriver) GenerateDump(_ context.Context, _ *dbtestkit.Environment, dumpPath string) error
- func (d *SQLiteDriver) ResetStrategy() dbtestkit.ResetStrategy
- func (d *SQLiteDriver) RestoreDump(_ context.Context, _ *dbtestkit.Environment, dumpPath string) error
- func (d *SQLiteDriver) Start(_ context.Context, env *dbtestkit.Environment) (string, error)
- func (d *SQLiteDriver) Stop(_ context.Context, _ *dbtestkit.Environment) error
- func (d *SQLiteDriver) Truncate(_ context.Context, env *dbtestkit.Environment) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New() dbtestkit.DatabaseDriver
New returns a fresh SQLite driver instance.
Pass the result to dbtestkit.WithDriver:
dbtestkit.Run(m,
dbtestkit.WithDriver(sqlite.New()),
...
)
Types ¶
type SQLiteDriver ¶ added in v0.3.2
type SQLiteDriver struct {
// contains filtered or unexported fields
}
SQLiteDriver implements dbtestkit.DatabaseDriver for SQLite.
func (*SQLiteDriver) Driver ¶ added in v0.3.2
func (d *SQLiteDriver) Driver() dbtestkit.Driver
Driver returns the dbtestkit.Driver constant this implementation serves.
func (*SQLiteDriver) GenerateDump ¶ added in v0.3.2
func (d *SQLiteDriver) GenerateDump(_ context.Context, _ *dbtestkit.Environment, dumpPath string) error
GenerateDump snapshots the current working database file as the pristine copy. Called once during the slow-path setup.
func (*SQLiteDriver) ResetStrategy ¶ added in v0.3.2
func (d *SQLiteDriver) ResetStrategy() dbtestkit.ResetStrategy
ResetStrategy returns TruncateAndSeed to avoid Windows file-locking issues when trying to replace the SQLite file while Xorm holds open connections.
func (*SQLiteDriver) RestoreDump ¶ added in v0.3.2
func (d *SQLiteDriver) RestoreDump(_ context.Context, _ *dbtestkit.Environment, dumpPath string) error
RestoreDump copies the pristine snapshot over the working database file. This is the fast-path reset (~μs).
For SQLite, the "dump path" passed in is treated as a binary snapshot file path rather than a SQL text dump. This is dramatically faster than re-running .dump output through the CLI.
func (*SQLiteDriver) Start ¶ added in v0.3.2
func (d *SQLiteDriver) Start(_ context.Context, env *dbtestkit.Environment) (string, error)
Start ensures the SQLite database file does not exist (fresh start) and returns its file:// DSN.
The actual schema + data initialization is performed by the dbtestkit core via the user's WithSchemaInitializer and WithDataInitializer callbacks — Start only prepares the filesystem.
func (*SQLiteDriver) Stop ¶ added in v0.3.2
func (d *SQLiteDriver) Stop(_ context.Context, _ *dbtestkit.Environment) error
Stop removes the working database file.
func (*SQLiteDriver) Truncate ¶ added in v0.3.2
func (d *SQLiteDriver) Truncate(_ context.Context, env *dbtestkit.Environment) error
Truncate empties every user table via DELETE statements. Used by the dbtestkit core as a fallback when no pristine snapshot is available.
SQLite does not support TRUNCATE TABLE — we use DELETE, which is slower than the snapshot restore but works without a pre-baked snapshot.