Move away from "SMS" as the operative word - we're going RCS. Move all comms processing to a separate goroutine Rename the DB tables
523 lines
15 KiB
Go
523 lines
15 KiB
Go
// Code generated by BobGen psql v0.42.1. 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"
|
|
|
|
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"
|
|
"github.com/stephenafamo/bob"
|
|
)
|
|
|
|
type CommsTextLogMod interface {
|
|
Apply(context.Context, *CommsTextLogTemplate)
|
|
}
|
|
|
|
type CommsTextLogModFunc func(context.Context, *CommsTextLogTemplate)
|
|
|
|
func (f CommsTextLogModFunc) Apply(ctx context.Context, n *CommsTextLogTemplate) {
|
|
f(ctx, n)
|
|
}
|
|
|
|
type CommsTextLogModSlice []CommsTextLogMod
|
|
|
|
func (mods CommsTextLogModSlice) Apply(ctx context.Context, n *CommsTextLogTemplate) {
|
|
for _, f := range mods {
|
|
f.Apply(ctx, n)
|
|
}
|
|
}
|
|
|
|
// CommsTextLogTemplate is an object representing the database table.
|
|
// all columns are optional and should be set by mods
|
|
type CommsTextLogTemplate struct {
|
|
Created func() time.Time
|
|
Destination func() string
|
|
Source func() string
|
|
Type func() enums.CommsMessagetypetext
|
|
|
|
r commsTextLogR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type commsTextLogR struct {
|
|
DestinationPhone *commsTextLogRDestinationPhoneR
|
|
SourcePhone *commsTextLogRSourcePhoneR
|
|
}
|
|
|
|
type commsTextLogRDestinationPhoneR struct {
|
|
o *CommsPhoneTemplate
|
|
}
|
|
type commsTextLogRSourcePhoneR struct {
|
|
o *CommsPhoneTemplate
|
|
}
|
|
|
|
// Apply mods to the CommsTextLogTemplate
|
|
func (o *CommsTextLogTemplate) Apply(ctx context.Context, mods ...CommsTextLogMod) {
|
|
for _, mod := range mods {
|
|
mod.Apply(ctx, o)
|
|
}
|
|
}
|
|
|
|
// setModelRels creates and sets the relationships on *models.CommsTextLog
|
|
// according to the relationships in the template. Nothing is inserted into the db
|
|
func (t CommsTextLogTemplate) setModelRels(o *models.CommsTextLog) {
|
|
if t.r.DestinationPhone != nil {
|
|
rel := t.r.DestinationPhone.o.Build()
|
|
rel.R.DestinationTextLogs = append(rel.R.DestinationTextLogs, o)
|
|
o.Destination = rel.E164 // h2
|
|
o.R.DestinationPhone = rel
|
|
}
|
|
|
|
if t.r.SourcePhone != nil {
|
|
rel := t.r.SourcePhone.o.Build()
|
|
rel.R.SourceTextLogs = append(rel.R.SourceTextLogs, o)
|
|
o.Source = rel.E164 // h2
|
|
o.R.SourcePhone = rel
|
|
}
|
|
}
|
|
|
|
// BuildSetter returns an *models.CommsTextLogSetter
|
|
// this does nothing with the relationship templates
|
|
func (o CommsTextLogTemplate) BuildSetter() *models.CommsTextLogSetter {
|
|
m := &models.CommsTextLogSetter{}
|
|
|
|
if o.Created != nil {
|
|
val := o.Created()
|
|
m.Created = omit.From(val)
|
|
}
|
|
if o.Destination != nil {
|
|
val := o.Destination()
|
|
m.Destination = omit.From(val)
|
|
}
|
|
if o.Source != nil {
|
|
val := o.Source()
|
|
m.Source = omit.From(val)
|
|
}
|
|
if o.Type != nil {
|
|
val := o.Type()
|
|
m.Type = omit.From(val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildManySetter returns an []*models.CommsTextLogSetter
|
|
// this does nothing with the relationship templates
|
|
func (o CommsTextLogTemplate) BuildManySetter(number int) []*models.CommsTextLogSetter {
|
|
m := make([]*models.CommsTextLogSetter, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.BuildSetter()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
// Build returns an *models.CommsTextLog
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use CommsTextLogTemplate.Create
|
|
func (o CommsTextLogTemplate) Build() *models.CommsTextLog {
|
|
m := &models.CommsTextLog{}
|
|
|
|
if o.Created != nil {
|
|
m.Created = o.Created()
|
|
}
|
|
if o.Destination != nil {
|
|
m.Destination = o.Destination()
|
|
}
|
|
if o.Source != nil {
|
|
m.Source = o.Source()
|
|
}
|
|
if o.Type != nil {
|
|
m.Type = o.Type()
|
|
}
|
|
|
|
o.setModelRels(m)
|
|
|
|
return m
|
|
}
|
|
|
|
// BuildMany returns an models.CommsTextLogSlice
|
|
// Related objects are also created and placed in the .R field
|
|
// NOTE: Objects are not inserted into the database. Use CommsTextLogTemplate.CreateMany
|
|
func (o CommsTextLogTemplate) BuildMany(number int) models.CommsTextLogSlice {
|
|
m := make(models.CommsTextLogSlice, number)
|
|
|
|
for i := range m {
|
|
m[i] = o.Build()
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func ensureCreatableCommsTextLog(m *models.CommsTextLogSetter) {
|
|
if !(m.Created.IsValue()) {
|
|
val := random_time_Time(nil)
|
|
m.Created = omit.From(val)
|
|
}
|
|
if !(m.Destination.IsValue()) {
|
|
val := random_string(nil)
|
|
m.Destination = omit.From(val)
|
|
}
|
|
if !(m.Source.IsValue()) {
|
|
val := random_string(nil)
|
|
m.Source = omit.From(val)
|
|
}
|
|
if !(m.Type.IsValue()) {
|
|
val := random_enums_CommsMessagetypetext(nil)
|
|
m.Type = omit.From(val)
|
|
}
|
|
}
|
|
|
|
// insertOptRels creates and inserts any optional the relationships on *models.CommsTextLog
|
|
// according to the relationships in the template.
|
|
// any required relationship should have already exist on the model
|
|
func (o *CommsTextLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsTextLog) error {
|
|
var err error
|
|
|
|
return err
|
|
}
|
|
|
|
// Create builds a commsTextLog and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o *CommsTextLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsTextLog, error) {
|
|
var err error
|
|
opt := o.BuildSetter()
|
|
ensureCreatableCommsTextLog(opt)
|
|
|
|
if o.r.DestinationPhone == nil {
|
|
CommsTextLogMods.WithNewDestinationPhone().Apply(ctx, o)
|
|
}
|
|
|
|
var rel0 *models.CommsPhone
|
|
|
|
if o.r.DestinationPhone.o.alreadyPersisted {
|
|
rel0 = o.r.DestinationPhone.o.Build()
|
|
} else {
|
|
rel0, err = o.r.DestinationPhone.o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
opt.Destination = omit.From(rel0.E164)
|
|
|
|
if o.r.SourcePhone == nil {
|
|
CommsTextLogMods.WithNewSourcePhone().Apply(ctx, o)
|
|
}
|
|
|
|
var rel1 *models.CommsPhone
|
|
|
|
if o.r.SourcePhone.o.alreadyPersisted {
|
|
rel1 = o.r.SourcePhone.o.Build()
|
|
} else {
|
|
rel1, err = o.r.SourcePhone.o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
opt.Source = omit.From(rel1.E164)
|
|
|
|
m, err := models.CommsTextLogs.Insert(opt).One(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
m.R.DestinationPhone = rel0
|
|
m.R.SourcePhone = rel1
|
|
|
|
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
|
return nil, err
|
|
}
|
|
return m, err
|
|
}
|
|
|
|
// MustCreate builds a commsTextLog and inserts it into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o *CommsTextLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsTextLog {
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateOrFail builds a commsTextLog 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 *CommsTextLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsTextLog {
|
|
tb.Helper()
|
|
m, err := o.Create(ctx, exec)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateMany builds multiple commsTextLogs and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
func (o CommsTextLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsTextLogSlice, error) {
|
|
var err error
|
|
m := make(models.CommsTextLogSlice, number)
|
|
|
|
for i := range m {
|
|
m[i], err = o.Create(ctx, exec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
// MustCreateMany builds multiple commsTextLogs and inserts them into the database
|
|
// Relations objects are also inserted and placed in the .R field
|
|
// panics if an error occurs
|
|
func (o CommsTextLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsTextLogSlice {
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CreateManyOrFail builds multiple commsTextLogs 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 CommsTextLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsTextLogSlice {
|
|
tb.Helper()
|
|
m, err := o.CreateMany(ctx, exec, number)
|
|
if err != nil {
|
|
tb.Fatal(err)
|
|
return nil
|
|
}
|
|
return m
|
|
}
|
|
|
|
// CommsTextLog has methods that act as mods for the CommsTextLogTemplate
|
|
var CommsTextLogMods commsTextLogMods
|
|
|
|
type commsTextLogMods struct{}
|
|
|
|
func (m commsTextLogMods) RandomizeAllColumns(f *faker.Faker) CommsTextLogMod {
|
|
return CommsTextLogModSlice{
|
|
CommsTextLogMods.RandomCreated(f),
|
|
CommsTextLogMods.RandomDestination(f),
|
|
CommsTextLogMods.RandomSource(f),
|
|
CommsTextLogMods.RandomType(f),
|
|
}
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsTextLogMods) Created(val time.Time) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Created = func() time.Time { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsTextLogMods) CreatedFunc(f func() time.Time) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Created = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsTextLogMods) UnsetCreated() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
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 commsTextLogMods) RandomCreated(f *faker.Faker) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Created = func() time.Time {
|
|
return random_time_Time(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsTextLogMods) Destination(val string) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Destination = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsTextLogMods) DestinationFunc(f func() string) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Destination = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsTextLogMods) UnsetDestination() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Destination = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m commsTextLogMods) RandomDestination(f *faker.Faker) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Destination = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsTextLogMods) Source(val string) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Source = func() string { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsTextLogMods) SourceFunc(f func() string) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Source = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsTextLogMods) UnsetSource() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Source = nil
|
|
})
|
|
}
|
|
|
|
// Generates a random value for the column using the given faker
|
|
// if faker is nil, a default faker is used
|
|
func (m commsTextLogMods) RandomSource(f *faker.Faker) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Source = func() string {
|
|
return random_string(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
// Set the model columns to this value
|
|
func (m commsTextLogMods) Type(val enums.CommsMessagetypetext) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Type = func() enums.CommsMessagetypetext { return val }
|
|
})
|
|
}
|
|
|
|
// Set the Column from the function
|
|
func (m commsTextLogMods) TypeFunc(f func() enums.CommsMessagetypetext) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Type = f
|
|
})
|
|
}
|
|
|
|
// Clear any values for the column
|
|
func (m commsTextLogMods) UnsetType() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
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 commsTextLogMods) RandomType(f *faker.Faker) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
|
o.Type = func() enums.CommsMessagetypetext {
|
|
return random_enums_CommsMessagetypetext(f)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithParentsCascading() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
if isDone, _ := commsTextLogWithParentsCascadingCtx.Value(ctx); isDone {
|
|
return
|
|
}
|
|
ctx = commsTextLogWithParentsCascadingCtx.WithValue(ctx, true)
|
|
{
|
|
|
|
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
|
m.WithDestinationPhone(related).Apply(ctx, o)
|
|
}
|
|
{
|
|
|
|
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
|
m.WithSourcePhone(related).Apply(ctx, o)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithDestinationPhone(rel *CommsPhoneTemplate) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
o.r.DestinationPhone = &commsTextLogRDestinationPhoneR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithNewDestinationPhone(mods ...CommsPhoneMod) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
|
|
|
|
m.WithDestinationPhone(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithExistingDestinationPhone(em *models.CommsPhone) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
o.r.DestinationPhone = &commsTextLogRDestinationPhoneR{
|
|
o: o.f.FromExistingCommsPhone(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithoutDestinationPhone() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
o.r.DestinationPhone = nil
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
o.r.SourcePhone = &commsTextLogRSourcePhoneR{
|
|
o: rel,
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
|
|
|
|
m.WithSourcePhone(related).Apply(ctx, o)
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
o.r.SourcePhone = &commsTextLogRSourcePhoneR{
|
|
o: o.f.FromExistingCommsPhone(em),
|
|
}
|
|
})
|
|
}
|
|
|
|
func (m commsTextLogMods) WithoutSourcePhone() CommsTextLogMod {
|
|
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
|
o.r.SourcePhone = nil
|
|
})
|
|
}
|