453 lines
13 KiB
Go
453 lines
13 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 FileuploadErrorMod interface {
|
|
Apply(context.Context, *FileuploadErrorTemplate)
|
|
}
|
|
|
|
type FileuploadErrorModFunc func(context.Context, *FileuploadErrorTemplate)
|
|
|
|
func (f FileuploadErrorModFunc) Apply(ctx context.Context, n *FileuploadErrorTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type FileuploadErrorModSlice []FileuploadErrorMod
|
|
|
|
func (mods FileuploadErrorModSlice) Apply(ctx context.Context, n *FileuploadErrorTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// FileuploadErrorTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type FileuploadErrorTemplate struct {
|
|
FileID func() int32
|
|
ID func() int32
|
|
Line func() int32
|
|
Message func() string
|
|
|
|
r fileuploadErrorR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type fileuploadErrorR struct {
|
|
File *fileuploadErrorRFileR
|
|
}
|
|
|
|
type fileuploadErrorRFileR struct {
|
|
o *FileuploadFileTemplate
|
|
}
|
|
|
|
// Apply mods to the FileuploadErrorTemplate
|
|
func (o *FileuploadErrorTemplate) Apply(ctx context.Context, mods ...FileuploadErrorMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.FileuploadError
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t FileuploadErrorTemplate) setModelRels(o *models.FileuploadError) {
|
|
if t.r.File != nil {
|
|
rel := t.r.File.o.Build()
|
|
rel.R.Errors = append(rel.R.Errors, o)
|
|
o.FileID = rel.ID // h2
|
|
o.R.File = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.FileuploadErrorSetter
|
|
// this does nothing with the relationship templates
|
|
func (o FileuploadErrorTemplate) BuildSetter() *models.FileuploadErrorSetter {
|
|
m := &models.FileuploadErrorSetter{}
|
|
|
|
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.Line != nil {
|
|
val := o.Line()
|
|
m.Line = omit.From(val)
|
|
}
|
|
if o.Message != nil {
|
|
val := o.Message()
|
|
m.Message = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.FileuploadErrorSetter
|
|
// this does nothing with the relationship templates
|
|
func (o FileuploadErrorTemplate) BuildManySetter(number int) []*models.FileuploadErrorSetter {
|
|
m := make([]*models.FileuploadErrorSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.FileuploadError
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use FileuploadErrorTemplate.Create
|
|
func (o FileuploadErrorTemplate) Build() *models.FileuploadError {
|
|
m := &models.FileuploadError{}
|
|
|
|
if o.FileID != nil {
|
|
m.FileID = o.FileID()
|
|
}
|
|
if o.ID != nil {
|
|
m.ID = o.ID()
|
|
}
|
|
if o.Line != nil {
|
|
m.Line = o.Line()
|
|
}
|
|
if o.Message != nil {
|
|
m.Message = o.Message()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.FileuploadErrorSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use FileuploadErrorTemplate.CreateMany
|
|
func (o FileuploadErrorTemplate) BuildMany(number int) models.FileuploadErrorSlice {
|
|
m := make(models.FileuploadErrorSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatableFileuploadError(m *models.FileuploadErrorSetter) {
|
|
if !(m.FileID.IsValue()) {
|
|
val := random_int32(nil)
|
|
m.FileID = omit.From(val)
|
|
}
|
|
if !(m.Line.IsValue()) {
|
|
val := random_int32(nil)
|
|
m.Line = 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.FileuploadError
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *FileuploadErrorTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.FileuploadError) error {
|
|
var err error
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a fileuploadError and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *FileuploadErrorTemplate) Create(ctx context.Context, exec bob.Executor) (*models.FileuploadError, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatableFileuploadError(opt)
|
|
|
|
if o.r.File == nil {
|
|
FileuploadErrorMods.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.FileuploadErrors.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 fileuploadError and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *FileuploadErrorTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.FileuploadError {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a fileuploadError 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 *FileuploadErrorTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.FileuploadError {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple fileuploadErrors and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o FileuploadErrorTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.FileuploadErrorSlice, error) {
|
|
var err error
|
|
m := make(models.FileuploadErrorSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple fileuploadErrors and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o FileuploadErrorTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.FileuploadErrorSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple fileuploadErrors 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 FileuploadErrorTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.FileuploadErrorSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// FileuploadError has methods that act as mods for the FileuploadErrorTemplate
|
|
var FileuploadErrorMods fileuploadErrorMods
|
|
|
|
type fileuploadErrorMods struct{}
|
|
|
|
func (m fileuploadErrorMods) RandomizeAllColumns(f *faker.Faker) FileuploadErrorMod {
|
|
return FileuploadErrorModSlice{
|
|
FileuploadErrorMods.RandomFileID(f),
|
|
FileuploadErrorMods.RandomID(f),
|
|
FileuploadErrorMods.RandomLine(f),
|
|
FileuploadErrorMods.RandomMessage(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorMods) FileID(val int32) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.FileID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorMods) FileIDFunc(f func() int32) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.FileID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorMods) UnsetFileID() FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
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 fileuploadErrorMods) RandomFileID(f *faker.Faker) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.FileID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorMods) ID(val int32) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.ID = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorMods) IDFunc(f func() int32) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.ID = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorMods) UnsetID() FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
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 fileuploadErrorMods) RandomID(f *faker.Faker) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.ID = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorMods) Line(val int32) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Line = func() int32 { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorMods) LineFunc(f func() int32) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Line = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorMods) UnsetLine() FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Line = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m fileuploadErrorMods) RandomLine(f *faker.Faker) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Line = func() int32 {
|
|
return random_int32(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m fileuploadErrorMods) Message(val string) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Message = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m fileuploadErrorMods) MessageFunc(f func() string) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Message = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m fileuploadErrorMods) UnsetMessage() FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
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 fileuploadErrorMods) RandomMessage(f *faker.Faker) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(_ context.Context, o *FileuploadErrorTemplate) {
|
|
o.Message = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorMods) WithParentsCascading() FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(ctx context.Context, o *FileuploadErrorTemplate) {
|
|
if isDone, _ := fileuploadErrorWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = fileuploadErrorWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewFileuploadFileWithContext(ctx, FileuploadFileMods.WithParentsCascading())
|
|
m.WithFile(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorMods) WithFile(rel *FileuploadFileTemplate) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(ctx context.Context, o *FileuploadErrorTemplate) {
|
|
o.r.File = &fileuploadErrorRFileR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorMods) WithNewFile(mods ...FileuploadFileMod) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(ctx context.Context, o *FileuploadErrorTemplate) {
|
|
related := o.f.NewFileuploadFileWithContext(ctx, mods...)
|
|
|
|
m.WithFile(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorMods) WithExistingFile(em *models.FileuploadFile) FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(ctx context.Context, o *FileuploadErrorTemplate) {
|
|
o.r.File = &fileuploadErrorRFileR{
|
|
o: o.f.FromExistingFileuploadFile(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m fileuploadErrorMods) WithoutFile() FileuploadErrorMod {
|
|
return FileuploadErrorModFunc(func(ctx context.Context, o *FileuploadErrorTemplate) {
|
|
o.r.File = nil
|
|
})
|
|
}
|