Clean up removed generated bob files
This commit is contained in:
parent
29bd1fab5c
commit
b292f47d47
8 changed files with 0 additions and 3247 deletions
|
|
@ -1,17 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var ArcgisFeatureServiceErrors = &arcgisFeatureServiceErrors{
|
||||
ErrUniqueFeatureServicePkey: &UniqueConstraintError{
|
||||
schema: "arcgis",
|
||||
table: "feature_service",
|
||||
columns: []string{"item_id"},
|
||||
s: "feature_service_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceErrors struct {
|
||||
ErrUniqueFeatureServicePkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var OauthTokenErrors = &oauthTokenErrors{
|
||||
ErrUniqueOauthTokenPkey: &UniqueConstraintError{
|
||||
schema: "",
|
||||
table: "oauth_token",
|
||||
columns: []string{"id"},
|
||||
s: "oauth_token_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type oauthTokenErrors struct {
|
||||
ErrUniqueOauthTokenPkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var ArcgisFeatureServices = Table[
|
||||
arcgisFeatureServiceColumns,
|
||||
arcgisFeatureServiceIndexes,
|
||||
arcgisFeatureServiceForeignKeys,
|
||||
arcgisFeatureServiceUniques,
|
||||
arcgisFeatureServiceChecks,
|
||||
]{
|
||||
Schema: "arcgis",
|
||||
Name: "feature_service",
|
||||
Columns: arcgisFeatureServiceColumns{
|
||||
Extent: column{
|
||||
Name: "extent",
|
||||
DBType: "box2d",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ItemID: column{
|
||||
Name: "item_id",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
SpatialReference: column{
|
||||
Name: "spatial_reference",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
URL: column{
|
||||
Name: "url",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: arcgisFeatureServiceIndexes{
|
||||
FeatureServicePkey: index{
|
||||
Type: "btree",
|
||||
Name: "feature_service_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "item_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "feature_service_pkey",
|
||||
Columns: []string{"item_id"},
|
||||
Comment: "",
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceColumns struct {
|
||||
Extent column
|
||||
ItemID column
|
||||
SpatialReference column
|
||||
URL column
|
||||
}
|
||||
|
||||
func (c arcgisFeatureServiceColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Extent, c.ItemID, c.SpatialReference, c.URL,
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceIndexes struct {
|
||||
FeatureServicePkey index
|
||||
}
|
||||
|
||||
func (i arcgisFeatureServiceIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.FeatureServicePkey,
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceForeignKeys struct{}
|
||||
|
||||
func (f arcgisFeatureServiceForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceUniques struct{}
|
||||
|
||||
func (u arcgisFeatureServiceUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceChecks struct{}
|
||||
|
||||
func (c arcgisFeatureServiceChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -1,207 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var OauthTokens = Table[
|
||||
oauthTokenColumns,
|
||||
oauthTokenIndexes,
|
||||
oauthTokenForeignKeys,
|
||||
oauthTokenUniques,
|
||||
oauthTokenChecks,
|
||||
]{
|
||||
Schema: "",
|
||||
Name: "oauth_token",
|
||||
Columns: oauthTokenColumns{
|
||||
ID: column{
|
||||
Name: "id",
|
||||
DBType: "integer",
|
||||
Default: "nextval('oauth_token_id_seq'::regclass)",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AccessToken: column{
|
||||
Name: "access_token",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
AccessTokenExpires: column{
|
||||
Name: "access_token_expires",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
RefreshToken: column{
|
||||
Name: "refresh_token",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Username: column{
|
||||
Name: "username",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
UserID: column{
|
||||
Name: "user_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ArcgisID: column{
|
||||
Name: "arcgis_id",
|
||||
DBType: "text",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ArcgisLicenseTypeID: column{
|
||||
Name: "arcgis_license_type_id",
|
||||
DBType: "text",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
RefreshTokenExpires: column{
|
||||
Name: "refresh_token_expires",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "CURRENT_TIMESTAMP",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
InvalidatedAt: column{
|
||||
Name: "invalidated_at",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: oauthTokenIndexes{
|
||||
OauthTokenPkey: index{
|
||||
Type: "btree",
|
||||
Name: "oauth_token_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "oauth_token_pkey",
|
||||
Columns: []string{"id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: oauthTokenForeignKeys{
|
||||
OauthTokenOauthTokenUserIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "oauth_token.oauth_token_user_id_fkey",
|
||||
Columns: []string{"user_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "user_",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type oauthTokenColumns struct {
|
||||
ID column
|
||||
AccessToken column
|
||||
AccessTokenExpires column
|
||||
RefreshToken column
|
||||
Username column
|
||||
UserID column
|
||||
ArcgisID column
|
||||
ArcgisLicenseTypeID column
|
||||
RefreshTokenExpires column
|
||||
InvalidatedAt column
|
||||
Created column
|
||||
}
|
||||
|
||||
func (c oauthTokenColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.AccessToken, c.AccessTokenExpires, c.RefreshToken, c.Username, c.UserID, c.ArcgisID, c.ArcgisLicenseTypeID, c.RefreshTokenExpires, c.InvalidatedAt, c.Created,
|
||||
}
|
||||
}
|
||||
|
||||
type oauthTokenIndexes struct {
|
||||
OauthTokenPkey index
|
||||
}
|
||||
|
||||
func (i oauthTokenIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.OauthTokenPkey,
|
||||
}
|
||||
}
|
||||
|
||||
type oauthTokenForeignKeys struct {
|
||||
OauthTokenOauthTokenUserIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f oauthTokenForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.OauthTokenOauthTokenUserIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type oauthTokenUniques struct{}
|
||||
|
||||
func (u oauthTokenUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type oauthTokenChecks struct{}
|
||||
|
||||
func (c oauthTokenChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -1,478 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
)
|
||||
|
||||
type ArcgisFeatureServiceMod interface {
|
||||
Apply(context.Context, *ArcgisFeatureServiceTemplate)
|
||||
}
|
||||
|
||||
type ArcgisFeatureServiceModFunc func(context.Context, *ArcgisFeatureServiceTemplate)
|
||||
|
||||
func (f ArcgisFeatureServiceModFunc) Apply(ctx context.Context, n *ArcgisFeatureServiceTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type ArcgisFeatureServiceModSlice []ArcgisFeatureServiceMod
|
||||
|
||||
func (mods ArcgisFeatureServiceModSlice) Apply(ctx context.Context, n *ArcgisFeatureServiceTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// ArcgisFeatureServiceTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type ArcgisFeatureServiceTemplate struct {
|
||||
Extent func() string
|
||||
ItemID func() string
|
||||
SpatialReference func() int32
|
||||
URL func() string
|
||||
|
||||
r arcgisFeatureServiceR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceR struct {
|
||||
FeatureServiceItemLayers []*arcgisFeatureServiceRFeatureServiceItemLayersR
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceRFeatureServiceItemLayersR struct {
|
||||
number int
|
||||
o *ArcgisLayerTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the ArcgisFeatureServiceTemplate
|
||||
func (o *ArcgisFeatureServiceTemplate) Apply(ctx context.Context, mods ...ArcgisFeatureServiceMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.ArcgisFeatureService
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t ArcgisFeatureServiceTemplate) setModelRels(o *models.ArcgisFeatureService) {
|
||||
if t.r.FeatureServiceItemLayers != nil {
|
||||
rel := models.ArcgisLayerSlice{}
|
||||
for _, r := range t.r.FeatureServiceItemLayers {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.FeatureServiceItemID = o.ItemID // h2
|
||||
rel.R.FeatureServiceItemFeatureService = o
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.FeatureServiceItemLayers = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.ArcgisFeatureServiceSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o ArcgisFeatureServiceTemplate) BuildSetter() *models.ArcgisFeatureServiceSetter {
|
||||
m := &models.ArcgisFeatureServiceSetter{}
|
||||
|
||||
if o.Extent != nil {
|
||||
val := o.Extent()
|
||||
m.Extent = omit.From(val)
|
||||
}
|
||||
if o.ItemID != nil {
|
||||
val := o.ItemID()
|
||||
m.ItemID = omit.From(val)
|
||||
}
|
||||
if o.SpatialReference != nil {
|
||||
val := o.SpatialReference()
|
||||
m.SpatialReference = omit.From(val)
|
||||
}
|
||||
if o.URL != nil {
|
||||
val := o.URL()
|
||||
m.URL = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.ArcgisFeatureServiceSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o ArcgisFeatureServiceTemplate) BuildManySetter(number int) []*models.ArcgisFeatureServiceSetter {
|
||||
m := make([]*models.ArcgisFeatureServiceSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.ArcgisFeatureService
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use ArcgisFeatureServiceTemplate.Create
|
||||
func (o ArcgisFeatureServiceTemplate) Build() *models.ArcgisFeatureService {
|
||||
m := &models.ArcgisFeatureService{}
|
||||
|
||||
if o.Extent != nil {
|
||||
m.Extent = o.Extent()
|
||||
}
|
||||
if o.ItemID != nil {
|
||||
m.ItemID = o.ItemID()
|
||||
}
|
||||
if o.SpatialReference != nil {
|
||||
m.SpatialReference = o.SpatialReference()
|
||||
}
|
||||
if o.URL != nil {
|
||||
m.URL = o.URL()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.ArcgisFeatureServiceSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use ArcgisFeatureServiceTemplate.CreateMany
|
||||
func (o ArcgisFeatureServiceTemplate) BuildMany(number int) models.ArcgisFeatureServiceSlice {
|
||||
m := make(models.ArcgisFeatureServiceSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatableArcgisFeatureService(m *models.ArcgisFeatureServiceSetter) {
|
||||
if !(m.Extent.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Extent = omit.From(val)
|
||||
}
|
||||
if !(m.ItemID.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.ItemID = omit.From(val)
|
||||
}
|
||||
if !(m.SpatialReference.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.SpatialReference = omit.From(val)
|
||||
}
|
||||
if !(m.URL.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.URL = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.ArcgisFeatureService
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *ArcgisFeatureServiceTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.ArcgisFeatureService) error {
|
||||
var err error
|
||||
|
||||
isFeatureServiceItemLayersDone, _ := arcgisFeatureServiceRelFeatureServiceItemLayersCtx.Value(ctx)
|
||||
if !isFeatureServiceItemLayersDone && o.r.FeatureServiceItemLayers != nil {
|
||||
ctx = arcgisFeatureServiceRelFeatureServiceItemLayersCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.FeatureServiceItemLayers {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.FeatureServiceItemLayers = append(m.R.FeatureServiceItemLayers, r.o.Build())
|
||||
} else {
|
||||
rel0, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachFeatureServiceItemLayers(ctx, exec, rel0...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a arcgisFeatureService and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *ArcgisFeatureServiceTemplate) Create(ctx context.Context, exec bob.Executor) (*models.ArcgisFeatureService, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatableArcgisFeatureService(opt)
|
||||
|
||||
m, err := models.ArcgisFeatureServices.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 arcgisFeatureService and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *ArcgisFeatureServiceTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.ArcgisFeatureService {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a arcgisFeatureService 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 *ArcgisFeatureServiceTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.ArcgisFeatureService {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple arcgisFeatureServices and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o ArcgisFeatureServiceTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.ArcgisFeatureServiceSlice, error) {
|
||||
var err error
|
||||
m := make(models.ArcgisFeatureServiceSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple arcgisFeatureServices and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o ArcgisFeatureServiceTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.ArcgisFeatureServiceSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple arcgisFeatureServices 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 ArcgisFeatureServiceTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.ArcgisFeatureServiceSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ArcgisFeatureService has methods that act as mods for the ArcgisFeatureServiceTemplate
|
||||
var ArcgisFeatureServiceMods arcgisFeatureServiceMods
|
||||
|
||||
type arcgisFeatureServiceMods struct{}
|
||||
|
||||
func (m arcgisFeatureServiceMods) RandomizeAllColumns(f *faker.Faker) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModSlice{
|
||||
ArcgisFeatureServiceMods.RandomExtent(f),
|
||||
ArcgisFeatureServiceMods.RandomItemID(f),
|
||||
ArcgisFeatureServiceMods.RandomSpatialReference(f),
|
||||
ArcgisFeatureServiceMods.RandomURL(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m arcgisFeatureServiceMods) Extent(val string) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.Extent = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m arcgisFeatureServiceMods) ExtentFunc(f func() string) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.Extent = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m arcgisFeatureServiceMods) UnsetExtent() ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.Extent = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m arcgisFeatureServiceMods) RandomExtent(f *faker.Faker) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.Extent = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m arcgisFeatureServiceMods) ItemID(val string) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.ItemID = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m arcgisFeatureServiceMods) ItemIDFunc(f func() string) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.ItemID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m arcgisFeatureServiceMods) UnsetItemID() ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.ItemID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m arcgisFeatureServiceMods) RandomItemID(f *faker.Faker) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.ItemID = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m arcgisFeatureServiceMods) SpatialReference(val int32) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.SpatialReference = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m arcgisFeatureServiceMods) SpatialReferenceFunc(f func() int32) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.SpatialReference = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m arcgisFeatureServiceMods) UnsetSpatialReference() ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.SpatialReference = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m arcgisFeatureServiceMods) RandomSpatialReference(f *faker.Faker) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.SpatialReference = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m arcgisFeatureServiceMods) URL(val string) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.URL = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m arcgisFeatureServiceMods) URLFunc(f func() string) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.URL = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m arcgisFeatureServiceMods) UnsetURL() ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.URL = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m arcgisFeatureServiceMods) RandomURL(f *faker.Faker) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(_ context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.URL = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) WithParentsCascading() ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
if isDone, _ := arcgisFeatureServiceWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = arcgisFeatureServiceWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) WithFeatureServiceItemLayers(number int, related *ArcgisLayerTemplate) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.r.FeatureServiceItemLayers = []*arcgisFeatureServiceRFeatureServiceItemLayersR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) WithNewFeatureServiceItemLayers(number int, mods ...ArcgisLayerMod) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
related := o.f.NewArcgisLayerWithContext(ctx, mods...)
|
||||
m.WithFeatureServiceItemLayers(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) AddFeatureServiceItemLayers(number int, related *ArcgisLayerTemplate) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.r.FeatureServiceItemLayers = append(o.r.FeatureServiceItemLayers, &arcgisFeatureServiceRFeatureServiceItemLayersR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) AddNewFeatureServiceItemLayers(number int, mods ...ArcgisLayerMod) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
related := o.f.NewArcgisLayerWithContext(ctx, mods...)
|
||||
m.AddFeatureServiceItemLayers(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) AddExistingFeatureServiceItemLayers(existingModels ...*models.ArcgisLayer) ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.FeatureServiceItemLayers = append(o.r.FeatureServiceItemLayers, &arcgisFeatureServiceRFeatureServiceItemLayersR{
|
||||
o: o.f.FromExistingArcgisLayer(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m arcgisFeatureServiceMods) WithoutFeatureServiceItemLayers() ArcgisFeatureServiceMod {
|
||||
return ArcgisFeatureServiceModFunc(func(ctx context.Context, o *ArcgisFeatureServiceTemplate) {
|
||||
o.r.FeatureServiceItemLayers = nil
|
||||
})
|
||||
}
|
||||
|
|
@ -1,814 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. 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"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
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"
|
||||
)
|
||||
|
||||
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
|
||||
AccessTokenExpires func() time.Time
|
||||
RefreshToken func() string
|
||||
Username func() string
|
||||
UserID func() int32
|
||||
ArcgisID func() null.Val[string]
|
||||
ArcgisLicenseTypeID func() null.Val[string]
|
||||
RefreshTokenExpires func() time.Time
|
||||
InvalidatedAt func() null.Val[time.Time]
|
||||
Created func() time.Time
|
||||
|
||||
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.AccessTokenExpires != nil {
|
||||
val := o.AccessTokenExpires()
|
||||
m.AccessTokenExpires = 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)
|
||||
}
|
||||
if o.RefreshTokenExpires != nil {
|
||||
val := o.RefreshTokenExpires()
|
||||
m.RefreshTokenExpires = omit.From(val)
|
||||
}
|
||||
if o.InvalidatedAt != nil {
|
||||
val := o.InvalidatedAt()
|
||||
m.InvalidatedAt = omitnull.FromNull(val)
|
||||
}
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(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.AccessTokenExpires != nil {
|
||||
m.AccessTokenExpires = o.AccessTokenExpires()
|
||||
}
|
||||
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()
|
||||
}
|
||||
if o.RefreshTokenExpires != nil {
|
||||
m.RefreshTokenExpires = o.RefreshTokenExpires()
|
||||
}
|
||||
if o.InvalidatedAt != nil {
|
||||
m.InvalidatedAt = o.InvalidatedAt()
|
||||
}
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
|
||||
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.AccessTokenExpires.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.AccessTokenExpires = 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)
|
||||
}
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = 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.RandomAccessTokenExpires(f),
|
||||
OauthTokenMods.RandomRefreshToken(f),
|
||||
OauthTokenMods.RandomUsername(f),
|
||||
OauthTokenMods.RandomUserID(f),
|
||||
OauthTokenMods.RandomArcgisID(f),
|
||||
OauthTokenMods.RandomArcgisLicenseTypeID(f),
|
||||
OauthTokenMods.RandomRefreshTokenExpires(f),
|
||||
OauthTokenMods.RandomInvalidatedAt(f),
|
||||
OauthTokenMods.RandomCreated(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) AccessTokenExpires(val time.Time) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.AccessTokenExpires = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m oauthTokenMods) AccessTokenExpiresFunc(f func() time.Time) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.AccessTokenExpires = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m oauthTokenMods) UnsetAccessTokenExpires() OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.AccessTokenExpires = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m oauthTokenMods) RandomAccessTokenExpires(f *faker.Faker) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.AccessTokenExpires = 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m oauthTokenMods) RefreshTokenExpires(val time.Time) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.RefreshTokenExpires = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m oauthTokenMods) RefreshTokenExpiresFunc(f func() time.Time) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.RefreshTokenExpires = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m oauthTokenMods) UnsetRefreshTokenExpires() OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.RefreshTokenExpires = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m oauthTokenMods) RandomRefreshTokenExpires(f *faker.Faker) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.RefreshTokenExpires = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m oauthTokenMods) InvalidatedAt(val null.Val[time.Time]) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.InvalidatedAt = func() null.Val[time.Time] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m oauthTokenMods) InvalidatedAtFunc(f func() null.Val[time.Time]) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.InvalidatedAt = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m oauthTokenMods) UnsetInvalidatedAt() OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.InvalidatedAt = 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) RandomInvalidatedAt(f *faker.Faker) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.InvalidatedAt = 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 oauthTokenMods) RandomInvalidatedAtNotNull(f *faker.Faker) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.InvalidatedAt = 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 oauthTokenMods) Created(val time.Time) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.Created = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m oauthTokenMods) CreatedFunc(f func() time.Time) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m oauthTokenMods) UnsetCreated() OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m oauthTokenMods) RandomCreated(f *faker.Faker) OauthTokenMod {
|
||||
return OauthTokenModFunc(func(_ context.Context, o *OauthTokenTemplate) {
|
||||
o.Created = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
|
@ -1,762 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// ArcgisFeatureService is an object representing the database table.
|
||||
type ArcgisFeatureService struct {
|
||||
Extent string `db:"extent" `
|
||||
ItemID string `db:"item_id,pk" `
|
||||
SpatialReference int32 `db:"spatial_reference" `
|
||||
URL string `db:"url" `
|
||||
|
||||
R arcgisFeatureServiceR `db:"-" `
|
||||
|
||||
C arcgisFeatureServiceC `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisFeatureServiceSlice is an alias for a slice of pointers to ArcgisFeatureService.
|
||||
// This should almost always be used instead of []*ArcgisFeatureService.
|
||||
type ArcgisFeatureServiceSlice []*ArcgisFeatureService
|
||||
|
||||
// ArcgisFeatureServices contains methods to work with the feature_service table
|
||||
var ArcgisFeatureServices = psql.NewTablex[*ArcgisFeatureService, ArcgisFeatureServiceSlice, *ArcgisFeatureServiceSetter]("arcgis", "feature_service", buildArcgisFeatureServiceColumns("arcgis.feature_service"))
|
||||
|
||||
// ArcgisFeatureServicesQuery is a query on the feature_service table
|
||||
type ArcgisFeatureServicesQuery = *psql.ViewQuery[*ArcgisFeatureService, ArcgisFeatureServiceSlice]
|
||||
|
||||
// arcgisFeatureServiceR is where relationships are stored.
|
||||
type arcgisFeatureServiceR struct {
|
||||
FeatureServiceItemLayers ArcgisLayerSlice // arcgis.layer.layer_feature_service_item_id_fkey
|
||||
}
|
||||
|
||||
func buildArcgisFeatureServiceColumns(alias string) arcgisFeatureServiceColumns {
|
||||
return arcgisFeatureServiceColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"extent", "item_id", "spatial_reference", "url",
|
||||
).WithParent("arcgis.feature_service"),
|
||||
tableAlias: alias,
|
||||
Extent: psql.Quote(alias, "extent"),
|
||||
ItemID: psql.Quote(alias, "item_id"),
|
||||
SpatialReference: psql.Quote(alias, "spatial_reference"),
|
||||
URL: psql.Quote(alias, "url"),
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Extent psql.Expression
|
||||
ItemID psql.Expression
|
||||
SpatialReference psql.Expression
|
||||
URL psql.Expression
|
||||
}
|
||||
|
||||
func (c arcgisFeatureServiceColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (arcgisFeatureServiceColumns) AliasedAs(alias string) arcgisFeatureServiceColumns {
|
||||
return buildArcgisFeatureServiceColumns(alias)
|
||||
}
|
||||
|
||||
// ArcgisFeatureServiceSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ArcgisFeatureServiceSetter struct {
|
||||
Extent omit.Val[string] `db:"extent" `
|
||||
ItemID omit.Val[string] `db:"item_id,pk" `
|
||||
SpatialReference omit.Val[int32] `db:"spatial_reference" `
|
||||
URL omit.Val[string] `db:"url" `
|
||||
}
|
||||
|
||||
func (s ArcgisFeatureServiceSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
if s.Extent.IsValue() {
|
||||
vals = append(vals, "extent")
|
||||
}
|
||||
if s.ItemID.IsValue() {
|
||||
vals = append(vals, "item_id")
|
||||
}
|
||||
if s.SpatialReference.IsValue() {
|
||||
vals = append(vals, "spatial_reference")
|
||||
}
|
||||
if s.URL.IsValue() {
|
||||
vals = append(vals, "url")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ArcgisFeatureServiceSetter) Overwrite(t *ArcgisFeatureService) {
|
||||
if s.Extent.IsValue() {
|
||||
t.Extent = s.Extent.MustGet()
|
||||
}
|
||||
if s.ItemID.IsValue() {
|
||||
t.ItemID = s.ItemID.MustGet()
|
||||
}
|
||||
if s.SpatialReference.IsValue() {
|
||||
t.SpatialReference = s.SpatialReference.MustGet()
|
||||
}
|
||||
if s.URL.IsValue() {
|
||||
t.URL = s.URL.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ArcgisFeatureServiceSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisFeatureServices.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 4)
|
||||
if s.Extent.IsValue() {
|
||||
vals[0] = psql.Arg(s.Extent.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ItemID.IsValue() {
|
||||
vals[1] = psql.Arg(s.ItemID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.SpatialReference.IsValue() {
|
||||
vals[2] = psql.Arg(s.SpatialReference.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.URL.IsValue() {
|
||||
vals[3] = psql.Arg(s.URL.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ArcgisFeatureServiceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ArcgisFeatureServiceSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
|
||||
if s.Extent.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "extent")...),
|
||||
psql.Arg(s.Extent),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ItemID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "item_id")...),
|
||||
psql.Arg(s.ItemID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.SpatialReference.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "spatial_reference")...),
|
||||
psql.Arg(s.SpatialReference),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.URL.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "url")...),
|
||||
psql.Arg(s.URL),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindArcgisFeatureService retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindArcgisFeatureService(ctx context.Context, exec bob.Executor, ItemIDPK string, cols ...string) (*ArcgisFeatureService, error) {
|
||||
if len(cols) == 0 {
|
||||
return ArcgisFeatureServices.Query(
|
||||
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(ItemIDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return ArcgisFeatureServices.Query(
|
||||
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(ItemIDPK))),
|
||||
sm.Columns(ArcgisFeatureServices.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ArcgisFeatureServiceExists checks the presence of a single record by primary key
|
||||
func ArcgisFeatureServiceExists(ctx context.Context, exec bob.Executor, ItemIDPK string) (bool, error) {
|
||||
return ArcgisFeatureServices.Query(
|
||||
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(ItemIDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisFeatureService is retrieved from the database
|
||||
func (o *ArcgisFeatureService) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisFeatureServices.AfterSelectHooks.RunHooks(ctx, exec, ArcgisFeatureServiceSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisFeatureServices.AfterInsertHooks.RunHooks(ctx, exec, ArcgisFeatureServiceSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisFeatureServices.AfterUpdateHooks.RunHooks(ctx, exec, ArcgisFeatureServiceSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisFeatureServices.AfterDeleteHooks.RunHooks(ctx, exec, ArcgisFeatureServiceSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the ArcgisFeatureService
|
||||
func (o *ArcgisFeatureService) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ItemID)
|
||||
}
|
||||
|
||||
func (o *ArcgisFeatureService) pkEQ() dialect.Expression {
|
||||
return psql.Quote("arcgis.feature_service", "item_id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the ArcgisFeatureService
|
||||
func (o *ArcgisFeatureService) Update(ctx context.Context, exec bob.Executor, s *ArcgisFeatureServiceSetter) error {
|
||||
v, err := ArcgisFeatureServices.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single ArcgisFeatureService record with an executor
|
||||
func (o *ArcgisFeatureService) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := ArcgisFeatureServices.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the ArcgisFeatureService using the executor
|
||||
func (o *ArcgisFeatureService) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := ArcgisFeatureServices.Query(
|
||||
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(o.ItemID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisFeatureServiceSlice is retrieved from the database
|
||||
func (o ArcgisFeatureServiceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisFeatureServices.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisFeatureServices.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisFeatureServices.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisFeatureServices.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisFeatureServiceSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("arcgis.feature_service", "item_id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o ArcgisFeatureServiceSlice) copyMatchingRows(from ...*ArcgisFeatureService) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ItemID != old.ItemID {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisFeatureServiceSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisFeatureServices.BeforeUpdateHooks.RunHooks(ctx, exec, o)
|
||||
})
|
||||
|
||||
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
|
||||
var err error
|
||||
switch retrieved := retrieved.(type) {
|
||||
case *ArcgisFeatureService:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisFeatureService:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisFeatureServiceSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisFeatureService or a slice of ArcgisFeatureService
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = ArcgisFeatureServices.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisFeatureServiceSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
|
||||
return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisFeatureServices.BeforeDeleteHooks.RunHooks(ctx, exec, o)
|
||||
})
|
||||
|
||||
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
|
||||
var err error
|
||||
switch retrieved := retrieved.(type) {
|
||||
case *ArcgisFeatureService:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisFeatureService:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisFeatureServiceSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisFeatureService or a slice of ArcgisFeatureService
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = ArcgisFeatureServices.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ArcgisFeatureServiceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ArcgisFeatureServiceSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisFeatureServices.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisFeatureServiceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisFeatureServices.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisFeatureServiceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := ArcgisFeatureServices.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FeatureServiceItemLayers starts a query for related objects on arcgis.layer
|
||||
func (o *ArcgisFeatureService) FeatureServiceItemLayers(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayersQuery {
|
||||
return ArcgisLayers.Query(append(mods,
|
||||
sm.Where(ArcgisLayers.Columns.FeatureServiceItemID.EQ(psql.Arg(o.ItemID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisFeatureServiceSlice) FeatureServiceItemLayers(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayersQuery {
|
||||
pkItemID := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkItemID = append(pkItemID, o.ItemID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkItemID), "text[]")),
|
||||
))
|
||||
|
||||
return ArcgisLayers.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisLayers.Columns.FeatureServiceItemID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertArcgisFeatureServiceFeatureServiceItemLayers0(ctx context.Context, exec bob.Executor, arcgisLayers1 []*ArcgisLayerSetter, arcgisFeatureService0 *ArcgisFeatureService) (ArcgisLayerSlice, error) {
|
||||
for i := range arcgisLayers1 {
|
||||
arcgisLayers1[i].FeatureServiceItemID = omit.From(arcgisFeatureService0.ItemID)
|
||||
}
|
||||
|
||||
ret, err := ArcgisLayers.Insert(bob.ToMods(arcgisLayers1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertArcgisFeatureServiceFeatureServiceItemLayers0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachArcgisFeatureServiceFeatureServiceItemLayers0(ctx context.Context, exec bob.Executor, count int, arcgisLayers1 ArcgisLayerSlice, arcgisFeatureService0 *ArcgisFeatureService) (ArcgisLayerSlice, error) {
|
||||
setter := &ArcgisLayerSetter{
|
||||
FeatureServiceItemID: omit.From(arcgisFeatureService0.ItemID),
|
||||
}
|
||||
|
||||
err := arcgisLayers1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisFeatureServiceFeatureServiceItemLayers0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisLayers1, nil
|
||||
}
|
||||
|
||||
func (arcgisFeatureService0 *ArcgisFeatureService) InsertFeatureServiceItemLayers(ctx context.Context, exec bob.Executor, related ...*ArcgisLayerSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
arcgisLayers1, err := insertArcgisFeatureServiceFeatureServiceItemLayers0(ctx, exec, related, arcgisFeatureService0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisFeatureService0.R.FeatureServiceItemLayers = append(arcgisFeatureService0.R.FeatureServiceItemLayers, arcgisLayers1...)
|
||||
|
||||
for _, rel := range arcgisLayers1 {
|
||||
rel.R.FeatureServiceItemFeatureService = arcgisFeatureService0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisFeatureService0 *ArcgisFeatureService) AttachFeatureServiceItemLayers(ctx context.Context, exec bob.Executor, related ...*ArcgisLayer) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
arcgisLayers1 := ArcgisLayerSlice(related)
|
||||
|
||||
_, err = attachArcgisFeatureServiceFeatureServiceItemLayers0(ctx, exec, len(related), arcgisLayers1, arcgisFeatureService0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisFeatureService0.R.FeatureServiceItemLayers = append(arcgisFeatureService0.R.FeatureServiceItemLayers, arcgisLayers1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.FeatureServiceItemFeatureService = arcgisFeatureService0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceWhere[Q psql.Filterable] struct {
|
||||
Extent psql.WhereMod[Q, string]
|
||||
ItemID psql.WhereMod[Q, string]
|
||||
SpatialReference psql.WhereMod[Q, int32]
|
||||
URL psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (arcgisFeatureServiceWhere[Q]) AliasedAs(alias string) arcgisFeatureServiceWhere[Q] {
|
||||
return buildArcgisFeatureServiceWhere[Q](buildArcgisFeatureServiceColumns(alias))
|
||||
}
|
||||
|
||||
func buildArcgisFeatureServiceWhere[Q psql.Filterable](cols arcgisFeatureServiceColumns) arcgisFeatureServiceWhere[Q] {
|
||||
return arcgisFeatureServiceWhere[Q]{
|
||||
Extent: psql.Where[Q, string](cols.Extent),
|
||||
ItemID: psql.Where[Q, string](cols.ItemID),
|
||||
SpatialReference: psql.Where[Q, int32](cols.SpatialReference),
|
||||
URL: psql.Where[Q, string](cols.URL),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ArcgisFeatureService) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "FeatureServiceItemLayers":
|
||||
rels, ok := retrieved.(ArcgisLayerSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisFeatureService cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.FeatureServiceItemLayers = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.FeatureServiceItemFeatureService = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("arcgisFeatureService has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisFeatureServicePreloader struct{}
|
||||
|
||||
func buildArcgisFeatureServicePreloader() arcgisFeatureServicePreloader {
|
||||
return arcgisFeatureServicePreloader{}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceThenLoader[Q orm.Loadable] struct {
|
||||
FeatureServiceItemLayers func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisFeatureServiceThenLoader[Q orm.Loadable]() arcgisFeatureServiceThenLoader[Q] {
|
||||
type FeatureServiceItemLayersLoadInterface interface {
|
||||
LoadFeatureServiceItemLayers(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisFeatureServiceThenLoader[Q]{
|
||||
FeatureServiceItemLayers: thenLoadBuilder[Q](
|
||||
"FeatureServiceItemLayers",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemLayersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFeatureServiceItemLayers(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadFeatureServiceItemLayers loads the arcgisFeatureService's FeatureServiceItemLayers into the .R struct
|
||||
func (o *ArcgisFeatureService) LoadFeatureServiceItemLayers(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.FeatureServiceItemLayers = nil
|
||||
|
||||
related, err := o.FeatureServiceItemLayers(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.FeatureServiceItemFeatureService = o
|
||||
}
|
||||
|
||||
o.R.FeatureServiceItemLayers = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFeatureServiceItemLayers loads the arcgisFeatureService's FeatureServiceItemLayers into the .R struct
|
||||
func (os ArcgisFeatureServiceSlice) LoadFeatureServiceItemLayers(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisLayers, err := os.FeatureServiceItemLayers(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.FeatureServiceItemLayers = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisLayers {
|
||||
|
||||
if !(o.ItemID == rel.FeatureServiceItemID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.FeatureServiceItemFeatureService = o
|
||||
|
||||
o.R.FeatureServiceItemLayers = append(o.R.FeatureServiceItemLayers, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// arcgisFeatureServiceC is where relationship counts are stored.
|
||||
type arcgisFeatureServiceC struct {
|
||||
FeatureServiceItemLayers *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *ArcgisFeatureService) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "FeatureServiceItemLayers":
|
||||
o.C.FeatureServiceItemLayers = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceCountPreloader struct {
|
||||
FeatureServiceItemLayers func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisFeatureServiceCountPreloader() arcgisFeatureServiceCountPreloader {
|
||||
return arcgisFeatureServiceCountPreloader{
|
||||
FeatureServiceItemLayers: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisFeatureService]("FeatureServiceItemLayers", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisFeatureServices.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisLayers.Name()),
|
||||
sm.Where(psql.Quote(ArcgisLayers.Alias(), "feature_service_item_id").EQ(psql.Quote(parent, "item_id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceCountThenLoader[Q orm.Loadable] struct {
|
||||
FeatureServiceItemLayers func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisFeatureServiceCountThenLoader[Q orm.Loadable]() arcgisFeatureServiceCountThenLoader[Q] {
|
||||
type FeatureServiceItemLayersCountInterface interface {
|
||||
LoadCountFeatureServiceItemLayers(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisFeatureServiceCountThenLoader[Q]{
|
||||
FeatureServiceItemLayers: countThenLoadBuilder[Q](
|
||||
"FeatureServiceItemLayers",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemLayersCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountFeatureServiceItemLayers(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountFeatureServiceItemLayers loads the count of FeatureServiceItemLayers into the C struct
|
||||
func (o *ArcgisFeatureService) LoadCountFeatureServiceItemLayers(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.FeatureServiceItemLayers(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.FeatureServiceItemLayers = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountFeatureServiceItemLayers loads the count of FeatureServiceItemLayers for a slice
|
||||
func (os ArcgisFeatureServiceSlice) LoadCountFeatureServiceItemLayers(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountFeatureServiceItemLayers(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisFeatureServiceJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
FeatureServiceItemLayers modAs[Q, arcgisLayerColumns]
|
||||
}
|
||||
|
||||
func (j arcgisFeatureServiceJoins[Q]) aliasedAs(alias string) arcgisFeatureServiceJoins[Q] {
|
||||
return buildArcgisFeatureServiceJoins[Q](buildArcgisFeatureServiceColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisFeatureServiceJoins[Q dialect.Joinable](cols arcgisFeatureServiceColumns, typ string) arcgisFeatureServiceJoins[Q] {
|
||||
return arcgisFeatureServiceJoins[Q]{
|
||||
typ: typ,
|
||||
FeatureServiceItemLayers: modAs[Q, arcgisLayerColumns]{
|
||||
c: ArcgisLayers.Columns,
|
||||
f: func(to arcgisLayerColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisLayers.Name().As(to.Alias())).On(
|
||||
to.FeatureServiceItemID.EQ(cols.ItemID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -1,830 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
)
|
||||
|
||||
// OauthToken is an object representing the database table.
|
||||
type OauthToken struct {
|
||||
ID int32 `db:"id,pk" `
|
||||
AccessToken string `db:"access_token" `
|
||||
AccessTokenExpires time.Time `db:"access_token_expires" `
|
||||
RefreshToken string `db:"refresh_token" `
|
||||
Username string `db:"username" `
|
||||
UserID int32 `db:"user_id" `
|
||||
ArcgisID null.Val[string] `db:"arcgis_id" `
|
||||
ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id" `
|
||||
RefreshTokenExpires time.Time `db:"refresh_token_expires" `
|
||||
InvalidatedAt null.Val[time.Time] `db:"invalidated_at" `
|
||||
Created time.Time `db:"created" `
|
||||
|
||||
R oauthTokenR `db:"-" `
|
||||
}
|
||||
|
||||
// OauthTokenSlice is an alias for a slice of pointers to OauthToken.
|
||||
// This should almost always be used instead of []*OauthToken.
|
||||
type OauthTokenSlice []*OauthToken
|
||||
|
||||
// OauthTokens contains methods to work with the oauth_token table
|
||||
var OauthTokens = psql.NewTablex[*OauthToken, OauthTokenSlice, *OauthTokenSetter]("", "oauth_token", buildOauthTokenColumns("oauth_token"))
|
||||
|
||||
// OauthTokensQuery is a query on the oauth_token table
|
||||
type OauthTokensQuery = *psql.ViewQuery[*OauthToken, OauthTokenSlice]
|
||||
|
||||
// oauthTokenR is where relationships are stored.
|
||||
type oauthTokenR struct {
|
||||
UserUser *User // oauth_token.oauth_token_user_id_fkey
|
||||
}
|
||||
|
||||
func buildOauthTokenColumns(alias string) oauthTokenColumns {
|
||||
return oauthTokenColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "access_token", "access_token_expires", "refresh_token", "username", "user_id", "arcgis_id", "arcgis_license_type_id", "refresh_token_expires", "invalidated_at", "created",
|
||||
).WithParent("oauth_token"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
AccessToken: psql.Quote(alias, "access_token"),
|
||||
AccessTokenExpires: psql.Quote(alias, "access_token_expires"),
|
||||
RefreshToken: psql.Quote(alias, "refresh_token"),
|
||||
Username: psql.Quote(alias, "username"),
|
||||
UserID: psql.Quote(alias, "user_id"),
|
||||
ArcgisID: psql.Quote(alias, "arcgis_id"),
|
||||
ArcgisLicenseTypeID: psql.Quote(alias, "arcgis_license_type_id"),
|
||||
RefreshTokenExpires: psql.Quote(alias, "refresh_token_expires"),
|
||||
InvalidatedAt: psql.Quote(alias, "invalidated_at"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
}
|
||||
}
|
||||
|
||||
type oauthTokenColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ID psql.Expression
|
||||
AccessToken psql.Expression
|
||||
AccessTokenExpires psql.Expression
|
||||
RefreshToken psql.Expression
|
||||
Username psql.Expression
|
||||
UserID psql.Expression
|
||||
ArcgisID psql.Expression
|
||||
ArcgisLicenseTypeID psql.Expression
|
||||
RefreshTokenExpires psql.Expression
|
||||
InvalidatedAt psql.Expression
|
||||
Created psql.Expression
|
||||
}
|
||||
|
||||
func (c oauthTokenColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (oauthTokenColumns) AliasedAs(alias string) oauthTokenColumns {
|
||||
return buildOauthTokenColumns(alias)
|
||||
}
|
||||
|
||||
// OauthTokenSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type OauthTokenSetter struct {
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
AccessToken omit.Val[string] `db:"access_token" `
|
||||
AccessTokenExpires omit.Val[time.Time] `db:"access_token_expires" `
|
||||
RefreshToken omit.Val[string] `db:"refresh_token" `
|
||||
Username omit.Val[string] `db:"username" `
|
||||
UserID omit.Val[int32] `db:"user_id" `
|
||||
ArcgisID omitnull.Val[string] `db:"arcgis_id" `
|
||||
ArcgisLicenseTypeID omitnull.Val[string] `db:"arcgis_license_type_id" `
|
||||
RefreshTokenExpires omit.Val[time.Time] `db:"refresh_token_expires" `
|
||||
InvalidatedAt omitnull.Val[time.Time] `db:"invalidated_at" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
}
|
||||
|
||||
func (s OauthTokenSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 11)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.AccessToken.IsValue() {
|
||||
vals = append(vals, "access_token")
|
||||
}
|
||||
if s.AccessTokenExpires.IsValue() {
|
||||
vals = append(vals, "access_token_expires")
|
||||
}
|
||||
if s.RefreshToken.IsValue() {
|
||||
vals = append(vals, "refresh_token")
|
||||
}
|
||||
if s.Username.IsValue() {
|
||||
vals = append(vals, "username")
|
||||
}
|
||||
if s.UserID.IsValue() {
|
||||
vals = append(vals, "user_id")
|
||||
}
|
||||
if !s.ArcgisID.IsUnset() {
|
||||
vals = append(vals, "arcgis_id")
|
||||
}
|
||||
if !s.ArcgisLicenseTypeID.IsUnset() {
|
||||
vals = append(vals, "arcgis_license_type_id")
|
||||
}
|
||||
if s.RefreshTokenExpires.IsValue() {
|
||||
vals = append(vals, "refresh_token_expires")
|
||||
}
|
||||
if !s.InvalidatedAt.IsUnset() {
|
||||
vals = append(vals, "invalidated_at")
|
||||
}
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s OauthTokenSetter) Overwrite(t *OauthToken) {
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.AccessToken.IsValue() {
|
||||
t.AccessToken = s.AccessToken.MustGet()
|
||||
}
|
||||
if s.AccessTokenExpires.IsValue() {
|
||||
t.AccessTokenExpires = s.AccessTokenExpires.MustGet()
|
||||
}
|
||||
if s.RefreshToken.IsValue() {
|
||||
t.RefreshToken = s.RefreshToken.MustGet()
|
||||
}
|
||||
if s.Username.IsValue() {
|
||||
t.Username = s.Username.MustGet()
|
||||
}
|
||||
if s.UserID.IsValue() {
|
||||
t.UserID = s.UserID.MustGet()
|
||||
}
|
||||
if !s.ArcgisID.IsUnset() {
|
||||
t.ArcgisID = s.ArcgisID.MustGetNull()
|
||||
}
|
||||
if !s.ArcgisLicenseTypeID.IsUnset() {
|
||||
t.ArcgisLicenseTypeID = s.ArcgisLicenseTypeID.MustGetNull()
|
||||
}
|
||||
if s.RefreshTokenExpires.IsValue() {
|
||||
t.RefreshTokenExpires = s.RefreshTokenExpires.MustGet()
|
||||
}
|
||||
if !s.InvalidatedAt.IsUnset() {
|
||||
t.InvalidatedAt = s.InvalidatedAt.MustGetNull()
|
||||
}
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *OauthTokenSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return OauthTokens.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 11)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AccessToken.IsValue() {
|
||||
vals[1] = psql.Arg(s.AccessToken.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.AccessTokenExpires.IsValue() {
|
||||
vals[2] = psql.Arg(s.AccessTokenExpires.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.RefreshToken.IsValue() {
|
||||
vals[3] = psql.Arg(s.RefreshToken.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Username.IsValue() {
|
||||
vals[4] = psql.Arg(s.Username.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.UserID.IsValue() {
|
||||
vals[5] = psql.Arg(s.UserID.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ArcgisID.IsUnset() {
|
||||
vals[6] = psql.Arg(s.ArcgisID.MustGetNull())
|
||||
} else {
|
||||
vals[6] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ArcgisLicenseTypeID.IsUnset() {
|
||||
vals[7] = psql.Arg(s.ArcgisLicenseTypeID.MustGetNull())
|
||||
} else {
|
||||
vals[7] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.RefreshTokenExpires.IsValue() {
|
||||
vals[8] = psql.Arg(s.RefreshTokenExpires.MustGet())
|
||||
} else {
|
||||
vals[8] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.InvalidatedAt.IsUnset() {
|
||||
vals[9] = psql.Arg(s.InvalidatedAt.MustGetNull())
|
||||
} else {
|
||||
vals[9] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
vals[10] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[10] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s OauthTokenSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s OauthTokenSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 11)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AccessToken.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "access_token")...),
|
||||
psql.Arg(s.AccessToken),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.AccessTokenExpires.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "access_token_expires")...),
|
||||
psql.Arg(s.AccessTokenExpires),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.RefreshToken.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "refresh_token")...),
|
||||
psql.Arg(s.RefreshToken),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Username.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "username")...),
|
||||
psql.Arg(s.Username),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.UserID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "user_id")...),
|
||||
psql.Arg(s.UserID),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.ArcgisID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "arcgis_id")...),
|
||||
psql.Arg(s.ArcgisID),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.ArcgisLicenseTypeID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "arcgis_license_type_id")...),
|
||||
psql.Arg(s.ArcgisLicenseTypeID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.RefreshTokenExpires.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "refresh_token_expires")...),
|
||||
psql.Arg(s.RefreshTokenExpires),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.InvalidatedAt.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "invalidated_at")...),
|
||||
psql.Arg(s.InvalidatedAt),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindOauthToken retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindOauthToken(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*OauthToken, error) {
|
||||
if len(cols) == 0 {
|
||||
return OauthTokens.Query(
|
||||
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return OauthTokens.Query(
|
||||
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(OauthTokens.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// OauthTokenExists checks the presence of a single record by primary key
|
||||
func OauthTokenExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return OauthTokens.Query(
|
||||
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after OauthToken is retrieved from the database
|
||||
func (o *OauthToken) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = OauthTokens.AfterSelectHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = OauthTokens.AfterInsertHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = OauthTokens.AfterUpdateHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = OauthTokens.AfterDeleteHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the OauthToken
|
||||
func (o *OauthToken) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *OauthToken) pkEQ() dialect.Expression {
|
||||
return psql.Quote("oauth_token", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the OauthToken
|
||||
func (o *OauthToken) Update(ctx context.Context, exec bob.Executor, s *OauthTokenSetter) error {
|
||||
v, err := OauthTokens.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single OauthToken record with an executor
|
||||
func (o *OauthToken) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := OauthTokens.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the OauthToken using the executor
|
||||
func (o *OauthToken) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := OauthTokens.Query(
|
||||
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(o.ID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after OauthTokenSlice is retrieved from the database
|
||||
func (o OauthTokenSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = OauthTokens.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = OauthTokens.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = OauthTokens.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = OauthTokens.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o OauthTokenSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("oauth_token", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o OauthTokenSlice) copyMatchingRows(from ...*OauthToken) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o OauthTokenSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return OauthTokens.BeforeUpdateHooks.RunHooks(ctx, exec, o)
|
||||
})
|
||||
|
||||
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
|
||||
var err error
|
||||
switch retrieved := retrieved.(type) {
|
||||
case *OauthToken:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*OauthToken:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case OauthTokenSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a OauthToken or a slice of OauthToken
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = OauthTokens.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o OauthTokenSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
|
||||
return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return OauthTokens.BeforeDeleteHooks.RunHooks(ctx, exec, o)
|
||||
})
|
||||
|
||||
q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
|
||||
var err error
|
||||
switch retrieved := retrieved.(type) {
|
||||
case *OauthToken:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*OauthToken:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case OauthTokenSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a OauthToken or a slice of OauthToken
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = OauthTokens.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o OauthTokenSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals OauthTokenSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := OauthTokens.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o OauthTokenSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := OauthTokens.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o OauthTokenSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := OauthTokens.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UserUser starts a query for related objects on user_
|
||||
func (o *OauthToken) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.UserID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OauthTokenSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkUserID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkUserID = append(pkUserID, o.UserID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkUserID), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachOauthTokenUserUser0(ctx context.Context, exec bob.Executor, count int, oauthToken0 *OauthToken, user1 *User) (*OauthToken, error) {
|
||||
setter := &OauthTokenSetter{
|
||||
UserID: omit.From(user1.ID),
|
||||
}
|
||||
|
||||
err := oauthToken0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOauthTokenUserUser0: %w", err)
|
||||
}
|
||||
|
||||
return oauthToken0, nil
|
||||
}
|
||||
|
||||
func (oauthToken0 *OauthToken) InsertUserUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
|
||||
var err error
|
||||
|
||||
user1, err := Users.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachOauthTokenUserUser0(ctx, exec, 1, oauthToken0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
oauthToken0.R.UserUser = user1
|
||||
|
||||
user1.R.UserOauthTokens = append(user1.R.UserOauthTokens, oauthToken0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (oauthToken0 *OauthToken) AttachUserUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachOauthTokenUserUser0(ctx, exec, 1, oauthToken0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
oauthToken0.R.UserUser = user1
|
||||
|
||||
user1.R.UserOauthTokens = append(user1.R.UserOauthTokens, oauthToken0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type oauthTokenWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
AccessToken psql.WhereMod[Q, string]
|
||||
AccessTokenExpires psql.WhereMod[Q, time.Time]
|
||||
RefreshToken psql.WhereMod[Q, string]
|
||||
Username psql.WhereMod[Q, string]
|
||||
UserID psql.WhereMod[Q, int32]
|
||||
ArcgisID psql.WhereNullMod[Q, string]
|
||||
ArcgisLicenseTypeID psql.WhereNullMod[Q, string]
|
||||
RefreshTokenExpires psql.WhereMod[Q, time.Time]
|
||||
InvalidatedAt psql.WhereNullMod[Q, time.Time]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
}
|
||||
|
||||
func (oauthTokenWhere[Q]) AliasedAs(alias string) oauthTokenWhere[Q] {
|
||||
return buildOauthTokenWhere[Q](buildOauthTokenColumns(alias))
|
||||
}
|
||||
|
||||
func buildOauthTokenWhere[Q psql.Filterable](cols oauthTokenColumns) oauthTokenWhere[Q] {
|
||||
return oauthTokenWhere[Q]{
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
AccessToken: psql.Where[Q, string](cols.AccessToken),
|
||||
AccessTokenExpires: psql.Where[Q, time.Time](cols.AccessTokenExpires),
|
||||
RefreshToken: psql.Where[Q, string](cols.RefreshToken),
|
||||
Username: psql.Where[Q, string](cols.Username),
|
||||
UserID: psql.Where[Q, int32](cols.UserID),
|
||||
ArcgisID: psql.WhereNull[Q, string](cols.ArcgisID),
|
||||
ArcgisLicenseTypeID: psql.WhereNull[Q, string](cols.ArcgisLicenseTypeID),
|
||||
RefreshTokenExpires: psql.Where[Q, time.Time](cols.RefreshTokenExpires),
|
||||
InvalidatedAt: psql.WhereNull[Q, time.Time](cols.InvalidatedAt),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OauthToken) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "UserUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("oauthToken cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.UserUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.UserOauthTokens = OauthTokenSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("oauthToken has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type oauthTokenPreloader struct {
|
||||
UserUser func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildOauthTokenPreloader() oauthTokenPreloader {
|
||||
return oauthTokenPreloader{
|
||||
UserUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "UserUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: OauthTokens,
|
||||
To: Users,
|
||||
FromColumns: []string{"user_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type oauthTokenThenLoader[Q orm.Loadable] struct {
|
||||
UserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildOauthTokenThenLoader[Q orm.Loadable]() oauthTokenThenLoader[Q] {
|
||||
type UserUserLoadInterface interface {
|
||||
LoadUserUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return oauthTokenThenLoader[Q]{
|
||||
UserUser: thenLoadBuilder[Q](
|
||||
"UserUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved UserUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadUserUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadUserUser loads the oauthToken's UserUser into the .R struct
|
||||
func (o *OauthToken) LoadUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.UserUser = nil
|
||||
|
||||
related, err := o.UserUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.UserOauthTokens = OauthTokenSlice{o}
|
||||
|
||||
o.R.UserUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadUserUser loads the oauthToken's UserUser into the .R struct
|
||||
func (os OauthTokenSlice) LoadUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.UserUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
|
||||
if !(o.UserID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.UserOauthTokens = append(rel.R.UserOauthTokens, o)
|
||||
|
||||
o.R.UserUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type oauthTokenJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
UserUser modAs[Q, userColumns]
|
||||
}
|
||||
|
||||
func (j oauthTokenJoins[Q]) aliasedAs(alias string) oauthTokenJoins[Q] {
|
||||
return buildOauthTokenJoins[Q](buildOauthTokenColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildOauthTokenJoins[Q dialect.Joinable](cols oauthTokenColumns, typ string) oauthTokenJoins[Q] {
|
||||
return oauthTokenJoins[Q]{
|
||||
typ: typ,
|
||||
UserUser: modAs[Q, userColumns]{
|
||||
c: Users.Columns,
|
||||
f: func(to userColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.UserID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue