Documentation
¶
Overview ¶
Package factory provides a generic, type-safe model factory inspired by Laravel's factories. Factories generate fake model instances and can persist them via orm.Save. States layer transformations on top of the default definition.
Index ¶
- type DefinitionFn
- type Factory
- func (f *Factory[T]) AfterCreate(fn func(context.Context, *T) error) *Factory[T]
- func (f *Factory[T]) AfterMake(fn func(*T)) *Factory[T]
- func (f *Factory[T]) Count(n int) *Factory[T]
- func (f *Factory[T]) Create(ctx context.Context) ([]T, error)
- func (f *Factory[T]) CreateOne(ctx context.Context) (T, error)
- func (f *Factory[T]) Make() []T
- func (f *Factory[T]) MakeOne() T
- func (f *Factory[T]) Set(fn func(*T)) *Factory[T]
- func (f *Factory[T]) State(fn StateFn[T]) *Factory[T]
- type Faker
- func (f *Faker) Address() string
- func (f *Faker) Bool() bool
- func (f *Faker) City() string
- func (f *Faker) Country() string
- func (f *Faker) Email() string
- func (f *Faker) FirstName() string
- func (f *Faker) Float64Range(min, max float64) float64
- func (f *Faker) IntRange(min, max int) int
- func (f *Faker) LastName() string
- func (f *Faker) Name() string
- func (f *Faker) Paragraph(paragraphs, sentences, words int, separator string) string
- func (f *Faker) Password() string
- func (f *Faker) Phone() string
- func (f *Faker) PickString(values []string) string
- func (f *Faker) Raw() *gofakeit.Faker
- func (f *Faker) Sentence(words int) string
- func (f *Faker) URL() string
- func (f *Faker) UUID() string
- func (f *Faker) UserName() string
- func (f *Faker) Word() string
- type StateFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefinitionFn ¶
DefinitionFn returns a freshly-built model instance.
type Factory ¶
type Factory[T any] struct { // contains filtered or unexported fields }
Factory builds and persists T instances.
func New ¶
func New[T any](conn *database.Connection, def DefinitionFn[T]) *Factory[T]
New constructs a Factory using a definition function.
func (*Factory[T]) AfterCreate ¶
AfterCreate runs after persistence.
type Faker ¶
type Faker struct {
// contains filtered or unexported fields
}
Faker wraps gofakeit with stable, allocation-conscious helpers. Each Factory owns one Faker; in tests, callers may seed the underlying Faker for reproducible builds.
func (*Faker) Float64Range ¶
func (*Faker) PickString ¶
Click to show internal directories.
Click to hide internal directories.