478 lines
16 KiB
Go
478 lines
16 KiB
Go
// 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
|
|
})
|
|
}
|