dbfixture

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: BSD-2-Clause Imports: 16 Imported by: 46 modules, 41 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeforeInsertData added in v1.0.9

type BeforeInsertData struct {
	Query *bun.InsertQuery
	Model any
}

BeforeInsertData holds the context passed to BeforeInsertFunc callbacks.

type BeforeInsertFunc added in v1.0.9

type BeforeInsertFunc func(ctx context.Context, data *BeforeInsertData) error

BeforeInsertFunc is a callback invoked before each fixture row is inserted.

type Encoder added in v1.0.0

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder writes fixture data as YAML.

func NewEncoder added in v1.0.0

func NewEncoder(db bun.IDB, w io.Writer) *Encoder

NewEncoder creates an Encoder that writes YAML to w.

func (*Encoder) Encode added in v1.0.0

func (e *Encoder) Encode(multiRows ...any) error

Encode encodes the given model slices as YAML fixture data.

type Fixture

type Fixture struct {
	// contains filtered or unexported fields
}

Fixture loads YAML fixtures into a database.

func New

func New(db bun.IDB, opts ...FixtureOption) *Fixture

New creates a Fixture for the given database.

func (*Fixture) Load

func (f *Fixture) Load(ctx context.Context, fsys fs.FS, names ...string) error

Load reads YAML fixture files from fsys and inserts rows into the database.

func (*Fixture) MustRow

func (f *Fixture) MustRow(id string) any

MustRow is like Row but panics on error.

func (*Fixture) Row

func (f *Fixture) Row(id string) (any, error)

Row returns a previously loaded fixture row by its "model.id" identifier.

type FixtureOption

type FixtureOption func(l *Fixture)

FixtureOption configures a Fixture.

func WithBeforeInsert added in v1.0.9

func WithBeforeInsert(fn BeforeInsertFunc) FixtureOption

WithBeforeInsert registers a callback that runs before inserting each fixture row.

func WithRecreateTables

func WithRecreateTables() FixtureOption

WithRecreateTables drops and re-creates tables before loading fixtures.

func WithTemplateFuncs

func WithTemplateFuncs(funcMap template.FuncMap) FixtureOption

WithTemplateFuncs merges the given template functions into the fixture's function map.

func WithTruncateTables

func WithTruncateTables() FixtureOption

WithTruncateTables truncates tables before loading fixtures.

Jump to

Keyboard shortcuts

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