881 lines
25 KiB
Go
881 lines
25 KiB
Go
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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/aarondl/opt/null"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/aarondl/opt/omitnull"
|
|
"github.com/shopspring/decimal"
|
|
"github.com/stephenafamo/bob"
|
|
"github.com/stephenafamo/bob/dialect/psql"
|
|
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
|
"github.com/stephenafamo/bob/dialect/psql/dm"
|
|
"github.com/stephenafamo/bob/dialect/psql/sm"
|
|
"github.com/stephenafamo/bob/dialect/psql/um"
|
|
"github.com/stephenafamo/bob/expr"
|
|
)
|
|
|
|
// District is an object representing the database table.
|
|
type District struct {
|
|
Gid int32 `db:"gid,pk" `
|
|
ID null.Val[decimal.Decimal] `db:"id" `
|
|
Website null.Val[string] `db:"website" `
|
|
Contact null.Val[string] `db:"contact" `
|
|
Address null.Val[string] `db:"address" `
|
|
Regionid null.Val[decimal.Decimal] `db:"regionid" `
|
|
PostalCod null.Val[decimal.Decimal] `db:"postal_cod" `
|
|
Phone1 null.Val[string] `db:"phone1" `
|
|
Fax1 null.Val[string] `db:"fax1" `
|
|
Agency null.Val[string] `db:"agency" `
|
|
Code1 null.Val[string] `db:"code1" `
|
|
City1 null.Val[string] `db:"city1" `
|
|
ShapeLeng null.Val[decimal.Decimal] `db:"shape_leng" `
|
|
Address2 null.Val[string] `db:"address2" `
|
|
GeneralMG null.Val[string] `db:"general_mg" `
|
|
City2 null.Val[string] `db:"city2" `
|
|
PostalC1 null.Val[decimal.Decimal] `db:"postal_c_1" `
|
|
Fax2 null.Val[string] `db:"fax2" `
|
|
Phone2 null.Val[string] `db:"phone2" `
|
|
ShapeLe1 null.Val[decimal.Decimal] `db:"shape_le_1" `
|
|
ShapeArea null.Val[decimal.Decimal] `db:"shape_area" `
|
|
Geom null.Val[string] `db:"geom" `
|
|
Geom4326 null.Val[string] `db:"geom_4326,generated" `
|
|
}
|
|
|
|
// DistrictSlice is an alias for a slice of pointers to District.
|
|
// This should almost always be used instead of []*District.
|
|
type DistrictSlice []*District
|
|
|
|
// Districts contains methods to work with the district table
|
|
var Districts = psql.NewTablex[*District, DistrictSlice, *DistrictSetter]("", "district", buildDistrictColumns("district"))
|
|
|
|
// DistrictsQuery is a query on the district table
|
|
type DistrictsQuery = *psql.ViewQuery[*District, DistrictSlice]
|
|
|
|
func buildDistrictColumns(alias string) districtColumns {
|
|
return districtColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"gid", "id", "website", "contact", "address", "regionid", "postal_cod", "phone1", "fax1", "agency", "code1", "city1", "shape_leng", "address2", "general_mg", "city2", "postal_c_1", "fax2", "phone2", "shape_le_1", "shape_area", "geom", "geom_4326",
|
|
).WithParent("district"),
|
|
tableAlias: alias,
|
|
Gid: psql.Quote(alias, "gid"),
|
|
ID: psql.Quote(alias, "id"),
|
|
Website: psql.Quote(alias, "website"),
|
|
Contact: psql.Quote(alias, "contact"),
|
|
Address: psql.Quote(alias, "address"),
|
|
Regionid: psql.Quote(alias, "regionid"),
|
|
PostalCod: psql.Quote(alias, "postal_cod"),
|
|
Phone1: psql.Quote(alias, "phone1"),
|
|
Fax1: psql.Quote(alias, "fax1"),
|
|
Agency: psql.Quote(alias, "agency"),
|
|
Code1: psql.Quote(alias, "code1"),
|
|
City1: psql.Quote(alias, "city1"),
|
|
ShapeLeng: psql.Quote(alias, "shape_leng"),
|
|
Address2: psql.Quote(alias, "address2"),
|
|
GeneralMG: psql.Quote(alias, "general_mg"),
|
|
City2: psql.Quote(alias, "city2"),
|
|
PostalC1: psql.Quote(alias, "postal_c_1"),
|
|
Fax2: psql.Quote(alias, "fax2"),
|
|
Phone2: psql.Quote(alias, "phone2"),
|
|
ShapeLe1: psql.Quote(alias, "shape_le_1"),
|
|
ShapeArea: psql.Quote(alias, "shape_area"),
|
|
Geom: psql.Quote(alias, "geom"),
|
|
Geom4326: psql.Quote(alias, "geom_4326"),
|
|
}
|
|
}
|
|
|
|
type districtColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
Gid psql.Expression
|
|
ID psql.Expression
|
|
Website psql.Expression
|
|
Contact psql.Expression
|
|
Address psql.Expression
|
|
Regionid psql.Expression
|
|
PostalCod psql.Expression
|
|
Phone1 psql.Expression
|
|
Fax1 psql.Expression
|
|
Agency psql.Expression
|
|
Code1 psql.Expression
|
|
City1 psql.Expression
|
|
ShapeLeng psql.Expression
|
|
Address2 psql.Expression
|
|
GeneralMG psql.Expression
|
|
City2 psql.Expression
|
|
PostalC1 psql.Expression
|
|
Fax2 psql.Expression
|
|
Phone2 psql.Expression
|
|
ShapeLe1 psql.Expression
|
|
ShapeArea psql.Expression
|
|
Geom psql.Expression
|
|
Geom4326 psql.Expression
|
|
}
|
|
|
|
func (c districtColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (districtColumns) AliasedAs(alias string) districtColumns {
|
|
return buildDistrictColumns(alias)
|
|
}
|
|
|
|
// DistrictSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type DistrictSetter struct {
|
|
Gid omit.Val[int32] `db:"gid,pk" `
|
|
ID omitnull.Val[decimal.Decimal] `db:"id" `
|
|
Website omitnull.Val[string] `db:"website" `
|
|
Contact omitnull.Val[string] `db:"contact" `
|
|
Address omitnull.Val[string] `db:"address" `
|
|
Regionid omitnull.Val[decimal.Decimal] `db:"regionid" `
|
|
PostalCod omitnull.Val[decimal.Decimal] `db:"postal_cod" `
|
|
Phone1 omitnull.Val[string] `db:"phone1" `
|
|
Fax1 omitnull.Val[string] `db:"fax1" `
|
|
Agency omitnull.Val[string] `db:"agency" `
|
|
Code1 omitnull.Val[string] `db:"code1" `
|
|
City1 omitnull.Val[string] `db:"city1" `
|
|
ShapeLeng omitnull.Val[decimal.Decimal] `db:"shape_leng" `
|
|
Address2 omitnull.Val[string] `db:"address2" `
|
|
GeneralMG omitnull.Val[string] `db:"general_mg" `
|
|
City2 omitnull.Val[string] `db:"city2" `
|
|
PostalC1 omitnull.Val[decimal.Decimal] `db:"postal_c_1" `
|
|
Fax2 omitnull.Val[string] `db:"fax2" `
|
|
Phone2 omitnull.Val[string] `db:"phone2" `
|
|
ShapeLe1 omitnull.Val[decimal.Decimal] `db:"shape_le_1" `
|
|
ShapeArea omitnull.Val[decimal.Decimal] `db:"shape_area" `
|
|
Geom omitnull.Val[string] `db:"geom" `
|
|
}
|
|
|
|
func (s DistrictSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 22)
|
|
if s.Gid.IsValue() {
|
|
vals = append(vals, "gid")
|
|
}
|
|
if !s.ID.IsUnset() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if !s.Website.IsUnset() {
|
|
vals = append(vals, "website")
|
|
}
|
|
if !s.Contact.IsUnset() {
|
|
vals = append(vals, "contact")
|
|
}
|
|
if !s.Address.IsUnset() {
|
|
vals = append(vals, "address")
|
|
}
|
|
if !s.Regionid.IsUnset() {
|
|
vals = append(vals, "regionid")
|
|
}
|
|
if !s.PostalCod.IsUnset() {
|
|
vals = append(vals, "postal_cod")
|
|
}
|
|
if !s.Phone1.IsUnset() {
|
|
vals = append(vals, "phone1")
|
|
}
|
|
if !s.Fax1.IsUnset() {
|
|
vals = append(vals, "fax1")
|
|
}
|
|
if !s.Agency.IsUnset() {
|
|
vals = append(vals, "agency")
|
|
}
|
|
if !s.Code1.IsUnset() {
|
|
vals = append(vals, "code1")
|
|
}
|
|
if !s.City1.IsUnset() {
|
|
vals = append(vals, "city1")
|
|
}
|
|
if !s.ShapeLeng.IsUnset() {
|
|
vals = append(vals, "shape_leng")
|
|
}
|
|
if !s.Address2.IsUnset() {
|
|
vals = append(vals, "address2")
|
|
}
|
|
if !s.GeneralMG.IsUnset() {
|
|
vals = append(vals, "general_mg")
|
|
}
|
|
if !s.City2.IsUnset() {
|
|
vals = append(vals, "city2")
|
|
}
|
|
if !s.PostalC1.IsUnset() {
|
|
vals = append(vals, "postal_c_1")
|
|
}
|
|
if !s.Fax2.IsUnset() {
|
|
vals = append(vals, "fax2")
|
|
}
|
|
if !s.Phone2.IsUnset() {
|
|
vals = append(vals, "phone2")
|
|
}
|
|
if !s.ShapeLe1.IsUnset() {
|
|
vals = append(vals, "shape_le_1")
|
|
}
|
|
if !s.ShapeArea.IsUnset() {
|
|
vals = append(vals, "shape_area")
|
|
}
|
|
if !s.Geom.IsUnset() {
|
|
vals = append(vals, "geom")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s DistrictSetter) Overwrite(t *District) {
|
|
if s.Gid.IsValue() {
|
|
t.Gid = s.Gid.MustGet()
|
|
}
|
|
if !s.ID.IsUnset() {
|
|
t.ID = s.ID.MustGetNull()
|
|
}
|
|
if !s.Website.IsUnset() {
|
|
t.Website = s.Website.MustGetNull()
|
|
}
|
|
if !s.Contact.IsUnset() {
|
|
t.Contact = s.Contact.MustGetNull()
|
|
}
|
|
if !s.Address.IsUnset() {
|
|
t.Address = s.Address.MustGetNull()
|
|
}
|
|
if !s.Regionid.IsUnset() {
|
|
t.Regionid = s.Regionid.MustGetNull()
|
|
}
|
|
if !s.PostalCod.IsUnset() {
|
|
t.PostalCod = s.PostalCod.MustGetNull()
|
|
}
|
|
if !s.Phone1.IsUnset() {
|
|
t.Phone1 = s.Phone1.MustGetNull()
|
|
}
|
|
if !s.Fax1.IsUnset() {
|
|
t.Fax1 = s.Fax1.MustGetNull()
|
|
}
|
|
if !s.Agency.IsUnset() {
|
|
t.Agency = s.Agency.MustGetNull()
|
|
}
|
|
if !s.Code1.IsUnset() {
|
|
t.Code1 = s.Code1.MustGetNull()
|
|
}
|
|
if !s.City1.IsUnset() {
|
|
t.City1 = s.City1.MustGetNull()
|
|
}
|
|
if !s.ShapeLeng.IsUnset() {
|
|
t.ShapeLeng = s.ShapeLeng.MustGetNull()
|
|
}
|
|
if !s.Address2.IsUnset() {
|
|
t.Address2 = s.Address2.MustGetNull()
|
|
}
|
|
if !s.GeneralMG.IsUnset() {
|
|
t.GeneralMG = s.GeneralMG.MustGetNull()
|
|
}
|
|
if !s.City2.IsUnset() {
|
|
t.City2 = s.City2.MustGetNull()
|
|
}
|
|
if !s.PostalC1.IsUnset() {
|
|
t.PostalC1 = s.PostalC1.MustGetNull()
|
|
}
|
|
if !s.Fax2.IsUnset() {
|
|
t.Fax2 = s.Fax2.MustGetNull()
|
|
}
|
|
if !s.Phone2.IsUnset() {
|
|
t.Phone2 = s.Phone2.MustGetNull()
|
|
}
|
|
if !s.ShapeLe1.IsUnset() {
|
|
t.ShapeLe1 = s.ShapeLe1.MustGetNull()
|
|
}
|
|
if !s.ShapeArea.IsUnset() {
|
|
t.ShapeArea = s.ShapeArea.MustGetNull()
|
|
}
|
|
if !s.Geom.IsUnset() {
|
|
t.Geom = s.Geom.MustGetNull()
|
|
}
|
|
}
|
|
|
|
func (s *DistrictSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return Districts.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, 22)
|
|
if s.Gid.IsValue() {
|
|
vals[0] = psql.Arg(s.Gid.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ID.IsUnset() {
|
|
vals[1] = psql.Arg(s.ID.MustGetNull())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Website.IsUnset() {
|
|
vals[2] = psql.Arg(s.Website.MustGetNull())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Contact.IsUnset() {
|
|
vals[3] = psql.Arg(s.Contact.MustGetNull())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Address.IsUnset() {
|
|
vals[4] = psql.Arg(s.Address.MustGetNull())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Regionid.IsUnset() {
|
|
vals[5] = psql.Arg(s.Regionid.MustGetNull())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.PostalCod.IsUnset() {
|
|
vals[6] = psql.Arg(s.PostalCod.MustGetNull())
|
|
} else {
|
|
vals[6] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Phone1.IsUnset() {
|
|
vals[7] = psql.Arg(s.Phone1.MustGetNull())
|
|
} else {
|
|
vals[7] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Fax1.IsUnset() {
|
|
vals[8] = psql.Arg(s.Fax1.MustGetNull())
|
|
} else {
|
|
vals[8] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Agency.IsUnset() {
|
|
vals[9] = psql.Arg(s.Agency.MustGetNull())
|
|
} else {
|
|
vals[9] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Code1.IsUnset() {
|
|
vals[10] = psql.Arg(s.Code1.MustGetNull())
|
|
} else {
|
|
vals[10] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.City1.IsUnset() {
|
|
vals[11] = psql.Arg(s.City1.MustGetNull())
|
|
} else {
|
|
vals[11] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ShapeLeng.IsUnset() {
|
|
vals[12] = psql.Arg(s.ShapeLeng.MustGetNull())
|
|
} else {
|
|
vals[12] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Address2.IsUnset() {
|
|
vals[13] = psql.Arg(s.Address2.MustGetNull())
|
|
} else {
|
|
vals[13] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.GeneralMG.IsUnset() {
|
|
vals[14] = psql.Arg(s.GeneralMG.MustGetNull())
|
|
} else {
|
|
vals[14] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.City2.IsUnset() {
|
|
vals[15] = psql.Arg(s.City2.MustGetNull())
|
|
} else {
|
|
vals[15] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.PostalC1.IsUnset() {
|
|
vals[16] = psql.Arg(s.PostalC1.MustGetNull())
|
|
} else {
|
|
vals[16] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Fax2.IsUnset() {
|
|
vals[17] = psql.Arg(s.Fax2.MustGetNull())
|
|
} else {
|
|
vals[17] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Phone2.IsUnset() {
|
|
vals[18] = psql.Arg(s.Phone2.MustGetNull())
|
|
} else {
|
|
vals[18] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ShapeLe1.IsUnset() {
|
|
vals[19] = psql.Arg(s.ShapeLe1.MustGetNull())
|
|
} else {
|
|
vals[19] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ShapeArea.IsUnset() {
|
|
vals[20] = psql.Arg(s.ShapeArea.MustGetNull())
|
|
} else {
|
|
vals[20] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Geom.IsUnset() {
|
|
vals[21] = psql.Arg(s.Geom.MustGetNull())
|
|
} else {
|
|
vals[21] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s DistrictSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s DistrictSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 22)
|
|
|
|
if s.Gid.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "gid")...),
|
|
psql.Arg(s.Gid),
|
|
}})
|
|
}
|
|
|
|
if !s.ID.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if !s.Website.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "website")...),
|
|
psql.Arg(s.Website),
|
|
}})
|
|
}
|
|
|
|
if !s.Contact.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "contact")...),
|
|
psql.Arg(s.Contact),
|
|
}})
|
|
}
|
|
|
|
if !s.Address.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "address")...),
|
|
psql.Arg(s.Address),
|
|
}})
|
|
}
|
|
|
|
if !s.Regionid.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "regionid")...),
|
|
psql.Arg(s.Regionid),
|
|
}})
|
|
}
|
|
|
|
if !s.PostalCod.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "postal_cod")...),
|
|
psql.Arg(s.PostalCod),
|
|
}})
|
|
}
|
|
|
|
if !s.Phone1.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "phone1")...),
|
|
psql.Arg(s.Phone1),
|
|
}})
|
|
}
|
|
|
|
if !s.Fax1.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "fax1")...),
|
|
psql.Arg(s.Fax1),
|
|
}})
|
|
}
|
|
|
|
if !s.Agency.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "agency")...),
|
|
psql.Arg(s.Agency),
|
|
}})
|
|
}
|
|
|
|
if !s.Code1.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "code1")...),
|
|
psql.Arg(s.Code1),
|
|
}})
|
|
}
|
|
|
|
if !s.City1.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "city1")...),
|
|
psql.Arg(s.City1),
|
|
}})
|
|
}
|
|
|
|
if !s.ShapeLeng.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "shape_leng")...),
|
|
psql.Arg(s.ShapeLeng),
|
|
}})
|
|
}
|
|
|
|
if !s.Address2.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "address2")...),
|
|
psql.Arg(s.Address2),
|
|
}})
|
|
}
|
|
|
|
if !s.GeneralMG.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "general_mg")...),
|
|
psql.Arg(s.GeneralMG),
|
|
}})
|
|
}
|
|
|
|
if !s.City2.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "city2")...),
|
|
psql.Arg(s.City2),
|
|
}})
|
|
}
|
|
|
|
if !s.PostalC1.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "postal_c_1")...),
|
|
psql.Arg(s.PostalC1),
|
|
}})
|
|
}
|
|
|
|
if !s.Fax2.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "fax2")...),
|
|
psql.Arg(s.Fax2),
|
|
}})
|
|
}
|
|
|
|
if !s.Phone2.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "phone2")...),
|
|
psql.Arg(s.Phone2),
|
|
}})
|
|
}
|
|
|
|
if !s.ShapeLe1.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "shape_le_1")...),
|
|
psql.Arg(s.ShapeLe1),
|
|
}})
|
|
}
|
|
|
|
if !s.ShapeArea.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "shape_area")...),
|
|
psql.Arg(s.ShapeArea),
|
|
}})
|
|
}
|
|
|
|
if !s.Geom.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "geom")...),
|
|
psql.Arg(s.Geom),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindDistrict retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindDistrict(ctx context.Context, exec bob.Executor, GidPK int32, cols ...string) (*District, error) {
|
|
if len(cols) == 0 {
|
|
return Districts.Query(
|
|
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(GidPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return Districts.Query(
|
|
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(GidPK))),
|
|
sm.Columns(Districts.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// DistrictExists checks the presence of a single record by primary key
|
|
func DistrictExists(ctx context.Context, exec bob.Executor, GidPK int32) (bool, error) {
|
|
return Districts.Query(
|
|
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(GidPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after District is retrieved from the database
|
|
func (o *District) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = Districts.AfterSelectHooks.RunHooks(ctx, exec, DistrictSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = Districts.AfterInsertHooks.RunHooks(ctx, exec, DistrictSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = Districts.AfterUpdateHooks.RunHooks(ctx, exec, DistrictSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = Districts.AfterDeleteHooks.RunHooks(ctx, exec, DistrictSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the District
|
|
func (o *District) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.Gid)
|
|
}
|
|
|
|
func (o *District) pkEQ() dialect.Expression {
|
|
return psql.Quote("district", "gid").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 District
|
|
func (o *District) Update(ctx context.Context, exec bob.Executor, s *DistrictSetter) error {
|
|
v, err := Districts.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*o = *v
|
|
|
|
return nil
|
|
}
|
|
|
|
// Delete deletes a single District record with an executor
|
|
func (o *District) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := Districts.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the District using the executor
|
|
func (o *District) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := Districts.Query(
|
|
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(o.Gid))),
|
|
).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*o = *o2
|
|
|
|
return nil
|
|
}
|
|
|
|
// AfterQueryHook is called after DistrictSlice is retrieved from the database
|
|
func (o DistrictSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = Districts.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = Districts.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = Districts.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = Districts.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o DistrictSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("district", "gid").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 DistrictSlice) copyMatchingRows(from ...*District) {
|
|
for i, old := range o {
|
|
for _, new := range from {
|
|
if new.Gid != old.Gid {
|
|
continue
|
|
}
|
|
|
|
o[i] = new
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
|
func (o DistrictSlice) 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 Districts.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 *District:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*District:
|
|
o.copyMatchingRows(retrieved...)
|
|
case DistrictSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a District or a slice of District
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = Districts.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o DistrictSlice) 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 Districts.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 *District:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*District:
|
|
o.copyMatchingRows(retrieved...)
|
|
case DistrictSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a District or a slice of District
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = Districts.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o DistrictSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DistrictSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := Districts.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o DistrictSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := Districts.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o DistrictSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := Districts.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
type districtWhere[Q psql.Filterable] struct {
|
|
Gid psql.WhereMod[Q, int32]
|
|
ID psql.WhereNullMod[Q, decimal.Decimal]
|
|
Website psql.WhereNullMod[Q, string]
|
|
Contact psql.WhereNullMod[Q, string]
|
|
Address psql.WhereNullMod[Q, string]
|
|
Regionid psql.WhereNullMod[Q, decimal.Decimal]
|
|
PostalCod psql.WhereNullMod[Q, decimal.Decimal]
|
|
Phone1 psql.WhereNullMod[Q, string]
|
|
Fax1 psql.WhereNullMod[Q, string]
|
|
Agency psql.WhereNullMod[Q, string]
|
|
Code1 psql.WhereNullMod[Q, string]
|
|
City1 psql.WhereNullMod[Q, string]
|
|
ShapeLeng psql.WhereNullMod[Q, decimal.Decimal]
|
|
Address2 psql.WhereNullMod[Q, string]
|
|
GeneralMG psql.WhereNullMod[Q, string]
|
|
City2 psql.WhereNullMod[Q, string]
|
|
PostalC1 psql.WhereNullMod[Q, decimal.Decimal]
|
|
Fax2 psql.WhereNullMod[Q, string]
|
|
Phone2 psql.WhereNullMod[Q, string]
|
|
ShapeLe1 psql.WhereNullMod[Q, decimal.Decimal]
|
|
ShapeArea psql.WhereNullMod[Q, decimal.Decimal]
|
|
Geom psql.WhereNullMod[Q, string]
|
|
Geom4326 psql.WhereNullMod[Q, string]
|
|
}
|
|
|
|
func (districtWhere[Q]) AliasedAs(alias string) districtWhere[Q] {
|
|
return buildDistrictWhere[Q](buildDistrictColumns(alias))
|
|
}
|
|
|
|
func buildDistrictWhere[Q psql.Filterable](cols districtColumns) districtWhere[Q] {
|
|
return districtWhere[Q]{
|
|
Gid: psql.Where[Q, int32](cols.Gid),
|
|
ID: psql.WhereNull[Q, decimal.Decimal](cols.ID),
|
|
Website: psql.WhereNull[Q, string](cols.Website),
|
|
Contact: psql.WhereNull[Q, string](cols.Contact),
|
|
Address: psql.WhereNull[Q, string](cols.Address),
|
|
Regionid: psql.WhereNull[Q, decimal.Decimal](cols.Regionid),
|
|
PostalCod: psql.WhereNull[Q, decimal.Decimal](cols.PostalCod),
|
|
Phone1: psql.WhereNull[Q, string](cols.Phone1),
|
|
Fax1: psql.WhereNull[Q, string](cols.Fax1),
|
|
Agency: psql.WhereNull[Q, string](cols.Agency),
|
|
Code1: psql.WhereNull[Q, string](cols.Code1),
|
|
City1: psql.WhereNull[Q, string](cols.City1),
|
|
ShapeLeng: psql.WhereNull[Q, decimal.Decimal](cols.ShapeLeng),
|
|
Address2: psql.WhereNull[Q, string](cols.Address2),
|
|
GeneralMG: psql.WhereNull[Q, string](cols.GeneralMG),
|
|
City2: psql.WhereNull[Q, string](cols.City2),
|
|
PostalC1: psql.WhereNull[Q, decimal.Decimal](cols.PostalC1),
|
|
Fax2: psql.WhereNull[Q, string](cols.Fax2),
|
|
Phone2: psql.WhereNull[Q, string](cols.Phone2),
|
|
ShapeLe1: psql.WhereNull[Q, decimal.Decimal](cols.ShapeLe1),
|
|
ShapeArea: psql.WhereNull[Q, decimal.Decimal](cols.ShapeArea),
|
|
Geom: psql.WhereNull[Q, string](cols.Geom),
|
|
Geom4326: psql.WhereNull[Q, string](cols.Geom4326),
|
|
}
|
|
}
|