409 lines
12 KiB
Go
409 lines
12 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"
|
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/jaswdr/faker/v2"
|
|
)
|
|
|
|
type FileuploadErrorFileMod interface {
|
|
Apply(context.Context, *FileuploadErrorFileTemplate)
|
|
}
|
|
|
|
type FileuploadErrorFileModFunc func(context.Context, *FileuploadErrorFileTemplate)
|
|
|
|
func (f FileuploadErrorFileModFunc) Apply(ctx context.Context, n *FileuploadErrorFileTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type FileuploadErrorFileModSlice []FileuploadErrorFileMod
|
|
|
|
func (mods FileuploadErrorFileModSlice) Apply(ctx context.Context, n *FileuploadErrorFileTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// FileuploadErrorFileTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type FileuploadErrorFileTemplate struct {
|
|
FileID func() int32
|
|
ID func() int32
|
|
Message func() string
|
|
|
|
r fileuploadErrorFileR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type fileuploadErrorFileR struct {
|
|
File *fileuploadErrorFileRFileR
|
|
}
|
|
|
|
type fileuploadErrorFileRFileR struct {
|
|
o *FileuploadFileTemplate
|
|
}
|
|
|
|
// Apply mods to the FileuploadErrorFileTemplate
|
|
func (o *FileuploadErrorFileTemplate) Apply(ctx context.Context, mods ...FileuploadErrorFileMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.FileuploadErrorFile
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t FileuploadErrorFileTemplate) setModelRels(o *models.FileuploadErrorFile) {
|
|
if t.r.File != nil {
|
|
rel := t.r.File.o.Build()
|
|
rel.R.ErrorFiles = append(rel.R.ErrorFiles, o)
|
|
o.FileID = rel.ID // h2
|
|
o.R.File = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.FileuploadErrorFileSetter
|
|
// this does nothing with the relationship templates
|
|
func (o FileuploadErrorFileTemplate) BuildSetter() *models.FileuploadErrorFileSetter {
|
|
m := &models.FileuploadErrorFileSetter{}
|
|
|
|
if o.FileID != nil {
|
|
val := o.FileID()
|
|
m.FileID = omit.From(val)
|
|
}
|
|
if o.ID != nil {
|
|
val := o.ID()
|
|
m.ID = omit.From(val)
|
|
}
|
|
if o.Message != nil {
|
|
val := o.Message()
|
|
m.Message = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.FileuploadErrorFileSetter
|
|
// this does nothing with the relationship templates
|
|
func (o FileuploadErrorFileTemplate) BuildManySetter(number int) []*models.FileuploadErrorFileSetter {
|
|
m := make([]*models.FileuploadErrorFileSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.FileuploadErrorFile
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use FileuploadErrorFileTemplate.Create
|
|
func (o FileuploadErrorFileTemplate) Build() *models.FileuploadErrorFile {
|
|
m := &models.FileuploadErrorFile{}
|
|
|
|
if o.FileID != nil {
|
|
m.FileID = o.FileID()
|
|
}
|
|
if o.ID != nil {
|
|
m.ID = o.ID()
|
|
}
|
|
if o.Message != nil {
|
|
m.Message = o.Message()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.FileuploadErrorFileSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use FileuploadErrorFileTemplate.CreateMany
|
|
func (o FileuploadErrorFileTemplate) BuildMany(number int) models.FileuploadErrorFileSlice {
|
|
m := make(models.FileuploadErrorFileSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatableFileuploadErrorFile(m *models.FileuploadErrorFileSetter) {
|
|
if !(m.FileID.IsValue()) {
|
|
val := random_int32(nil)
|
|
m.FileID = omit.From(val)
|
|
}
|
|
if !(m.Message.IsValue()) {
|
|
val := random_string(nil)
|
|
m.Message = omit.From(val)
|
|
}
|
|
}
|
|
|
|
// insertOptRels creates and inserts any optional the relationships on *models.FileuploadErrorFile
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *FileuploadErrorFileTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.FileuploadErrorFile) error {
|
|
var err error
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a fileuploadErrorFile and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *FileuploadErrorFileTemplate) Create(ctx context.Context, exec bob.Executor) (*models.FileuploadErrorFile, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatableFileuploadErrorFile(opt)
|
|
|
|
if o.r.File == nil {
|
|
FileuploadErrorFileMods.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.FileuploadErrorFiles.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 fileuploadErrorFile and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *FileuploadErrorFileTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.FileuploadErrorFile {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a fileuploadErrorFile 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 *FileuploadErrorFileTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.FileuploadErrorFile {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple fileuploadErrorFiles and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o FileuploadErrorFileTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.FileuploadErrorFileSlice, error) {
|
|
var err error
|
|
m := make(models.FileuploadErrorFileSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple fileuploadErrorFiles and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o FileuploadErrorFileTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.FileuploadErrorFileSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple fileuploadErrorFiles 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 FileuploadErrorFileTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.FileuploadErrorFileSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// FileuploadErrorFile has methods that act as mods for the FileuploadErrorFileTemplate
|
|
var FileuploadErrorFileMods fileuploadErrorFileMods
|
|
|
|
type fileuploadErrorFileMods struct{}
|
|
|
|
func (m fileuploadErrorFileMods) RandomizeAllColumns(f *faker.Faker) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModSlice{
|
|
FileuploadErrorFileMods.RandomFileID(f),
|
|
FileuploadErrorFileMods.RandomID(f),
|
|
FileuploadErrorFileMods.RandomMessage(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorFileMods) FileID(val int32) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.FileID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorFileMods) FileIDFunc(f func() int32) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.FileID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorFileMods) UnsetFileID() FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
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 fileuploadErrorFileMods) RandomFileID(f *faker.Faker) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.FileID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorFileMods) ID(val int32) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.ID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorFileMods) IDFunc(f func() int32) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.ID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorFileMods) UnsetID() FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
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 fileuploadErrorFileMods) RandomID(f *faker.Faker) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.ID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorFileMods) Message(val string) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.Message = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorFileMods) MessageFunc(f func() string) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.Message = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorFileMods) UnsetMessage() FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.Message = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m fileuploadErrorFileMods) RandomMessage(f *faker.Faker) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(_ context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.Message = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorFileMods) WithParentsCascading() FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(ctx context.Context, o *FileuploadErrorFileTemplate) {
|
|
if isDone, _ := fileuploadErrorFileWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = fileuploadErrorFileWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewFileuploadFileWithContext(ctx, FileuploadFileMods.WithParentsCascading())
|
|
m.WithFile(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorFileMods) WithFile(rel *FileuploadFileTemplate) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(ctx context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.r.File = &fileuploadErrorFileRFileR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorFileMods) WithNewFile(mods ...FileuploadFileMod) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(ctx context.Context, o *FileuploadErrorFileTemplate) {
|
|
related := o.f.NewFileuploadFileWithContext(ctx, mods...)
|
|
|
|
m.WithFile(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorFileMods) WithExistingFile(em *models.FileuploadFile) FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(ctx context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.r.File = &fileuploadErrorFileRFileR{
|
|
o: o.f.FromExistingFileuploadFile(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorFileMods) WithoutFile() FileuploadErrorFileMod {
|
|
return FileuploadErrorFileModFunc(func(ctx context.Context, o *FileuploadErrorFileTemplate) {
|
|
o.r.File = nil
|
|
})
|
|
}
|