nidus-sync/db/models/comms.phone.bob.go
Eli Ribble e40fe55eaf
Modify email subscription table to drop district ID
I don't have time to work out all the behavior, this is just to get to
where I can release
2026-02-10 05:12:42 +00:00

2297 lines
69 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"
"strconv"
"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/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/omit"
"github.com/stephenafamo/scan"
)
// CommsPhone is an object representing the database table.
type CommsPhone struct {
E164 string `db:"e164,pk" `
IsSubscribed bool `db:"is_subscribed" `
Status enums.CommsPhonestatustype `db:"status" `
R commsPhoneR `db:"-" `
C commsPhoneC `db:"-" `
}
// CommsPhoneSlice is an alias for a slice of pointers to CommsPhone.
// This should almost always be used instead of []*CommsPhone.
type CommsPhoneSlice []*CommsPhone
// CommsPhones contains methods to work with the phone table
var CommsPhones = psql.NewTablex[*CommsPhone, CommsPhoneSlice, *CommsPhoneSetter]("comms", "phone", buildCommsPhoneColumns("comms.phone"))
// CommsPhonesQuery is a query on the phone table
type CommsPhonesQuery = *psql.ViewQuery[*CommsPhone, CommsPhoneSlice]
// commsPhoneR is where relationships are stored.
type commsPhoneR struct {
DestinationTextJobs CommsTextJobSlice // comms.text_job.text_job_destination_fkey
DestinationTextLogs CommsTextLogSlice // comms.text_log.text_log_destination_fkey
SourceTextLogs CommsTextLogSlice // comms.text_log.text_log_source_fkey
Organizations OrganizationSlice // district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey
PhoneE164NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey
PhoneE164NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey
PhoneE164SubscribePhones PublicreportSubscribePhoneSlice // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
}
func buildCommsPhoneColumns(alias string) commsPhoneColumns {
return commsPhoneColumns{
ColumnsExpr: expr.NewColumnsExpr(
"e164", "is_subscribed", "status",
).WithParent("comms.phone"),
tableAlias: alias,
E164: psql.Quote(alias, "e164"),
IsSubscribed: psql.Quote(alias, "is_subscribed"),
Status: psql.Quote(alias, "status"),
}
}
type commsPhoneColumns struct {
expr.ColumnsExpr
tableAlias string
E164 psql.Expression
IsSubscribed psql.Expression
Status psql.Expression
}
func (c commsPhoneColumns) Alias() string {
return c.tableAlias
}
func (commsPhoneColumns) AliasedAs(alias string) commsPhoneColumns {
return buildCommsPhoneColumns(alias)
}
// CommsPhoneSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type CommsPhoneSetter struct {
E164 omit.Val[string] `db:"e164,pk" `
IsSubscribed omit.Val[bool] `db:"is_subscribed" `
Status omit.Val[enums.CommsPhonestatustype] `db:"status" `
}
func (s CommsPhoneSetter) SetColumns() []string {
vals := make([]string, 0, 3)
if s.E164.IsValue() {
vals = append(vals, "e164")
}
if s.IsSubscribed.IsValue() {
vals = append(vals, "is_subscribed")
}
if s.Status.IsValue() {
vals = append(vals, "status")
}
return vals
}
func (s CommsPhoneSetter) Overwrite(t *CommsPhone) {
if s.E164.IsValue() {
t.E164 = s.E164.MustGet()
}
if s.IsSubscribed.IsValue() {
t.IsSubscribed = s.IsSubscribed.MustGet()
}
if s.Status.IsValue() {
t.Status = s.Status.MustGet()
}
}
func (s *CommsPhoneSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return CommsPhones.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, 3)
if s.E164.IsValue() {
vals[0] = psql.Arg(s.E164.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.IsSubscribed.IsValue() {
vals[1] = psql.Arg(s.IsSubscribed.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.Status.IsValue() {
vals[2] = psql.Arg(s.Status.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s CommsPhoneSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s CommsPhoneSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 3)
if s.E164.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "e164")...),
psql.Arg(s.E164),
}})
}
if s.IsSubscribed.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "is_subscribed")...),
psql.Arg(s.IsSubscribed),
}})
}
if s.Status.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "status")...),
psql.Arg(s.Status),
}})
}
return exprs
}
// FindCommsPhone retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindCommsPhone(ctx context.Context, exec bob.Executor, E164PK string, cols ...string) (*CommsPhone, error) {
if len(cols) == 0 {
return CommsPhones.Query(
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(E164PK))),
).One(ctx, exec)
}
return CommsPhones.Query(
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(E164PK))),
sm.Columns(CommsPhones.Columns.Only(cols...)),
).One(ctx, exec)
}
// CommsPhoneExists checks the presence of a single record by primary key
func CommsPhoneExists(ctx context.Context, exec bob.Executor, E164PK string) (bool, error) {
return CommsPhones.Query(
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(E164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after CommsPhone is retrieved from the database
func (o *CommsPhone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = CommsPhones.AfterSelectHooks.RunHooks(ctx, exec, CommsPhoneSlice{o})
case bob.QueryTypeInsert:
ctx, err = CommsPhones.AfterInsertHooks.RunHooks(ctx, exec, CommsPhoneSlice{o})
case bob.QueryTypeUpdate:
ctx, err = CommsPhones.AfterUpdateHooks.RunHooks(ctx, exec, CommsPhoneSlice{o})
case bob.QueryTypeDelete:
ctx, err = CommsPhones.AfterDeleteHooks.RunHooks(ctx, exec, CommsPhoneSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the CommsPhone
func (o *CommsPhone) primaryKeyVals() bob.Expression {
return psql.Arg(o.E164)
}
func (o *CommsPhone) pkEQ() dialect.Expression {
return psql.Quote("comms.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 CommsPhone
func (o *CommsPhone) Update(ctx context.Context, exec bob.Executor, s *CommsPhoneSetter) error {
v, err := CommsPhones.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 CommsPhone record with an executor
func (o *CommsPhone) Delete(ctx context.Context, exec bob.Executor) error {
_, err := CommsPhones.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the CommsPhone using the executor
func (o *CommsPhone) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := CommsPhones.Query(
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.E164))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after CommsPhoneSlice is retrieved from the database
func (o CommsPhoneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = CommsPhones.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = CommsPhones.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = CommsPhones.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = CommsPhones.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o CommsPhoneSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("comms.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 CommsPhoneSlice) copyMatchingRows(from ...*CommsPhone) {
for i, old := range o {
for _, new := range from {
if new.E164 != old.E164 {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o CommsPhoneSlice) 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 CommsPhones.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 *CommsPhone:
o.copyMatchingRows(retrieved)
case []*CommsPhone:
o.copyMatchingRows(retrieved...)
case CommsPhoneSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a CommsPhone or a slice of CommsPhone
// then run the AfterUpdateHooks on the slice
_, err = CommsPhones.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o CommsPhoneSlice) 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 CommsPhones.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 *CommsPhone:
o.copyMatchingRows(retrieved)
case []*CommsPhone:
o.copyMatchingRows(retrieved...)
case CommsPhoneSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a CommsPhone or a slice of CommsPhone
// then run the AfterDeleteHooks on the slice
_, err = CommsPhones.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o CommsPhoneSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsPhoneSetter) error {
if len(o) == 0 {
return nil
}
_, err := CommsPhones.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o CommsPhoneSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := CommsPhones.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o CommsPhoneSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := CommsPhones.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// DestinationTextJobs starts a query for related objects on comms.text_job
func (o *CommsPhone) DestinationTextJobs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextJobsQuery {
return CommsTextJobs.Query(append(mods,
sm.Where(CommsTextJobs.Columns.Destination.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) DestinationTextJobs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextJobsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return CommsTextJobs.Query(append(mods,
sm.Where(psql.Group(CommsTextJobs.Columns.Destination).OP("IN", PKArgExpr)),
)...)
}
// DestinationTextLogs starts a query for related objects on comms.text_log
func (o *CommsPhone) DestinationTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
return CommsTextLogs.Query(append(mods,
sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) DestinationTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return CommsTextLogs.Query(append(mods,
sm.Where(psql.Group(CommsTextLogs.Columns.Destination).OP("IN", PKArgExpr)),
)...)
}
// SourceTextLogs starts a query for related objects on comms.text_log
func (o *CommsPhone) SourceTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
return CommsTextLogs.Query(append(mods,
sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) SourceTextLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return CommsTextLogs.Query(append(mods,
sm.Where(psql.Group(CommsTextLogs.Columns.Source).OP("IN", PKArgExpr)),
)...)
}
// Organizations starts a query for related objects on organization
func (o *CommsPhone) Organizations(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
return Organizations.Query(append(mods,
sm.InnerJoin(DistrictSubscriptionPhones.NameAs()).On(
Organizations.Columns.ID.EQ(DistrictSubscriptionPhones.Columns.OrganizationID)),
sm.Where(DistrictSubscriptionPhones.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) Organizations(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return Organizations.Query(append(mods,
sm.InnerJoin(DistrictSubscriptionPhones.NameAs()).On(
Organizations.Columns.ID.EQ(DistrictSubscriptionPhones.Columns.OrganizationID),
),
sm.Where(psql.Group(DistrictSubscriptionPhones.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164NotifyPhoneNuisances starts a query for related objects on publicreport.notify_phone_nuisance
func (o *CommsPhone) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery {
return PublicreportNotifyPhoneNuisances.Query(append(mods,
sm.Where(PublicreportNotifyPhoneNuisances.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportNotifyPhoneNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhoneNuisances.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164NotifyPhonePools starts a query for related objects on publicreport.notify_phone_pool
func (o *CommsPhone) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery {
return PublicreportNotifyPhonePools.Query(append(mods,
sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportNotifyPhonePools.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhonePools.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164SubscribePhones starts a query for related objects on publicreport.subscribe_phone
func (o *CommsPhone) PhoneE164SubscribePhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportSubscribePhonesQuery {
return PublicreportSubscribePhones.Query(append(mods,
sm.Where(PublicreportSubscribePhones.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164SubscribePhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportSubscribePhonesQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportSubscribePhones.Query(append(mods,
sm.Where(psql.Group(PublicreportSubscribePhones.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
func insertCommsPhoneDestinationTextJobs0(ctx context.Context, exec bob.Executor, commsTextJobs1 []*CommsTextJobSetter, commsPhone0 *CommsPhone) (CommsTextJobSlice, error) {
for i := range commsTextJobs1 {
commsTextJobs1[i].Destination = omit.From(commsPhone0.E164)
}
ret, err := CommsTextJobs.Insert(bob.ToMods(commsTextJobs1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhoneDestinationTextJobs0: %w", err)
}
return ret, nil
}
func attachCommsPhoneDestinationTextJobs0(ctx context.Context, exec bob.Executor, count int, commsTextJobs1 CommsTextJobSlice, commsPhone0 *CommsPhone) (CommsTextJobSlice, error) {
setter := &CommsTextJobSetter{
Destination: omit.From(commsPhone0.E164),
}
err := commsTextJobs1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhoneDestinationTextJobs0: %w", err)
}
return commsTextJobs1, nil
}
func (commsPhone0 *CommsPhone) InsertDestinationTextJobs(ctx context.Context, exec bob.Executor, related ...*CommsTextJobSetter) error {
if len(related) == 0 {
return nil
}
var err error
commsTextJobs1, err := insertCommsPhoneDestinationTextJobs0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.DestinationTextJobs = append(commsPhone0.R.DestinationTextJobs, commsTextJobs1...)
for _, rel := range commsTextJobs1 {
rel.R.DestinationPhone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachDestinationTextJobs(ctx context.Context, exec bob.Executor, related ...*CommsTextJob) error {
if len(related) == 0 {
return nil
}
var err error
commsTextJobs1 := CommsTextJobSlice(related)
_, err = attachCommsPhoneDestinationTextJobs0(ctx, exec, len(related), commsTextJobs1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.DestinationTextJobs = append(commsPhone0.R.DestinationTextJobs, commsTextJobs1...)
for _, rel := range related {
rel.R.DestinationPhone = commsPhone0
}
return nil
}
func insertCommsPhoneDestinationTextLogs0(ctx context.Context, exec bob.Executor, commsTextLogs1 []*CommsTextLogSetter, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) {
for i := range commsTextLogs1 {
commsTextLogs1[i].Destination = omit.From(commsPhone0.E164)
}
ret, err := CommsTextLogs.Insert(bob.ToMods(commsTextLogs1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhoneDestinationTextLogs0: %w", err)
}
return ret, nil
}
func attachCommsPhoneDestinationTextLogs0(ctx context.Context, exec bob.Executor, count int, commsTextLogs1 CommsTextLogSlice, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) {
setter := &CommsTextLogSetter{
Destination: omit.From(commsPhone0.E164),
}
err := commsTextLogs1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhoneDestinationTextLogs0: %w", err)
}
return commsTextLogs1, nil
}
func (commsPhone0 *CommsPhone) InsertDestinationTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLogSetter) error {
if len(related) == 0 {
return nil
}
var err error
commsTextLogs1, err := insertCommsPhoneDestinationTextLogs0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.DestinationTextLogs = append(commsPhone0.R.DestinationTextLogs, commsTextLogs1...)
for _, rel := range commsTextLogs1 {
rel.R.DestinationPhone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachDestinationTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLog) error {
if len(related) == 0 {
return nil
}
var err error
commsTextLogs1 := CommsTextLogSlice(related)
_, err = attachCommsPhoneDestinationTextLogs0(ctx, exec, len(related), commsTextLogs1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.DestinationTextLogs = append(commsPhone0.R.DestinationTextLogs, commsTextLogs1...)
for _, rel := range related {
rel.R.DestinationPhone = commsPhone0
}
return nil
}
func insertCommsPhoneSourceTextLogs0(ctx context.Context, exec bob.Executor, commsTextLogs1 []*CommsTextLogSetter, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) {
for i := range commsTextLogs1 {
commsTextLogs1[i].Source = omit.From(commsPhone0.E164)
}
ret, err := CommsTextLogs.Insert(bob.ToMods(commsTextLogs1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhoneSourceTextLogs0: %w", err)
}
return ret, nil
}
func attachCommsPhoneSourceTextLogs0(ctx context.Context, exec bob.Executor, count int, commsTextLogs1 CommsTextLogSlice, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) {
setter := &CommsTextLogSetter{
Source: omit.From(commsPhone0.E164),
}
err := commsTextLogs1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhoneSourceTextLogs0: %w", err)
}
return commsTextLogs1, nil
}
func (commsPhone0 *CommsPhone) InsertSourceTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLogSetter) error {
if len(related) == 0 {
return nil
}
var err error
commsTextLogs1, err := insertCommsPhoneSourceTextLogs0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.SourceTextLogs = append(commsPhone0.R.SourceTextLogs, commsTextLogs1...)
for _, rel := range commsTextLogs1 {
rel.R.SourcePhone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachSourceTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLog) error {
if len(related) == 0 {
return nil
}
var err error
commsTextLogs1 := CommsTextLogSlice(related)
_, err = attachCommsPhoneSourceTextLogs0(ctx, exec, len(related), commsTextLogs1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.SourceTextLogs = append(commsPhone0.R.SourceTextLogs, commsTextLogs1...)
for _, rel := range related {
rel.R.SourcePhone = commsPhone0
}
return nil
}
func attachCommsPhoneOrganizations0(ctx context.Context, exec bob.Executor, count int, commsPhone0 *CommsPhone, organizations2 OrganizationSlice) (DistrictSubscriptionPhoneSlice, error) {
setters := make([]*DistrictSubscriptionPhoneSetter, count)
for i := range count {
setters[i] = &DistrictSubscriptionPhoneSetter{
PhoneE164: omit.From(commsPhone0.E164),
OrganizationID: omit.From(organizations2[i].ID),
}
}
districtSubscriptionPhones1, err := DistrictSubscriptionPhones.Insert(bob.ToMods(setters...)).All(ctx, exec)
if err != nil {
return nil, fmt.Errorf("attachCommsPhoneOrganizations0: %w", err)
}
return districtSubscriptionPhones1, nil
}
func (commsPhone0 *CommsPhone) InsertOrganizations(ctx context.Context, exec bob.Executor, related ...*OrganizationSetter) error {
if len(related) == 0 {
return nil
}
var err error
inserted, err := Organizations.Insert(bob.ToMods(related...)).All(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
organizations2 := OrganizationSlice(inserted)
_, err = attachCommsPhoneOrganizations0(ctx, exec, len(related), commsPhone0, organizations2)
if err != nil {
return err
}
commsPhone0.R.Organizations = append(commsPhone0.R.Organizations, organizations2...)
for _, rel := range organizations2 {
rel.R.Phones = append(rel.R.Phones, commsPhone0)
}
return nil
}
func (commsPhone0 *CommsPhone) AttachOrganizations(ctx context.Context, exec bob.Executor, related ...*Organization) error {
if len(related) == 0 {
return nil
}
var err error
organizations2 := OrganizationSlice(related)
_, err = attachCommsPhoneOrganizations0(ctx, exec, len(related), commsPhone0, organizations2)
if err != nil {
return err
}
commsPhone0.R.Organizations = append(commsPhone0.R.Organizations, organizations2...)
for _, rel := range related {
rel.R.Phones = append(rel.R.Phones, commsPhone0)
}
return nil
}
func insertCommsPhonePhoneE164NotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneNuisances1 []*PublicreportNotifyPhoneNuisanceSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceSlice, error) {
for i := range publicreportNotifyPhoneNuisances1 {
publicreportNotifyPhoneNuisances1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhoneNuisances.Insert(bob.ToMods(publicreportNotifyPhoneNuisances1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneNuisances0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisances1 PublicreportNotifyPhoneNuisanceSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceSlice, error) {
setter := &PublicreportNotifyPhoneNuisanceSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhoneNuisances1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneNuisances0: %w", err)
}
return publicreportNotifyPhoneNuisances1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneNuisances1, err := insertCommsPhonePhoneE164NotifyPhoneNuisances0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneNuisances = append(commsPhone0.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...)
for _, rel := range publicreportNotifyPhoneNuisances1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisance) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneNuisances1 := PublicreportNotifyPhoneNuisanceSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhoneNuisances0(ctx, exec, len(related), publicreportNotifyPhoneNuisances1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneNuisances = append(commsPhone0.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func insertCommsPhonePhoneE164NotifyPhonePools0(ctx context.Context, exec bob.Executor, publicreportNotifyPhonePools1 []*PublicreportNotifyPhonePoolSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhonePoolSlice, error) {
for i := range publicreportNotifyPhonePools1 {
publicreportNotifyPhonePools1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhonePools.Insert(bob.ToMods(publicreportNotifyPhonePools1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhonePools0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhonePools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePools1 PublicreportNotifyPhonePoolSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhonePoolSlice, error) {
setter := &PublicreportNotifyPhonePoolSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhonePools1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhonePools0: %w", err)
}
return publicreportNotifyPhonePools1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePoolSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhonePools1, err := insertCommsPhonePhoneE164NotifyPhonePools0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhonePools = append(commsPhone0.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePools1...)
for _, rel := range publicreportNotifyPhonePools1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePool) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhonePools1 := PublicreportNotifyPhonePoolSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhonePools0(ctx, exec, len(related), publicreportNotifyPhonePools1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhonePools = append(commsPhone0.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePools1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func insertCommsPhonePhoneE164SubscribePhones0(ctx context.Context, exec bob.Executor, publicreportSubscribePhones1 []*PublicreportSubscribePhoneSetter, commsPhone0 *CommsPhone) (PublicreportSubscribePhoneSlice, error) {
for i := range publicreportSubscribePhones1 {
publicreportSubscribePhones1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportSubscribePhones.Insert(bob.ToMods(publicreportSubscribePhones1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164SubscribePhones0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164SubscribePhones0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribePhones1 PublicreportSubscribePhoneSlice, commsPhone0 *CommsPhone) (PublicreportSubscribePhoneSlice, error) {
setter := &PublicreportSubscribePhoneSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportSubscribePhones1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164SubscribePhones0: %w", err)
}
return publicreportSubscribePhones1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribePhoneSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportSubscribePhones1, err := insertCommsPhonePhoneE164SubscribePhones0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164SubscribePhones = append(commsPhone0.R.PhoneE164SubscribePhones, publicreportSubscribePhones1...)
for _, rel := range publicreportSubscribePhones1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribePhone) error {
if len(related) == 0 {
return nil
}
var err error
publicreportSubscribePhones1 := PublicreportSubscribePhoneSlice(related)
_, err = attachCommsPhonePhoneE164SubscribePhones0(ctx, exec, len(related), publicreportSubscribePhones1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164SubscribePhones = append(commsPhone0.R.PhoneE164SubscribePhones, publicreportSubscribePhones1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
type commsPhoneWhere[Q psql.Filterable] struct {
E164 psql.WhereMod[Q, string]
IsSubscribed psql.WhereMod[Q, bool]
Status psql.WhereMod[Q, enums.CommsPhonestatustype]
}
func (commsPhoneWhere[Q]) AliasedAs(alias string) commsPhoneWhere[Q] {
return buildCommsPhoneWhere[Q](buildCommsPhoneColumns(alias))
}
func buildCommsPhoneWhere[Q psql.Filterable](cols commsPhoneColumns) commsPhoneWhere[Q] {
return commsPhoneWhere[Q]{
E164: psql.Where[Q, string](cols.E164),
IsSubscribed: psql.Where[Q, bool](cols.IsSubscribed),
Status: psql.Where[Q, enums.CommsPhonestatustype](cols.Status),
}
}
func (o *CommsPhone) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "DestinationTextJobs":
rels, ok := retrieved.(CommsTextJobSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.DestinationTextJobs = rels
for _, rel := range rels {
if rel != nil {
rel.R.DestinationPhone = o
}
}
return nil
case "DestinationTextLogs":
rels, ok := retrieved.(CommsTextLogSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.DestinationTextLogs = rels
for _, rel := range rels {
if rel != nil {
rel.R.DestinationPhone = o
}
}
return nil
case "SourceTextLogs":
rels, ok := retrieved.(CommsTextLogSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.SourceTextLogs = rels
for _, rel := range rels {
if rel != nil {
rel.R.SourcePhone = o
}
}
return nil
case "Organizations":
rels, ok := retrieved.(OrganizationSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.Organizations = rels
for _, rel := range rels {
if rel != nil {
rel.R.Phones = CommsPhoneSlice{o}
}
}
return nil
case "PhoneE164NotifyPhoneNuisances":
rels, ok := retrieved.(PublicreportNotifyPhoneNuisanceSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhoneNuisances = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneE164Phone = o
}
}
return nil
case "PhoneE164NotifyPhonePools":
rels, ok := retrieved.(PublicreportNotifyPhonePoolSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhonePools = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneE164Phone = o
}
}
return nil
case "PhoneE164SubscribePhones":
rels, ok := retrieved.(PublicreportSubscribePhoneSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164SubscribePhones = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneE164Phone = o
}
}
return nil
default:
return fmt.Errorf("commsPhone has no relationship %q", name)
}
}
type commsPhonePreloader struct{}
func buildCommsPhonePreloader() commsPhonePreloader {
return commsPhonePreloader{}
}
type commsPhoneThenLoader[Q orm.Loadable] struct {
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
type DestinationTextJobsLoadInterface interface {
LoadDestinationTextJobs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type DestinationTextLogsLoadInterface interface {
LoadDestinationTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SourceTextLogsLoadInterface interface {
LoadSourceTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type OrganizationsLoadInterface interface {
LoadOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneNuisancesLoadInterface interface {
LoadPhoneE164NotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhonePoolsLoadInterface interface {
LoadPhoneE164NotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164SubscribePhonesLoadInterface interface {
LoadPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsPhoneThenLoader[Q]{
DestinationTextJobs: thenLoadBuilder[Q](
"DestinationTextJobs",
func(ctx context.Context, exec bob.Executor, retrieved DestinationTextJobsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadDestinationTextJobs(ctx, exec, mods...)
},
),
DestinationTextLogs: thenLoadBuilder[Q](
"DestinationTextLogs",
func(ctx context.Context, exec bob.Executor, retrieved DestinationTextLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadDestinationTextLogs(ctx, exec, mods...)
},
),
SourceTextLogs: thenLoadBuilder[Q](
"SourceTextLogs",
func(ctx context.Context, exec bob.Executor, retrieved SourceTextLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadSourceTextLogs(ctx, exec, mods...)
},
),
Organizations: thenLoadBuilder[Q](
"Organizations",
func(ctx context.Context, exec bob.Executor, retrieved OrganizationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadOrganizations(ctx, exec, mods...)
},
),
PhoneE164NotifyPhoneNuisances: thenLoadBuilder[Q](
"PhoneE164NotifyPhoneNuisances",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhoneNuisances(ctx, exec, mods...)
},
),
PhoneE164NotifyPhonePools: thenLoadBuilder[Q](
"PhoneE164NotifyPhonePools",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhonePoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhonePools(ctx, exec, mods...)
},
),
PhoneE164SubscribePhones: thenLoadBuilder[Q](
"PhoneE164SubscribePhones",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164SubscribePhonesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164SubscribePhones(ctx, exec, mods...)
},
),
}
}
// LoadDestinationTextJobs loads the commsPhone's DestinationTextJobs into the .R struct
func (o *CommsPhone) LoadDestinationTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.DestinationTextJobs = nil
related, err := o.DestinationTextJobs(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.DestinationPhone = o
}
o.R.DestinationTextJobs = related
return nil
}
// LoadDestinationTextJobs loads the commsPhone's DestinationTextJobs into the .R struct
func (os CommsPhoneSlice) LoadDestinationTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsTextJobs, err := os.DestinationTextJobs(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.DestinationTextJobs = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsTextJobs {
if !(o.E164 == rel.Destination) {
continue
}
rel.R.DestinationPhone = o
o.R.DestinationTextJobs = append(o.R.DestinationTextJobs, rel)
}
}
return nil
}
// LoadDestinationTextLogs loads the commsPhone's DestinationTextLogs into the .R struct
func (o *CommsPhone) LoadDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.DestinationTextLogs = nil
related, err := o.DestinationTextLogs(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.DestinationPhone = o
}
o.R.DestinationTextLogs = related
return nil
}
// LoadDestinationTextLogs loads the commsPhone's DestinationTextLogs into the .R struct
func (os CommsPhoneSlice) LoadDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsTextLogs, err := os.DestinationTextLogs(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.DestinationTextLogs = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsTextLogs {
if !(o.E164 == rel.Destination) {
continue
}
rel.R.DestinationPhone = o
o.R.DestinationTextLogs = append(o.R.DestinationTextLogs, rel)
}
}
return nil
}
// LoadSourceTextLogs loads the commsPhone's SourceTextLogs into the .R struct
func (o *CommsPhone) LoadSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.SourceTextLogs = nil
related, err := o.SourceTextLogs(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.SourcePhone = o
}
o.R.SourceTextLogs = related
return nil
}
// LoadSourceTextLogs loads the commsPhone's SourceTextLogs into the .R struct
func (os CommsPhoneSlice) LoadSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsTextLogs, err := os.SourceTextLogs(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.SourceTextLogs = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsTextLogs {
if !(o.E164 == rel.Source) {
continue
}
rel.R.SourcePhone = o
o.R.SourceTextLogs = append(o.R.SourceTextLogs, rel)
}
}
return nil
}
// LoadOrganizations loads the commsPhone's Organizations into the .R struct
func (o *CommsPhone) LoadOrganizations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Organizations = nil
related, err := o.Organizations(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Phones = CommsPhoneSlice{o}
}
o.R.Organizations = related
return nil
}
// LoadOrganizations loads the commsPhone's Organizations into the .R struct
func (os CommsPhoneSlice) LoadOrganizations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
// since we are changing the columns, we need to check if the original columns were set or add the defaults
sq := dialect.SelectQuery{}
for _, mod := range mods {
mod.Apply(&sq)
}
if len(sq.SelectList.Columns) == 0 {
mods = append(mods, sm.Columns(Organizations.Columns))
}
q := os.Organizations(append(
mods,
sm.Columns(DistrictSubscriptionPhones.Columns.PhoneE164.As("related_comms.phone.E164")),
)...)
E164Slice := []string{}
mapper := scan.Mod(scan.StructMapper[*Organization](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
return func(row *scan.Row) (any, error) {
E164Slice = append(E164Slice, *new(string))
row.ScheduleScanByName("related_comms.phone.E164", &E164Slice[len(E164Slice)-1])
return nil, nil
},
func(any, any) error {
return nil
}
})
organizations, err := bob.Allx[bob.SliceTransformer[*Organization, OrganizationSlice]](ctx, exec, q, mapper)
if err != nil {
return err
}
for _, o := range os {
o.R.Organizations = nil
}
for _, o := range os {
for i, rel := range organizations {
if !(o.E164 == E164Slice[i]) {
continue
}
rel.R.Phones = append(rel.R.Phones, o)
o.R.Organizations = append(o.R.Organizations, rel)
}
}
return nil
}
// LoadPhoneE164NotifyPhoneNuisances loads the commsPhone's PhoneE164NotifyPhoneNuisances into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhoneNuisances = nil
related, err := o.PhoneE164NotifyPhoneNuisances(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhoneNuisances = related
return nil
}
// LoadPhoneE164NotifyPhoneNuisances loads the commsPhone's PhoneE164NotifyPhoneNuisances into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhoneNuisances, err := os.PhoneE164NotifyPhoneNuisances(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneE164NotifyPhoneNuisances = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyPhoneNuisances {
if !(o.E164 == rel.PhoneE164) {
continue
}
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhoneNuisances = append(o.R.PhoneE164NotifyPhoneNuisances, rel)
}
}
return nil
}
// LoadPhoneE164NotifyPhonePools loads the commsPhone's PhoneE164NotifyPhonePools into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhonePools = nil
related, err := o.PhoneE164NotifyPhonePools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhonePools = related
return nil
}
// LoadPhoneE164NotifyPhonePools loads the commsPhone's PhoneE164NotifyPhonePools into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhonePools, err := os.PhoneE164NotifyPhonePools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneE164NotifyPhonePools = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyPhonePools {
if !(o.E164 == rel.PhoneE164) {
continue
}
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhonePools = append(o.R.PhoneE164NotifyPhonePools, rel)
}
}
return nil
}
// LoadPhoneE164SubscribePhones loads the commsPhone's PhoneE164SubscribePhones into the .R struct
func (o *CommsPhone) LoadPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164SubscribePhones = nil
related, err := o.PhoneE164SubscribePhones(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164SubscribePhones = related
return nil
}
// LoadPhoneE164SubscribePhones loads the commsPhone's PhoneE164SubscribePhones into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportSubscribePhones, err := os.PhoneE164SubscribePhones(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneE164SubscribePhones = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportSubscribePhones {
if !(o.E164 == rel.PhoneE164) {
continue
}
rel.R.PhoneE164Phone = o
o.R.PhoneE164SubscribePhones = append(o.R.PhoneE164SubscribePhones, rel)
}
}
return nil
}
// commsPhoneC is where relationship counts are stored.
type commsPhoneC struct {
DestinationTextJobs *int64
DestinationTextLogs *int64
SourceTextLogs *int64
Organizations *int64
PhoneE164NotifyPhoneNuisances *int64
PhoneE164NotifyPhonePools *int64
PhoneE164SubscribePhones *int64
}
// PreloadCount sets a count in the C struct by name
func (o *CommsPhone) PreloadCount(name string, count int64) error {
if o == nil {
return nil
}
switch name {
case "DestinationTextJobs":
o.C.DestinationTextJobs = &count
case "DestinationTextLogs":
o.C.DestinationTextLogs = &count
case "SourceTextLogs":
o.C.SourceTextLogs = &count
case "Organizations":
o.C.Organizations = &count
case "PhoneE164NotifyPhoneNuisances":
o.C.PhoneE164NotifyPhoneNuisances = &count
case "PhoneE164NotifyPhonePools":
o.C.PhoneE164NotifyPhonePools = &count
case "PhoneE164SubscribePhones":
o.C.PhoneE164SubscribePhones = &count
}
return nil
}
type commsPhoneCountPreloader struct {
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
Organizations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
return commsPhoneCountPreloader{
DestinationTextJobs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("DestinationTextJobs", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(CommsTextJobs.Name()),
sm.Where(psql.Quote(CommsTextJobs.Alias(), "destination").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
DestinationTextLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("DestinationTextLogs", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(CommsTextLogs.Name()),
sm.Where(psql.Quote(CommsTextLogs.Alias(), "destination").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
SourceTextLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("SourceTextLogs", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(CommsTextLogs.Name()),
sm.Where(psql.Quote(CommsTextLogs.Alias(), "source").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
Organizations: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("Organizations", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(DistrictSubscriptionPhones.Name()),
sm.Where(psql.Quote(DistrictSubscriptionPhones.Alias(), "phone_e164").EQ(psql.Quote(parent, "e164"))),
sm.InnerJoin(Organizations.Name()).On(
psql.Quote(Organizations.Alias(), "id").EQ(psql.Quote(DistrictSubscriptionPhones.Alias(), "organization_id")),
),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
PhoneE164NotifyPhoneNuisances: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("PhoneE164NotifyPhoneNuisances", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyPhoneNuisances.Name()),
sm.Where(psql.Quote(PublicreportNotifyPhoneNuisances.Alias(), "phone_e164").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
PhoneE164NotifyPhonePools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("PhoneE164NotifyPhonePools", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyPhonePools.Name()),
sm.Where(psql.Quote(PublicreportNotifyPhonePools.Alias(), "phone_e164").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
PhoneE164SubscribePhones: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("PhoneE164SubscribePhones", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportSubscribePhones.Name()),
sm.Where(psql.Quote(PublicreportSubscribePhones.Alias(), "phone_e164").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
}
}
type commsPhoneCountThenLoader[Q orm.Loadable] struct {
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[Q] {
type DestinationTextJobsCountInterface interface {
LoadCountDestinationTextJobs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type DestinationTextLogsCountInterface interface {
LoadCountDestinationTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type SourceTextLogsCountInterface interface {
LoadCountSourceTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type OrganizationsCountInterface interface {
LoadCountOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneNuisancesCountInterface interface {
LoadCountPhoneE164NotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhonePoolsCountInterface interface {
LoadCountPhoneE164NotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164SubscribePhonesCountInterface interface {
LoadCountPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsPhoneCountThenLoader[Q]{
DestinationTextJobs: countThenLoadBuilder[Q](
"DestinationTextJobs",
func(ctx context.Context, exec bob.Executor, retrieved DestinationTextJobsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountDestinationTextJobs(ctx, exec, mods...)
},
),
DestinationTextLogs: countThenLoadBuilder[Q](
"DestinationTextLogs",
func(ctx context.Context, exec bob.Executor, retrieved DestinationTextLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountDestinationTextLogs(ctx, exec, mods...)
},
),
SourceTextLogs: countThenLoadBuilder[Q](
"SourceTextLogs",
func(ctx context.Context, exec bob.Executor, retrieved SourceTextLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountSourceTextLogs(ctx, exec, mods...)
},
),
Organizations: countThenLoadBuilder[Q](
"Organizations",
func(ctx context.Context, exec bob.Executor, retrieved OrganizationsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountOrganizations(ctx, exec, mods...)
},
),
PhoneE164NotifyPhoneNuisances: countThenLoadBuilder[Q](
"PhoneE164NotifyPhoneNuisances",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneNuisancesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountPhoneE164NotifyPhoneNuisances(ctx, exec, mods...)
},
),
PhoneE164NotifyPhonePools: countThenLoadBuilder[Q](
"PhoneE164NotifyPhonePools",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhonePoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountPhoneE164NotifyPhonePools(ctx, exec, mods...)
},
),
PhoneE164SubscribePhones: countThenLoadBuilder[Q](
"PhoneE164SubscribePhones",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164SubscribePhonesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountPhoneE164SubscribePhones(ctx, exec, mods...)
},
),
}
}
// LoadCountDestinationTextJobs loads the count of DestinationTextJobs into the C struct
func (o *CommsPhone) LoadCountDestinationTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.DestinationTextJobs(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.DestinationTextJobs = &count
return nil
}
// LoadCountDestinationTextJobs loads the count of DestinationTextJobs for a slice
func (os CommsPhoneSlice) LoadCountDestinationTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountDestinationTextJobs(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountDestinationTextLogs loads the count of DestinationTextLogs into the C struct
func (o *CommsPhone) LoadCountDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.DestinationTextLogs(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.DestinationTextLogs = &count
return nil
}
// LoadCountDestinationTextLogs loads the count of DestinationTextLogs for a slice
func (os CommsPhoneSlice) LoadCountDestinationTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountDestinationTextLogs(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountSourceTextLogs loads the count of SourceTextLogs into the C struct
func (o *CommsPhone) LoadCountSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.SourceTextLogs(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.SourceTextLogs = &count
return nil
}
// LoadCountSourceTextLogs loads the count of SourceTextLogs for a slice
func (os CommsPhoneSlice) LoadCountSourceTextLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountSourceTextLogs(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountOrganizations loads the count of Organizations into the C struct
func (o *CommsPhone) LoadCountOrganizations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.Organizations(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.Organizations = &count
return nil
}
// LoadCountOrganizations loads the count of Organizations for a slice
func (os CommsPhoneSlice) LoadCountOrganizations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountOrganizations(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountPhoneE164NotifyPhoneNuisances loads the count of PhoneE164NotifyPhoneNuisances into the C struct
func (o *CommsPhone) LoadCountPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.PhoneE164NotifyPhoneNuisances(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.PhoneE164NotifyPhoneNuisances = &count
return nil
}
// LoadCountPhoneE164NotifyPhoneNuisances loads the count of PhoneE164NotifyPhoneNuisances for a slice
func (os CommsPhoneSlice) LoadCountPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountPhoneE164NotifyPhoneNuisances(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountPhoneE164NotifyPhonePools loads the count of PhoneE164NotifyPhonePools into the C struct
func (o *CommsPhone) LoadCountPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.PhoneE164NotifyPhonePools(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.PhoneE164NotifyPhonePools = &count
return nil
}
// LoadCountPhoneE164NotifyPhonePools loads the count of PhoneE164NotifyPhonePools for a slice
func (os CommsPhoneSlice) LoadCountPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountPhoneE164NotifyPhonePools(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountPhoneE164SubscribePhones loads the count of PhoneE164SubscribePhones into the C struct
func (o *CommsPhone) LoadCountPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.PhoneE164SubscribePhones(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.PhoneE164SubscribePhones = &count
return nil
}
// LoadCountPhoneE164SubscribePhones loads the count of PhoneE164SubscribePhones for a slice
func (os CommsPhoneSlice) LoadCountPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountPhoneE164SubscribePhones(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
type commsPhoneJoins[Q dialect.Joinable] struct {
typ string
DestinationTextJobs modAs[Q, commsTextJobColumns]
DestinationTextLogs modAs[Q, commsTextLogColumns]
SourceTextLogs modAs[Q, commsTextLogColumns]
Organizations modAs[Q, organizationColumns]
PhoneE164NotifyPhoneNuisances modAs[Q, publicreportNotifyPhoneNuisanceColumns]
PhoneE164NotifyPhonePools modAs[Q, publicreportNotifyPhonePoolColumns]
PhoneE164SubscribePhones modAs[Q, publicreportSubscribePhoneColumns]
}
func (j commsPhoneJoins[Q]) aliasedAs(alias string) commsPhoneJoins[Q] {
return buildCommsPhoneJoins[Q](buildCommsPhoneColumns(alias), j.typ)
}
func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string) commsPhoneJoins[Q] {
return commsPhoneJoins[Q]{
typ: typ,
DestinationTextJobs: modAs[Q, commsTextJobColumns]{
c: CommsTextJobs.Columns,
f: func(to commsTextJobColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsTextJobs.Name().As(to.Alias())).On(
to.Destination.EQ(cols.E164),
))
}
return mods
},
},
DestinationTextLogs: modAs[Q, commsTextLogColumns]{
c: CommsTextLogs.Columns,
f: func(to commsTextLogColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsTextLogs.Name().As(to.Alias())).On(
to.Destination.EQ(cols.E164),
))
}
return mods
},
},
SourceTextLogs: modAs[Q, commsTextLogColumns]{
c: CommsTextLogs.Columns,
f: func(to commsTextLogColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsTextLogs.Name().As(to.Alias())).On(
to.Source.EQ(cols.E164),
))
}
return mods
},
},
Organizations: modAs[Q, organizationColumns]{
c: Organizations.Columns,
f: func(to organizationColumns) bob.Mod[Q] {
random := strconv.FormatInt(randInt(), 10)
mods := make(mods.QueryMods[Q], 0, 2)
{
to := DistrictSubscriptionPhones.Columns.AliasedAs(DistrictSubscriptionPhones.Columns.Alias() + random)
mods = append(mods, dialect.Join[Q](typ, DistrictSubscriptionPhones.Name().As(to.Alias())).On(
to.PhoneE164.EQ(cols.E164),
))
}
{
cols := DistrictSubscriptionPhones.Columns.AliasedAs(DistrictSubscriptionPhones.Columns.Alias() + random)
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
to.ID.EQ(cols.OrganizationID),
))
}
return mods
},
},
PhoneE164NotifyPhoneNuisances: modAs[Q, publicreportNotifyPhoneNuisanceColumns]{
c: PublicreportNotifyPhoneNuisances.Columns,
f: func(to publicreportNotifyPhoneNuisanceColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyPhoneNuisances.Name().As(to.Alias())).On(
to.PhoneE164.EQ(cols.E164),
))
}
return mods
},
},
PhoneE164NotifyPhonePools: modAs[Q, publicreportNotifyPhonePoolColumns]{
c: PublicreportNotifyPhonePools.Columns,
f: func(to publicreportNotifyPhonePoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyPhonePools.Name().As(to.Alias())).On(
to.PhoneE164.EQ(cols.E164),
))
}
return mods
},
},
PhoneE164SubscribePhones: modAs[Q, publicreportSubscribePhoneColumns]{
c: PublicreportSubscribePhones.Columns,
f: func(to publicreportSubscribePhoneColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportSubscribePhones.Name().As(to.Alias())).On(
to.PhoneE164.EQ(cols.E164),
))
}
return mods
},
},
}
}