Add generated Bob database integration
This commit is contained in:
parent
8203c50b08
commit
7c4a181cdf
32 changed files with 5128 additions and 2 deletions
39
factory/bobfactory_context.bob.go
Normal file
39
factory/bobfactory_context.bob.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import "context"
|
||||
|
||||
type contextKey string
|
||||
|
||||
var (
|
||||
// Relationship Contexts for goose_db_version
|
||||
gooseDBVersionWithParentsCascadingCtx = newContextual[bool]("gooseDBVersionWithParentsCascading")
|
||||
|
||||
// Relationship Contexts for organization
|
||||
organizationWithParentsCascadingCtx = newContextual[bool]("organizationWithParentsCascading")
|
||||
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
|
||||
|
||||
// Relationship Contexts for user_
|
||||
userWithParentsCascadingCtx = newContextual[bool]("userWithParentsCascading")
|
||||
userRelOrganizationCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
|
||||
)
|
||||
|
||||
// Contextual is a convienience wrapper around context.WithValue and context.Value
|
||||
type contextual[V any] struct {
|
||||
key contextKey
|
||||
}
|
||||
|
||||
func newContextual[V any](key string) contextual[V] {
|
||||
return contextual[V]{key: contextKey(key)}
|
||||
}
|
||||
|
||||
func (k contextual[V]) WithValue(ctx context.Context, val V) context.Context {
|
||||
return context.WithValue(ctx, k.key, val)
|
||||
}
|
||||
|
||||
func (k contextual[V]) Value(ctx context.Context) (V, bool) {
|
||||
v, ok := ctx.Value(k.key).(V)
|
||||
return v, ok
|
||||
}
|
||||
142
factory/bobfactory_main.bob.go
Normal file
142
factory/bobfactory_main.bob.go
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
)
|
||||
|
||||
type Factory struct {
|
||||
baseGooseDBVersionMods GooseDBVersionModSlice
|
||||
baseOrganizationMods OrganizationModSlice
|
||||
baseUserMods UserModSlice
|
||||
}
|
||||
|
||||
func New() *Factory {
|
||||
return &Factory{}
|
||||
}
|
||||
|
||||
func (f *Factory) NewGooseDBVersion(mods ...GooseDBVersionMod) *GooseDBVersionTemplate {
|
||||
return f.NewGooseDBVersionWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewGooseDBVersionWithContext(ctx context.Context, mods ...GooseDBVersionMod) *GooseDBVersionTemplate {
|
||||
o := &GooseDBVersionTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.baseGooseDBVersionMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
GooseDBVersionModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingGooseDBVersion(m *models.GooseDBVersion) *GooseDBVersionTemplate {
|
||||
o := &GooseDBVersionTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.VersionID = func() int64 { return m.VersionID }
|
||||
o.IsApplied = func() bool { return m.IsApplied }
|
||||
o.Tstamp = func() time.Time { return m.Tstamp }
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewOrganization(mods ...OrganizationMod) *OrganizationTemplate {
|
||||
return f.NewOrganizationWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewOrganizationWithContext(ctx context.Context, mods ...OrganizationMod) *OrganizationTemplate {
|
||||
o := &OrganizationTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.baseOrganizationMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
OrganizationModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingOrganization(m *models.Organization) *OrganizationTemplate {
|
||||
o := &OrganizationTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.Name = func() null.Val[string] { return m.Name }
|
||||
|
||||
ctx := context.Background()
|
||||
if len(m.R.User) > 0 {
|
||||
OrganizationMods.AddExistingUser(m.R.User...).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewUser(mods ...UserMod) *UserTemplate {
|
||||
return f.NewUserWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewUserWithContext(ctx context.Context, mods ...UserMod) *UserTemplate {
|
||||
o := &UserTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.baseUserMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
UserModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingUser(m *models.User) *UserTemplate {
|
||||
o := &UserTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.ArcgisAccessToken = func() null.Val[string] { return m.ArcgisAccessToken }
|
||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] { return m.ArcgisLicense }
|
||||
o.ArcgisRefreshToken = func() null.Val[string] { return m.ArcgisRefreshToken }
|
||||
o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] { return m.ArcgisRefreshTokenExpires }
|
||||
o.ArcgisRole = func() null.Val[string] { return m.ArcgisRole }
|
||||
o.DisplayName = func() null.Val[string] { return m.DisplayName }
|
||||
o.Email = func() null.Val[string] { return m.Email }
|
||||
o.OrganizationID = func() null.Val[int32] { return m.OrganizationID }
|
||||
o.Username = func() string { return m.Username }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Organization != nil {
|
||||
UserMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBaseGooseDBVersionMods() {
|
||||
f.baseGooseDBVersionMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBaseGooseDBVersionMod(mods ...GooseDBVersionMod) {
|
||||
f.baseGooseDBVersionMods = append(f.baseGooseDBVersionMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBaseOrganizationMods() {
|
||||
f.baseOrganizationMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBaseOrganizationMod(mods ...OrganizationMod) {
|
||||
f.baseOrganizationMods = append(f.baseOrganizationMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBaseUserMods() {
|
||||
f.baseUserMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBaseUserMod(mods ...UserMod) {
|
||||
f.baseUserMods = append(f.baseUserMods, mods...)
|
||||
}
|
||||
81
factory/bobfactory_main.bob_test.go
Normal file
81
factory/bobfactory_main.bob_test.go
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Code generated by BobGen psql v0.41.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"
|
||||
)
|
||||
|
||||
func TestCreateGooseDBVersion(t *testing.T) {
|
||||
if testDB == nil {
|
||||
t.Skip("skipping test, no DSN provided")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
tx, err := testDB.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting transaction: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := tx.Rollback(ctx); err != nil {
|
||||
t.Fatalf("Error rolling back transaction: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := New().NewGooseDBVersionWithContext(ctx).Create(ctx, tx); err != nil {
|
||||
t.Fatalf("Error creating GooseDBVersion: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOrganization(t *testing.T) {
|
||||
if testDB == nil {
|
||||
t.Skip("skipping test, no DSN provided")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
tx, err := testDB.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting transaction: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := tx.Rollback(ctx); err != nil {
|
||||
t.Fatalf("Error rolling back transaction: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := New().NewOrganizationWithContext(ctx).Create(ctx, tx); err != nil {
|
||||
t.Fatalf("Error creating Organization: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateUser(t *testing.T) {
|
||||
if testDB == nil {
|
||||
t.Skip("skipping test, no DSN provided")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
tx, err := testDB.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Error starting transaction: %v", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := tx.Rollback(ctx); err != nil {
|
||||
t.Fatalf("Error rolling back transaction: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := New().NewUserWithContext(ctx).Create(ctx, tx); err != nil {
|
||||
t.Fatalf("Error creating User: %v", err)
|
||||
}
|
||||
}
|
||||
76
factory/bobfactory_random.bob.go
Normal file
76
factory/bobfactory_random.bob.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
)
|
||||
|
||||
var defaultFaker = faker.New()
|
||||
|
||||
func random_bool(f *faker.Faker, limits ...string) bool {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
return f.Bool()
|
||||
}
|
||||
|
||||
func random_enums_ArcgisLicenseType(f *faker.Faker, limits ...string) enums.ArcgisLicenseType {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
var e enums.ArcgisLicenseType
|
||||
all := e.All()
|
||||
return all[f.IntBetween(0, len(all)-1)]
|
||||
}
|
||||
|
||||
func random_int32(f *faker.Faker, limits ...string) int32 {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
return f.Int32()
|
||||
}
|
||||
|
||||
func random_int64(f *faker.Faker, limits ...string) int64 {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
return f.Int64()
|
||||
}
|
||||
|
||||
func random_string(f *faker.Faker, limits ...string) string {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := strings.Join(f.Lorem().Words(f.IntBetween(1, 5)), " ")
|
||||
if len(limits) == 0 {
|
||||
return val
|
||||
}
|
||||
limitInt, _ := strconv.Atoi(limits[0])
|
||||
if limitInt > 0 && limitInt < len(val) {
|
||||
val = val[:limitInt]
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func random_time_Time(f *faker.Faker, limits ...string) time.Time {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
year := time.Hour * 24 * 365
|
||||
min := time.Now().Add(-year)
|
||||
max := time.Now().Add(year)
|
||||
return f.Time().TimeBetween(min, max)
|
||||
}
|
||||
57
factory/bobfactory_random.bob_test.go
Normal file
57
factory/bobfactory_random.bob_test.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// Code generated by BobGen psql v0.41.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
// Set the testDB to enable tests that use the database
|
||||
var testDB bob.Transactor[bob.Tx]
|
||||
|
||||
func TestRandom_int32(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_int32(nil)
|
||||
val2 := random_int32(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_int32() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_int64(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_int64(nil)
|
||||
val2 := random_int64(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_int64() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_string(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_string(nil)
|
||||
val2 := random_string(nil)
|
||||
|
||||
if val1 == val2 {
|
||||
t.Fatalf("random_string() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom_time_Time(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
val1 := random_time_Time(nil)
|
||||
val2 := random_time_Time(nil)
|
||||
|
||||
if val1.Equal(val2) {
|
||||
t.Fatalf("random_time_Time() returned the same value twice: %v", val1)
|
||||
}
|
||||
}
|
||||
380
factory/goose_db_version.bob.go
Normal file
380
factory/goose_db_version.bob.go
Normal file
|
|
@ -0,0 +1,380 @@
|
|||
// Code generated by BobGen psql v0.41.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"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type GooseDBVersionMod interface {
|
||||
Apply(context.Context, *GooseDBVersionTemplate)
|
||||
}
|
||||
|
||||
type GooseDBVersionModFunc func(context.Context, *GooseDBVersionTemplate)
|
||||
|
||||
func (f GooseDBVersionModFunc) Apply(ctx context.Context, n *GooseDBVersionTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type GooseDBVersionModSlice []GooseDBVersionMod
|
||||
|
||||
func (mods GooseDBVersionModSlice) Apply(ctx context.Context, n *GooseDBVersionTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// GooseDBVersionTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type GooseDBVersionTemplate struct {
|
||||
ID func() int32
|
||||
VersionID func() int64
|
||||
IsApplied func() bool
|
||||
Tstamp func() time.Time
|
||||
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
// Apply mods to the GooseDBVersionTemplate
|
||||
func (o *GooseDBVersionTemplate) Apply(ctx context.Context, mods ...GooseDBVersionMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.GooseDBVersion
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t GooseDBVersionTemplate) setModelRels(o *models.GooseDBVersion) {}
|
||||
|
||||
// BuildSetter returns an *models.GooseDBVersionSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o GooseDBVersionTemplate) BuildSetter() *models.GooseDBVersionSetter {
|
||||
m := &models.GooseDBVersionSetter{}
|
||||
|
||||
if o.ID != nil {
|
||||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.VersionID != nil {
|
||||
val := o.VersionID()
|
||||
m.VersionID = omit.From(val)
|
||||
}
|
||||
if o.IsApplied != nil {
|
||||
val := o.IsApplied()
|
||||
m.IsApplied = omit.From(val)
|
||||
}
|
||||
if o.Tstamp != nil {
|
||||
val := o.Tstamp()
|
||||
m.Tstamp = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.GooseDBVersionSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o GooseDBVersionTemplate) BuildManySetter(number int) []*models.GooseDBVersionSetter {
|
||||
m := make([]*models.GooseDBVersionSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.GooseDBVersion
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use GooseDBVersionTemplate.Create
|
||||
func (o GooseDBVersionTemplate) Build() *models.GooseDBVersion {
|
||||
m := &models.GooseDBVersion{}
|
||||
|
||||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.VersionID != nil {
|
||||
m.VersionID = o.VersionID()
|
||||
}
|
||||
if o.IsApplied != nil {
|
||||
m.IsApplied = o.IsApplied()
|
||||
}
|
||||
if o.Tstamp != nil {
|
||||
m.Tstamp = o.Tstamp()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.GooseDBVersionSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use GooseDBVersionTemplate.CreateMany
|
||||
func (o GooseDBVersionTemplate) BuildMany(number int) models.GooseDBVersionSlice {
|
||||
m := make(models.GooseDBVersionSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatableGooseDBVersion(m *models.GooseDBVersionSetter) {
|
||||
if !(m.VersionID.IsValue()) {
|
||||
val := random_int64(nil)
|
||||
m.VersionID = omit.From(val)
|
||||
}
|
||||
if !(m.IsApplied.IsValue()) {
|
||||
val := random_bool(nil)
|
||||
m.IsApplied = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.GooseDBVersion
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *GooseDBVersionTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.GooseDBVersion) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a gooseDBVersion and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *GooseDBVersionTemplate) Create(ctx context.Context, exec bob.Executor) (*models.GooseDBVersion, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatableGooseDBVersion(opt)
|
||||
|
||||
m, err := models.GooseDBVersions.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a gooseDBVersion and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *GooseDBVersionTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.GooseDBVersion {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a gooseDBVersion 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 *GooseDBVersionTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.GooseDBVersion {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple gooseDBVersions and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o GooseDBVersionTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.GooseDBVersionSlice, error) {
|
||||
var err error
|
||||
m := make(models.GooseDBVersionSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple gooseDBVersions and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o GooseDBVersionTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.GooseDBVersionSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple gooseDBVersions 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 GooseDBVersionTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.GooseDBVersionSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// GooseDBVersion has methods that act as mods for the GooseDBVersionTemplate
|
||||
var GooseDBVersionMods gooseDBVersionMods
|
||||
|
||||
type gooseDBVersionMods struct{}
|
||||
|
||||
func (m gooseDBVersionMods) RandomizeAllColumns(f *faker.Faker) GooseDBVersionMod {
|
||||
return GooseDBVersionModSlice{
|
||||
GooseDBVersionMods.RandomID(f),
|
||||
GooseDBVersionMods.RandomVersionID(f),
|
||||
GooseDBVersionMods.RandomIsApplied(f),
|
||||
GooseDBVersionMods.RandomTstamp(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m gooseDBVersionMods) ID(val int32) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.ID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m gooseDBVersionMods) IDFunc(f func() int32) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.ID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m gooseDBVersionMods) UnsetID() GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
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 gooseDBVersionMods) RandomID(f *faker.Faker) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.ID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m gooseDBVersionMods) VersionID(val int64) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.VersionID = func() int64 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m gooseDBVersionMods) VersionIDFunc(f func() int64) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.VersionID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m gooseDBVersionMods) UnsetVersionID() GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.VersionID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m gooseDBVersionMods) RandomVersionID(f *faker.Faker) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.VersionID = func() int64 {
|
||||
return random_int64(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m gooseDBVersionMods) IsApplied(val bool) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.IsApplied = func() bool { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m gooseDBVersionMods) IsAppliedFunc(f func() bool) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.IsApplied = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m gooseDBVersionMods) UnsetIsApplied() GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.IsApplied = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m gooseDBVersionMods) RandomIsApplied(f *faker.Faker) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.IsApplied = func() bool {
|
||||
return random_bool(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m gooseDBVersionMods) Tstamp(val time.Time) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.Tstamp = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m gooseDBVersionMods) TstampFunc(f func() time.Time) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.Tstamp = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m gooseDBVersionMods) UnsetTstamp() GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.Tstamp = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m gooseDBVersionMods) RandomTstamp(f *faker.Faker) GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(_ context.Context, o *GooseDBVersionTemplate) {
|
||||
o.Tstamp = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m gooseDBVersionMods) WithParentsCascading() GooseDBVersionMod {
|
||||
return GooseDBVersionModFunc(func(ctx context.Context, o *GooseDBVersionTemplate) {
|
||||
if isDone, _ := gooseDBVersionWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = gooseDBVersionWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
})
|
||||
}
|
||||
406
factory/organization.bob.go
Normal file
406
factory/organization.bob.go
Normal file
|
|
@ -0,0 +1,406 @@
|
|||
// Code generated by BobGen psql v0.41.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"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type OrganizationMod interface {
|
||||
Apply(context.Context, *OrganizationTemplate)
|
||||
}
|
||||
|
||||
type OrganizationModFunc func(context.Context, *OrganizationTemplate)
|
||||
|
||||
func (f OrganizationModFunc) Apply(ctx context.Context, n *OrganizationTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type OrganizationModSlice []OrganizationMod
|
||||
|
||||
func (mods OrganizationModSlice) Apply(ctx context.Context, n *OrganizationTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// OrganizationTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type OrganizationTemplate struct {
|
||||
ID func() int32
|
||||
Name func() null.Val[string]
|
||||
|
||||
r organizationR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type organizationR struct {
|
||||
User []*organizationRUserR
|
||||
}
|
||||
|
||||
type organizationRUserR struct {
|
||||
number int
|
||||
o *UserTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the OrganizationTemplate
|
||||
func (o *OrganizationTemplate) Apply(ctx context.Context, mods ...OrganizationMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.Organization
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t OrganizationTemplate) setModelRels(o *models.Organization) {
|
||||
if t.r.User != nil {
|
||||
rel := models.UserSlice{}
|
||||
for _, r := range t.r.User {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.OrganizationID = null.From(o.ID) // h2
|
||||
rel.R.Organization = o
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.User = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.OrganizationSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o OrganizationTemplate) BuildSetter() *models.OrganizationSetter {
|
||||
m := &models.OrganizationSetter{}
|
||||
|
||||
if o.ID != nil {
|
||||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.Name != nil {
|
||||
val := o.Name()
|
||||
m.Name = omitnull.FromNull(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.OrganizationSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o OrganizationTemplate) BuildManySetter(number int) []*models.OrganizationSetter {
|
||||
m := make([]*models.OrganizationSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.Organization
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use OrganizationTemplate.Create
|
||||
func (o OrganizationTemplate) Build() *models.Organization {
|
||||
m := &models.Organization{}
|
||||
|
||||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.Name != nil {
|
||||
m.Name = o.Name()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.OrganizationSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use OrganizationTemplate.CreateMany
|
||||
func (o OrganizationTemplate) BuildMany(number int) models.OrganizationSlice {
|
||||
m := make(models.OrganizationSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatableOrganization(m *models.OrganizationSetter) {
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.Organization
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Organization) error {
|
||||
var err error
|
||||
|
||||
isUserDone, _ := organizationRelUserCtx.Value(ctx)
|
||||
if !isUserDone && o.r.User != nil {
|
||||
ctx = organizationRelUserCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.User {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.User = append(m.R.User, r.o.Build())
|
||||
} else {
|
||||
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachUser(ctx, exec, rel0...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a organization and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *OrganizationTemplate) Create(ctx context.Context, exec bob.Executor) (*models.Organization, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatableOrganization(opt)
|
||||
|
||||
m, err := models.Organizations.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a organization and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *OrganizationTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.Organization {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a organization 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 *OrganizationTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.Organization {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple organizations and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o OrganizationTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.OrganizationSlice, error) {
|
||||
var err error
|
||||
m := make(models.OrganizationSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple organizations and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o OrganizationTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.OrganizationSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple organizations 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 OrganizationTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.OrganizationSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Organization has methods that act as mods for the OrganizationTemplate
|
||||
var OrganizationMods organizationMods
|
||||
|
||||
type organizationMods struct{}
|
||||
|
||||
func (m organizationMods) RandomizeAllColumns(f *faker.Faker) OrganizationMod {
|
||||
return OrganizationModSlice{
|
||||
OrganizationMods.RandomID(f),
|
||||
OrganizationMods.RandomName(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m organizationMods) ID(val int32) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.ID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m organizationMods) IDFunc(f func() int32) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.ID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m organizationMods) UnsetID() OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
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 organizationMods) RandomID(f *faker.Faker) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.ID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m organizationMods) Name(val null.Val[string]) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.Name = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m organizationMods) NameFunc(f func() null.Val[string]) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.Name = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m organizationMods) UnsetName() OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.Name = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m organizationMods) RandomName(f *faker.Faker) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.Name = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m organizationMods) RandomNameNotNull(f *faker.Faker) OrganizationMod {
|
||||
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
|
||||
o.Name = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithParentsCascading() OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
if isDone, _ := organizationWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = organizationWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithUser(number int, related *UserTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.User = []*organizationRUserR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithNewUser(number int, mods ...UserMod) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
related := o.f.NewUserWithContext(ctx, mods...)
|
||||
m.WithUser(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddUser(number int, related *UserTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.User = append(o.r.User, &organizationRUserR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddNewUser(number int, mods ...UserMod) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
related := o.f.NewUserWithContext(ctx, mods...)
|
||||
m.AddUser(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddExistingUser(existingModels ...*models.User) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.User = append(o.r.User, &organizationRUserR{
|
||||
o: o.f.FromExistingUser(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithoutUser() OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.User = nil
|
||||
})
|
||||
}
|
||||
865
factory/user_.bob.go
Normal file
865
factory/user_.bob.go
Normal file
|
|
@ -0,0 +1,865 @@
|
|||
// Code generated by BobGen psql v0.41.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/enums"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type UserMod interface {
|
||||
Apply(context.Context, *UserTemplate)
|
||||
}
|
||||
|
||||
type UserModFunc func(context.Context, *UserTemplate)
|
||||
|
||||
func (f UserModFunc) Apply(ctx context.Context, n *UserTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type UserModSlice []UserMod
|
||||
|
||||
func (mods UserModSlice) Apply(ctx context.Context, n *UserTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// UserTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type UserTemplate struct {
|
||||
ID func() int32
|
||||
ArcgisAccessToken func() null.Val[string]
|
||||
ArcgisLicense func() null.Val[enums.ArcgisLicenseType]
|
||||
ArcgisRefreshToken func() null.Val[string]
|
||||
ArcgisRefreshTokenExpires func() null.Val[time.Time]
|
||||
ArcgisRole func() null.Val[string]
|
||||
DisplayName func() null.Val[string]
|
||||
Email func() null.Val[string]
|
||||
OrganizationID func() null.Val[int32]
|
||||
Username func() string
|
||||
|
||||
r userR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type userR struct {
|
||||
Organization *userROrganizationR
|
||||
}
|
||||
|
||||
type userROrganizationR struct {
|
||||
o *OrganizationTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the UserTemplate
|
||||
func (o *UserTemplate) Apply(ctx context.Context, mods ...UserMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.User
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t UserTemplate) setModelRels(o *models.User) {
|
||||
if t.r.Organization != nil {
|
||||
rel := t.r.Organization.o.Build()
|
||||
rel.R.User = append(rel.R.User, o)
|
||||
o.OrganizationID = null.From(rel.ID) // h2
|
||||
o.R.Organization = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.UserSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o UserTemplate) BuildSetter() *models.UserSetter {
|
||||
m := &models.UserSetter{}
|
||||
|
||||
if o.ID != nil {
|
||||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.ArcgisAccessToken != nil {
|
||||
val := o.ArcgisAccessToken()
|
||||
m.ArcgisAccessToken = omitnull.FromNull(val)
|
||||
}
|
||||
if o.ArcgisLicense != nil {
|
||||
val := o.ArcgisLicense()
|
||||
m.ArcgisLicense = omitnull.FromNull(val)
|
||||
}
|
||||
if o.ArcgisRefreshToken != nil {
|
||||
val := o.ArcgisRefreshToken()
|
||||
m.ArcgisRefreshToken = omitnull.FromNull(val)
|
||||
}
|
||||
if o.ArcgisRefreshTokenExpires != nil {
|
||||
val := o.ArcgisRefreshTokenExpires()
|
||||
m.ArcgisRefreshTokenExpires = omitnull.FromNull(val)
|
||||
}
|
||||
if o.ArcgisRole != nil {
|
||||
val := o.ArcgisRole()
|
||||
m.ArcgisRole = omitnull.FromNull(val)
|
||||
}
|
||||
if o.DisplayName != nil {
|
||||
val := o.DisplayName()
|
||||
m.DisplayName = omitnull.FromNull(val)
|
||||
}
|
||||
if o.Email != nil {
|
||||
val := o.Email()
|
||||
m.Email = omitnull.FromNull(val)
|
||||
}
|
||||
if o.OrganizationID != nil {
|
||||
val := o.OrganizationID()
|
||||
m.OrganizationID = omitnull.FromNull(val)
|
||||
}
|
||||
if o.Username != nil {
|
||||
val := o.Username()
|
||||
m.Username = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.UserSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o UserTemplate) BuildManySetter(number int) []*models.UserSetter {
|
||||
m := make([]*models.UserSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.User
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use UserTemplate.Create
|
||||
func (o UserTemplate) Build() *models.User {
|
||||
m := &models.User{}
|
||||
|
||||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.ArcgisAccessToken != nil {
|
||||
m.ArcgisAccessToken = o.ArcgisAccessToken()
|
||||
}
|
||||
if o.ArcgisLicense != nil {
|
||||
m.ArcgisLicense = o.ArcgisLicense()
|
||||
}
|
||||
if o.ArcgisRefreshToken != nil {
|
||||
m.ArcgisRefreshToken = o.ArcgisRefreshToken()
|
||||
}
|
||||
if o.ArcgisRefreshTokenExpires != nil {
|
||||
m.ArcgisRefreshTokenExpires = o.ArcgisRefreshTokenExpires()
|
||||
}
|
||||
if o.ArcgisRole != nil {
|
||||
m.ArcgisRole = o.ArcgisRole()
|
||||
}
|
||||
if o.DisplayName != nil {
|
||||
m.DisplayName = o.DisplayName()
|
||||
}
|
||||
if o.Email != nil {
|
||||
m.Email = o.Email()
|
||||
}
|
||||
if o.OrganizationID != nil {
|
||||
m.OrganizationID = o.OrganizationID()
|
||||
}
|
||||
if o.Username != nil {
|
||||
m.Username = o.Username()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.UserSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use UserTemplate.CreateMany
|
||||
func (o UserTemplate) BuildMany(number int) models.UserSlice {
|
||||
m := make(models.UserSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatableUser(m *models.UserSetter) {
|
||||
if !(m.Username.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Username = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.User
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.User) error {
|
||||
var err error
|
||||
|
||||
isOrganizationDone, _ := userRelOrganizationCtx.Value(ctx)
|
||||
if !isOrganizationDone && o.r.Organization != nil {
|
||||
ctx = userRelOrganizationCtx.WithValue(ctx, true)
|
||||
if o.r.Organization.o.alreadyPersisted {
|
||||
m.R.Organization = o.r.Organization.o.Build()
|
||||
} else {
|
||||
var rel0 *models.Organization
|
||||
rel0, err = o.r.Organization.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = m.AttachOrganization(ctx, exec, rel0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a user and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *UserTemplate) Create(ctx context.Context, exec bob.Executor) (*models.User, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatableUser(opt)
|
||||
|
||||
m, err := models.Users.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a user and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *UserTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.User {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a user 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 *UserTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.User {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple users and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o UserTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.UserSlice, error) {
|
||||
var err error
|
||||
m := make(models.UserSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple users and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o UserTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.UserSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple users 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 UserTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.UserSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// User has methods that act as mods for the UserTemplate
|
||||
var UserMods userMods
|
||||
|
||||
type userMods struct{}
|
||||
|
||||
func (m userMods) RandomizeAllColumns(f *faker.Faker) UserMod {
|
||||
return UserModSlice{
|
||||
UserMods.RandomID(f),
|
||||
UserMods.RandomArcgisAccessToken(f),
|
||||
UserMods.RandomArcgisLicense(f),
|
||||
UserMods.RandomArcgisRefreshToken(f),
|
||||
UserMods.RandomArcgisRefreshTokenExpires(f),
|
||||
UserMods.RandomArcgisRole(f),
|
||||
UserMods.RandomDisplayName(f),
|
||||
UserMods.RandomEmail(f),
|
||||
UserMods.RandomOrganizationID(f),
|
||||
UserMods.RandomUsername(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) ID(val int32) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) IDFunc(f func() int32) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetID() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
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 userMods) RandomID(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) ArcgisAccessToken(val null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisAccessToken = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) ArcgisAccessTokenFunc(f func() null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisAccessToken = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetArcgisAccessToken() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisAccessToken = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomArcgisAccessToken(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisAccessToken = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomArcgisAccessTokenNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisAccessToken = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) ArcgisLicense(val null.Val[enums.ArcgisLicenseType]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) ArcgisLicenseFunc(f func() null.Val[enums.ArcgisLicenseType]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisLicense = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetArcgisLicense() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisLicense = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomArcgisLicense(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_enums_ArcgisLicenseType(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomArcgisLicenseNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisLicense = func() null.Val[enums.ArcgisLicenseType] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_enums_ArcgisLicenseType(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) ArcgisRefreshToken(val null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshToken = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) ArcgisRefreshTokenFunc(f func() null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshToken = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetArcgisRefreshToken() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshToken = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomArcgisRefreshToken(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshToken = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomArcgisRefreshTokenNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshToken = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) ArcgisRefreshTokenExpires(val null.Val[time.Time]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) ArcgisRefreshTokenExpiresFunc(f func() null.Val[time.Time]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshTokenExpires = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetArcgisRefreshTokenExpires() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshTokenExpires = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomArcgisRefreshTokenExpires(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomArcgisRefreshTokenExpiresNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRefreshTokenExpires = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) ArcgisRole(val null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRole = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) ArcgisRoleFunc(f func() null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRole = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetArcgisRole() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRole = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomArcgisRole(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRole = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomArcgisRoleNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.ArcgisRole = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) DisplayName(val null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.DisplayName = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) DisplayNameFunc(f func() null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.DisplayName = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetDisplayName() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.DisplayName = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomDisplayName(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.DisplayName = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f, "200")
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomDisplayNameNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.DisplayName = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f, "200")
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) Email(val null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Email = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) EmailFunc(f func() null.Val[string]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Email = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetEmail() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Email = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomEmail(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Email = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomEmailNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Email = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) OrganizationID(val null.Val[int32]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.OrganizationID = func() null.Val[int32] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) OrganizationIDFunc(f func() null.Val[int32]) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.OrganizationID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetOrganizationID() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.OrganizationID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m userMods) RandomOrganizationID(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.OrganizationID = func() null.Val[int32] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_int32(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m userMods) RandomOrganizationIDNotNull(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.OrganizationID = func() null.Val[int32] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_int32(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m userMods) Username(val string) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Username = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m userMods) UsernameFunc(f func() string) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Username = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m userMods) UnsetUsername() UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Username = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m userMods) RandomUsername(f *faker.Faker) UserMod {
|
||||
return UserModFunc(func(_ context.Context, o *UserTemplate) {
|
||||
o.Username = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m userMods) WithParentsCascading() UserMod {
|
||||
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
|
||||
if isDone, _ := userWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = userWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewOrganizationWithContext(ctx, OrganizationMods.WithParentsCascading())
|
||||
m.WithOrganization(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m userMods) WithOrganization(rel *OrganizationTemplate) UserMod {
|
||||
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
|
||||
o.r.Organization = &userROrganizationR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m userMods) WithNewOrganization(mods ...OrganizationMod) UserMod {
|
||||
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
|
||||
related := o.f.NewOrganizationWithContext(ctx, mods...)
|
||||
|
||||
m.WithOrganization(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m userMods) WithExistingOrganization(em *models.Organization) UserMod {
|
||||
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
|
||||
o.r.Organization = &userROrganizationR{
|
||||
o: o.f.FromExistingOrganization(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m userMods) WithoutOrganization() UserMod {
|
||||
return UserModFunc(func(ctx context.Context, o *UserTemplate) {
|
||||
o.r.Organization = nil
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue