seed

package
v0.0.0-...-2da20e2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package seed provides helpers for seeding test and development data.

The package is intended for non-production use (tests, local development).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCount is returned when a count argument is less than or equal to zero.
	ErrInvalidCount = errors.New("count must be greater than zero")

	// ErrNoRows indicates that a query or operation returned no rows.
	ErrNoRows = errors.New("no rows")
)

Functions

This section is empty.

Types

type Seed

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

Seed holds dependencies required by Seed methods.

func New

func New(db *app.DB) *Seed

New creates a Seed instance with all required dependencies initialized.

func (*Seed) All

func (s *Seed) All(ctx context.Context, count int) (err error)

All seeds all supported entities in a predefined order.

func (*Seed) Books

func (s *Seed) Books(ctx context.Context, count int) (err error)

Books seeds the database with `count` random books.

It generates a unique public slug (entities.public_id) for each book title, creates and persists a cover image file, then creates an entity + book record. Inserts are executed concurrently; the first error stops the seeding.

func (*Seed) RandomUserID

func (s *Seed) RandomUserID(ctx context.Context) (ds.ID, error)

RandomUserID returns a random user ID.

On the first call, it loads up to 100 random user IDs from the database and caches them for subsequent calls to avoid repeated queries.

func (*Seed) Users

func (s *Seed) Users(ctx context.Context, count int) (err error)

Users seeds the database with `count` random users.

It generates unique usernames and emails, assigns randomized timestamps (created/updated/deleted), and inserts users concurrently using the factory.

Jump to

Keyboard shortcuts

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