This is an intermediate step between shifting from the old fs_* prefixed table names to an entire fieldseeker schema. At this point we have both, and we aren't doing much with the new schema but compiling.
1107 lines
30 KiB
Go
1107 lines
30 KiB
Go
// Code generated by BobGen psql v0.42.0. 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() null.Val[int32]
|
|
Username func() string
|
|
PasswordHashType func() enums.Hashtype
|
|
PasswordHash func() string
|
|
|
|
r userR
|
|
f *Factory
|
|
|
|
alreadyPersisted bool
|
|
}
|
|
|
|
type userR struct {
|
|
UserNotifications []*userRUserNotificationsR
|
|
UserOauthTokens []*userRUserOauthTokensR
|
|
Organization *userROrganizationR
|
|
}
|
|
|
|
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.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 = 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 = omit.From(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)
|
|
}
|
|
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.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
|
|
|
|
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 {
|
|
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = m.AttachUserNotifications(ctx, exec, rel0...)
|
|
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 {
|
|
rel1, err := r.o.CreateMany(ctx, exec, r.number)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = m.AttachUserOauthTokens(ctx, exec, rel1...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 rel2 *models.Organization
|
|
rel2, err = o.r.Organization.o.Create(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = m.AttachOrganization(ctx, exec, rel2)
|
|
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),
|
|
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 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)
|
|
}
|
|
})
|
|
}
|
|
|
|
// 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) 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
|
|
})
|
|
}
|