Remove old FieldSeeker tables, use v2 generated tables.
This requires a bunch of changes since the types on these tables are much closer to the underlying types of the Fieldseeker data we are getting back from the API. I now need to use proper UUID types everywhere, which means I had to modify the bob gen config to consistently use google UUID, my UUID library of choice. I also had to add the organization_id to all the fieldseeker tables since we rely on them existing for some of our compound queries. There were some changes to the API type signatures to get things to build. I may yet regret those.
This commit is contained in:
parent
58f5afccc9
commit
1395e3d3ac
445 changed files with 54077 additions and 275856 deletions
|
|
@ -1,17 +1,19 @@
|
|||
// Code generated by BobGen psql v0.0.3-0.20251202003046-49148fc66a73+dirty. DO NOT EDIT.
|
||||
// Code generated by BobGen psql v0.0.4-0.20251216163753-8e325b7c773a+dirty. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/gofrs/uuid/v5"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
|
|
@ -19,31 +21,55 @@ import (
|
|||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// FieldseekerTreatmentarea is an object representing the database table.
|
||||
type FieldseekerTreatmentarea struct {
|
||||
Objectid int64 `db:"objectid,pk" `
|
||||
TreatID null.Val[uuid.UUID] `db:"treat_id" `
|
||||
Objectid int64 `db:"objectid,pk" `
|
||||
// Original attribute from ArcGIS API is TREAT_ID
|
||||
TreatID null.Val[uuid.UUID] `db:"treat_id" `
|
||||
// Original attribute from ArcGIS API is SESSION_ID
|
||||
SessionID null.Val[uuid.UUID] `db:"session_id" `
|
||||
// Treatment Date
|
||||
Treatdate null.Val[time.Time] `db:"treatdate" `
|
||||
Comments null.Val[string] `db:"comments" `
|
||||
Globalid null.Val[uuid.UUID] `db:"globalid" `
|
||||
CreatedUser null.Val[string] `db:"created_user" `
|
||||
CreatedDate null.Val[time.Time] `db:"created_date" `
|
||||
LastEditedUser null.Val[string] `db:"last_edited_user" `
|
||||
// Original attribute from ArcGIS API is TREATDATE
|
||||
Treatdate null.Val[time.Time] `db:"treatdate" `
|
||||
// Original attribute from ArcGIS API is COMMENTS
|
||||
Comments null.Val[string] `db:"comments" `
|
||||
// Original attribute from ArcGIS API is GlobalID
|
||||
Globalid null.Val[uuid.UUID] `db:"globalid" `
|
||||
// Original attribute from ArcGIS API is created_user
|
||||
CreatedUser null.Val[string] `db:"created_user" `
|
||||
// Original attribute from ArcGIS API is created_date
|
||||
CreatedDate null.Val[time.Time] `db:"created_date" `
|
||||
// Original attribute from ArcGIS API is last_edited_user
|
||||
LastEditedUser null.Val[string] `db:"last_edited_user" `
|
||||
// Original attribute from ArcGIS API is last_edited_date
|
||||
LastEditedDate null.Val[time.Time] `db:"last_edited_date" `
|
||||
Notified null.Val[int16] `db:"notified" `
|
||||
Type null.Val[string] `db:"type" `
|
||||
Creationdate null.Val[time.Time] `db:"creationdate" `
|
||||
Creator null.Val[string] `db:"creator" `
|
||||
Editdate null.Val[time.Time] `db:"editdate" `
|
||||
Editor null.Val[string] `db:"editor" `
|
||||
ShapeArea null.Val[float64] `db:"shape__area" `
|
||||
ShapeLength null.Val[float64] `db:"shape__length" `
|
||||
// Tracks version changes to the row. Increases when data is modified.
|
||||
Version int32 `db:"version,pk" `
|
||||
// Original attribute from ArcGIS API is Notified
|
||||
Notified null.Val[int16] `db:"notified" `
|
||||
// Original attribute from ArcGIS API is Type
|
||||
Type null.Val[string] `db:"type" `
|
||||
// Original attribute from ArcGIS API is CreationDate
|
||||
Creationdate null.Val[time.Time] `db:"creationdate" `
|
||||
// Original attribute from ArcGIS API is Creator
|
||||
Creator null.Val[string] `db:"creator" `
|
||||
// Original attribute from ArcGIS API is EditDate
|
||||
Editdate null.Val[time.Time] `db:"editdate" `
|
||||
// Original attribute from ArcGIS API is Editor
|
||||
Editor null.Val[string] `db:"editor" `
|
||||
// Original attribute from ArcGIS API is Shape__Area
|
||||
ShapeArea null.Val[float64] `db:"shape__area" `
|
||||
// Original attribute from ArcGIS API is Shape__Length
|
||||
ShapeLength null.Val[float64] `db:"shape__length" `
|
||||
Geometry types.JSON[json.RawMessage] `db:"geometry" `
|
||||
Geospatial null.Val[string] `db:"geospatial" `
|
||||
Version int32 `db:"version,pk" `
|
||||
OrganizationID int32 `db:"organization_id" `
|
||||
|
||||
R fieldseekerTreatmentareaR `db:"-" `
|
||||
}
|
||||
|
||||
// FieldseekerTreatmentareaSlice is an alias for a slice of pointers to FieldseekerTreatmentarea.
|
||||
|
|
@ -56,10 +82,15 @@ var FieldseekerTreatmentareas = psql.NewTablex[*FieldseekerTreatmentarea, Fields
|
|||
// FieldseekerTreatmentareasQuery is a query on the treatmentarea table
|
||||
type FieldseekerTreatmentareasQuery = *psql.ViewQuery[*FieldseekerTreatmentarea, FieldseekerTreatmentareaSlice]
|
||||
|
||||
// fieldseekerTreatmentareaR is where relationships are stored.
|
||||
type fieldseekerTreatmentareaR struct {
|
||||
Organization *Organization // fieldseeker.treatmentarea.treatmentarea_organization_id_fkey
|
||||
}
|
||||
|
||||
func buildFieldseekerTreatmentareaColumns(alias string) fieldseekerTreatmentareaColumns {
|
||||
return fieldseekerTreatmentareaColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"objectid", "treat_id", "session_id", "treatdate", "comments", "globalid", "created_user", "created_date", "last_edited_user", "last_edited_date", "notified", "type", "creationdate", "creator", "editdate", "editor", "shape__area", "shape__length", "version",
|
||||
"objectid", "treat_id", "session_id", "treatdate", "comments", "globalid", "created_user", "created_date", "last_edited_user", "last_edited_date", "notified", "type", "creationdate", "creator", "editdate", "editor", "shape__area", "shape__length", "geometry", "geospatial", "version", "organization_id",
|
||||
).WithParent("fieldseeker.treatmentarea"),
|
||||
tableAlias: alias,
|
||||
Objectid: psql.Quote(alias, "objectid"),
|
||||
|
|
@ -80,7 +111,10 @@ func buildFieldseekerTreatmentareaColumns(alias string) fieldseekerTreatmentarea
|
|||
Editor: psql.Quote(alias, "editor"),
|
||||
ShapeArea: psql.Quote(alias, "shape__area"),
|
||||
ShapeLength: psql.Quote(alias, "shape__length"),
|
||||
Geometry: psql.Quote(alias, "geometry"),
|
||||
Geospatial: psql.Quote(alias, "geospatial"),
|
||||
Version: psql.Quote(alias, "version"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +139,10 @@ type fieldseekerTreatmentareaColumns struct {
|
|||
Editor psql.Expression
|
||||
ShapeArea psql.Expression
|
||||
ShapeLength psql.Expression
|
||||
Geometry psql.Expression
|
||||
Geospatial psql.Expression
|
||||
Version psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
}
|
||||
|
||||
func (c fieldseekerTreatmentareaColumns) Alias() string {
|
||||
|
|
@ -120,29 +157,32 @@ func (fieldseekerTreatmentareaColumns) AliasedAs(alias string) fieldseekerTreatm
|
|||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type FieldseekerTreatmentareaSetter struct {
|
||||
Objectid omit.Val[int64] `db:"objectid,pk" `
|
||||
TreatID omitnull.Val[uuid.UUID] `db:"treat_id" `
|
||||
SessionID omitnull.Val[uuid.UUID] `db:"session_id" `
|
||||
Treatdate omitnull.Val[time.Time] `db:"treatdate" `
|
||||
Comments omitnull.Val[string] `db:"comments" `
|
||||
Globalid omitnull.Val[uuid.UUID] `db:"globalid" `
|
||||
CreatedUser omitnull.Val[string] `db:"created_user" `
|
||||
CreatedDate omitnull.Val[time.Time] `db:"created_date" `
|
||||
LastEditedUser omitnull.Val[string] `db:"last_edited_user" `
|
||||
LastEditedDate omitnull.Val[time.Time] `db:"last_edited_date" `
|
||||
Notified omitnull.Val[int16] `db:"notified" `
|
||||
Type omitnull.Val[string] `db:"type" `
|
||||
Creationdate omitnull.Val[time.Time] `db:"creationdate" `
|
||||
Creator omitnull.Val[string] `db:"creator" `
|
||||
Editdate omitnull.Val[time.Time] `db:"editdate" `
|
||||
Editor omitnull.Val[string] `db:"editor" `
|
||||
ShapeArea omitnull.Val[float64] `db:"shape__area" `
|
||||
ShapeLength omitnull.Val[float64] `db:"shape__length" `
|
||||
Version omit.Val[int32] `db:"version,pk" `
|
||||
Objectid omit.Val[int64] `db:"objectid,pk" `
|
||||
TreatID omitnull.Val[uuid.UUID] `db:"treat_id" `
|
||||
SessionID omitnull.Val[uuid.UUID] `db:"session_id" `
|
||||
Treatdate omitnull.Val[time.Time] `db:"treatdate" `
|
||||
Comments omitnull.Val[string] `db:"comments" `
|
||||
Globalid omitnull.Val[uuid.UUID] `db:"globalid" `
|
||||
CreatedUser omitnull.Val[string] `db:"created_user" `
|
||||
CreatedDate omitnull.Val[time.Time] `db:"created_date" `
|
||||
LastEditedUser omitnull.Val[string] `db:"last_edited_user" `
|
||||
LastEditedDate omitnull.Val[time.Time] `db:"last_edited_date" `
|
||||
Notified omitnull.Val[int16] `db:"notified" `
|
||||
Type omitnull.Val[string] `db:"type" `
|
||||
Creationdate omitnull.Val[time.Time] `db:"creationdate" `
|
||||
Creator omitnull.Val[string] `db:"creator" `
|
||||
Editdate omitnull.Val[time.Time] `db:"editdate" `
|
||||
Editor omitnull.Val[string] `db:"editor" `
|
||||
ShapeArea omitnull.Val[float64] `db:"shape__area" `
|
||||
ShapeLength omitnull.Val[float64] `db:"shape__length" `
|
||||
Geometry omit.Val[types.JSON[json.RawMessage]] `db:"geometry" `
|
||||
Geospatial omitnull.Val[string] `db:"geospatial" `
|
||||
Version omit.Val[int32] `db:"version,pk" `
|
||||
OrganizationID omit.Val[int32] `db:"organization_id" `
|
||||
}
|
||||
|
||||
func (s FieldseekerTreatmentareaSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 19)
|
||||
vals := make([]string, 0, 22)
|
||||
if s.Objectid.IsValue() {
|
||||
vals = append(vals, "objectid")
|
||||
}
|
||||
|
|
@ -197,9 +237,18 @@ func (s FieldseekerTreatmentareaSetter) SetColumns() []string {
|
|||
if !s.ShapeLength.IsUnset() {
|
||||
vals = append(vals, "shape__length")
|
||||
}
|
||||
if s.Geometry.IsValue() {
|
||||
vals = append(vals, "geometry")
|
||||
}
|
||||
if !s.Geospatial.IsUnset() {
|
||||
vals = append(vals, "geospatial")
|
||||
}
|
||||
if s.Version.IsValue() {
|
||||
vals = append(vals, "version")
|
||||
}
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -258,9 +307,18 @@ func (s FieldseekerTreatmentareaSetter) Overwrite(t *FieldseekerTreatmentarea) {
|
|||
if !s.ShapeLength.IsUnset() {
|
||||
t.ShapeLength = s.ShapeLength.MustGetNull()
|
||||
}
|
||||
if s.Geometry.IsValue() {
|
||||
t.Geometry = s.Geometry.MustGet()
|
||||
}
|
||||
if !s.Geospatial.IsUnset() {
|
||||
t.Geospatial = s.Geospatial.MustGetNull()
|
||||
}
|
||||
if s.Version.IsValue() {
|
||||
t.Version = s.Version.MustGet()
|
||||
}
|
||||
if s.OrganizationID.IsValue() {
|
||||
t.OrganizationID = s.OrganizationID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FieldseekerTreatmentareaSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -269,7 +327,7 @@ func (s *FieldseekerTreatmentareaSetter) 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, 19)
|
||||
vals := make([]bob.Expression, 22)
|
||||
if s.Objectid.IsValue() {
|
||||
vals[0] = psql.Arg(s.Objectid.MustGet())
|
||||
} else {
|
||||
|
|
@ -378,12 +436,30 @@ func (s *FieldseekerTreatmentareaSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[17] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Version.IsValue() {
|
||||
vals[18] = psql.Arg(s.Version.MustGet())
|
||||
if s.Geometry.IsValue() {
|
||||
vals[18] = psql.Arg(s.Geometry.MustGet())
|
||||
} else {
|
||||
vals[18] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Geospatial.IsUnset() {
|
||||
vals[19] = psql.Arg(s.Geospatial.MustGetNull())
|
||||
} else {
|
||||
vals[19] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Version.IsValue() {
|
||||
vals[20] = psql.Arg(s.Version.MustGet())
|
||||
} else {
|
||||
vals[20] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[21] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
vals[21] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -393,7 +469,7 @@ func (s FieldseekerTreatmentareaSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery
|
|||
}
|
||||
|
||||
func (s FieldseekerTreatmentareaSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 19)
|
||||
exprs := make([]bob.Expression, 0, 22)
|
||||
|
||||
if s.Objectid.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -521,6 +597,20 @@ func (s FieldseekerTreatmentareaSetter) Expressions(prefix ...string) []bob.Expr
|
|||
}})
|
||||
}
|
||||
|
||||
if s.Geometry.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "geometry")...),
|
||||
psql.Arg(s.Geometry),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.Geospatial.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "geospatial")...),
|
||||
psql.Arg(s.Geospatial),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Version.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "version")...),
|
||||
|
|
@ -528,6 +618,13 @@ func (s FieldseekerTreatmentareaSetter) Expressions(prefix ...string) []bob.Expr
|
|||
}})
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -595,6 +692,7 @@ func (o *FieldseekerTreatmentarea) Update(ctx context.Context, exec bob.Executor
|
|||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
|
|
@ -615,7 +713,7 @@ func (o *FieldseekerTreatmentarea) Reload(ctx context.Context, exec bob.Executor
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
|
|
@ -665,7 +763,7 @@ func (o FieldseekerTreatmentareaSlice) copyMatchingRows(from ...*FieldseekerTrea
|
|||
if new.Version != old.Version {
|
||||
continue
|
||||
}
|
||||
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
|
|
@ -763,6 +861,78 @@ func (o FieldseekerTreatmentareaSlice) ReloadAll(ctx context.Context, exec bob.E
|
|||
return nil
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *FieldseekerTreatmentarea) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FieldseekerTreatmentareaSlice) 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 attachFieldseekerTreatmentareaOrganization0(ctx context.Context, exec bob.Executor, count int, fieldseekerTreatmentarea0 *FieldseekerTreatmentarea, organization1 *Organization) (*FieldseekerTreatmentarea, error) {
|
||||
setter := &FieldseekerTreatmentareaSetter{
|
||||
OrganizationID: omit.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := fieldseekerTreatmentarea0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachFieldseekerTreatmentareaOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return fieldseekerTreatmentarea0, nil
|
||||
}
|
||||
|
||||
func (fieldseekerTreatmentarea0 *FieldseekerTreatmentarea) 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 = attachFieldseekerTreatmentareaOrganization0(ctx, exec, 1, fieldseekerTreatmentarea0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldseekerTreatmentarea0.R.Organization = organization1
|
||||
|
||||
organization1.R.Treatmentareas = append(organization1.R.Treatmentareas, fieldseekerTreatmentarea0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fieldseekerTreatmentarea0 *FieldseekerTreatmentarea) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachFieldseekerTreatmentareaOrganization0(ctx, exec, 1, fieldseekerTreatmentarea0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fieldseekerTreatmentarea0.R.Organization = organization1
|
||||
|
||||
organization1.R.Treatmentareas = append(organization1.R.Treatmentareas, fieldseekerTreatmentarea0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fieldseekerTreatmentareaWhere[Q psql.Filterable] struct {
|
||||
Objectid psql.WhereMod[Q, int64]
|
||||
TreatID psql.WhereNullMod[Q, uuid.UUID]
|
||||
|
|
@ -782,7 +952,10 @@ type fieldseekerTreatmentareaWhere[Q psql.Filterable] struct {
|
|||
Editor psql.WhereNullMod[Q, string]
|
||||
ShapeArea psql.WhereNullMod[Q, float64]
|
||||
ShapeLength psql.WhereNullMod[Q, float64]
|
||||
Geometry psql.WhereMod[Q, types.JSON[json.RawMessage]]
|
||||
Geospatial psql.WhereNullMod[Q, string]
|
||||
Version psql.WhereMod[Q, int32]
|
||||
OrganizationID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (fieldseekerTreatmentareaWhere[Q]) AliasedAs(alias string) fieldseekerTreatmentareaWhere[Q] {
|
||||
|
|
@ -809,6 +982,154 @@ func buildFieldseekerTreatmentareaWhere[Q psql.Filterable](cols fieldseekerTreat
|
|||
Editor: psql.WhereNull[Q, string](cols.Editor),
|
||||
ShapeArea: psql.WhereNull[Q, float64](cols.ShapeArea),
|
||||
ShapeLength: psql.WhereNull[Q, float64](cols.ShapeLength),
|
||||
Geometry: psql.Where[Q, types.JSON[json.RawMessage]](cols.Geometry),
|
||||
Geospatial: psql.WhereNull[Q, string](cols.Geospatial),
|
||||
Version: psql.Where[Q, int32](cols.Version),
|
||||
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FieldseekerTreatmentarea) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("fieldseekerTreatmentarea cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Treatmentareas = FieldseekerTreatmentareaSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("fieldseekerTreatmentarea has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type fieldseekerTreatmentareaPreloader struct {
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildFieldseekerTreatmentareaPreloader() fieldseekerTreatmentareaPreloader {
|
||||
return fieldseekerTreatmentareaPreloader{
|
||||
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "Organization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: FieldseekerTreatmentareas,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"organization_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type fieldseekerTreatmentareaThenLoader[Q orm.Loadable] struct {
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildFieldseekerTreatmentareaThenLoader[Q orm.Loadable]() fieldseekerTreatmentareaThenLoader[Q] {
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return fieldseekerTreatmentareaThenLoader[Q]{
|
||||
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...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadOrganization loads the fieldseekerTreatmentarea's Organization into the .R struct
|
||||
func (o *FieldseekerTreatmentarea) 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.Treatmentareas = FieldseekerTreatmentareaSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the fieldseekerTreatmentarea's Organization into the .R struct
|
||||
func (os FieldseekerTreatmentareaSlice) 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.Treatmentareas = append(rel.R.Treatmentareas, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type fieldseekerTreatmentareaJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
func (j fieldseekerTreatmentareaJoins[Q]) aliasedAs(alias string) fieldseekerTreatmentareaJoins[Q] {
|
||||
return buildFieldseekerTreatmentareaJoins[Q](buildFieldseekerTreatmentareaColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildFieldseekerTreatmentareaJoins[Q dialect.Joinable](cols fieldseekerTreatmentareaColumns, typ string) fieldseekerTreatmentareaJoins[Q] {
|
||||
return fieldseekerTreatmentareaJoins[Q]{
|
||||
typ: typ,
|
||||
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
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue