nidus-sync/factory/oauth_token.bob.go

669 lines
18 KiB
Go
Raw Normal View History

// 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/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
"github.com/stephenafamo/bob"
)
type OauthTokenMod interface {
Apply(context.Context, *OauthTokenTemplate)
}
type OauthTokenModFunc func(context.Context, *OauthTokenTemplate)
func (f OauthTokenModFunc) Apply(ctx context.Context, n *OauthTokenTemplate) {
f(ctx, n)
}
type OauthTokenModSlice []OauthTokenMod
func (mods OauthTokenModSlice) Apply(ctx context.Context, n *OauthTokenTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// OauthTokenTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type OauthTokenTemplate struct {
ID func() int32
AccessToken func() string
Expires func() time.Time
RefreshToken func() string
Username func() string
UserID func() int32
ArcgisID func() null.Val[string]
ArcgisLicenseTypeID func() null.Val[string]
r oauthTokenR
f *Factory
alreadyPersisted bool
}
type oauthTokenR struct {
UserUser *oauthTokenRUserUserR
}
type oauthTokenRUserUserR struct {
o *UserTemplate
}
// Apply mods to the OauthTokenTemplate
func (o *OauthTokenTemplate) Apply(ctx context.Context, mods ...OauthTokenMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.OauthToken
// according to the relationships in the template. Nothing is inserted into the db
func (t OauthTokenTemplate) setModelRels(o *models.OauthToken) {
if t.r.UserUser != nil {
rel := t.r.UserUser.o.Build()
rel.R.UserOauthTokens = append(rel.R.UserOauthTokens, o)
o.UserID = rel.ID // h2
o.R.UserUser = rel
}
}
// BuildSetter returns an *models.OauthTokenSetter
// this does nothing with the relationship templates
func (o OauthTokenTemplate) BuildSetter() *models.OauthTokenSetter {
m := &models.OauthTokenSetter{}
if o.ID != nil {
val := o.ID()
m.ID = omit.From(val)
}
if o.AccessToken != nil {
val := o.AccessToken()
m.AccessToken = omit.From(val)
}
if o.Expires != nil {
val := o.Expires()
m.Expires = omit.From(val)
}
if o.RefreshToken != nil {
val := o.RefreshToken()
m.RefreshToken = omit.From(val)
}
if o.Username != nil {
val := o.Username()
m.Username = omit.From(val)
}
if o.UserID != nil {
val := o.UserID()
m.UserID = omit.From(val)
}
if o.ArcgisID != nil {
val := o.ArcgisID()
m.ArcgisID = omitnull.FromNull(val)
}
if o.ArcgisLicenseTypeID != nil {
val := o.ArcgisLicenseTypeID()
m.ArcgisLicenseTypeID = omitnull.FromNull(val)
}
return m
}
// BuildManySetter returns an []*models.OauthTokenSetter
// this does nothing with the relationship templates
func (o OauthTokenTemplate) BuildManySetter(number int) []*models.OauthTokenSetter {
m := make([]*models.OauthTokenSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.OauthToken
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use OauthTokenTemplate.Create
func (o OauthTokenTemplate) Build() *models.OauthToken {
m := &models.OauthToken{}
if o.ID != nil {
m.ID = o.ID()
}
if o.AccessToken != nil {
m.AccessToken = o.AccessToken()
}
if o.Expires != nil {
m.Expires = o.Expires()
}
if o.RefreshToken != nil {
m.RefreshToken = o.RefreshToken()
}
if o.Username != nil {
m.Username = o.Username()
}
if o.UserID != nil {
m.UserID = o.UserID()
}
if o.ArcgisID != nil {
m.ArcgisID = o.ArcgisID()
}
if o.ArcgisLicenseTypeID != nil {
m.ArcgisLicenseTypeID = o.ArcgisLicenseTypeID()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.OauthTokenSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use OauthTokenTemplate.CreateMany
func (o OauthTokenTemplate) BuildMany(number int) models.OauthTokenSlice {
m := make(models.OauthTokenSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatableOauthToken(m *models.OauthTokenSetter) {
if !(m.AccessToken.IsValue()) {
val := random_string(nil)
m.AccessToken = omit.From(val)
}
if !(m.Expires.IsValue()) {
val := random_time_Time(nil)
m.Expires = omit.From(val)
}
if !(m.RefreshToken.IsValue()) {
val := random_string(nil)
m.RefreshToken = omit.From(val)
}
if !(m.Username.IsValue()) {
val := random_string(nil)
m.Username = omit.From(val)
}
if !(m.UserID.IsValue()) {
val := random_int32(nil)
m.UserID = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.OauthToken
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *OauthTokenTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.OauthToken) error {
var err error
return err
}
// Create builds a oauthToken and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *OauthTokenTemplate) Create(ctx context.Context, exec bob.Executor) (*models.OauthToken, error) {
var err error
opt := o.BuildSetter()
ensureCreatableOauthToken(opt)
if o.r.UserUser == nil {
OauthTokenMods.WithNewUserUser().Apply(ctx, o)
}
var rel0 *models.User
if o.r.UserUser.o.alreadyPersisted {
rel0 = o.r.UserUser.o.Build()
} else {
rel0, err = o.r.UserUser.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.UserID = omit.From(rel0.ID)
m, err := models.OauthTokens.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.UserUser = rel0
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a oauthToken and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *OauthTokenTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.OauthToken {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a oauthToken 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 *OauthTokenTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.OauthToken {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple oauthTokens and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o OauthTokenTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.OauthTokenSlice, error) {
var err error
m := make(models.OauthTokenSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple oauthTokens and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o OauthTokenTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.OauthTokenSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple oauthTokens 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 OauthTokenTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.OauthTokenSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// OauthToken has methods that act as mods for the OauthTokenTemplate
var OauthTokenMods oauthTokenMods
type oauthTokenMods struct{}
func (m oauthTokenMods) RandomizeAllColumns(f *faker.Faker) OauthTokenMod {
return OauthTokenModSlice{
OauthTokenMods.RandomID(f),
OauthTokenMods.RandomAccessToken(f),
OauthTokenMods.RandomExpires(f),
OauthTokenMods.RandomRefreshToken(f),
OauthTokenMods.RandomUsername(f),
OauthTokenMods.RandomUserID(f),
OauthTokenMods.RandomArcgisID(f),
OauthTokenMods.RandomArcgisLicenseTypeID(f),
}
}
// Set the model columns to this value
func (m oauthTokenMods) ID(val int32) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ID = func() int32 { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) IDFunc(f func() int32) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ID = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetID() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
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 oauthTokenMods) RandomID(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m oauthTokenMods) AccessToken(val string) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.AccessToken = func() string { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) AccessTokenFunc(f func() string) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.AccessToken = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetAccessToken() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.AccessToken = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m oauthTokenMods) RandomAccessToken(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.AccessToken = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m oauthTokenMods) Expires(val time.Time) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Expires = func() time.Time { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) ExpiresFunc(f func() time.Time) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Expires = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetExpires() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Expires = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m oauthTokenMods) RandomExpires(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Expires = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m oauthTokenMods) RefreshToken(val string) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.RefreshToken = func() string { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) RefreshTokenFunc(f func() string) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.RefreshToken = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetRefreshToken() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.RefreshToken = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m oauthTokenMods) RandomRefreshToken(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.RefreshToken = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m oauthTokenMods) Username(val string) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Username = func() string { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) UsernameFunc(f func() string) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Username = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetUsername() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
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 oauthTokenMods) RandomUsername(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.Username = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m oauthTokenMods) UserID(val int32) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.UserID = func() int32 { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) UserIDFunc(f func() int32) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.UserID = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetUserID() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.UserID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m oauthTokenMods) RandomUserID(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.UserID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m oauthTokenMods) ArcgisID(val null.Val[string]) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisID = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) ArcgisIDFunc(f func() null.Val[string]) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisID = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetArcgisID() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisID = 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 oauthTokenMods) RandomArcgisID(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisID = 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 oauthTokenMods) RandomArcgisIDNotNull(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisID = 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 oauthTokenMods) ArcgisLicenseTypeID(val null.Val[string]) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisLicenseTypeID = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m oauthTokenMods) ArcgisLicenseTypeIDFunc(f func() null.Val[string]) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisLicenseTypeID = f
})
}
// Clear any values for the column
func (m oauthTokenMods) UnsetArcgisLicenseTypeID() OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisLicenseTypeID = 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 oauthTokenMods) RandomArcgisLicenseTypeID(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisLicenseTypeID = 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 oauthTokenMods) RandomArcgisLicenseTypeIDNotNull(f *faker.Faker) OauthTokenMod {
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
o.ArcgisLicenseTypeID = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
func (m oauthTokenMods) WithParentsCascading() OauthTokenMod {
return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) {
if isDone, _ := oauthTokenWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = oauthTokenWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading())
m.WithUserUser(related).Apply(ctx, o)
}
})
}
func (m oauthTokenMods) WithUserUser(rel *UserTemplate) OauthTokenMod {
return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) {
o.r.UserUser = &oauthTokenRUserUserR{
o: rel,
}
})
}
func (m oauthTokenMods) WithNewUserUser(mods ...UserMod) OauthTokenMod {
return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) {
related := o.f.NewUserWithContext(ctx, mods...)
m.WithUserUser(related).Apply(ctx, o)
})
}
func (m oauthTokenMods) WithExistingUserUser(em *models.User) OauthTokenMod {
return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) {
o.r.UserUser = &oauthTokenRUserUserR{
o: o.f.FromExistingUser(em),
}
})
}
func (m oauthTokenMods) WithoutUserUser() OauthTokenMod {
return OauthTokenModFunc(func(ctx context.Context, o *OauthTokenTemplate) {
o.r.UserUser = nil
})
}