seeders

command
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

README

Seeders Example

This example demonstrates how to use seeders to populate your database with initial data.

What are Seeders?

Seeders are used to populate your database with test or initial data. They provide a convenient way to fill your database with sample records for development and testing purposes.

Running the Example

go run main.go

What This Example Demonstrates

  1. Creating seeders: Implements the Seeder interface with Signature() and Run() methods
  2. Using Seed(): Runs seeders every time called
  3. Using SeedOnce(): Runs seeders only once (subsequent calls skip them)
  4. Using Seeder facade: Advanced operations like getting specific seeders
  5. Verifying seeded data: Checking that data was successfully seeded

Key Concepts

Seeder Interface

A seeder must implement:

type Seeder interface {
    Signature() string
    Run() error
}
Running Seeders
// Run seeders (executes every time)
db.Seed([]contractsseeder.Seeder{userSeeder, roleSeeder})

// Run seeders once (subsequent calls skip)
db.SeedOnce([]contractsseeder.Seeder{userSeeder, roleSeeder})

// Use facade for advanced operations
facade := db.Seeder()
facade.Register(seeders)
facade.Call(seeders)

Best Practices

  • Use descriptive signatures for your seeders
  • Handle errors gracefully in your seeders
  • Use SeedOnce for idempotent operations
  • Keep seeders simple and focused

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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