Documentation
¶
Overview ¶
Package seeder runs database seeders with dependency ordering and transactional execution. A Seeder is any type that implements Seeder; the Runner topologically sorts the registered seeders and runs them in turn.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Default = NewRegistry()
Default is the process-wide registry.
Functions ¶
Types ¶
type Dependent ¶
type Dependent interface {
Dependencies() []string
}
Dependent is an optional interface for declaring dependencies. Seeders without Dependencies are ordered by registration order.
type FuncSeeder ¶
type FuncSeeder struct {
N string
Deps []string
Fn func(ctx context.Context, conn *database.Connection) error
}
FuncSeeder adapts a function to the Seeder interface.
func (*FuncSeeder) Dependencies ¶
func (f *FuncSeeder) Dependencies() []string
func (*FuncSeeder) Name ¶
func (f *FuncSeeder) Name() string
func (*FuncSeeder) Run ¶
func (f *FuncSeeder) Run(ctx context.Context, c *database.Connection) error
type Options ¶
type Options struct {
// Transactional wraps each seeder run in a transaction.
Transactional bool
// Logger receives status messages.
Logger *logger.Logger
// Only restricts the run to the named seeders (and their deps).
Only []string
}
Options configures Runner behavior.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores seeders.
type Runner ¶
type Runner struct {
Conn *database.Connection
Registry *Registry
Opts Options
}
Runner executes seeders.
Click to show internal directories.
Click to hide internal directories.