Also start the pattern of breaking out pool pages together in their own file. I think its easier to read this way.
498 lines
15 KiB
Go
498 lines
15 KiB
Go
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
|
|
|
package factory
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/google/uuid"
|
|
"github.com/jaswdr/faker/v2"
|
|
"github.com/stephenafamo/bob"
|
|
)
|
|
|
|
type PublicreportPoolPhotoMod interface {
|
|
Apply(context.Context, *PublicreportPoolPhotoTemplate)
|
|
}
|
|
|
|
type PublicreportPoolPhotoModFunc func(context.Context, *PublicreportPoolPhotoTemplate)
|
|
|
|
func (f PublicreportPoolPhotoModFunc) Apply(ctx context.Context, n *PublicreportPoolPhotoTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type PublicreportPoolPhotoModSlice []PublicreportPoolPhotoMod
|
|
|
|
func (mods PublicreportPoolPhotoModSlice) Apply(ctx context.Context, n *PublicreportPoolPhotoTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// PublicreportPoolPhotoTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type PublicreportPoolPhotoTemplate struct {
|
|
ID func() int32
|
|
Size func() int64
|
|
Filename func() string
|
|
PoolID func() int32
|
|
UUID func() uuid.UUID
|
|
|
|
r publicreportPoolPhotoR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type publicreportPoolPhotoR struct {
|
|
Pool *publicreportPoolPhotoRPoolR
|
|
}
|
|
|
|
type publicreportPoolPhotoRPoolR struct {
|
|
o *PublicreportPoolTemplate
|
|
}
|
|
|
|
// Apply mods to the PublicreportPoolPhotoTemplate
|
|
func (o *PublicreportPoolPhotoTemplate) Apply(ctx context.Context, mods ...PublicreportPoolPhotoMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.PublicreportPoolPhoto
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t PublicreportPoolPhotoTemplate) setModelRels(o *models.PublicreportPoolPhoto) {
|
|
if t.r.Pool != nil {
|
|
rel := t.r.Pool.o.Build()
|
|
rel.R.PoolPhotos = append(rel.R.PoolPhotos, o)
|
|
o.PoolID = rel.ID // h2
|
|
o.R.Pool = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.PublicreportPoolPhotoSetter
|
|
// this does nothing with the relationship templates
|
|
func (o PublicreportPoolPhotoTemplate) BuildSetter() *models.PublicreportPoolPhotoSetter {
|
|
m := &models.PublicreportPoolPhotoSetter{}
|
|
|
|
if o.ID != nil {
|
|
val := o.ID()
|
|
m.ID = omit.From(val)
|
|
}
|
|
if o.Size != nil {
|
|
val := o.Size()
|
|
m.Size = omit.From(val)
|
|
}
|
|
if o.Filename != nil {
|
|
val := o.Filename()
|
|
m.Filename = omit.From(val)
|
|
}
|
|
if o.PoolID != nil {
|
|
val := o.PoolID()
|
|
m.PoolID = omit.From(val)
|
|
}
|
|
if o.UUID != nil {
|
|
val := o.UUID()
|
|
m.UUID = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.PublicreportPoolPhotoSetter
|
|
// this does nothing with the relationship templates
|
|
func (o PublicreportPoolPhotoTemplate) BuildManySetter(number int) []*models.PublicreportPoolPhotoSetter {
|
|
m := make([]*models.PublicreportPoolPhotoSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.PublicreportPoolPhoto
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use PublicreportPoolPhotoTemplate.Create
|
|
func (o PublicreportPoolPhotoTemplate) Build() *models.PublicreportPoolPhoto {
|
|
m := &models.PublicreportPoolPhoto{}
|
|
|
|
if o.ID != nil {
|
|
m.ID = o.ID()
|
|
}
|
|
if o.Size != nil {
|
|
m.Size = o.Size()
|
|
}
|
|
if o.Filename != nil {
|
|
m.Filename = o.Filename()
|
|
}
|
|
if o.PoolID != nil {
|
|
m.PoolID = o.PoolID()
|
|
}
|
|
if o.UUID != nil {
|
|
m.UUID = o.UUID()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.PublicreportPoolPhotoSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use PublicreportPoolPhotoTemplate.CreateMany
|
|
func (o PublicreportPoolPhotoTemplate) BuildMany(number int) models.PublicreportPoolPhotoSlice {
|
|
m := make(models.PublicreportPoolPhotoSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatablePublicreportPoolPhoto(m *models.PublicreportPoolPhotoSetter) {
|
|
if !(m.Size.IsValue()) {
|
|
val := random_int64(nil)
|
|
m.Size = omit.From(val)
|
|
}
|
|
if !(m.Filename.IsValue()) {
|
|
val := random_string(nil)
|
|
m.Filename = omit.From(val)
|
|
}
|
|
if !(m.PoolID.IsValue()) {
|
|
val := random_int32(nil)
|
|
m.PoolID = omit.From(val)
|
|
}
|
|
if !(m.UUID.IsValue()) {
|
|
val := random_uuid_UUID(nil)
|
|
m.UUID = omit.From(val)
|
|
}
|
|
}
|
|
|
|
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportPoolPhoto
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *PublicreportPoolPhotoTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportPoolPhoto) error {
|
|
var err error
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a publicreportPoolPhoto and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *PublicreportPoolPhotoTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportPoolPhoto, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatablePublicreportPoolPhoto(opt)
|
|
|
|
if o.r.Pool == nil {
|
|
PublicreportPoolPhotoMods.WithNewPool().Apply(ctx, o)
|
|
}
|
|
|
|
var rel0 *models.PublicreportPool
|
|
|
|
if o.r.Pool.o.alreadyPersisted {
|
|
rel0 = o.r.Pool.o.Build()
|
|
} else {
|
|
rel0, err = o.r.Pool.o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
opt.PoolID = omit.From(rel0.ID)
|
|
|
|
m, err := models.PublicreportPoolPhotos.Insert(opt).One(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
m.R.Pool = rel0
|
|
|
|
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, err
|
|
}
|
|
|
|
// MustCreate builds a publicreportPoolPhoto and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *PublicreportPoolPhotoTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportPoolPhoto {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a publicreportPoolPhoto 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 *PublicreportPoolPhotoTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportPoolPhoto {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple publicreportPoolPhotos and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o PublicreportPoolPhotoTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportPoolPhotoSlice, error) {
|
|
var err error
|
|
m := make(models.PublicreportPoolPhotoSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple publicreportPoolPhotos and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o PublicreportPoolPhotoTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportPoolPhotoSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple publicreportPoolPhotos 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 PublicreportPoolPhotoTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportPoolPhotoSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// PublicreportPoolPhoto has methods that act as mods for the PublicreportPoolPhotoTemplate
|
|
var PublicreportPoolPhotoMods publicreportPoolPhotoMods
|
|
|
|
type publicreportPoolPhotoMods struct{}
|
|
|
|
func (m publicreportPoolPhotoMods) RandomizeAllColumns(f *faker.Faker) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModSlice{
|
|
PublicreportPoolPhotoMods.RandomID(f),
|
|
PublicreportPoolPhotoMods.RandomSize(f),
|
|
PublicreportPoolPhotoMods.RandomFilename(f),
|
|
PublicreportPoolPhotoMods.RandomPoolID(f),
|
|
PublicreportPoolPhotoMods.RandomUUID(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportPoolPhotoMods) ID(val int32) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.ID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportPoolPhotoMods) IDFunc(f func() int32) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.ID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportPoolPhotoMods) UnsetID() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.ID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m publicreportPoolPhotoMods) RandomID(f *faker.Faker) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.ID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportPoolPhotoMods) Size(val int64) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Size = func() int64 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportPoolPhotoMods) SizeFunc(f func() int64) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Size = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportPoolPhotoMods) UnsetSize() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Size = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m publicreportPoolPhotoMods) RandomSize(f *faker.Faker) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Size = func() int64 {
|
|
return random_int64(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportPoolPhotoMods) Filename(val string) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Filename = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportPoolPhotoMods) FilenameFunc(f func() string) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Filename = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportPoolPhotoMods) UnsetFilename() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Filename = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m publicreportPoolPhotoMods) RandomFilename(f *faker.Faker) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.Filename = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportPoolPhotoMods) PoolID(val int32) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.PoolID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportPoolPhotoMods) PoolIDFunc(f func() int32) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.PoolID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportPoolPhotoMods) UnsetPoolID() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.PoolID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m publicreportPoolPhotoMods) RandomPoolID(f *faker.Faker) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.PoolID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportPoolPhotoMods) UUID(val uuid.UUID) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.UUID = func() uuid.UUID { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportPoolPhotoMods) UUIDFunc(f func() uuid.UUID) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.UUID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportPoolPhotoMods) UnsetUUID() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.UUID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m publicreportPoolPhotoMods) RandomUUID(f *faker.Faker) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(_ context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.UUID = func() uuid.UUID {
|
|
return random_uuid_UUID(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportPoolPhotoMods) WithParentsCascading() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
if isDone, _ := publicreportPoolPhotoWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = publicreportPoolPhotoWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewPublicreportPoolWithContext(ctx, PublicreportPoolMods.WithParentsCascading())
|
|
m.WithPool(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportPoolPhotoMods) WithPool(rel *PublicreportPoolTemplate) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.r.Pool = &publicreportPoolPhotoRPoolR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportPoolPhotoMods) WithNewPool(mods ...PublicreportPoolMod) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
|
|
|
|
m.WithPool(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m publicreportPoolPhotoMods) WithExistingPool(em *models.PublicreportPool) PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.r.Pool = &publicreportPoolPhotoRPoolR{
|
|
o: o.f.FromExistingPublicreportPool(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportPoolPhotoMods) WithoutPool() PublicreportPoolPhotoMod {
|
|
return PublicreportPoolPhotoModFunc(func(ctx context.Context, o *PublicreportPoolPhotoTemplate) {
|
|
o.r.Pool = nil
|
|
})
|
|
}
|