262 lines
6.8 KiB
Go
262 lines
6.8 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"
|
|
|
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
"github.com/jaswdr/faker/v2"
|
|
)
|
|
|
|
type SignalPoolMod interface {
|
|
Apply(context.Context, *SignalPoolTemplate)
|
|
}
|
|
|
|
type SignalPoolModFunc func(context.Context, *SignalPoolTemplate)
|
|
|
|
func (f SignalPoolModFunc) Apply(ctx context.Context, n *SignalPoolTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type SignalPoolModSlice []SignalPoolMod
|
|
|
|
func (mods SignalPoolModSlice) Apply(ctx context.Context, n *SignalPoolTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// SignalPoolTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type SignalPoolTemplate struct {
|
|
PoolID func() int32
|
|
SignalID func() int32
|
|
|
|
r signalPoolR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type signalPoolR struct {
|
|
Pool *signalPoolRPoolR
|
|
Signal *signalPoolRSignalR
|
|
}
|
|
|
|
type signalPoolRPoolR struct {
|
|
o *PoolTemplate
|
|
}
|
|
type signalPoolRSignalR struct {
|
|
o *SignalTemplate
|
|
}
|
|
|
|
// Apply mods to the SignalPoolTemplate
|
|
func (o *SignalPoolTemplate) Apply(ctx context.Context, mods ...SignalPoolMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.SignalPool
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t SignalPoolTemplate) setModelRels(o *models.SignalPool) {
|
|
if t.r.Pool != nil {
|
|
rel := t.r.Pool.o.Build()
|
|
rel.R.SignalPools = append(rel.R.SignalPools, o)
|
|
o.PoolID = rel.ID // h2
|
|
o.R.Pool = rel
|
|
}
|
|
|
|
if t.r.Signal != nil {
|
|
rel := t.r.Signal.o.Build()
|
|
rel.R.SignalPools = append(rel.R.SignalPools, o)
|
|
o.SignalID = rel.ID // h2
|
|
o.R.Signal = rel
|
|
}
|
|
}
|
|
|
|
// Build returns an *models.SignalPool
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use SignalPoolTemplate.Create
|
|
func (o SignalPoolTemplate) Build() *models.SignalPool {
|
|
m := &models.SignalPool{}
|
|
|
|
if o.PoolID != nil {
|
|
m.PoolID = o.PoolID()
|
|
}
|
|
if o.SignalID != nil {
|
|
m.SignalID = o.SignalID()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.SignalPoolSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use SignalPoolTemplate.CreateMany
|
|
func (o SignalPoolTemplate) BuildMany(number int) models.SignalPoolSlice {
|
|
m := make(models.SignalPoolSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// SignalPool has methods that act as mods for the SignalPoolTemplate
|
|
var SignalPoolMods signalPoolMods
|
|
|
|
type signalPoolMods struct{}
|
|
|
|
func (m signalPoolMods) RandomizeAllColumns(f *faker.Faker) SignalPoolMod {
|
|
return SignalPoolModSlice{
|
|
SignalPoolMods.RandomPoolID(f),
|
|
SignalPoolMods.RandomSignalID(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m signalPoolMods) PoolID(val int32) SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.PoolID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m signalPoolMods) PoolIDFunc(f func() int32) SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.PoolID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m signalPoolMods) UnsetPoolID() SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
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 signalPoolMods) RandomPoolID(f *faker.Faker) SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.PoolID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m signalPoolMods) SignalID(val int32) SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.SignalID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m signalPoolMods) SignalIDFunc(f func() int32) SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.SignalID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m signalPoolMods) UnsetSignalID() SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.SignalID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m signalPoolMods) RandomSignalID(f *faker.Faker) SignalPoolMod {
|
|
return SignalPoolModFunc(func(_ context.Context, o *SignalPoolTemplate) {
|
|
o.SignalID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithParentsCascading() SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
if isDone, _ := signalPoolWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = signalPoolWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewPoolWithContext(ctx, PoolMods.WithParentsCascading())
|
|
m.WithPool(related).Apply(ctx, o)
|
|
}
|
|
{
|
|
|
|
related := o.f.NewSignalWithContext(ctx, SignalMods.WithParentsCascading())
|
|
m.WithSignal(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithPool(rel *PoolTemplate) SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
o.r.Pool = &signalPoolRPoolR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithNewPool(mods ...PoolMod) SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
related := o.f.NewPoolWithContext(ctx, mods...)
|
|
|
|
m.WithPool(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithExistingPool(em *models.Pool) SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
o.r.Pool = &signalPoolRPoolR{
|
|
o: o.f.FromExistingPool(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithoutPool() SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
o.r.Pool = nil
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithSignal(rel *SignalTemplate) SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
o.r.Signal = &signalPoolRSignalR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithNewSignal(mods ...SignalMod) SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
related := o.f.NewSignalWithContext(ctx, mods...)
|
|
|
|
m.WithSignal(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithExistingSignal(em *models.Signal) SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
o.r.Signal = &signalPoolRSignalR{
|
|
o: o.f.FromExistingSignal(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m signalPoolMods) WithoutSignal() SignalPoolMod {
|
|
return SignalPoolModFunc(func(ctx context.Context, o *SignalPoolTemplate) {
|
|
o.r.Signal = nil
|
|
})
|
|
}
|