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
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
package dberrors
|
||||
|
||||
var CommsSMSLogErrors = &commsSMSLogErrors{
|
||||
ErrUniqueSmsLogPkey: &UniqueConstraintError{
|
||||
var CommsTextLogErrors = &commsTextLogErrors{
|
||||
ErrUniqueTextLogPkey: &UniqueConstraintError{
|
||||
schema: "comms",
|
||||
table: "sms_log",
|
||||
table: "text_log",
|
||||
columns: []string{"destination", "source", "type"},
|
||||
s: "sms_log_pkey",
|
||||
s: "text_log_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type commsSMSLogErrors struct {
|
||||
ErrUniqueSmsLogPkey *UniqueConstraintError
|
||||
type commsTextLogErrors struct {
|
||||
ErrUniqueTextLogPkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ var CommsEmailLogs = Table[
|
|||
},
|
||||
Type: column{
|
||||
Name: "type",
|
||||
DBType: "comms.emailmessagetype",
|
||||
DBType: "comms.messagetypeemail",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@ package dbinfo
|
|||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var CommsSMSLogs = Table[
|
||||
commsSMSLogColumns,
|
||||
commsSMSLogIndexes,
|
||||
commsSMSLogForeignKeys,
|
||||
commsSMSLogUniques,
|
||||
commsSMSLogChecks,
|
||||
var CommsTextLogs = Table[
|
||||
commsTextLogColumns,
|
||||
commsTextLogIndexes,
|
||||
commsTextLogForeignKeys,
|
||||
commsTextLogUniques,
|
||||
commsTextLogChecks,
|
||||
]{
|
||||
Schema: "comms",
|
||||
Name: "sms_log",
|
||||
Columns: commsSMSLogColumns{
|
||||
Name: "text_log",
|
||||
Columns: commsTextLogColumns{
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
|
|
@ -44,7 +44,7 @@ var CommsSMSLogs = Table[
|
|||
},
|
||||
Type: column{
|
||||
Name: "type",
|
||||
DBType: "comms.smsmessagetype",
|
||||
DBType: "comms.messagetypetext",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
|
|
@ -52,10 +52,10 @@ var CommsSMSLogs = Table[
|
|||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: commsSMSLogIndexes{
|
||||
SMSLogPkey: index{
|
||||
Indexes: commsTextLogIndexes{
|
||||
TextLogPkey: index{
|
||||
Type: "btree",
|
||||
Name: "sms_log_pkey",
|
||||
Name: "text_log_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "destination",
|
||||
|
|
@ -82,23 +82,23 @@ var CommsSMSLogs = Table[
|
|||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "sms_log_pkey",
|
||||
Name: "text_log_pkey",
|
||||
Columns: []string{"destination", "source", "type"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: commsSMSLogForeignKeys{
|
||||
CommsSMSLogSMSLogDestinationFkey: foreignKey{
|
||||
ForeignKeys: commsTextLogForeignKeys{
|
||||
CommsTextLogTextLogDestinationFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "comms.sms_log.sms_log_destination_fkey",
|
||||
Name: "comms.text_log.text_log_destination_fkey",
|
||||
Columns: []string{"destination"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "comms.phone",
|
||||
ForeignColumns: []string{"e164"},
|
||||
},
|
||||
CommsSMSLogSMSLogSourceFkey: foreignKey{
|
||||
CommsTextLogTextLogSourceFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "comms.sms_log.sms_log_source_fkey",
|
||||
Name: "comms.text_log.text_log_source_fkey",
|
||||
Columns: []string{"source"},
|
||||
Comment: "",
|
||||
},
|
||||
|
|
@ -110,48 +110,48 @@ var CommsSMSLogs = Table[
|
|||
Comment: "",
|
||||
}
|
||||
|
||||
type commsSMSLogColumns struct {
|
||||
type commsTextLogColumns struct {
|
||||
Created column
|
||||
Destination column
|
||||
Source column
|
||||
Type column
|
||||
}
|
||||
|
||||
func (c commsSMSLogColumns) AsSlice() []column {
|
||||
func (c commsTextLogColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Created, c.Destination, c.Source, c.Type,
|
||||
}
|
||||
}
|
||||
|
||||
type commsSMSLogIndexes struct {
|
||||
SMSLogPkey index
|
||||
type commsTextLogIndexes struct {
|
||||
TextLogPkey index
|
||||
}
|
||||
|
||||
func (i commsSMSLogIndexes) AsSlice() []index {
|
||||
func (i commsTextLogIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.SMSLogPkey,
|
||||
i.TextLogPkey,
|
||||
}
|
||||
}
|
||||
|
||||
type commsSMSLogForeignKeys struct {
|
||||
CommsSMSLogSMSLogDestinationFkey foreignKey
|
||||
CommsSMSLogSMSLogSourceFkey foreignKey
|
||||
type commsTextLogForeignKeys struct {
|
||||
CommsTextLogTextLogDestinationFkey foreignKey
|
||||
CommsTextLogTextLogSourceFkey foreignKey
|
||||
}
|
||||
|
||||
func (f commsSMSLogForeignKeys) AsSlice() []foreignKey {
|
||||
func (f commsTextLogForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.CommsSMSLogSMSLogDestinationFkey, f.CommsSMSLogSMSLogSourceFkey,
|
||||
f.CommsTextLogTextLogDestinationFkey, f.CommsTextLogTextLogSourceFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type commsSMSLogUniques struct{}
|
||||
type commsTextLogUniques struct{}
|
||||
|
||||
func (u commsSMSLogUniques) AsSlice() []constraint {
|
||||
func (u commsTextLogUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type commsSMSLogChecks struct{}
|
||||
type commsTextLogChecks struct{}
|
||||
|
||||
func (c commsSMSLogChecks) AsSlice() []check {
|
||||
func (c commsTextLogChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -193,32 +193,35 @@ func (e *Audiodatatype) Scan(value any) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Enum values for CommsEmailmessagetype
|
||||
// Enum values for CommsMessagetypeemail
|
||||
const (
|
||||
CommsEmailmessagetypeReportSubscriptionConfirmation CommsEmailmessagetype = "report-subscription-confirmation"
|
||||
CommsEmailmessagetypeReportStatusScheduled CommsEmailmessagetype = "report-status-scheduled"
|
||||
CommsEmailmessagetypeReportStatusComplete CommsEmailmessagetype = "report-status-complete"
|
||||
CommsMessagetypeemailInitialContact CommsMessagetypeemail = "initial-contact"
|
||||
CommsMessagetypeemailReportSubscriptionConfirmation CommsMessagetypeemail = "report-subscription-confirmation"
|
||||
CommsMessagetypeemailReportStatusScheduled CommsMessagetypeemail = "report-status-scheduled"
|
||||
CommsMessagetypeemailReportStatusComplete CommsMessagetypeemail = "report-status-complete"
|
||||
)
|
||||
|
||||
func AllCommsEmailmessagetype() []CommsEmailmessagetype {
|
||||
return []CommsEmailmessagetype{
|
||||
CommsEmailmessagetypeReportSubscriptionConfirmation,
|
||||
CommsEmailmessagetypeReportStatusScheduled,
|
||||
CommsEmailmessagetypeReportStatusComplete,
|
||||
func AllCommsMessagetypeemail() []CommsMessagetypeemail {
|
||||
return []CommsMessagetypeemail{
|
||||
CommsMessagetypeemailInitialContact,
|
||||
CommsMessagetypeemailReportSubscriptionConfirmation,
|
||||
CommsMessagetypeemailReportStatusScheduled,
|
||||
CommsMessagetypeemailReportStatusComplete,
|
||||
}
|
||||
}
|
||||
|
||||
type CommsEmailmessagetype string
|
||||
type CommsMessagetypeemail string
|
||||
|
||||
func (e CommsEmailmessagetype) String() string {
|
||||
func (e CommsMessagetypeemail) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e CommsEmailmessagetype) Valid() bool {
|
||||
func (e CommsMessagetypeemail) Valid() bool {
|
||||
switch e {
|
||||
case CommsEmailmessagetypeReportSubscriptionConfirmation,
|
||||
CommsEmailmessagetypeReportStatusScheduled,
|
||||
CommsEmailmessagetypeReportStatusComplete:
|
||||
case CommsMessagetypeemailInitialContact,
|
||||
CommsMessagetypeemailReportSubscriptionConfirmation,
|
||||
CommsMessagetypeemailReportStatusScheduled,
|
||||
CommsMessagetypeemailReportStatusComplete:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
|
@ -226,75 +229,78 @@ func (e CommsEmailmessagetype) Valid() bool {
|
|||
}
|
||||
|
||||
// useful when testing in other packages
|
||||
func (e CommsEmailmessagetype) All() []CommsEmailmessagetype {
|
||||
return AllCommsEmailmessagetype()
|
||||
func (e CommsMessagetypeemail) All() []CommsMessagetypeemail {
|
||||
return AllCommsMessagetypeemail()
|
||||
}
|
||||
|
||||
func (e CommsEmailmessagetype) MarshalText() ([]byte, error) {
|
||||
func (e CommsMessagetypeemail) MarshalText() ([]byte, error) {
|
||||
return []byte(e), nil
|
||||
}
|
||||
|
||||
func (e *CommsEmailmessagetype) UnmarshalText(text []byte) error {
|
||||
func (e *CommsMessagetypeemail) UnmarshalText(text []byte) error {
|
||||
return e.Scan(text)
|
||||
}
|
||||
|
||||
func (e CommsEmailmessagetype) MarshalBinary() ([]byte, error) {
|
||||
func (e CommsMessagetypeemail) MarshalBinary() ([]byte, error) {
|
||||
return []byte(e), nil
|
||||
}
|
||||
|
||||
func (e *CommsEmailmessagetype) UnmarshalBinary(data []byte) error {
|
||||
func (e *CommsMessagetypeemail) UnmarshalBinary(data []byte) error {
|
||||
return e.Scan(data)
|
||||
}
|
||||
|
||||
func (e CommsEmailmessagetype) Value() (driver.Value, error) {
|
||||
func (e CommsMessagetypeemail) Value() (driver.Value, error) {
|
||||
return string(e), nil
|
||||
}
|
||||
|
||||
func (e *CommsEmailmessagetype) Scan(value any) error {
|
||||
func (e *CommsMessagetypeemail) Scan(value any) error {
|
||||
switch x := value.(type) {
|
||||
case string:
|
||||
*e = CommsEmailmessagetype(x)
|
||||
*e = CommsMessagetypeemail(x)
|
||||
case []byte:
|
||||
*e = CommsEmailmessagetype(x)
|
||||
*e = CommsMessagetypeemail(x)
|
||||
case nil:
|
||||
return fmt.Errorf("cannot nil into CommsEmailmessagetype")
|
||||
return fmt.Errorf("cannot nil into CommsMessagetypeemail")
|
||||
default:
|
||||
return fmt.Errorf("cannot scan type %T: %v", value, value)
|
||||
}
|
||||
|
||||
if !e.Valid() {
|
||||
return fmt.Errorf("invalid CommsEmailmessagetype value: %s", *e)
|
||||
return fmt.Errorf("invalid CommsMessagetypeemail value: %s", *e)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enum values for CommsSmsmessagetype
|
||||
// Enum values for CommsMessagetypetext
|
||||
const (
|
||||
CommsSmsmessagetypeReportSubscriptionConfirmation CommsSmsmessagetype = "report-subscription-confirmation"
|
||||
CommsSmsmessagetypeReportStatusScheduled CommsSmsmessagetype = "report-status-scheduled"
|
||||
CommsSmsmessagetypeReportStatusComplete CommsSmsmessagetype = "report-status-complete"
|
||||
CommsMessagetypetextInitialContact CommsMessagetypetext = "initial-contact"
|
||||
CommsMessagetypetextReportSubscriptionConfirmation CommsMessagetypetext = "report-subscription-confirmation"
|
||||
CommsMessagetypetextReportStatusScheduled CommsMessagetypetext = "report-status-scheduled"
|
||||
CommsMessagetypetextReportStatusComplete CommsMessagetypetext = "report-status-complete"
|
||||
)
|
||||
|
||||
func AllCommsSmsmessagetype() []CommsSmsmessagetype {
|
||||
return []CommsSmsmessagetype{
|
||||
CommsSmsmessagetypeReportSubscriptionConfirmation,
|
||||
CommsSmsmessagetypeReportStatusScheduled,
|
||||
CommsSmsmessagetypeReportStatusComplete,
|
||||
func AllCommsMessagetypetext() []CommsMessagetypetext {
|
||||
return []CommsMessagetypetext{
|
||||
CommsMessagetypetextInitialContact,
|
||||
CommsMessagetypetextReportSubscriptionConfirmation,
|
||||
CommsMessagetypetextReportStatusScheduled,
|
||||
CommsMessagetypetextReportStatusComplete,
|
||||
}
|
||||
}
|
||||
|
||||
type CommsSmsmessagetype string
|
||||
type CommsMessagetypetext string
|
||||
|
||||
func (e CommsSmsmessagetype) String() string {
|
||||
func (e CommsMessagetypetext) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e CommsSmsmessagetype) Valid() bool {
|
||||
func (e CommsMessagetypetext) Valid() bool {
|
||||
switch e {
|
||||
case CommsSmsmessagetypeReportSubscriptionConfirmation,
|
||||
CommsSmsmessagetypeReportStatusScheduled,
|
||||
CommsSmsmessagetypeReportStatusComplete:
|
||||
case CommsMessagetypetextInitialContact,
|
||||
CommsMessagetypetextReportSubscriptionConfirmation,
|
||||
CommsMessagetypetextReportStatusScheduled,
|
||||
CommsMessagetypetextReportStatusComplete:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
|
@ -302,44 +308,44 @@ func (e CommsSmsmessagetype) Valid() bool {
|
|||
}
|
||||
|
||||
// useful when testing in other packages
|
||||
func (e CommsSmsmessagetype) All() []CommsSmsmessagetype {
|
||||
return AllCommsSmsmessagetype()
|
||||
func (e CommsMessagetypetext) All() []CommsMessagetypetext {
|
||||
return AllCommsMessagetypetext()
|
||||
}
|
||||
|
||||
func (e CommsSmsmessagetype) MarshalText() ([]byte, error) {
|
||||
func (e CommsMessagetypetext) MarshalText() ([]byte, error) {
|
||||
return []byte(e), nil
|
||||
}
|
||||
|
||||
func (e *CommsSmsmessagetype) UnmarshalText(text []byte) error {
|
||||
func (e *CommsMessagetypetext) UnmarshalText(text []byte) error {
|
||||
return e.Scan(text)
|
||||
}
|
||||
|
||||
func (e CommsSmsmessagetype) MarshalBinary() ([]byte, error) {
|
||||
func (e CommsMessagetypetext) MarshalBinary() ([]byte, error) {
|
||||
return []byte(e), nil
|
||||
}
|
||||
|
||||
func (e *CommsSmsmessagetype) UnmarshalBinary(data []byte) error {
|
||||
func (e *CommsMessagetypetext) UnmarshalBinary(data []byte) error {
|
||||
return e.Scan(data)
|
||||
}
|
||||
|
||||
func (e CommsSmsmessagetype) Value() (driver.Value, error) {
|
||||
func (e CommsMessagetypetext) Value() (driver.Value, error) {
|
||||
return string(e), nil
|
||||
}
|
||||
|
||||
func (e *CommsSmsmessagetype) Scan(value any) error {
|
||||
func (e *CommsMessagetypetext) Scan(value any) error {
|
||||
switch x := value.(type) {
|
||||
case string:
|
||||
*e = CommsSmsmessagetype(x)
|
||||
*e = CommsMessagetypetext(x)
|
||||
case []byte:
|
||||
*e = CommsSmsmessagetype(x)
|
||||
*e = CommsMessagetypetext(x)
|
||||
case nil:
|
||||
return fmt.Errorf("cannot nil into CommsSmsmessagetype")
|
||||
return fmt.Errorf("cannot nil into CommsMessagetypetext")
|
||||
default:
|
||||
return fmt.Errorf("cannot scan type %T: %v", value, value)
|
||||
}
|
||||
|
||||
if !e.Valid() {
|
||||
return fmt.Errorf("invalid CommsSmsmessagetype value: %s", *e)
|
||||
return fmt.Errorf("invalid CommsMessagetypetext value: %s", *e)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -27,15 +27,15 @@ var (
|
|||
commsEmailLogRelSourcePhoneCtx = newContextual[bool]("comms.email_log.comms.phone.comms.email_log.email_log_source_fkey")
|
||||
|
||||
// Relationship Contexts for comms.phone
|
||||
commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading")
|
||||
commsPhoneRelSourceEmailLogsCtx = newContextual[bool]("comms.email_log.comms.phone.comms.email_log.email_log_source_fkey")
|
||||
commsPhoneRelDestinationSMSLogsCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_destination_fkey")
|
||||
commsPhoneRelSourceSMSLogsCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_source_fkey")
|
||||
commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading")
|
||||
commsPhoneRelSourceEmailLogsCtx = newContextual[bool]("comms.email_log.comms.phone.comms.email_log.email_log_source_fkey")
|
||||
commsPhoneRelDestinationTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey")
|
||||
commsPhoneRelSourceTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_source_fkey")
|
||||
|
||||
// Relationship Contexts for comms.sms_log
|
||||
commsSMSLogWithParentsCascadingCtx = newContextual[bool]("commsSMSLogWithParentsCascading")
|
||||
commsSMSLogRelDestinationPhoneCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_destination_fkey")
|
||||
commsSMSLogRelSourcePhoneCtx = newContextual[bool]("comms.phone.comms.sms_log.comms.sms_log.sms_log_source_fkey")
|
||||
// Relationship Contexts for comms.text_log
|
||||
commsTextLogWithParentsCascadingCtx = newContextual[bool]("commsTextLogWithParentsCascading")
|
||||
commsTextLogRelDestinationPhoneCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey")
|
||||
commsTextLogRelSourcePhoneCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_source_fkey")
|
||||
|
||||
// Relationship Contexts for fieldseeker.containerrelate
|
||||
fieldseekerContainerrelateWithParentsCascadingCtx = newContextual[bool]("fieldseekerContainerrelateWithParentsCascading")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ type Factory struct {
|
|||
baseCommsEmailMods CommsEmailModSlice
|
||||
baseCommsEmailLogMods CommsEmailLogModSlice
|
||||
baseCommsPhoneMods CommsPhoneModSlice
|
||||
baseCommsSMSLogMods CommsSMSLogModSlice
|
||||
baseCommsTextLogMods CommsTextLogModSlice
|
||||
baseFieldseekerContainerrelateMods FieldseekerContainerrelateModSlice
|
||||
baseFieldseekerFieldscoutinglogMods FieldseekerFieldscoutinglogModSlice
|
||||
baseFieldseekerHabitatrelateMods FieldseekerHabitatrelateModSlice
|
||||
|
|
@ -213,7 +213,7 @@ func (f *Factory) FromExistingCommsEmailLog(m *models.CommsEmailLog) *CommsEmail
|
|||
o.Created = func() time.Time { return m.Created }
|
||||
o.Destination = func() string { return m.Destination }
|
||||
o.Source = func() string { return m.Source }
|
||||
o.Type = func() enums.CommsEmailmessagetype { return m.Type }
|
||||
o.Type = func() enums.CommsMessagetypeemail { return m.Type }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.DestinationEmail != nil {
|
||||
|
|
@ -252,46 +252,46 @@ func (f *Factory) FromExistingCommsPhone(m *models.CommsPhone) *CommsPhoneTempla
|
|||
if len(m.R.SourceEmailLogs) > 0 {
|
||||
CommsPhoneMods.AddExistingSourceEmailLogs(m.R.SourceEmailLogs...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.DestinationSMSLogs) > 0 {
|
||||
CommsPhoneMods.AddExistingDestinationSMSLogs(m.R.DestinationSMSLogs...).Apply(ctx, o)
|
||||
if len(m.R.DestinationTextLogs) > 0 {
|
||||
CommsPhoneMods.AddExistingDestinationTextLogs(m.R.DestinationTextLogs...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.SourceSMSLogs) > 0 {
|
||||
CommsPhoneMods.AddExistingSourceSMSLogs(m.R.SourceSMSLogs...).Apply(ctx, o)
|
||||
if len(m.R.SourceTextLogs) > 0 {
|
||||
CommsPhoneMods.AddExistingSourceTextLogs(m.R.SourceTextLogs...).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) NewCommsSMSLog(mods ...CommsSMSLogMod) *CommsSMSLogTemplate {
|
||||
return f.NewCommsSMSLogWithContext(context.Background(), mods...)
|
||||
func (f *Factory) NewCommsTextLog(mods ...CommsTextLogMod) *CommsTextLogTemplate {
|
||||
return f.NewCommsTextLogWithContext(context.Background(), mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) NewCommsSMSLogWithContext(ctx context.Context, mods ...CommsSMSLogMod) *CommsSMSLogTemplate {
|
||||
o := &CommsSMSLogTemplate{f: f}
|
||||
func (f *Factory) NewCommsTextLogWithContext(ctx context.Context, mods ...CommsTextLogMod) *CommsTextLogTemplate {
|
||||
o := &CommsTextLogTemplate{f: f}
|
||||
|
||||
if f != nil {
|
||||
f.baseCommsSMSLogMods.Apply(ctx, o)
|
||||
f.baseCommsTextLogMods.Apply(ctx, o)
|
||||
}
|
||||
|
||||
CommsSMSLogModSlice(mods).Apply(ctx, o)
|
||||
CommsTextLogModSlice(mods).Apply(ctx, o)
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (f *Factory) FromExistingCommsSMSLog(m *models.CommsSMSLog) *CommsSMSLogTemplate {
|
||||
o := &CommsSMSLogTemplate{f: f, alreadyPersisted: true}
|
||||
func (f *Factory) FromExistingCommsTextLog(m *models.CommsTextLog) *CommsTextLogTemplate {
|
||||
o := &CommsTextLogTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.Created = func() time.Time { return m.Created }
|
||||
o.Destination = func() string { return m.Destination }
|
||||
o.Source = func() string { return m.Source }
|
||||
o.Type = func() enums.CommsSmsmessagetype { return m.Type }
|
||||
o.Type = func() enums.CommsMessagetypetext { return m.Type }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.DestinationPhone != nil {
|
||||
CommsSMSLogMods.WithExistingDestinationPhone(m.R.DestinationPhone).Apply(ctx, o)
|
||||
CommsTextLogMods.WithExistingDestinationPhone(m.R.DestinationPhone).Apply(ctx, o)
|
||||
}
|
||||
if m.R.SourcePhone != nil {
|
||||
CommsSMSLogMods.WithExistingSourcePhone(m.R.SourcePhone).Apply(ctx, o)
|
||||
CommsTextLogMods.WithExistingSourcePhone(m.R.SourcePhone).Apply(ctx, o)
|
||||
}
|
||||
|
||||
return o
|
||||
|
|
@ -3198,12 +3198,12 @@ func (f *Factory) AddBaseCommsPhoneMod(mods ...CommsPhoneMod) {
|
|||
f.baseCommsPhoneMods = append(f.baseCommsPhoneMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBaseCommsSMSLogMods() {
|
||||
f.baseCommsSMSLogMods = nil
|
||||
func (f *Factory) ClearBaseCommsTextLogMods() {
|
||||
f.baseCommsTextLogMods = nil
|
||||
}
|
||||
|
||||
func (f *Factory) AddBaseCommsSMSLogMod(mods ...CommsSMSLogMod) {
|
||||
f.baseCommsSMSLogMods = append(f.baseCommsSMSLogMods, mods...)
|
||||
func (f *Factory) AddBaseCommsTextLogMod(mods ...CommsTextLogMod) {
|
||||
f.baseCommsTextLogMods = append(f.baseCommsTextLogMods, mods...)
|
||||
}
|
||||
|
||||
func (f *Factory) ClearBaseFieldseekerContainerrelateMods() {
|
||||
|
|
|
|||
|
|
@ -89,22 +89,22 @@ func random_enums_Audiodatatype(f *faker.Faker, limits ...string) enums.Audiodat
|
|||
return all[f.IntBetween(0, len(all)-1)]
|
||||
}
|
||||
|
||||
func random_enums_CommsEmailmessagetype(f *faker.Faker, limits ...string) enums.CommsEmailmessagetype {
|
||||
func random_enums_CommsMessagetypeemail(f *faker.Faker, limits ...string) enums.CommsMessagetypeemail {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
var e enums.CommsEmailmessagetype
|
||||
var e enums.CommsMessagetypeemail
|
||||
all := e.All()
|
||||
return all[f.IntBetween(0, len(all)-1)]
|
||||
}
|
||||
|
||||
func random_enums_CommsSmsmessagetype(f *faker.Faker, limits ...string) enums.CommsSmsmessagetype {
|
||||
func random_enums_CommsMessagetypetext(f *faker.Faker, limits ...string) enums.CommsMessagetypetext {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
var e enums.CommsSmsmessagetype
|
||||
var e enums.CommsMessagetypetext
|
||||
all := e.All()
|
||||
return all[f.IntBetween(0, len(all)-1)]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ type CommsEmailLogTemplate struct {
|
|||
Created func() time.Time
|
||||
Destination func() string
|
||||
Source func() string
|
||||
Type func() enums.CommsEmailmessagetype
|
||||
Type func() enums.CommsMessagetypeemail
|
||||
|
||||
r commsEmailLogR
|
||||
f *Factory
|
||||
|
|
@ -172,7 +172,7 @@ func ensureCreatableCommsEmailLog(m *models.CommsEmailLogSetter) {
|
|||
m.Source = omit.From(val)
|
||||
}
|
||||
if !(m.Type.IsValue()) {
|
||||
val := random_enums_CommsEmailmessagetype(nil)
|
||||
val := random_enums_CommsMessagetypeemail(nil)
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
|
@ -413,14 +413,14 @@ func (m commsEmailLogMods) RandomSource(f *faker.Faker) CommsEmailLogMod {
|
|||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsEmailLogMods) Type(val enums.CommsEmailmessagetype) CommsEmailLogMod {
|
||||
func (m commsEmailLogMods) Type(val enums.CommsMessagetypeemail) CommsEmailLogMod {
|
||||
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
|
||||
o.Type = func() enums.CommsEmailmessagetype { return val }
|
||||
o.Type = func() enums.CommsMessagetypeemail { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsEmailLogMods) TypeFunc(f func() enums.CommsEmailmessagetype) CommsEmailLogMod {
|
||||
func (m commsEmailLogMods) TypeFunc(f func() enums.CommsMessagetypeemail) CommsEmailLogMod {
|
||||
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
|
||||
o.Type = f
|
||||
})
|
||||
|
|
@ -437,8 +437,8 @@ func (m commsEmailLogMods) UnsetType() CommsEmailLogMod {
|
|||
// if faker is nil, a default faker is used
|
||||
func (m commsEmailLogMods) RandomType(f *faker.Faker) CommsEmailLogMod {
|
||||
return CommsEmailLogModFunc(func(_ context.Context, o *CommsEmailLogTemplate) {
|
||||
o.Type = func() enums.CommsEmailmessagetype {
|
||||
return random_enums_CommsEmailmessagetype(f)
|
||||
o.Type = func() enums.CommsMessagetypeemail {
|
||||
return random_enums_CommsMessagetypeemail(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,22 +44,22 @@ type CommsPhoneTemplate struct {
|
|||
}
|
||||
|
||||
type commsPhoneR struct {
|
||||
SourceEmailLogs []*commsPhoneRSourceEmailLogsR
|
||||
DestinationSMSLogs []*commsPhoneRDestinationSMSLogsR
|
||||
SourceSMSLogs []*commsPhoneRSourceSMSLogsR
|
||||
SourceEmailLogs []*commsPhoneRSourceEmailLogsR
|
||||
DestinationTextLogs []*commsPhoneRDestinationTextLogsR
|
||||
SourceTextLogs []*commsPhoneRSourceTextLogsR
|
||||
}
|
||||
|
||||
type commsPhoneRSourceEmailLogsR struct {
|
||||
number int
|
||||
o *CommsEmailLogTemplate
|
||||
}
|
||||
type commsPhoneRDestinationSMSLogsR struct {
|
||||
type commsPhoneRDestinationTextLogsR struct {
|
||||
number int
|
||||
o *CommsSMSLogTemplate
|
||||
o *CommsTextLogTemplate
|
||||
}
|
||||
type commsPhoneRSourceSMSLogsR struct {
|
||||
type commsPhoneRSourceTextLogsR struct {
|
||||
number int
|
||||
o *CommsSMSLogTemplate
|
||||
o *CommsTextLogTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the CommsPhoneTemplate
|
||||
|
|
@ -85,9 +85,9 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
|
|||
o.R.SourceEmailLogs = rel
|
||||
}
|
||||
|
||||
if t.r.DestinationSMSLogs != nil {
|
||||
rel := models.CommsSMSLogSlice{}
|
||||
for _, r := range t.r.DestinationSMSLogs {
|
||||
if t.r.DestinationTextLogs != nil {
|
||||
rel := models.CommsTextLogSlice{}
|
||||
for _, r := range t.r.DestinationTextLogs {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.Destination = o.E164 // h2
|
||||
|
|
@ -95,12 +95,12 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
|
|||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.DestinationSMSLogs = rel
|
||||
o.R.DestinationTextLogs = rel
|
||||
}
|
||||
|
||||
if t.r.SourceSMSLogs != nil {
|
||||
rel := models.CommsSMSLogSlice{}
|
||||
for _, r := range t.r.SourceSMSLogs {
|
||||
if t.r.SourceTextLogs != nil {
|
||||
rel := models.CommsTextLogSlice{}
|
||||
for _, r := range t.r.SourceTextLogs {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.Source = o.E164 // h2
|
||||
|
|
@ -108,7 +108,7 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
|
|||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.SourceSMSLogs = rel
|
||||
o.R.SourceTextLogs = rel
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,19 +209,19 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo
|
|||
}
|
||||
}
|
||||
|
||||
isDestinationSMSLogsDone, _ := commsPhoneRelDestinationSMSLogsCtx.Value(ctx)
|
||||
if !isDestinationSMSLogsDone && o.r.DestinationSMSLogs != nil {
|
||||
ctx = commsPhoneRelDestinationSMSLogsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.DestinationSMSLogs {
|
||||
isDestinationTextLogsDone, _ := commsPhoneRelDestinationTextLogsCtx.Value(ctx)
|
||||
if !isDestinationTextLogsDone && o.r.DestinationTextLogs != nil {
|
||||
ctx = commsPhoneRelDestinationTextLogsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.DestinationTextLogs {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.DestinationSMSLogs = append(m.R.DestinationSMSLogs, r.o.Build())
|
||||
m.R.DestinationTextLogs = append(m.R.DestinationTextLogs, r.o.Build())
|
||||
} else {
|
||||
rel1, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachDestinationSMSLogs(ctx, exec, rel1...)
|
||||
err = m.AttachDestinationTextLogs(ctx, exec, rel1...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -229,19 +229,19 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo
|
|||
}
|
||||
}
|
||||
|
||||
isSourceSMSLogsDone, _ := commsPhoneRelSourceSMSLogsCtx.Value(ctx)
|
||||
if !isSourceSMSLogsDone && o.r.SourceSMSLogs != nil {
|
||||
ctx = commsPhoneRelSourceSMSLogsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.SourceSMSLogs {
|
||||
isSourceTextLogsDone, _ := commsPhoneRelSourceTextLogsCtx.Value(ctx)
|
||||
if !isSourceTextLogsDone && o.r.SourceTextLogs != nil {
|
||||
ctx = commsPhoneRelSourceTextLogsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.SourceTextLogs {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.SourceSMSLogs = append(m.R.SourceSMSLogs, r.o.Build())
|
||||
m.R.SourceTextLogs = append(m.R.SourceTextLogs, r.o.Build())
|
||||
} else {
|
||||
rel2, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachSourceSMSLogs(ctx, exec, rel2...)
|
||||
err = m.AttachSourceTextLogs(ctx, exec, rel2...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -465,98 +465,98 @@ func (m commsPhoneMods) WithoutSourceEmailLogs() CommsPhoneMod {
|
|||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) WithDestinationSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
|
||||
func (m commsPhoneMods) WithDestinationTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
o.r.DestinationSMSLogs = []*commsPhoneRDestinationSMSLogsR{{
|
||||
o.r.DestinationTextLogs = []*commsPhoneRDestinationTextLogsR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) WithNewDestinationSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
|
||||
func (m commsPhoneMods) WithNewDestinationTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
|
||||
m.WithDestinationSMSLogs(number, related).Apply(ctx, o)
|
||||
related := o.f.NewCommsTextLogWithContext(ctx, mods...)
|
||||
m.WithDestinationTextLogs(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) AddDestinationSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
|
||||
func (m commsPhoneMods) AddDestinationTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
o.r.DestinationSMSLogs = append(o.r.DestinationSMSLogs, &commsPhoneRDestinationSMSLogsR{
|
||||
o.r.DestinationTextLogs = append(o.r.DestinationTextLogs, &commsPhoneRDestinationTextLogsR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) AddNewDestinationSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
|
||||
func (m commsPhoneMods) AddNewDestinationTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
|
||||
m.AddDestinationSMSLogs(number, related).Apply(ctx, o)
|
||||
related := o.f.NewCommsTextLogWithContext(ctx, mods...)
|
||||
m.AddDestinationTextLogs(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) AddExistingDestinationSMSLogs(existingModels ...*models.CommsSMSLog) CommsPhoneMod {
|
||||
func (m commsPhoneMods) AddExistingDestinationTextLogs(existingModels ...*models.CommsTextLog) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.DestinationSMSLogs = append(o.r.DestinationSMSLogs, &commsPhoneRDestinationSMSLogsR{
|
||||
o: o.f.FromExistingCommsSMSLog(em),
|
||||
o.r.DestinationTextLogs = append(o.r.DestinationTextLogs, &commsPhoneRDestinationTextLogsR{
|
||||
o: o.f.FromExistingCommsTextLog(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) WithoutDestinationSMSLogs() CommsPhoneMod {
|
||||
func (m commsPhoneMods) WithoutDestinationTextLogs() CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
o.r.DestinationSMSLogs = nil
|
||||
o.r.DestinationTextLogs = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) WithSourceSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
|
||||
func (m commsPhoneMods) WithSourceTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
o.r.SourceSMSLogs = []*commsPhoneRSourceSMSLogsR{{
|
||||
o.r.SourceTextLogs = []*commsPhoneRSourceTextLogsR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) WithNewSourceSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
|
||||
func (m commsPhoneMods) WithNewSourceTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
|
||||
m.WithSourceSMSLogs(number, related).Apply(ctx, o)
|
||||
related := o.f.NewCommsTextLogWithContext(ctx, mods...)
|
||||
m.WithSourceTextLogs(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) AddSourceSMSLogs(number int, related *CommsSMSLogTemplate) CommsPhoneMod {
|
||||
func (m commsPhoneMods) AddSourceTextLogs(number int, related *CommsTextLogTemplate) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
o.r.SourceSMSLogs = append(o.r.SourceSMSLogs, &commsPhoneRSourceSMSLogsR{
|
||||
o.r.SourceTextLogs = append(o.r.SourceTextLogs, &commsPhoneRSourceTextLogsR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) AddNewSourceSMSLogs(number int, mods ...CommsSMSLogMod) CommsPhoneMod {
|
||||
func (m commsPhoneMods) AddNewSourceTextLogs(number int, mods ...CommsTextLogMod) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
related := o.f.NewCommsSMSLogWithContext(ctx, mods...)
|
||||
m.AddSourceSMSLogs(number, related).Apply(ctx, o)
|
||||
related := o.f.NewCommsTextLogWithContext(ctx, mods...)
|
||||
m.AddSourceTextLogs(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) AddExistingSourceSMSLogs(existingModels ...*models.CommsSMSLog) CommsPhoneMod {
|
||||
func (m commsPhoneMods) AddExistingSourceTextLogs(existingModels ...*models.CommsTextLog) CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.SourceSMSLogs = append(o.r.SourceSMSLogs, &commsPhoneRSourceSMSLogsR{
|
||||
o: o.f.FromExistingCommsSMSLog(em),
|
||||
o.r.SourceTextLogs = append(o.r.SourceTextLogs, &commsPhoneRSourceTextLogsR{
|
||||
o: o.f.FromExistingCommsTextLog(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsPhoneMods) WithoutSourceSMSLogs() CommsPhoneMod {
|
||||
func (m commsPhoneMods) WithoutSourceTextLogs() CommsPhoneMod {
|
||||
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
|
||||
o.r.SourceSMSLogs = nil
|
||||
o.r.SourceTextLogs = nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,523 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type CommsSMSLogMod interface {
|
||||
Apply(context.Context, *CommsSMSLogTemplate)
|
||||
}
|
||||
|
||||
type CommsSMSLogModFunc func(context.Context, *CommsSMSLogTemplate)
|
||||
|
||||
func (f CommsSMSLogModFunc) Apply(ctx context.Context, n *CommsSMSLogTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type CommsSMSLogModSlice []CommsSMSLogMod
|
||||
|
||||
func (mods CommsSMSLogModSlice) Apply(ctx context.Context, n *CommsSMSLogTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// CommsSMSLogTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type CommsSMSLogTemplate struct {
|
||||
Created func() time.Time
|
||||
Destination func() string
|
||||
Source func() string
|
||||
Type func() enums.CommsSmsmessagetype
|
||||
|
||||
r commsSMSLogR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type commsSMSLogR struct {
|
||||
DestinationPhone *commsSMSLogRDestinationPhoneR
|
||||
SourcePhone *commsSMSLogRSourcePhoneR
|
||||
}
|
||||
|
||||
type commsSMSLogRDestinationPhoneR struct {
|
||||
o *CommsPhoneTemplate
|
||||
}
|
||||
type commsSMSLogRSourcePhoneR struct {
|
||||
o *CommsPhoneTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the CommsSMSLogTemplate
|
||||
func (o *CommsSMSLogTemplate) Apply(ctx context.Context, mods ...CommsSMSLogMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.CommsSMSLog
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t CommsSMSLogTemplate) setModelRels(o *models.CommsSMSLog) {
|
||||
if t.r.DestinationPhone != nil {
|
||||
rel := t.r.DestinationPhone.o.Build()
|
||||
rel.R.DestinationSMSLogs = append(rel.R.DestinationSMSLogs, o)
|
||||
o.Destination = rel.E164 // h2
|
||||
o.R.DestinationPhone = rel
|
||||
}
|
||||
|
||||
if t.r.SourcePhone != nil {
|
||||
rel := t.r.SourcePhone.o.Build()
|
||||
rel.R.SourceSMSLogs = append(rel.R.SourceSMSLogs, o)
|
||||
o.Source = rel.E164 // h2
|
||||
o.R.SourcePhone = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.CommsSMSLogSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o CommsSMSLogTemplate) BuildSetter() *models.CommsSMSLogSetter {
|
||||
m := &models.CommsSMSLogSetter{}
|
||||
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if o.Destination != nil {
|
||||
val := o.Destination()
|
||||
m.Destination = omit.From(val)
|
||||
}
|
||||
if o.Source != nil {
|
||||
val := o.Source()
|
||||
m.Source = omit.From(val)
|
||||
}
|
||||
if o.Type != nil {
|
||||
val := o.Type()
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.CommsSMSLogSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o CommsSMSLogTemplate) BuildManySetter(number int) []*models.CommsSMSLogSetter {
|
||||
m := make([]*models.CommsSMSLogSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.CommsSMSLog
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use CommsSMSLogTemplate.Create
|
||||
func (o CommsSMSLogTemplate) Build() *models.CommsSMSLog {
|
||||
m := &models.CommsSMSLog{}
|
||||
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
if o.Destination != nil {
|
||||
m.Destination = o.Destination()
|
||||
}
|
||||
if o.Source != nil {
|
||||
m.Source = o.Source()
|
||||
}
|
||||
if o.Type != nil {
|
||||
m.Type = o.Type()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.CommsSMSLogSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use CommsSMSLogTemplate.CreateMany
|
||||
func (o CommsSMSLogTemplate) BuildMany(number int) models.CommsSMSLogSlice {
|
||||
m := make(models.CommsSMSLogSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatableCommsSMSLog(m *models.CommsSMSLogSetter) {
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if !(m.Destination.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Destination = omit.From(val)
|
||||
}
|
||||
if !(m.Source.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Source = omit.From(val)
|
||||
}
|
||||
if !(m.Type.IsValue()) {
|
||||
val := random_enums_CommsSmsmessagetype(nil)
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.CommsSMSLog
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *CommsSMSLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsSMSLog) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a commsSMSLog and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *CommsSMSLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsSMSLog, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatableCommsSMSLog(opt)
|
||||
|
||||
if o.r.DestinationPhone == nil {
|
||||
CommsSMSLogMods.WithNewDestinationPhone().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.CommsPhone
|
||||
|
||||
if o.r.DestinationPhone.o.alreadyPersisted {
|
||||
rel0 = o.r.DestinationPhone.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.DestinationPhone.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.Destination = omit.From(rel0.E164)
|
||||
|
||||
if o.r.SourcePhone == nil {
|
||||
CommsSMSLogMods.WithNewSourcePhone().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel1 *models.CommsPhone
|
||||
|
||||
if o.r.SourcePhone.o.alreadyPersisted {
|
||||
rel1 = o.r.SourcePhone.o.Build()
|
||||
} else {
|
||||
rel1, err = o.r.SourcePhone.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.Source = omit.From(rel1.E164)
|
||||
|
||||
m, err := models.CommsSMSLogs.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.DestinationPhone = rel0
|
||||
m.R.SourcePhone = rel1
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a commsSMSLog and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *CommsSMSLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsSMSLog {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a commsSMSLog and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *CommsSMSLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsSMSLog {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple commsSMSLogs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o CommsSMSLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsSMSLogSlice, error) {
|
||||
var err error
|
||||
m := make(models.CommsSMSLogSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple commsSMSLogs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o CommsSMSLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsSMSLogSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple commsSMSLogs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o CommsSMSLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsSMSLogSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CommsSMSLog has methods that act as mods for the CommsSMSLogTemplate
|
||||
var CommsSMSLogMods commsSMSLogMods
|
||||
|
||||
type commsSMSLogMods struct{}
|
||||
|
||||
func (m commsSMSLogMods) RandomizeAllColumns(f *faker.Faker) CommsSMSLogMod {
|
||||
return CommsSMSLogModSlice{
|
||||
CommsSMSLogMods.RandomCreated(f),
|
||||
CommsSMSLogMods.RandomDestination(f),
|
||||
CommsSMSLogMods.RandomSource(f),
|
||||
CommsSMSLogMods.RandomType(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsSMSLogMods) Created(val time.Time) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Created = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsSMSLogMods) CreatedFunc(f func() time.Time) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsSMSLogMods) UnsetCreated() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsSMSLogMods) RandomCreated(f *faker.Faker) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Created = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsSMSLogMods) Destination(val string) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Destination = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsSMSLogMods) DestinationFunc(f func() string) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Destination = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsSMSLogMods) UnsetDestination() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Destination = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsSMSLogMods) RandomDestination(f *faker.Faker) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Destination = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsSMSLogMods) Source(val string) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Source = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsSMSLogMods) SourceFunc(f func() string) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Source = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsSMSLogMods) UnsetSource() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Source = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsSMSLogMods) RandomSource(f *faker.Faker) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Source = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsSMSLogMods) Type(val enums.CommsSmsmessagetype) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Type = func() enums.CommsSmsmessagetype { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsSMSLogMods) TypeFunc(f func() enums.CommsSmsmessagetype) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Type = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsSMSLogMods) UnsetType() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Type = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsSMSLogMods) RandomType(f *faker.Faker) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(_ context.Context, o *CommsSMSLogTemplate) {
|
||||
o.Type = func() enums.CommsSmsmessagetype {
|
||||
return random_enums_CommsSmsmessagetype(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithParentsCascading() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
if isDone, _ := commsSMSLogWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = commsSMSLogWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
||||
m.WithDestinationPhone(related).Apply(ctx, o)
|
||||
}
|
||||
{
|
||||
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
||||
m.WithSourcePhone(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithDestinationPhone(rel *CommsPhoneTemplate) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
o.r.DestinationPhone = &commsSMSLogRDestinationPhoneR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithNewDestinationPhone(mods ...CommsPhoneMod) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
|
||||
|
||||
m.WithDestinationPhone(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithExistingDestinationPhone(em *models.CommsPhone) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
o.r.DestinationPhone = &commsSMSLogRDestinationPhoneR{
|
||||
o: o.f.FromExistingCommsPhone(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithoutDestinationPhone() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
o.r.DestinationPhone = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
o.r.SourcePhone = &commsSMSLogRSourcePhoneR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
|
||||
|
||||
m.WithSourcePhone(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
o.r.SourcePhone = &commsSMSLogRSourcePhoneR{
|
||||
o: o.f.FromExistingCommsPhone(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsSMSLogMods) WithoutSourcePhone() CommsSMSLogMod {
|
||||
return CommsSMSLogModFunc(func(ctx context.Context, o *CommsSMSLogTemplate) {
|
||||
o.r.SourcePhone = nil
|
||||
})
|
||||
}
|
||||
523
db/factory/comms.text_log.bob.go
Normal file
523
db/factory/comms.text_log.bob.go
Normal file
|
|
@ -0,0 +1,523 @@
|
|||
// Code generated by BobGen psql v0.42.1. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package factory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
||||
type CommsTextLogMod interface {
|
||||
Apply(context.Context, *CommsTextLogTemplate)
|
||||
}
|
||||
|
||||
type CommsTextLogModFunc func(context.Context, *CommsTextLogTemplate)
|
||||
|
||||
func (f CommsTextLogModFunc) Apply(ctx context.Context, n *CommsTextLogTemplate) {
|
||||
f(ctx, n)
|
||||
}
|
||||
|
||||
type CommsTextLogModSlice []CommsTextLogMod
|
||||
|
||||
func (mods CommsTextLogModSlice) Apply(ctx context.Context, n *CommsTextLogTemplate) {
|
||||
for _, f := range mods {
|
||||
f.Apply(ctx, n)
|
||||
}
|
||||
}
|
||||
|
||||
// CommsTextLogTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type CommsTextLogTemplate struct {
|
||||
Created func() time.Time
|
||||
Destination func() string
|
||||
Source func() string
|
||||
Type func() enums.CommsMessagetypetext
|
||||
|
||||
r commsTextLogR
|
||||
f *Factory
|
||||
|
||||
alreadyPersisted bool
|
||||
}
|
||||
|
||||
type commsTextLogR struct {
|
||||
DestinationPhone *commsTextLogRDestinationPhoneR
|
||||
SourcePhone *commsTextLogRSourcePhoneR
|
||||
}
|
||||
|
||||
type commsTextLogRDestinationPhoneR struct {
|
||||
o *CommsPhoneTemplate
|
||||
}
|
||||
type commsTextLogRSourcePhoneR struct {
|
||||
o *CommsPhoneTemplate
|
||||
}
|
||||
|
||||
// Apply mods to the CommsTextLogTemplate
|
||||
func (o *CommsTextLogTemplate) Apply(ctx context.Context, mods ...CommsTextLogMod) {
|
||||
for _, mod := range mods {
|
||||
mod.Apply(ctx, o)
|
||||
}
|
||||
}
|
||||
|
||||
// setModelRels creates and sets the relationships on *models.CommsTextLog
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t CommsTextLogTemplate) setModelRels(o *models.CommsTextLog) {
|
||||
if t.r.DestinationPhone != nil {
|
||||
rel := t.r.DestinationPhone.o.Build()
|
||||
rel.R.DestinationTextLogs = append(rel.R.DestinationTextLogs, o)
|
||||
o.Destination = rel.E164 // h2
|
||||
o.R.DestinationPhone = rel
|
||||
}
|
||||
|
||||
if t.r.SourcePhone != nil {
|
||||
rel := t.r.SourcePhone.o.Build()
|
||||
rel.R.SourceTextLogs = append(rel.R.SourceTextLogs, o)
|
||||
o.Source = rel.E164 // h2
|
||||
o.R.SourcePhone = rel
|
||||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.CommsTextLogSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o CommsTextLogTemplate) BuildSetter() *models.CommsTextLogSetter {
|
||||
m := &models.CommsTextLogSetter{}
|
||||
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if o.Destination != nil {
|
||||
val := o.Destination()
|
||||
m.Destination = omit.From(val)
|
||||
}
|
||||
if o.Source != nil {
|
||||
val := o.Source()
|
||||
m.Source = omit.From(val)
|
||||
}
|
||||
if o.Type != nil {
|
||||
val := o.Type()
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.CommsTextLogSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o CommsTextLogTemplate) BuildManySetter(number int) []*models.CommsTextLogSetter {
|
||||
m := make([]*models.CommsTextLogSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.CommsTextLog
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use CommsTextLogTemplate.Create
|
||||
func (o CommsTextLogTemplate) Build() *models.CommsTextLog {
|
||||
m := &models.CommsTextLog{}
|
||||
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
if o.Destination != nil {
|
||||
m.Destination = o.Destination()
|
||||
}
|
||||
if o.Source != nil {
|
||||
m.Source = o.Source()
|
||||
}
|
||||
if o.Type != nil {
|
||||
m.Type = o.Type()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildMany returns an models.CommsTextLogSlice
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use CommsTextLogTemplate.CreateMany
|
||||
func (o CommsTextLogTemplate) BuildMany(number int) models.CommsTextLogSlice {
|
||||
m := make(models.CommsTextLogSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.Build()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func ensureCreatableCommsTextLog(m *models.CommsTextLogSetter) {
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if !(m.Destination.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Destination = omit.From(val)
|
||||
}
|
||||
if !(m.Source.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Source = omit.From(val)
|
||||
}
|
||||
if !(m.Type.IsValue()) {
|
||||
val := random_enums_CommsMessagetypetext(nil)
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.CommsTextLog
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *CommsTextLogTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.CommsTextLog) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a commsTextLog and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *CommsTextLogTemplate) Create(ctx context.Context, exec bob.Executor) (*models.CommsTextLog, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatableCommsTextLog(opt)
|
||||
|
||||
if o.r.DestinationPhone == nil {
|
||||
CommsTextLogMods.WithNewDestinationPhone().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.CommsPhone
|
||||
|
||||
if o.r.DestinationPhone.o.alreadyPersisted {
|
||||
rel0 = o.r.DestinationPhone.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.DestinationPhone.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.Destination = omit.From(rel0.E164)
|
||||
|
||||
if o.r.SourcePhone == nil {
|
||||
CommsTextLogMods.WithNewSourcePhone().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel1 *models.CommsPhone
|
||||
|
||||
if o.r.SourcePhone.o.alreadyPersisted {
|
||||
rel1 = o.r.SourcePhone.o.Build()
|
||||
} else {
|
||||
rel1, err = o.r.SourcePhone.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.Source = omit.From(rel1.E164)
|
||||
|
||||
m, err := models.CommsTextLogs.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.DestinationPhone = rel0
|
||||
m.R.SourcePhone = rel1
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a commsTextLog and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *CommsTextLogTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.CommsTextLog {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a commsTextLog and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o *CommsTextLogTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.CommsTextLog {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple commsTextLogs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o CommsTextLogTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.CommsTextLogSlice, error) {
|
||||
var err error
|
||||
m := make(models.CommsTextLogSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple commsTextLogs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o CommsTextLogTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.CommsTextLogSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple commsTextLogs and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs
|
||||
func (o CommsTextLogTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.CommsTextLogSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CommsTextLog has methods that act as mods for the CommsTextLogTemplate
|
||||
var CommsTextLogMods commsTextLogMods
|
||||
|
||||
type commsTextLogMods struct{}
|
||||
|
||||
func (m commsTextLogMods) RandomizeAllColumns(f *faker.Faker) CommsTextLogMod {
|
||||
return CommsTextLogModSlice{
|
||||
CommsTextLogMods.RandomCreated(f),
|
||||
CommsTextLogMods.RandomDestination(f),
|
||||
CommsTextLogMods.RandomSource(f),
|
||||
CommsTextLogMods.RandomType(f),
|
||||
}
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsTextLogMods) Created(val time.Time) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Created = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsTextLogMods) CreatedFunc(f func() time.Time) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsTextLogMods) UnsetCreated() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsTextLogMods) RandomCreated(f *faker.Faker) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Created = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsTextLogMods) Destination(val string) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Destination = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsTextLogMods) DestinationFunc(f func() string) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Destination = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsTextLogMods) UnsetDestination() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Destination = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsTextLogMods) RandomDestination(f *faker.Faker) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Destination = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsTextLogMods) Source(val string) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Source = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsTextLogMods) SourceFunc(f func() string) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Source = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsTextLogMods) UnsetSource() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Source = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsTextLogMods) RandomSource(f *faker.Faker) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Source = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m commsTextLogMods) Type(val enums.CommsMessagetypetext) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Type = func() enums.CommsMessagetypetext { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m commsTextLogMods) TypeFunc(f func() enums.CommsMessagetypetext) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Type = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m commsTextLogMods) UnsetType() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Type = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m commsTextLogMods) RandomType(f *faker.Faker) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(_ context.Context, o *CommsTextLogTemplate) {
|
||||
o.Type = func() enums.CommsMessagetypetext {
|
||||
return random_enums_CommsMessagetypetext(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithParentsCascading() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
if isDone, _ := commsTextLogWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
return
|
||||
}
|
||||
ctx = commsTextLogWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
||||
m.WithDestinationPhone(related).Apply(ctx, o)
|
||||
}
|
||||
{
|
||||
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
||||
m.WithSourcePhone(related).Apply(ctx, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithDestinationPhone(rel *CommsPhoneTemplate) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
o.r.DestinationPhone = &commsTextLogRDestinationPhoneR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithNewDestinationPhone(mods ...CommsPhoneMod) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
|
||||
|
||||
m.WithDestinationPhone(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithExistingDestinationPhone(em *models.CommsPhone) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
o.r.DestinationPhone = &commsTextLogRDestinationPhoneR{
|
||||
o: o.f.FromExistingCommsPhone(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithoutDestinationPhone() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
o.r.DestinationPhone = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithSourcePhone(rel *CommsPhoneTemplate) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
o.r.SourcePhone = &commsTextLogRSourcePhoneR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithNewSourcePhone(mods ...CommsPhoneMod) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
|
||||
|
||||
m.WithSourcePhone(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithExistingSourcePhone(em *models.CommsPhone) CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
o.r.SourcePhone = &commsTextLogRSourcePhoneR{
|
||||
o: o.f.FromExistingCommsPhone(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m commsTextLogMods) WithoutSourcePhone() CommsTextLogMod {
|
||||
return CommsTextLogModFunc(func(ctx context.Context, o *CommsTextLogTemplate) {
|
||||
o.r.SourcePhone = nil
|
||||
})
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
-- +goose Up
|
||||
CREATE SCHEMA comms;
|
||||
CREATE TYPE comms.SMSMessageType AS ENUM (
|
||||
CREATE TYPE comms.MessageTypeText AS ENUM (
|
||||
'initial-contact',
|
||||
'report-subscription-confirmation',
|
||||
'report-status-scheduled',
|
||||
'report-status-complete'
|
||||
);
|
||||
CREATE TYPE comms.EmailMessageType AS ENUM (
|
||||
CREATE TYPE comms.MessageTypeEmail AS ENUM (
|
||||
'initial-contact',
|
||||
'report-subscription-confirmation',
|
||||
'report-status-scheduled',
|
||||
'report-status-complete'
|
||||
|
|
@ -15,11 +17,11 @@ CREATE TABLE comms.phone (
|
|||
is_subscribed BOOLEAN NOT NULL,
|
||||
PRIMARY KEY (e164)
|
||||
);
|
||||
CREATE TABLE comms.sms_log (
|
||||
CREATE TABLE comms.text_log (
|
||||
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
destination TEXT NOT NULL REFERENCES comms.phone(e164),
|
||||
source TEXT NOT NULL REFERENCES comms.phone(e164),
|
||||
type comms.SMSMessageType NOT NULL,
|
||||
type comms.MessageTypeText NOT NULL,
|
||||
PRIMARY KEY (destination, source, type)
|
||||
);
|
||||
CREATE TABLE comms.email (
|
||||
|
|
@ -32,6 +34,14 @@ CREATE TABLE comms.email_log (
|
|||
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
destination TEXT NOT NULL REFERENCES comms.email(address),
|
||||
source TEXT NOT NULL REFERENCES comms.phone(e164),
|
||||
type comms.EmailMessageType NOT NULL,
|
||||
type comms.MessageTypeEmail NOT NULL,
|
||||
PRIMARY KEY(destination, source, type)
|
||||
);
|
||||
-- +goose Down
|
||||
DROP TABLE comms.email_log;
|
||||
DROP TABLE comms.email;
|
||||
DROP TABLE comms.text_log;
|
||||
DROP TABLE comms.phone;
|
||||
DROP TYPE comms.MessageTypeEmail;
|
||||
DROP TYPE comms.MessageTypeText;
|
||||
DROP SCHEMA comms;
|
||||
|
|
|
|||
|
|
@ -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