498 lines
16 KiB
Go
498 lines
16 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 PublicreportQuickPhotoMod interface {
|
|
Apply(context.Context, *PublicreportQuickPhotoTemplate)
|
|
}
|
|
|
|
type PublicreportQuickPhotoModFunc func(context.Context, *PublicreportQuickPhotoTemplate)
|
|
|
|
func (f PublicreportQuickPhotoModFunc) Apply(ctx context.Context, n *PublicreportQuickPhotoTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type PublicreportQuickPhotoModSlice []PublicreportQuickPhotoMod
|
|
|
|
func (mods PublicreportQuickPhotoModSlice) Apply(ctx context.Context, n *PublicreportQuickPhotoTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// PublicreportQuickPhotoTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type PublicreportQuickPhotoTemplate struct {
|
|
ID func() int32
|
|
Size func() int64
|
|
Filename func() string
|
|
QuickID func() int32
|
|
UUID func() uuid.UUID
|
|
|
|
r publicreportQuickPhotoR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type publicreportQuickPhotoR struct {
|
|
Quick *publicreportQuickPhotoRQuickR
|
|
}
|
|
|
|
type publicreportQuickPhotoRQuickR struct {
|
|
o *PublicreportQuickTemplate
|
|
}
|
|
|
|
// Apply mods to the PublicreportQuickPhotoTemplate
|
|
func (o *PublicreportQuickPhotoTemplate) Apply(ctx context.Context, mods ...PublicreportQuickPhotoMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.PublicreportQuickPhoto
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t PublicreportQuickPhotoTemplate) setModelRels(o *models.PublicreportQuickPhoto) {
|
|
if t.r.Quick != nil {
|
|
rel := t.r.Quick.o.Build()
|
|
rel.R.QuickPhotos = append(rel.R.QuickPhotos, o)
|
|
o.QuickID = rel.ID // h2
|
|
o.R.Quick = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.PublicreportQuickPhotoSetter
|
|
// this does nothing with the relationship templates
|
|
func (o PublicreportQuickPhotoTemplate) BuildSetter() *models.PublicreportQuickPhotoSetter {
|
|
m := &models.PublicreportQuickPhotoSetter{}
|
|
|
|
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.QuickID != nil {
|
|
val := o.QuickID()
|
|
m.QuickID = omit.From(val)
|
|
}
|
|
if o.UUID != nil {
|
|
val := o.UUID()
|
|
m.UUID = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.PublicreportQuickPhotoSetter
|
|
// this does nothing with the relationship templates
|
|
func (o PublicreportQuickPhotoTemplate) BuildManySetter(number int) []*models.PublicreportQuickPhotoSetter {
|
|
m := make([]*models.PublicreportQuickPhotoSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.PublicreportQuickPhoto
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use PublicreportQuickPhotoTemplate.Create
|
|
func (o PublicreportQuickPhotoTemplate) Build() *models.PublicreportQuickPhoto {
|
|
m := &models.PublicreportQuickPhoto{}
|
|
|
|
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.QuickID != nil {
|
|
m.QuickID = o.QuickID()
|
|
}
|
|
if o.UUID != nil {
|
|
m.UUID = o.UUID()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.PublicreportQuickPhotoSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use PublicreportQuickPhotoTemplate.CreateMany
|
|
func (o PublicreportQuickPhotoTemplate) BuildMany(number int) models.PublicreportQuickPhotoSlice {
|
|
m := make(models.PublicreportQuickPhotoSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatablePublicreportQuickPhoto(m *models.PublicreportQuickPhotoSetter) {
|
|
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.QuickID.IsValue()) {
|
|
val := random_int32(nil)
|
|
m.QuickID = 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.PublicreportQuickPhoto
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *PublicreportQuickPhotoTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportQuickPhoto) error {
|
|
var err error
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a publicreportQuickPhoto and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *PublicreportQuickPhotoTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportQuickPhoto, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatablePublicreportQuickPhoto(opt)
|
|
|
|
if o.r.Quick == nil {
|
|
PublicreportQuickPhotoMods.WithNewQuick().Apply(ctx, o)
|
|
}
|
|
|
|
var rel0 *models.PublicreportQuick
|
|
|
|
if o.r.Quick.o.alreadyPersisted {
|
|
rel0 = o.r.Quick.o.Build()
|
|
} else {
|
|
rel0, err = o.r.Quick.o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
opt.QuickID = omit.From(rel0.ID)
|
|
|
|
m, err := models.PublicreportQuickPhotos.Insert(opt).One(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
m.R.Quick = rel0
|
|
|
|
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, err
|
|
}
|
|
|
|
// MustCreate builds a publicreportQuickPhoto and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *PublicreportQuickPhotoTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportQuickPhoto {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a publicreportQuickPhoto 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 *PublicreportQuickPhotoTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportQuickPhoto {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple publicreportQuickPhotos and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o PublicreportQuickPhotoTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportQuickPhotoSlice, error) {
|
|
var err error
|
|
m := make(models.PublicreportQuickPhotoSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple publicreportQuickPhotos and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o PublicreportQuickPhotoTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportQuickPhotoSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple publicreportQuickPhotos 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 PublicreportQuickPhotoTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportQuickPhotoSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// PublicreportQuickPhoto has methods that act as mods for the PublicreportQuickPhotoTemplate
|
|
var PublicreportQuickPhotoMods publicreportQuickPhotoMods
|
|
|
|
type publicreportQuickPhotoMods struct{}
|
|
|
|
func (m publicreportQuickPhotoMods) RandomizeAllColumns(f *faker.Faker) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModSlice{
|
|
PublicreportQuickPhotoMods.RandomID(f),
|
|
PublicreportQuickPhotoMods.RandomSize(f),
|
|
PublicreportQuickPhotoMods.RandomFilename(f),
|
|
PublicreportQuickPhotoMods.RandomQuickID(f),
|
|
PublicreportQuickPhotoMods.RandomUUID(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportQuickPhotoMods) ID(val int32) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.ID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportQuickPhotoMods) IDFunc(f func() int32) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.ID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportQuickPhotoMods) UnsetID() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
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 publicreportQuickPhotoMods) RandomID(f *faker.Faker) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.ID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportQuickPhotoMods) Size(val int64) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.Size = func() int64 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportQuickPhotoMods) SizeFunc(f func() int64) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.Size = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportQuickPhotoMods) UnsetSize() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
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 publicreportQuickPhotoMods) RandomSize(f *faker.Faker) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.Size = func() int64 {
|
|
return random_int64(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportQuickPhotoMods) Filename(val string) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.Filename = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportQuickPhotoMods) FilenameFunc(f func() string) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.Filename = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportQuickPhotoMods) UnsetFilename() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
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 publicreportQuickPhotoMods) RandomFilename(f *faker.Faker) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.Filename = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportQuickPhotoMods) QuickID(val int32) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.QuickID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportQuickPhotoMods) QuickIDFunc(f func() int32) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.QuickID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportQuickPhotoMods) UnsetQuickID() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.QuickID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m publicreportQuickPhotoMods) RandomQuickID(f *faker.Faker) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.QuickID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m publicreportQuickPhotoMods) UUID(val uuid.UUID) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.UUID = func() uuid.UUID { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m publicreportQuickPhotoMods) UUIDFunc(f func() uuid.UUID) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.UUID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m publicreportQuickPhotoMods) UnsetUUID() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
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 publicreportQuickPhotoMods) RandomUUID(f *faker.Faker) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(_ context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.UUID = func() uuid.UUID {
|
|
return random_uuid_UUID(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportQuickPhotoMods) WithParentsCascading() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
if isDone, _ := publicreportQuickPhotoWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = publicreportQuickPhotoWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewPublicreportQuickWithContext(ctx, PublicreportQuickMods.WithParentsCascading())
|
|
m.WithQuick(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportQuickPhotoMods) WithQuick(rel *PublicreportQuickTemplate) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.r.Quick = &publicreportQuickPhotoRQuickR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportQuickPhotoMods) WithNewQuick(mods ...PublicreportQuickMod) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
related := o.f.NewPublicreportQuickWithContext(ctx, mods...)
|
|
|
|
m.WithQuick(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m publicreportQuickPhotoMods) WithExistingQuick(em *models.PublicreportQuick) PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.r.Quick = &publicreportQuickPhotoRQuickR{
|
|
o: o.f.FromExistingPublicreportQuick(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m publicreportQuickPhotoMods) WithoutQuick() PublicreportQuickPhotoMod {
|
|
return PublicreportQuickPhotoModFunc(func(ctx context.Context, o *PublicreportQuickPhotoTemplate) {
|
|
o.r.Quick = nil
|
|
})
|
|
}
|