nidus-sync/db/factory/site.bob.go

1361 lines
35 KiB
Go

// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type SiteMod interface {
Apply(context.Context, *SiteTemplate)
}
type SiteModFunc func(context.Context, *SiteTemplate)
func (f SiteModFunc) Apply(ctx context.Context, n *SiteTemplate) {
f(ctx, n)
}
type SiteModSlice []SiteMod
func (mods SiteModSlice) Apply(ctx context.Context, n *SiteTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// SiteTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type SiteTemplate struct {
AddressID func() int32
Created func() time.Time
CreatorID func() int32
FileID func() null.Val[int32]
ID func() int32
Notes func() string
OrganizationID func() int32
OwnerName func() string
OwnerPhoneE164 func() null.Val[string]
ParcelID func() int32
ResidentOwned func() null.Val[bool]
Tags func() pgtypes.HStore
Version func() int32
r siteR
f *Factory
alreadyPersisted bool
}
type siteR struct {
ComplianceReportRequests []*siteRComplianceReportRequestsR
Pools []*siteRPoolsR
Residents []*siteRResidentsR
Address *siteRAddressR
CreatorUser *siteRCreatorUserR
File *siteRFileR
Parcel *siteRParcelR
}
type siteRComplianceReportRequestsR struct {
number int
o *ComplianceReportRequestTemplate
}
type siteRPoolsR struct {
number int
o *PoolTemplate
}
type siteRResidentsR struct {
number int
o *ResidentTemplate
}
type siteRAddressR struct {
o *AddressTemplate
}
type siteRCreatorUserR struct {
o *UserTemplate
}
type siteRFileR struct {
o *FileuploadFileTemplate
}
type siteRParcelR struct {
o *ParcelTemplate
}
// Apply mods to the SiteTemplate
func (o *SiteTemplate) Apply(ctx context.Context, mods ...SiteMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.Site
// according to the relationships in the template. Nothing is inserted into the db
func (t SiteTemplate) setModelRels(o *models.Site) {
if t.r.ComplianceReportRequests != nil {
rel := models.ComplianceReportRequestSlice{}
for _, r := range t.r.ComplianceReportRequests {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.SiteID = o.ID // h2
rel.SiteVersion = o.Version // h2
rel.R.Site = o
}
rel = append(rel, related...)
}
o.R.ComplianceReportRequests = rel
}
if t.r.Pools != nil {
rel := models.PoolSlice{}
for _, r := range t.r.Pools {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.SiteID = o.ID // h2
rel.SiteVersion = o.Version // h2
rel.R.Site = o
}
rel = append(rel, related...)
}
o.R.Pools = rel
}
if t.r.Residents != nil {
rel := models.ResidentSlice{}
for _, r := range t.r.Residents {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.SiteID = o.ID // h2
rel.SiteVersion = o.Version // h2
rel.R.Site = o
}
rel = append(rel, related...)
}
o.R.Residents = rel
}
if t.r.Address != nil {
rel := t.r.Address.o.Build()
rel.R.Site = o
o.AddressID = rel.ID // h2
o.R.Address = rel
}
if t.r.CreatorUser != nil {
rel := t.r.CreatorUser.o.Build()
rel.R.CreatorSites = append(rel.R.CreatorSites, o)
o.CreatorID = rel.ID // h2
o.R.CreatorUser = rel
}
if t.r.File != nil {
rel := t.r.File.o.Build()
rel.R.Sites = append(rel.R.Sites, o)
o.FileID = null.From(rel.ID) // h2
o.R.File = rel
}
if t.r.Parcel != nil {
rel := t.r.Parcel.o.Build()
rel.R.Sites = append(rel.R.Sites, o)
o.ParcelID = rel.ID // h2
o.R.Parcel = rel
}
}
// BuildSetter returns an *models.SiteSetter
// this does nothing with the relationship templates
func (o SiteTemplate) BuildSetter() *models.SiteSetter {
m := &models.SiteSetter{}
if o.AddressID != nil {
val := o.AddressID()
m.AddressID = omit.From(val)
}
if o.Created != nil {
val := o.Created()
m.Created = omit.From(val)
}
if o.CreatorID != nil {
val := o.CreatorID()
m.CreatorID = omit.From(val)
}
if o.FileID != nil {
val := o.FileID()
m.FileID = omitnull.FromNull(val)
}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.Notes != nil {
val := o.Notes()
m.Notes = omit.From(val)
}
if o.OrganizationID != nil {
val := o.OrganizationID()
m.OrganizationID = omit.From(val)
}
if o.OwnerName != nil {
val := o.OwnerName()
m.OwnerName = omit.From(val)
}
if o.OwnerPhoneE164 != nil {
val := o.OwnerPhoneE164()
m.OwnerPhoneE164 = omitnull.FromNull(val)
}
if o.ParcelID != nil {
val := o.ParcelID()
m.ParcelID = omit.From(val)
}
if o.ResidentOwned != nil {
val := o.ResidentOwned()
m.ResidentOwned = omitnull.FromNull(val)
}
if o.Tags != nil {
val := o.Tags()
m.Tags = omit.From(val)
}
if o.Version != nil {
val := o.Version()
m.Version = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.SiteSetter
// this does nothing with the relationship templates
func (o SiteTemplate) BuildManySetter(number int) []*models.SiteSetter {
m := make([]*models.SiteSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.Site
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use SiteTemplate.Create
func (o SiteTemplate) Build() *models.Site {
m := &models.Site{}
if o.AddressID != nil {
m.AddressID = o.AddressID()
}
if o.Created != nil {
m.Created = o.Created()
}
if o.CreatorID != nil {
m.CreatorID = o.CreatorID()
}
if o.FileID != nil {
m.FileID = o.FileID()
}
if o.ID != nil {
m.ID = o.ID()
}
if o.Notes != nil {
m.Notes = o.Notes()
}
if o.OrganizationID != nil {
m.OrganizationID = o.OrganizationID()
}
if o.OwnerName != nil {
m.OwnerName = o.OwnerName()
}
if o.OwnerPhoneE164 != nil {
m.OwnerPhoneE164 = o.OwnerPhoneE164()
}
if o.ParcelID != nil {
m.ParcelID = o.ParcelID()
}
if o.ResidentOwned != nil {
m.ResidentOwned = o.ResidentOwned()
}
if o.Tags != nil {
m.Tags = o.Tags()
}
if o.Version != nil {
m.Version = o.Version()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.SiteSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use SiteTemplate.CreateMany
func (o SiteTemplate) BuildMany(number int) models.SiteSlice {
m := make(models.SiteSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableSite(m *models.SiteSetter) {
if !(m.AddressID.IsValue()) {
val := random_int32(nil)
m.AddressID = omit.From(val)
}
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.CreatorID.IsValue()) {
val := random_int32(nil)
m.CreatorID = omit.From(val)
}
if !(m.Notes.IsValue()) {
val := random_string(nil)
m.Notes = omit.From(val)
}
if !(m.OrganizationID.IsValue()) {
val := random_int32(nil)
m.OrganizationID = omit.From(val)
}
if !(m.OwnerName.IsValue()) {
val := random_string(nil)
m.OwnerName = omit.From(val)
}
if !(m.ParcelID.IsValue()) {
val := random_int32(nil)
m.ParcelID = omit.From(val)
}
if !(m.Tags.IsValue()) {
val := random_pgtypes_HStore(nil)
m.Tags = omit.From(val)
}
if !(m.Version.IsValue()) {
val := random_int32(nil)
m.Version = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.Site
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *SiteTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Site) error {
var err error
isComplianceReportRequestsDone, _ := siteRelComplianceReportRequestsCtx.Value(ctx)
if !isComplianceReportRequestsDone && o.r.ComplianceReportRequests != nil {
ctx = siteRelComplianceReportRequestsCtx.WithValue(ctx, true)
for _, r := range o.r.ComplianceReportRequests {
if r.o.alreadyPersisted {
m.R.ComplianceReportRequests = append(m.R.ComplianceReportRequests, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachComplianceReportRequests(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isPoolsDone, _ := siteRelPoolsCtx.Value(ctx)
if !isPoolsDone && o.r.Pools != nil {
ctx = siteRelPoolsCtx.WithValue(ctx, true)
for _, r := range o.r.Pools {
if r.o.alreadyPersisted {
m.R.Pools = append(m.R.Pools, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachPools(ctx, exec, rel1...)
if err != nil {
return err
}
}
}
}
isResidentsDone, _ := siteRelResidentsCtx.Value(ctx)
if !isResidentsDone && o.r.Residents != nil {
ctx = siteRelResidentsCtx.WithValue(ctx, true)
for _, r := range o.r.Residents {
if r.o.alreadyPersisted {
m.R.Residents = append(m.R.Residents, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachResidents(ctx, exec, rel2...)
if err != nil {
return err
}
}
}
}
isFileDone, _ := siteRelFileCtx.Value(ctx)
if !isFileDone && o.r.File != nil {
ctx = siteRelFileCtx.WithValue(ctx, true)
if o.r.File.o.alreadyPersisted {
m.R.File = o.r.File.o.Build()
} else {
var rel5 *models.FileuploadFile
rel5, err = o.r.File.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachFile(ctx, exec, rel5)
if err != nil {
return err
}
}
}
return err
}
// Create builds a site and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *SiteTemplate) Create(ctx context.Context, exec bob.Executor) (*models.Site, error) {
var err error
opt := o.BuildSetter()
ensureCreatableSite(opt)
if o.r.Address == nil {
SiteMods.WithNewAddress().Apply(ctx, o)
}
var rel3 *models.Address
if o.r.Address.o.alreadyPersisted {
rel3 = o.r.Address.o.Build()
} else {
rel3, err = o.r.Address.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.AddressID = omit.From(rel3.ID)
if o.r.CreatorUser == nil {
SiteMods.WithNewCreatorUser().Apply(ctx, o)
}
var rel4 *models.User
if o.r.CreatorUser.o.alreadyPersisted {
rel4 = o.r.CreatorUser.o.Build()
} else {
rel4, err = o.r.CreatorUser.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.CreatorID = omit.From(rel4.ID)
if o.r.Parcel == nil {
SiteMods.WithNewParcel().Apply(ctx, o)
}
var rel6 *models.Parcel
if o.r.Parcel.o.alreadyPersisted {
rel6 = o.r.Parcel.o.Build()
} else {
rel6, err = o.r.Parcel.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.ParcelID = omit.From(rel6.ID)
m, err := models.Sites.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Address = rel3
m.R.CreatorUser = rel4
m.R.Parcel = rel6
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a site and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *SiteTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.Site {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a site 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 *SiteTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.Site {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple sites and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o SiteTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.SiteSlice, error) {
var err error
m := make(models.SiteSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple sites and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o SiteTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.SiteSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple sites 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 SiteTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.SiteSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// Site has methods that act as mods for the SiteTemplate
var SiteMods siteMods
type siteMods struct{}
func (m siteMods) RandomizeAllColumns(f *faker.Faker) SiteMod {
return SiteModSlice{
SiteMods.RandomAddressID(f),
SiteMods.RandomCreated(f),
SiteMods.RandomCreatorID(f),
SiteMods.RandomFileID(f),
SiteMods.RandomID(f),
SiteMods.RandomNotes(f),
SiteMods.RandomOrganizationID(f),
SiteMods.RandomOwnerName(f),
SiteMods.RandomOwnerPhoneE164(f),
SiteMods.RandomParcelID(f),
SiteMods.RandomResidentOwned(f),
SiteMods.RandomTags(f),
SiteMods.RandomVersion(f),
}
}
// Set the model columns to this value
func (m siteMods) AddressID(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.AddressID = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) AddressIDFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.AddressID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetAddressID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.AddressID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomAddressID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.AddressID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m siteMods) Created(val time.Time) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m siteMods) CreatedFunc(f func() time.Time) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m siteMods) UnsetCreated() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomCreated(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m siteMods) CreatorID(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.CreatorID = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) CreatorIDFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.CreatorID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetCreatorID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.CreatorID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomCreatorID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.CreatorID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m siteMods) FileID(val null.Val[int32]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.FileID = func() null.Val[int32] { return val }
})
}
// Set the Column from the function
func (m siteMods) FileIDFunc(f func() null.Val[int32]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.FileID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetFileID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.FileID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m siteMods) RandomFileID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.FileID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m siteMods) RandomFileIDNotNull(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.FileID = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m siteMods) ID(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) IDFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
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 siteMods) RandomID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m siteMods) Notes(val string) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Notes = func() string { return val }
})
}
// Set the Column from the function
func (m siteMods) NotesFunc(f func() string) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Notes = f
})
}
// Clear any values for the column
func (m siteMods) UnsetNotes() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Notes = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomNotes(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Notes = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m siteMods) OrganizationID(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OrganizationID = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) OrganizationIDFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OrganizationID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetOrganizationID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OrganizationID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomOrganizationID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OrganizationID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m siteMods) OwnerName(val string) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerName = func() string { return val }
})
}
// Set the Column from the function
func (m siteMods) OwnerNameFunc(f func() string) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerName = f
})
}
// Clear any values for the column
func (m siteMods) UnsetOwnerName() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerName = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomOwnerName(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerName = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m siteMods) OwnerPhoneE164(val null.Val[string]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerPhoneE164 = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m siteMods) OwnerPhoneE164Func(f func() null.Val[string]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerPhoneE164 = f
})
}
// Clear any values for the column
func (m siteMods) UnsetOwnerPhoneE164() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerPhoneE164 = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m siteMods) RandomOwnerPhoneE164(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerPhoneE164 = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m siteMods) RandomOwnerPhoneE164NotNull(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.OwnerPhoneE164 = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m siteMods) ParcelID(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) ParcelIDFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = f
})
}
// Clear any values for the column
func (m siteMods) UnsetParcelID() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomParcelID(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ParcelID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m siteMods) ResidentOwned(val null.Val[bool]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentOwned = func() null.Val[bool] { return val }
})
}
// Set the Column from the function
func (m siteMods) ResidentOwnedFunc(f func() null.Val[bool]) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentOwned = f
})
}
// Clear any values for the column
func (m siteMods) UnsetResidentOwned() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentOwned = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m siteMods) RandomResidentOwned(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentOwned = func() null.Val[bool] {
if f == nil {
f = &defaultFaker
}
val := random_bool(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m siteMods) RandomResidentOwnedNotNull(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.ResidentOwned = func() null.Val[bool] {
if f == nil {
f = &defaultFaker
}
val := random_bool(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m siteMods) Tags(val pgtypes.HStore) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Tags = func() pgtypes.HStore { return val }
})
}
// Set the Column from the function
func (m siteMods) TagsFunc(f func() pgtypes.HStore) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Tags = f
})
}
// Clear any values for the column
func (m siteMods) UnsetTags() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Tags = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m siteMods) RandomTags(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Tags = func() pgtypes.HStore {
return random_pgtypes_HStore(f)
}
})
}
// Set the model columns to this value
func (m siteMods) Version(val int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Version = func() int32 { return val }
})
}
// Set the Column from the function
func (m siteMods) VersionFunc(f func() int32) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Version = f
})
}
// Clear any values for the column
func (m siteMods) UnsetVersion() SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
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 siteMods) RandomVersion(f *faker.Faker) SiteMod {
return SiteModFunc(func(_ context.Context, o *SiteTemplate) {
o.Version = func() int32 {
return random_int32(f)
}
})
}
func (m siteMods) WithParentsCascading() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
if isDone, _ := siteWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = siteWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewAddressWithContext(ctx, AddressMods.WithParentsCascading())
m.WithAddress(related).Apply(ctx, o)
}
{
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithCreatorUser(related).Apply(ctx, o)
}
{
related := o.f.NewFileuploadFileWithContext(ctx, FileuploadFileMods.WithParentsCascading())
m.WithFile(related).Apply(ctx, o)
}
{
related := o.f.NewParcelWithContext(ctx, ParcelMods.WithParentsCascading())
m.WithParcel(related).Apply(ctx, o)
}
})
}
func (m siteMods) WithAddress(rel *AddressTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Address = &siteRAddressR{
o: rel,
}
})
}
func (m siteMods) WithNewAddress(mods ...AddressMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewAddressWithContext(ctx, mods...)
m.WithAddress(related).Apply(ctx, o)
})
}
func (m siteMods) WithExistingAddress(em *models.Address) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Address = &siteRAddressR{
o: o.f.FromExistingAddress(em),
}
})
}
func (m siteMods) WithoutAddress() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Address = nil
})
}
func (m siteMods) WithCreatorUser(rel *UserTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.CreatorUser = &siteRCreatorUserR{
o: rel,
}
})
}
func (m siteMods) WithNewCreatorUser(mods ...UserMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewUserWithContext(ctx, mods...)
m.WithCreatorUser(related).Apply(ctx, o)
})
}
func (m siteMods) WithExistingCreatorUser(em *models.User) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.CreatorUser = &siteRCreatorUserR{
o: o.f.FromExistingUser(em),
}
})
}
func (m siteMods) WithoutCreatorUser() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.CreatorUser = nil
})
}
func (m siteMods) WithFile(rel *FileuploadFileTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.File = &siteRFileR{
o: rel,
}
})
}
func (m siteMods) WithNewFile(mods ...FileuploadFileMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewFileuploadFileWithContext(ctx, mods...)
m.WithFile(related).Apply(ctx, o)
})
}
func (m siteMods) WithExistingFile(em *models.FileuploadFile) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.File = &siteRFileR{
o: o.f.FromExistingFileuploadFile(em),
}
})
}
func (m siteMods) WithoutFile() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.File = nil
})
}
func (m siteMods) WithParcel(rel *ParcelTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Parcel = &siteRParcelR{
o: rel,
}
})
}
func (m siteMods) WithNewParcel(mods ...ParcelMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewParcelWithContext(ctx, mods...)
m.WithParcel(related).Apply(ctx, o)
})
}
func (m siteMods) WithExistingParcel(em *models.Parcel) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Parcel = &siteRParcelR{
o: o.f.FromExistingParcel(em),
}
})
}
func (m siteMods) WithoutParcel() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Parcel = nil
})
}
func (m siteMods) WithComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.ComplianceReportRequests = []*siteRComplianceReportRequestsR{{
number: number,
o: related,
}}
})
}
func (m siteMods) WithNewComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
m.WithComplianceReportRequests(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddComplianceReportRequests(number int, related *ComplianceReportRequestTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.ComplianceReportRequests = append(o.r.ComplianceReportRequests, &siteRComplianceReportRequestsR{
number: number,
o: related,
})
})
}
func (m siteMods) AddNewComplianceReportRequests(number int, mods ...ComplianceReportRequestMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewComplianceReportRequestWithContext(ctx, mods...)
m.AddComplianceReportRequests(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddExistingComplianceReportRequests(existingModels ...*models.ComplianceReportRequest) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
for _, em := range existingModels {
o.r.ComplianceReportRequests = append(o.r.ComplianceReportRequests, &siteRComplianceReportRequestsR{
o: o.f.FromExistingComplianceReportRequest(em),
})
}
})
}
func (m siteMods) WithoutComplianceReportRequests() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.ComplianceReportRequests = nil
})
}
func (m siteMods) WithPools(number int, related *PoolTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Pools = []*siteRPoolsR{{
number: number,
o: related,
}}
})
}
func (m siteMods) WithNewPools(number int, mods ...PoolMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewPoolWithContext(ctx, mods...)
m.WithPools(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddPools(number int, related *PoolTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Pools = append(o.r.Pools, &siteRPoolsR{
number: number,
o: related,
})
})
}
func (m siteMods) AddNewPools(number int, mods ...PoolMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewPoolWithContext(ctx, mods...)
m.AddPools(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddExistingPools(existingModels ...*models.Pool) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
for _, em := range existingModels {
o.r.Pools = append(o.r.Pools, &siteRPoolsR{
o: o.f.FromExistingPool(em),
})
}
})
}
func (m siteMods) WithoutPools() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Pools = nil
})
}
func (m siteMods) WithResidents(number int, related *ResidentTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Residents = []*siteRResidentsR{{
number: number,
o: related,
}}
})
}
func (m siteMods) WithNewResidents(number int, mods ...ResidentMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.WithResidents(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddResidents(number int, related *ResidentTemplate) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Residents = append(o.r.Residents, &siteRResidentsR{
number: number,
o: related,
})
})
}
func (m siteMods) AddNewResidents(number int, mods ...ResidentMod) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
related := o.f.NewResidentWithContext(ctx, mods...)
m.AddResidents(number, related).Apply(ctx, o)
})
}
func (m siteMods) AddExistingResidents(existingModels ...*models.Resident) SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
for _, em := range existingModels {
o.r.Residents = append(o.r.Residents, &siteRResidentsR{
o: o.f.FromExistingResident(em),
})
}
})
}
func (m siteMods) WithoutResidents() SiteMod {
return SiteModFunc(func(ctx context.Context, o *SiteTemplate) {
o.r.Residents = nil
})
}