797 lines
27 KiB
Go
797 lines
27 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"
|
||
|
|
)
|
||
|
|
|
||
|
|
// PublicreportNotifyEmailWater is an object representing the database table.
|
||
|
|
type PublicreportNotifyEmailWater struct {
|
||
|
|
Created time.Time `db:"created" `
|
||
|
|
Deleted null.Val[time.Time] `db:"deleted" `
|
||
|
|
WaterID int32 `db:"water_id,pk" `
|
||
|
|
EmailAddress string `db:"email_address,pk" `
|
||
|
|
|
||
|
|
R publicreportNotifyEmailWaterR `db:"-" `
|
||
|
|
}
|
||
|
|
|
||
|
|
// PublicreportNotifyEmailWaterSlice is an alias for a slice of pointers to PublicreportNotifyEmailWater.
|
||
|
|
// This should almost always be used instead of []*PublicreportNotifyEmailWater.
|
||
|
|
type PublicreportNotifyEmailWaterSlice []*PublicreportNotifyEmailWater
|
||
|
|
|
||
|
|
// PublicreportNotifyEmailWaters contains methods to work with the notify_email_water table
|
||
|
|
var PublicreportNotifyEmailWaters = psql.NewTablex[*PublicreportNotifyEmailWater, PublicreportNotifyEmailWaterSlice, *PublicreportNotifyEmailWaterSetter]("publicreport", "notify_email_water", buildPublicreportNotifyEmailWaterColumns("publicreport.notify_email_water"))
|
||
|
|
|
||
|
|
// PublicreportNotifyEmailWatersQuery is a query on the notify_email_water table
|
||
|
|
type PublicreportNotifyEmailWatersQuery = *psql.ViewQuery[*PublicreportNotifyEmailWater, PublicreportNotifyEmailWaterSlice]
|
||
|
|
|
||
|
|
// publicreportNotifyEmailWaterR is where relationships are stored.
|
||
|
|
type publicreportNotifyEmailWaterR struct {
|
||
|
|
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_water.notify_email_pool_email_address_fkey
|
||
|
|
Water *PublicreportWater // publicreport.notify_email_water.notify_email_pool_pool_id_fkey
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildPublicreportNotifyEmailWaterColumns(alias string) publicreportNotifyEmailWaterColumns {
|
||
|
|
return publicreportNotifyEmailWaterColumns{
|
||
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
||
|
|
"created", "deleted", "water_id", "email_address",
|
||
|
|
).WithParent("publicreport.notify_email_water"),
|
||
|
|
tableAlias: alias,
|
||
|
|
Created: psql.Quote(alias, "created"),
|
||
|
|
Deleted: psql.Quote(alias, "deleted"),
|
||
|
|
WaterID: psql.Quote(alias, "water_id"),
|
||
|
|
EmailAddress: psql.Quote(alias, "email_address"),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type publicreportNotifyEmailWaterColumns struct {
|
||
|
|
expr.ColumnsExpr
|
||
|
|
tableAlias string
|
||
|
|
Created psql.Expression
|
||
|
|
Deleted psql.Expression
|
||
|
|
WaterID psql.Expression
|
||
|
|
EmailAddress psql.Expression
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c publicreportNotifyEmailWaterColumns) Alias() string {
|
||
|
|
return c.tableAlias
|
||
|
|
}
|
||
|
|
|
||
|
|
func (publicreportNotifyEmailWaterColumns) AliasedAs(alias string) publicreportNotifyEmailWaterColumns {
|
||
|
|
return buildPublicreportNotifyEmailWaterColumns(alias)
|
||
|
|
}
|
||
|
|
|
||
|
|
// PublicreportNotifyEmailWaterSetter is used for insert/upsert/update operations
|
||
|
|
// All values are optional, and do not have to be set
|
||
|
|
// Generated columns are not included
|
||
|
|
type PublicreportNotifyEmailWaterSetter struct {
|
||
|
|
Created omit.Val[time.Time] `db:"created" `
|
||
|
|
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
||
|
|
WaterID omit.Val[int32] `db:"water_id,pk" `
|
||
|
|
EmailAddress omit.Val[string] `db:"email_address,pk" `
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s PublicreportNotifyEmailWaterSetter) 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.WaterID.IsValue() {
|
||
|
|
vals = append(vals, "water_id")
|
||
|
|
}
|
||
|
|
if s.EmailAddress.IsValue() {
|
||
|
|
vals = append(vals, "email_address")
|
||
|
|
}
|
||
|
|
return vals
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s PublicreportNotifyEmailWaterSetter) Overwrite(t *PublicreportNotifyEmailWater) {
|
||
|
|
if s.Created.IsValue() {
|
||
|
|
t.Created = s.Created.MustGet()
|
||
|
|
}
|
||
|
|
if !s.Deleted.IsUnset() {
|
||
|
|
t.Deleted = s.Deleted.MustGetNull()
|
||
|
|
}
|
||
|
|
if s.WaterID.IsValue() {
|
||
|
|
t.WaterID = s.WaterID.MustGet()
|
||
|
|
}
|
||
|
|
if s.EmailAddress.IsValue() {
|
||
|
|
t.EmailAddress = s.EmailAddress.MustGet()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *PublicreportNotifyEmailWaterSetter) Apply(q *dialect.InsertQuery) {
|
||
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||
|
|
return PublicreportNotifyEmailWaters.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.WaterID.IsValue() {
|
||
|
|
vals[2] = psql.Arg(s.WaterID.MustGet())
|
||
|
|
} else {
|
||
|
|
vals[2] = psql.Raw("DEFAULT")
|
||
|
|
}
|
||
|
|
|
||
|
|
if s.EmailAddress.IsValue() {
|
||
|
|
vals[3] = psql.Arg(s.EmailAddress.MustGet())
|
||
|
|
} else {
|
||
|
|
vals[3] = psql.Raw("DEFAULT")
|
||
|
|
}
|
||
|
|
|
||
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||
|
|
}))
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s PublicreportNotifyEmailWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||
|
|
return um.Set(s.Expressions()...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s PublicreportNotifyEmailWaterSetter) 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.WaterID.IsValue() {
|
||
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||
|
|
psql.Quote(append(prefix, "water_id")...),
|
||
|
|
psql.Arg(s.WaterID),
|
||
|
|
}})
|
||
|
|
}
|
||
|
|
|
||
|
|
if s.EmailAddress.IsValue() {
|
||
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||
|
|
psql.Quote(append(prefix, "email_address")...),
|
||
|
|
psql.Arg(s.EmailAddress),
|
||
|
|
}})
|
||
|
|
}
|
||
|
|
|
||
|
|
return exprs
|
||
|
|
}
|
||
|
|
|
||
|
|
// FindPublicreportNotifyEmailWater retrieves a single record by primary key
|
||
|
|
// If cols is empty Find will return all columns.
|
||
|
|
func FindPublicreportNotifyEmailWater(ctx context.Context, exec bob.Executor, WaterIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailWater, error) {
|
||
|
|
if len(cols) == 0 {
|
||
|
|
return PublicreportNotifyEmailWaters.Query(
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
|
||
|
|
).One(ctx, exec)
|
||
|
|
}
|
||
|
|
|
||
|
|
return PublicreportNotifyEmailWaters.Query(
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
|
||
|
|
sm.Columns(PublicreportNotifyEmailWaters.Columns.Only(cols...)),
|
||
|
|
).One(ctx, exec)
|
||
|
|
}
|
||
|
|
|
||
|
|
// PublicreportNotifyEmailWaterExists checks the presence of a single record by primary key
|
||
|
|
func PublicreportNotifyEmailWaterExists(ctx context.Context, exec bob.Executor, WaterIDPK int32, EmailAddressPK string) (bool, error) {
|
||
|
|
return PublicreportNotifyEmailWaters.Query(
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
|
||
|
|
).Exists(ctx, exec)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AfterQueryHook is called after PublicreportNotifyEmailWater is retrieved from the database
|
||
|
|
func (o *PublicreportNotifyEmailWater) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||
|
|
var err error
|
||
|
|
|
||
|
|
switch queryType {
|
||
|
|
case bob.QueryTypeSelect:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
|
||
|
|
case bob.QueryTypeInsert:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
|
||
|
|
case bob.QueryTypeUpdate:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
|
||
|
|
case bob.QueryTypeDelete:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
|
||
|
|
}
|
||
|
|
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailWater
|
||
|
|
func (o *PublicreportNotifyEmailWater) primaryKeyVals() bob.Expression {
|
||
|
|
return psql.ArgGroup(
|
||
|
|
o.WaterID,
|
||
|
|
o.EmailAddress,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o *PublicreportNotifyEmailWater) pkEQ() dialect.Expression {
|
||
|
|
return psql.Group(psql.Quote("publicreport.notify_email_water", "water_id"), psql.Quote("publicreport.notify_email_water", "email_address")).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 PublicreportNotifyEmailWater
|
||
|
|
func (o *PublicreportNotifyEmailWater) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailWaterSetter) error {
|
||
|
|
v, err := PublicreportNotifyEmailWaters.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 PublicreportNotifyEmailWater record with an executor
|
||
|
|
func (o *PublicreportNotifyEmailWater) Delete(ctx context.Context, exec bob.Executor) error {
|
||
|
|
_, err := PublicreportNotifyEmailWaters.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// Reload refreshes the PublicreportNotifyEmailWater using the executor
|
||
|
|
func (o *PublicreportNotifyEmailWater) Reload(ctx context.Context, exec bob.Executor) error {
|
||
|
|
o2, err := PublicreportNotifyEmailWaters.Query(
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
|
||
|
|
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(o.EmailAddress))),
|
||
|
|
).One(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
o2.R = o.R
|
||
|
|
*o = *o2
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// AfterQueryHook is called after PublicreportNotifyEmailWaterSlice is retrieved from the database
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||
|
|
var err error
|
||
|
|
|
||
|
|
switch queryType {
|
||
|
|
case bob.QueryTypeSelect:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||
|
|
case bob.QueryTypeInsert:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||
|
|
case bob.QueryTypeUpdate:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||
|
|
case bob.QueryTypeDelete:
|
||
|
|
ctx, err = PublicreportNotifyEmailWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||
|
|
}
|
||
|
|
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) pkIN() dialect.Expression {
|
||
|
|
if len(o) == 0 {
|
||
|
|
return psql.Raw("NULL")
|
||
|
|
}
|
||
|
|
|
||
|
|
return psql.Group(psql.Quote("publicreport.notify_email_water", "water_id"), psql.Quote("publicreport.notify_email_water", "email_address")).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 PublicreportNotifyEmailWaterSlice) copyMatchingRows(from ...*PublicreportNotifyEmailWater) {
|
||
|
|
for i, old := range o {
|
||
|
|
for _, new := range from {
|
||
|
|
if new.WaterID != old.WaterID {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
if new.EmailAddress != old.EmailAddress {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
new.R = old.R
|
||
|
|
o[i] = new
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) 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 PublicreportNotifyEmailWaters.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 *PublicreportNotifyEmailWater:
|
||
|
|
o.copyMatchingRows(retrieved)
|
||
|
|
case []*PublicreportNotifyEmailWater:
|
||
|
|
o.copyMatchingRows(retrieved...)
|
||
|
|
case PublicreportNotifyEmailWaterSlice:
|
||
|
|
o.copyMatchingRows(retrieved...)
|
||
|
|
default:
|
||
|
|
// If the retrieved value is not a PublicreportNotifyEmailWater or a slice of PublicreportNotifyEmailWater
|
||
|
|
// then run the AfterUpdateHooks on the slice
|
||
|
|
_, err = PublicreportNotifyEmailWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||
|
|
}
|
||
|
|
|
||
|
|
return err
|
||
|
|
}))
|
||
|
|
|
||
|
|
q.AppendWhere(o.pkIN())
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) 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 PublicreportNotifyEmailWaters.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 *PublicreportNotifyEmailWater:
|
||
|
|
o.copyMatchingRows(retrieved)
|
||
|
|
case []*PublicreportNotifyEmailWater:
|
||
|
|
o.copyMatchingRows(retrieved...)
|
||
|
|
case PublicreportNotifyEmailWaterSlice:
|
||
|
|
o.copyMatchingRows(retrieved...)
|
||
|
|
default:
|
||
|
|
// If the retrieved value is not a PublicreportNotifyEmailWater or a slice of PublicreportNotifyEmailWater
|
||
|
|
// then run the AfterDeleteHooks on the slice
|
||
|
|
_, err = PublicreportNotifyEmailWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||
|
|
}
|
||
|
|
|
||
|
|
return err
|
||
|
|
}))
|
||
|
|
|
||
|
|
q.AppendWhere(o.pkIN())
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailWaterSetter) error {
|
||
|
|
if len(o) == 0 {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
_, err := PublicreportNotifyEmailWaters.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||
|
|
if len(o) == 0 {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
_, err := PublicreportNotifyEmailWaters.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o PublicreportNotifyEmailWaterSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||
|
|
if len(o) == 0 {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
o2, err := PublicreportNotifyEmailWaters.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
o.copyMatchingRows(o2...)
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// EmailAddressEmailContact starts a query for related objects on comms.email_contact
|
||
|
|
func (o *PublicreportNotifyEmailWater) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
|
||
|
|
return CommsEmailContacts.Query(append(mods,
|
||
|
|
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
|
||
|
|
)...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (os PublicreportNotifyEmailWaterSlice) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
|
||
|
|
pkEmailAddress := make(pgtypes.Array[string], 0, len(os))
|
||
|
|
for _, o := range os {
|
||
|
|
if o == nil {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
pkEmailAddress = append(pkEmailAddress, o.EmailAddress)
|
||
|
|
}
|
||
|
|
PKArgExpr := psql.Select(sm.Columns(
|
||
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkEmailAddress), "text[]")),
|
||
|
|
))
|
||
|
|
|
||
|
|
return CommsEmailContacts.Query(append(mods,
|
||
|
|
sm.Where(psql.Group(CommsEmailContacts.Columns.Address).OP("IN", PKArgExpr)),
|
||
|
|
)...)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Water starts a query for related objects on publicreport.water
|
||
|
|
func (o *PublicreportNotifyEmailWater) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
|
||
|
|
return PublicreportWaters.Query(append(mods,
|
||
|
|
sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(o.WaterID))),
|
||
|
|
)...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (os PublicreportNotifyEmailWaterSlice) 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 attachPublicreportNotifyEmailWaterEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailWater, error) {
|
||
|
|
setter := &PublicreportNotifyEmailWaterSetter{
|
||
|
|
EmailAddress: omit.From(commsEmailContact1.Address),
|
||
|
|
}
|
||
|
|
|
||
|
|
err := publicreportNotifyEmailWater0.Update(ctx, exec, setter)
|
||
|
|
if err != nil {
|
||
|
|
return nil, fmt.Errorf("attachPublicreportNotifyEmailWaterEmailAddressEmailContact0: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
return publicreportNotifyEmailWater0, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) InsertEmailAddressEmailContact(ctx context.Context, exec bob.Executor, related *CommsEmailContactSetter) error {
|
||
|
|
var err error
|
||
|
|
|
||
|
|
commsEmailContact1, err := CommsEmailContacts.Insert(related).One(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
_, err = attachPublicreportNotifyEmailWaterEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailWater0, commsEmailContact1)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
publicreportNotifyEmailWater0.R.EmailAddressEmailContact = commsEmailContact1
|
||
|
|
|
||
|
|
commsEmailContact1.R.EmailAddressNotifyEmailWaters = append(commsEmailContact1.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWater0)
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
|
||
|
|
var err error
|
||
|
|
|
||
|
|
_, err = attachPublicreportNotifyEmailWaterEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailWater0, commsEmailContact1)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
publicreportNotifyEmailWater0.R.EmailAddressEmailContact = commsEmailContact1
|
||
|
|
|
||
|
|
commsEmailContact1.R.EmailAddressNotifyEmailWaters = append(commsEmailContact1.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWater0)
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func attachPublicreportNotifyEmailWaterWater0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater, publicreportWater1 *PublicreportWater) (*PublicreportNotifyEmailWater, error) {
|
||
|
|
setter := &PublicreportNotifyEmailWaterSetter{
|
||
|
|
WaterID: omit.From(publicreportWater1.ID),
|
||
|
|
}
|
||
|
|
|
||
|
|
err := publicreportNotifyEmailWater0.Update(ctx, exec, setter)
|
||
|
|
if err != nil {
|
||
|
|
return nil, fmt.Errorf("attachPublicreportNotifyEmailWaterWater0: %w", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
return publicreportNotifyEmailWater0, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) 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 = attachPublicreportNotifyEmailWaterWater0(ctx, exec, 1, publicreportNotifyEmailWater0, publicreportWater1)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
publicreportNotifyEmailWater0.R.Water = publicreportWater1
|
||
|
|
|
||
|
|
publicreportWater1.R.NotifyEmailWaters = append(publicreportWater1.R.NotifyEmailWaters, publicreportNotifyEmailWater0)
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) AttachWater(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWater) error {
|
||
|
|
var err error
|
||
|
|
|
||
|
|
_, err = attachPublicreportNotifyEmailWaterWater0(ctx, exec, 1, publicreportNotifyEmailWater0, publicreportWater1)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
publicreportNotifyEmailWater0.R.Water = publicreportWater1
|
||
|
|
|
||
|
|
publicreportWater1.R.NotifyEmailWaters = append(publicreportWater1.R.NotifyEmailWaters, publicreportNotifyEmailWater0)
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
type publicreportNotifyEmailWaterWhere[Q psql.Filterable] struct {
|
||
|
|
Created psql.WhereMod[Q, time.Time]
|
||
|
|
Deleted psql.WhereNullMod[Q, time.Time]
|
||
|
|
WaterID psql.WhereMod[Q, int32]
|
||
|
|
EmailAddress psql.WhereMod[Q, string]
|
||
|
|
}
|
||
|
|
|
||
|
|
func (publicreportNotifyEmailWaterWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailWaterWhere[Q] {
|
||
|
|
return buildPublicreportNotifyEmailWaterWhere[Q](buildPublicreportNotifyEmailWaterColumns(alias))
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildPublicreportNotifyEmailWaterWhere[Q psql.Filterable](cols publicreportNotifyEmailWaterColumns) publicreportNotifyEmailWaterWhere[Q] {
|
||
|
|
return publicreportNotifyEmailWaterWhere[Q]{
|
||
|
|
Created: psql.Where[Q, time.Time](cols.Created),
|
||
|
|
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
||
|
|
WaterID: psql.Where[Q, int32](cols.WaterID),
|
||
|
|
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o *PublicreportNotifyEmailWater) Preload(name string, retrieved any) error {
|
||
|
|
if o == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
switch name {
|
||
|
|
case "EmailAddressEmailContact":
|
||
|
|
rel, ok := retrieved.(*CommsEmailContact)
|
||
|
|
if !ok {
|
||
|
|
return fmt.Errorf("publicreportNotifyEmailWater cannot load %T as %q", retrieved, name)
|
||
|
|
}
|
||
|
|
|
||
|
|
o.R.EmailAddressEmailContact = rel
|
||
|
|
|
||
|
|
if rel != nil {
|
||
|
|
rel.R.EmailAddressNotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
case "Water":
|
||
|
|
rel, ok := retrieved.(*PublicreportWater)
|
||
|
|
if !ok {
|
||
|
|
return fmt.Errorf("publicreportNotifyEmailWater cannot load %T as %q", retrieved, name)
|
||
|
|
}
|
||
|
|
|
||
|
|
o.R.Water = rel
|
||
|
|
|
||
|
|
if rel != nil {
|
||
|
|
rel.R.NotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
default:
|
||
|
|
return fmt.Errorf("publicreportNotifyEmailWater has no relationship %q", name)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type publicreportNotifyEmailWaterPreloader struct {
|
||
|
|
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
|
||
|
|
Water func(...psql.PreloadOption) psql.Preloader
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildPublicreportNotifyEmailWaterPreloader() publicreportNotifyEmailWaterPreloader {
|
||
|
|
return publicreportNotifyEmailWaterPreloader{
|
||
|
|
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
|
||
|
|
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
|
||
|
|
Name: "EmailAddressEmailContact",
|
||
|
|
Sides: []psql.PreloadSide{
|
||
|
|
{
|
||
|
|
From: PublicreportNotifyEmailWaters,
|
||
|
|
To: CommsEmailContacts,
|
||
|
|
FromColumns: []string{"email_address"},
|
||
|
|
ToColumns: []string{"address"},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}, CommsEmailContacts.Columns.Names(), opts...)
|
||
|
|
},
|
||
|
|
Water: func(opts ...psql.PreloadOption) psql.Preloader {
|
||
|
|
return psql.Preload[*PublicreportWater, PublicreportWaterSlice](psql.PreloadRel{
|
||
|
|
Name: "Water",
|
||
|
|
Sides: []psql.PreloadSide{
|
||
|
|
{
|
||
|
|
From: PublicreportNotifyEmailWaters,
|
||
|
|
To: PublicreportWaters,
|
||
|
|
FromColumns: []string{"water_id"},
|
||
|
|
ToColumns: []string{"id"},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}, PublicreportWaters.Columns.Names(), opts...)
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type publicreportNotifyEmailWaterThenLoader[Q orm.Loadable] struct {
|
||
|
|
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||
|
|
Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||
|
|
}
|
||
|
|
|
||
|
|
func buildPublicreportNotifyEmailWaterThenLoader[Q orm.Loadable]() publicreportNotifyEmailWaterThenLoader[Q] {
|
||
|
|
type EmailAddressEmailContactLoadInterface interface {
|
||
|
|
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||
|
|
}
|
||
|
|
type WaterLoadInterface interface {
|
||
|
|
LoadWater(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||
|
|
}
|
||
|
|
|
||
|
|
return publicreportNotifyEmailWaterThenLoader[Q]{
|
||
|
|
EmailAddressEmailContact: thenLoadBuilder[Q](
|
||
|
|
"EmailAddressEmailContact",
|
||
|
|
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressEmailContactLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||
|
|
return retrieved.LoadEmailAddressEmailContact(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...)
|
||
|
|
},
|
||
|
|
),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailWater's EmailAddressEmailContact into the .R struct
|
||
|
|
func (o *PublicreportNotifyEmailWater) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||
|
|
if o == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// Reset the relationship
|
||
|
|
o.R.EmailAddressEmailContact = nil
|
||
|
|
|
||
|
|
related, err := o.EmailAddressEmailContact(mods...).One(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
related.R.EmailAddressNotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
|
||
|
|
|
||
|
|
o.R.EmailAddressEmailContact = related
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailWater's EmailAddressEmailContact into the .R struct
|
||
|
|
func (os PublicreportNotifyEmailWaterSlice) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||
|
|
if len(os) == 0 {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
commsEmailContacts, err := os.EmailAddressEmailContact(mods...).All(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, o := range os {
|
||
|
|
if o == nil {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, rel := range commsEmailContacts {
|
||
|
|
|
||
|
|
if !(o.EmailAddress == rel.Address) {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
|
||
|
|
rel.R.EmailAddressNotifyEmailWaters = append(rel.R.EmailAddressNotifyEmailWaters, o)
|
||
|
|
|
||
|
|
o.R.EmailAddressEmailContact = rel
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// LoadWater loads the publicreportNotifyEmailWater's Water into the .R struct
|
||
|
|
func (o *PublicreportNotifyEmailWater) 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.NotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
|
||
|
|
|
||
|
|
o.R.Water = related
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// LoadWater loads the publicreportNotifyEmailWater's Water into the .R struct
|
||
|
|
func (os PublicreportNotifyEmailWaterSlice) 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.NotifyEmailWaters = append(rel.R.NotifyEmailWaters, o)
|
||
|
|
|
||
|
|
o.R.Water = rel
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|