trevstack/server/internal/models/factory/schema_migrations.bob.go
2025-04-10 19:15:21 -04:00

277 lines
8.4 KiB
Go

// Code generated by BobGen sql (devel). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"github.com/aarondl/opt/omit"
"github.com/jaswdr/faker/v2"
models "github.com/spotdemo4/trevstack/server/internal/models"
"github.com/stephenafamo/bob"
)
type SchemaMigrationMod interface {
Apply(*SchemaMigrationTemplate)
}
type SchemaMigrationModFunc func(*SchemaMigrationTemplate)
func (f SchemaMigrationModFunc) Apply(n *SchemaMigrationTemplate) {
f(n)
}
type SchemaMigrationModSlice []SchemaMigrationMod
func (mods SchemaMigrationModSlice) Apply(n *SchemaMigrationTemplate) {
for _, f := range mods {
f.Apply(n)
}
}
// SchemaMigrationTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type SchemaMigrationTemplate struct {
Version func() string
f *Factory
}
// Apply mods to the SchemaMigrationTemplate
func (o *SchemaMigrationTemplate) Apply(mods ...SchemaMigrationMod) {
for _, mod := range mods {
mod.Apply(o)
}
}
// toModel returns an *models.SchemaMigration
// this does nothing with the relationship templates
func (o SchemaMigrationTemplate) toModel() *models.SchemaMigration {
m := &models.SchemaMigration{}
if o.Version != nil {
m.Version = o.Version()
}
return m
}
// toModels returns an models.SchemaMigrationSlice
// this does nothing with the relationship templates
func (o SchemaMigrationTemplate) toModels(number int) models.SchemaMigrationSlice {
m := make(models.SchemaMigrationSlice, number)
for i := range m {
m[i] = o.toModel()
}
return m
}
// setModelRels creates and sets the relationships on *models.SchemaMigration
// according to the relationships in the template. Nothing is inserted into the db
func (t SchemaMigrationTemplate) setModelRels(o *models.SchemaMigration) {}
// BuildSetter returns an *models.SchemaMigrationSetter
// this does nothing with the relationship templates
func (o SchemaMigrationTemplate) BuildSetter() *models.SchemaMigrationSetter {
m := &models.SchemaMigrationSetter{}
if o.Version != nil {
m.Version = omit.From(o.Version())
}
return m
}
// BuildManySetter returns an []*models.SchemaMigrationSetter
// this does nothing with the relationship templates
func (o SchemaMigrationTemplate) BuildManySetter(number int) []*models.SchemaMigrationSetter {
m := make([]*models.SchemaMigrationSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.SchemaMigration
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use SchemaMigrationTemplate.Create
func (o SchemaMigrationTemplate) Build() *models.SchemaMigration {
m := o.toModel()
o.setModelRels(m)
return m
}
// BuildMany returns an models.SchemaMigrationSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use SchemaMigrationTemplate.CreateMany
func (o SchemaMigrationTemplate) BuildMany(number int) models.SchemaMigrationSlice {
m := make(models.SchemaMigrationSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableSchemaMigration(m *models.SchemaMigrationSetter) {
if m.Version.IsUnset() {
m.Version = omit.From(random_string(nil))
}
}
// insertOptRels creates and inserts any optional the relationships on *models.SchemaMigration
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *SchemaMigrationTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.SchemaMigration) (context.Context, error) {
var err error
return ctx, err
}
// Create builds a schemaMigration and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *SchemaMigrationTemplate) Create(ctx context.Context, exec bob.Executor) (*models.SchemaMigration, error) {
_, m, err := o.create(ctx, exec)
return m, err
}
// MustCreate builds a schemaMigration and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *SchemaMigrationTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.SchemaMigration {
_, m, err := o.create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a schemaMigration and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o *SchemaMigrationTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.SchemaMigration {
tb.Helper()
_, m, err := o.create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// create builds a schemaMigration and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// this returns a context that includes the newly inserted model
func (o *SchemaMigrationTemplate) create(ctx context.Context, exec bob.Executor) (context.Context, *models.SchemaMigration, error) {
var err error
opt := o.BuildSetter()
ensureCreatableSchemaMigration(opt)
m, err := models.SchemaMigrations.Insert(opt).One(ctx, exec)
if err != nil {
return ctx, nil, err
}
ctx = schemaMigrationCtx.WithValue(ctx, m)
ctx, err = o.insertOptRels(ctx, exec, m)
return ctx, m, err
}
// CreateMany builds multiple schemaMigrations and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o SchemaMigrationTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.SchemaMigrationSlice, error) {
_, m, err := o.createMany(ctx, exec, number)
return m, err
}
// MustCreateMany builds multiple schemaMigrations and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o SchemaMigrationTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.SchemaMigrationSlice {
_, m, err := o.createMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple schemaMigrations and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
func (o SchemaMigrationTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.SchemaMigrationSlice {
tb.Helper()
_, m, err := o.createMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// createMany builds multiple schemaMigrations and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// this returns a context that includes the newly inserted models
func (o SchemaMigrationTemplate) createMany(ctx context.Context, exec bob.Executor, number int) (context.Context, models.SchemaMigrationSlice, error) {
var err error
m := make(models.SchemaMigrationSlice, number)
for i := range m {
ctx, m[i], err = o.create(ctx, exec)
if err != nil {
return ctx, nil, err
}
}
return ctx, m, nil
}
// SchemaMigration has methods that act as mods for the SchemaMigrationTemplate
var SchemaMigrationMods schemaMigrationMods
type schemaMigrationMods struct{}
func (m schemaMigrationMods) RandomizeAllColumns(f *faker.Faker) SchemaMigrationMod {
return SchemaMigrationModSlice{
SchemaMigrationMods.RandomVersion(f),
}
}
// Set the model columns to this value
func (m schemaMigrationMods) Version(val string) SchemaMigrationMod {
return SchemaMigrationModFunc(func(o *SchemaMigrationTemplate) {
o.Version = func() string { return val }
})
}
// Set the Column from the function
func (m schemaMigrationMods) VersionFunc(f func() string) SchemaMigrationMod {
return SchemaMigrationModFunc(func(o *SchemaMigrationTemplate) {
o.Version = f
})
}
// Clear any values for the column
func (m schemaMigrationMods) UnsetVersion() SchemaMigrationMod {
return SchemaMigrationModFunc(func(o *SchemaMigrationTemplate) {
o.Version = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m schemaMigrationMods) RandomVersion(f *faker.Faker) SchemaMigrationMod {
return SchemaMigrationModFunc(func(o *SchemaMigrationTemplate) {
o.Version = func() string {
return random_string(f)
}
})
}