sqlite

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL