Add new tables for storing parcel and address data
This commit is contained in:
parent
060e2915f1
commit
7b1ffbab12
55 changed files with 18008 additions and 170 deletions
810
db/models/address.bob.go
Normal file
810
db/models/address.bob.go
Normal file
|
|
@ -0,0 +1,810 @@
|
|||
// 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"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// Address is an object representing the database table.
|
||||
type Address struct {
|
||||
Country enums.Countrytype `db:"country" `
|
||||
Created time.Time `db:"created" `
|
||||
Geom string `db:"geom" `
|
||||
H3cell string `db:"h3cell" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Locality string `db:"locality" `
|
||||
Number int32 `db:"number_" `
|
||||
PostalCode string `db:"postal_code" `
|
||||
Street string `db:"street" `
|
||||
Unit string `db:"unit" `
|
||||
|
||||
R addressR `db:"-" `
|
||||
}
|
||||
|
||||
// AddressSlice is an alias for a slice of pointers to Address.
|
||||
// This should almost always be used instead of []*Address.
|
||||
type AddressSlice []*Address
|
||||
|
||||
// Addresses contains methods to work with the address table
|
||||
var Addresses = psql.NewTablex[*Address, AddressSlice, *AddressSetter]("", "address", buildAddressColumns("address"))
|
||||
|
||||
// AddressesQuery is a query on the address table
|
||||
type AddressesQuery = *psql.ViewQuery[*Address, AddressSlice]
|
||||
|
||||
// addressR is where relationships are stored.
|
||||
type addressR struct {
|
||||
Site *Site // site.site_address_id_fkey
|
||||
}
|
||||
|
||||
func buildAddressColumns(alias string) addressColumns {
|
||||
return addressColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"country", "created", "geom", "h3cell", "id", "locality", "number_", "postal_code", "street", "unit",
|
||||
).WithParent("address"),
|
||||
tableAlias: alias,
|
||||
Country: psql.Quote(alias, "country"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Geom: psql.Quote(alias, "geom"),
|
||||
H3cell: psql.Quote(alias, "h3cell"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Locality: psql.Quote(alias, "locality"),
|
||||
Number: psql.Quote(alias, "number_"),
|
||||
PostalCode: psql.Quote(alias, "postal_code"),
|
||||
Street: psql.Quote(alias, "street"),
|
||||
Unit: psql.Quote(alias, "unit"),
|
||||
}
|
||||
}
|
||||
|
||||
type addressColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Country psql.Expression
|
||||
Created psql.Expression
|
||||
Geom psql.Expression
|
||||
H3cell psql.Expression
|
||||
ID psql.Expression
|
||||
Locality psql.Expression
|
||||
Number psql.Expression
|
||||
PostalCode psql.Expression
|
||||
Street psql.Expression
|
||||
Unit psql.Expression
|
||||
}
|
||||
|
||||
func (c addressColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (addressColumns) AliasedAs(alias string) addressColumns {
|
||||
return buildAddressColumns(alias)
|
||||
}
|
||||
|
||||
// AddressSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type AddressSetter struct {
|
||||
Country omit.Val[enums.Countrytype] `db:"country" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Geom omit.Val[string] `db:"geom" `
|
||||
H3cell omit.Val[string] `db:"h3cell" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Locality omit.Val[string] `db:"locality" `
|
||||
Number omit.Val[int32] `db:"number_" `
|
||||
PostalCode omit.Val[string] `db:"postal_code" `
|
||||
Street omit.Val[string] `db:"street" `
|
||||
Unit omit.Val[string] `db:"unit" `
|
||||
}
|
||||
|
||||
func (s AddressSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 10)
|
||||
if s.Country.IsValue() {
|
||||
vals = append(vals, "country")
|
||||
}
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if s.Geom.IsValue() {
|
||||
vals = append(vals, "geom")
|
||||
}
|
||||
if s.H3cell.IsValue() {
|
||||
vals = append(vals, "h3cell")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Locality.IsValue() {
|
||||
vals = append(vals, "locality")
|
||||
}
|
||||
if s.Number.IsValue() {
|
||||
vals = append(vals, "number_")
|
||||
}
|
||||
if s.PostalCode.IsValue() {
|
||||
vals = append(vals, "postal_code")
|
||||
}
|
||||
if s.Street.IsValue() {
|
||||
vals = append(vals, "street")
|
||||
}
|
||||
if s.Unit.IsValue() {
|
||||
vals = append(vals, "unit")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s AddressSetter) Overwrite(t *Address) {
|
||||
if s.Country.IsValue() {
|
||||
t.Country = s.Country.MustGet()
|
||||
}
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
if s.Geom.IsValue() {
|
||||
t.Geom = s.Geom.MustGet()
|
||||
}
|
||||
if s.H3cell.IsValue() {
|
||||
t.H3cell = s.H3cell.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Locality.IsValue() {
|
||||
t.Locality = s.Locality.MustGet()
|
||||
}
|
||||
if s.Number.IsValue() {
|
||||
t.Number = s.Number.MustGet()
|
||||
}
|
||||
if s.PostalCode.IsValue() {
|
||||
t.PostalCode = s.PostalCode.MustGet()
|
||||
}
|
||||
if s.Street.IsValue() {
|
||||
t.Street = s.Street.MustGet()
|
||||
}
|
||||
if s.Unit.IsValue() {
|
||||
t.Unit = s.Unit.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AddressSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return Addresses.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, 10)
|
||||
if s.Country.IsValue() {
|
||||
vals[0] = psql.Arg(s.Country.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
vals[1] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Geom.IsValue() {
|
||||
vals[2] = psql.Arg(s.Geom.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.H3cell.IsValue() {
|
||||
vals[3] = psql.Arg(s.H3cell.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[4] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Locality.IsValue() {
|
||||
vals[5] = psql.Arg(s.Locality.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Number.IsValue() {
|
||||
vals[6] = psql.Arg(s.Number.MustGet())
|
||||
} else {
|
||||
vals[6] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.PostalCode.IsValue() {
|
||||
vals[7] = psql.Arg(s.PostalCode.MustGet())
|
||||
} else {
|
||||
vals[7] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Street.IsValue() {
|
||||
vals[8] = psql.Arg(s.Street.MustGet())
|
||||
} else {
|
||||
vals[8] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Unit.IsValue() {
|
||||
vals[9] = psql.Arg(s.Unit.MustGet())
|
||||
} else {
|
||||
vals[9] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s AddressSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s AddressSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 10)
|
||||
|
||||
if s.Country.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "country")...),
|
||||
psql.Arg(s.Country),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Geom.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "geom")...),
|
||||
psql.Arg(s.Geom),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.H3cell.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "h3cell")...),
|
||||
psql.Arg(s.H3cell),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Locality.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "locality")...),
|
||||
psql.Arg(s.Locality),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Number.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "number_")...),
|
||||
psql.Arg(s.Number),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.PostalCode.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "postal_code")...),
|
||||
psql.Arg(s.PostalCode),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Street.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "street")...),
|
||||
psql.Arg(s.Street),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Unit.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "unit")...),
|
||||
psql.Arg(s.Unit),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindAddress retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindAddress(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Address, error) {
|
||||
if len(cols) == 0 {
|
||||
return Addresses.Query(
|
||||
sm.Where(Addresses.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return Addresses.Query(
|
||||
sm.Where(Addresses.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(Addresses.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// AddressExists checks the presence of a single record by primary key
|
||||
func AddressExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return Addresses.Query(
|
||||
sm.Where(Addresses.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after Address is retrieved from the database
|
||||
func (o *Address) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = Addresses.AfterSelectHooks.RunHooks(ctx, exec, AddressSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = Addresses.AfterInsertHooks.RunHooks(ctx, exec, AddressSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = Addresses.AfterUpdateHooks.RunHooks(ctx, exec, AddressSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = Addresses.AfterDeleteHooks.RunHooks(ctx, exec, AddressSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the Address
|
||||
func (o *Address) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *Address) pkEQ() dialect.Expression {
|
||||
return psql.Quote("address", "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 Address
|
||||
func (o *Address) Update(ctx context.Context, exec bob.Executor, s *AddressSetter) error {
|
||||
v, err := Addresses.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 Address record with an executor
|
||||
func (o *Address) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := Addresses.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the Address using the executor
|
||||
func (o *Address) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := Addresses.Query(
|
||||
sm.Where(Addresses.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 AddressSlice is retrieved from the database
|
||||
func (o AddressSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = Addresses.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = Addresses.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = Addresses.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = Addresses.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o AddressSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("address", "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 AddressSlice) copyMatchingRows(from ...*Address) {
|
||||
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 AddressSlice) 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 Addresses.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 *Address:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*Address:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case AddressSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a Address or a slice of Address
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = Addresses.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o AddressSlice) 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 Addresses.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 *Address:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*Address:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case AddressSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a Address or a slice of Address
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = Addresses.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o AddressSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AddressSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := Addresses.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o AddressSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := Addresses.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o AddressSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := Addresses.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Site starts a query for related objects on site
|
||||
func (o *Address) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.AddressID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os AddressSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.AddressID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertAddressSite0(ctx context.Context, exec bob.Executor, site1 *SiteSetter, address0 *Address) (*Site, error) {
|
||||
site1.AddressID = omit.From(address0.ID)
|
||||
|
||||
ret, err := Sites.Insert(site1).One(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertAddressSite0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachAddressSite0(ctx context.Context, exec bob.Executor, count int, site1 *Site, address0 *Address) (*Site, error) {
|
||||
setter := &SiteSetter{
|
||||
AddressID: omit.From(address0.ID),
|
||||
}
|
||||
|
||||
err := site1.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachAddressSite0: %w", err)
|
||||
}
|
||||
|
||||
return site1, nil
|
||||
}
|
||||
|
||||
func (address0 *Address) InsertSite(ctx context.Context, exec bob.Executor, related *SiteSetter) error {
|
||||
var err error
|
||||
|
||||
site1, err := insertAddressSite0(ctx, exec, related, address0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
address0.R.Site = site1
|
||||
|
||||
site1.R.Address = address0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (address0 *Address) AttachSite(ctx context.Context, exec bob.Executor, site1 *Site) error {
|
||||
var err error
|
||||
|
||||
_, err = attachAddressSite0(ctx, exec, 1, site1, address0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
address0.R.Site = site1
|
||||
|
||||
site1.R.Address = address0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type addressWhere[Q psql.Filterable] struct {
|
||||
Country psql.WhereMod[Q, enums.Countrytype]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Geom psql.WhereMod[Q, string]
|
||||
H3cell psql.WhereMod[Q, string]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Locality psql.WhereMod[Q, string]
|
||||
Number psql.WhereMod[Q, int32]
|
||||
PostalCode psql.WhereMod[Q, string]
|
||||
Street psql.WhereMod[Q, string]
|
||||
Unit psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (addressWhere[Q]) AliasedAs(alias string) addressWhere[Q] {
|
||||
return buildAddressWhere[Q](buildAddressColumns(alias))
|
||||
}
|
||||
|
||||
func buildAddressWhere[Q psql.Filterable](cols addressColumns) addressWhere[Q] {
|
||||
return addressWhere[Q]{
|
||||
Country: psql.Where[Q, enums.Countrytype](cols.Country),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Geom: psql.Where[Q, string](cols.Geom),
|
||||
H3cell: psql.Where[Q, string](cols.H3cell),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Locality: psql.Where[Q, string](cols.Locality),
|
||||
Number: psql.Where[Q, int32](cols.Number),
|
||||
PostalCode: psql.Where[Q, string](cols.PostalCode),
|
||||
Street: psql.Where[Q, string](cols.Street),
|
||||
Unit: psql.Where[Q, string](cols.Unit),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Address) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Site":
|
||||
rel, ok := retrieved.(*Site)
|
||||
if !ok {
|
||||
return fmt.Errorf("address cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Site = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Address = o
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("address has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type addressPreloader struct {
|
||||
Site func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildAddressPreloader() addressPreloader {
|
||||
return addressPreloader{
|
||||
Site: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Site, SiteSlice](psql.PreloadRel{
|
||||
Name: "Site",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: Addresses,
|
||||
To: Sites,
|
||||
FromColumns: []string{"id"},
|
||||
ToColumns: []string{"address_id"},
|
||||
},
|
||||
},
|
||||
}, Sites.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type addressThenLoader[Q orm.Loadable] struct {
|
||||
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
|
||||
type SiteLoadInterface interface {
|
||||
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return addressThenLoader[Q]{
|
||||
Site: thenLoadBuilder[Q](
|
||||
"Site",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadSite(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadSite loads the address's Site into the .R struct
|
||||
func (o *Address) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Site = nil
|
||||
|
||||
related, err := o.Site(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.Address = o
|
||||
|
||||
o.R.Site = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSite loads the address's Site into the .R struct
|
||||
func (os AddressSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sites, err := os.Site(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range sites {
|
||||
|
||||
if !(o.ID == rel.AddressID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Address = o
|
||||
|
||||
o.R.Site = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type addressJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Site modAs[Q, siteColumns]
|
||||
}
|
||||
|
||||
func (j addressJoins[Q]) aliasedAs(alias string) addressJoins[Q] {
|
||||
return buildAddressJoins[Q](buildAddressColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildAddressJoins[Q dialect.Joinable](cols addressColumns, typ string) addressJoins[Q] {
|
||||
return addressJoins[Q]{
|
||||
typ: typ,
|
||||
Site: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
|
||||
to.AddressID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
882
db/models/arcgis.address_mapping.bob.go
Normal file
882
db/models/arcgis.address_mapping.bob.go
Normal file
|
|
@ -0,0 +1,882 @@
|
|||
// 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"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// ArcgisAddressMapping is an object representing the database table.
|
||||
type ArcgisAddressMapping struct {
|
||||
Destination enums.ArcgisMappingdestinationaddress `db:"destination,pk" `
|
||||
LayerFeatureServiceItemID string `db:"layer_feature_service_item_id" `
|
||||
LayerIndex int32 `db:"layer_index" `
|
||||
LayerFieldName string `db:"layer_field_name" `
|
||||
OrganizationID int32 `db:"organization_id,pk" `
|
||||
|
||||
R arcgisAddressMappingR `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisAddressMappingSlice is an alias for a slice of pointers to ArcgisAddressMapping.
|
||||
// This should almost always be used instead of []*ArcgisAddressMapping.
|
||||
type ArcgisAddressMappingSlice []*ArcgisAddressMapping
|
||||
|
||||
// ArcgisAddressMappings contains methods to work with the address_mapping table
|
||||
var ArcgisAddressMappings = psql.NewTablex[*ArcgisAddressMapping, ArcgisAddressMappingSlice, *ArcgisAddressMappingSetter]("arcgis", "address_mapping", buildArcgisAddressMappingColumns("arcgis.address_mapping"))
|
||||
|
||||
// ArcgisAddressMappingsQuery is a query on the address_mapping table
|
||||
type ArcgisAddressMappingsQuery = *psql.ViewQuery[*ArcgisAddressMapping, ArcgisAddressMappingSlice]
|
||||
|
||||
// arcgisAddressMappingR is where relationships are stored.
|
||||
type arcgisAddressMappingR struct {
|
||||
LayerField *ArcgisLayerField // arcgis.address_mapping.address_mapping_layer_feature_service_item_id_layer_index__fkey
|
||||
Organization *Organization // arcgis.address_mapping.address_mapping_organization_id_fkey
|
||||
}
|
||||
|
||||
func buildArcgisAddressMappingColumns(alias string) arcgisAddressMappingColumns {
|
||||
return arcgisAddressMappingColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"destination", "layer_feature_service_item_id", "layer_index", "layer_field_name", "organization_id",
|
||||
).WithParent("arcgis.address_mapping"),
|
||||
tableAlias: alias,
|
||||
Destination: psql.Quote(alias, "destination"),
|
||||
LayerFeatureServiceItemID: psql.Quote(alias, "layer_feature_service_item_id"),
|
||||
LayerIndex: psql.Quote(alias, "layer_index"),
|
||||
LayerFieldName: psql.Quote(alias, "layer_field_name"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisAddressMappingColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Destination psql.Expression
|
||||
LayerFeatureServiceItemID psql.Expression
|
||||
LayerIndex psql.Expression
|
||||
LayerFieldName psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
}
|
||||
|
||||
func (c arcgisAddressMappingColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (arcgisAddressMappingColumns) AliasedAs(alias string) arcgisAddressMappingColumns {
|
||||
return buildArcgisAddressMappingColumns(alias)
|
||||
}
|
||||
|
||||
// ArcgisAddressMappingSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ArcgisAddressMappingSetter struct {
|
||||
Destination omit.Val[enums.ArcgisMappingdestinationaddress] `db:"destination,pk" `
|
||||
LayerFeatureServiceItemID omit.Val[string] `db:"layer_feature_service_item_id" `
|
||||
LayerIndex omit.Val[int32] `db:"layer_index" `
|
||||
LayerFieldName omit.Val[string] `db:"layer_field_name" `
|
||||
OrganizationID omit.Val[int32] `db:"organization_id,pk" `
|
||||
}
|
||||
|
||||
func (s ArcgisAddressMappingSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.Destination.IsValue() {
|
||||
vals = append(vals, "destination")
|
||||
}
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
vals = append(vals, "layer_feature_service_item_id")
|
||||
}
|
||||
if s.LayerIndex.IsValue() {
|
||||
vals = append(vals, "layer_index")
|
||||
}
|
||||
if s.LayerFieldName.IsValue() {
|
||||
vals = append(vals, "layer_field_name")
|
||||
}
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ArcgisAddressMappingSetter) Overwrite(t *ArcgisAddressMapping) {
|
||||
if s.Destination.IsValue() {
|
||||
t.Destination = s.Destination.MustGet()
|
||||
}
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
t.LayerFeatureServiceItemID = s.LayerFeatureServiceItemID.MustGet()
|
||||
}
|
||||
if s.LayerIndex.IsValue() {
|
||||
t.LayerIndex = s.LayerIndex.MustGet()
|
||||
}
|
||||
if s.LayerFieldName.IsValue() {
|
||||
t.LayerFieldName = s.LayerFieldName.MustGet()
|
||||
}
|
||||
if s.OrganizationID.IsValue() {
|
||||
t.OrganizationID = s.OrganizationID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ArcgisAddressMappingSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisAddressMappings.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, 5)
|
||||
if s.Destination.IsValue() {
|
||||
vals[0] = psql.Arg(s.Destination.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
vals[1] = psql.Arg(s.LayerFeatureServiceItemID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LayerIndex.IsValue() {
|
||||
vals[2] = psql.Arg(s.LayerIndex.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LayerFieldName.IsValue() {
|
||||
vals[3] = psql.Arg(s.LayerFieldName.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[4] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ArcgisAddressMappingSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ArcgisAddressMappingSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.Destination.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "destination")...),
|
||||
psql.Arg(s.Destination),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "layer_feature_service_item_id")...),
|
||||
psql.Arg(s.LayerFeatureServiceItemID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.LayerIndex.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "layer_index")...),
|
||||
psql.Arg(s.LayerIndex),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.LayerFieldName.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "layer_field_name")...),
|
||||
psql.Arg(s.LayerFieldName),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "organization_id")...),
|
||||
psql.Arg(s.OrganizationID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindArcgisAddressMapping retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindArcgisAddressMapping(ctx context.Context, exec bob.Executor, OrganizationIDPK int32, DestinationPK enums.ArcgisMappingdestinationaddress, cols ...string) (*ArcgisAddressMapping, error) {
|
||||
if len(cols) == 0 {
|
||||
return ArcgisAddressMappings.Query(
|
||||
sm.Where(ArcgisAddressMappings.Columns.OrganizationID.EQ(psql.Arg(OrganizationIDPK))),
|
||||
sm.Where(ArcgisAddressMappings.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return ArcgisAddressMappings.Query(
|
||||
sm.Where(ArcgisAddressMappings.Columns.OrganizationID.EQ(psql.Arg(OrganizationIDPK))),
|
||||
sm.Where(ArcgisAddressMappings.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Columns(ArcgisAddressMappings.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ArcgisAddressMappingExists checks the presence of a single record by primary key
|
||||
func ArcgisAddressMappingExists(ctx context.Context, exec bob.Executor, OrganizationIDPK int32, DestinationPK enums.ArcgisMappingdestinationaddress) (bool, error) {
|
||||
return ArcgisAddressMappings.Query(
|
||||
sm.Where(ArcgisAddressMappings.Columns.OrganizationID.EQ(psql.Arg(OrganizationIDPK))),
|
||||
sm.Where(ArcgisAddressMappings.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisAddressMapping is retrieved from the database
|
||||
func (o *ArcgisAddressMapping) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisAddressMappings.AfterSelectHooks.RunHooks(ctx, exec, ArcgisAddressMappingSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisAddressMappings.AfterInsertHooks.RunHooks(ctx, exec, ArcgisAddressMappingSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisAddressMappings.AfterUpdateHooks.RunHooks(ctx, exec, ArcgisAddressMappingSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisAddressMappings.AfterDeleteHooks.RunHooks(ctx, exec, ArcgisAddressMappingSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the ArcgisAddressMapping
|
||||
func (o *ArcgisAddressMapping) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.OrganizationID,
|
||||
o.Destination,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *ArcgisAddressMapping) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("arcgis.address_mapping", "organization_id"), psql.Quote("arcgis.address_mapping", "destination")).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 ArcgisAddressMapping
|
||||
func (o *ArcgisAddressMapping) Update(ctx context.Context, exec bob.Executor, s *ArcgisAddressMappingSetter) error {
|
||||
v, err := ArcgisAddressMappings.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 ArcgisAddressMapping record with an executor
|
||||
func (o *ArcgisAddressMapping) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := ArcgisAddressMappings.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the ArcgisAddressMapping using the executor
|
||||
func (o *ArcgisAddressMapping) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := ArcgisAddressMappings.Query(
|
||||
sm.Where(ArcgisAddressMappings.Columns.OrganizationID.EQ(psql.Arg(o.OrganizationID))),
|
||||
sm.Where(ArcgisAddressMappings.Columns.Destination.EQ(psql.Arg(o.Destination))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisAddressMappingSlice is retrieved from the database
|
||||
func (o ArcgisAddressMappingSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisAddressMappings.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisAddressMappings.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisAddressMappings.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisAddressMappings.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisAddressMappingSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("arcgis.address_mapping", "organization_id"), psql.Quote("arcgis.address_mapping", "destination")).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 ArcgisAddressMappingSlice) copyMatchingRows(from ...*ArcgisAddressMapping) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.OrganizationID != old.OrganizationID {
|
||||
continue
|
||||
}
|
||||
if new.Destination != old.Destination {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisAddressMappingSlice) 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 ArcgisAddressMappings.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 *ArcgisAddressMapping:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisAddressMapping:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisAddressMappingSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisAddressMapping or a slice of ArcgisAddressMapping
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = ArcgisAddressMappings.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisAddressMappingSlice) 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 ArcgisAddressMappings.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 *ArcgisAddressMapping:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisAddressMapping:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisAddressMappingSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisAddressMapping or a slice of ArcgisAddressMapping
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = ArcgisAddressMappings.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ArcgisAddressMappingSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ArcgisAddressMappingSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisAddressMappings.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisAddressMappingSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisAddressMappings.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisAddressMappingSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := ArcgisAddressMappings.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LayerField starts a query for related objects on arcgis.layer_field
|
||||
func (o *ArcgisAddressMapping) LayerField(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayerFieldsQuery {
|
||||
return ArcgisLayerFields.Query(append(mods,
|
||||
sm.Where(ArcgisLayerFields.Columns.LayerFeatureServiceItemID.EQ(psql.Arg(o.LayerFeatureServiceItemID))), sm.Where(ArcgisLayerFields.Columns.LayerIndex.EQ(psql.Arg(o.LayerIndex))), sm.Where(ArcgisLayerFields.Columns.Name.EQ(psql.Arg(o.LayerFieldName))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisAddressMappingSlice) LayerField(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayerFieldsQuery {
|
||||
pkLayerFeatureServiceItemID := make(pgtypes.Array[string], 0, len(os))
|
||||
|
||||
pkLayerIndex := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkLayerFieldName := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkLayerFeatureServiceItemID = append(pkLayerFeatureServiceItemID, o.LayerFeatureServiceItemID)
|
||||
pkLayerIndex = append(pkLayerIndex, o.LayerIndex)
|
||||
pkLayerFieldName = append(pkLayerFieldName, o.LayerFieldName)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkLayerFeatureServiceItemID), "text[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkLayerIndex), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkLayerFieldName), "text[]")),
|
||||
))
|
||||
|
||||
return ArcgisLayerFields.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisLayerFields.Columns.LayerFeatureServiceItemID, ArcgisLayerFields.Columns.LayerIndex, ArcgisLayerFields.Columns.Name).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *ArcgisAddressMapping) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisAddressMappingSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkOrganizationID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachArcgisAddressMappingLayerField0(ctx context.Context, exec bob.Executor, count int, arcgisAddressMapping0 *ArcgisAddressMapping, arcgisLayerField1 *ArcgisLayerField) (*ArcgisAddressMapping, error) {
|
||||
setter := &ArcgisAddressMappingSetter{
|
||||
LayerFeatureServiceItemID: omit.From(arcgisLayerField1.LayerFeatureServiceItemID),
|
||||
LayerIndex: omit.From(arcgisLayerField1.LayerIndex),
|
||||
LayerFieldName: omit.From(arcgisLayerField1.Name),
|
||||
}
|
||||
|
||||
err := arcgisAddressMapping0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisAddressMappingLayerField0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisAddressMapping0, nil
|
||||
}
|
||||
|
||||
func (arcgisAddressMapping0 *ArcgisAddressMapping) InsertLayerField(ctx context.Context, exec bob.Executor, related *ArcgisLayerFieldSetter) error {
|
||||
var err error
|
||||
|
||||
arcgisLayerField1, err := ArcgisLayerFields.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisAddressMappingLayerField0(ctx, exec, 1, arcgisAddressMapping0, arcgisLayerField1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisAddressMapping0.R.LayerField = arcgisLayerField1
|
||||
|
||||
arcgisLayerField1.R.AddressMappings = append(arcgisLayerField1.R.AddressMappings, arcgisAddressMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisAddressMapping0 *ArcgisAddressMapping) AttachLayerField(ctx context.Context, exec bob.Executor, arcgisLayerField1 *ArcgisLayerField) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisAddressMappingLayerField0(ctx, exec, 1, arcgisAddressMapping0, arcgisLayerField1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisAddressMapping0.R.LayerField = arcgisLayerField1
|
||||
|
||||
arcgisLayerField1.R.AddressMappings = append(arcgisLayerField1.R.AddressMappings, arcgisAddressMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachArcgisAddressMappingOrganization0(ctx context.Context, exec bob.Executor, count int, arcgisAddressMapping0 *ArcgisAddressMapping, organization1 *Organization) (*ArcgisAddressMapping, error) {
|
||||
setter := &ArcgisAddressMappingSetter{
|
||||
OrganizationID: omit.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := arcgisAddressMapping0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisAddressMappingOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisAddressMapping0, nil
|
||||
}
|
||||
|
||||
func (arcgisAddressMapping0 *ArcgisAddressMapping) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisAddressMappingOrganization0(ctx, exec, 1, arcgisAddressMapping0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisAddressMapping0.R.Organization = organization1
|
||||
|
||||
organization1.R.AddressMappings = append(organization1.R.AddressMappings, arcgisAddressMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisAddressMapping0 *ArcgisAddressMapping) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisAddressMappingOrganization0(ctx, exec, 1, arcgisAddressMapping0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisAddressMapping0.R.Organization = organization1
|
||||
|
||||
organization1.R.AddressMappings = append(organization1.R.AddressMappings, arcgisAddressMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisAddressMappingWhere[Q psql.Filterable] struct {
|
||||
Destination psql.WhereMod[Q, enums.ArcgisMappingdestinationaddress]
|
||||
LayerFeatureServiceItemID psql.WhereMod[Q, string]
|
||||
LayerIndex psql.WhereMod[Q, int32]
|
||||
LayerFieldName psql.WhereMod[Q, string]
|
||||
OrganizationID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (arcgisAddressMappingWhere[Q]) AliasedAs(alias string) arcgisAddressMappingWhere[Q] {
|
||||
return buildArcgisAddressMappingWhere[Q](buildArcgisAddressMappingColumns(alias))
|
||||
}
|
||||
|
||||
func buildArcgisAddressMappingWhere[Q psql.Filterable](cols arcgisAddressMappingColumns) arcgisAddressMappingWhere[Q] {
|
||||
return arcgisAddressMappingWhere[Q]{
|
||||
Destination: psql.Where[Q, enums.ArcgisMappingdestinationaddress](cols.Destination),
|
||||
LayerFeatureServiceItemID: psql.Where[Q, string](cols.LayerFeatureServiceItemID),
|
||||
LayerIndex: psql.Where[Q, int32](cols.LayerIndex),
|
||||
LayerFieldName: psql.Where[Q, string](cols.LayerFieldName),
|
||||
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ArcgisAddressMapping) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "LayerField":
|
||||
rel, ok := retrieved.(*ArcgisLayerField)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisAddressMapping cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.LayerField = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.AddressMappings = ArcgisAddressMappingSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisAddressMapping cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.AddressMappings = ArcgisAddressMappingSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("arcgisAddressMapping has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisAddressMappingPreloader struct {
|
||||
LayerField func(...psql.PreloadOption) psql.Preloader
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisAddressMappingPreloader() arcgisAddressMappingPreloader {
|
||||
return arcgisAddressMappingPreloader{
|
||||
LayerField: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*ArcgisLayerField, ArcgisLayerFieldSlice](psql.PreloadRel{
|
||||
Name: "LayerField",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisAddressMappings,
|
||||
To: ArcgisLayerFields,
|
||||
FromColumns: []string{"layer_feature_service_item_id", "layer_index", "layer_field_name"},
|
||||
ToColumns: []string{"layer_feature_service_item_id", "layer_index", "name"},
|
||||
},
|
||||
},
|
||||
}, ArcgisLayerFields.Columns.Names(), opts...)
|
||||
},
|
||||
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "Organization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisAddressMappings,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"organization_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisAddressMappingThenLoader[Q orm.Loadable] struct {
|
||||
LayerField func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisAddressMappingThenLoader[Q orm.Loadable]() arcgisAddressMappingThenLoader[Q] {
|
||||
type LayerFieldLoadInterface interface {
|
||||
LoadLayerField(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisAddressMappingThenLoader[Q]{
|
||||
LayerField: thenLoadBuilder[Q](
|
||||
"LayerField",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved LayerFieldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadLayerField(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadLayerField loads the arcgisAddressMapping's LayerField into the .R struct
|
||||
func (o *ArcgisAddressMapping) LoadLayerField(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.LayerField = nil
|
||||
|
||||
related, err := o.LayerField(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.AddressMappings = ArcgisAddressMappingSlice{o}
|
||||
|
||||
o.R.LayerField = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadLayerField loads the arcgisAddressMapping's LayerField into the .R struct
|
||||
func (os ArcgisAddressMappingSlice) LoadLayerField(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisLayerFields, err := os.LayerField(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisLayerFields {
|
||||
|
||||
if !(o.LayerFeatureServiceItemID == rel.LayerFeatureServiceItemID) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.LayerIndex == rel.LayerIndex) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.LayerFieldName == rel.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.AddressMappings = append(rel.R.AddressMappings, o)
|
||||
|
||||
o.R.LayerField = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the arcgisAddressMapping's Organization into the .R struct
|
||||
func (o *ArcgisAddressMapping) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Organization = nil
|
||||
|
||||
related, err := o.Organization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.AddressMappings = ArcgisAddressMappingSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the arcgisAddressMapping's Organization into the .R struct
|
||||
func (os ArcgisAddressMappingSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.Organization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
|
||||
if !(o.OrganizationID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.AddressMappings = append(rel.R.AddressMappings, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisAddressMappingJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
LayerField modAs[Q, arcgisLayerFieldColumns]
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
func (j arcgisAddressMappingJoins[Q]) aliasedAs(alias string) arcgisAddressMappingJoins[Q] {
|
||||
return buildArcgisAddressMappingJoins[Q](buildArcgisAddressMappingColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisAddressMappingJoins[Q dialect.Joinable](cols arcgisAddressMappingColumns, typ string) arcgisAddressMappingJoins[Q] {
|
||||
return arcgisAddressMappingJoins[Q]{
|
||||
typ: typ,
|
||||
LayerField: modAs[Q, arcgisLayerFieldColumns]{
|
||||
c: ArcgisLayerFields.Columns,
|
||||
f: func(to arcgisLayerFieldColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisLayerFields.Name().As(to.Alias())).On(
|
||||
to.LayerFeatureServiceItemID.EQ(cols.LayerFeatureServiceItemID), to.LayerIndex.EQ(cols.LayerIndex), to.Name.EQ(cols.LayerFieldName),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Organization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.OrganizationID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
762
db/models/arcgis.feature_service.bob.go
Normal file
762
db/models/arcgis.feature_service.bob.go
Normal file
|
|
@ -0,0 +1,762 @@
|
|||
// 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
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
936
db/models/arcgis.layer.bob.go
Normal file
936
db/models/arcgis.layer.bob.go
Normal file
|
|
@ -0,0 +1,936 @@
|
|||
// 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"
|
||||
)
|
||||
|
||||
// ArcgisLayer is an object representing the database table.
|
||||
type ArcgisLayer struct {
|
||||
Extent string `db:"extent" `
|
||||
FeatureServiceItemID string `db:"feature_service_item_id,pk" `
|
||||
Index int32 `db:"index_,pk" `
|
||||
|
||||
R arcgisLayerR `db:"-" `
|
||||
|
||||
C arcgisLayerC `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisLayerSlice is an alias for a slice of pointers to ArcgisLayer.
|
||||
// This should almost always be used instead of []*ArcgisLayer.
|
||||
type ArcgisLayerSlice []*ArcgisLayer
|
||||
|
||||
// ArcgisLayers contains methods to work with the layer table
|
||||
var ArcgisLayers = psql.NewTablex[*ArcgisLayer, ArcgisLayerSlice, *ArcgisLayerSetter]("arcgis", "layer", buildArcgisLayerColumns("arcgis.layer"))
|
||||
|
||||
// ArcgisLayersQuery is a query on the layer table
|
||||
type ArcgisLayersQuery = *psql.ViewQuery[*ArcgisLayer, ArcgisLayerSlice]
|
||||
|
||||
// arcgisLayerR is where relationships are stored.
|
||||
type arcgisLayerR struct {
|
||||
FeatureServiceItemFeatureService *ArcgisFeatureService // arcgis.layer.layer_feature_service_item_id_fkey
|
||||
LayerFields ArcgisLayerFieldSlice // arcgis.layer_field.layer_field_layer_feature_service_item_id_layer_index_fkey
|
||||
}
|
||||
|
||||
func buildArcgisLayerColumns(alias string) arcgisLayerColumns {
|
||||
return arcgisLayerColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"extent", "feature_service_item_id", "index_",
|
||||
).WithParent("arcgis.layer"),
|
||||
tableAlias: alias,
|
||||
Extent: psql.Quote(alias, "extent"),
|
||||
FeatureServiceItemID: psql.Quote(alias, "feature_service_item_id"),
|
||||
Index: psql.Quote(alias, "index_"),
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisLayerColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Extent psql.Expression
|
||||
FeatureServiceItemID psql.Expression
|
||||
Index psql.Expression
|
||||
}
|
||||
|
||||
func (c arcgisLayerColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (arcgisLayerColumns) AliasedAs(alias string) arcgisLayerColumns {
|
||||
return buildArcgisLayerColumns(alias)
|
||||
}
|
||||
|
||||
// ArcgisLayerSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ArcgisLayerSetter struct {
|
||||
Extent omit.Val[string] `db:"extent" `
|
||||
FeatureServiceItemID omit.Val[string] `db:"feature_service_item_id,pk" `
|
||||
Index omit.Val[int32] `db:"index_,pk" `
|
||||
}
|
||||
|
||||
func (s ArcgisLayerSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 3)
|
||||
if s.Extent.IsValue() {
|
||||
vals = append(vals, "extent")
|
||||
}
|
||||
if s.FeatureServiceItemID.IsValue() {
|
||||
vals = append(vals, "feature_service_item_id")
|
||||
}
|
||||
if s.Index.IsValue() {
|
||||
vals = append(vals, "index_")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ArcgisLayerSetter) Overwrite(t *ArcgisLayer) {
|
||||
if s.Extent.IsValue() {
|
||||
t.Extent = s.Extent.MustGet()
|
||||
}
|
||||
if s.FeatureServiceItemID.IsValue() {
|
||||
t.FeatureServiceItemID = s.FeatureServiceItemID.MustGet()
|
||||
}
|
||||
if s.Index.IsValue() {
|
||||
t.Index = s.Index.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ArcgisLayerSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisLayers.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, 3)
|
||||
if s.Extent.IsValue() {
|
||||
vals[0] = psql.Arg(s.Extent.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.FeatureServiceItemID.IsValue() {
|
||||
vals[1] = psql.Arg(s.FeatureServiceItemID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Index.IsValue() {
|
||||
vals[2] = psql.Arg(s.Index.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ArcgisLayerSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ArcgisLayerSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 3)
|
||||
|
||||
if s.Extent.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "extent")...),
|
||||
psql.Arg(s.Extent),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.FeatureServiceItemID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "feature_service_item_id")...),
|
||||
psql.Arg(s.FeatureServiceItemID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Index.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "index_")...),
|
||||
psql.Arg(s.Index),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindArcgisLayer retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindArcgisLayer(ctx context.Context, exec bob.Executor, FeatureServiceItemIDPK string, IndexPK int32, cols ...string) (*ArcgisLayer, error) {
|
||||
if len(cols) == 0 {
|
||||
return ArcgisLayers.Query(
|
||||
sm.Where(ArcgisLayers.Columns.FeatureServiceItemID.EQ(psql.Arg(FeatureServiceItemIDPK))),
|
||||
sm.Where(ArcgisLayers.Columns.Index.EQ(psql.Arg(IndexPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return ArcgisLayers.Query(
|
||||
sm.Where(ArcgisLayers.Columns.FeatureServiceItemID.EQ(psql.Arg(FeatureServiceItemIDPK))),
|
||||
sm.Where(ArcgisLayers.Columns.Index.EQ(psql.Arg(IndexPK))),
|
||||
sm.Columns(ArcgisLayers.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ArcgisLayerExists checks the presence of a single record by primary key
|
||||
func ArcgisLayerExists(ctx context.Context, exec bob.Executor, FeatureServiceItemIDPK string, IndexPK int32) (bool, error) {
|
||||
return ArcgisLayers.Query(
|
||||
sm.Where(ArcgisLayers.Columns.FeatureServiceItemID.EQ(psql.Arg(FeatureServiceItemIDPK))),
|
||||
sm.Where(ArcgisLayers.Columns.Index.EQ(psql.Arg(IndexPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisLayer is retrieved from the database
|
||||
func (o *ArcgisLayer) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisLayers.AfterSelectHooks.RunHooks(ctx, exec, ArcgisLayerSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisLayers.AfterInsertHooks.RunHooks(ctx, exec, ArcgisLayerSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisLayers.AfterUpdateHooks.RunHooks(ctx, exec, ArcgisLayerSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisLayers.AfterDeleteHooks.RunHooks(ctx, exec, ArcgisLayerSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the ArcgisLayer
|
||||
func (o *ArcgisLayer) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.FeatureServiceItemID,
|
||||
o.Index,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *ArcgisLayer) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("arcgis.layer", "feature_service_item_id"), psql.Quote("arcgis.layer", "index_")).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 ArcgisLayer
|
||||
func (o *ArcgisLayer) Update(ctx context.Context, exec bob.Executor, s *ArcgisLayerSetter) error {
|
||||
v, err := ArcgisLayers.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 ArcgisLayer record with an executor
|
||||
func (o *ArcgisLayer) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := ArcgisLayers.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the ArcgisLayer using the executor
|
||||
func (o *ArcgisLayer) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := ArcgisLayers.Query(
|
||||
sm.Where(ArcgisLayers.Columns.FeatureServiceItemID.EQ(psql.Arg(o.FeatureServiceItemID))),
|
||||
sm.Where(ArcgisLayers.Columns.Index.EQ(psql.Arg(o.Index))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisLayerSlice is retrieved from the database
|
||||
func (o ArcgisLayerSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisLayers.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisLayers.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisLayers.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisLayers.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisLayerSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("arcgis.layer", "feature_service_item_id"), psql.Quote("arcgis.layer", "index_")).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 ArcgisLayerSlice) copyMatchingRows(from ...*ArcgisLayer) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.FeatureServiceItemID != old.FeatureServiceItemID {
|
||||
continue
|
||||
}
|
||||
if new.Index != old.Index {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisLayerSlice) 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 ArcgisLayers.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 *ArcgisLayer:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisLayer:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisLayerSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisLayer or a slice of ArcgisLayer
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = ArcgisLayers.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisLayerSlice) 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 ArcgisLayers.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 *ArcgisLayer:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisLayer:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisLayerSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisLayer or a slice of ArcgisLayer
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = ArcgisLayers.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ArcgisLayerSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ArcgisLayerSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisLayers.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisLayerSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisLayers.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisLayerSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := ArcgisLayers.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FeatureServiceItemFeatureService starts a query for related objects on arcgis.feature_service
|
||||
func (o *ArcgisLayer) FeatureServiceItemFeatureService(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisFeatureServicesQuery {
|
||||
return ArcgisFeatureServices.Query(append(mods,
|
||||
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(o.FeatureServiceItemID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisLayerSlice) FeatureServiceItemFeatureService(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisFeatureServicesQuery {
|
||||
pkFeatureServiceItemID := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkFeatureServiceItemID = append(pkFeatureServiceItemID, o.FeatureServiceItemID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkFeatureServiceItemID), "text[]")),
|
||||
))
|
||||
|
||||
return ArcgisFeatureServices.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisFeatureServices.Columns.ItemID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// LayerFields starts a query for related objects on arcgis.layer_field
|
||||
func (o *ArcgisLayer) LayerFields(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayerFieldsQuery {
|
||||
return ArcgisLayerFields.Query(append(mods,
|
||||
sm.Where(ArcgisLayerFields.Columns.LayerFeatureServiceItemID.EQ(psql.Arg(o.FeatureServiceItemID))), sm.Where(ArcgisLayerFields.Columns.LayerIndex.EQ(psql.Arg(o.Index))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisLayerSlice) LayerFields(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayerFieldsQuery {
|
||||
pkFeatureServiceItemID := make(pgtypes.Array[string], 0, len(os))
|
||||
|
||||
pkIndex := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkFeatureServiceItemID = append(pkFeatureServiceItemID, o.FeatureServiceItemID)
|
||||
pkIndex = append(pkIndex, o.Index)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkFeatureServiceItemID), "text[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkIndex), "integer[]")),
|
||||
))
|
||||
|
||||
return ArcgisLayerFields.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisLayerFields.Columns.LayerFeatureServiceItemID, ArcgisLayerFields.Columns.LayerIndex).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachArcgisLayerFeatureServiceItemFeatureService0(ctx context.Context, exec bob.Executor, count int, arcgisLayer0 *ArcgisLayer, arcgisFeatureService1 *ArcgisFeatureService) (*ArcgisLayer, error) {
|
||||
setter := &ArcgisLayerSetter{
|
||||
FeatureServiceItemID: omit.From(arcgisFeatureService1.ItemID),
|
||||
}
|
||||
|
||||
err := arcgisLayer0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisLayerFeatureServiceItemFeatureService0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisLayer0, nil
|
||||
}
|
||||
|
||||
func (arcgisLayer0 *ArcgisLayer) InsertFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, related *ArcgisFeatureServiceSetter) error {
|
||||
var err error
|
||||
|
||||
arcgisFeatureService1, err := ArcgisFeatureServices.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisLayerFeatureServiceItemFeatureService0(ctx, exec, 1, arcgisLayer0, arcgisFeatureService1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisLayer0.R.FeatureServiceItemFeatureService = arcgisFeatureService1
|
||||
|
||||
arcgisFeatureService1.R.FeatureServiceItemLayers = append(arcgisFeatureService1.R.FeatureServiceItemLayers, arcgisLayer0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisLayer0 *ArcgisLayer) AttachFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, arcgisFeatureService1 *ArcgisFeatureService) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisLayerFeatureServiceItemFeatureService0(ctx, exec, 1, arcgisLayer0, arcgisFeatureService1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisLayer0.R.FeatureServiceItemFeatureService = arcgisFeatureService1
|
||||
|
||||
arcgisFeatureService1.R.FeatureServiceItemLayers = append(arcgisFeatureService1.R.FeatureServiceItemLayers, arcgisLayer0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertArcgisLayerLayerFields0(ctx context.Context, exec bob.Executor, arcgisLayerFields1 []*ArcgisLayerFieldSetter, arcgisLayer0 *ArcgisLayer) (ArcgisLayerFieldSlice, error) {
|
||||
for i := range arcgisLayerFields1 {
|
||||
arcgisLayerFields1[i].LayerFeatureServiceItemID = omit.From(arcgisLayer0.FeatureServiceItemID)
|
||||
arcgisLayerFields1[i].LayerIndex = omit.From(arcgisLayer0.Index)
|
||||
}
|
||||
|
||||
ret, err := ArcgisLayerFields.Insert(bob.ToMods(arcgisLayerFields1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertArcgisLayerLayerFields0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachArcgisLayerLayerFields0(ctx context.Context, exec bob.Executor, count int, arcgisLayerFields1 ArcgisLayerFieldSlice, arcgisLayer0 *ArcgisLayer) (ArcgisLayerFieldSlice, error) {
|
||||
setter := &ArcgisLayerFieldSetter{
|
||||
LayerFeatureServiceItemID: omit.From(arcgisLayer0.FeatureServiceItemID),
|
||||
LayerIndex: omit.From(arcgisLayer0.Index),
|
||||
}
|
||||
|
||||
err := arcgisLayerFields1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisLayerLayerFields0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisLayerFields1, nil
|
||||
}
|
||||
|
||||
func (arcgisLayer0 *ArcgisLayer) InsertLayerFields(ctx context.Context, exec bob.Executor, related ...*ArcgisLayerFieldSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
arcgisLayerFields1, err := insertArcgisLayerLayerFields0(ctx, exec, related, arcgisLayer0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisLayer0.R.LayerFields = append(arcgisLayer0.R.LayerFields, arcgisLayerFields1...)
|
||||
|
||||
for _, rel := range arcgisLayerFields1 {
|
||||
rel.R.Layer = arcgisLayer0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisLayer0 *ArcgisLayer) AttachLayerFields(ctx context.Context, exec bob.Executor, related ...*ArcgisLayerField) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
arcgisLayerFields1 := ArcgisLayerFieldSlice(related)
|
||||
|
||||
_, err = attachArcgisLayerLayerFields0(ctx, exec, len(related), arcgisLayerFields1, arcgisLayer0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisLayer0.R.LayerFields = append(arcgisLayer0.R.LayerFields, arcgisLayerFields1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Layer = arcgisLayer0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisLayerWhere[Q psql.Filterable] struct {
|
||||
Extent psql.WhereMod[Q, string]
|
||||
FeatureServiceItemID psql.WhereMod[Q, string]
|
||||
Index psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (arcgisLayerWhere[Q]) AliasedAs(alias string) arcgisLayerWhere[Q] {
|
||||
return buildArcgisLayerWhere[Q](buildArcgisLayerColumns(alias))
|
||||
}
|
||||
|
||||
func buildArcgisLayerWhere[Q psql.Filterable](cols arcgisLayerColumns) arcgisLayerWhere[Q] {
|
||||
return arcgisLayerWhere[Q]{
|
||||
Extent: psql.Where[Q, string](cols.Extent),
|
||||
FeatureServiceItemID: psql.Where[Q, string](cols.FeatureServiceItemID),
|
||||
Index: psql.Where[Q, int32](cols.Index),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ArcgisLayer) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "FeatureServiceItemFeatureService":
|
||||
rel, ok := retrieved.(*ArcgisFeatureService)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisLayer cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.FeatureServiceItemFeatureService = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.FeatureServiceItemLayers = ArcgisLayerSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "LayerFields":
|
||||
rels, ok := retrieved.(ArcgisLayerFieldSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisLayer cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.LayerFields = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Layer = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("arcgisLayer has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisLayerPreloader struct {
|
||||
FeatureServiceItemFeatureService func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisLayerPreloader() arcgisLayerPreloader {
|
||||
return arcgisLayerPreloader{
|
||||
FeatureServiceItemFeatureService: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*ArcgisFeatureService, ArcgisFeatureServiceSlice](psql.PreloadRel{
|
||||
Name: "FeatureServiceItemFeatureService",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisLayers,
|
||||
To: ArcgisFeatureServices,
|
||||
FromColumns: []string{"feature_service_item_id"},
|
||||
ToColumns: []string{"item_id"},
|
||||
},
|
||||
},
|
||||
}, ArcgisFeatureServices.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisLayerThenLoader[Q orm.Loadable] struct {
|
||||
FeatureServiceItemFeatureService func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
LayerFields func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisLayerThenLoader[Q orm.Loadable]() arcgisLayerThenLoader[Q] {
|
||||
type FeatureServiceItemFeatureServiceLoadInterface interface {
|
||||
LoadFeatureServiceItemFeatureService(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type LayerFieldsLoadInterface interface {
|
||||
LoadLayerFields(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisLayerThenLoader[Q]{
|
||||
FeatureServiceItemFeatureService: thenLoadBuilder[Q](
|
||||
"FeatureServiceItemFeatureService",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemFeatureServiceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFeatureServiceItemFeatureService(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
LayerFields: thenLoadBuilder[Q](
|
||||
"LayerFields",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved LayerFieldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadLayerFields(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadFeatureServiceItemFeatureService loads the arcgisLayer's FeatureServiceItemFeatureService into the .R struct
|
||||
func (o *ArcgisLayer) LoadFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.FeatureServiceItemFeatureService = nil
|
||||
|
||||
related, err := o.FeatureServiceItemFeatureService(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.FeatureServiceItemLayers = ArcgisLayerSlice{o}
|
||||
|
||||
o.R.FeatureServiceItemFeatureService = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFeatureServiceItemFeatureService loads the arcgisLayer's FeatureServiceItemFeatureService into the .R struct
|
||||
func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisFeatureServices, err := os.FeatureServiceItemFeatureService(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisFeatureServices {
|
||||
|
||||
if !(o.FeatureServiceItemID == rel.ItemID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.FeatureServiceItemLayers = append(rel.R.FeatureServiceItemLayers, o)
|
||||
|
||||
o.R.FeatureServiceItemFeatureService = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadLayerFields loads the arcgisLayer's LayerFields into the .R struct
|
||||
func (o *ArcgisLayer) LoadLayerFields(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.LayerFields = nil
|
||||
|
||||
related, err := o.LayerFields(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Layer = o
|
||||
}
|
||||
|
||||
o.R.LayerFields = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadLayerFields loads the arcgisLayer's LayerFields into the .R struct
|
||||
func (os ArcgisLayerSlice) LoadLayerFields(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisLayerFields, err := os.LayerFields(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.LayerFields = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisLayerFields {
|
||||
|
||||
if !(o.FeatureServiceItemID == rel.LayerFeatureServiceItemID) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.Index == rel.LayerIndex) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Layer = o
|
||||
|
||||
o.R.LayerFields = append(o.R.LayerFields, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// arcgisLayerC is where relationship counts are stored.
|
||||
type arcgisLayerC struct {
|
||||
LayerFields *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *ArcgisLayer) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "LayerFields":
|
||||
o.C.LayerFields = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisLayerCountPreloader struct {
|
||||
LayerFields func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisLayerCountPreloader() arcgisLayerCountPreloader {
|
||||
return arcgisLayerCountPreloader{
|
||||
LayerFields: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisLayer]("LayerFields", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisLayers.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisLayerFields.Name()),
|
||||
sm.Where(psql.Quote(ArcgisLayerFields.Alias(), "layer_feature_service_item_id").EQ(psql.Quote(parent, "feature_service_item_id"))),
|
||||
sm.Where(psql.Quote(ArcgisLayerFields.Alias(), "layer_index").EQ(psql.Quote(parent, "index_"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisLayerCountThenLoader[Q orm.Loadable] struct {
|
||||
LayerFields func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisLayerCountThenLoader[Q orm.Loadable]() arcgisLayerCountThenLoader[Q] {
|
||||
type LayerFieldsCountInterface interface {
|
||||
LoadCountLayerFields(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisLayerCountThenLoader[Q]{
|
||||
LayerFields: countThenLoadBuilder[Q](
|
||||
"LayerFields",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved LayerFieldsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountLayerFields(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountLayerFields loads the count of LayerFields into the C struct
|
||||
func (o *ArcgisLayer) LoadCountLayerFields(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.LayerFields(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.LayerFields = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountLayerFields loads the count of LayerFields for a slice
|
||||
func (os ArcgisLayerSlice) LoadCountLayerFields(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.LoadCountLayerFields(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisLayerJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
FeatureServiceItemFeatureService modAs[Q, arcgisFeatureServiceColumns]
|
||||
LayerFields modAs[Q, arcgisLayerFieldColumns]
|
||||
}
|
||||
|
||||
func (j arcgisLayerJoins[Q]) aliasedAs(alias string) arcgisLayerJoins[Q] {
|
||||
return buildArcgisLayerJoins[Q](buildArcgisLayerColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisLayerJoins[Q dialect.Joinable](cols arcgisLayerColumns, typ string) arcgisLayerJoins[Q] {
|
||||
return arcgisLayerJoins[Q]{
|
||||
typ: typ,
|
||||
FeatureServiceItemFeatureService: modAs[Q, arcgisFeatureServiceColumns]{
|
||||
c: ArcgisFeatureServices.Columns,
|
||||
f: func(to arcgisFeatureServiceColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisFeatureServices.Name().As(to.Alias())).On(
|
||||
to.ItemID.EQ(cols.FeatureServiceItemID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
LayerFields: modAs[Q, arcgisLayerFieldColumns]{
|
||||
c: ArcgisLayerFields.Columns,
|
||||
f: func(to arcgisLayerFieldColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisLayerFields.Name().As(to.Alias())).On(
|
||||
to.LayerFeatureServiceItemID.EQ(cols.FeatureServiceItemID), to.LayerIndex.EQ(cols.Index),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
1266
db/models/arcgis.layer_field.bob.go
Normal file
1266
db/models/arcgis.layer_field.bob.go
Normal file
File diff suppressed because it is too large
Load diff
882
db/models/arcgis.parcel_mapping.bob.go
Normal file
882
db/models/arcgis.parcel_mapping.bob.go
Normal file
|
|
@ -0,0 +1,882 @@
|
|||
// 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"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// ArcgisParcelMapping is an object representing the database table.
|
||||
type ArcgisParcelMapping struct {
|
||||
Destination enums.ArcgisMappingdestinationparcel `db:"destination,pk" `
|
||||
LayerFeatureServiceItemID string `db:"layer_feature_service_item_id" `
|
||||
LayerIndex int32 `db:"layer_index" `
|
||||
LayerFieldName string `db:"layer_field_name" `
|
||||
OrganizationID int32 `db:"organization_id,pk" `
|
||||
|
||||
R arcgisParcelMappingR `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisParcelMappingSlice is an alias for a slice of pointers to ArcgisParcelMapping.
|
||||
// This should almost always be used instead of []*ArcgisParcelMapping.
|
||||
type ArcgisParcelMappingSlice []*ArcgisParcelMapping
|
||||
|
||||
// ArcgisParcelMappings contains methods to work with the parcel_mapping table
|
||||
var ArcgisParcelMappings = psql.NewTablex[*ArcgisParcelMapping, ArcgisParcelMappingSlice, *ArcgisParcelMappingSetter]("arcgis", "parcel_mapping", buildArcgisParcelMappingColumns("arcgis.parcel_mapping"))
|
||||
|
||||
// ArcgisParcelMappingsQuery is a query on the parcel_mapping table
|
||||
type ArcgisParcelMappingsQuery = *psql.ViewQuery[*ArcgisParcelMapping, ArcgisParcelMappingSlice]
|
||||
|
||||
// arcgisParcelMappingR is where relationships are stored.
|
||||
type arcgisParcelMappingR struct {
|
||||
LayerField *ArcgisLayerField // arcgis.parcel_mapping.parcel_mapping_layer_feature_service_item_id_layer_index_l_fkey
|
||||
Organization *Organization // arcgis.parcel_mapping.parcel_mapping_organization_id_fkey
|
||||
}
|
||||
|
||||
func buildArcgisParcelMappingColumns(alias string) arcgisParcelMappingColumns {
|
||||
return arcgisParcelMappingColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"destination", "layer_feature_service_item_id", "layer_index", "layer_field_name", "organization_id",
|
||||
).WithParent("arcgis.parcel_mapping"),
|
||||
tableAlias: alias,
|
||||
Destination: psql.Quote(alias, "destination"),
|
||||
LayerFeatureServiceItemID: psql.Quote(alias, "layer_feature_service_item_id"),
|
||||
LayerIndex: psql.Quote(alias, "layer_index"),
|
||||
LayerFieldName: psql.Quote(alias, "layer_field_name"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisParcelMappingColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Destination psql.Expression
|
||||
LayerFeatureServiceItemID psql.Expression
|
||||
LayerIndex psql.Expression
|
||||
LayerFieldName psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
}
|
||||
|
||||
func (c arcgisParcelMappingColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (arcgisParcelMappingColumns) AliasedAs(alias string) arcgisParcelMappingColumns {
|
||||
return buildArcgisParcelMappingColumns(alias)
|
||||
}
|
||||
|
||||
// ArcgisParcelMappingSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ArcgisParcelMappingSetter struct {
|
||||
Destination omit.Val[enums.ArcgisMappingdestinationparcel] `db:"destination,pk" `
|
||||
LayerFeatureServiceItemID omit.Val[string] `db:"layer_feature_service_item_id" `
|
||||
LayerIndex omit.Val[int32] `db:"layer_index" `
|
||||
LayerFieldName omit.Val[string] `db:"layer_field_name" `
|
||||
OrganizationID omit.Val[int32] `db:"organization_id,pk" `
|
||||
}
|
||||
|
||||
func (s ArcgisParcelMappingSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.Destination.IsValue() {
|
||||
vals = append(vals, "destination")
|
||||
}
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
vals = append(vals, "layer_feature_service_item_id")
|
||||
}
|
||||
if s.LayerIndex.IsValue() {
|
||||
vals = append(vals, "layer_index")
|
||||
}
|
||||
if s.LayerFieldName.IsValue() {
|
||||
vals = append(vals, "layer_field_name")
|
||||
}
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ArcgisParcelMappingSetter) Overwrite(t *ArcgisParcelMapping) {
|
||||
if s.Destination.IsValue() {
|
||||
t.Destination = s.Destination.MustGet()
|
||||
}
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
t.LayerFeatureServiceItemID = s.LayerFeatureServiceItemID.MustGet()
|
||||
}
|
||||
if s.LayerIndex.IsValue() {
|
||||
t.LayerIndex = s.LayerIndex.MustGet()
|
||||
}
|
||||
if s.LayerFieldName.IsValue() {
|
||||
t.LayerFieldName = s.LayerFieldName.MustGet()
|
||||
}
|
||||
if s.OrganizationID.IsValue() {
|
||||
t.OrganizationID = s.OrganizationID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ArcgisParcelMappingSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisParcelMappings.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, 5)
|
||||
if s.Destination.IsValue() {
|
||||
vals[0] = psql.Arg(s.Destination.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
vals[1] = psql.Arg(s.LayerFeatureServiceItemID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LayerIndex.IsValue() {
|
||||
vals[2] = psql.Arg(s.LayerIndex.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.LayerFieldName.IsValue() {
|
||||
vals[3] = psql.Arg(s.LayerFieldName.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[4] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ArcgisParcelMappingSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ArcgisParcelMappingSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.Destination.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "destination")...),
|
||||
psql.Arg(s.Destination),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.LayerFeatureServiceItemID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "layer_feature_service_item_id")...),
|
||||
psql.Arg(s.LayerFeatureServiceItemID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.LayerIndex.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "layer_index")...),
|
||||
psql.Arg(s.LayerIndex),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.LayerFieldName.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "layer_field_name")...),
|
||||
psql.Arg(s.LayerFieldName),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "organization_id")...),
|
||||
psql.Arg(s.OrganizationID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindArcgisParcelMapping retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindArcgisParcelMapping(ctx context.Context, exec bob.Executor, OrganizationIDPK int32, DestinationPK enums.ArcgisMappingdestinationparcel, cols ...string) (*ArcgisParcelMapping, error) {
|
||||
if len(cols) == 0 {
|
||||
return ArcgisParcelMappings.Query(
|
||||
sm.Where(ArcgisParcelMappings.Columns.OrganizationID.EQ(psql.Arg(OrganizationIDPK))),
|
||||
sm.Where(ArcgisParcelMappings.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return ArcgisParcelMappings.Query(
|
||||
sm.Where(ArcgisParcelMappings.Columns.OrganizationID.EQ(psql.Arg(OrganizationIDPK))),
|
||||
sm.Where(ArcgisParcelMappings.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Columns(ArcgisParcelMappings.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ArcgisParcelMappingExists checks the presence of a single record by primary key
|
||||
func ArcgisParcelMappingExists(ctx context.Context, exec bob.Executor, OrganizationIDPK int32, DestinationPK enums.ArcgisMappingdestinationparcel) (bool, error) {
|
||||
return ArcgisParcelMappings.Query(
|
||||
sm.Where(ArcgisParcelMappings.Columns.OrganizationID.EQ(psql.Arg(OrganizationIDPK))),
|
||||
sm.Where(ArcgisParcelMappings.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisParcelMapping is retrieved from the database
|
||||
func (o *ArcgisParcelMapping) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisParcelMappings.AfterSelectHooks.RunHooks(ctx, exec, ArcgisParcelMappingSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisParcelMappings.AfterInsertHooks.RunHooks(ctx, exec, ArcgisParcelMappingSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisParcelMappings.AfterUpdateHooks.RunHooks(ctx, exec, ArcgisParcelMappingSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisParcelMappings.AfterDeleteHooks.RunHooks(ctx, exec, ArcgisParcelMappingSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the ArcgisParcelMapping
|
||||
func (o *ArcgisParcelMapping) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.OrganizationID,
|
||||
o.Destination,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *ArcgisParcelMapping) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("arcgis.parcel_mapping", "organization_id"), psql.Quote("arcgis.parcel_mapping", "destination")).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 ArcgisParcelMapping
|
||||
func (o *ArcgisParcelMapping) Update(ctx context.Context, exec bob.Executor, s *ArcgisParcelMappingSetter) error {
|
||||
v, err := ArcgisParcelMappings.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 ArcgisParcelMapping record with an executor
|
||||
func (o *ArcgisParcelMapping) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := ArcgisParcelMappings.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the ArcgisParcelMapping using the executor
|
||||
func (o *ArcgisParcelMapping) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := ArcgisParcelMappings.Query(
|
||||
sm.Where(ArcgisParcelMappings.Columns.OrganizationID.EQ(psql.Arg(o.OrganizationID))),
|
||||
sm.Where(ArcgisParcelMappings.Columns.Destination.EQ(psql.Arg(o.Destination))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisParcelMappingSlice is retrieved from the database
|
||||
func (o ArcgisParcelMappingSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisParcelMappings.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisParcelMappings.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisParcelMappings.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisParcelMappings.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisParcelMappingSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("arcgis.parcel_mapping", "organization_id"), psql.Quote("arcgis.parcel_mapping", "destination")).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 ArcgisParcelMappingSlice) copyMatchingRows(from ...*ArcgisParcelMapping) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.OrganizationID != old.OrganizationID {
|
||||
continue
|
||||
}
|
||||
if new.Destination != old.Destination {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisParcelMappingSlice) 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 ArcgisParcelMappings.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 *ArcgisParcelMapping:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisParcelMapping:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisParcelMappingSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisParcelMapping or a slice of ArcgisParcelMapping
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = ArcgisParcelMappings.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisParcelMappingSlice) 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 ArcgisParcelMappings.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 *ArcgisParcelMapping:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisParcelMapping:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisParcelMappingSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisParcelMapping or a slice of ArcgisParcelMapping
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = ArcgisParcelMappings.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ArcgisParcelMappingSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ArcgisParcelMappingSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisParcelMappings.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisParcelMappingSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisParcelMappings.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisParcelMappingSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := ArcgisParcelMappings.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LayerField starts a query for related objects on arcgis.layer_field
|
||||
func (o *ArcgisParcelMapping) LayerField(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayerFieldsQuery {
|
||||
return ArcgisLayerFields.Query(append(mods,
|
||||
sm.Where(ArcgisLayerFields.Columns.LayerFeatureServiceItemID.EQ(psql.Arg(o.LayerFeatureServiceItemID))), sm.Where(ArcgisLayerFields.Columns.LayerIndex.EQ(psql.Arg(o.LayerIndex))), sm.Where(ArcgisLayerFields.Columns.Name.EQ(psql.Arg(o.LayerFieldName))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisParcelMappingSlice) LayerField(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisLayerFieldsQuery {
|
||||
pkLayerFeatureServiceItemID := make(pgtypes.Array[string], 0, len(os))
|
||||
|
||||
pkLayerIndex := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkLayerFieldName := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkLayerFeatureServiceItemID = append(pkLayerFeatureServiceItemID, o.LayerFeatureServiceItemID)
|
||||
pkLayerIndex = append(pkLayerIndex, o.LayerIndex)
|
||||
pkLayerFieldName = append(pkLayerFieldName, o.LayerFieldName)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkLayerFeatureServiceItemID), "text[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkLayerIndex), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkLayerFieldName), "text[]")),
|
||||
))
|
||||
|
||||
return ArcgisLayerFields.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisLayerFields.Columns.LayerFeatureServiceItemID, ArcgisLayerFields.Columns.LayerIndex, ArcgisLayerFields.Columns.Name).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *ArcgisParcelMapping) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisParcelMappingSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkOrganizationID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachArcgisParcelMappingLayerField0(ctx context.Context, exec bob.Executor, count int, arcgisParcelMapping0 *ArcgisParcelMapping, arcgisLayerField1 *ArcgisLayerField) (*ArcgisParcelMapping, error) {
|
||||
setter := &ArcgisParcelMappingSetter{
|
||||
LayerFeatureServiceItemID: omit.From(arcgisLayerField1.LayerFeatureServiceItemID),
|
||||
LayerIndex: omit.From(arcgisLayerField1.LayerIndex),
|
||||
LayerFieldName: omit.From(arcgisLayerField1.Name),
|
||||
}
|
||||
|
||||
err := arcgisParcelMapping0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisParcelMappingLayerField0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisParcelMapping0, nil
|
||||
}
|
||||
|
||||
func (arcgisParcelMapping0 *ArcgisParcelMapping) InsertLayerField(ctx context.Context, exec bob.Executor, related *ArcgisLayerFieldSetter) error {
|
||||
var err error
|
||||
|
||||
arcgisLayerField1, err := ArcgisLayerFields.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisParcelMappingLayerField0(ctx, exec, 1, arcgisParcelMapping0, arcgisLayerField1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisParcelMapping0.R.LayerField = arcgisLayerField1
|
||||
|
||||
arcgisLayerField1.R.ParcelMappings = append(arcgisLayerField1.R.ParcelMappings, arcgisParcelMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisParcelMapping0 *ArcgisParcelMapping) AttachLayerField(ctx context.Context, exec bob.Executor, arcgisLayerField1 *ArcgisLayerField) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisParcelMappingLayerField0(ctx, exec, 1, arcgisParcelMapping0, arcgisLayerField1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisParcelMapping0.R.LayerField = arcgisLayerField1
|
||||
|
||||
arcgisLayerField1.R.ParcelMappings = append(arcgisLayerField1.R.ParcelMappings, arcgisParcelMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachArcgisParcelMappingOrganization0(ctx context.Context, exec bob.Executor, count int, arcgisParcelMapping0 *ArcgisParcelMapping, organization1 *Organization) (*ArcgisParcelMapping, error) {
|
||||
setter := &ArcgisParcelMappingSetter{
|
||||
OrganizationID: omit.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := arcgisParcelMapping0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisParcelMappingOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisParcelMapping0, nil
|
||||
}
|
||||
|
||||
func (arcgisParcelMapping0 *ArcgisParcelMapping) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisParcelMappingOrganization0(ctx, exec, 1, arcgisParcelMapping0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisParcelMapping0.R.Organization = organization1
|
||||
|
||||
organization1.R.ParcelMappings = append(organization1.R.ParcelMappings, arcgisParcelMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisParcelMapping0 *ArcgisParcelMapping) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisParcelMappingOrganization0(ctx, exec, 1, arcgisParcelMapping0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisParcelMapping0.R.Organization = organization1
|
||||
|
||||
organization1.R.ParcelMappings = append(organization1.R.ParcelMappings, arcgisParcelMapping0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisParcelMappingWhere[Q psql.Filterable] struct {
|
||||
Destination psql.WhereMod[Q, enums.ArcgisMappingdestinationparcel]
|
||||
LayerFeatureServiceItemID psql.WhereMod[Q, string]
|
||||
LayerIndex psql.WhereMod[Q, int32]
|
||||
LayerFieldName psql.WhereMod[Q, string]
|
||||
OrganizationID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (arcgisParcelMappingWhere[Q]) AliasedAs(alias string) arcgisParcelMappingWhere[Q] {
|
||||
return buildArcgisParcelMappingWhere[Q](buildArcgisParcelMappingColumns(alias))
|
||||
}
|
||||
|
||||
func buildArcgisParcelMappingWhere[Q psql.Filterable](cols arcgisParcelMappingColumns) arcgisParcelMappingWhere[Q] {
|
||||
return arcgisParcelMappingWhere[Q]{
|
||||
Destination: psql.Where[Q, enums.ArcgisMappingdestinationparcel](cols.Destination),
|
||||
LayerFeatureServiceItemID: psql.Where[Q, string](cols.LayerFeatureServiceItemID),
|
||||
LayerIndex: psql.Where[Q, int32](cols.LayerIndex),
|
||||
LayerFieldName: psql.Where[Q, string](cols.LayerFieldName),
|
||||
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ArcgisParcelMapping) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "LayerField":
|
||||
rel, ok := retrieved.(*ArcgisLayerField)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisParcelMapping cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.LayerField = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ParcelMappings = ArcgisParcelMappingSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisParcelMapping cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ParcelMappings = ArcgisParcelMappingSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("arcgisParcelMapping has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisParcelMappingPreloader struct {
|
||||
LayerField func(...psql.PreloadOption) psql.Preloader
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisParcelMappingPreloader() arcgisParcelMappingPreloader {
|
||||
return arcgisParcelMappingPreloader{
|
||||
LayerField: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*ArcgisLayerField, ArcgisLayerFieldSlice](psql.PreloadRel{
|
||||
Name: "LayerField",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisParcelMappings,
|
||||
To: ArcgisLayerFields,
|
||||
FromColumns: []string{"layer_feature_service_item_id", "layer_index", "layer_field_name"},
|
||||
ToColumns: []string{"layer_feature_service_item_id", "layer_index", "name"},
|
||||
},
|
||||
},
|
||||
}, ArcgisLayerFields.Columns.Names(), opts...)
|
||||
},
|
||||
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "Organization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisParcelMappings,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"organization_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisParcelMappingThenLoader[Q orm.Loadable] struct {
|
||||
LayerField func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisParcelMappingThenLoader[Q orm.Loadable]() arcgisParcelMappingThenLoader[Q] {
|
||||
type LayerFieldLoadInterface interface {
|
||||
LoadLayerField(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisParcelMappingThenLoader[Q]{
|
||||
LayerField: thenLoadBuilder[Q](
|
||||
"LayerField",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved LayerFieldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadLayerField(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadLayerField loads the arcgisParcelMapping's LayerField into the .R struct
|
||||
func (o *ArcgisParcelMapping) LoadLayerField(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.LayerField = nil
|
||||
|
||||
related, err := o.LayerField(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ParcelMappings = ArcgisParcelMappingSlice{o}
|
||||
|
||||
o.R.LayerField = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadLayerField loads the arcgisParcelMapping's LayerField into the .R struct
|
||||
func (os ArcgisParcelMappingSlice) LoadLayerField(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisLayerFields, err := os.LayerField(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisLayerFields {
|
||||
|
||||
if !(o.LayerFeatureServiceItemID == rel.LayerFeatureServiceItemID) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.LayerIndex == rel.LayerIndex) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.LayerFieldName == rel.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ParcelMappings = append(rel.R.ParcelMappings, o)
|
||||
|
||||
o.R.LayerField = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the arcgisParcelMapping's Organization into the .R struct
|
||||
func (o *ArcgisParcelMapping) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Organization = nil
|
||||
|
||||
related, err := o.Organization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ParcelMappings = ArcgisParcelMappingSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the arcgisParcelMapping's Organization into the .R struct
|
||||
func (os ArcgisParcelMappingSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.Organization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
|
||||
if !(o.OrganizationID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ParcelMappings = append(rel.R.ParcelMappings, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisParcelMappingJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
LayerField modAs[Q, arcgisLayerFieldColumns]
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
func (j arcgisParcelMappingJoins[Q]) aliasedAs(alias string) arcgisParcelMappingJoins[Q] {
|
||||
return buildArcgisParcelMappingJoins[Q](buildArcgisParcelMappingColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisParcelMappingJoins[Q dialect.Joinable](cols arcgisParcelMappingColumns, typ string) arcgisParcelMappingJoins[Q] {
|
||||
return arcgisParcelMappingJoins[Q]{
|
||||
typ: typ,
|
||||
LayerField: modAs[Q, arcgisLayerFieldColumns]{
|
||||
c: ArcgisLayerFields.Columns,
|
||||
f: func(to arcgisLayerFieldColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisLayerFields.Name().As(to.Alias())).On(
|
||||
to.LayerFeatureServiceItemID.EQ(cols.LayerFeatureServiceItemID), to.LayerIndex.EQ(cols.LayerIndex), to.Name.EQ(cols.LayerFieldName),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Organization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.OrganizationID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,9 @@ var (
|
|||
)
|
||||
|
||||
type preloadCounts struct {
|
||||
ArcgisFeatureService arcgisFeatureServiceCountPreloader
|
||||
ArcgisLayer arcgisLayerCountPreloader
|
||||
ArcgisLayerField arcgisLayerFieldCountPreloader
|
||||
ArcgisUser arcgisuserCountPreloader
|
||||
CommsEmailContact commsEmailContactCountPreloader
|
||||
CommsEmailTemplate commsEmailTemplateCountPreloader
|
||||
|
|
@ -39,6 +42,9 @@ type preloadCounts struct {
|
|||
|
||||
func getPreloadCount() preloadCounts {
|
||||
return preloadCounts{
|
||||
ArcgisFeatureService: buildArcgisFeatureServiceCountPreloader(),
|
||||
ArcgisLayer: buildArcgisLayerCountPreloader(),
|
||||
ArcgisLayerField: buildArcgisLayerFieldCountPreloader(),
|
||||
ArcgisUser: buildArcgisUserCountPreloader(),
|
||||
CommsEmailContact: buildCommsEmailContactCountPreloader(),
|
||||
CommsEmailTemplate: buildCommsEmailTemplateCountPreloader(),
|
||||
|
|
@ -57,6 +63,9 @@ func getPreloadCount() preloadCounts {
|
|||
}
|
||||
|
||||
type thenLoadCounts[Q orm.Loadable] struct {
|
||||
ArcgisFeatureService arcgisFeatureServiceCountThenLoader[Q]
|
||||
ArcgisLayer arcgisLayerCountThenLoader[Q]
|
||||
ArcgisLayerField arcgisLayerFieldCountThenLoader[Q]
|
||||
ArcgisUser arcgisuserCountThenLoader[Q]
|
||||
CommsEmailContact commsEmailContactCountThenLoader[Q]
|
||||
CommsEmailTemplate commsEmailTemplateCountThenLoader[Q]
|
||||
|
|
@ -75,6 +84,9 @@ type thenLoadCounts[Q orm.Loadable] struct {
|
|||
|
||||
func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
|
||||
return thenLoadCounts[Q]{
|
||||
ArcgisFeatureService: buildArcgisFeatureServiceCountThenLoader[Q](),
|
||||
ArcgisLayer: buildArcgisLayerCountThenLoader[Q](),
|
||||
ArcgisLayerField: buildArcgisLayerFieldCountThenLoader[Q](),
|
||||
ArcgisUser: buildArcgisUserCountThenLoader[Q](),
|
||||
CommsEmailContact: buildCommsEmailContactCountThenLoader[Q](),
|
||||
CommsEmailTemplate: buildCommsEmailTemplateCountThenLoader[Q](),
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] {
|
|||
}
|
||||
|
||||
type joins[Q dialect.Joinable] struct {
|
||||
Addresses joinSet[addressJoins[Q]]
|
||||
ArcgisAddressMappings joinSet[arcgisAddressMappingJoins[Q]]
|
||||
ArcgisFeatureServices joinSet[arcgisFeatureServiceJoins[Q]]
|
||||
ArcgisLayers joinSet[arcgisLayerJoins[Q]]
|
||||
ArcgisLayerFields joinSet[arcgisLayerFieldJoins[Q]]
|
||||
ArcgisParcelMappings joinSet[arcgisParcelMappingJoins[Q]]
|
||||
ArcgisUsers joinSet[arcgisuserJoins[Q]]
|
||||
ArcgisUserPrivileges joinSet[arcgisUserPrivilegeJoins[Q]]
|
||||
CommsEmailContacts joinSet[commsEmailContactJoins[Q]]
|
||||
|
|
@ -85,6 +91,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
Notifications joinSet[notificationJoins[Q]]
|
||||
OauthTokens joinSet[oauthTokenJoins[Q]]
|
||||
Organizations joinSet[organizationJoins[Q]]
|
||||
Pools joinSet[poolJoins[Q]]
|
||||
PublicreportImages joinSet[publicreportImageJoins[Q]]
|
||||
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
|
||||
PublicreportNotifyEmailNuisances joinSet[publicreportNotifyEmailNuisanceJoins[Q]]
|
||||
|
|
@ -99,6 +106,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
PublicreportQuickImages joinSet[publicreportQuickImageJoins[Q]]
|
||||
PublicreportSubscribeEmails joinSet[publicreportSubscribeEmailJoins[Q]]
|
||||
PublicreportSubscribePhones joinSet[publicreportSubscribePhoneJoins[Q]]
|
||||
Sites joinSet[siteJoins[Q]]
|
||||
Users joinSet[userJoins[Q]]
|
||||
}
|
||||
|
||||
|
|
@ -112,6 +120,12 @@ func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q
|
|||
|
||||
func getJoins[Q dialect.Joinable]() joins[Q] {
|
||||
return joins[Q]{
|
||||
Addresses: buildJoinSet[addressJoins[Q]](Addresses.Columns, buildAddressJoins),
|
||||
ArcgisAddressMappings: buildJoinSet[arcgisAddressMappingJoins[Q]](ArcgisAddressMappings.Columns, buildArcgisAddressMappingJoins),
|
||||
ArcgisFeatureServices: buildJoinSet[arcgisFeatureServiceJoins[Q]](ArcgisFeatureServices.Columns, buildArcgisFeatureServiceJoins),
|
||||
ArcgisLayers: buildJoinSet[arcgisLayerJoins[Q]](ArcgisLayers.Columns, buildArcgisLayerJoins),
|
||||
ArcgisLayerFields: buildJoinSet[arcgisLayerFieldJoins[Q]](ArcgisLayerFields.Columns, buildArcgisLayerFieldJoins),
|
||||
ArcgisParcelMappings: buildJoinSet[arcgisParcelMappingJoins[Q]](ArcgisParcelMappings.Columns, buildArcgisParcelMappingJoins),
|
||||
ArcgisUsers: buildJoinSet[arcgisuserJoins[Q]](ArcgisUsers.Columns, buildArcgisUserJoins),
|
||||
ArcgisUserPrivileges: buildJoinSet[arcgisUserPrivilegeJoins[Q]](ArcgisUserPrivileges.Columns, buildArcgisUserPrivilegeJoins),
|
||||
CommsEmailContacts: buildJoinSet[commsEmailContactJoins[Q]](CommsEmailContacts.Columns, buildCommsEmailContactJoins),
|
||||
|
|
@ -165,6 +179,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
Notifications: buildJoinSet[notificationJoins[Q]](Notifications.Columns, buildNotificationJoins),
|
||||
OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins),
|
||||
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
|
||||
Pools: buildJoinSet[poolJoins[Q]](Pools.Columns, buildPoolJoins),
|
||||
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
|
||||
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
|
||||
PublicreportNotifyEmailNuisances: buildJoinSet[publicreportNotifyEmailNuisanceJoins[Q]](PublicreportNotifyEmailNuisances.Columns, buildPublicreportNotifyEmailNuisanceJoins),
|
||||
|
|
@ -179,6 +194,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
PublicreportQuickImages: buildJoinSet[publicreportQuickImageJoins[Q]](PublicreportQuickImages.Columns, buildPublicreportQuickImageJoins),
|
||||
PublicreportSubscribeEmails: buildJoinSet[publicreportSubscribeEmailJoins[Q]](PublicreportSubscribeEmails.Columns, buildPublicreportSubscribeEmailJoins),
|
||||
PublicreportSubscribePhones: buildJoinSet[publicreportSubscribePhoneJoins[Q]](PublicreportSubscribePhones.Columns, buildPublicreportSubscribePhoneJoins),
|
||||
Sites: buildJoinSet[siteJoins[Q]](Sites.Columns, buildSiteJoins),
|
||||
Users: buildJoinSet[userJoins[Q]](Users.Columns, buildUserJoins),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@ import (
|
|||
var Preload = getPreloaders()
|
||||
|
||||
type preloaders struct {
|
||||
Address addressPreloader
|
||||
ArcgisAddressMapping arcgisAddressMappingPreloader
|
||||
ArcgisFeatureService arcgisFeatureServicePreloader
|
||||
ArcgisLayer arcgisLayerPreloader
|
||||
ArcgisLayerField arcgisLayerFieldPreloader
|
||||
ArcgisParcelMapping arcgisParcelMappingPreloader
|
||||
ArcgisUser arcgisuserPreloader
|
||||
ArcgisUserPrivilege arcgisUserPrivilegePreloader
|
||||
CommsEmailContact commsEmailContactPreloader
|
||||
|
|
@ -70,6 +76,7 @@ type preloaders struct {
|
|||
Notification notificationPreloader
|
||||
OauthToken oauthTokenPreloader
|
||||
Organization organizationPreloader
|
||||
Pool poolPreloader
|
||||
PublicreportImage publicreportImagePreloader
|
||||
PublicreportImageExif publicreportImageExifPreloader
|
||||
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisancePreloader
|
||||
|
|
@ -84,11 +91,18 @@ type preloaders struct {
|
|||
PublicreportQuickImage publicreportQuickImagePreloader
|
||||
PublicreportSubscribeEmail publicreportSubscribeEmailPreloader
|
||||
PublicreportSubscribePhone publicreportSubscribePhonePreloader
|
||||
Site sitePreloader
|
||||
User userPreloader
|
||||
}
|
||||
|
||||
func getPreloaders() preloaders {
|
||||
return preloaders{
|
||||
Address: buildAddressPreloader(),
|
||||
ArcgisAddressMapping: buildArcgisAddressMappingPreloader(),
|
||||
ArcgisFeatureService: buildArcgisFeatureServicePreloader(),
|
||||
ArcgisLayer: buildArcgisLayerPreloader(),
|
||||
ArcgisLayerField: buildArcgisLayerFieldPreloader(),
|
||||
ArcgisParcelMapping: buildArcgisParcelMappingPreloader(),
|
||||
ArcgisUser: buildArcgisUserPreloader(),
|
||||
ArcgisUserPrivilege: buildArcgisUserPrivilegePreloader(),
|
||||
CommsEmailContact: buildCommsEmailContactPreloader(),
|
||||
|
|
@ -142,6 +156,7 @@ func getPreloaders() preloaders {
|
|||
Notification: buildNotificationPreloader(),
|
||||
OauthToken: buildOauthTokenPreloader(),
|
||||
Organization: buildOrganizationPreloader(),
|
||||
Pool: buildPoolPreloader(),
|
||||
PublicreportImage: buildPublicreportImagePreloader(),
|
||||
PublicreportImageExif: buildPublicreportImageExifPreloader(),
|
||||
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisancePreloader(),
|
||||
|
|
@ -156,6 +171,7 @@ func getPreloaders() preloaders {
|
|||
PublicreportQuickImage: buildPublicreportQuickImagePreloader(),
|
||||
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailPreloader(),
|
||||
PublicreportSubscribePhone: buildPublicreportSubscribePhonePreloader(),
|
||||
Site: buildSitePreloader(),
|
||||
User: buildUserPreloader(),
|
||||
}
|
||||
}
|
||||
|
|
@ -167,6 +183,12 @@ var (
|
|||
)
|
||||
|
||||
type thenLoaders[Q orm.Loadable] struct {
|
||||
Address addressThenLoader[Q]
|
||||
ArcgisAddressMapping arcgisAddressMappingThenLoader[Q]
|
||||
ArcgisFeatureService arcgisFeatureServiceThenLoader[Q]
|
||||
ArcgisLayer arcgisLayerThenLoader[Q]
|
||||
ArcgisLayerField arcgisLayerFieldThenLoader[Q]
|
||||
ArcgisParcelMapping arcgisParcelMappingThenLoader[Q]
|
||||
ArcgisUser arcgisuserThenLoader[Q]
|
||||
ArcgisUserPrivilege arcgisUserPrivilegeThenLoader[Q]
|
||||
CommsEmailContact commsEmailContactThenLoader[Q]
|
||||
|
|
@ -220,6 +242,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
Notification notificationThenLoader[Q]
|
||||
OauthToken oauthTokenThenLoader[Q]
|
||||
Organization organizationThenLoader[Q]
|
||||
Pool poolThenLoader[Q]
|
||||
PublicreportImage publicreportImageThenLoader[Q]
|
||||
PublicreportImageExif publicreportImageExifThenLoader[Q]
|
||||
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisanceThenLoader[Q]
|
||||
|
|
@ -234,11 +257,18 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
PublicreportQuickImage publicreportQuickImageThenLoader[Q]
|
||||
PublicreportSubscribeEmail publicreportSubscribeEmailThenLoader[Q]
|
||||
PublicreportSubscribePhone publicreportSubscribePhoneThenLoader[Q]
|
||||
Site siteThenLoader[Q]
|
||||
User userThenLoader[Q]
|
||||
}
|
||||
|
||||
func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
||||
return thenLoaders[Q]{
|
||||
Address: buildAddressThenLoader[Q](),
|
||||
ArcgisAddressMapping: buildArcgisAddressMappingThenLoader[Q](),
|
||||
ArcgisFeatureService: buildArcgisFeatureServiceThenLoader[Q](),
|
||||
ArcgisLayer: buildArcgisLayerThenLoader[Q](),
|
||||
ArcgisLayerField: buildArcgisLayerFieldThenLoader[Q](),
|
||||
ArcgisParcelMapping: buildArcgisParcelMappingThenLoader[Q](),
|
||||
ArcgisUser: buildArcgisUserThenLoader[Q](),
|
||||
ArcgisUserPrivilege: buildArcgisUserPrivilegeThenLoader[Q](),
|
||||
CommsEmailContact: buildCommsEmailContactThenLoader[Q](),
|
||||
|
|
@ -292,6 +322,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
Notification: buildNotificationThenLoader[Q](),
|
||||
OauthToken: buildOauthTokenThenLoader[Q](),
|
||||
Organization: buildOrganizationThenLoader[Q](),
|
||||
Pool: buildPoolThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageThenLoader[Q](),
|
||||
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
|
||||
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisanceThenLoader[Q](),
|
||||
|
|
@ -306,6 +337,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
PublicreportQuickImage: buildPublicreportQuickImageThenLoader[Q](),
|
||||
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailThenLoader[Q](),
|
||||
PublicreportSubscribePhone: buildPublicreportSubscribePhoneThenLoader[Q](),
|
||||
Site: buildSiteThenLoader[Q](),
|
||||
User: buildUserThenLoader[Q](),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@ var (
|
|||
)
|
||||
|
||||
func Where[Q psql.Filterable]() struct {
|
||||
Addresses addressWhere[Q]
|
||||
ArcgisAddressMappings arcgisAddressMappingWhere[Q]
|
||||
ArcgisFeatureServices arcgisFeatureServiceWhere[Q]
|
||||
ArcgisLayers arcgisLayerWhere[Q]
|
||||
ArcgisLayerFields arcgisLayerFieldWhere[Q]
|
||||
ArcgisParcelMappings arcgisParcelMappingWhere[Q]
|
||||
ArcgisUsers arcgisuserWhere[Q]
|
||||
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
|
||||
CommsEmailContacts commsEmailContactWhere[Q]
|
||||
|
|
@ -73,6 +79,8 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
Parcels parcelWhere[Q]
|
||||
Pools poolWhere[Q]
|
||||
PublicreportImages publicreportImageWhere[Q]
|
||||
PublicreportImageExifs publicreportImageExifWhere[Q]
|
||||
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
|
||||
|
|
@ -91,10 +99,17 @@ func Where[Q psql.Filterable]() struct {
|
|||
RasterColumns rasterColumnWhere[Q]
|
||||
RasterOverviews rasterOverviewWhere[Q]
|
||||
Sessions sessionWhere[Q]
|
||||
Sites siteWhere[Q]
|
||||
SpatialRefSys spatialRefSyWhere[Q]
|
||||
Users userWhere[Q]
|
||||
} {
|
||||
return struct {
|
||||
Addresses addressWhere[Q]
|
||||
ArcgisAddressMappings arcgisAddressMappingWhere[Q]
|
||||
ArcgisFeatureServices arcgisFeatureServiceWhere[Q]
|
||||
ArcgisLayers arcgisLayerWhere[Q]
|
||||
ArcgisLayerFields arcgisLayerFieldWhere[Q]
|
||||
ArcgisParcelMappings arcgisParcelMappingWhere[Q]
|
||||
ArcgisUsers arcgisuserWhere[Q]
|
||||
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
|
||||
CommsEmailContacts commsEmailContactWhere[Q]
|
||||
|
|
@ -151,6 +166,8 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
Parcels parcelWhere[Q]
|
||||
Pools poolWhere[Q]
|
||||
PublicreportImages publicreportImageWhere[Q]
|
||||
PublicreportImageExifs publicreportImageExifWhere[Q]
|
||||
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
|
||||
|
|
@ -169,9 +186,16 @@ func Where[Q psql.Filterable]() struct {
|
|||
RasterColumns rasterColumnWhere[Q]
|
||||
RasterOverviews rasterOverviewWhere[Q]
|
||||
Sessions sessionWhere[Q]
|
||||
Sites siteWhere[Q]
|
||||
SpatialRefSys spatialRefSyWhere[Q]
|
||||
Users userWhere[Q]
|
||||
}{
|
||||
Addresses: buildAddressWhere[Q](Addresses.Columns),
|
||||
ArcgisAddressMappings: buildArcgisAddressMappingWhere[Q](ArcgisAddressMappings.Columns),
|
||||
ArcgisFeatureServices: buildArcgisFeatureServiceWhere[Q](ArcgisFeatureServices.Columns),
|
||||
ArcgisLayers: buildArcgisLayerWhere[Q](ArcgisLayers.Columns),
|
||||
ArcgisLayerFields: buildArcgisLayerFieldWhere[Q](ArcgisLayerFields.Columns),
|
||||
ArcgisParcelMappings: buildArcgisParcelMappingWhere[Q](ArcgisParcelMappings.Columns),
|
||||
ArcgisUsers: buildArcgisUserWhere[Q](ArcgisUsers.Columns),
|
||||
ArcgisUserPrivileges: buildArcgisUserPrivilegeWhere[Q](ArcgisUserPrivileges.Columns),
|
||||
CommsEmailContacts: buildCommsEmailContactWhere[Q](CommsEmailContacts.Columns),
|
||||
|
|
@ -228,6 +252,8 @@ func Where[Q psql.Filterable]() struct {
|
|||
Notifications: buildNotificationWhere[Q](Notifications.Columns),
|
||||
OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns),
|
||||
Organizations: buildOrganizationWhere[Q](Organizations.Columns),
|
||||
Parcels: buildParcelWhere[Q](Parcels.Columns),
|
||||
Pools: buildPoolWhere[Q](Pools.Columns),
|
||||
PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns),
|
||||
PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns),
|
||||
PublicreportNotifyEmailNuisances: buildPublicreportNotifyEmailNuisanceWhere[Q](PublicreportNotifyEmailNuisances.Columns),
|
||||
|
|
@ -246,6 +272,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
RasterColumns: buildRasterColumnWhere[Q](RasterColumns.Columns),
|
||||
RasterOverviews: buildRasterOverviewWhere[Q](RasterOverviews.Columns),
|
||||
Sessions: buildSessionWhere[Q](Sessions.Columns),
|
||||
Sites: buildSiteWhere[Q](Sites.Columns),
|
||||
SpatialRefSys: buildSpatialRefSyWhere[Q](SpatialRefSys.Columns),
|
||||
Users: buildUserWhere[Q](Users.Columns),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ type fileuploadFileR struct {
|
|||
ErrorFiles FileuploadErrorFileSlice // fileupload.error_file.error_file_file_id_fkey
|
||||
CreatorUser *User // fileupload.file.file_creator_id_fkey
|
||||
Organization *Organization // fileupload.file.file_organization_id_fkey
|
||||
Sites SiteSlice // site.site_file_id_fkey
|
||||
}
|
||||
|
||||
func buildFileuploadFileColumns(alias string) fileuploadFileColumns {
|
||||
|
|
@ -658,6 +659,30 @@ func (os FileuploadFileSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]
|
|||
)...)
|
||||
}
|
||||
|
||||
// Sites starts a query for related objects on site
|
||||
func (o *FileuploadFile) Sites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.FileID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FileuploadFileSlice) Sites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.FileID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertFileuploadFileCSV0(ctx context.Context, exec bob.Executor, fileuploadCSV1 *FileuploadCSVSetter, fileuploadFile0 *FileuploadFile) (*FileuploadCSV, error) {
|
||||
fileuploadCSV1.FileID = omit.From(fileuploadFile0.ID)
|
||||
|
||||
|
|
@ -876,6 +901,74 @@ func (fileuploadFile0 *FileuploadFile) AttachOrganization(ctx context.Context, e
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertFileuploadFileSites0(ctx context.Context, exec bob.Executor, sites1 []*SiteSetter, fileuploadFile0 *FileuploadFile) (SiteSlice, error) {
|
||||
for i := range sites1 {
|
||||
sites1[i].FileID = omitnull.From(fileuploadFile0.ID)
|
||||
}
|
||||
|
||||
ret, err := Sites.Insert(bob.ToMods(sites1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertFileuploadFileSites0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachFileuploadFileSites0(ctx context.Context, exec bob.Executor, count int, sites1 SiteSlice, fileuploadFile0 *FileuploadFile) (SiteSlice, error) {
|
||||
setter := &SiteSetter{
|
||||
FileID: omitnull.From(fileuploadFile0.ID),
|
||||
}
|
||||
|
||||
err := sites1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFileuploadFileSites0: %w", err)
|
||||
}
|
||||
|
||||
return sites1, nil
|
||||
}
|
||||
|
||||
func (fileuploadFile0 *FileuploadFile) InsertSites(ctx context.Context, exec bob.Executor, related ...*SiteSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
sites1, err := insertFileuploadFileSites0(ctx, exec, related, fileuploadFile0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadFile0.R.Sites = append(fileuploadFile0.R.Sites, sites1...)
|
||||
|
||||
for _, rel := range sites1 {
|
||||
rel.R.File = fileuploadFile0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fileuploadFile0 *FileuploadFile) AttachSites(ctx context.Context, exec bob.Executor, related ...*Site) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
sites1 := SiteSlice(related)
|
||||
|
||||
_, err = attachFileuploadFileSites0(ctx, exec, len(related), sites1, fileuploadFile0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fileuploadFile0.R.Sites = append(fileuploadFile0.R.Sites, sites1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.File = fileuploadFile0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadFileWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
ContentType psql.WhereMod[Q, string]
|
||||
|
|
@ -964,6 +1057,20 @@ func (o *FileuploadFile) Preload(name string, retrieved any) error {
|
|||
rel.R.Files = FileuploadFileSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Sites":
|
||||
rels, ok := retrieved.(SiteSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("fileuploadFile cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Sites = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.File = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("fileuploadFile has no relationship %q", name)
|
||||
}
|
||||
|
|
@ -1024,6 +1131,7 @@ type fileuploadFileThenLoader[Q orm.Loadable] struct {
|
|||
ErrorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Sites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadFileThenLoader[Q orm.Loadable]() fileuploadFileThenLoader[Q] {
|
||||
|
|
@ -1039,6 +1147,9 @@ func buildFileuploadFileThenLoader[Q orm.Loadable]() fileuploadFileThenLoader[Q]
|
|||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SitesLoadInterface interface {
|
||||
LoadSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadFileThenLoader[Q]{
|
||||
CSV: thenLoadBuilder[Q](
|
||||
|
|
@ -1065,6 +1176,12 @@ func buildFileuploadFileThenLoader[Q orm.Loadable]() fileuploadFileThenLoader[Q]
|
|||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Sites: thenLoadBuilder[Q](
|
||||
"Sites",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SitesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadSites(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1285,9 +1402,74 @@ func (os FileuploadFileSlice) LoadOrganization(ctx context.Context, exec bob.Exe
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadSites loads the fileuploadFile's Sites into the .R struct
|
||||
func (o *FileuploadFile) LoadSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Sites = nil
|
||||
|
||||
related, err := o.Sites(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.File = o
|
||||
}
|
||||
|
||||
o.R.Sites = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSites loads the fileuploadFile's Sites into the .R struct
|
||||
func (os FileuploadFileSlice) LoadSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sites, err := os.Sites(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Sites = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range sites {
|
||||
|
||||
if !rel.FileID.IsValue() {
|
||||
continue
|
||||
}
|
||||
if !(rel.FileID.IsValue() && o.ID == rel.FileID.MustGet()) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.File = o
|
||||
|
||||
o.R.Sites = append(o.R.Sites, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// fileuploadFileC is where relationship counts are stored.
|
||||
type fileuploadFileC struct {
|
||||
ErrorFiles *int64
|
||||
Sites *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -1299,12 +1481,15 @@ func (o *FileuploadFile) PreloadCount(name string, count int64) error {
|
|||
switch name {
|
||||
case "ErrorFiles":
|
||||
o.C.ErrorFiles = &count
|
||||
case "Sites":
|
||||
o.C.Sites = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadFileCountPreloader struct {
|
||||
ErrorFiles func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Sites func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFileuploadFileCountPreloader() fileuploadFileCountPreloader {
|
||||
|
|
@ -1326,17 +1511,38 @@ func buildFileuploadFileCountPreloader() fileuploadFileCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
Sites: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*FileuploadFile]("Sites", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = FileuploadFiles.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Sites.Name()),
|
||||
sm.Where(psql.Quote(Sites.Alias(), "file_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fileuploadFileCountThenLoader[Q orm.Loadable] struct {
|
||||
ErrorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Sites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFileuploadFileCountThenLoader[Q orm.Loadable]() fileuploadFileCountThenLoader[Q] {
|
||||
type ErrorFilesCountInterface interface {
|
||||
LoadCountErrorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SitesCountInterface interface {
|
||||
LoadCountSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fileuploadFileCountThenLoader[Q]{
|
||||
ErrorFiles: countThenLoadBuilder[Q](
|
||||
|
|
@ -1345,6 +1551,12 @@ func buildFileuploadFileCountThenLoader[Q orm.Loadable]() fileuploadFileCountThe
|
|||
return retrieved.LoadCountErrorFiles(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Sites: countThenLoadBuilder[Q](
|
||||
"Sites",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SitesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountSites(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1378,12 +1590,43 @@ func (os FileuploadFileSlice) LoadCountErrorFiles(ctx context.Context, exec bob.
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountSites loads the count of Sites into the C struct
|
||||
func (o *FileuploadFile) LoadCountSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.Sites(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.Sites = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountSites loads the count of Sites for a slice
|
||||
func (os FileuploadFileSlice) LoadCountSites(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.LoadCountSites(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileuploadFileJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
CSV modAs[Q, fileuploadCSVColumns]
|
||||
ErrorFiles modAs[Q, fileuploadErrorFileColumns]
|
||||
CreatorUser modAs[Q, userColumns]
|
||||
Organization modAs[Q, organizationColumns]
|
||||
Sites modAs[Q, siteColumns]
|
||||
}
|
||||
|
||||
func (j fileuploadFileJoins[Q]) aliasedAs(alias string) fileuploadFileJoins[Q] {
|
||||
|
|
@ -1446,6 +1689,20 @@ func buildFileuploadFileJoins[Q dialect.Joinable](cols fileuploadFileColumns, ty
|
|||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Sites: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
|
||||
to.FileID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -984,7 +984,7 @@ func (fileuploadPool0 *FileuploadPool) InsertCreatorUser(ctx context.Context, ex
|
|||
|
||||
fileuploadPool0.R.CreatorUser = user1
|
||||
|
||||
user1.R.CreatorPools = append(user1.R.CreatorPools, fileuploadPool0)
|
||||
user1.R.FileuploadPool = append(user1.R.FileuploadPool, fileuploadPool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -999,7 +999,7 @@ func (fileuploadPool0 *FileuploadPool) AttachCreatorUser(ctx context.Context, ex
|
|||
|
||||
fileuploadPool0.R.CreatorUser = user1
|
||||
|
||||
user1.R.CreatorPools = append(user1.R.CreatorPools, fileuploadPool0)
|
||||
user1.R.FileuploadPool = append(user1.R.FileuploadPool, fileuploadPool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1267,7 +1267,7 @@ func (o *FileuploadPool) Preload(name string, retrieved any) error {
|
|||
o.R.CreatorUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.CreatorPools = FileuploadPoolSlice{o}
|
||||
rel.R.FileuploadPool = FileuploadPoolSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "CSVFileCSV":
|
||||
|
|
@ -1474,7 +1474,7 @@ func (o *FileuploadPool) LoadCreatorUser(ctx context.Context, exec bob.Executor,
|
|||
return err
|
||||
}
|
||||
|
||||
related.R.CreatorPools = FileuploadPoolSlice{o}
|
||||
related.R.FileuploadPool = FileuploadPoolSlice{o}
|
||||
|
||||
o.R.CreatorUser = related
|
||||
return nil
|
||||
|
|
@ -1502,7 +1502,7 @@ func (os FileuploadPoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Exec
|
|||
continue
|
||||
}
|
||||
|
||||
rel.R.CreatorPools = append(rel.R.CreatorPools, o)
|
||||
rel.R.FileuploadPool = append(rel.R.FileuploadPool, o)
|
||||
|
||||
o.R.CreatorUser = rel
|
||||
break
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ type OrganizationsQuery = *psql.ViewQuery[*Organization, OrganizationSlice]
|
|||
|
||||
// organizationR is where relationships are stored.
|
||||
type organizationR struct {
|
||||
AddressMappings ArcgisAddressMappingSlice // arcgis.address_mapping.address_mapping_organization_id_fkey
|
||||
ParcelMappings ArcgisParcelMappingSlice // arcgis.parcel_mapping.parcel_mapping_organization_id_fkey
|
||||
EmailContacts CommsEmailContactSlice // district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey
|
||||
Phones CommsPhoneSlice // district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey
|
||||
Containerrelates FieldseekerContainerrelateSlice // fieldseeker.containerrelate.containerrelate_organization_id_fkey
|
||||
|
|
@ -835,6 +837,54 @@ func (o OrganizationSlice) ReloadAll(ctx context.Context, exec bob.Executor) err
|
|||
return nil
|
||||
}
|
||||
|
||||
// AddressMappings starts a query for related objects on arcgis.address_mapping
|
||||
func (o *Organization) AddressMappings(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisAddressMappingsQuery {
|
||||
return ArcgisAddressMappings.Query(append(mods,
|
||||
sm.Where(ArcgisAddressMappings.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OrganizationSlice) AddressMappings(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisAddressMappingsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return ArcgisAddressMappings.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisAddressMappings.Columns.OrganizationID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// ParcelMappings starts a query for related objects on arcgis.parcel_mapping
|
||||
func (o *Organization) ParcelMappings(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisParcelMappingsQuery {
|
||||
return ArcgisParcelMappings.Query(append(mods,
|
||||
sm.Where(ArcgisParcelMappings.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OrganizationSlice) ParcelMappings(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisParcelMappingsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return ArcgisParcelMappings.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisParcelMappings.Columns.OrganizationID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// EmailContacts starts a query for related objects on comms.email_contact
|
||||
func (o *Organization) EmailContacts(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
|
||||
return CommsEmailContacts.Query(append(mods,
|
||||
|
|
@ -1781,6 +1831,142 @@ func (os OrganizationSlice) User(mods ...bob.Mod[*dialect.SelectQuery]) UsersQue
|
|||
)...)
|
||||
}
|
||||
|
||||
func insertOrganizationAddressMappings0(ctx context.Context, exec bob.Executor, arcgisAddressMappings1 []*ArcgisAddressMappingSetter, organization0 *Organization) (ArcgisAddressMappingSlice, error) {
|
||||
for i := range arcgisAddressMappings1 {
|
||||
arcgisAddressMappings1[i].OrganizationID = omit.From(organization0.ID)
|
||||
}
|
||||
|
||||
ret, err := ArcgisAddressMappings.Insert(bob.ToMods(arcgisAddressMappings1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertOrganizationAddressMappings0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachOrganizationAddressMappings0(ctx context.Context, exec bob.Executor, count int, arcgisAddressMappings1 ArcgisAddressMappingSlice, organization0 *Organization) (ArcgisAddressMappingSlice, error) {
|
||||
setter := &ArcgisAddressMappingSetter{
|
||||
OrganizationID: omit.From(organization0.ID),
|
||||
}
|
||||
|
||||
err := arcgisAddressMappings1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOrganizationAddressMappings0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisAddressMappings1, nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) InsertAddressMappings(ctx context.Context, exec bob.Executor, related ...*ArcgisAddressMappingSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
arcgisAddressMappings1, err := insertOrganizationAddressMappings0(ctx, exec, related, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.AddressMappings = append(organization0.R.AddressMappings, arcgisAddressMappings1...)
|
||||
|
||||
for _, rel := range arcgisAddressMappings1 {
|
||||
rel.R.Organization = organization0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) AttachAddressMappings(ctx context.Context, exec bob.Executor, related ...*ArcgisAddressMapping) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
arcgisAddressMappings1 := ArcgisAddressMappingSlice(related)
|
||||
|
||||
_, err = attachOrganizationAddressMappings0(ctx, exec, len(related), arcgisAddressMappings1, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.AddressMappings = append(organization0.R.AddressMappings, arcgisAddressMappings1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = organization0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationParcelMappings0(ctx context.Context, exec bob.Executor, arcgisParcelMappings1 []*ArcgisParcelMappingSetter, organization0 *Organization) (ArcgisParcelMappingSlice, error) {
|
||||
for i := range arcgisParcelMappings1 {
|
||||
arcgisParcelMappings1[i].OrganizationID = omit.From(organization0.ID)
|
||||
}
|
||||
|
||||
ret, err := ArcgisParcelMappings.Insert(bob.ToMods(arcgisParcelMappings1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertOrganizationParcelMappings0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachOrganizationParcelMappings0(ctx context.Context, exec bob.Executor, count int, arcgisParcelMappings1 ArcgisParcelMappingSlice, organization0 *Organization) (ArcgisParcelMappingSlice, error) {
|
||||
setter := &ArcgisParcelMappingSetter{
|
||||
OrganizationID: omit.From(organization0.ID),
|
||||
}
|
||||
|
||||
err := arcgisParcelMappings1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOrganizationParcelMappings0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisParcelMappings1, nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) InsertParcelMappings(ctx context.Context, exec bob.Executor, related ...*ArcgisParcelMappingSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
arcgisParcelMappings1, err := insertOrganizationParcelMappings0(ctx, exec, related, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.ParcelMappings = append(organization0.R.ParcelMappings, arcgisParcelMappings1...)
|
||||
|
||||
for _, rel := range arcgisParcelMappings1 {
|
||||
rel.R.Organization = organization0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) AttachParcelMappings(ctx context.Context, exec bob.Executor, related ...*ArcgisParcelMapping) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
arcgisParcelMappings1 := ArcgisParcelMappingSlice(related)
|
||||
|
||||
_, err = attachOrganizationParcelMappings0(ctx, exec, len(related), arcgisParcelMappings1, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.ParcelMappings = append(organization0.R.ParcelMappings, arcgisParcelMappings1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = organization0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachOrganizationEmailContacts0(ctx context.Context, exec bob.Executor, count int, organization0 *Organization, commsEmailContacts2 CommsEmailContactSlice) (DistrictSubscriptionEmailSlice, error) {
|
||||
setters := make([]*DistrictSubscriptionEmailSetter, count)
|
||||
for i := range count {
|
||||
|
|
@ -4503,6 +4689,34 @@ func (o *Organization) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "AddressMappings":
|
||||
rels, ok := retrieved.(ArcgisAddressMappingSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.AddressMappings = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Organization = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "ParcelMappings":
|
||||
rels, ok := retrieved.(ArcgisParcelMappingSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ParcelMappings = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Organization = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "EmailContacts":
|
||||
rels, ok := retrieved.(CommsEmailContactSlice)
|
||||
if !ok {
|
||||
|
|
@ -5061,6 +5275,8 @@ func buildOrganizationPreloader() organizationPreloader {
|
|||
}
|
||||
|
||||
type organizationThenLoader[Q orm.Loadable] struct {
|
||||
AddressMappings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ParcelMappings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
EmailContacts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Phones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Containerrelates func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -5103,6 +5319,12 @@ type organizationThenLoader[Q orm.Loadable] struct {
|
|||
}
|
||||
|
||||
func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
||||
type AddressMappingsLoadInterface interface {
|
||||
LoadAddressMappings(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ParcelMappingsLoadInterface interface {
|
||||
LoadParcelMappings(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type EmailContactsLoadInterface interface {
|
||||
LoadEmailContacts(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -5222,6 +5444,18 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
}
|
||||
|
||||
return organizationThenLoader[Q]{
|
||||
AddressMappings: thenLoadBuilder[Q](
|
||||
"AddressMappings",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved AddressMappingsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadAddressMappings(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ParcelMappings: thenLoadBuilder[Q](
|
||||
"ParcelMappings",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ParcelMappingsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadParcelMappings(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
EmailContacts: thenLoadBuilder[Q](
|
||||
"EmailContacts",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved EmailContactsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -5459,6 +5693,128 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
}
|
||||
}
|
||||
|
||||
// LoadAddressMappings loads the organization's AddressMappings into the .R struct
|
||||
func (o *Organization) LoadAddressMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.AddressMappings = nil
|
||||
|
||||
related, err := o.AddressMappings(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = o
|
||||
}
|
||||
|
||||
o.R.AddressMappings = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadAddressMappings loads the organization's AddressMappings into the .R struct
|
||||
func (os OrganizationSlice) LoadAddressMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisAddressMappings, err := os.AddressMappings(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.AddressMappings = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisAddressMappings {
|
||||
|
||||
if !(o.ID == rel.OrganizationID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Organization = o
|
||||
|
||||
o.R.AddressMappings = append(o.R.AddressMappings, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadParcelMappings loads the organization's ParcelMappings into the .R struct
|
||||
func (o *Organization) LoadParcelMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ParcelMappings = nil
|
||||
|
||||
related, err := o.ParcelMappings(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Organization = o
|
||||
}
|
||||
|
||||
o.R.ParcelMappings = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadParcelMappings loads the organization's ParcelMappings into the .R struct
|
||||
func (os OrganizationSlice) LoadParcelMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisParcelMappings, err := os.ParcelMappings(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.ParcelMappings = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisParcelMappings {
|
||||
|
||||
if !(o.ID == rel.OrganizationID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Organization = o
|
||||
|
||||
o.R.ParcelMappings = append(o.R.ParcelMappings, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadEmailContacts loads the organization's EmailContacts into the .R struct
|
||||
func (o *Organization) LoadEmailContacts(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -7889,6 +8245,8 @@ func (os OrganizationSlice) LoadUser(ctx context.Context, exec bob.Executor, mod
|
|||
|
||||
// organizationC is where relationship counts are stored.
|
||||
type organizationC struct {
|
||||
AddressMappings *int64
|
||||
ParcelMappings *int64
|
||||
EmailContacts *int64
|
||||
Phones *int64
|
||||
Containerrelates *int64
|
||||
|
|
@ -7937,6 +8295,10 @@ func (o *Organization) PreloadCount(name string, count int64) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "AddressMappings":
|
||||
o.C.AddressMappings = &count
|
||||
case "ParcelMappings":
|
||||
o.C.ParcelMappings = &count
|
||||
case "EmailContacts":
|
||||
o.C.EmailContacts = &count
|
||||
case "Phones":
|
||||
|
|
@ -8020,6 +8382,8 @@ func (o *Organization) PreloadCount(name string, count int64) error {
|
|||
}
|
||||
|
||||
type organizationCountPreloader struct {
|
||||
AddressMappings func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
ParcelMappings func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
EmailContacts func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Phones func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Containerrelates func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
|
|
@ -8063,6 +8427,40 @@ type organizationCountPreloader struct {
|
|||
|
||||
func buildOrganizationCountPreloader() organizationCountPreloader {
|
||||
return organizationCountPreloader{
|
||||
AddressMappings: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("AddressMappings", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Organizations.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisAddressMappings.Name()),
|
||||
sm.Where(psql.Quote(ArcgisAddressMappings.Alias(), "organization_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
ParcelMappings: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("ParcelMappings", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Organizations.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisParcelMappings.Name()),
|
||||
sm.Where(psql.Quote(ArcgisParcelMappings.Alias(), "organization_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
EmailContacts: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("EmailContacts", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
|
|
@ -8736,6 +9134,8 @@ func buildOrganizationCountPreloader() organizationCountPreloader {
|
|||
}
|
||||
|
||||
type organizationCountThenLoader[Q orm.Loadable] struct {
|
||||
AddressMappings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ParcelMappings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
EmailContacts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Phones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Containerrelates func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -8778,6 +9178,12 @@ type organizationCountThenLoader[Q orm.Loadable] struct {
|
|||
}
|
||||
|
||||
func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoader[Q] {
|
||||
type AddressMappingsCountInterface interface {
|
||||
LoadCountAddressMappings(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ParcelMappingsCountInterface interface {
|
||||
LoadCountParcelMappings(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type EmailContactsCountInterface interface {
|
||||
LoadCountEmailContacts(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -8897,6 +9303,18 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
}
|
||||
|
||||
return organizationCountThenLoader[Q]{
|
||||
AddressMappings: countThenLoadBuilder[Q](
|
||||
"AddressMappings",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved AddressMappingsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountAddressMappings(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ParcelMappings: countThenLoadBuilder[Q](
|
||||
"ParcelMappings",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ParcelMappingsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountParcelMappings(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
EmailContacts: countThenLoadBuilder[Q](
|
||||
"EmailContacts",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved EmailContactsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -9134,6 +9552,66 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
}
|
||||
}
|
||||
|
||||
// LoadCountAddressMappings loads the count of AddressMappings into the C struct
|
||||
func (o *Organization) LoadCountAddressMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.AddressMappings(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.AddressMappings = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountAddressMappings loads the count of AddressMappings for a slice
|
||||
func (os OrganizationSlice) LoadCountAddressMappings(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.LoadCountAddressMappings(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountParcelMappings loads the count of ParcelMappings into the C struct
|
||||
func (o *Organization) LoadCountParcelMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.ParcelMappings(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.ParcelMappings = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountParcelMappings loads the count of ParcelMappings for a slice
|
||||
func (os OrganizationSlice) LoadCountParcelMappings(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.LoadCountParcelMappings(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountEmailContacts loads the count of EmailContacts into the C struct
|
||||
func (o *Organization) LoadCountEmailContacts(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -10306,6 +10784,8 @@ func (os OrganizationSlice) LoadCountUser(ctx context.Context, exec bob.Executor
|
|||
|
||||
type organizationJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
AddressMappings modAs[Q, arcgisAddressMappingColumns]
|
||||
ParcelMappings modAs[Q, arcgisParcelMappingColumns]
|
||||
EmailContacts modAs[Q, commsEmailContactColumns]
|
||||
Phones modAs[Q, commsPhoneColumns]
|
||||
Containerrelates modAs[Q, fieldseekerContainerrelateColumns]
|
||||
|
|
@ -10354,6 +10834,34 @@ func (j organizationJoins[Q]) aliasedAs(alias string) organizationJoins[Q] {
|
|||
func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ string) organizationJoins[Q] {
|
||||
return organizationJoins[Q]{
|
||||
typ: typ,
|
||||
AddressMappings: modAs[Q, arcgisAddressMappingColumns]{
|
||||
c: ArcgisAddressMappings.Columns,
|
||||
f: func(to arcgisAddressMappingColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisAddressMappings.Name().As(to.Alias())).On(
|
||||
to.OrganizationID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
ParcelMappings: modAs[Q, arcgisParcelMappingColumns]{
|
||||
c: ArcgisParcelMappings.Columns,
|
||||
f: func(to arcgisParcelMappingColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisParcelMappings.Name().As(to.Alias())).On(
|
||||
to.OrganizationID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
EmailContacts: modAs[Q, commsEmailContactColumns]{
|
||||
c: CommsEmailContacts.Columns,
|
||||
f: func(to commsEmailContactColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
423
db/models/parcel.bob.go
Normal file
423
db/models/parcel.bob.go
Normal file
|
|
@ -0,0 +1,423 @@
|
|||
// 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"
|
||||
"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/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// Parcel is an object representing the database table.
|
||||
type Parcel struct {
|
||||
Apn string `db:"apn" `
|
||||
Description string `db:"description" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Geometry string `db:"geometry" `
|
||||
}
|
||||
|
||||
// ParcelSlice is an alias for a slice of pointers to Parcel.
|
||||
// This should almost always be used instead of []*Parcel.
|
||||
type ParcelSlice []*Parcel
|
||||
|
||||
// Parcels contains methods to work with the parcel table
|
||||
var Parcels = psql.NewTablex[*Parcel, ParcelSlice, *ParcelSetter]("", "parcel", buildParcelColumns("parcel"))
|
||||
|
||||
// ParcelsQuery is a query on the parcel table
|
||||
type ParcelsQuery = *psql.ViewQuery[*Parcel, ParcelSlice]
|
||||
|
||||
func buildParcelColumns(alias string) parcelColumns {
|
||||
return parcelColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"apn", "description", "id", "geometry",
|
||||
).WithParent("parcel"),
|
||||
tableAlias: alias,
|
||||
Apn: psql.Quote(alias, "apn"),
|
||||
Description: psql.Quote(alias, "description"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Geometry: psql.Quote(alias, "geometry"),
|
||||
}
|
||||
}
|
||||
|
||||
type parcelColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Apn psql.Expression
|
||||
Description psql.Expression
|
||||
ID psql.Expression
|
||||
Geometry psql.Expression
|
||||
}
|
||||
|
||||
func (c parcelColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (parcelColumns) AliasedAs(alias string) parcelColumns {
|
||||
return buildParcelColumns(alias)
|
||||
}
|
||||
|
||||
// ParcelSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ParcelSetter struct {
|
||||
Apn omit.Val[string] `db:"apn" `
|
||||
Description omit.Val[string] `db:"description" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Geometry omit.Val[string] `db:"geometry" `
|
||||
}
|
||||
|
||||
func (s ParcelSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
if s.Apn.IsValue() {
|
||||
vals = append(vals, "apn")
|
||||
}
|
||||
if s.Description.IsValue() {
|
||||
vals = append(vals, "description")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Geometry.IsValue() {
|
||||
vals = append(vals, "geometry")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ParcelSetter) Overwrite(t *Parcel) {
|
||||
if s.Apn.IsValue() {
|
||||
t.Apn = s.Apn.MustGet()
|
||||
}
|
||||
if s.Description.IsValue() {
|
||||
t.Description = s.Description.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Geometry.IsValue() {
|
||||
t.Geometry = s.Geometry.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ParcelSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return Parcels.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.Apn.IsValue() {
|
||||
vals[0] = psql.Arg(s.Apn.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Description.IsValue() {
|
||||
vals[1] = psql.Arg(s.Description.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[2] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Geometry.IsValue() {
|
||||
vals[3] = psql.Arg(s.Geometry.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ParcelSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ParcelSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
|
||||
if s.Apn.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "apn")...),
|
||||
psql.Arg(s.Apn),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Description.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "description")...),
|
||||
psql.Arg(s.Description),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Geometry.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "geometry")...),
|
||||
psql.Arg(s.Geometry),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindParcel retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindParcel(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Parcel, error) {
|
||||
if len(cols) == 0 {
|
||||
return Parcels.Query(
|
||||
sm.Where(Parcels.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return Parcels.Query(
|
||||
sm.Where(Parcels.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(Parcels.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ParcelExists checks the presence of a single record by primary key
|
||||
func ParcelExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return Parcels.Query(
|
||||
sm.Where(Parcels.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after Parcel is retrieved from the database
|
||||
func (o *Parcel) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = Parcels.AfterSelectHooks.RunHooks(ctx, exec, ParcelSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = Parcels.AfterInsertHooks.RunHooks(ctx, exec, ParcelSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = Parcels.AfterUpdateHooks.RunHooks(ctx, exec, ParcelSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = Parcels.AfterDeleteHooks.RunHooks(ctx, exec, ParcelSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the Parcel
|
||||
func (o *Parcel) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *Parcel) pkEQ() dialect.Expression {
|
||||
return psql.Quote("parcel", "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 Parcel
|
||||
func (o *Parcel) Update(ctx context.Context, exec bob.Executor, s *ParcelSetter) error {
|
||||
v, err := Parcels.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single Parcel record with an executor
|
||||
func (o *Parcel) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := Parcels.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the Parcel using the executor
|
||||
func (o *Parcel) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := Parcels.Query(
|
||||
sm.Where(Parcels.Columns.ID.EQ(psql.Arg(o.ID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ParcelSlice is retrieved from the database
|
||||
func (o ParcelSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = Parcels.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = Parcels.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = Parcels.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = Parcels.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ParcelSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("parcel", "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 ParcelSlice) copyMatchingRows(from ...*Parcel) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ParcelSlice) 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 Parcels.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 *Parcel:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*Parcel:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ParcelSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a Parcel or a slice of Parcel
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = Parcels.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ParcelSlice) 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 Parcels.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 *Parcel:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*Parcel:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ParcelSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a Parcel or a slice of Parcel
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = Parcels.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ParcelSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ParcelSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := Parcels.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ParcelSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := Parcels.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ParcelSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := Parcels.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type parcelWhere[Q psql.Filterable] struct {
|
||||
Apn psql.WhereMod[Q, string]
|
||||
Description psql.WhereMod[Q, string]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Geometry psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (parcelWhere[Q]) AliasedAs(alias string) parcelWhere[Q] {
|
||||
return buildParcelWhere[Q](buildParcelColumns(alias))
|
||||
}
|
||||
|
||||
func buildParcelWhere[Q psql.Filterable](cols parcelColumns) parcelWhere[Q] {
|
||||
return parcelWhere[Q]{
|
||||
Apn: psql.Where[Q, string](cols.Apn),
|
||||
Description: psql.Where[Q, string](cols.Description),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Geometry: psql.Where[Q, string](cols.Geometry),
|
||||
}
|
||||
}
|
||||
681
db/models/pool.bob.go
Normal file
681
db/models/pool.bob.go
Normal file
|
|
@ -0,0 +1,681 @@
|
|||
// 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"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
)
|
||||
|
||||
// Pool is an object representing the database table.
|
||||
type Pool struct {
|
||||
Condition enums.Poolconditiontype `db:"condition" `
|
||||
Created time.Time `db:"created" `
|
||||
CreatorID int32 `db:"creator_id" `
|
||||
ID int32 `db:"id,pk" `
|
||||
SiteID null.Val[int32] `db:"site_id" `
|
||||
|
||||
R poolR `db:"-" `
|
||||
}
|
||||
|
||||
// PoolSlice is an alias for a slice of pointers to Pool.
|
||||
// This should almost always be used instead of []*Pool.
|
||||
type PoolSlice []*Pool
|
||||
|
||||
// Pools contains methods to work with the pool table
|
||||
var Pools = psql.NewTablex[*Pool, PoolSlice, *PoolSetter]("", "pool", buildPoolColumns("pool"))
|
||||
|
||||
// PoolsQuery is a query on the pool table
|
||||
type PoolsQuery = *psql.ViewQuery[*Pool, PoolSlice]
|
||||
|
||||
// poolR is where relationships are stored.
|
||||
type poolR struct {
|
||||
CreatorUser *User // pool.pool_creator_id_fkey
|
||||
}
|
||||
|
||||
func buildPoolColumns(alias string) poolColumns {
|
||||
return poolColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"condition", "created", "creator_id", "id", "site_id",
|
||||
).WithParent("pool"),
|
||||
tableAlias: alias,
|
||||
Condition: psql.Quote(alias, "condition"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
CreatorID: psql.Quote(alias, "creator_id"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type poolColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Condition psql.Expression
|
||||
Created psql.Expression
|
||||
CreatorID psql.Expression
|
||||
ID psql.Expression
|
||||
SiteID psql.Expression
|
||||
}
|
||||
|
||||
func (c poolColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (poolColumns) AliasedAs(alias string) poolColumns {
|
||||
return buildPoolColumns(alias)
|
||||
}
|
||||
|
||||
// PoolSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PoolSetter struct {
|
||||
Condition omit.Val[enums.Poolconditiontype] `db:"condition" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
CreatorID omit.Val[int32] `db:"creator_id" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
SiteID omitnull.Val[int32] `db:"site_id" `
|
||||
}
|
||||
|
||||
func (s PoolSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.Condition.IsValue() {
|
||||
vals = append(vals, "condition")
|
||||
}
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if s.CreatorID.IsValue() {
|
||||
vals = append(vals, "creator_id")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if !s.SiteID.IsUnset() {
|
||||
vals = append(vals, "site_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s PoolSetter) Overwrite(t *Pool) {
|
||||
if s.Condition.IsValue() {
|
||||
t.Condition = s.Condition.MustGet()
|
||||
}
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
if s.CreatorID.IsValue() {
|
||||
t.CreatorID = s.CreatorID.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if !s.SiteID.IsUnset() {
|
||||
t.SiteID = s.SiteID.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PoolSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return Pools.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, 5)
|
||||
if s.Condition.IsValue() {
|
||||
vals[0] = psql.Arg(s.Condition.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
vals[1] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.CreatorID.IsValue() {
|
||||
vals[2] = psql.Arg(s.CreatorID.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[3] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.SiteID.IsUnset() {
|
||||
vals[4] = psql.Arg(s.SiteID.MustGetNull())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s PoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s PoolSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.Condition.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "condition")...),
|
||||
psql.Arg(s.Condition),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.CreatorID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "creator_id")...),
|
||||
psql.Arg(s.CreatorID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.SiteID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_id")...),
|
||||
psql.Arg(s.SiteID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindPool retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPool(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Pool, error) {
|
||||
if len(cols) == 0 {
|
||||
return Pools.Query(
|
||||
sm.Where(Pools.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return Pools.Query(
|
||||
sm.Where(Pools.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(Pools.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PoolExists checks the presence of a single record by primary key
|
||||
func PoolExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return Pools.Query(
|
||||
sm.Where(Pools.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after Pool is retrieved from the database
|
||||
func (o *Pool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = Pools.AfterSelectHooks.RunHooks(ctx, exec, PoolSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = Pools.AfterInsertHooks.RunHooks(ctx, exec, PoolSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = Pools.AfterUpdateHooks.RunHooks(ctx, exec, PoolSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = Pools.AfterDeleteHooks.RunHooks(ctx, exec, PoolSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the Pool
|
||||
func (o *Pool) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *Pool) pkEQ() dialect.Expression {
|
||||
return psql.Quote("pool", "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 Pool
|
||||
func (o *Pool) Update(ctx context.Context, exec bob.Executor, s *PoolSetter) error {
|
||||
v, err := Pools.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 Pool record with an executor
|
||||
func (o *Pool) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := Pools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the Pool using the executor
|
||||
func (o *Pool) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := Pools.Query(
|
||||
sm.Where(Pools.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 PoolSlice is retrieved from the database
|
||||
func (o PoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = Pools.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = Pools.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = Pools.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = Pools.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PoolSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("pool", "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 PoolSlice) copyMatchingRows(from ...*Pool) {
|
||||
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 PoolSlice) 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 Pools.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 *Pool:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*Pool:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PoolSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a Pool or a slice of Pool
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = Pools.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PoolSlice) 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 Pools.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 *Pool:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*Pool:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PoolSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a Pool or a slice of Pool
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = Pools.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PoolSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := Pools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := Pools.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := Pools.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreatorUser starts a query for related objects on user_
|
||||
func (o *Pool) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.CreatorID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PoolSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkCreatorID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkCreatorID = append(pkCreatorID, o.CreatorID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkCreatorID), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPoolCreatorUser0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, user1 *User) (*Pool, error) {
|
||||
setter := &PoolSetter{
|
||||
CreatorID: omit.From(user1.ID),
|
||||
}
|
||||
|
||||
err := pool0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPoolCreatorUser0: %w", err)
|
||||
}
|
||||
|
||||
return pool0, nil
|
||||
}
|
||||
|
||||
func (pool0 *Pool) InsertCreatorUser(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 = attachPoolCreatorUser0(ctx, exec, 1, pool0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pool0.R.CreatorUser = user1
|
||||
|
||||
user1.R.CreatorPools = append(user1.R.CreatorPools, pool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pool0 *Pool) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPoolCreatorUser0(ctx, exec, 1, pool0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pool0.R.CreatorUser = user1
|
||||
|
||||
user1.R.CreatorPools = append(user1.R.CreatorPools, pool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type poolWhere[Q psql.Filterable] struct {
|
||||
Condition psql.WhereMod[Q, enums.Poolconditiontype]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
CreatorID psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
SiteID psql.WhereNullMod[Q, int32]
|
||||
}
|
||||
|
||||
func (poolWhere[Q]) AliasedAs(alias string) poolWhere[Q] {
|
||||
return buildPoolWhere[Q](buildPoolColumns(alias))
|
||||
}
|
||||
|
||||
func buildPoolWhere[Q psql.Filterable](cols poolColumns) poolWhere[Q] {
|
||||
return poolWhere[Q]{
|
||||
Condition: psql.Where[Q, enums.Poolconditiontype](cols.Condition),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
CreatorID: psql.Where[Q, int32](cols.CreatorID),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
SiteID: psql.WhereNull[Q, int32](cols.SiteID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Pool) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "CreatorUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("pool cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CreatorUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.CreatorPools = PoolSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("pool has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type poolPreloader struct {
|
||||
CreatorUser func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPoolPreloader() poolPreloader {
|
||||
return poolPreloader{
|
||||
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "CreatorUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: Pools,
|
||||
To: Users,
|
||||
FromColumns: []string{"creator_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type poolThenLoader[Q orm.Loadable] struct {
|
||||
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPoolThenLoader[Q orm.Loadable]() poolThenLoader[Q] {
|
||||
type CreatorUserLoadInterface interface {
|
||||
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return poolThenLoader[Q]{
|
||||
CreatorUser: thenLoadBuilder[Q](
|
||||
"CreatorUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCreatorUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCreatorUser loads the pool's CreatorUser into the .R struct
|
||||
func (o *Pool) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CreatorUser = nil
|
||||
|
||||
related, err := o.CreatorUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.CreatorPools = PoolSlice{o}
|
||||
|
||||
o.R.CreatorUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorUser loads the pool's CreatorUser into the .R struct
|
||||
func (os PoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.CreatorUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
|
||||
if !(o.CreatorID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CreatorPools = append(rel.R.CreatorPools, o)
|
||||
|
||||
o.R.CreatorUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type poolJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
CreatorUser modAs[Q, userColumns]
|
||||
}
|
||||
|
||||
func (j poolJoins[Q]) aliasedAs(alias string) poolJoins[Q] {
|
||||
return buildPoolJoins[Q](buildPoolColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPoolJoins[Q dialect.Joinable](cols poolColumns, typ string) poolJoins[Q] {
|
||||
return poolJoins[Q]{
|
||||
typ: typ,
|
||||
CreatorUser: 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.CreatorID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
1245
db/models/site.bob.go
Normal file
1245
db/models/site.bob.go
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -60,13 +60,15 @@ type UsersQuery = *psql.ViewQuery[*User, UserSlice]
|
|||
type userR struct {
|
||||
PublicUserUser ArcgisUserSlice // arcgis.user_.user__public_user_id_fkey
|
||||
CreatorFiles FileuploadFileSlice // fileupload.file.file_creator_id_fkey
|
||||
CreatorPools FileuploadPoolSlice // fileupload.pool.pool_creator_id_fkey
|
||||
FileuploadPool FileuploadPoolSlice // fileupload.pool.pool_creator_id_fkey
|
||||
CreatorNoteAudios NoteAudioSlice // note_audio.note_audio_creator_id_fkey
|
||||
DeletorNoteAudios NoteAudioSlice // note_audio.note_audio_deletor_id_fkey
|
||||
CreatorNoteImages NoteImageSlice // note_image.note_image_creator_id_fkey
|
||||
DeletorNoteImages NoteImageSlice // note_image.note_image_deletor_id_fkey
|
||||
UserNotifications NotificationSlice // notification.notification_user_id_fkey
|
||||
UserOauthTokens OauthTokenSlice // oauth_token.oauth_token_user_id_fkey
|
||||
CreatorPools PoolSlice // pool.pool_creator_id_fkey
|
||||
CreatorSites SiteSlice // site.site_creator_id_fkey
|
||||
Organization *Organization // user_.user__organization_id_fkey
|
||||
}
|
||||
|
||||
|
|
@ -684,14 +686,14 @@ func (os UserSlice) CreatorFiles(mods ...bob.Mod[*dialect.SelectQuery]) Fileuplo
|
|||
)...)
|
||||
}
|
||||
|
||||
// CreatorPools starts a query for related objects on fileupload.pool
|
||||
func (o *User) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery {
|
||||
// FileuploadPool starts a query for related objects on fileupload.pool
|
||||
func (o *User) FileuploadPool(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery {
|
||||
return FileuploadPools.Query(append(mods,
|
||||
sm.Where(FileuploadPools.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery {
|
||||
func (os UserSlice) FileuploadPool(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -852,6 +854,54 @@ func (os UserSlice) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) Oauth
|
|||
)...)
|
||||
}
|
||||
|
||||
// CreatorPools starts a query for related objects on pool
|
||||
func (o *User) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery {
|
||||
return Pools.Query(append(mods,
|
||||
sm.Where(Pools.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return Pools.Query(append(mods,
|
||||
sm.Where(psql.Group(Pools.Columns.CreatorID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// CreatorSites starts a query for related objects on site
|
||||
func (o *User) CreatorSites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) CreatorSites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.CreatorID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *User) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
|
|
@ -1012,45 +1062,45 @@ func (user0 *User) AttachCreatorFiles(ctx context.Context, exec bob.Executor, re
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertUserCreatorPools0(ctx context.Context, exec bob.Executor, fileuploadPools1 []*FileuploadPoolSetter, user0 *User) (FileuploadPoolSlice, error) {
|
||||
func insertUserFileuploadPool0(ctx context.Context, exec bob.Executor, fileuploadPools1 []*FileuploadPoolSetter, user0 *User) (FileuploadPoolSlice, error) {
|
||||
for i := range fileuploadPools1 {
|
||||
fileuploadPools1[i].CreatorID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := FileuploadPools.Insert(bob.ToMods(fileuploadPools1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserCreatorPools0: %w", err)
|
||||
return ret, fmt.Errorf("insertUserFileuploadPool0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserCreatorPools0(ctx context.Context, exec bob.Executor, count int, fileuploadPools1 FileuploadPoolSlice, user0 *User) (FileuploadPoolSlice, error) {
|
||||
func attachUserFileuploadPool0(ctx context.Context, exec bob.Executor, count int, fileuploadPools1 FileuploadPoolSlice, user0 *User) (FileuploadPoolSlice, error) {
|
||||
setter := &FileuploadPoolSetter{
|
||||
CreatorID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := fileuploadPools1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserCreatorPools0: %w", err)
|
||||
return nil, fmt.Errorf("attachUserFileuploadPool0: %w", err)
|
||||
}
|
||||
|
||||
return fileuploadPools1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertCreatorPools(ctx context.Context, exec bob.Executor, related ...*FileuploadPoolSetter) error {
|
||||
func (user0 *User) InsertFileuploadPool(ctx context.Context, exec bob.Executor, related ...*FileuploadPoolSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
fileuploadPools1, err := insertUserCreatorPools0(ctx, exec, related, user0)
|
||||
fileuploadPools1, err := insertUserFileuploadPool0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorPools = append(user0.R.CreatorPools, fileuploadPools1...)
|
||||
user0.R.FileuploadPool = append(user0.R.FileuploadPool, fileuploadPools1...)
|
||||
|
||||
for _, rel := range fileuploadPools1 {
|
||||
rel.R.CreatorUser = user0
|
||||
|
|
@ -1058,7 +1108,7 @@ func (user0 *User) InsertCreatorPools(ctx context.Context, exec bob.Executor, re
|
|||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachCreatorPools(ctx context.Context, exec bob.Executor, related ...*FileuploadPool) error {
|
||||
func (user0 *User) AttachFileuploadPool(ctx context.Context, exec bob.Executor, related ...*FileuploadPool) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1066,12 +1116,12 @@ func (user0 *User) AttachCreatorPools(ctx context.Context, exec bob.Executor, re
|
|||
var err error
|
||||
fileuploadPools1 := FileuploadPoolSlice(related)
|
||||
|
||||
_, err = attachUserCreatorPools0(ctx, exec, len(related), fileuploadPools1, user0)
|
||||
_, err = attachUserFileuploadPool0(ctx, exec, len(related), fileuploadPools1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorPools = append(user0.R.CreatorPools, fileuploadPools1...)
|
||||
user0.R.FileuploadPool = append(user0.R.FileuploadPool, fileuploadPools1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = user0
|
||||
|
|
@ -1488,6 +1538,142 @@ func (user0 *User) AttachUserOauthTokens(ctx context.Context, exec bob.Executor,
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertUserCreatorPools0(ctx context.Context, exec bob.Executor, pools1 []*PoolSetter, user0 *User) (PoolSlice, error) {
|
||||
for i := range pools1 {
|
||||
pools1[i].CreatorID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := Pools.Insert(bob.ToMods(pools1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserCreatorPools0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserCreatorPools0(ctx context.Context, exec bob.Executor, count int, pools1 PoolSlice, user0 *User) (PoolSlice, error) {
|
||||
setter := &PoolSetter{
|
||||
CreatorID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := pools1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserCreatorPools0: %w", err)
|
||||
}
|
||||
|
||||
return pools1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertCreatorPools(ctx context.Context, exec bob.Executor, related ...*PoolSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
pools1, err := insertUserCreatorPools0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorPools = append(user0.R.CreatorPools, pools1...)
|
||||
|
||||
for _, rel := range pools1 {
|
||||
rel.R.CreatorUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachCreatorPools(ctx context.Context, exec bob.Executor, related ...*Pool) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
pools1 := PoolSlice(related)
|
||||
|
||||
_, err = attachUserCreatorPools0(ctx, exec, len(related), pools1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorPools = append(user0.R.CreatorPools, pools1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertUserCreatorSites0(ctx context.Context, exec bob.Executor, sites1 []*SiteSetter, user0 *User) (SiteSlice, error) {
|
||||
for i := range sites1 {
|
||||
sites1[i].CreatorID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := Sites.Insert(bob.ToMods(sites1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserCreatorSites0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserCreatorSites0(ctx context.Context, exec bob.Executor, count int, sites1 SiteSlice, user0 *User) (SiteSlice, error) {
|
||||
setter := &SiteSetter{
|
||||
CreatorID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := sites1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserCreatorSites0: %w", err)
|
||||
}
|
||||
|
||||
return sites1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertCreatorSites(ctx context.Context, exec bob.Executor, related ...*SiteSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
sites1, err := insertUserCreatorSites0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorSites = append(user0.R.CreatorSites, sites1...)
|
||||
|
||||
for _, rel := range sites1 {
|
||||
rel.R.CreatorUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachCreatorSites(ctx context.Context, exec bob.Executor, related ...*Site) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
sites1 := SiteSlice(related)
|
||||
|
||||
_, err = attachUserCreatorSites0(ctx, exec, len(related), sites1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.CreatorSites = append(user0.R.CreatorSites, sites1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachUserOrganization0(ctx context.Context, exec bob.Executor, count int, user0 *User, organization1 *Organization) (*User, error) {
|
||||
setter := &UserSetter{
|
||||
OrganizationID: omit.From(organization1.ID),
|
||||
|
|
@ -1608,13 +1794,13 @@ func (o *User) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "CreatorPools":
|
||||
case "FileuploadPool":
|
||||
rels, ok := retrieved.(FileuploadPoolSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CreatorPools = rels
|
||||
o.R.FileuploadPool = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
|
|
@ -1706,6 +1892,34 @@ func (o *User) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "CreatorPools":
|
||||
rels, ok := retrieved.(PoolSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CreatorPools = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.CreatorUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "CreatorSites":
|
||||
rels, ok := retrieved.(SiteSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CreatorSites = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.CreatorUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
|
|
@ -1748,13 +1962,15 @@ func buildUserPreloader() userPreloader {
|
|||
type userThenLoader[Q orm.Loadable] struct {
|
||||
PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
FileuploadPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorSites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -1765,8 +1981,8 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
type CreatorFilesLoadInterface interface {
|
||||
LoadCreatorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorPoolsLoadInterface interface {
|
||||
LoadCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type FileuploadPoolLoadInterface interface {
|
||||
LoadFileuploadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorNoteAudiosLoadInterface interface {
|
||||
LoadCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
|
|
@ -1786,6 +2002,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
type UserOauthTokensLoadInterface interface {
|
||||
LoadUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorPoolsLoadInterface interface {
|
||||
LoadCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorSitesLoadInterface interface {
|
||||
LoadCreatorSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -1803,10 +2025,10 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
return retrieved.LoadCreatorFiles(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorPools: thenLoadBuilder[Q](
|
||||
"CreatorPools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCreatorPools(ctx, exec, mods...)
|
||||
FileuploadPool: thenLoadBuilder[Q](
|
||||
"FileuploadPool",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FileuploadPoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFileuploadPool(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorNoteAudios: thenLoadBuilder[Q](
|
||||
|
|
@ -1845,6 +2067,18 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
return retrieved.LoadUserOauthTokens(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorPools: thenLoadBuilder[Q](
|
||||
"CreatorPools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCreatorPools(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorSites: thenLoadBuilder[Q](
|
||||
"CreatorSites",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorSitesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCreatorSites(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -1976,16 +2210,16 @@ func (os UserSlice) LoadCreatorFiles(ctx context.Context, exec bob.Executor, mod
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorPools loads the user's CreatorPools into the .R struct
|
||||
func (o *User) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadFileuploadPool loads the user's FileuploadPool into the .R struct
|
||||
func (o *User) LoadFileuploadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CreatorPools = nil
|
||||
o.R.FileuploadPool = nil
|
||||
|
||||
related, err := o.CreatorPools(mods...).All(ctx, exec)
|
||||
related, err := o.FileuploadPool(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1994,17 +2228,17 @@ func (o *User) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...
|
|||
rel.R.CreatorUser = o
|
||||
}
|
||||
|
||||
o.R.CreatorPools = related
|
||||
o.R.FileuploadPool = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorPools loads the user's CreatorPools into the .R struct
|
||||
func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadFileuploadPool loads the user's FileuploadPool into the .R struct
|
||||
func (os UserSlice) LoadFileuploadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileuploadPools, err := os.CreatorPools(mods...).All(ctx, exec)
|
||||
fileuploadPools, err := os.FileuploadPool(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -2014,7 +2248,7 @@ func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mod
|
|||
continue
|
||||
}
|
||||
|
||||
o.R.CreatorPools = nil
|
||||
o.R.FileuploadPool = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
|
|
@ -2030,7 +2264,7 @@ func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mod
|
|||
|
||||
rel.R.CreatorUser = o
|
||||
|
||||
o.R.CreatorPools = append(o.R.CreatorPools, rel)
|
||||
o.R.FileuploadPool = append(o.R.FileuploadPool, rel)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2409,6 +2643,128 @@ func (os UserSlice) LoadUserOauthTokens(ctx context.Context, exec bob.Executor,
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorPools loads the user's CreatorPools into the .R struct
|
||||
func (o *User) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CreatorPools = nil
|
||||
|
||||
related, err := o.CreatorPools(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = o
|
||||
}
|
||||
|
||||
o.R.CreatorPools = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorPools loads the user's CreatorPools into the .R struct
|
||||
func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
pools, err := os.CreatorPools(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.CreatorPools = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range pools {
|
||||
|
||||
if !(o.ID == rel.CreatorID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CreatorUser = o
|
||||
|
||||
o.R.CreatorPools = append(o.R.CreatorPools, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorSites loads the user's CreatorSites into the .R struct
|
||||
func (o *User) LoadCreatorSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CreatorSites = nil
|
||||
|
||||
related, err := o.CreatorSites(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.CreatorUser = o
|
||||
}
|
||||
|
||||
o.R.CreatorSites = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorSites loads the user's CreatorSites into the .R struct
|
||||
func (os UserSlice) LoadCreatorSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sites, err := os.CreatorSites(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.CreatorSites = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range sites {
|
||||
|
||||
if !(o.ID == rel.CreatorID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CreatorUser = o
|
||||
|
||||
o.R.CreatorSites = append(o.R.CreatorSites, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the user's Organization into the .R struct
|
||||
func (o *User) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -2465,13 +2821,15 @@ func (os UserSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mod
|
|||
type userC struct {
|
||||
PublicUserUser *int64
|
||||
CreatorFiles *int64
|
||||
CreatorPools *int64
|
||||
FileuploadPool *int64
|
||||
CreatorNoteAudios *int64
|
||||
DeletorNoteAudios *int64
|
||||
CreatorNoteImages *int64
|
||||
DeletorNoteImages *int64
|
||||
UserNotifications *int64
|
||||
UserOauthTokens *int64
|
||||
CreatorPools *int64
|
||||
CreatorSites *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -2485,8 +2843,8 @@ func (o *User) PreloadCount(name string, count int64) error {
|
|||
o.C.PublicUserUser = &count
|
||||
case "CreatorFiles":
|
||||
o.C.CreatorFiles = &count
|
||||
case "CreatorPools":
|
||||
o.C.CreatorPools = &count
|
||||
case "FileuploadPool":
|
||||
o.C.FileuploadPool = &count
|
||||
case "CreatorNoteAudios":
|
||||
o.C.CreatorNoteAudios = &count
|
||||
case "DeletorNoteAudios":
|
||||
|
|
@ -2499,6 +2857,10 @@ func (o *User) PreloadCount(name string, count int64) error {
|
|||
o.C.UserNotifications = &count
|
||||
case "UserOauthTokens":
|
||||
o.C.UserOauthTokens = &count
|
||||
case "CreatorPools":
|
||||
o.C.CreatorPools = &count
|
||||
case "CreatorSites":
|
||||
o.C.CreatorSites = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -2506,13 +2868,15 @@ func (o *User) PreloadCount(name string, count int64) error {
|
|||
type userCountPreloader struct {
|
||||
PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
FileuploadPool func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
CreatorSites func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildUserCountPreloader() userCountPreloader {
|
||||
|
|
@ -2551,8 +2915,8 @@ func buildUserCountPreloader() userCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
CreatorPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*User]("CreatorPools", func(parent string) bob.Expression {
|
||||
FileuploadPool: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*User]("FileuploadPool", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Users.Alias()
|
||||
|
|
@ -2670,19 +3034,55 @@ func buildUserCountPreloader() userCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
CreatorPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*User]("CreatorPools", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Users.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Pools.Name()),
|
||||
sm.Where(psql.Quote(Pools.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
CreatorSites: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*User]("CreatorSites", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Users.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Sites.Name()),
|
||||
sm.Where(psql.Quote(Sites.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type userCountThenLoader[Q orm.Loadable] struct {
|
||||
PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
FileuploadPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorSites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
||||
|
|
@ -2692,8 +3092,8 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|||
type CreatorFilesCountInterface interface {
|
||||
LoadCountCreatorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorPoolsCountInterface interface {
|
||||
LoadCountCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type FileuploadPoolCountInterface interface {
|
||||
LoadCountFileuploadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorNoteAudiosCountInterface interface {
|
||||
LoadCountCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
|
|
@ -2713,6 +3113,12 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|||
type UserOauthTokensCountInterface interface {
|
||||
LoadCountUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorPoolsCountInterface interface {
|
||||
LoadCountCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorSitesCountInterface interface {
|
||||
LoadCountCreatorSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return userCountThenLoader[Q]{
|
||||
PublicUserUser: countThenLoadBuilder[Q](
|
||||
|
|
@ -2727,10 +3133,10 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|||
return retrieved.LoadCountCreatorFiles(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorPools: countThenLoadBuilder[Q](
|
||||
"CreatorPools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountCreatorPools(ctx, exec, mods...)
|
||||
FileuploadPool: countThenLoadBuilder[Q](
|
||||
"FileuploadPool",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FileuploadPoolCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountFileuploadPool(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorNoteAudios: countThenLoadBuilder[Q](
|
||||
|
|
@ -2769,6 +3175,18 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|||
return retrieved.LoadCountUserOauthTokens(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorPools: countThenLoadBuilder[Q](
|
||||
"CreatorPools",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountCreatorPools(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorSites: countThenLoadBuilder[Q](
|
||||
"CreatorSites",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorSitesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountCreatorSites(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2832,29 +3250,29 @@ func (os UserSlice) LoadCountCreatorFiles(ctx context.Context, exec bob.Executor
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorPools loads the count of CreatorPools into the C struct
|
||||
func (o *User) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountFileuploadPool loads the count of FileuploadPool into the C struct
|
||||
func (o *User) LoadCountFileuploadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.CreatorPools(mods...).Count(ctx, exec)
|
||||
count, err := o.FileuploadPool(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.CreatorPools = &count
|
||||
o.C.FileuploadPool = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorPools loads the count of CreatorPools for a slice
|
||||
func (os UserSlice) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadCountFileuploadPool loads the count of FileuploadPool for a slice
|
||||
func (os UserSlice) LoadCountFileuploadPool(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.LoadCountCreatorPools(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountFileuploadPool(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -3042,17 +3460,79 @@ func (os UserSlice) LoadCountUserOauthTokens(ctx context.Context, exec bob.Execu
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorPools loads the count of CreatorPools into the C struct
|
||||
func (o *User) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.CreatorPools(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.CreatorPools = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorPools loads the count of CreatorPools for a slice
|
||||
func (os UserSlice) LoadCountCreatorPools(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.LoadCountCreatorPools(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorSites loads the count of CreatorSites into the C struct
|
||||
func (o *User) LoadCountCreatorSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.CreatorSites(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.CreatorSites = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountCreatorSites loads the count of CreatorSites for a slice
|
||||
func (os UserSlice) LoadCountCreatorSites(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.LoadCountCreatorSites(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type userJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
PublicUserUser modAs[Q, arcgisuserColumns]
|
||||
CreatorFiles modAs[Q, fileuploadFileColumns]
|
||||
CreatorPools modAs[Q, fileuploadPoolColumns]
|
||||
FileuploadPool modAs[Q, fileuploadPoolColumns]
|
||||
CreatorNoteAudios modAs[Q, noteAudioColumns]
|
||||
DeletorNoteAudios modAs[Q, noteAudioColumns]
|
||||
CreatorNoteImages modAs[Q, noteImageColumns]
|
||||
DeletorNoteImages modAs[Q, noteImageColumns]
|
||||
UserNotifications modAs[Q, notificationColumns]
|
||||
UserOauthTokens modAs[Q, oauthTokenColumns]
|
||||
CreatorPools modAs[Q, poolColumns]
|
||||
CreatorSites modAs[Q, siteColumns]
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
|
|
@ -3091,7 +3571,7 @@ func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[
|
|||
return mods
|
||||
},
|
||||
},
|
||||
CreatorPools: modAs[Q, fileuploadPoolColumns]{
|
||||
FileuploadPool: modAs[Q, fileuploadPoolColumns]{
|
||||
c: FileuploadPools.Columns,
|
||||
f: func(to fileuploadPoolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
|
@ -3189,6 +3669,34 @@ func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[
|
|||
return mods
|
||||
},
|
||||
},
|
||||
CreatorPools: modAs[Q, poolColumns]{
|
||||
c: Pools.Columns,
|
||||
f: func(to poolColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Pools.Name().As(to.Alias())).On(
|
||||
to.CreatorID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
CreatorSites: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
|
||||
to.CreatorID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Organization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue