Overhaul system for handling text messaging
Move away from "SMS" as the operative word - we're going RCS. Move all comms processing to a separate goroutine Rename the DB tables
This commit is contained in:
parent
842e6cff43
commit
f4a88623af
35 changed files with 1426 additions and 1212 deletions
|
|
@ -37,7 +37,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
CommsEmails joinSet[commsEmailJoins[Q]]
|
||||
CommsEmailLogs joinSet[commsEmailLogJoins[Q]]
|
||||
CommsPhones joinSet[commsPhoneJoins[Q]]
|
||||
CommsSMSLogs joinSet[commsSMSLogJoins[Q]]
|
||||
CommsTextLogs joinSet[commsTextLogJoins[Q]]
|
||||
FieldseekerContainerrelates joinSet[fieldseekerContainerrelateJoins[Q]]
|
||||
FieldseekerFieldscoutinglogs joinSet[fieldseekerFieldscoutinglogJoins[Q]]
|
||||
FieldseekerHabitatrelates joinSet[fieldseekerHabitatrelateJoins[Q]]
|
||||
|
|
@ -101,7 +101,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
CommsEmails: buildJoinSet[commsEmailJoins[Q]](CommsEmails.Columns, buildCommsEmailJoins),
|
||||
CommsEmailLogs: buildJoinSet[commsEmailLogJoins[Q]](CommsEmailLogs.Columns, buildCommsEmailLogJoins),
|
||||
CommsPhones: buildJoinSet[commsPhoneJoins[Q]](CommsPhones.Columns, buildCommsPhoneJoins),
|
||||
CommsSMSLogs: buildJoinSet[commsSMSLogJoins[Q]](CommsSMSLogs.Columns, buildCommsSMSLogJoins),
|
||||
CommsTextLogs: buildJoinSet[commsTextLogJoins[Q]](CommsTextLogs.Columns, buildCommsTextLogJoins),
|
||||
FieldseekerContainerrelates: buildJoinSet[fieldseekerContainerrelateJoins[Q]](FieldseekerContainerrelates.Columns, buildFieldseekerContainerrelateJoins),
|
||||
FieldseekerFieldscoutinglogs: buildJoinSet[fieldseekerFieldscoutinglogJoins[Q]](FieldseekerFieldscoutinglogs.Columns, buildFieldseekerFieldscoutinglogJoins),
|
||||
FieldseekerHabitatrelates: buildJoinSet[fieldseekerHabitatrelateJoins[Q]](FieldseekerHabitatrelates.Columns, buildFieldseekerHabitatrelateJoins),
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ type preloaders struct {
|
|||
CommsEmail commsEmailPreloader
|
||||
CommsEmailLog commsEmailLogPreloader
|
||||
CommsPhone commsPhonePreloader
|
||||
CommsSMSLog commsSMSLogPreloader
|
||||
CommsTextLog commsTextLogPreloader
|
||||
FieldseekerContainerrelate fieldseekerContainerrelatePreloader
|
||||
FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogPreloader
|
||||
FieldseekerHabitatrelate fieldseekerHabitatrelatePreloader
|
||||
|
|
@ -78,7 +78,7 @@ func getPreloaders() preloaders {
|
|||
CommsEmail: buildCommsEmailPreloader(),
|
||||
CommsEmailLog: buildCommsEmailLogPreloader(),
|
||||
CommsPhone: buildCommsPhonePreloader(),
|
||||
CommsSMSLog: buildCommsSMSLogPreloader(),
|
||||
CommsTextLog: buildCommsTextLogPreloader(),
|
||||
FieldseekerContainerrelate: buildFieldseekerContainerrelatePreloader(),
|
||||
FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogPreloader(),
|
||||
FieldseekerHabitatrelate: buildFieldseekerHabitatrelatePreloader(),
|
||||
|
|
@ -140,7 +140,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
CommsEmail commsEmailThenLoader[Q]
|
||||
CommsEmailLog commsEmailLogThenLoader[Q]
|
||||
CommsPhone commsPhoneThenLoader[Q]
|
||||
CommsSMSLog commsSMSLogThenLoader[Q]
|
||||
CommsTextLog commsTextLogThenLoader[Q]
|
||||
FieldseekerContainerrelate fieldseekerContainerrelateThenLoader[Q]
|
||||
FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogThenLoader[Q]
|
||||
FieldseekerHabitatrelate fieldseekerHabitatrelateThenLoader[Q]
|
||||
|
|
@ -196,7 +196,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
CommsEmail: buildCommsEmailThenLoader[Q](),
|
||||
CommsEmailLog: buildCommsEmailLogThenLoader[Q](),
|
||||
CommsPhone: buildCommsPhoneThenLoader[Q](),
|
||||
CommsSMSLog: buildCommsSMSLogThenLoader[Q](),
|
||||
CommsTextLog: buildCommsTextLogThenLoader[Q](),
|
||||
FieldseekerContainerrelate: buildFieldseekerContainerrelateThenLoader[Q](),
|
||||
FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogThenLoader[Q](),
|
||||
FieldseekerHabitatrelate: buildFieldseekerHabitatrelateThenLoader[Q](),
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
CommsEmails commsEmailWhere[Q]
|
||||
CommsEmailLogs commsEmailLogWhere[Q]
|
||||
CommsPhones commsPhoneWhere[Q]
|
||||
CommsSMSLogs commsSMSLogWhere[Q]
|
||||
CommsTextLogs commsTextLogWhere[Q]
|
||||
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
|
||||
FieldseekerFieldscoutinglogs fieldseekerFieldscoutinglogWhere[Q]
|
||||
FieldseekerHabitatrelates fieldseekerHabitatrelateWhere[Q]
|
||||
|
|
@ -85,7 +85,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
CommsEmails commsEmailWhere[Q]
|
||||
CommsEmailLogs commsEmailLogWhere[Q]
|
||||
CommsPhones commsPhoneWhere[Q]
|
||||
CommsSMSLogs commsSMSLogWhere[Q]
|
||||
CommsTextLogs commsTextLogWhere[Q]
|
||||
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
|
||||
FieldseekerFieldscoutinglogs fieldseekerFieldscoutinglogWhere[Q]
|
||||
FieldseekerHabitatrelates fieldseekerHabitatrelateWhere[Q]
|
||||
|
|
@ -147,7 +147,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
CommsEmails: buildCommsEmailWhere[Q](CommsEmails.Columns),
|
||||
CommsEmailLogs: buildCommsEmailLogWhere[Q](CommsEmailLogs.Columns),
|
||||
CommsPhones: buildCommsPhoneWhere[Q](CommsPhones.Columns),
|
||||
CommsSMSLogs: buildCommsSMSLogWhere[Q](CommsSMSLogs.Columns),
|
||||
CommsTextLogs: buildCommsTextLogWhere[Q](CommsTextLogs.Columns),
|
||||
FieldseekerContainerrelates: buildFieldseekerContainerrelateWhere[Q](FieldseekerContainerrelates.Columns),
|
||||
FieldseekerFieldscoutinglogs: buildFieldseekerFieldscoutinglogWhere[Q](FieldseekerFieldscoutinglogs.Columns),
|
||||
FieldseekerHabitatrelates: buildFieldseekerHabitatrelateWhere[Q](FieldseekerHabitatrelates.Columns),
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ type CommsEmailLog struct {
|
|||
Created time.Time `db:"created" `
|
||||
Destination string `db:"destination,pk" `
|
||||
Source string `db:"source,pk" `
|
||||
Type enums.CommsEmailmessagetype `db:"type,pk" `
|
||||
Type enums.CommsMessagetypeemail `db:"type,pk" `
|
||||
|
||||
R commsEmailLogR `db:"-" `
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ type CommsEmailLogSetter struct {
|
|||
Created omit.Val[time.Time] `db:"created" `
|
||||
Destination omit.Val[string] `db:"destination,pk" `
|
||||
Source omit.Val[string] `db:"source,pk" `
|
||||
Type omit.Val[enums.CommsEmailmessagetype] `db:"type,pk" `
|
||||
Type omit.Val[enums.CommsMessagetypeemail] `db:"type,pk" `
|
||||
}
|
||||
|
||||
func (s CommsEmailLogSetter) SetColumns() []string {
|
||||
|
|
@ -196,7 +196,7 @@ func (s CommsEmailLogSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
|
||||
// FindCommsEmailLog retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindCommsEmailLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsEmailmessagetype, cols ...string) (*CommsEmailLog, error) {
|
||||
func FindCommsEmailLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypeemail, cols ...string) (*CommsEmailLog, error) {
|
||||
if len(cols) == 0 {
|
||||
return CommsEmailLogs.Query(
|
||||
sm.Where(CommsEmailLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
|
|
@ -214,7 +214,7 @@ func FindCommsEmailLog(ctx context.Context, exec bob.Executor, DestinationPK str
|
|||
}
|
||||
|
||||
// CommsEmailLogExists checks the presence of a single record by primary key
|
||||
func CommsEmailLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsEmailmessagetype) (bool, error) {
|
||||
func CommsEmailLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypeemail) (bool, error) {
|
||||
return CommsEmailLogs.Query(
|
||||
sm.Where(CommsEmailLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsEmailLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
|
|
@ -583,7 +583,7 @@ type commsEmailLogWhere[Q psql.Filterable] struct {
|
|||
Created psql.WhereMod[Q, time.Time]
|
||||
Destination psql.WhereMod[Q, string]
|
||||
Source psql.WhereMod[Q, string]
|
||||
Type psql.WhereMod[Q, enums.CommsEmailmessagetype]
|
||||
Type psql.WhereMod[Q, enums.CommsMessagetypeemail]
|
||||
}
|
||||
|
||||
func (commsEmailLogWhere[Q]) AliasedAs(alias string) commsEmailLogWhere[Q] {
|
||||
|
|
@ -595,7 +595,7 @@ func buildCommsEmailLogWhere[Q psql.Filterable](cols commsEmailLogColumns) comms
|
|||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Destination: psql.Where[Q, string](cols.Destination),
|
||||
Source: psql.Where[Q, string](cols.Source),
|
||||
Type: psql.Where[Q, enums.CommsEmailmessagetype](cols.Type),
|
||||
Type: psql.Where[Q, enums.CommsMessagetypeemail](cols.Type),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ type CommsPhonesQuery = *psql.ViewQuery[*CommsPhone, CommsPhoneSlice]
|
|||
|
||||
// commsPhoneR is where relationships are stored.
|
||||
type commsPhoneR struct {
|
||||
SourceEmailLogs CommsEmailLogSlice // comms.email_log.email_log_source_fkey
|
||||
DestinationSMSLogs CommsSMSLogSlice // comms.sms_log.sms_log_destination_fkey
|
||||
SourceSMSLogs CommsSMSLogSlice // comms.sms_log.sms_log_source_fkey
|
||||
SourceEmailLogs CommsEmailLogSlice // comms.email_log.email_log_source_fkey
|
||||
DestinationTextLogs CommsTextLogSlice // comms.text_log.text_log_destination_fkey
|
||||
SourceTextLogs CommsTextLogSlice // comms.text_log.text_log_source_fkey
|
||||
}
|
||||
|
||||
func buildCommsPhoneColumns(alias string) commsPhoneColumns {
|
||||
|
|
@ -396,14 +396,14 @@ func (os CommsPhoneSlice) SourceEmailLogs(mods ...bob.Mod[*dialect.SelectQuery])
|
|||
)...)
|
||||
}
|
||||
|
||||
// DestinationSMSLogs starts a query for related objects on comms.sms_log
|
||||
func (o *CommsPhone) DestinationSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery {
|
||||
return CommsSMSLogs.Query(append(mods,
|
||||
sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(o.E164))),
|
||||
// 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) DestinationSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery {
|
||||
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 {
|
||||
|
|
@ -415,19 +415,19 @@ func (os CommsPhoneSlice) DestinationSMSLogs(mods ...bob.Mod[*dialect.SelectQuer
|
|||
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
|
||||
))
|
||||
|
||||
return CommsSMSLogs.Query(append(mods,
|
||||
sm.Where(psql.Group(CommsSMSLogs.Columns.Destination).OP("IN", PKArgExpr)),
|
||||
return CommsTextLogs.Query(append(mods,
|
||||
sm.Where(psql.Group(CommsTextLogs.Columns.Destination).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// SourceSMSLogs starts a query for related objects on comms.sms_log
|
||||
func (o *CommsPhone) SourceSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery {
|
||||
return CommsSMSLogs.Query(append(mods,
|
||||
sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(o.E164))),
|
||||
// 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) SourceSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) CommsSMSLogsQuery {
|
||||
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 {
|
||||
|
|
@ -439,8 +439,8 @@ func (os CommsPhoneSlice) SourceSMSLogs(mods ...bob.Mod[*dialect.SelectQuery]) C
|
|||
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
|
||||
))
|
||||
|
||||
return CommsSMSLogs.Query(append(mods,
|
||||
sm.Where(psql.Group(CommsSMSLogs.Columns.Source).OP("IN", PKArgExpr)),
|
||||
return CommsTextLogs.Query(append(mods,
|
||||
sm.Where(psql.Group(CommsTextLogs.Columns.Source).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -512,66 +512,66 @@ func (commsPhone0 *CommsPhone) AttachSourceEmailLogs(ctx context.Context, exec b
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertCommsPhoneDestinationSMSLogs0(ctx context.Context, exec bob.Executor, commsSMSLogs1 []*CommsSMSLogSetter, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) {
|
||||
for i := range commsSMSLogs1 {
|
||||
commsSMSLogs1[i].Destination = omit.From(commsPhone0.E164)
|
||||
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 := CommsSMSLogs.Insert(bob.ToMods(commsSMSLogs1...)).All(ctx, exec)
|
||||
ret, err := CommsTextLogs.Insert(bob.ToMods(commsTextLogs1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertCommsPhoneDestinationSMSLogs0: %w", err)
|
||||
return ret, fmt.Errorf("insertCommsPhoneDestinationTextLogs0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachCommsPhoneDestinationSMSLogs0(ctx context.Context, exec bob.Executor, count int, commsSMSLogs1 CommsSMSLogSlice, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) {
|
||||
setter := &CommsSMSLogSetter{
|
||||
func attachCommsPhoneDestinationTextLogs0(ctx context.Context, exec bob.Executor, count int, commsTextLogs1 CommsTextLogSlice, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) {
|
||||
setter := &CommsTextLogSetter{
|
||||
Destination: omit.From(commsPhone0.E164),
|
||||
}
|
||||
|
||||
err := commsSMSLogs1.UpdateAll(ctx, exec, *setter)
|
||||
err := commsTextLogs1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsPhoneDestinationSMSLogs0: %w", err)
|
||||
return nil, fmt.Errorf("attachCommsPhoneDestinationTextLogs0: %w", err)
|
||||
}
|
||||
|
||||
return commsSMSLogs1, nil
|
||||
return commsTextLogs1, nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) InsertDestinationSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLogSetter) error {
|
||||
func (commsPhone0 *CommsPhone) InsertDestinationTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLogSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
commsSMSLogs1, err := insertCommsPhoneDestinationSMSLogs0(ctx, exec, related, commsPhone0)
|
||||
commsTextLogs1, err := insertCommsPhoneDestinationTextLogs0(ctx, exec, related, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.DestinationSMSLogs = append(commsPhone0.R.DestinationSMSLogs, commsSMSLogs1...)
|
||||
commsPhone0.R.DestinationTextLogs = append(commsPhone0.R.DestinationTextLogs, commsTextLogs1...)
|
||||
|
||||
for _, rel := range commsSMSLogs1 {
|
||||
for _, rel := range commsTextLogs1 {
|
||||
rel.R.DestinationPhone = commsPhone0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) AttachDestinationSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLog) error {
|
||||
func (commsPhone0 *CommsPhone) AttachDestinationTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLog) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
commsSMSLogs1 := CommsSMSLogSlice(related)
|
||||
commsTextLogs1 := CommsTextLogSlice(related)
|
||||
|
||||
_, err = attachCommsPhoneDestinationSMSLogs0(ctx, exec, len(related), commsSMSLogs1, commsPhone0)
|
||||
_, err = attachCommsPhoneDestinationTextLogs0(ctx, exec, len(related), commsTextLogs1, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.DestinationSMSLogs = append(commsPhone0.R.DestinationSMSLogs, commsSMSLogs1...)
|
||||
commsPhone0.R.DestinationTextLogs = append(commsPhone0.R.DestinationTextLogs, commsTextLogs1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.DestinationPhone = commsPhone0
|
||||
|
|
@ -580,66 +580,66 @@ func (commsPhone0 *CommsPhone) AttachDestinationSMSLogs(ctx context.Context, exe
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertCommsPhoneSourceSMSLogs0(ctx context.Context, exec bob.Executor, commsSMSLogs1 []*CommsSMSLogSetter, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) {
|
||||
for i := range commsSMSLogs1 {
|
||||
commsSMSLogs1[i].Source = omit.From(commsPhone0.E164)
|
||||
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 := CommsSMSLogs.Insert(bob.ToMods(commsSMSLogs1...)).All(ctx, exec)
|
||||
ret, err := CommsTextLogs.Insert(bob.ToMods(commsTextLogs1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertCommsPhoneSourceSMSLogs0: %w", err)
|
||||
return ret, fmt.Errorf("insertCommsPhoneSourceTextLogs0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachCommsPhoneSourceSMSLogs0(ctx context.Context, exec bob.Executor, count int, commsSMSLogs1 CommsSMSLogSlice, commsPhone0 *CommsPhone) (CommsSMSLogSlice, error) {
|
||||
setter := &CommsSMSLogSetter{
|
||||
func attachCommsPhoneSourceTextLogs0(ctx context.Context, exec bob.Executor, count int, commsTextLogs1 CommsTextLogSlice, commsPhone0 *CommsPhone) (CommsTextLogSlice, error) {
|
||||
setter := &CommsTextLogSetter{
|
||||
Source: omit.From(commsPhone0.E164),
|
||||
}
|
||||
|
||||
err := commsSMSLogs1.UpdateAll(ctx, exec, *setter)
|
||||
err := commsTextLogs1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsPhoneSourceSMSLogs0: %w", err)
|
||||
return nil, fmt.Errorf("attachCommsPhoneSourceTextLogs0: %w", err)
|
||||
}
|
||||
|
||||
return commsSMSLogs1, nil
|
||||
return commsTextLogs1, nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) InsertSourceSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLogSetter) error {
|
||||
func (commsPhone0 *CommsPhone) InsertSourceTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLogSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
commsSMSLogs1, err := insertCommsPhoneSourceSMSLogs0(ctx, exec, related, commsPhone0)
|
||||
commsTextLogs1, err := insertCommsPhoneSourceTextLogs0(ctx, exec, related, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.SourceSMSLogs = append(commsPhone0.R.SourceSMSLogs, commsSMSLogs1...)
|
||||
commsPhone0.R.SourceTextLogs = append(commsPhone0.R.SourceTextLogs, commsTextLogs1...)
|
||||
|
||||
for _, rel := range commsSMSLogs1 {
|
||||
for _, rel := range commsTextLogs1 {
|
||||
rel.R.SourcePhone = commsPhone0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) AttachSourceSMSLogs(ctx context.Context, exec bob.Executor, related ...*CommsSMSLog) error {
|
||||
func (commsPhone0 *CommsPhone) AttachSourceTextLogs(ctx context.Context, exec bob.Executor, related ...*CommsTextLog) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
commsSMSLogs1 := CommsSMSLogSlice(related)
|
||||
commsTextLogs1 := CommsTextLogSlice(related)
|
||||
|
||||
_, err = attachCommsPhoneSourceSMSLogs0(ctx, exec, len(related), commsSMSLogs1, commsPhone0)
|
||||
_, err = attachCommsPhoneSourceTextLogs0(ctx, exec, len(related), commsTextLogs1, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.SourceSMSLogs = append(commsPhone0.R.SourceSMSLogs, commsSMSLogs1...)
|
||||
commsPhone0.R.SourceTextLogs = append(commsPhone0.R.SourceTextLogs, commsTextLogs1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.SourcePhone = commsPhone0
|
||||
|
|
@ -684,13 +684,13 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "DestinationSMSLogs":
|
||||
rels, ok := retrieved.(CommsSMSLogSlice)
|
||||
case "DestinationTextLogs":
|
||||
rels, ok := retrieved.(CommsTextLogSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.DestinationSMSLogs = rels
|
||||
o.R.DestinationTextLogs = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
|
|
@ -698,13 +698,13 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "SourceSMSLogs":
|
||||
rels, ok := retrieved.(CommsSMSLogSlice)
|
||||
case "SourceTextLogs":
|
||||
rels, ok := retrieved.(CommsTextLogSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.SourceSMSLogs = rels
|
||||
o.R.SourceTextLogs = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
|
|
@ -724,20 +724,20 @@ func buildCommsPhonePreloader() commsPhonePreloader {
|
|||
}
|
||||
|
||||
type commsPhoneThenLoader[Q orm.Loadable] struct {
|
||||
SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DestinationSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
SourceSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
SourceEmailLogs 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]
|
||||
}
|
||||
|
||||
func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
|
||||
type SourceEmailLogsLoadInterface interface {
|
||||
LoadSourceEmailLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type DestinationSMSLogsLoadInterface interface {
|
||||
LoadDestinationSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type DestinationTextLogsLoadInterface interface {
|
||||
LoadDestinationTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SourceSMSLogsLoadInterface interface {
|
||||
LoadSourceSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type SourceTextLogsLoadInterface interface {
|
||||
LoadSourceTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return commsPhoneThenLoader[Q]{
|
||||
|
|
@ -747,16 +747,16 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
|
|||
return retrieved.LoadSourceEmailLogs(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
DestinationSMSLogs: thenLoadBuilder[Q](
|
||||
"DestinationSMSLogs",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DestinationSMSLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadDestinationSMSLogs(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...)
|
||||
},
|
||||
),
|
||||
SourceSMSLogs: thenLoadBuilder[Q](
|
||||
"SourceSMSLogs",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SourceSMSLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadSourceSMSLogs(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...)
|
||||
},
|
||||
),
|
||||
}
|
||||
|
|
@ -823,16 +823,16 @@ func (os CommsPhoneSlice) LoadSourceEmailLogs(ctx context.Context, exec bob.Exec
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadDestinationSMSLogs loads the commsPhone's DestinationSMSLogs into the .R struct
|
||||
func (o *CommsPhone) LoadDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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.DestinationSMSLogs = nil
|
||||
o.R.DestinationTextLogs = nil
|
||||
|
||||
related, err := o.DestinationSMSLogs(mods...).All(ctx, exec)
|
||||
related, err := o.DestinationTextLogs(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -841,17 +841,17 @@ func (o *CommsPhone) LoadDestinationSMSLogs(ctx context.Context, exec bob.Execut
|
|||
rel.R.DestinationPhone = o
|
||||
}
|
||||
|
||||
o.R.DestinationSMSLogs = related
|
||||
o.R.DestinationTextLogs = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDestinationSMSLogs loads the commsPhone's DestinationSMSLogs into the .R struct
|
||||
func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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
|
||||
}
|
||||
|
||||
commsSMSLogs, err := os.DestinationSMSLogs(mods...).All(ctx, exec)
|
||||
commsTextLogs, err := os.DestinationTextLogs(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -861,7 +861,7 @@ func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.E
|
|||
continue
|
||||
}
|
||||
|
||||
o.R.DestinationSMSLogs = nil
|
||||
o.R.DestinationTextLogs = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
|
|
@ -869,7 +869,7 @@ func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.E
|
|||
continue
|
||||
}
|
||||
|
||||
for _, rel := range commsSMSLogs {
|
||||
for _, rel := range commsTextLogs {
|
||||
|
||||
if !(o.E164 == rel.Destination) {
|
||||
continue
|
||||
|
|
@ -877,23 +877,23 @@ func (os CommsPhoneSlice) LoadDestinationSMSLogs(ctx context.Context, exec bob.E
|
|||
|
||||
rel.R.DestinationPhone = o
|
||||
|
||||
o.R.DestinationSMSLogs = append(o.R.DestinationSMSLogs, rel)
|
||||
o.R.DestinationTextLogs = append(o.R.DestinationTextLogs, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSourceSMSLogs loads the commsPhone's SourceSMSLogs into the .R struct
|
||||
func (o *CommsPhone) LoadSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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.SourceSMSLogs = nil
|
||||
o.R.SourceTextLogs = nil
|
||||
|
||||
related, err := o.SourceSMSLogs(mods...).All(ctx, exec)
|
||||
related, err := o.SourceTextLogs(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -902,17 +902,17 @@ func (o *CommsPhone) LoadSourceSMSLogs(ctx context.Context, exec bob.Executor, m
|
|||
rel.R.SourcePhone = o
|
||||
}
|
||||
|
||||
o.R.SourceSMSLogs = related
|
||||
o.R.SourceTextLogs = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSourceSMSLogs loads the commsPhone's SourceSMSLogs into the .R struct
|
||||
func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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
|
||||
}
|
||||
|
||||
commsSMSLogs, err := os.SourceSMSLogs(mods...).All(ctx, exec)
|
||||
commsTextLogs, err := os.SourceTextLogs(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -922,7 +922,7 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut
|
|||
continue
|
||||
}
|
||||
|
||||
o.R.SourceSMSLogs = nil
|
||||
o.R.SourceTextLogs = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
|
|
@ -930,7 +930,7 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut
|
|||
continue
|
||||
}
|
||||
|
||||
for _, rel := range commsSMSLogs {
|
||||
for _, rel := range commsTextLogs {
|
||||
|
||||
if !(o.E164 == rel.Source) {
|
||||
continue
|
||||
|
|
@ -938,7 +938,7 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut
|
|||
|
||||
rel.R.SourcePhone = o
|
||||
|
||||
o.R.SourceSMSLogs = append(o.R.SourceSMSLogs, rel)
|
||||
o.R.SourceTextLogs = append(o.R.SourceTextLogs, rel)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -947,9 +947,9 @@ func (os CommsPhoneSlice) LoadSourceSMSLogs(ctx context.Context, exec bob.Execut
|
|||
|
||||
// commsPhoneC is where relationship counts are stored.
|
||||
type commsPhoneC struct {
|
||||
SourceEmailLogs *int64
|
||||
DestinationSMSLogs *int64
|
||||
SourceSMSLogs *int64
|
||||
SourceEmailLogs *int64
|
||||
DestinationTextLogs *int64
|
||||
SourceTextLogs *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -961,18 +961,18 @@ func (o *CommsPhone) PreloadCount(name string, count int64) error {
|
|||
switch name {
|
||||
case "SourceEmailLogs":
|
||||
o.C.SourceEmailLogs = &count
|
||||
case "DestinationSMSLogs":
|
||||
o.C.DestinationSMSLogs = &count
|
||||
case "SourceSMSLogs":
|
||||
o.C.SourceSMSLogs = &count
|
||||
case "DestinationTextLogs":
|
||||
o.C.DestinationTextLogs = &count
|
||||
case "SourceTextLogs":
|
||||
o.C.SourceTextLogs = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsPhoneCountPreloader struct {
|
||||
SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
DestinationSMSLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
SourceSMSLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
||||
|
|
@ -994,8 +994,8 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
DestinationSMSLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*CommsPhone]("DestinationSMSLogs", func(parent string) bob.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()
|
||||
|
|
@ -1004,15 +1004,15 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
|||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(CommsSMSLogs.Name()),
|
||||
sm.Where(psql.Quote(CommsSMSLogs.Alias(), "destination").EQ(psql.Quote(parent, "e164"))),
|
||||
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)
|
||||
})
|
||||
},
|
||||
SourceSMSLogs: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*CommsPhone]("SourceSMSLogs", func(parent string) bob.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()
|
||||
|
|
@ -1021,8 +1021,8 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
|||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(CommsSMSLogs.Name()),
|
||||
sm.Where(psql.Quote(CommsSMSLogs.Alias(), "source").EQ(psql.Quote(parent, "e164"))),
|
||||
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)
|
||||
|
|
@ -1032,20 +1032,20 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
|||
}
|
||||
|
||||
type commsPhoneCountThenLoader[Q orm.Loadable] struct {
|
||||
SourceEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DestinationSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
SourceSMSLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
SourceEmailLogs 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]
|
||||
}
|
||||
|
||||
func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[Q] {
|
||||
type SourceEmailLogsCountInterface interface {
|
||||
LoadCountSourceEmailLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type DestinationSMSLogsCountInterface interface {
|
||||
LoadCountDestinationSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type DestinationTextLogsCountInterface interface {
|
||||
LoadCountDestinationTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SourceSMSLogsCountInterface interface {
|
||||
LoadCountSourceSMSLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type SourceTextLogsCountInterface interface {
|
||||
LoadCountSourceTextLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return commsPhoneCountThenLoader[Q]{
|
||||
|
|
@ -1055,16 +1055,16 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
|
|||
return retrieved.LoadCountSourceEmailLogs(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
DestinationSMSLogs: countThenLoadBuilder[Q](
|
||||
"DestinationSMSLogs",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DestinationSMSLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountDestinationSMSLogs(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...)
|
||||
},
|
||||
),
|
||||
SourceSMSLogs: countThenLoadBuilder[Q](
|
||||
"SourceSMSLogs",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SourceSMSLogsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountSourceSMSLogs(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...)
|
||||
},
|
||||
),
|
||||
}
|
||||
|
|
@ -1100,29 +1100,29 @@ func (os CommsPhoneSlice) LoadCountSourceEmailLogs(ctx context.Context, exec bob
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountDestinationSMSLogs loads the count of DestinationSMSLogs into the C struct
|
||||
func (o *CommsPhone) LoadCountDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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.DestinationSMSLogs(mods...).Count(ctx, exec)
|
||||
count, err := o.DestinationTextLogs(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.DestinationSMSLogs = &count
|
||||
o.C.DestinationTextLogs = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountDestinationSMSLogs loads the count of DestinationSMSLogs for a slice
|
||||
func (os CommsPhoneSlice) LoadCountDestinationSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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.LoadCountDestinationSMSLogs(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountDestinationTextLogs(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1130,29 +1130,29 @@ func (os CommsPhoneSlice) LoadCountDestinationSMSLogs(ctx context.Context, exec
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountSourceSMSLogs loads the count of SourceSMSLogs into the C struct
|
||||
func (o *CommsPhone) LoadCountSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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.SourceSMSLogs(mods...).Count(ctx, exec)
|
||||
count, err := o.SourceTextLogs(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.SourceSMSLogs = &count
|
||||
o.C.SourceTextLogs = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountSourceSMSLogs loads the count of SourceSMSLogs for a slice
|
||||
func (os CommsPhoneSlice) LoadCountSourceSMSLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// 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.LoadCountSourceSMSLogs(ctx, exec, mods...); err != nil {
|
||||
if err := o.LoadCountSourceTextLogs(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1161,10 +1161,10 @@ func (os CommsPhoneSlice) LoadCountSourceSMSLogs(ctx context.Context, exec bob.E
|
|||
}
|
||||
|
||||
type commsPhoneJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
SourceEmailLogs modAs[Q, commsEmailLogColumns]
|
||||
DestinationSMSLogs modAs[Q, commsSMSLogColumns]
|
||||
SourceSMSLogs modAs[Q, commsSMSLogColumns]
|
||||
typ string
|
||||
SourceEmailLogs modAs[Q, commsEmailLogColumns]
|
||||
DestinationTextLogs modAs[Q, commsTextLogColumns]
|
||||
SourceTextLogs modAs[Q, commsTextLogColumns]
|
||||
}
|
||||
|
||||
func (j commsPhoneJoins[Q]) aliasedAs(alias string) commsPhoneJoins[Q] {
|
||||
|
|
@ -1188,13 +1188,13 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string
|
|||
return mods
|
||||
},
|
||||
},
|
||||
DestinationSMSLogs: modAs[Q, commsSMSLogColumns]{
|
||||
c: CommsSMSLogs.Columns,
|
||||
f: func(to commsSMSLogColumns) bob.Mod[Q] {
|
||||
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, CommsSMSLogs.Name().As(to.Alias())).On(
|
||||
mods = append(mods, dialect.Join[Q](typ, CommsTextLogs.Name().As(to.Alias())).On(
|
||||
to.Destination.EQ(cols.E164),
|
||||
))
|
||||
}
|
||||
|
|
@ -1202,13 +1202,13 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string
|
|||
return mods
|
||||
},
|
||||
},
|
||||
SourceSMSLogs: modAs[Q, commsSMSLogColumns]{
|
||||
c: CommsSMSLogs.Columns,
|
||||
f: func(to commsSMSLogColumns) bob.Mod[Q] {
|
||||
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, CommsSMSLogs.Name().As(to.Alias())).On(
|
||||
mods = append(mods, dialect.Join[Q](typ, CommsTextLogs.Name().As(to.Alias())).On(
|
||||
to.Source.EQ(cols.E164),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,37 +23,37 @@ import (
|
|||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// CommsSMSLog is an object representing the database table.
|
||||
type CommsSMSLog struct {
|
||||
Created time.Time `db:"created" `
|
||||
Destination string `db:"destination,pk" `
|
||||
Source string `db:"source,pk" `
|
||||
Type enums.CommsSmsmessagetype `db:"type,pk" `
|
||||
// CommsTextLog is an object representing the database table.
|
||||
type CommsTextLog struct {
|
||||
Created time.Time `db:"created" `
|
||||
Destination string `db:"destination,pk" `
|
||||
Source string `db:"source,pk" `
|
||||
Type enums.CommsMessagetypetext `db:"type,pk" `
|
||||
|
||||
R commsSMSLogR `db:"-" `
|
||||
R commsTextLogR `db:"-" `
|
||||
}
|
||||
|
||||
// CommsSMSLogSlice is an alias for a slice of pointers to CommsSMSLog.
|
||||
// This should almost always be used instead of []*CommsSMSLog.
|
||||
type CommsSMSLogSlice []*CommsSMSLog
|
||||
// CommsTextLogSlice is an alias for a slice of pointers to CommsTextLog.
|
||||
// This should almost always be used instead of []*CommsTextLog.
|
||||
type CommsTextLogSlice []*CommsTextLog
|
||||
|
||||
// CommsSMSLogs contains methods to work with the sms_log table
|
||||
var CommsSMSLogs = psql.NewTablex[*CommsSMSLog, CommsSMSLogSlice, *CommsSMSLogSetter]("comms", "sms_log", buildCommsSMSLogColumns("comms.sms_log"))
|
||||
// CommsTextLogs contains methods to work with the text_log table
|
||||
var CommsTextLogs = psql.NewTablex[*CommsTextLog, CommsTextLogSlice, *CommsTextLogSetter]("comms", "text_log", buildCommsTextLogColumns("comms.text_log"))
|
||||
|
||||
// CommsSMSLogsQuery is a query on the sms_log table
|
||||
type CommsSMSLogsQuery = *psql.ViewQuery[*CommsSMSLog, CommsSMSLogSlice]
|
||||
// CommsTextLogsQuery is a query on the text_log table
|
||||
type CommsTextLogsQuery = *psql.ViewQuery[*CommsTextLog, CommsTextLogSlice]
|
||||
|
||||
// commsSMSLogR is where relationships are stored.
|
||||
type commsSMSLogR struct {
|
||||
DestinationPhone *CommsPhone // comms.sms_log.sms_log_destination_fkey
|
||||
SourcePhone *CommsPhone // comms.sms_log.sms_log_source_fkey
|
||||
// commsTextLogR is where relationships are stored.
|
||||
type commsTextLogR struct {
|
||||
DestinationPhone *CommsPhone // comms.text_log.text_log_destination_fkey
|
||||
SourcePhone *CommsPhone // comms.text_log.text_log_source_fkey
|
||||
}
|
||||
|
||||
func buildCommsSMSLogColumns(alias string) commsSMSLogColumns {
|
||||
return commsSMSLogColumns{
|
||||
func buildCommsTextLogColumns(alias string) commsTextLogColumns {
|
||||
return commsTextLogColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "destination", "source", "type",
|
||||
).WithParent("comms.sms_log"),
|
||||
).WithParent("comms.text_log"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Destination: psql.Quote(alias, "destination"),
|
||||
|
|
@ -62,7 +62,7 @@ func buildCommsSMSLogColumns(alias string) commsSMSLogColumns {
|
|||
}
|
||||
}
|
||||
|
||||
type commsSMSLogColumns struct {
|
||||
type commsTextLogColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Created psql.Expression
|
||||
|
|
@ -71,25 +71,25 @@ type commsSMSLogColumns struct {
|
|||
Type psql.Expression
|
||||
}
|
||||
|
||||
func (c commsSMSLogColumns) Alias() string {
|
||||
func (c commsTextLogColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (commsSMSLogColumns) AliasedAs(alias string) commsSMSLogColumns {
|
||||
return buildCommsSMSLogColumns(alias)
|
||||
func (commsTextLogColumns) AliasedAs(alias string) commsTextLogColumns {
|
||||
return buildCommsTextLogColumns(alias)
|
||||
}
|
||||
|
||||
// CommsSMSLogSetter is used for insert/upsert/update operations
|
||||
// CommsTextLogSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type CommsSMSLogSetter struct {
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Destination omit.Val[string] `db:"destination,pk" `
|
||||
Source omit.Val[string] `db:"source,pk" `
|
||||
Type omit.Val[enums.CommsSmsmessagetype] `db:"type,pk" `
|
||||
type CommsTextLogSetter struct {
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Destination omit.Val[string] `db:"destination,pk" `
|
||||
Source omit.Val[string] `db:"source,pk" `
|
||||
Type omit.Val[enums.CommsMessagetypetext] `db:"type,pk" `
|
||||
}
|
||||
|
||||
func (s CommsSMSLogSetter) SetColumns() []string {
|
||||
func (s CommsTextLogSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
|
|
@ -106,7 +106,7 @@ func (s CommsSMSLogSetter) SetColumns() []string {
|
|||
return vals
|
||||
}
|
||||
|
||||
func (s CommsSMSLogSetter) Overwrite(t *CommsSMSLog) {
|
||||
func (s CommsTextLogSetter) Overwrite(t *CommsTextLog) {
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
|
|
@ -121,9 +121,9 @@ func (s CommsSMSLogSetter) Overwrite(t *CommsSMSLog) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *CommsSMSLogSetter) Apply(q *dialect.InsertQuery) {
|
||||
func (s *CommsTextLogSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return CommsSMSLogs.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
return CommsTextLogs.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
|
|
@ -156,11 +156,11 @@ func (s *CommsSMSLogSetter) Apply(q *dialect.InsertQuery) {
|
|||
}))
|
||||
}
|
||||
|
||||
func (s CommsSMSLogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
func (s CommsTextLogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s CommsSMSLogSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
func (s CommsTextLogSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
|
|
@ -194,54 +194,54 @@ func (s CommsSMSLogSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
return exprs
|
||||
}
|
||||
|
||||
// FindCommsSMSLog retrieves a single record by primary key
|
||||
// FindCommsTextLog retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindCommsSMSLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsSmsmessagetype, cols ...string) (*CommsSMSLog, error) {
|
||||
func FindCommsTextLog(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypetext, cols ...string) (*CommsTextLog, error) {
|
||||
if len(cols) == 0 {
|
||||
return CommsSMSLogs.Query(
|
||||
sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(TypePK))),
|
||||
return CommsTextLogs.Query(
|
||||
sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(TypePK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return CommsSMSLogs.Query(
|
||||
sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(TypePK))),
|
||||
sm.Columns(CommsSMSLogs.Columns.Only(cols...)),
|
||||
return CommsTextLogs.Query(
|
||||
sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(TypePK))),
|
||||
sm.Columns(CommsTextLogs.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// CommsSMSLogExists checks the presence of a single record by primary key
|
||||
func CommsSMSLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsSmsmessagetype) (bool, error) {
|
||||
return CommsSMSLogs.Query(
|
||||
sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(TypePK))),
|
||||
// CommsTextLogExists checks the presence of a single record by primary key
|
||||
func CommsTextLogExists(ctx context.Context, exec bob.Executor, DestinationPK string, SourcePK string, TypePK enums.CommsMessagetypetext) (bool, error) {
|
||||
return CommsTextLogs.Query(
|
||||
sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(DestinationPK))),
|
||||
sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(SourcePK))),
|
||||
sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(TypePK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after CommsSMSLog is retrieved from the database
|
||||
func (o *CommsSMSLog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
// AfterQueryHook is called after CommsTextLog is retrieved from the database
|
||||
func (o *CommsTextLog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = CommsSMSLogs.AfterSelectHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o})
|
||||
ctx, err = CommsTextLogs.AfterSelectHooks.RunHooks(ctx, exec, CommsTextLogSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = CommsSMSLogs.AfterInsertHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o})
|
||||
ctx, err = CommsTextLogs.AfterInsertHooks.RunHooks(ctx, exec, CommsTextLogSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = CommsSMSLogs.AfterUpdateHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o})
|
||||
ctx, err = CommsTextLogs.AfterUpdateHooks.RunHooks(ctx, exec, CommsTextLogSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = CommsSMSLogs.AfterDeleteHooks.RunHooks(ctx, exec, CommsSMSLogSlice{o})
|
||||
ctx, err = CommsTextLogs.AfterDeleteHooks.RunHooks(ctx, exec, CommsTextLogSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the CommsSMSLog
|
||||
func (o *CommsSMSLog) primaryKeyVals() bob.Expression {
|
||||
// primaryKeyVals returns the primary key values of the CommsTextLog
|
||||
func (o *CommsTextLog) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.Destination,
|
||||
o.Source,
|
||||
|
|
@ -249,15 +249,15 @@ func (o *CommsSMSLog) primaryKeyVals() bob.Expression {
|
|||
)
|
||||
}
|
||||
|
||||
func (o *CommsSMSLog) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("comms.sms_log", "destination"), psql.Quote("comms.sms_log", "source"), psql.Quote("comms.sms_log", "type")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
func (o *CommsTextLog) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("comms.text_log", "destination"), psql.Quote("comms.text_log", "source"), psql.Quote("comms.text_log", "type")).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 CommsSMSLog
|
||||
func (o *CommsSMSLog) Update(ctx context.Context, exec bob.Executor, s *CommsSMSLogSetter) error {
|
||||
v, err := CommsSMSLogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
// Update uses an executor to update the CommsTextLog
|
||||
func (o *CommsTextLog) Update(ctx context.Context, exec bob.Executor, s *CommsTextLogSetter) error {
|
||||
v, err := CommsTextLogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -268,18 +268,18 @@ func (o *CommsSMSLog) Update(ctx context.Context, exec bob.Executor, s *CommsSMS
|
|||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single CommsSMSLog record with an executor
|
||||
func (o *CommsSMSLog) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := CommsSMSLogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
// Delete deletes a single CommsTextLog record with an executor
|
||||
func (o *CommsTextLog) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := CommsTextLogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the CommsSMSLog using the executor
|
||||
func (o *CommsSMSLog) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := CommsSMSLogs.Query(
|
||||
sm.Where(CommsSMSLogs.Columns.Destination.EQ(psql.Arg(o.Destination))),
|
||||
sm.Where(CommsSMSLogs.Columns.Source.EQ(psql.Arg(o.Source))),
|
||||
sm.Where(CommsSMSLogs.Columns.Type.EQ(psql.Arg(o.Type))),
|
||||
// Reload refreshes the CommsTextLog using the executor
|
||||
func (o *CommsTextLog) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := CommsTextLogs.Query(
|
||||
sm.Where(CommsTextLogs.Columns.Destination.EQ(psql.Arg(o.Destination))),
|
||||
sm.Where(CommsTextLogs.Columns.Source.EQ(psql.Arg(o.Source))),
|
||||
sm.Where(CommsTextLogs.Columns.Type.EQ(psql.Arg(o.Type))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -290,30 +290,30 @@ func (o *CommsSMSLog) Reload(ctx context.Context, exec bob.Executor) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after CommsSMSLogSlice is retrieved from the database
|
||||
func (o CommsSMSLogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
// AfterQueryHook is called after CommsTextLogSlice is retrieved from the database
|
||||
func (o CommsTextLogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = CommsSMSLogs.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
ctx, err = CommsTextLogs.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = CommsSMSLogs.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
ctx, err = CommsTextLogs.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = CommsSMSLogs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
ctx, err = CommsTextLogs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = CommsSMSLogs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
ctx, err = CommsTextLogs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o CommsSMSLogSlice) pkIN() dialect.Expression {
|
||||
func (o CommsTextLogSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("comms.sms_log", "destination"), psql.Quote("comms.sms_log", "source"), psql.Quote("comms.sms_log", "type")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return psql.Group(psql.Quote("comms.text_log", "destination"), psql.Quote("comms.text_log", "source"), psql.Quote("comms.text_log", "type")).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()
|
||||
|
|
@ -325,7 +325,7 @@ func (o CommsSMSLogSlice) pkIN() dialect.Expression {
|
|||
// 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 CommsSMSLogSlice) copyMatchingRows(from ...*CommsSMSLog) {
|
||||
func (o CommsTextLogSlice) copyMatchingRows(from ...*CommsTextLog) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.Destination != old.Destination {
|
||||
|
|
@ -345,25 +345,25 @@ func (o CommsSMSLogSlice) copyMatchingRows(from ...*CommsSMSLog) {
|
|||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o CommsSMSLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
func (o CommsTextLogSlice) 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 CommsSMSLogs.BeforeUpdateHooks.RunHooks(ctx, exec, o)
|
||||
return CommsTextLogs.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 *CommsSMSLog:
|
||||
case *CommsTextLog:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*CommsSMSLog:
|
||||
case []*CommsTextLog:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case CommsSMSLogSlice:
|
||||
case CommsTextLogSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a CommsSMSLog or a slice of CommsSMSLog
|
||||
// If the retrieved value is not a CommsTextLog or a slice of CommsTextLog
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = CommsSMSLogs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
_, err = CommsTextLogs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
@ -374,25 +374,25 @@ func (o CommsSMSLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o CommsSMSLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
|
||||
func (o CommsTextLogSlice) 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 CommsSMSLogs.BeforeDeleteHooks.RunHooks(ctx, exec, o)
|
||||
return CommsTextLogs.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 *CommsSMSLog:
|
||||
case *CommsTextLog:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*CommsSMSLog:
|
||||
case []*CommsTextLog:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case CommsSMSLogSlice:
|
||||
case CommsTextLogSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a CommsSMSLog or a slice of CommsSMSLog
|
||||
// If the retrieved value is not a CommsTextLog or a slice of CommsTextLog
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = CommsSMSLogs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
_, err = CommsTextLogs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
@ -402,30 +402,30 @@ func (o CommsSMSLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
|
|||
})
|
||||
}
|
||||
|
||||
func (o CommsSMSLogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsSMSLogSetter) error {
|
||||
func (o CommsTextLogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsTextLogSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := CommsSMSLogs.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
_, err := CommsTextLogs.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o CommsSMSLogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
func (o CommsTextLogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := CommsSMSLogs.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
_, err := CommsTextLogs.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o CommsSMSLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
func (o CommsTextLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := CommsSMSLogs.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
o2, err := CommsTextLogs.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -436,13 +436,13 @@ func (o CommsSMSLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) erro
|
|||
}
|
||||
|
||||
// DestinationPhone starts a query for related objects on comms.phone
|
||||
func (o *CommsSMSLog) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
func (o *CommsTextLog) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
return CommsPhones.Query(append(mods,
|
||||
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.Destination))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os CommsSMSLogSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
func (os CommsTextLogSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
pkDestination := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -460,13 +460,13 @@ func (os CommsSMSLogSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery
|
|||
}
|
||||
|
||||
// SourcePhone starts a query for related objects on comms.phone
|
||||
func (o *CommsSMSLog) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
func (o *CommsTextLog) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
return CommsPhones.Query(append(mods,
|
||||
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.Source))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os CommsSMSLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
func (os CommsTextLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
pkSource := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -483,20 +483,20 @@ func (os CommsSMSLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) Co
|
|||
)...)
|
||||
}
|
||||
|
||||
func attachCommsSMSLogDestinationPhone0(ctx context.Context, exec bob.Executor, count int, commsSMSLog0 *CommsSMSLog, commsPhone1 *CommsPhone) (*CommsSMSLog, error) {
|
||||
setter := &CommsSMSLogSetter{
|
||||
func attachCommsTextLogDestinationPhone0(ctx context.Context, exec bob.Executor, count int, commsTextLog0 *CommsTextLog, commsPhone1 *CommsPhone) (*CommsTextLog, error) {
|
||||
setter := &CommsTextLogSetter{
|
||||
Destination: omit.From(commsPhone1.E164),
|
||||
}
|
||||
|
||||
err := commsSMSLog0.Update(ctx, exec, setter)
|
||||
err := commsTextLog0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsSMSLogDestinationPhone0: %w", err)
|
||||
return nil, fmt.Errorf("attachCommsTextLogDestinationPhone0: %w", err)
|
||||
}
|
||||
|
||||
return commsSMSLog0, nil
|
||||
return commsTextLog0, nil
|
||||
}
|
||||
|
||||
func (commsSMSLog0 *CommsSMSLog) InsertDestinationPhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
|
||||
func (commsTextLog0 *CommsTextLog) InsertDestinationPhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
|
||||
var err error
|
||||
|
||||
commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec)
|
||||
|
|
@ -504,47 +504,47 @@ func (commsSMSLog0 *CommsSMSLog) InsertDestinationPhone(ctx context.Context, exe
|
|||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachCommsSMSLogDestinationPhone0(ctx, exec, 1, commsSMSLog0, commsPhone1)
|
||||
_, err = attachCommsTextLogDestinationPhone0(ctx, exec, 1, commsTextLog0, commsPhone1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsSMSLog0.R.DestinationPhone = commsPhone1
|
||||
commsTextLog0.R.DestinationPhone = commsPhone1
|
||||
|
||||
commsPhone1.R.DestinationSMSLogs = append(commsPhone1.R.DestinationSMSLogs, commsSMSLog0)
|
||||
commsPhone1.R.DestinationTextLogs = append(commsPhone1.R.DestinationTextLogs, commsTextLog0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsSMSLog0 *CommsSMSLog) AttachDestinationPhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
|
||||
func (commsTextLog0 *CommsTextLog) AttachDestinationPhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
|
||||
var err error
|
||||
|
||||
_, err = attachCommsSMSLogDestinationPhone0(ctx, exec, 1, commsSMSLog0, commsPhone1)
|
||||
_, err = attachCommsTextLogDestinationPhone0(ctx, exec, 1, commsTextLog0, commsPhone1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsSMSLog0.R.DestinationPhone = commsPhone1
|
||||
commsTextLog0.R.DestinationPhone = commsPhone1
|
||||
|
||||
commsPhone1.R.DestinationSMSLogs = append(commsPhone1.R.DestinationSMSLogs, commsSMSLog0)
|
||||
commsPhone1.R.DestinationTextLogs = append(commsPhone1.R.DestinationTextLogs, commsTextLog0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachCommsSMSLogSourcePhone0(ctx context.Context, exec bob.Executor, count int, commsSMSLog0 *CommsSMSLog, commsPhone1 *CommsPhone) (*CommsSMSLog, error) {
|
||||
setter := &CommsSMSLogSetter{
|
||||
func attachCommsTextLogSourcePhone0(ctx context.Context, exec bob.Executor, count int, commsTextLog0 *CommsTextLog, commsPhone1 *CommsPhone) (*CommsTextLog, error) {
|
||||
setter := &CommsTextLogSetter{
|
||||
Source: omit.From(commsPhone1.E164),
|
||||
}
|
||||
|
||||
err := commsSMSLog0.Update(ctx, exec, setter)
|
||||
err := commsTextLog0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsSMSLogSourcePhone0: %w", err)
|
||||
return nil, fmt.Errorf("attachCommsTextLogSourcePhone0: %w", err)
|
||||
}
|
||||
|
||||
return commsSMSLog0, nil
|
||||
return commsTextLog0, nil
|
||||
}
|
||||
|
||||
func (commsSMSLog0 *CommsSMSLog) InsertSourcePhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
|
||||
func (commsTextLog0 *CommsTextLog) InsertSourcePhone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
|
||||
var err error
|
||||
|
||||
commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec)
|
||||
|
|
@ -552,54 +552,54 @@ func (commsSMSLog0 *CommsSMSLog) InsertSourcePhone(ctx context.Context, exec bob
|
|||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachCommsSMSLogSourcePhone0(ctx, exec, 1, commsSMSLog0, commsPhone1)
|
||||
_, err = attachCommsTextLogSourcePhone0(ctx, exec, 1, commsTextLog0, commsPhone1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsSMSLog0.R.SourcePhone = commsPhone1
|
||||
commsTextLog0.R.SourcePhone = commsPhone1
|
||||
|
||||
commsPhone1.R.SourceSMSLogs = append(commsPhone1.R.SourceSMSLogs, commsSMSLog0)
|
||||
commsPhone1.R.SourceTextLogs = append(commsPhone1.R.SourceTextLogs, commsTextLog0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsSMSLog0 *CommsSMSLog) AttachSourcePhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
|
||||
func (commsTextLog0 *CommsTextLog) AttachSourcePhone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
|
||||
var err error
|
||||
|
||||
_, err = attachCommsSMSLogSourcePhone0(ctx, exec, 1, commsSMSLog0, commsPhone1)
|
||||
_, err = attachCommsTextLogSourcePhone0(ctx, exec, 1, commsTextLog0, commsPhone1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsSMSLog0.R.SourcePhone = commsPhone1
|
||||
commsTextLog0.R.SourcePhone = commsPhone1
|
||||
|
||||
commsPhone1.R.SourceSMSLogs = append(commsPhone1.R.SourceSMSLogs, commsSMSLog0)
|
||||
commsPhone1.R.SourceTextLogs = append(commsPhone1.R.SourceTextLogs, commsTextLog0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsSMSLogWhere[Q psql.Filterable] struct {
|
||||
type commsTextLogWhere[Q psql.Filterable] struct {
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Destination psql.WhereMod[Q, string]
|
||||
Source psql.WhereMod[Q, string]
|
||||
Type psql.WhereMod[Q, enums.CommsSmsmessagetype]
|
||||
Type psql.WhereMod[Q, enums.CommsMessagetypetext]
|
||||
}
|
||||
|
||||
func (commsSMSLogWhere[Q]) AliasedAs(alias string) commsSMSLogWhere[Q] {
|
||||
return buildCommsSMSLogWhere[Q](buildCommsSMSLogColumns(alias))
|
||||
func (commsTextLogWhere[Q]) AliasedAs(alias string) commsTextLogWhere[Q] {
|
||||
return buildCommsTextLogWhere[Q](buildCommsTextLogColumns(alias))
|
||||
}
|
||||
|
||||
func buildCommsSMSLogWhere[Q psql.Filterable](cols commsSMSLogColumns) commsSMSLogWhere[Q] {
|
||||
return commsSMSLogWhere[Q]{
|
||||
func buildCommsTextLogWhere[Q psql.Filterable](cols commsTextLogColumns) commsTextLogWhere[Q] {
|
||||
return commsTextLogWhere[Q]{
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Destination: psql.Where[Q, string](cols.Destination),
|
||||
Source: psql.Where[Q, string](cols.Source),
|
||||
Type: psql.Where[Q, enums.CommsSmsmessagetype](cols.Type),
|
||||
Type: psql.Where[Q, enums.CommsMessagetypetext](cols.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *CommsSMSLog) Preload(name string, retrieved any) error {
|
||||
func (o *CommsTextLog) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -608,45 +608,45 @@ func (o *CommsSMSLog) Preload(name string, retrieved any) error {
|
|||
case "DestinationPhone":
|
||||
rel, ok := retrieved.(*CommsPhone)
|
||||
if !ok {
|
||||
return fmt.Errorf("commsSMSLog cannot load %T as %q", retrieved, name)
|
||||
return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.DestinationPhone = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.DestinationSMSLogs = CommsSMSLogSlice{o}
|
||||
rel.R.DestinationTextLogs = CommsTextLogSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "SourcePhone":
|
||||
rel, ok := retrieved.(*CommsPhone)
|
||||
if !ok {
|
||||
return fmt.Errorf("commsSMSLog cannot load %T as %q", retrieved, name)
|
||||
return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.SourcePhone = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.SourceSMSLogs = CommsSMSLogSlice{o}
|
||||
rel.R.SourceTextLogs = CommsTextLogSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("commsSMSLog has no relationship %q", name)
|
||||
return fmt.Errorf("commsTextLog has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type commsSMSLogPreloader struct {
|
||||
type commsTextLogPreloader struct {
|
||||
DestinationPhone func(...psql.PreloadOption) psql.Preloader
|
||||
SourcePhone func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildCommsSMSLogPreloader() commsSMSLogPreloader {
|
||||
return commsSMSLogPreloader{
|
||||
func buildCommsTextLogPreloader() commsTextLogPreloader {
|
||||
return commsTextLogPreloader{
|
||||
DestinationPhone: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
|
||||
Name: "DestinationPhone",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: CommsSMSLogs,
|
||||
From: CommsTextLogs,
|
||||
To: CommsPhones,
|
||||
FromColumns: []string{"destination"},
|
||||
ToColumns: []string{"e164"},
|
||||
|
|
@ -659,7 +659,7 @@ func buildCommsSMSLogPreloader() commsSMSLogPreloader {
|
|||
Name: "SourcePhone",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: CommsSMSLogs,
|
||||
From: CommsTextLogs,
|
||||
To: CommsPhones,
|
||||
FromColumns: []string{"source"},
|
||||
ToColumns: []string{"e164"},
|
||||
|
|
@ -670,12 +670,12 @@ func buildCommsSMSLogPreloader() commsSMSLogPreloader {
|
|||
}
|
||||
}
|
||||
|
||||
type commsSMSLogThenLoader[Q orm.Loadable] struct {
|
||||
type commsTextLogThenLoader[Q orm.Loadable] struct {
|
||||
DestinationPhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
SourcePhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildCommsSMSLogThenLoader[Q orm.Loadable]() commsSMSLogThenLoader[Q] {
|
||||
func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] {
|
||||
type DestinationPhoneLoadInterface interface {
|
||||
LoadDestinationPhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -683,7 +683,7 @@ func buildCommsSMSLogThenLoader[Q orm.Loadable]() commsSMSLogThenLoader[Q] {
|
|||
LoadSourcePhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return commsSMSLogThenLoader[Q]{
|
||||
return commsTextLogThenLoader[Q]{
|
||||
DestinationPhone: thenLoadBuilder[Q](
|
||||
"DestinationPhone",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DestinationPhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -699,8 +699,8 @@ func buildCommsSMSLogThenLoader[Q orm.Loadable]() commsSMSLogThenLoader[Q] {
|
|||
}
|
||||
}
|
||||
|
||||
// LoadDestinationPhone loads the commsSMSLog's DestinationPhone into the .R struct
|
||||
func (o *CommsSMSLog) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadDestinationPhone loads the commsTextLog's DestinationPhone into the .R struct
|
||||
func (o *CommsTextLog) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -713,14 +713,14 @@ func (o *CommsSMSLog) LoadDestinationPhone(ctx context.Context, exec bob.Executo
|
|||
return err
|
||||
}
|
||||
|
||||
related.R.DestinationSMSLogs = CommsSMSLogSlice{o}
|
||||
related.R.DestinationTextLogs = CommsTextLogSlice{o}
|
||||
|
||||
o.R.DestinationPhone = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDestinationPhone loads the commsSMSLog's DestinationPhone into the .R struct
|
||||
func (os CommsSMSLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadDestinationPhone loads the commsTextLog's DestinationPhone into the .R struct
|
||||
func (os CommsTextLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -741,7 +741,7 @@ func (os CommsSMSLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Ex
|
|||
continue
|
||||
}
|
||||
|
||||
rel.R.DestinationSMSLogs = append(rel.R.DestinationSMSLogs, o)
|
||||
rel.R.DestinationTextLogs = append(rel.R.DestinationTextLogs, o)
|
||||
|
||||
o.R.DestinationPhone = rel
|
||||
break
|
||||
|
|
@ -751,8 +751,8 @@ func (os CommsSMSLogSlice) LoadDestinationPhone(ctx context.Context, exec bob.Ex
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadSourcePhone loads the commsSMSLog's SourcePhone into the .R struct
|
||||
func (o *CommsSMSLog) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadSourcePhone loads the commsTextLog's SourcePhone into the .R struct
|
||||
func (o *CommsTextLog) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -765,14 +765,14 @@ func (o *CommsSMSLog) LoadSourcePhone(ctx context.Context, exec bob.Executor, mo
|
|||
return err
|
||||
}
|
||||
|
||||
related.R.SourceSMSLogs = CommsSMSLogSlice{o}
|
||||
related.R.SourceTextLogs = CommsTextLogSlice{o}
|
||||
|
||||
o.R.SourcePhone = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSourcePhone loads the commsSMSLog's SourcePhone into the .R struct
|
||||
func (os CommsSMSLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadSourcePhone loads the commsTextLog's SourcePhone into the .R struct
|
||||
func (os CommsTextLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -793,7 +793,7 @@ func (os CommsSMSLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executo
|
|||
continue
|
||||
}
|
||||
|
||||
rel.R.SourceSMSLogs = append(rel.R.SourceSMSLogs, o)
|
||||
rel.R.SourceTextLogs = append(rel.R.SourceTextLogs, o)
|
||||
|
||||
o.R.SourcePhone = rel
|
||||
break
|
||||
|
|
@ -803,18 +803,18 @@ func (os CommsSMSLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Executo
|
|||
return nil
|
||||
}
|
||||
|
||||
type commsSMSLogJoins[Q dialect.Joinable] struct {
|
||||
type commsTextLogJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
DestinationPhone modAs[Q, commsPhoneColumns]
|
||||
SourcePhone modAs[Q, commsPhoneColumns]
|
||||
}
|
||||
|
||||
func (j commsSMSLogJoins[Q]) aliasedAs(alias string) commsSMSLogJoins[Q] {
|
||||
return buildCommsSMSLogJoins[Q](buildCommsSMSLogColumns(alias), j.typ)
|
||||
func (j commsTextLogJoins[Q]) aliasedAs(alias string) commsTextLogJoins[Q] {
|
||||
return buildCommsTextLogJoins[Q](buildCommsTextLogColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildCommsSMSLogJoins[Q dialect.Joinable](cols commsSMSLogColumns, typ string) commsSMSLogJoins[Q] {
|
||||
return commsSMSLogJoins[Q]{
|
||||
func buildCommsTextLogJoins[Q dialect.Joinable](cols commsTextLogColumns, typ string) commsTextLogJoins[Q] {
|
||||
return commsTextLogJoins[Q]{
|
||||
typ: typ,
|
||||
DestinationPhone: modAs[Q, commsPhoneColumns]{
|
||||
c: CommsPhones.Columns,
|
||||
Loading…
Add table
Add a link
Reference in a new issue