370 lines
10 KiB
Go
370 lines
10 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"
|
|
|
|
"github.com/Gleipnir-Technology/bob"
|
|
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/jaswdr/faker/v2"
|
|
)
|
|
|
|
type FileuploadCSVMod interface {
|
|
Apply(context.Context, *FileuploadCSVTemplate)
|
|
}
|
|
|
|
type FileuploadCSVModFunc func(context.Context, *FileuploadCSVTemplate)
|
|
|
|
func (f FileuploadCSVModFunc) Apply(ctx context.Context, n *FileuploadCSVTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type FileuploadCSVModSlice []FileuploadCSVMod
|
|
|
|
func (mods FileuploadCSVModSlice) Apply(ctx context.Context, n *FileuploadCSVTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// FileuploadCSVTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type FileuploadCSVTemplate struct {
|
|
FileID func() int32
|
|
Type func() enums.FileuploadCsvtype
|
|
|
|
r fileuploadCSVR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type fileuploadCSVR struct {
|
|
File *fileuploadCSVRFileR
|
|
}
|
|
|
|
type fileuploadCSVRFileR struct {
|
|
o *FileuploadFileTemplate
|
|
}
|
|
|
|
// Apply mods to the FileuploadCSVTemplate
|
|
func (o *FileuploadCSVTemplate) Apply(ctx context.Context, mods ...FileuploadCSVMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.FileuploadCSV
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t FileuploadCSVTemplate) setModelRels(o *models.FileuploadCSV) {
|
|
if t.r.File != nil {
|
|
rel := t.r.File.o.Build()
|
|
rel.R.CSV = o
|
|
o.FileID = rel.ID // h2
|
|
o.R.File = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.FileuploadCSVSetter
|
|
// this does nothing with the relationship templates
|
|
func (o FileuploadCSVTemplate) BuildSetter() *models.FileuploadCSVSetter {
|
|
m := &models.FileuploadCSVSetter{}
|
|
|
|
if o.FileID != nil {
|
|
val := o.FileID()
|
|
m.FileID = omit.From(val)
|
|
}
|
|
if o.Type != nil {
|
|
val := o.Type()
|
|
m.Type = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.FileuploadCSVSetter
|
|
// this does nothing with the relationship templates
|
|
func (o FileuploadCSVTemplate) BuildManySetter(number int) []*models.FileuploadCSVSetter {
|
|
m := make([]*models.FileuploadCSVSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.FileuploadCSV
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use FileuploadCSVTemplate.Create
|
|
func (o FileuploadCSVTemplate) Build() *models.FileuploadCSV {
|
|
m := &models.FileuploadCSV{}
|
|
|
|
if o.FileID != nil {
|
|
m.FileID = o.FileID()
|
|
}
|
|
if o.Type != nil {
|
|
m.Type = o.Type()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.FileuploadCSVSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use FileuploadCSVTemplate.CreateMany
|
|
func (o FileuploadCSVTemplate) BuildMany(number int) models.FileuploadCSVSlice {
|
|
m := make(models.FileuploadCSVSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatableFileuploadCSV(m *models.FileuploadCSVSetter) {
|
|
if !(m.FileID.IsValue()) {
|
|
val := random_int32(nil)
|
|
m.FileID = omit.From(val)
|
|
}
|
|
if !(m.Type.IsValue()) {
|
|
val := random_enums_FileuploadCsvtype(nil)
|
|
m.Type = omit.From(val)
|
|
}
|
|
}
|
|
|
|
// insertOptRels creates and inserts any optional the relationships on *models.FileuploadCSV
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *FileuploadCSVTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.FileuploadCSV) error {
|
|
var err error
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a fileuploadCSV and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *FileuploadCSVTemplate) Create(ctx context.Context, exec bob.Executor) (*models.FileuploadCSV, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatableFileuploadCSV(opt)
|
|
|
|
if o.r.File == nil {
|
|
FileuploadCSVMods.WithNewFile().Apply(ctx, o)
|
|
}
|
|
|
|
var rel0 *models.FileuploadFile
|
|
|
|
if o.r.File.o.alreadyPersisted {
|
|
rel0 = o.r.File.o.Build()
|
|
} else {
|
|
rel0, err = o.r.File.o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
opt.FileID = omit.From(rel0.ID)
|
|
|
|
m, err := models.FileuploadCSVS.Insert(opt).One(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
m.R.File = rel0
|
|
|
|
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, err
|
|
}
|
|
|
|
// MustCreate builds a fileuploadCSV and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *FileuploadCSVTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.FileuploadCSV {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a fileuploadCSV 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 *FileuploadCSVTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.FileuploadCSV {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple fileuploadCSVS and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o FileuploadCSVTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.FileuploadCSVSlice, error) {
|
|
var err error
|
|
m := make(models.FileuploadCSVSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple fileuploadCSVS and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o FileuploadCSVTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.FileuploadCSVSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple fileuploadCSVS 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 FileuploadCSVTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.FileuploadCSVSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// FileuploadCSV has methods that act as mods for the FileuploadCSVTemplate
|
|
var FileuploadCSVMods fileuploadCSVMods
|
|
|
|
type fileuploadCSVMods struct{}
|
|
|
|
func (m fileuploadCSVMods) RandomizeAllColumns(f *faker.Faker) FileuploadCSVMod {
|
|
return FileuploadCSVModSlice{
|
|
FileuploadCSVMods.RandomFileID(f),
|
|
FileuploadCSVMods.RandomType(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadCSVMods) FileID(val int32) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.FileID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadCSVMods) FileIDFunc(f func() int32) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.FileID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadCSVMods) UnsetFileID() FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.FileID = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m fileuploadCSVMods) RandomFileID(f *faker.Faker) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.FileID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadCSVMods) Type(val enums.FileuploadCsvtype) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.Type = func() enums.FileuploadCsvtype { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadCSVMods) TypeFunc(f func() enums.FileuploadCsvtype) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.Type = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadCSVMods) UnsetType() FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.Type = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m fileuploadCSVMods) RandomType(f *faker.Faker) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(_ context.Context, o *FileuploadCSVTemplate) {
|
|
o.Type = func() enums.FileuploadCsvtype {
|
|
return random_enums_FileuploadCsvtype(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadCSVMods) WithParentsCascading() FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) {
|
|
if isDone, _ := fileuploadCSVWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = fileuploadCSVWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewFileuploadFileWithContext(ctx, FileuploadFileMods.WithParentsCascading())
|
|
m.WithFile(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadCSVMods) WithFile(rel *FileuploadFileTemplate) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) {
|
|
o.r.File = &fileuploadCSVRFileR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadCSVMods) WithNewFile(mods ...FileuploadFileMod) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) {
|
|
related := o.f.NewFileuploadFileWithContext(ctx, mods...)
|
|
|
|
m.WithFile(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m fileuploadCSVMods) WithExistingFile(em *models.FileuploadFile) FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) {
|
|
o.r.File = &fileuploadCSVRFileR{
|
|
o: o.f.FromExistingFileuploadFile(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadCSVMods) WithoutFile() FileuploadCSVMod {
|
|
return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) {
|
|
o.r.File = nil
|
|
})
|
|
}
|