factory

package
v0.0.0-...-7b21f04 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Batch

func Batch[T any](size int, createFn func(m ...T) (*T, error), override ...T) ([]*T, error)

Batch is a function that repeatedly executes a data creation function ('createFn') a specified number of times and returns a slice of pointers to the created objects.

T is the type of the struct being created (e.g., ds.User). fn is the function that creates a single instance of T (e.g., CreateUser). override allows passing custom field values to override defaults in the created instances.

func Five

func Five[T any](fn func(m ...T) (*T, error), override ...T) ([]*T, error)

Five is a convenience function to create exactly five instances of a data structure T. It is a wrapper around Batch with size=5.

func LookupIUnique

func LookupIUnique[T any](ctx context.Context, db *app.DB, table, column string, value T,
	transformFn func(T) T) (T, error)

LookupIUnique tries to find a unique value in the given table.column by repeatedly querying the database with a transformed version of the input value.

The transformFn is expected to produce a new candidate value (for example, by appending a suffix or incrementing a counter) and must eventually lead to a value that does not exist in the database, otherwise the function will recurse indefinitely (angry emoji).

func NewBookAuthor

func NewBookAuthor() ds.BookAuthor

NewBookAuthor creates a new BookAuthor model populated with fake data.

func NewBookAuthors

func NewBookAuthors(countOpt ...int) []ds.BookAuthor

NewBookAuthors generates and returns a slice of BookAuthor values.

func Ten

func Ten[T any](fn func(m ...T) (*T, error), override ...T) ([]*T, error)

Ten is a convenience function to create exactly ten instances of a data structure T. It is a wrapper around Batch with size=10.

func Two

func Two[T any](fn func(m ...T) (*T, error), override ...T) ([]*T, error)

Two is a convenience function to create exactly two instances of a data structure T. It is a wrapper around Batch with size=2.

Types

type Factory

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

Factory holds dependencies required by factory methods.

func New

func New(db *app.DB) *Factory

New is a factory function that creates and returns a new Factory instance.

func (*Factory) CreateBook

func (f *Factory) CreateBook(overrideOpt ...ds.Book) (m *ds.Book, err error)

CreateBook creates and persists a new Book record in the repository.

func (*Factory) CreateChangeEmailRequest

func (f *Factory) CreateChangeEmailRequest(overrideOpt ...ds.ChangeEmailRequest) (
	m *ds.ChangeEmailRequest, err error)

CreateChangeEmailRequest ...

func (*Factory) CreateEmailConfirmation

func (f *Factory) CreateEmailConfirmation(overrideOpt ...ds.EmailConfirmation) (m *ds.EmailConfirmation, err error)

CreateEmailConfirmation ...

func (*Factory) CreateEntity

func (f *Factory) CreateEntity(overrideOpt ...ds.Entity) (m *ds.Entity, err error)

CreateEntity ...

func (*Factory) CreateEntityChangeRequest

func (f *Factory) CreateEntityChangeRequest(overrideOpt ...ds.EntityChangeRequest) (
	m *ds.EntityChangeRequest, err error)

CreateEntityChangeRequest creates and persists a new EntityChangeRequest to the repository. Automatically creates associated Book and User entities if not provided in the override.

func (*Factory) CreateEventLog

func (f *Factory) CreateEventLog(overrideOpt ...ds.EventLog) (m *ds.EventLog, err error)

CreateEventLog creates and persists a new EventLog using the repository.

func (*Factory) CreateFile

func (f *Factory) CreateFile(overrideOpt ...ds.File) (m *ds.File, err error)

CreateFile ...

func (*Factory) CreateOAuthUserAccount

func (f *Factory) CreateOAuthUserAccount(overrideOpt ...ds.OAuthUserAccount) (
	m *ds.OAuthUserAccount, err error)

CreateOAuthUserAccount ...

func (*Factory) CreatePage

func (f *Factory) CreatePage(overrideOpt ...ds.Page) (m *ds.Page, err error)

CreatePage creates and persists a Page domain model using the factory.

func (*Factory) CreatePasswordResetToken

func (f *Factory) CreatePasswordResetToken(overrideOpt ...ds.PasswordResetToken) (
	m *ds.PasswordResetToken, err error)

CreatePasswordResetToken ...

func (*Factory) CreateTopic

func (f *Factory) CreateTopic(overrideOpt ...ds.Topic) (m *ds.Topic, err error)

CreateTopic creates and persists a new Topic record in the repository.

func (*Factory) CreateUser

func (f *Factory) CreateUser(overrideOpt ...ds.User) (m *ds.User, err error)

CreateUser ...

func (*Factory) CreateUserSession

func (f *Factory) CreateUserSession(overrideOpt ...ds.UserSession) (m *ds.UserSession, err error)

CreateUserSession ...

func (*Factory) NewBook

func (f *Factory) NewBook(overrideOpt ...ds.Book) (m *ds.Book)

NewBook creates a new Book model populated with fake data.

func (*Factory) NewChangeEmailRequest

func (f *Factory) NewChangeEmailRequest(overrideOpt ...ds.ChangeEmailRequest) (m *ds.ChangeEmailRequest)

NewChangeEmailRequest ...

func (*Factory) NewEmailConfirmation

func (f *Factory) NewEmailConfirmation(overrideOpt ...ds.EmailConfirmation) (m *ds.EmailConfirmation)

NewEmailConfirmation ...

func (*Factory) NewEntity

func (f *Factory) NewEntity(overrideOpt ...ds.Entity) (m *ds.Entity)

NewEntity ...

func (*Factory) NewEntityChangeRequest

func (f *Factory) NewEntityChangeRequest(overrideOpt ...ds.EntityChangeRequest) (m *ds.EntityChangeRequest)

NewEntityChangeRequest creates a new EntityChangeRequest with default values.

func (*Factory) NewEventLog

func (f *Factory) NewEventLog(overrideOpt ...ds.EventLog) (m *ds.EventLog)

NewEventLog creates a new EventLog instance populated with sensible default values for testing and seeding purposes.

func (*Factory) NewFile

func (f *Factory) NewFile(overrideOpt ...ds.File) (m *ds.File)

NewFile ...

func (*Factory) NewOAuthUserAccount

func (f *Factory) NewOAuthUserAccount(overrideOpt ...ds.OAuthUserAccount) (m *ds.OAuthUserAccount)

NewOAuthUserAccount ...

func (*Factory) NewPage

func (f *Factory) NewPage(overrideOpt ...ds.Page) (m *ds.Page)

NewPage constructs a new Page model with default values.

func (*Factory) NewPasswordResetToken

func (f *Factory) NewPasswordResetToken(overrideOpt ...ds.PasswordResetToken) (m *ds.PasswordResetToken)

NewPasswordResetToken ...

func (*Factory) NewTopic

func (f *Factory) NewTopic(overrideOpt ...ds.Topic) (m *ds.Topic)

NewTopic creates a new Topic model instance populated with default randomly generated data.

func (*Factory) NewUser

func (f *Factory) NewUser(overrideOpt ...ds.User) (m *ds.User)

NewUser ...

func (*Factory) NewUserSession

func (f *Factory) NewUserSession(overrideOpt ...ds.UserSession) (m *ds.UserSession)

NewUserSession ...

Directories

Path Synopsis
Package random provides utility functions for generating various types of random data.
Package random provides utility functions for generating various types of random data.

Jump to

Keyboard shortcuts

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