This adds the ability to link a proper address in the database to the report and harmonizes the field names with the address table. It also migrates away from mapbox entirely. And I fixed the "pool" naming for the publicreports, which are supposed to be the more generic 'water'.
796 lines
26 KiB
Go
796 lines
26 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"
|
|
"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/orm"
|
|
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
|
"github.com/aarondl/opt/null"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/aarondl/opt/omitnull"
|
|
)
|
|
|
|
// PublicreportNotifyPhoneWater is an object representing the database table.
|
|
type PublicreportNotifyPhoneWater struct {
|
|
Created time.Time `db:"created" `
|
|
Deleted null.Val[time.Time] `db:"deleted" `
|
|
PhoneE164 string `db:"phone_e164,pk" `
|
|
WaterID int32 `db:"water_id,pk" `
|
|
|
|
R publicreportNotifyPhoneWaterR `db:"-" `
|
|
}
|
|
|
|
// PublicreportNotifyPhoneWaterSlice is an alias for a slice of pointers to PublicreportNotifyPhoneWater.
|
|
// This should almost always be used instead of []*PublicreportNotifyPhoneWater.
|
|
type PublicreportNotifyPhoneWaterSlice []*PublicreportNotifyPhoneWater
|
|
|
|
// PublicreportNotifyPhoneWaters contains methods to work with the notify_phone_water table
|
|
var PublicreportNotifyPhoneWaters = psql.NewTablex[*PublicreportNotifyPhoneWater, PublicreportNotifyPhoneWaterSlice, *PublicreportNotifyPhoneWaterSetter]("publicreport", "notify_phone_water", buildPublicreportNotifyPhoneWaterColumns("publicreport.notify_phone_water"))
|
|
|
|
// PublicreportNotifyPhoneWatersQuery is a query on the notify_phone_water table
|
|
type PublicreportNotifyPhoneWatersQuery = *psql.ViewQuery[*PublicreportNotifyPhoneWater, PublicreportNotifyPhoneWaterSlice]
|
|
|
|
// publicreportNotifyPhoneWaterR is where relationships are stored.
|
|
type publicreportNotifyPhoneWaterR struct {
|
|
PhoneE164Phone *CommsPhone // publicreport.notify_phone_water.notify_phone_pool_phone_e164_fkey
|
|
Water *PublicreportWater // publicreport.notify_phone_water.notify_phone_pool_pool_id_fkey
|
|
}
|
|
|
|
func buildPublicreportNotifyPhoneWaterColumns(alias string) publicreportNotifyPhoneWaterColumns {
|
|
return publicreportNotifyPhoneWaterColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"created", "deleted", "phone_e164", "water_id",
|
|
).WithParent("publicreport.notify_phone_water"),
|
|
tableAlias: alias,
|
|
Created: psql.Quote(alias, "created"),
|
|
Deleted: psql.Quote(alias, "deleted"),
|
|
PhoneE164: psql.Quote(alias, "phone_e164"),
|
|
WaterID: psql.Quote(alias, "water_id"),
|
|
}
|
|
}
|
|
|
|
type publicreportNotifyPhoneWaterColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
Created psql.Expression
|
|
Deleted psql.Expression
|
|
PhoneE164 psql.Expression
|
|
WaterID psql.Expression
|
|
}
|
|
|
|
func (c publicreportNotifyPhoneWaterColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (publicreportNotifyPhoneWaterColumns) AliasedAs(alias string) publicreportNotifyPhoneWaterColumns {
|
|
return buildPublicreportNotifyPhoneWaterColumns(alias)
|
|
}
|
|
|
|
// PublicreportNotifyPhoneWaterSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type PublicreportNotifyPhoneWaterSetter struct {
|
|
Created omit.Val[time.Time] `db:"created" `
|
|
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
|
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
|
|
WaterID omit.Val[int32] `db:"water_id,pk" `
|
|
}
|
|
|
|
func (s PublicreportNotifyPhoneWaterSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 4)
|
|
if s.Created.IsValue() {
|
|
vals = append(vals, "created")
|
|
}
|
|
if !s.Deleted.IsUnset() {
|
|
vals = append(vals, "deleted")
|
|
}
|
|
if s.PhoneE164.IsValue() {
|
|
vals = append(vals, "phone_e164")
|
|
}
|
|
if s.WaterID.IsValue() {
|
|
vals = append(vals, "water_id")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s PublicreportNotifyPhoneWaterSetter) Overwrite(t *PublicreportNotifyPhoneWater) {
|
|
if s.Created.IsValue() {
|
|
t.Created = s.Created.MustGet()
|
|
}
|
|
if !s.Deleted.IsUnset() {
|
|
t.Deleted = s.Deleted.MustGetNull()
|
|
}
|
|
if s.PhoneE164.IsValue() {
|
|
t.PhoneE164 = s.PhoneE164.MustGet()
|
|
}
|
|
if s.WaterID.IsValue() {
|
|
t.WaterID = s.WaterID.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *PublicreportNotifyPhoneWaterSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return PublicreportNotifyPhoneWaters.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.Created.IsValue() {
|
|
vals[0] = psql.Arg(s.Created.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Deleted.IsUnset() {
|
|
vals[1] = psql.Arg(s.Deleted.MustGetNull())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.PhoneE164.IsValue() {
|
|
vals[2] = psql.Arg(s.PhoneE164.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.WaterID.IsValue() {
|
|
vals[3] = psql.Arg(s.WaterID.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s PublicreportNotifyPhoneWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s PublicreportNotifyPhoneWaterSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 4)
|
|
|
|
if s.Created.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "created")...),
|
|
psql.Arg(s.Created),
|
|
}})
|
|
}
|
|
|
|
if !s.Deleted.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "deleted")...),
|
|
psql.Arg(s.Deleted),
|
|
}})
|
|
}
|
|
|
|
if s.PhoneE164.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "phone_e164")...),
|
|
psql.Arg(s.PhoneE164),
|
|
}})
|
|
}
|
|
|
|
if s.WaterID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "water_id")...),
|
|
psql.Arg(s.WaterID),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindPublicreportNotifyPhoneWater retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindPublicreportNotifyPhoneWater(ctx context.Context, exec bob.Executor, WaterIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhoneWater, error) {
|
|
if len(cols) == 0 {
|
|
return PublicreportNotifyPhoneWaters.Query(
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return PublicreportNotifyPhoneWaters.Query(
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
|
|
sm.Columns(PublicreportNotifyPhoneWaters.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// PublicreportNotifyPhoneWaterExists checks the presence of a single record by primary key
|
|
func PublicreportNotifyPhoneWaterExists(ctx context.Context, exec bob.Executor, WaterIDPK int32, PhoneE164PK string) (bool, error) {
|
|
return PublicreportNotifyPhoneWaters.Query(
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after PublicreportNotifyPhoneWater is retrieved from the database
|
|
func (o *PublicreportNotifyPhoneWater) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhoneWater
|
|
func (o *PublicreportNotifyPhoneWater) primaryKeyVals() bob.Expression {
|
|
return psql.ArgGroup(
|
|
o.WaterID,
|
|
o.PhoneE164,
|
|
)
|
|
}
|
|
|
|
func (o *PublicreportNotifyPhoneWater) pkEQ() dialect.Expression {
|
|
return psql.Group(psql.Quote("publicreport.notify_phone_water", "water_id"), psql.Quote("publicreport.notify_phone_water", "phone_e164")).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 PublicreportNotifyPhoneWater
|
|
func (o *PublicreportNotifyPhoneWater) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhoneWaterSetter) error {
|
|
v, err := PublicreportNotifyPhoneWaters.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 PublicreportNotifyPhoneWater record with an executor
|
|
func (o *PublicreportNotifyPhoneWater) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := PublicreportNotifyPhoneWaters.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the PublicreportNotifyPhoneWater using the executor
|
|
func (o *PublicreportNotifyPhoneWater) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := PublicreportNotifyPhoneWaters.Query(
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
|
|
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(o.PhoneE164))),
|
|
).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
o2.R = o.R
|
|
*o = *o2
|
|
|
|
return nil
|
|
}
|
|
|
|
// AfterQueryHook is called after PublicreportNotifyPhoneWaterSlice is retrieved from the database
|
|
func (o PublicreportNotifyPhoneWaterSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportNotifyPhoneWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportNotifyPhoneWaterSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Group(psql.Quote("publicreport.notify_phone_water", "water_id"), psql.Quote("publicreport.notify_phone_water", "phone_e164")).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 PublicreportNotifyPhoneWaterSlice) copyMatchingRows(from ...*PublicreportNotifyPhoneWater) {
|
|
for i, old := range o {
|
|
for _, new := range from {
|
|
if new.WaterID != old.WaterID {
|
|
continue
|
|
}
|
|
if new.PhoneE164 != old.PhoneE164 {
|
|
continue
|
|
}
|
|
new.R = old.R
|
|
o[i] = new
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
|
func (o PublicreportNotifyPhoneWaterSlice) 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 PublicreportNotifyPhoneWaters.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 *PublicreportNotifyPhoneWater:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportNotifyPhoneWater:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportNotifyPhoneWaterSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportNotifyPhoneWater or a slice of PublicreportNotifyPhoneWater
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = PublicreportNotifyPhoneWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o PublicreportNotifyPhoneWaterSlice) 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 PublicreportNotifyPhoneWaters.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 *PublicreportNotifyPhoneWater:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportNotifyPhoneWater:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportNotifyPhoneWaterSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportNotifyPhoneWater or a slice of PublicreportNotifyPhoneWater
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = PublicreportNotifyPhoneWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o PublicreportNotifyPhoneWaterSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhoneWaterSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportNotifyPhoneWaters.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportNotifyPhoneWaterSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportNotifyPhoneWaters.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportNotifyPhoneWaterSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := PublicreportNotifyPhoneWaters.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// PhoneE164Phone starts a query for related objects on comms.phone
|
|
func (o *PublicreportNotifyPhoneWater) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
|
return CommsPhones.Query(append(mods,
|
|
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportNotifyPhoneWaterSlice) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
|
pkPhoneE164 := make(pgtypes.Array[string], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkPhoneE164 = append(pkPhoneE164, o.PhoneE164)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkPhoneE164), "text[]")),
|
|
))
|
|
|
|
return CommsPhones.Query(append(mods,
|
|
sm.Where(psql.Group(CommsPhones.Columns.E164).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// Water starts a query for related objects on publicreport.water
|
|
func (o *PublicreportNotifyPhoneWater) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
|
|
return PublicreportWaters.Query(append(mods,
|
|
sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(o.WaterID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportNotifyPhoneWaterSlice) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
|
|
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkWaterID = append(pkWaterID, o.WaterID)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
|
|
))
|
|
|
|
return PublicreportWaters.Query(append(mods,
|
|
sm.Where(psql.Group(PublicreportWaters.Columns.ID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func attachPublicreportNotifyPhoneWaterPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater, commsPhone1 *CommsPhone) (*PublicreportNotifyPhoneWater, error) {
|
|
setter := &PublicreportNotifyPhoneWaterSetter{
|
|
PhoneE164: omit.From(commsPhone1.E164),
|
|
}
|
|
|
|
err := publicreportNotifyPhoneWater0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportNotifyPhoneWaterPhoneE164Phone0: %w", err)
|
|
}
|
|
|
|
return publicreportNotifyPhoneWater0, nil
|
|
}
|
|
|
|
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) InsertPhoneE164Phone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
|
|
var err error
|
|
|
|
commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec)
|
|
if err != nil {
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
|
}
|
|
|
|
_, err = attachPublicreportNotifyPhoneWaterPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneWater0, commsPhone1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportNotifyPhoneWater0.R.PhoneE164Phone = commsPhone1
|
|
|
|
commsPhone1.R.PhoneE164NotifyPhoneWaters = append(commsPhone1.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWater0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
|
|
var err error
|
|
|
|
_, err = attachPublicreportNotifyPhoneWaterPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneWater0, commsPhone1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportNotifyPhoneWater0.R.PhoneE164Phone = commsPhone1
|
|
|
|
commsPhone1.R.PhoneE164NotifyPhoneWaters = append(commsPhone1.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWater0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func attachPublicreportNotifyPhoneWaterWater0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater, publicreportWater1 *PublicreportWater) (*PublicreportNotifyPhoneWater, error) {
|
|
setter := &PublicreportNotifyPhoneWaterSetter{
|
|
WaterID: omit.From(publicreportWater1.ID),
|
|
}
|
|
|
|
err := publicreportNotifyPhoneWater0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportNotifyPhoneWaterWater0: %w", err)
|
|
}
|
|
|
|
return publicreportNotifyPhoneWater0, nil
|
|
}
|
|
|
|
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) InsertWater(ctx context.Context, exec bob.Executor, related *PublicreportWaterSetter) error {
|
|
var err error
|
|
|
|
publicreportWater1, err := PublicreportWaters.Insert(related).One(ctx, exec)
|
|
if err != nil {
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
|
}
|
|
|
|
_, err = attachPublicreportNotifyPhoneWaterWater0(ctx, exec, 1, publicreportNotifyPhoneWater0, publicreportWater1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportNotifyPhoneWater0.R.Water = publicreportWater1
|
|
|
|
publicreportWater1.R.NotifyPhoneWaters = append(publicreportWater1.R.NotifyPhoneWaters, publicreportNotifyPhoneWater0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) AttachWater(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWater) error {
|
|
var err error
|
|
|
|
_, err = attachPublicreportNotifyPhoneWaterWater0(ctx, exec, 1, publicreportNotifyPhoneWater0, publicreportWater1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportNotifyPhoneWater0.R.Water = publicreportWater1
|
|
|
|
publicreportWater1.R.NotifyPhoneWaters = append(publicreportWater1.R.NotifyPhoneWaters, publicreportNotifyPhoneWater0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportNotifyPhoneWaterWhere[Q psql.Filterable] struct {
|
|
Created psql.WhereMod[Q, time.Time]
|
|
Deleted psql.WhereNullMod[Q, time.Time]
|
|
PhoneE164 psql.WhereMod[Q, string]
|
|
WaterID psql.WhereMod[Q, int32]
|
|
}
|
|
|
|
func (publicreportNotifyPhoneWaterWhere[Q]) AliasedAs(alias string) publicreportNotifyPhoneWaterWhere[Q] {
|
|
return buildPublicreportNotifyPhoneWaterWhere[Q](buildPublicreportNotifyPhoneWaterColumns(alias))
|
|
}
|
|
|
|
func buildPublicreportNotifyPhoneWaterWhere[Q psql.Filterable](cols publicreportNotifyPhoneWaterColumns) publicreportNotifyPhoneWaterWhere[Q] {
|
|
return publicreportNotifyPhoneWaterWhere[Q]{
|
|
Created: psql.Where[Q, time.Time](cols.Created),
|
|
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
|
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
|
|
WaterID: psql.Where[Q, int32](cols.WaterID),
|
|
}
|
|
}
|
|
|
|
func (o *PublicreportNotifyPhoneWater) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "PhoneE164Phone":
|
|
rel, ok := retrieved.(*CommsPhone)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportNotifyPhoneWater cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.PhoneE164Phone = rel
|
|
|
|
if rel != nil {
|
|
rel.R.PhoneE164NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
|
|
}
|
|
return nil
|
|
case "Water":
|
|
rel, ok := retrieved.(*PublicreportWater)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportNotifyPhoneWater cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Water = rel
|
|
|
|
if rel != nil {
|
|
rel.R.NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("publicreportNotifyPhoneWater has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type publicreportNotifyPhoneWaterPreloader struct {
|
|
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
|
|
Water func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildPublicreportNotifyPhoneWaterPreloader() publicreportNotifyPhoneWaterPreloader {
|
|
return publicreportNotifyPhoneWaterPreloader{
|
|
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
|
|
Name: "PhoneE164Phone",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: PublicreportNotifyPhoneWaters,
|
|
To: CommsPhones,
|
|
FromColumns: []string{"phone_e164"},
|
|
ToColumns: []string{"e164"},
|
|
},
|
|
},
|
|
}, CommsPhones.Columns.Names(), opts...)
|
|
},
|
|
Water: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*PublicreportWater, PublicreportWaterSlice](psql.PreloadRel{
|
|
Name: "Water",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: PublicreportNotifyPhoneWaters,
|
|
To: PublicreportWaters,
|
|
FromColumns: []string{"water_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, PublicreportWaters.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type publicreportNotifyPhoneWaterThenLoader[Q orm.Loadable] struct {
|
|
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildPublicreportNotifyPhoneWaterThenLoader[Q orm.Loadable]() publicreportNotifyPhoneWaterThenLoader[Q] {
|
|
type PhoneE164PhoneLoadInterface interface {
|
|
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type WaterLoadInterface interface {
|
|
LoadWater(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return publicreportNotifyPhoneWaterThenLoader[Q]{
|
|
PhoneE164Phone: thenLoadBuilder[Q](
|
|
"PhoneE164Phone",
|
|
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadPhoneE164Phone(ctx, exec, mods...)
|
|
},
|
|
),
|
|
Water: thenLoadBuilder[Q](
|
|
"Water",
|
|
func(ctx context.Context, exec bob.Executor, retrieved WaterLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadWater(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadPhoneE164Phone loads the publicreportNotifyPhoneWater's PhoneE164Phone into the .R struct
|
|
func (o *PublicreportNotifyPhoneWater) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.PhoneE164Phone = nil
|
|
|
|
related, err := o.PhoneE164Phone(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.PhoneE164NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
|
|
|
|
o.R.PhoneE164Phone = related
|
|
return nil
|
|
}
|
|
|
|
// LoadPhoneE164Phone loads the publicreportNotifyPhoneWater's PhoneE164Phone into the .R struct
|
|
func (os PublicreportNotifyPhoneWaterSlice) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
commsPhones, err := os.PhoneE164Phone(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range commsPhones {
|
|
|
|
if !(o.PhoneE164 == rel.E164) {
|
|
continue
|
|
}
|
|
|
|
rel.R.PhoneE164NotifyPhoneWaters = append(rel.R.PhoneE164NotifyPhoneWaters, o)
|
|
|
|
o.R.PhoneE164Phone = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadWater loads the publicreportNotifyPhoneWater's Water into the .R struct
|
|
func (o *PublicreportNotifyPhoneWater) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.Water = nil
|
|
|
|
related, err := o.Water(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
|
|
|
|
o.R.Water = related
|
|
return nil
|
|
}
|
|
|
|
// LoadWater loads the publicreportNotifyPhoneWater's Water into the .R struct
|
|
func (os PublicreportNotifyPhoneWaterSlice) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
publicreportWaters, err := os.Water(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range publicreportWaters {
|
|
|
|
if !(o.WaterID == rel.ID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.NotifyPhoneWaters = append(rel.R.NotifyPhoneWaters, o)
|
|
|
|
o.R.Water = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|