seed

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 5 Imported by: 1

README

👮‍♀️ Seed

Go Reference Go Report Card Taylor Swift

Installation

$ go get github.com/zeiss/gorm-seed

Examples

See examples to understand the provided interfaces.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database added in v0.1.1

type Database[R, W any] interface {
	// ReadTx starts a read only transaction.
	ReadTx(context.Context, func(context.Context, R) error) error
	// ReadWriteTx starts a read write transaction.
	ReadWriteTx(context.Context, func(context.Context, W) error) error

	Migrator
	io.Closer
}

Database provides methods for transactional operations.

func NewDatabase added in v0.1.1

func NewDatabase[R, W any](conn *gorm.DB, r ReadTxFactory[R], rw ReadWriteTxFactory[W]) (Database[R, W], error)

NewDatabase returns a new instance of db.

type Migrator added in v0.1.1

type Migrator interface {
	// Migrate is a method that runs the migration.
	Migrate(context.Context, ...any) error
}

Migrator is a method that runs the migration.

type Opt

type Opt func(*seederImpl)

Opt is a function that configures the Seeder.

func WithDatabase

func WithDatabase(db *gorm.DB) Opt

WithDatabase sets the database for the Seeder.

type QueryError added in v0.1.1

type QueryError struct {
	// Query is the query that caused the error.
	Query string
	// Err is the error that occurred.
	Err error
}

QueryError is an error that occurred while executing a query.

func NewQueryError added in v0.1.1

func NewQueryError(query string, err error) *QueryError

NewQueryError returns a new QueryError.

func (*QueryError) Error added in v0.1.1

func (e *QueryError) Error() string

Error implements the error interface.

func (*QueryError) Unwrap added in v0.1.1

func (e *QueryError) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type ReadTxFactory added in v0.1.1

type ReadTxFactory[R any] func(*gorm.DB) (R, error)

ReadTxFactory is a function that creates a new instance of Datastore.

type ReadWriteTxFactory added in v0.1.1

type ReadWriteTxFactory[W any] func(*gorm.DB) (W, error)

ReadWriteTxFactory is a function that creates a new instance of Datastore.

type Seed

type Seed struct {
	// Name is the name of the seed.
	Name string
	// Run is the function that seeds the data.
	Run SeedFunc
}

Seed is a struct that contains the data to be seeded.

type SeedFunc

type SeedFunc func(*gorm.DB) error

SeedFunc is a function that seeds data.

type Seeder

type Seeder interface {
	Seed(ctx context.Context, seeds ...Seed) error
}

Seeder is an interface for seeding data.

func NewSeeder

func NewSeeder(db *gorm.DB, opts ...Opt) Seeder

NewSeeder creates a new Seeder.

type Seeds

type Seeds []Seed

Seeds is a slice of Seed.

func (Seeds) All

func (s Seeds) All() []Seed

All returns all the seeds.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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