// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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/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() string Email func() null.Val[string] OrganizationID func() int32 Username func() string PasswordHashType func() enums.Hashtype PasswordHash func() string r userR f *Factory alreadyPersisted bool } type userR struct { CreatorNoteAudios []*userRCreatorNoteAudiosR DeletorNoteAudios []*userRDeletorNoteAudiosR CreatorNoteImages []*userRCreatorNoteImagesR DeletorNoteImages []*userRDeletorNoteImagesR UserNotifications []*userRUserNotificationsR UserOauthTokens []*userRUserOauthTokensR Organization *userROrganizationR } type userRCreatorNoteAudiosR struct { number int o *NoteAudioTemplate } type userRDeletorNoteAudiosR struct { number int o *NoteAudioTemplate } type userRCreatorNoteImagesR struct { number int o *NoteImageTemplate } type userRDeletorNoteImagesR struct { number int o *NoteImageTemplate } type userRUserNotificationsR struct { number int o *NotificationTemplate } type userRUserOauthTokensR struct { number int o *OauthTokenTemplate } 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.CreatorNoteAudios != nil { rel := models.NoteAudioSlice{} for _, r := range t.r.CreatorNoteAudios { related := r.o.BuildMany(r.number) for _, rel := range related { rel.CreatorID = o.ID // h2 rel.R.CreatorUser = o } rel = append(rel, related...) } o.R.CreatorNoteAudios = rel } if t.r.DeletorNoteAudios != nil { rel := models.NoteAudioSlice{} for _, r := range t.r.DeletorNoteAudios { related := r.o.BuildMany(r.number) for _, rel := range related { rel.DeletorID = null.From(o.ID) // h2 rel.R.DeletorUser = o } rel = append(rel, related...) } o.R.DeletorNoteAudios = rel } if t.r.CreatorNoteImages != nil { rel := models.NoteImageSlice{} for _, r := range t.r.CreatorNoteImages { related := r.o.BuildMany(r.number) for _, rel := range related { rel.CreatorID = o.ID // h2 rel.R.CreatorUser = o } rel = append(rel, related...) } o.R.CreatorNoteImages = rel } if t.r.DeletorNoteImages != nil { rel := models.NoteImageSlice{} for _, r := range t.r.DeletorNoteImages { related := r.o.BuildMany(r.number) for _, rel := range related { rel.DeletorID = null.From(o.ID) // h2 rel.R.DeletorUser = o } rel = append(rel, related...) } o.R.DeletorNoteImages = rel } if t.r.UserNotifications != nil { rel := models.NotificationSlice{} for _, r := range t.r.UserNotifications { related := r.o.BuildMany(r.number) for _, rel := range related { rel.UserID = o.ID // h2 rel.R.UserUser = o } rel = append(rel, related...) } o.R.UserNotifications = rel } if t.r.UserOauthTokens != nil { rel := models.OauthTokenSlice{} for _, r := range t.r.UserOauthTokens { related := r.o.BuildMany(r.number) for _, rel := range related { rel.UserID = o.ID // h2 rel.R.UserUser = o } rel = append(rel, related...) } o.R.UserOauthTokens = rel } if t.r.Organization != nil { rel := t.r.Organization.o.Build() rel.R.User = append(rel.R.User, o) o.OrganizationID = 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 = omit.From(val) } if o.Email != nil { val := o.Email() m.Email = omitnull.FromNull(val) } if o.OrganizationID != nil { val := o.OrganizationID() m.OrganizationID = omit.From(val) } if o.Username != nil { val := o.Username() m.Username = omit.From(val) } if o.PasswordHashType != nil { val := o.PasswordHashType() m.PasswordHashType = omit.From(val) } if o.PasswordHash != nil { val := o.PasswordHash() m.PasswordHash = 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() } if o.PasswordHashType != nil { m.PasswordHashType = o.PasswordHashType() } if o.PasswordHash != nil { m.PasswordHash = o.PasswordHash() } 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.DisplayName.IsValue()) { val := random_string(nil, "200") m.DisplayName = omit.From(val) } if !(m.OrganizationID.IsValue()) { val := random_int32(nil) m.OrganizationID = omit.From(val) } if !(m.Username.IsValue()) { val := random_string(nil) m.Username = omit.From(val) } if !(m.PasswordHashType.IsValue()) { val := random_enums_Hashtype(nil) m.PasswordHashType = omit.From(val) } if !(m.PasswordHash.IsValue()) { val := random_string(nil) m.PasswordHash = 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 isCreatorNoteAudiosDone, _ := userRelCreatorNoteAudiosCtx.Value(ctx) if !isCreatorNoteAudiosDone && o.r.CreatorNoteAudios != nil { ctx = userRelCreatorNoteAudiosCtx.WithValue(ctx, true) for _, r := range o.r.CreatorNoteAudios { if r.o.alreadyPersisted { m.R.CreatorNoteAudios = append(m.R.CreatorNoteAudios, r.o.Build()) } else { rel0, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } err = m.AttachCreatorNoteAudios(ctx, exec, rel0...) if err != nil { return err } } } } isDeletorNoteAudiosDone, _ := userRelDeletorNoteAudiosCtx.Value(ctx) if !isDeletorNoteAudiosDone && o.r.DeletorNoteAudios != nil { ctx = userRelDeletorNoteAudiosCtx.WithValue(ctx, true) for _, r := range o.r.DeletorNoteAudios { if r.o.alreadyPersisted { m.R.DeletorNoteAudios = append(m.R.DeletorNoteAudios, r.o.Build()) } else { rel1, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } err = m.AttachDeletorNoteAudios(ctx, exec, rel1...) if err != nil { return err } } } } isCreatorNoteImagesDone, _ := userRelCreatorNoteImagesCtx.Value(ctx) if !isCreatorNoteImagesDone && o.r.CreatorNoteImages != nil { ctx = userRelCreatorNoteImagesCtx.WithValue(ctx, true) for _, r := range o.r.CreatorNoteImages { if r.o.alreadyPersisted { m.R.CreatorNoteImages = append(m.R.CreatorNoteImages, r.o.Build()) } else { rel2, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } err = m.AttachCreatorNoteImages(ctx, exec, rel2...) if err != nil { return err } } } } isDeletorNoteImagesDone, _ := userRelDeletorNoteImagesCtx.Value(ctx) if !isDeletorNoteImagesDone && o.r.DeletorNoteImages != nil { ctx = userRelDeletorNoteImagesCtx.WithValue(ctx, true) for _, r := range o.r.DeletorNoteImages { if r.o.alreadyPersisted { m.R.DeletorNoteImages = append(m.R.DeletorNoteImages, r.o.Build()) } else { rel3, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } err = m.AttachDeletorNoteImages(ctx, exec, rel3...) if err != nil { return err } } } } isUserNotificationsDone, _ := userRelUserNotificationsCtx.Value(ctx) if !isUserNotificationsDone && o.r.UserNotifications != nil { ctx = userRelUserNotificationsCtx.WithValue(ctx, true) for _, r := range o.r.UserNotifications { if r.o.alreadyPersisted { m.R.UserNotifications = append(m.R.UserNotifications, r.o.Build()) } else { rel4, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } err = m.AttachUserNotifications(ctx, exec, rel4...) if err != nil { return err } } } } isUserOauthTokensDone, _ := userRelUserOauthTokensCtx.Value(ctx) if !isUserOauthTokensDone && o.r.UserOauthTokens != nil { ctx = userRelUserOauthTokensCtx.WithValue(ctx, true) for _, r := range o.r.UserOauthTokens { if r.o.alreadyPersisted { m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build()) } else { rel5, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } err = m.AttachUserOauthTokens(ctx, exec, rel5...) 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) if o.r.Organization == nil { UserMods.WithNewOrganization().Apply(ctx, o) } var rel6 *models.Organization if o.r.Organization.o.alreadyPersisted { rel6 = o.r.Organization.o.Build() } else { rel6, err = o.r.Organization.o.Create(ctx, exec) if err != nil { return nil, err } } opt.OrganizationID = omit.From(rel6.ID) m, err := models.Users.Insert(opt).One(ctx, exec) if err != nil { return nil, err } m.R.Organization = rel6 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), UserMods.RandomPasswordHashType(f), UserMods.RandomPasswordHash(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 string) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.DisplayName = func() string { return val } }) } // Set the Column from the function func (m userMods) DisplayNameFunc(f func() 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 func (m userMods) RandomDisplayName(f *faker.Faker) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.DisplayName = func() string { return random_string(f, "200") } }) } // 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 int32) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.OrganizationID = func() int32 { return val } }) } // Set the Column from the function func (m userMods) OrganizationIDFunc(f func() 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 func (m userMods) RandomOrganizationID(f *faker.Faker) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.OrganizationID = func() int32 { return random_int32(f) } }) } // 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) } }) } // Set the model columns to this value func (m userMods) PasswordHashType(val enums.Hashtype) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHashType = func() enums.Hashtype { return val } }) } // Set the Column from the function func (m userMods) PasswordHashTypeFunc(f func() enums.Hashtype) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHashType = f }) } // Clear any values for the column func (m userMods) UnsetPasswordHashType() UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHashType = nil }) } // Generates a random value for the column using the given faker // if faker is nil, a default faker is used func (m userMods) RandomPasswordHashType(f *faker.Faker) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHashType = func() enums.Hashtype { return random_enums_Hashtype(f) } }) } // Set the model columns to this value func (m userMods) PasswordHash(val string) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHash = func() string { return val } }) } // Set the Column from the function func (m userMods) PasswordHashFunc(f func() string) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHash = f }) } // Clear any values for the column func (m userMods) UnsetPasswordHash() UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHash = nil }) } // Generates a random value for the column using the given faker // if faker is nil, a default faker is used func (m userMods) RandomPasswordHash(f *faker.Faker) UserMod { return UserModFunc(func(_ context.Context, o *UserTemplate) { o.PasswordHash = 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 }) } func (m userMods) WithCreatorNoteAudios(number int, related *NoteAudioTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteAudios = []*userRCreatorNoteAudiosR{{ number: number, o: related, }} }) } func (m userMods) WithNewCreatorNoteAudios(number int, mods ...NoteAudioMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteAudioWithContext(ctx, mods...) m.WithCreatorNoteAudios(number, related).Apply(ctx, o) }) } func (m userMods) AddCreatorNoteAudios(number int, related *NoteAudioTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteAudios = append(o.r.CreatorNoteAudios, &userRCreatorNoteAudiosR{ number: number, o: related, }) }) } func (m userMods) AddNewCreatorNoteAudios(number int, mods ...NoteAudioMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteAudioWithContext(ctx, mods...) m.AddCreatorNoteAudios(number, related).Apply(ctx, o) }) } func (m userMods) AddExistingCreatorNoteAudios(existingModels ...*models.NoteAudio) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { for _, em := range existingModels { o.r.CreatorNoteAudios = append(o.r.CreatorNoteAudios, &userRCreatorNoteAudiosR{ o: o.f.FromExistingNoteAudio(em), }) } }) } func (m userMods) WithoutCreatorNoteAudios() UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteAudios = nil }) } func (m userMods) WithDeletorNoteAudios(number int, related *NoteAudioTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.DeletorNoteAudios = []*userRDeletorNoteAudiosR{{ number: number, o: related, }} }) } func (m userMods) WithNewDeletorNoteAudios(number int, mods ...NoteAudioMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteAudioWithContext(ctx, mods...) m.WithDeletorNoteAudios(number, related).Apply(ctx, o) }) } func (m userMods) AddDeletorNoteAudios(number int, related *NoteAudioTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.DeletorNoteAudios = append(o.r.DeletorNoteAudios, &userRDeletorNoteAudiosR{ number: number, o: related, }) }) } func (m userMods) AddNewDeletorNoteAudios(number int, mods ...NoteAudioMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteAudioWithContext(ctx, mods...) m.AddDeletorNoteAudios(number, related).Apply(ctx, o) }) } func (m userMods) AddExistingDeletorNoteAudios(existingModels ...*models.NoteAudio) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { for _, em := range existingModels { o.r.DeletorNoteAudios = append(o.r.DeletorNoteAudios, &userRDeletorNoteAudiosR{ o: o.f.FromExistingNoteAudio(em), }) } }) } func (m userMods) WithoutDeletorNoteAudios() UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.DeletorNoteAudios = nil }) } func (m userMods) WithCreatorNoteImages(number int, related *NoteImageTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteImages = []*userRCreatorNoteImagesR{{ number: number, o: related, }} }) } func (m userMods) WithNewCreatorNoteImages(number int, mods ...NoteImageMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteImageWithContext(ctx, mods...) m.WithCreatorNoteImages(number, related).Apply(ctx, o) }) } func (m userMods) AddCreatorNoteImages(number int, related *NoteImageTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteImages = append(o.r.CreatorNoteImages, &userRCreatorNoteImagesR{ number: number, o: related, }) }) } func (m userMods) AddNewCreatorNoteImages(number int, mods ...NoteImageMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteImageWithContext(ctx, mods...) m.AddCreatorNoteImages(number, related).Apply(ctx, o) }) } func (m userMods) AddExistingCreatorNoteImages(existingModels ...*models.NoteImage) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { for _, em := range existingModels { o.r.CreatorNoteImages = append(o.r.CreatorNoteImages, &userRCreatorNoteImagesR{ o: o.f.FromExistingNoteImage(em), }) } }) } func (m userMods) WithoutCreatorNoteImages() UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteImages = nil }) } func (m userMods) WithDeletorNoteImages(number int, related *NoteImageTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.DeletorNoteImages = []*userRDeletorNoteImagesR{{ number: number, o: related, }} }) } func (m userMods) WithNewDeletorNoteImages(number int, mods ...NoteImageMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteImageWithContext(ctx, mods...) m.WithDeletorNoteImages(number, related).Apply(ctx, o) }) } func (m userMods) AddDeletorNoteImages(number int, related *NoteImageTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.DeletorNoteImages = append(o.r.DeletorNoteImages, &userRDeletorNoteImagesR{ number: number, o: related, }) }) } func (m userMods) AddNewDeletorNoteImages(number int, mods ...NoteImageMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNoteImageWithContext(ctx, mods...) m.AddDeletorNoteImages(number, related).Apply(ctx, o) }) } func (m userMods) AddExistingDeletorNoteImages(existingModels ...*models.NoteImage) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { for _, em := range existingModels { o.r.DeletorNoteImages = append(o.r.DeletorNoteImages, &userRDeletorNoteImagesR{ o: o.f.FromExistingNoteImage(em), }) } }) } func (m userMods) WithoutDeletorNoteImages() UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.DeletorNoteImages = nil }) } func (m userMods) WithUserNotifications(number int, related *NotificationTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.UserNotifications = []*userRUserNotificationsR{{ number: number, o: related, }} }) } func (m userMods) WithNewUserNotifications(number int, mods ...NotificationMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNotificationWithContext(ctx, mods...) m.WithUserNotifications(number, related).Apply(ctx, o) }) } func (m userMods) AddUserNotifications(number int, related *NotificationTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.UserNotifications = append(o.r.UserNotifications, &userRUserNotificationsR{ number: number, o: related, }) }) } func (m userMods) AddNewUserNotifications(number int, mods ...NotificationMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewNotificationWithContext(ctx, mods...) m.AddUserNotifications(number, related).Apply(ctx, o) }) } func (m userMods) AddExistingUserNotifications(existingModels ...*models.Notification) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { for _, em := range existingModels { o.r.UserNotifications = append(o.r.UserNotifications, &userRUserNotificationsR{ o: o.f.FromExistingNotification(em), }) } }) } func (m userMods) WithoutUserNotifications() UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.UserNotifications = nil }) } func (m userMods) WithUserOauthTokens(number int, related *OauthTokenTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.UserOauthTokens = []*userRUserOauthTokensR{{ number: number, o: related, }} }) } func (m userMods) WithNewUserOauthTokens(number int, mods ...OauthTokenMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewOauthTokenWithContext(ctx, mods...) m.WithUserOauthTokens(number, related).Apply(ctx, o) }) } func (m userMods) AddUserOauthTokens(number int, related *OauthTokenTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{ number: number, o: related, }) }) } func (m userMods) AddNewUserOauthTokens(number int, mods ...OauthTokenMod) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { related := o.f.NewOauthTokenWithContext(ctx, mods...) m.AddUserOauthTokens(number, related).Apply(ctx, o) }) } func (m userMods) AddExistingUserOauthTokens(existingModels ...*models.OauthToken) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { for _, em := range existingModels { o.r.UserOauthTokens = append(o.r.UserOauthTokens, &userRUserOauthTokensR{ o: o.f.FromExistingOauthToken(em), }) } }) } func (m userMods) WithoutUserOauthTokens() UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.UserOauthTokens = nil }) }