dreltest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Begin

func Begin(t testingTB, engine *drel.Engine) *drel.Tx

Begin opens a transaction-scoped sandbox against a SQLite (or libSQL) engine: every write made through the returned *drel.Tx is rolled back when the test completes, giving per-test isolation without recreating the schema. Unlike a raw SAVEPOINT through the connection pool, this drives the engine's own single-connection transaction, so isolation holds for file-backed SQLite too (not just in-memory). Begin fails the test on a non-SQLite engine.

func CreateSchema added in v0.5.0

func CreateSchema(t testingTB, engine *drel.Engine, ddl ...string)

CreateSchema executes each DDL statement against the engine in order, failing the test on the first error. Convenience for tests that already hold an engine (it is the helper the PRD's hand-waved createSchema(t, engine) refers to).

func NewSQLite

func NewSQLite(t testingTB, opts ...Option) *drel.Engine

NewSQLite creates an in-memory SQLite engine for testing, applying any options (WithMigrations, WithSchema, WithSeed) in that order. The engine is automatically closed when the test completes.

Types

type Option

type Option func(*config)

Option configures NewSQLite.

func WithMigrations added in v0.5.0

func WithMigrations(dir string) Option

WithMigrations applies all pending up-migrations from dir against the test engine. The migration files must be written for SQLite (the test engine's dialect); see CreateSchema for raw-DDL setup.

func WithSchema added in v0.5.0

func WithSchema(ddl ...string) Option

WithSchema applies raw DDL statements (e.g. CREATE TABLE) after the database is created, each in order. A failing statement fails the test.

func WithSeed

func WithSeed(fn func(*drel.Engine) error) Option

WithSeed runs a seed function after the database is created and after any schema/migrations have been applied. A non-nil error fails the test.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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