seed

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List() []string

List returns the registered seeder names.

func Register

func Register(seed ...Seeder)

Register adds seeders to the global registry.

func Reset

func Reset()

Reset clears the global registry.

func Run

func Run(ctx context.Context, db *dorm.DB, opts ...RunOption) error

Run executes registered seeders in dependency order.

func Sync

func Sync(ctx context.Context, db SessionProvider, value any, opts ...SyncOption) error

Sync reconciles one record or a collection of records against the database.

Types

type DependencyProvider

type DependencyProvider interface {
	Dependencies() []string
}

DependencyProvider is optional for seeders that depend on other seeders.

type RunOption

type RunOption func(*runConfig)

RunOption configures seeder execution.

func WithPerSeederTransaction

func WithPerSeederTransaction() RunOption

WithPerSeederTransaction keeps the default per-seeder transaction mode explicit.

func WithSingleTransaction

func WithSingleTransaction() RunOption

WithSingleTransaction wraps the full seed run in one transaction.

type Seeder

type Seeder interface {
	Name() string
	Run(context.Context, *orm.Session) error
}

Seeder defines a unit of seed work that can be executed by the runner.

func Registered

func Registered() []Seeder

Registered returns the registered seeders in registration order.

type SessionProvider

type SessionProvider interface {
	WithContext(context.Context) *orm.Session
	WithPolicy(access.Policy) *orm.Session
}

SessionProvider is the minimal database session surface required by Sync.

type SyncOption

type SyncOption func(*syncConfig)

SyncOption configures record synchronization.

func Key

func Key(name string) SyncOption

Key marks a field used to identify a desired record.

Jump to

Keyboard shortcuts

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