370 lines
9.9 KiB
Go
370 lines
9.9 KiB
Go
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
|
|
|
package 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/sm"
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
|
"github.com/Gleipnir-Technology/bob/expr"
|
|
"github.com/Gleipnir-Technology/bob/orm"
|
|
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
|
"github.com/aarondl/opt/omit"
|
|
)
|
|
|
|
// TileCachedImage is an object representing the database table.
|
|
type TileCachedImage struct {
|
|
ArcgisID string `db:"arcgis_id" `
|
|
X int32 `db:"x" `
|
|
Y int32 `db:"y" `
|
|
Z int32 `db:"z" `
|
|
|
|
R tileCachedImageR `db:"-" `
|
|
}
|
|
|
|
// TileCachedImageSlice is an alias for a slice of pointers to TileCachedImage.
|
|
// This should almost always be used instead of []*TileCachedImage.
|
|
type TileCachedImageSlice []*TileCachedImage
|
|
|
|
// TileCachedImages contains methods to work with the cached_image view
|
|
var TileCachedImages = psql.NewViewx[*TileCachedImage, TileCachedImageSlice]("tile", "cached_image", buildTileCachedImageColumns("tile.cached_image"))
|
|
|
|
// TileCachedImagesQuery is a query on the cached_image view
|
|
type TileCachedImagesQuery = *psql.ViewQuery[*TileCachedImage, TileCachedImageSlice]
|
|
|
|
// tileCachedImageR is where relationships are stored.
|
|
type tileCachedImageR struct {
|
|
ArcgisServiceMap *ArcgisServiceMap // tile.cached_image.cached_image_arcgis_id_fkey
|
|
}
|
|
|
|
func buildTileCachedImageColumns(alias string) tileCachedImageColumns {
|
|
return tileCachedImageColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"arcgis_id", "x", "y", "z",
|
|
).WithParent("tile.cached_image"),
|
|
tableAlias: alias,
|
|
ArcgisID: psql.Quote(alias, "arcgis_id"),
|
|
X: psql.Quote(alias, "x"),
|
|
Y: psql.Quote(alias, "y"),
|
|
Z: psql.Quote(alias, "z"),
|
|
}
|
|
}
|
|
|
|
type tileCachedImageColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ArcgisID psql.Expression
|
|
X psql.Expression
|
|
Y psql.Expression
|
|
Z psql.Expression
|
|
}
|
|
|
|
func (c tileCachedImageColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (tileCachedImageColumns) AliasedAs(alias string) tileCachedImageColumns {
|
|
return buildTileCachedImageColumns(alias)
|
|
}
|
|
|
|
// TileCachedImageSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type TileCachedImageSetter struct {
|
|
ArcgisID omit.Val[string] `db:"arcgis_id" `
|
|
X omit.Val[int32] `db:"x" `
|
|
Y omit.Val[int32] `db:"y" `
|
|
Z omit.Val[int32] `db:"z" `
|
|
}
|
|
|
|
func (s TileCachedImageSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 4)
|
|
if s.ArcgisID.IsValue() {
|
|
vals = append(vals, "arcgis_id")
|
|
}
|
|
if s.X.IsValue() {
|
|
vals = append(vals, "x")
|
|
}
|
|
if s.Y.IsValue() {
|
|
vals = append(vals, "y")
|
|
}
|
|
if s.Z.IsValue() {
|
|
vals = append(vals, "z")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s TileCachedImageSetter) Overwrite(t *TileCachedImage) {
|
|
if s.ArcgisID.IsValue() {
|
|
t.ArcgisID = s.ArcgisID.MustGet()
|
|
}
|
|
if s.X.IsValue() {
|
|
t.X = s.X.MustGet()
|
|
}
|
|
if s.Y.IsValue() {
|
|
t.Y = s.Y.MustGet()
|
|
}
|
|
if s.Z.IsValue() {
|
|
t.Z = s.Z.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *TileCachedImageSetter) Apply(q *dialect.InsertQuery) {
|
|
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.ArcgisID.IsValue() {
|
|
vals[0] = psql.Arg(s.ArcgisID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.X.IsValue() {
|
|
vals[1] = psql.Arg(s.X.MustGet())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Y.IsValue() {
|
|
vals[2] = psql.Arg(s.Y.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Z.IsValue() {
|
|
vals[3] = psql.Arg(s.Z.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s TileCachedImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s TileCachedImageSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 4)
|
|
|
|
if s.ArcgisID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_id")...),
|
|
psql.Arg(s.ArcgisID),
|
|
}})
|
|
}
|
|
|
|
if s.X.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "x")...),
|
|
psql.Arg(s.X),
|
|
}})
|
|
}
|
|
|
|
if s.Y.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "y")...),
|
|
psql.Arg(s.Y),
|
|
}})
|
|
}
|
|
|
|
if s.Z.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "z")...),
|
|
psql.Arg(s.Z),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// AfterQueryHook is called after TileCachedImage is retrieved from the database
|
|
func (o *TileCachedImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = TileCachedImages.AfterSelectHooks.RunHooks(ctx, exec, TileCachedImageSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// AfterQueryHook is called after TileCachedImageSlice is retrieved from the database
|
|
func (o TileCachedImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = TileCachedImages.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// ArcgisServiceMap starts a query for related objects on arcgis.service_map
|
|
func (o *TileCachedImage) ArcgisServiceMap(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisServiceMapsQuery {
|
|
return ArcgisServiceMaps.Query(append(mods,
|
|
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(o.ArcgisID))),
|
|
)...)
|
|
}
|
|
|
|
func (os TileCachedImageSlice) ArcgisServiceMap(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisServiceMapsQuery {
|
|
pkArcgisID := make(pgtypes.Array[string], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkArcgisID = append(pkArcgisID, o.ArcgisID)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkArcgisID), "text[]")),
|
|
))
|
|
|
|
return ArcgisServiceMaps.Query(append(mods,
|
|
sm.Where(psql.Group(ArcgisServiceMaps.Columns.ArcgisID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
type tileCachedImageWhere[Q psql.Filterable] struct {
|
|
ArcgisID psql.WhereMod[Q, string]
|
|
X psql.WhereMod[Q, int32]
|
|
Y psql.WhereMod[Q, int32]
|
|
Z psql.WhereMod[Q, int32]
|
|
}
|
|
|
|
func (tileCachedImageWhere[Q]) AliasedAs(alias string) tileCachedImageWhere[Q] {
|
|
return buildTileCachedImageWhere[Q](buildTileCachedImageColumns(alias))
|
|
}
|
|
|
|
func buildTileCachedImageWhere[Q psql.Filterable](cols tileCachedImageColumns) tileCachedImageWhere[Q] {
|
|
return tileCachedImageWhere[Q]{
|
|
ArcgisID: psql.Where[Q, string](cols.ArcgisID),
|
|
X: psql.Where[Q, int32](cols.X),
|
|
Y: psql.Where[Q, int32](cols.Y),
|
|
Z: psql.Where[Q, int32](cols.Z),
|
|
}
|
|
}
|
|
|
|
func (o *TileCachedImage) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "ArcgisServiceMap":
|
|
rel, ok := retrieved.(*ArcgisServiceMap)
|
|
if !ok {
|
|
return fmt.Errorf("tileCachedImage cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.ArcgisServiceMap = rel
|
|
|
|
if rel != nil {
|
|
rel.R.ArcgisCachedImages = TileCachedImageSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("tileCachedImage has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type tileCachedImagePreloader struct {
|
|
ArcgisServiceMap func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildTileCachedImagePreloader() tileCachedImagePreloader {
|
|
return tileCachedImagePreloader{
|
|
ArcgisServiceMap: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*ArcgisServiceMap, ArcgisServiceMapSlice](psql.PreloadRel{
|
|
Name: "ArcgisServiceMap",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: TileCachedImages,
|
|
To: ArcgisServiceMaps,
|
|
FromColumns: []string{"arcgis_id"},
|
|
ToColumns: []string{"arcgis_id"},
|
|
},
|
|
},
|
|
}, ArcgisServiceMaps.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type tileCachedImageThenLoader[Q orm.Loadable] struct {
|
|
ArcgisServiceMap func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildTileCachedImageThenLoader[Q orm.Loadable]() tileCachedImageThenLoader[Q] {
|
|
type ArcgisServiceMapLoadInterface interface {
|
|
LoadArcgisServiceMap(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return tileCachedImageThenLoader[Q]{
|
|
ArcgisServiceMap: thenLoadBuilder[Q](
|
|
"ArcgisServiceMap",
|
|
func(ctx context.Context, exec bob.Executor, retrieved ArcgisServiceMapLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadArcgisServiceMap(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadArcgisServiceMap loads the tileCachedImage's ArcgisServiceMap into the .R struct
|
|
func (o *TileCachedImage) LoadArcgisServiceMap(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.ArcgisServiceMap = nil
|
|
|
|
related, err := o.ArcgisServiceMap(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.ArcgisCachedImages = TileCachedImageSlice{o}
|
|
|
|
o.R.ArcgisServiceMap = related
|
|
return nil
|
|
}
|
|
|
|
// LoadArcgisServiceMap loads the tileCachedImage's ArcgisServiceMap into the .R struct
|
|
func (os TileCachedImageSlice) LoadArcgisServiceMap(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
arcgisServiceMaps, err := os.ArcgisServiceMap(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range arcgisServiceMaps {
|
|
|
|
if !(o.ArcgisID == rel.ArcgisID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.ArcgisCachedImages = append(rel.R.ArcgisCachedImages, o)
|
|
|
|
o.R.ArcgisServiceMap = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|