Drop district_id from subscriptions
This commit is contained in:
parent
b25daf12fa
commit
d93cdbef41
17 changed files with 62 additions and 2533 deletions
|
|
@ -1,17 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportSubscribeEmailErrors = &publicreportSubscribeEmailErrors{
|
||||
ErrUniqueSubscribeEmailPkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "subscribe_email",
|
||||
columns: []string{"district_id", "email_address"},
|
||||
s: "subscribe_email_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportSubscribeEmailErrors struct {
|
||||
ErrUniqueSubscribeEmailPkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dberrors
|
||||
|
||||
var PublicreportSubscribePhoneErrors = &publicreportSubscribePhoneErrors{
|
||||
ErrUniqueSubscribePhonePkey: &UniqueConstraintError{
|
||||
schema: "publicreport",
|
||||
table: "subscribe_phone",
|
||||
columns: []string{"district_id", "phone_e164"},
|
||||
s: "subscribe_phone_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type publicreportSubscribePhoneErrors struct {
|
||||
ErrUniqueSubscribePhonePkey *UniqueConstraintError
|
||||
}
|
||||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportSubscribeEmails = Table[
|
||||
publicreportSubscribeEmailColumns,
|
||||
publicreportSubscribeEmailIndexes,
|
||||
|
|
@ -33,15 +31,6 @@ var PublicreportSubscribeEmails = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
DistrictID: column{
|
||||
Name: "district_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
EmailAddress: column{
|
||||
Name: "email_address",
|
||||
DBType: "text",
|
||||
|
|
@ -52,45 +41,8 @@ var PublicreportSubscribeEmails = Table[
|
|||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportSubscribeEmailIndexes{
|
||||
SubscribeEmailPkey: index{
|
||||
Type: "btree",
|
||||
Name: "subscribe_email_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "district_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "email_address",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "subscribe_email_pkey",
|
||||
Columns: []string{"district_id", "email_address"},
|
||||
Comment: "",
|
||||
},
|
||||
|
||||
ForeignKeys: publicreportSubscribeEmailForeignKeys{
|
||||
PublicreportSubscribeEmailSubscribeEmailDistrictIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.subscribe_email.subscribe_email_district_id_fkey",
|
||||
Columns: []string{"district_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "organization",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
PublicreportSubscribeEmailSubscribeEmailEmailAddressFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.subscribe_email.subscribe_email_email_address_fkey",
|
||||
|
|
@ -108,34 +60,28 @@ var PublicreportSubscribeEmails = Table[
|
|||
type publicreportSubscribeEmailColumns struct {
|
||||
Created column
|
||||
Deleted column
|
||||
DistrictID column
|
||||
EmailAddress column
|
||||
}
|
||||
|
||||
func (c publicreportSubscribeEmailColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Created, c.Deleted, c.DistrictID, c.EmailAddress,
|
||||
c.Created, c.Deleted, c.EmailAddress,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportSubscribeEmailIndexes struct {
|
||||
SubscribeEmailPkey index
|
||||
}
|
||||
type publicreportSubscribeEmailIndexes struct{}
|
||||
|
||||
func (i publicreportSubscribeEmailIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.SubscribeEmailPkey,
|
||||
}
|
||||
return []index{}
|
||||
}
|
||||
|
||||
type publicreportSubscribeEmailForeignKeys struct {
|
||||
PublicreportSubscribeEmailSubscribeEmailDistrictIDFkey foreignKey
|
||||
PublicreportSubscribeEmailSubscribeEmailEmailAddressFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportSubscribeEmailForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportSubscribeEmailSubscribeEmailDistrictIDFkey, f.PublicreportSubscribeEmailSubscribeEmailEmailAddressFkey,
|
||||
f.PublicreportSubscribeEmailSubscribeEmailEmailAddressFkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
package dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var PublicreportSubscribePhones = Table[
|
||||
publicreportSubscribePhoneColumns,
|
||||
publicreportSubscribePhoneIndexes,
|
||||
|
|
@ -33,15 +31,6 @@ var PublicreportSubscribePhones = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
DistrictID: column{
|
||||
Name: "district_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
PhoneE164: column{
|
||||
Name: "phone_e164",
|
||||
DBType: "text",
|
||||
|
|
@ -52,45 +41,8 @@ var PublicreportSubscribePhones = Table[
|
|||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportSubscribePhoneIndexes{
|
||||
SubscribePhonePkey: index{
|
||||
Type: "btree",
|
||||
Name: "subscribe_phone_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "district_id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "phone_e164",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "subscribe_phone_pkey",
|
||||
Columns: []string{"district_id", "phone_e164"},
|
||||
Comment: "",
|
||||
},
|
||||
|
||||
ForeignKeys: publicreportSubscribePhoneForeignKeys{
|
||||
PublicreportSubscribePhoneSubscribePhoneDistrictIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.subscribe_phone.subscribe_phone_district_id_fkey",
|
||||
Columns: []string{"district_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "organization",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey",
|
||||
|
|
@ -106,36 +58,30 @@ var PublicreportSubscribePhones = Table[
|
|||
}
|
||||
|
||||
type publicreportSubscribePhoneColumns struct {
|
||||
Created column
|
||||
Deleted column
|
||||
DistrictID column
|
||||
PhoneE164 column
|
||||
Created column
|
||||
Deleted column
|
||||
PhoneE164 column
|
||||
}
|
||||
|
||||
func (c publicreportSubscribePhoneColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Created, c.Deleted, c.DistrictID, c.PhoneE164,
|
||||
c.Created, c.Deleted, c.PhoneE164,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportSubscribePhoneIndexes struct {
|
||||
SubscribePhonePkey index
|
||||
}
|
||||
type publicreportSubscribePhoneIndexes struct{}
|
||||
|
||||
func (i publicreportSubscribePhoneIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.SubscribePhonePkey,
|
||||
}
|
||||
return []index{}
|
||||
}
|
||||
|
||||
type publicreportSubscribePhoneForeignKeys struct {
|
||||
PublicreportSubscribePhoneSubscribePhoneDistrictIDFkey foreignKey
|
||||
PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey foreignKey
|
||||
PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportSubscribePhoneForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportSubscribePhoneSubscribePhoneDistrictIDFkey, f.PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey,
|
||||
f.PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -300,8 +300,6 @@ var (
|
|||
organizationRelNuisancesCtx = newContextual[bool]("organization.publicreport.nuisance.publicreport.nuisance.nuisance_organization_id_fkey")
|
||||
organizationRelPublicreportPoolCtx = newContextual[bool]("organization.publicreport.pool.publicreport.pool.pool_organization_id_fkey")
|
||||
organizationRelQuicksCtx = newContextual[bool]("organization.publicreport.quick.publicreport.quick.quick_organization_id_fkey")
|
||||
organizationRelDistrictSubscribeEmailsCtx = newContextual[bool]("organization.publicreport.subscribe_email.publicreport.subscribe_email.subscribe_email_district_id_fkey")
|
||||
organizationRelDistrictSubscribePhonesCtx = newContextual[bool]("organization.publicreport.subscribe_phone.publicreport.subscribe_phone.subscribe_phone_district_id_fkey")
|
||||
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.image
|
||||
|
|
@ -374,13 +372,11 @@ var (
|
|||
|
||||
// Relationship Contexts for publicreport.subscribe_email
|
||||
publicreportSubscribeEmailWithParentsCascadingCtx = newContextual[bool]("publicreportSubscribeEmailWithParentsCascading")
|
||||
publicreportSubscribeEmailRelDistrictOrganizationCtx = newContextual[bool]("organization.publicreport.subscribe_email.publicreport.subscribe_email.subscribe_email_district_id_fkey")
|
||||
publicreportSubscribeEmailRelEmailAddressEmailContactCtx = newContextual[bool]("comms.email_contact.publicreport.subscribe_email.publicreport.subscribe_email.subscribe_email_email_address_fkey")
|
||||
|
||||
// Relationship Contexts for publicreport.subscribe_phone
|
||||
publicreportSubscribePhoneWithParentsCascadingCtx = newContextual[bool]("publicreportSubscribePhoneWithParentsCascading")
|
||||
publicreportSubscribePhoneRelDistrictOrganizationCtx = newContextual[bool]("organization.publicreport.subscribe_phone.publicreport.subscribe_phone.subscribe_phone_district_id_fkey")
|
||||
publicreportSubscribePhoneRelPhoneE164PhoneCtx = newContextual[bool]("comms.phone.publicreport.subscribe_phone.publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey")
|
||||
publicreportSubscribePhoneWithParentsCascadingCtx = newContextual[bool]("publicreportSubscribePhoneWithParentsCascading")
|
||||
publicreportSubscribePhoneRelPhoneE164PhoneCtx = newContextual[bool]("comms.phone.publicreport.subscribe_phone.publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey")
|
||||
|
||||
// Relationship Contexts for raster_columns
|
||||
rasterColumnWithParentsCascadingCtx = newContextual[bool]("rasterColumnWithParentsCascading")
|
||||
|
|
|
|||
|
|
@ -3068,12 +3068,6 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
|
|||
if len(m.R.Quicks) > 0 {
|
||||
OrganizationMods.AddExistingQuicks(m.R.Quicks...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.DistrictSubscribeEmails) > 0 {
|
||||
OrganizationMods.AddExistingDistrictSubscribeEmails(m.R.DistrictSubscribeEmails...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.DistrictSubscribePhones) > 0 {
|
||||
OrganizationMods.AddExistingDistrictSubscribePhones(m.R.DistrictSubscribePhones...).Apply(ctx, o)
|
||||
}
|
||||
if len(m.R.User) > 0 {
|
||||
OrganizationMods.AddExistingUser(m.R.User...).Apply(ctx, o)
|
||||
}
|
||||
|
|
@ -3633,13 +3627,9 @@ func (f *Factory) FromExistingPublicreportSubscribeEmail(m *models.PublicreportS
|
|||
|
||||
o.Created = func() time.Time { return m.Created }
|
||||
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
|
||||
o.DistrictID = func() int32 { return m.DistrictID }
|
||||
o.EmailAddress = func() string { return m.EmailAddress }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.DistrictOrganization != nil {
|
||||
PublicreportSubscribeEmailMods.WithExistingDistrictOrganization(m.R.DistrictOrganization).Apply(ctx, o)
|
||||
}
|
||||
if m.R.EmailAddressEmailContact != nil {
|
||||
PublicreportSubscribeEmailMods.WithExistingEmailAddressEmailContact(m.R.EmailAddressEmailContact).Apply(ctx, o)
|
||||
}
|
||||
|
|
@ -3668,13 +3658,9 @@ func (f *Factory) FromExistingPublicreportSubscribePhone(m *models.PublicreportS
|
|||
|
||||
o.Created = func() time.Time { return m.Created }
|
||||
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
|
||||
o.DistrictID = func() int32 { return m.DistrictID }
|
||||
o.PhoneE164 = func() string { return m.PhoneE164 }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.DistrictOrganization != nil {
|
||||
PublicreportSubscribePhoneMods.WithExistingDistrictOrganization(m.R.DistrictOrganization).Apply(ctx, o)
|
||||
}
|
||||
if m.R.PhoneE164Phone != nil {
|
||||
PublicreportSubscribePhoneMods.WithExistingPhoneE164Phone(m.R.PhoneE164Phone).Apply(ctx, o)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -328,26 +328,6 @@ func (o *CommsEmailContactTemplate) insertOptRels(ctx context.Context, exec bob.
|
|||
}
|
||||
}
|
||||
|
||||
isEmailAddressSubscribeEmailsDone, _ := commsEmailContactRelEmailAddressSubscribeEmailsCtx.Value(ctx)
|
||||
if !isEmailAddressSubscribeEmailsDone && o.r.EmailAddressSubscribeEmails != nil {
|
||||
ctx = commsEmailContactRelEmailAddressSubscribeEmailsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.EmailAddressSubscribeEmails {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.EmailAddressSubscribeEmails = append(m.R.EmailAddressSubscribeEmails, r.o.Build())
|
||||
} else {
|
||||
rel4, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachEmailAddressSubscribeEmails(ctx, exec, rel4...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -393,26 +393,6 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo
|
|||
}
|
||||
}
|
||||
|
||||
isPhoneE164SubscribePhonesDone, _ := commsPhoneRelPhoneE164SubscribePhonesCtx.Value(ctx)
|
||||
if !isPhoneE164SubscribePhonesDone && o.r.PhoneE164SubscribePhones != nil {
|
||||
ctx = commsPhoneRelPhoneE164SubscribePhonesCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.PhoneE164SubscribePhones {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.PhoneE164SubscribePhones = append(m.R.PhoneE164SubscribePhones, r.o.Build())
|
||||
} else {
|
||||
rel6, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachPhoneE164SubscribePhones(ctx, exec, rel6...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,8 +93,6 @@ type organizationR struct {
|
|||
Nuisances []*organizationRNuisancesR
|
||||
PublicreportPool []*organizationRPublicreportPoolR
|
||||
Quicks []*organizationRQuicksR
|
||||
DistrictSubscribeEmails []*organizationRDistrictSubscribeEmailsR
|
||||
DistrictSubscribePhones []*organizationRDistrictSubscribePhonesR
|
||||
User []*organizationRUserR
|
||||
}
|
||||
|
||||
|
|
@ -253,14 +251,6 @@ type organizationRQuicksR struct {
|
|||
number int
|
||||
o *PublicreportQuickTemplate
|
||||
}
|
||||
type organizationRDistrictSubscribeEmailsR struct {
|
||||
number int
|
||||
o *PublicreportSubscribeEmailTemplate
|
||||
}
|
||||
type organizationRDistrictSubscribePhonesR struct {
|
||||
number int
|
||||
o *PublicreportSubscribePhoneTemplate
|
||||
}
|
||||
type organizationRUserR struct {
|
||||
number int
|
||||
o *UserTemplate
|
||||
|
|
@ -775,32 +765,6 @@ func (t OrganizationTemplate) setModelRels(o *models.Organization) {
|
|||
o.R.Quicks = rel
|
||||
}
|
||||
|
||||
if t.r.DistrictSubscribeEmails != nil {
|
||||
rel := models.PublicreportSubscribeEmailSlice{}
|
||||
for _, r := range t.r.DistrictSubscribeEmails {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.DistrictID = o.ID // h2
|
||||
rel.R.DistrictOrganization = o
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.DistrictSubscribeEmails = rel
|
||||
}
|
||||
|
||||
if t.r.DistrictSubscribePhones != nil {
|
||||
rel := models.PublicreportSubscribePhoneSlice{}
|
||||
for _, r := range t.r.DistrictSubscribePhones {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.DistrictID = o.ID // h2
|
||||
rel.R.DistrictOrganization = o
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
}
|
||||
o.R.DistrictSubscribePhones = rel
|
||||
}
|
||||
|
||||
if t.r.User != nil {
|
||||
rel := models.UserSlice{}
|
||||
for _, r := range t.r.User {
|
||||
|
|
@ -1716,46 +1680,6 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu
|
|||
}
|
||||
}
|
||||
|
||||
isDistrictSubscribeEmailsDone, _ := organizationRelDistrictSubscribeEmailsCtx.Value(ctx)
|
||||
if !isDistrictSubscribeEmailsDone && o.r.DistrictSubscribeEmails != nil {
|
||||
ctx = organizationRelDistrictSubscribeEmailsCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.DistrictSubscribeEmails {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.DistrictSubscribeEmails = append(m.R.DistrictSubscribeEmails, r.o.Build())
|
||||
} else {
|
||||
rel39, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachDistrictSubscribeEmails(ctx, exec, rel39...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isDistrictSubscribePhonesDone, _ := organizationRelDistrictSubscribePhonesCtx.Value(ctx)
|
||||
if !isDistrictSubscribePhonesDone && o.r.DistrictSubscribePhones != nil {
|
||||
ctx = organizationRelDistrictSubscribePhonesCtx.WithValue(ctx, true)
|
||||
for _, r := range o.r.DistrictSubscribePhones {
|
||||
if r.o.alreadyPersisted {
|
||||
m.R.DistrictSubscribePhones = append(m.R.DistrictSubscribePhones, r.o.Build())
|
||||
} else {
|
||||
rel40, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachDistrictSubscribePhones(ctx, exec, rel40...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isUserDone, _ := organizationRelUserCtx.Value(ctx)
|
||||
if !isUserDone && o.r.User != nil {
|
||||
ctx = organizationRelUserCtx.WithValue(ctx, true)
|
||||
|
|
@ -1763,12 +1687,12 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu
|
|||
if r.o.alreadyPersisted {
|
||||
m.R.User = append(m.R.User, r.o.Build())
|
||||
} else {
|
||||
rel41, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
rel39, err := r.o.CreateMany(ctx, exec, r.number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.AttachUser(ctx, exec, rel41...)
|
||||
err = m.AttachUser(ctx, exec, rel39...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -4181,102 +4105,6 @@ func (m organizationMods) WithoutQuicks() OrganizationMod {
|
|||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithDistrictSubscribeEmails(number int, related *PublicreportSubscribeEmailTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.DistrictSubscribeEmails = []*organizationRDistrictSubscribeEmailsR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithNewDistrictSubscribeEmails(number int, mods ...PublicreportSubscribeEmailMod) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
related := o.f.NewPublicreportSubscribeEmailWithContext(ctx, mods...)
|
||||
m.WithDistrictSubscribeEmails(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddDistrictSubscribeEmails(number int, related *PublicreportSubscribeEmailTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.DistrictSubscribeEmails = append(o.r.DistrictSubscribeEmails, &organizationRDistrictSubscribeEmailsR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddNewDistrictSubscribeEmails(number int, mods ...PublicreportSubscribeEmailMod) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
related := o.f.NewPublicreportSubscribeEmailWithContext(ctx, mods...)
|
||||
m.AddDistrictSubscribeEmails(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddExistingDistrictSubscribeEmails(existingModels ...*models.PublicreportSubscribeEmail) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.DistrictSubscribeEmails = append(o.r.DistrictSubscribeEmails, &organizationRDistrictSubscribeEmailsR{
|
||||
o: o.f.FromExistingPublicreportSubscribeEmail(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithoutDistrictSubscribeEmails() OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.DistrictSubscribeEmails = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithDistrictSubscribePhones(number int, related *PublicreportSubscribePhoneTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.DistrictSubscribePhones = []*organizationRDistrictSubscribePhonesR{{
|
||||
number: number,
|
||||
o: related,
|
||||
}}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithNewDistrictSubscribePhones(number int, mods ...PublicreportSubscribePhoneMod) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
related := o.f.NewPublicreportSubscribePhoneWithContext(ctx, mods...)
|
||||
m.WithDistrictSubscribePhones(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddDistrictSubscribePhones(number int, related *PublicreportSubscribePhoneTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.DistrictSubscribePhones = append(o.r.DistrictSubscribePhones, &organizationRDistrictSubscribePhonesR{
|
||||
number: number,
|
||||
o: related,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddNewDistrictSubscribePhones(number int, mods ...PublicreportSubscribePhoneMod) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
related := o.f.NewPublicreportSubscribePhoneWithContext(ctx, mods...)
|
||||
m.AddDistrictSubscribePhones(number, related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) AddExistingDistrictSubscribePhones(existingModels ...*models.PublicreportSubscribePhone) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
for _, em := range existingModels {
|
||||
o.r.DistrictSubscribePhones = append(o.r.DistrictSubscribePhones, &organizationRDistrictSubscribePhonesR{
|
||||
o: o.f.FromExistingPublicreportSubscribePhone(em),
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithoutDistrictSubscribePhones() OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.DistrictSubscribePhones = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m organizationMods) WithUser(number int, related *UserTemplate) OrganizationMod {
|
||||
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
|
||||
o.r.User = []*organizationRUserR{{
|
||||
|
|
|
|||
|
|
@ -5,14 +5,10 @@ package factory
|
|||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
)
|
||||
|
||||
|
|
@ -39,7 +35,6 @@ func (mods PublicreportSubscribeEmailModSlice) Apply(ctx context.Context, n *Pub
|
|||
type PublicreportSubscribeEmailTemplate struct {
|
||||
Created func() time.Time
|
||||
Deleted func() null.Val[time.Time]
|
||||
DistrictID func() int32
|
||||
EmailAddress func() string
|
||||
|
||||
r publicreportSubscribeEmailR
|
||||
|
|
@ -49,13 +44,9 @@ type PublicreportSubscribeEmailTemplate struct {
|
|||
}
|
||||
|
||||
type publicreportSubscribeEmailR struct {
|
||||
DistrictOrganization *publicreportSubscribeEmailRDistrictOrganizationR
|
||||
EmailAddressEmailContact *publicreportSubscribeEmailREmailAddressEmailContactR
|
||||
}
|
||||
|
||||
type publicreportSubscribeEmailRDistrictOrganizationR struct {
|
||||
o *OrganizationTemplate
|
||||
}
|
||||
type publicreportSubscribeEmailREmailAddressEmailContactR struct {
|
||||
o *CommsEmailContactTemplate
|
||||
}
|
||||
|
|
@ -70,13 +61,6 @@ func (o *PublicreportSubscribeEmailTemplate) Apply(ctx context.Context, mods ...
|
|||
// setModelRels creates and sets the relationships on *models.PublicreportSubscribeEmail
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportSubscribeEmailTemplate) setModelRels(o *models.PublicreportSubscribeEmail) {
|
||||
if t.r.DistrictOrganization != nil {
|
||||
rel := t.r.DistrictOrganization.o.Build()
|
||||
rel.R.DistrictSubscribeEmails = append(rel.R.DistrictSubscribeEmails, o)
|
||||
o.DistrictID = rel.ID // h2
|
||||
o.R.DistrictOrganization = rel
|
||||
}
|
||||
|
||||
if t.r.EmailAddressEmailContact != nil {
|
||||
rel := t.r.EmailAddressEmailContact.o.Build()
|
||||
rel.R.EmailAddressSubscribeEmails = append(rel.R.EmailAddressSubscribeEmails, o)
|
||||
|
|
@ -85,43 +69,6 @@ func (t PublicreportSubscribeEmailTemplate) setModelRels(o *models.PublicreportS
|
|||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportSubscribeEmailSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportSubscribeEmailTemplate) BuildSetter() *models.PublicreportSubscribeEmailSetter {
|
||||
m := &models.PublicreportSubscribeEmailSetter{}
|
||||
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if o.Deleted != nil {
|
||||
val := o.Deleted()
|
||||
m.Deleted = omitnull.FromNull(val)
|
||||
}
|
||||
if o.DistrictID != nil {
|
||||
val := o.DistrictID()
|
||||
m.DistrictID = omit.From(val)
|
||||
}
|
||||
if o.EmailAddress != nil {
|
||||
val := o.EmailAddress()
|
||||
m.EmailAddress = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportSubscribeEmailSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportSubscribeEmailTemplate) BuildManySetter(number int) []*models.PublicreportSubscribeEmailSetter {
|
||||
m := make([]*models.PublicreportSubscribeEmailSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportSubscribeEmail
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportSubscribeEmailTemplate.Create
|
||||
|
|
@ -134,9 +81,6 @@ func (o PublicreportSubscribeEmailTemplate) Build() *models.PublicreportSubscrib
|
|||
if o.Deleted != nil {
|
||||
m.Deleted = o.Deleted()
|
||||
}
|
||||
if o.DistrictID != nil {
|
||||
m.DistrictID = o.DistrictID()
|
||||
}
|
||||
if o.EmailAddress != nil {
|
||||
m.EmailAddress = o.EmailAddress()
|
||||
}
|
||||
|
|
@ -159,149 +103,6 @@ func (o PublicreportSubscribeEmailTemplate) BuildMany(number int) models.Publicr
|
|||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportSubscribeEmail(m *models.PublicreportSubscribeEmailSetter) {
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if !(m.DistrictID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.DistrictID = omit.From(val)
|
||||
}
|
||||
if !(m.EmailAddress.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.EmailAddress = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportSubscribeEmail
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportSubscribeEmailTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportSubscribeEmail) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportSubscribeEmail and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportSubscribeEmailTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportSubscribeEmail, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportSubscribeEmail(opt)
|
||||
|
||||
if o.r.DistrictOrganization == nil {
|
||||
PublicreportSubscribeEmailMods.WithNewDistrictOrganization().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.Organization
|
||||
|
||||
if o.r.DistrictOrganization.o.alreadyPersisted {
|
||||
rel0 = o.r.DistrictOrganization.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.DistrictOrganization.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.DistrictID = omit.From(rel0.ID)
|
||||
|
||||
if o.r.EmailAddressEmailContact == nil {
|
||||
PublicreportSubscribeEmailMods.WithNewEmailAddressEmailContact().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel1 *models.CommsEmailContact
|
||||
|
||||
if o.r.EmailAddressEmailContact.o.alreadyPersisted {
|
||||
rel1 = o.r.EmailAddressEmailContact.o.Build()
|
||||
} else {
|
||||
rel1, err = o.r.EmailAddressEmailContact.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.EmailAddress = omit.From(rel1.Address)
|
||||
|
||||
m, err := models.PublicreportSubscribeEmails.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.DistrictOrganization = rel0
|
||||
m.R.EmailAddressEmailContact = rel1
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportSubscribeEmail and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportSubscribeEmailTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportSubscribeEmail {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportSubscribeEmail 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 *PublicreportSubscribeEmailTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportSubscribeEmail {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportSubscribeEmails and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportSubscribeEmailTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportSubscribeEmailSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportSubscribeEmailSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportSubscribeEmails and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportSubscribeEmailTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportSubscribeEmailSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportSubscribeEmails 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 PublicreportSubscribeEmailTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportSubscribeEmailSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportSubscribeEmail has methods that act as mods for the PublicreportSubscribeEmailTemplate
|
||||
var PublicreportSubscribeEmailMods publicreportSubscribeEmailMods
|
||||
|
||||
|
|
@ -311,7 +112,6 @@ func (m publicreportSubscribeEmailMods) RandomizeAllColumns(f *faker.Faker) Publ
|
|||
return PublicreportSubscribeEmailModSlice{
|
||||
PublicreportSubscribeEmailMods.RandomCreated(f),
|
||||
PublicreportSubscribeEmailMods.RandomDeleted(f),
|
||||
PublicreportSubscribeEmailMods.RandomDistrictID(f),
|
||||
PublicreportSubscribeEmailMods.RandomEmailAddress(f),
|
||||
}
|
||||
}
|
||||
|
|
@ -400,37 +200,6 @@ func (m publicreportSubscribeEmailMods) RandomDeletedNotNull(f *faker.Faker) Pub
|
|||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportSubscribeEmailMods) DistrictID(val int32) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.DistrictID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportSubscribeEmailMods) DistrictIDFunc(f func() int32) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.DistrictID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportSubscribeEmailMods) UnsetDistrictID() PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.DistrictID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportSubscribeEmailMods) RandomDistrictID(f *faker.Faker) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.DistrictID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportSubscribeEmailMods) EmailAddress(val string) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
|
|
@ -468,11 +237,6 @@ func (m publicreportSubscribeEmailMods) WithParentsCascading() PublicreportSubsc
|
|||
return
|
||||
}
|
||||
ctx = publicreportSubscribeEmailWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewOrganizationWithContext(ctx, OrganizationMods.WithParentsCascading())
|
||||
m.WithDistrictOrganization(related).Apply(ctx, o)
|
||||
}
|
||||
{
|
||||
|
||||
related := o.f.NewCommsEmailContactWithContext(ctx, CommsEmailContactMods.WithParentsCascading())
|
||||
|
|
@ -481,36 +245,6 @@ func (m publicreportSubscribeEmailMods) WithParentsCascading() PublicreportSubsc
|
|||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribeEmailMods) WithDistrictOrganization(rel *OrganizationTemplate) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.r.DistrictOrganization = &publicreportSubscribeEmailRDistrictOrganizationR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribeEmailMods) WithNewDistrictOrganization(mods ...OrganizationMod) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
related := o.f.NewOrganizationWithContext(ctx, mods...)
|
||||
|
||||
m.WithDistrictOrganization(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribeEmailMods) WithExistingDistrictOrganization(em *models.Organization) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.r.DistrictOrganization = &publicreportSubscribeEmailRDistrictOrganizationR{
|
||||
o: o.f.FromExistingOrganization(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribeEmailMods) WithoutDistrictOrganization() PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.r.DistrictOrganization = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribeEmailMods) WithEmailAddressEmailContact(rel *CommsEmailContactTemplate) PublicreportSubscribeEmailMod {
|
||||
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||
o.r.EmailAddressEmailContact = &publicreportSubscribeEmailREmailAddressEmailContactR{
|
||||
|
|
|
|||
|
|
@ -5,14 +5,10 @@ package factory
|
|||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
)
|
||||
|
||||
|
|
@ -37,10 +33,9 @@ func (mods PublicreportSubscribePhoneModSlice) Apply(ctx context.Context, n *Pub
|
|||
// PublicreportSubscribePhoneTemplate is an object representing the database table.
|
||||
// all columns are optional and should be set by mods
|
||||
type PublicreportSubscribePhoneTemplate struct {
|
||||
Created func() time.Time
|
||||
Deleted func() null.Val[time.Time]
|
||||
DistrictID func() int32
|
||||
PhoneE164 func() string
|
||||
Created func() time.Time
|
||||
Deleted func() null.Val[time.Time]
|
||||
PhoneE164 func() string
|
||||
|
||||
r publicreportSubscribePhoneR
|
||||
f *Factory
|
||||
|
|
@ -49,13 +44,9 @@ type PublicreportSubscribePhoneTemplate struct {
|
|||
}
|
||||
|
||||
type publicreportSubscribePhoneR struct {
|
||||
DistrictOrganization *publicreportSubscribePhoneRDistrictOrganizationR
|
||||
PhoneE164Phone *publicreportSubscribePhoneRPhoneE164PhoneR
|
||||
PhoneE164Phone *publicreportSubscribePhoneRPhoneE164PhoneR
|
||||
}
|
||||
|
||||
type publicreportSubscribePhoneRDistrictOrganizationR struct {
|
||||
o *OrganizationTemplate
|
||||
}
|
||||
type publicreportSubscribePhoneRPhoneE164PhoneR struct {
|
||||
o *CommsPhoneTemplate
|
||||
}
|
||||
|
|
@ -70,13 +61,6 @@ func (o *PublicreportSubscribePhoneTemplate) Apply(ctx context.Context, mods ...
|
|||
// setModelRels creates and sets the relationships on *models.PublicreportSubscribePhone
|
||||
// according to the relationships in the template. Nothing is inserted into the db
|
||||
func (t PublicreportSubscribePhoneTemplate) setModelRels(o *models.PublicreportSubscribePhone) {
|
||||
if t.r.DistrictOrganization != nil {
|
||||
rel := t.r.DistrictOrganization.o.Build()
|
||||
rel.R.DistrictSubscribePhones = append(rel.R.DistrictSubscribePhones, o)
|
||||
o.DistrictID = rel.ID // h2
|
||||
o.R.DistrictOrganization = rel
|
||||
}
|
||||
|
||||
if t.r.PhoneE164Phone != nil {
|
||||
rel := t.r.PhoneE164Phone.o.Build()
|
||||
rel.R.PhoneE164SubscribePhones = append(rel.R.PhoneE164SubscribePhones, o)
|
||||
|
|
@ -85,43 +69,6 @@ func (t PublicreportSubscribePhoneTemplate) setModelRels(o *models.PublicreportS
|
|||
}
|
||||
}
|
||||
|
||||
// BuildSetter returns an *models.PublicreportSubscribePhoneSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportSubscribePhoneTemplate) BuildSetter() *models.PublicreportSubscribePhoneSetter {
|
||||
m := &models.PublicreportSubscribePhoneSetter{}
|
||||
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if o.Deleted != nil {
|
||||
val := o.Deleted()
|
||||
m.Deleted = omitnull.FromNull(val)
|
||||
}
|
||||
if o.DistrictID != nil {
|
||||
val := o.DistrictID()
|
||||
m.DistrictID = omit.From(val)
|
||||
}
|
||||
if o.PhoneE164 != nil {
|
||||
val := o.PhoneE164()
|
||||
m.PhoneE164 = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// BuildManySetter returns an []*models.PublicreportSubscribePhoneSetter
|
||||
// this does nothing with the relationship templates
|
||||
func (o PublicreportSubscribePhoneTemplate) BuildManySetter(number int) []*models.PublicreportSubscribePhoneSetter {
|
||||
m := make([]*models.PublicreportSubscribePhoneSetter, number)
|
||||
|
||||
for i := range m {
|
||||
m[i] = o.BuildSetter()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build returns an *models.PublicreportSubscribePhone
|
||||
// Related objects are also created and placed in the .R field
|
||||
// NOTE: Objects are not inserted into the database. Use PublicreportSubscribePhoneTemplate.Create
|
||||
|
|
@ -134,9 +81,6 @@ func (o PublicreportSubscribePhoneTemplate) Build() *models.PublicreportSubscrib
|
|||
if o.Deleted != nil {
|
||||
m.Deleted = o.Deleted()
|
||||
}
|
||||
if o.DistrictID != nil {
|
||||
m.DistrictID = o.DistrictID()
|
||||
}
|
||||
if o.PhoneE164 != nil {
|
||||
m.PhoneE164 = o.PhoneE164()
|
||||
}
|
||||
|
|
@ -159,149 +103,6 @@ func (o PublicreportSubscribePhoneTemplate) BuildMany(number int) models.Publicr
|
|||
return m
|
||||
}
|
||||
|
||||
func ensureCreatablePublicreportSubscribePhone(m *models.PublicreportSubscribePhoneSetter) {
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if !(m.DistrictID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.DistrictID = omit.From(val)
|
||||
}
|
||||
if !(m.PhoneE164.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.PhoneE164 = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportSubscribePhone
|
||||
// according to the relationships in the template.
|
||||
// any required relationship should have already exist on the model
|
||||
func (o *PublicreportSubscribePhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportSubscribePhone) error {
|
||||
var err error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Create builds a publicreportSubscribePhone and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o *PublicreportSubscribePhoneTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportSubscribePhone, error) {
|
||||
var err error
|
||||
opt := o.BuildSetter()
|
||||
ensureCreatablePublicreportSubscribePhone(opt)
|
||||
|
||||
if o.r.DistrictOrganization == nil {
|
||||
PublicreportSubscribePhoneMods.WithNewDistrictOrganization().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.Organization
|
||||
|
||||
if o.r.DistrictOrganization.o.alreadyPersisted {
|
||||
rel0 = o.r.DistrictOrganization.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.DistrictOrganization.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.DistrictID = omit.From(rel0.ID)
|
||||
|
||||
if o.r.PhoneE164Phone == nil {
|
||||
PublicreportSubscribePhoneMods.WithNewPhoneE164Phone().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel1 *models.CommsPhone
|
||||
|
||||
if o.r.PhoneE164Phone.o.alreadyPersisted {
|
||||
rel1 = o.r.PhoneE164Phone.o.Build()
|
||||
} else {
|
||||
rel1, err = o.r.PhoneE164Phone.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.PhoneE164 = omit.From(rel1.E164)
|
||||
|
||||
m, err := models.PublicreportSubscribePhones.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.DistrictOrganization = rel0
|
||||
m.R.PhoneE164Phone = rel1
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// MustCreate builds a publicreportSubscribePhone and inserts it into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o *PublicreportSubscribePhoneTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportSubscribePhone {
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateOrFail builds a publicreportSubscribePhone 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 *PublicreportSubscribePhoneTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportSubscribePhone {
|
||||
tb.Helper()
|
||||
m, err := o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateMany builds multiple publicreportSubscribePhones and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
func (o PublicreportSubscribePhoneTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportSubscribePhoneSlice, error) {
|
||||
var err error
|
||||
m := make(models.PublicreportSubscribePhoneSlice, number)
|
||||
|
||||
for i := range m {
|
||||
m[i], err = o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustCreateMany builds multiple publicreportSubscribePhones and inserts them into the database
|
||||
// Relations objects are also inserted and placed in the .R field
|
||||
// panics if an error occurs
|
||||
func (o PublicreportSubscribePhoneTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportSubscribePhoneSlice {
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// CreateManyOrFail builds multiple publicreportSubscribePhones 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 PublicreportSubscribePhoneTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportSubscribePhoneSlice {
|
||||
tb.Helper()
|
||||
m, err := o.CreateMany(ctx, exec, number)
|
||||
if err != nil {
|
||||
tb.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// PublicreportSubscribePhone has methods that act as mods for the PublicreportSubscribePhoneTemplate
|
||||
var PublicreportSubscribePhoneMods publicreportSubscribePhoneMods
|
||||
|
||||
|
|
@ -311,7 +112,6 @@ func (m publicreportSubscribePhoneMods) RandomizeAllColumns(f *faker.Faker) Publ
|
|||
return PublicreportSubscribePhoneModSlice{
|
||||
PublicreportSubscribePhoneMods.RandomCreated(f),
|
||||
PublicreportSubscribePhoneMods.RandomDeleted(f),
|
||||
PublicreportSubscribePhoneMods.RandomDistrictID(f),
|
||||
PublicreportSubscribePhoneMods.RandomPhoneE164(f),
|
||||
}
|
||||
}
|
||||
|
|
@ -400,37 +200,6 @@ func (m publicreportSubscribePhoneMods) RandomDeletedNotNull(f *faker.Faker) Pub
|
|||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportSubscribePhoneMods) DistrictID(val int32) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.DistrictID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m publicreportSubscribePhoneMods) DistrictIDFunc(f func() int32) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.DistrictID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m publicreportSubscribePhoneMods) UnsetDistrictID() PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.DistrictID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m publicreportSubscribePhoneMods) RandomDistrictID(f *faker.Faker) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.DistrictID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m publicreportSubscribePhoneMods) PhoneE164(val string) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
|
|
@ -468,11 +237,6 @@ func (m publicreportSubscribePhoneMods) WithParentsCascading() PublicreportSubsc
|
|||
return
|
||||
}
|
||||
ctx = publicreportSubscribePhoneWithParentsCascadingCtx.WithValue(ctx, true)
|
||||
{
|
||||
|
||||
related := o.f.NewOrganizationWithContext(ctx, OrganizationMods.WithParentsCascading())
|
||||
m.WithDistrictOrganization(related).Apply(ctx, o)
|
||||
}
|
||||
{
|
||||
|
||||
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
|
||||
|
|
@ -481,36 +245,6 @@ func (m publicreportSubscribePhoneMods) WithParentsCascading() PublicreportSubsc
|
|||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribePhoneMods) WithDistrictOrganization(rel *OrganizationTemplate) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(ctx context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.r.DistrictOrganization = &publicreportSubscribePhoneRDistrictOrganizationR{
|
||||
o: rel,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribePhoneMods) WithNewDistrictOrganization(mods ...OrganizationMod) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(ctx context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
related := o.f.NewOrganizationWithContext(ctx, mods...)
|
||||
|
||||
m.WithDistrictOrganization(related).Apply(ctx, o)
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribePhoneMods) WithExistingDistrictOrganization(em *models.Organization) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(ctx context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.r.DistrictOrganization = &publicreportSubscribePhoneRDistrictOrganizationR{
|
||||
o: o.f.FromExistingOrganization(em),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribePhoneMods) WithoutDistrictOrganization() PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(ctx context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.r.DistrictOrganization = nil
|
||||
})
|
||||
}
|
||||
|
||||
func (m publicreportSubscribePhoneMods) WithPhoneE164Phone(rel *CommsPhoneTemplate) PublicreportSubscribePhoneMod {
|
||||
return PublicreportSubscribePhoneModFunc(func(ctx context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||
o.r.PhoneE164Phone = &publicreportSubscribePhoneRPhoneE164PhoneR{
|
||||
|
|
|
|||
3
db/migrations/00059_subscription_drop_district.sql
Normal file
3
db/migrations/00059_subscription_drop_district.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-- +goose Up
|
||||
ALTER TABLE publicreport.subscribe_email DROP COLUMN district_id;
|
||||
ALTER TABLE publicreport.subscribe_phone DROP COLUMN district_id;
|
||||
|
|
@ -816,74 +816,6 @@ func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailPools(
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertCommsEmailContactEmailAddressSubscribeEmails0(ctx context.Context, exec bob.Executor, publicreportSubscribeEmails1 []*PublicreportSubscribeEmailSetter, commsEmailContact0 *CommsEmailContact) (PublicreportSubscribeEmailSlice, error) {
|
||||
for i := range publicreportSubscribeEmails1 {
|
||||
publicreportSubscribeEmails1[i].EmailAddress = omit.From(commsEmailContact0.Address)
|
||||
}
|
||||
|
||||
ret, err := PublicreportSubscribeEmails.Insert(bob.ToMods(publicreportSubscribeEmails1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressSubscribeEmails0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachCommsEmailContactEmailAddressSubscribeEmails0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribeEmails1 PublicreportSubscribeEmailSlice, commsEmailContact0 *CommsEmailContact) (PublicreportSubscribeEmailSlice, error) {
|
||||
setter := &PublicreportSubscribeEmailSetter{
|
||||
EmailAddress: omit.From(commsEmailContact0.Address),
|
||||
}
|
||||
|
||||
err := publicreportSubscribeEmails1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressSubscribeEmails0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribeEmails1, nil
|
||||
}
|
||||
|
||||
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressSubscribeEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribeEmailSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportSubscribeEmails1, err := insertCommsEmailContactEmailAddressSubscribeEmails0(ctx, exec, related, commsEmailContact0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsEmailContact0.R.EmailAddressSubscribeEmails = append(commsEmailContact0.R.EmailAddressSubscribeEmails, publicreportSubscribeEmails1...)
|
||||
|
||||
for _, rel := range publicreportSubscribeEmails1 {
|
||||
rel.R.EmailAddressEmailContact = commsEmailContact0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressSubscribeEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribeEmail) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportSubscribeEmails1 := PublicreportSubscribeEmailSlice(related)
|
||||
|
||||
_, err = attachCommsEmailContactEmailAddressSubscribeEmails0(ctx, exec, len(related), publicreportSubscribeEmails1, commsEmailContact0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsEmailContact0.R.EmailAddressSubscribeEmails = append(commsEmailContact0.R.EmailAddressSubscribeEmails, publicreportSubscribeEmails1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.EmailAddressEmailContact = commsEmailContact0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsEmailContactWhere[Q psql.Filterable] struct {
|
||||
Address psql.WhereMod[Q, string]
|
||||
Confirmed psql.WhereMod[Q, bool]
|
||||
|
|
|
|||
|
|
@ -980,74 +980,6 @@ func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhonePools(ctx context.Conte
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertCommsPhonePhoneE164SubscribePhones0(ctx context.Context, exec bob.Executor, publicreportSubscribePhones1 []*PublicreportSubscribePhoneSetter, commsPhone0 *CommsPhone) (PublicreportSubscribePhoneSlice, error) {
|
||||
for i := range publicreportSubscribePhones1 {
|
||||
publicreportSubscribePhones1[i].PhoneE164 = omit.From(commsPhone0.E164)
|
||||
}
|
||||
|
||||
ret, err := PublicreportSubscribePhones.Insert(bob.ToMods(publicreportSubscribePhones1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertCommsPhonePhoneE164SubscribePhones0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachCommsPhonePhoneE164SubscribePhones0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribePhones1 PublicreportSubscribePhoneSlice, commsPhone0 *CommsPhone) (PublicreportSubscribePhoneSlice, error) {
|
||||
setter := &PublicreportSubscribePhoneSetter{
|
||||
PhoneE164: omit.From(commsPhone0.E164),
|
||||
}
|
||||
|
||||
err := publicreportSubscribePhones1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsPhonePhoneE164SubscribePhones0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribePhones1, nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) InsertPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribePhoneSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportSubscribePhones1, err := insertCommsPhonePhoneE164SubscribePhones0(ctx, exec, related, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.PhoneE164SubscribePhones = append(commsPhone0.R.PhoneE164SubscribePhones, publicreportSubscribePhones1...)
|
||||
|
||||
for _, rel := range publicreportSubscribePhones1 {
|
||||
rel.R.PhoneE164Phone = commsPhone0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) AttachPhoneE164SubscribePhones(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribePhone) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportSubscribePhones1 := PublicreportSubscribePhoneSlice(related)
|
||||
|
||||
_, err = attachCommsPhonePhoneE164SubscribePhones0(ctx, exec, len(related), publicreportSubscribePhones1, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.PhoneE164SubscribePhones = append(commsPhone0.R.PhoneE164SubscribePhones, publicreportSubscribePhones1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.PhoneE164Phone = commsPhone0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsPhoneWhere[Q psql.Filterable] struct {
|
||||
E164 psql.WhereMod[Q, string]
|
||||
IsSubscribed psql.WhereMod[Q, bool]
|
||||
|
|
|
|||
|
|
@ -94,8 +94,6 @@ type organizationR struct {
|
|||
Nuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_organization_id_fkey
|
||||
PublicreportPool PublicreportPoolSlice // publicreport.pool.pool_organization_id_fkey
|
||||
Quicks PublicreportQuickSlice // publicreport.quick.quick_organization_id_fkey
|
||||
DistrictSubscribeEmails PublicreportSubscribeEmailSlice // publicreport.subscribe_email.subscribe_email_district_id_fkey
|
||||
DistrictSubscribePhones PublicreportSubscribePhoneSlice // publicreport.subscribe_phone.subscribe_phone_district_id_fkey
|
||||
User UserSlice // user_.user__organization_id_fkey
|
||||
}
|
||||
|
||||
|
|
@ -1523,54 +1521,6 @@ func (os OrganizationSlice) Quicks(mods ...bob.Mod[*dialect.SelectQuery]) Public
|
|||
)...)
|
||||
}
|
||||
|
||||
// DistrictSubscribeEmails starts a query for related objects on publicreport.subscribe_email
|
||||
func (o *Organization) DistrictSubscribeEmails(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportSubscribeEmailsQuery {
|
||||
return PublicreportSubscribeEmails.Query(append(mods,
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.DistrictID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OrganizationSlice) DistrictSubscribeEmails(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportSubscribeEmailsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportSubscribeEmails.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportSubscribeEmails.Columns.DistrictID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// DistrictSubscribePhones starts a query for related objects on publicreport.subscribe_phone
|
||||
func (o *Organization) DistrictSubscribePhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportSubscribePhonesQuery {
|
||||
return PublicreportSubscribePhones.Query(append(mods,
|
||||
sm.Where(PublicreportSubscribePhones.Columns.DistrictID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os OrganizationSlice) DistrictSubscribePhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportSubscribePhonesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return PublicreportSubscribePhones.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportSubscribePhones.Columns.DistrictID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// User starts a query for related objects on user_
|
||||
func (o *Organization) User(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
|
|
@ -4221,142 +4171,6 @@ func (organization0 *Organization) AttachQuicks(ctx context.Context, exec bob.Ex
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationDistrictSubscribeEmails0(ctx context.Context, exec bob.Executor, publicreportSubscribeEmails1 []*PublicreportSubscribeEmailSetter, organization0 *Organization) (PublicreportSubscribeEmailSlice, error) {
|
||||
for i := range publicreportSubscribeEmails1 {
|
||||
publicreportSubscribeEmails1[i].DistrictID = omit.From(organization0.ID)
|
||||
}
|
||||
|
||||
ret, err := PublicreportSubscribeEmails.Insert(bob.ToMods(publicreportSubscribeEmails1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertOrganizationDistrictSubscribeEmails0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachOrganizationDistrictSubscribeEmails0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribeEmails1 PublicreportSubscribeEmailSlice, organization0 *Organization) (PublicreportSubscribeEmailSlice, error) {
|
||||
setter := &PublicreportSubscribeEmailSetter{
|
||||
DistrictID: omit.From(organization0.ID),
|
||||
}
|
||||
|
||||
err := publicreportSubscribeEmails1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOrganizationDistrictSubscribeEmails0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribeEmails1, nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) InsertDistrictSubscribeEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribeEmailSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportSubscribeEmails1, err := insertOrganizationDistrictSubscribeEmails0(ctx, exec, related, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.DistrictSubscribeEmails = append(organization0.R.DistrictSubscribeEmails, publicreportSubscribeEmails1...)
|
||||
|
||||
for _, rel := range publicreportSubscribeEmails1 {
|
||||
rel.R.DistrictOrganization = organization0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) AttachDistrictSubscribeEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribeEmail) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportSubscribeEmails1 := PublicreportSubscribeEmailSlice(related)
|
||||
|
||||
_, err = attachOrganizationDistrictSubscribeEmails0(ctx, exec, len(related), publicreportSubscribeEmails1, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.DistrictSubscribeEmails = append(organization0.R.DistrictSubscribeEmails, publicreportSubscribeEmails1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.DistrictOrganization = organization0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationDistrictSubscribePhones0(ctx context.Context, exec bob.Executor, publicreportSubscribePhones1 []*PublicreportSubscribePhoneSetter, organization0 *Organization) (PublicreportSubscribePhoneSlice, error) {
|
||||
for i := range publicreportSubscribePhones1 {
|
||||
publicreportSubscribePhones1[i].DistrictID = omit.From(organization0.ID)
|
||||
}
|
||||
|
||||
ret, err := PublicreportSubscribePhones.Insert(bob.ToMods(publicreportSubscribePhones1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertOrganizationDistrictSubscribePhones0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachOrganizationDistrictSubscribePhones0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribePhones1 PublicreportSubscribePhoneSlice, organization0 *Organization) (PublicreportSubscribePhoneSlice, error) {
|
||||
setter := &PublicreportSubscribePhoneSetter{
|
||||
DistrictID: omit.From(organization0.ID),
|
||||
}
|
||||
|
||||
err := publicreportSubscribePhones1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachOrganizationDistrictSubscribePhones0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribePhones1, nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) InsertDistrictSubscribePhones(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribePhoneSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportSubscribePhones1, err := insertOrganizationDistrictSubscribePhones0(ctx, exec, related, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.DistrictSubscribePhones = append(organization0.R.DistrictSubscribePhones, publicreportSubscribePhones1...)
|
||||
|
||||
for _, rel := range publicreportSubscribePhones1 {
|
||||
rel.R.DistrictOrganization = organization0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (organization0 *Organization) AttachDistrictSubscribePhones(ctx context.Context, exec bob.Executor, related ...*PublicreportSubscribePhone) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportSubscribePhones1 := PublicreportSubscribePhoneSlice(related)
|
||||
|
||||
_, err = attachOrganizationDistrictSubscribePhones0(ctx, exec, len(related), publicreportSubscribePhones1, organization0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
organization0.R.DistrictSubscribePhones = append(organization0.R.DistrictSubscribePhones, publicreportSubscribePhones1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.DistrictOrganization = organization0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertOrganizationUser0(ctx context.Context, exec bob.Executor, users1 []*UserSetter, organization0 *Organization) (UserSlice, error) {
|
||||
for i := range users1 {
|
||||
users1[i].OrganizationID = omit.From(organization0.ID)
|
||||
|
|
@ -5005,34 +4819,6 @@ func (o *Organization) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "DistrictSubscribeEmails":
|
||||
rels, ok := retrieved.(PublicreportSubscribeEmailSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.DistrictSubscribeEmails = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.DistrictOrganization = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "DistrictSubscribePhones":
|
||||
rels, ok := retrieved.(PublicreportSubscribePhoneSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.DistrictSubscribePhones = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.DistrictOrganization = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "User":
|
||||
rels, ok := retrieved.(UserSlice)
|
||||
if !ok {
|
||||
|
|
@ -5114,8 +4900,6 @@ type organizationThenLoader[Q orm.Loadable] struct {
|
|||
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Quicks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DistrictSubscribeEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DistrictSubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
User func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -5237,12 +5021,6 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
type QuicksLoadInterface interface {
|
||||
LoadQuicks(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type DistrictSubscribeEmailsLoadInterface interface {
|
||||
LoadDistrictSubscribeEmails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type DistrictSubscribePhonesLoadInterface interface {
|
||||
LoadDistrictSubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type UserLoadInterface interface {
|
||||
LoadUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -5482,18 +5260,6 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
|
|||
return retrieved.LoadQuicks(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
DistrictSubscribeEmails: thenLoadBuilder[Q](
|
||||
"DistrictSubscribeEmails",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DistrictSubscribeEmailsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadDistrictSubscribeEmails(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
DistrictSubscribePhones: thenLoadBuilder[Q](
|
||||
"DistrictSubscribePhones",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DistrictSubscribePhonesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadDistrictSubscribePhones(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
User: thenLoadBuilder[Q](
|
||||
"User",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved UserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -7925,128 +7691,6 @@ func (os OrganizationSlice) LoadQuicks(ctx context.Context, exec bob.Executor, m
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadDistrictSubscribeEmails loads the organization's DistrictSubscribeEmails into the .R struct
|
||||
func (o *Organization) LoadDistrictSubscribeEmails(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.DistrictSubscribeEmails = nil
|
||||
|
||||
related, err := o.DistrictSubscribeEmails(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.DistrictOrganization = o
|
||||
}
|
||||
|
||||
o.R.DistrictSubscribeEmails = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDistrictSubscribeEmails loads the organization's DistrictSubscribeEmails into the .R struct
|
||||
func (os OrganizationSlice) LoadDistrictSubscribeEmails(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportSubscribeEmails, err := os.DistrictSubscribeEmails(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.DistrictSubscribeEmails = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportSubscribeEmails {
|
||||
|
||||
if !(o.ID == rel.DistrictID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.DistrictOrganization = o
|
||||
|
||||
o.R.DistrictSubscribeEmails = append(o.R.DistrictSubscribeEmails, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDistrictSubscribePhones loads the organization's DistrictSubscribePhones into the .R struct
|
||||
func (o *Organization) LoadDistrictSubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.DistrictSubscribePhones = nil
|
||||
|
||||
related, err := o.DistrictSubscribePhones(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.DistrictOrganization = o
|
||||
}
|
||||
|
||||
o.R.DistrictSubscribePhones = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDistrictSubscribePhones loads the organization's DistrictSubscribePhones into the .R struct
|
||||
func (os OrganizationSlice) LoadDistrictSubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportSubscribePhones, err := os.DistrictSubscribePhones(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.DistrictSubscribePhones = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportSubscribePhones {
|
||||
|
||||
if !(o.ID == rel.DistrictID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.DistrictOrganization = o
|
||||
|
||||
o.R.DistrictSubscribePhones = append(o.R.DistrictSubscribePhones, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadUser loads the organization's User into the .R struct
|
||||
func (o *Organization) LoadUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -8148,8 +7792,6 @@ type organizationC struct {
|
|||
Nuisances *int64
|
||||
PublicreportPool *int64
|
||||
Quicks *int64
|
||||
DistrictSubscribeEmails *int64
|
||||
DistrictSubscribePhones *int64
|
||||
User *int64
|
||||
}
|
||||
|
||||
|
|
@ -8236,10 +7878,6 @@ func (o *Organization) PreloadCount(name string, count int64) error {
|
|||
o.C.PublicreportPool = &count
|
||||
case "Quicks":
|
||||
o.C.Quicks = &count
|
||||
case "DistrictSubscribeEmails":
|
||||
o.C.DistrictSubscribeEmails = &count
|
||||
case "DistrictSubscribePhones":
|
||||
o.C.DistrictSubscribePhones = &count
|
||||
case "User":
|
||||
o.C.User = &count
|
||||
}
|
||||
|
|
@ -8285,8 +7923,6 @@ type organizationCountPreloader struct {
|
|||
Nuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
Quicks func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
DistrictSubscribeEmails func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
DistrictSubscribePhones func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
User func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
|
|
@ -8944,40 +8580,6 @@ func buildOrganizationCountPreloader() organizationCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
DistrictSubscribeEmails: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("DistrictSubscribeEmails", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Organizations.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(PublicreportSubscribeEmails.Name()),
|
||||
sm.Where(psql.Quote(PublicreportSubscribeEmails.Alias(), "district_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
DistrictSubscribePhones: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("DistrictSubscribePhones", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Organizations.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(PublicreportSubscribePhones.Name()),
|
||||
sm.Where(psql.Quote(PublicreportSubscribePhones.Alias(), "district_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
User: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Organization]("User", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
|
|
@ -9037,8 +8639,6 @@ type organizationCountThenLoader[Q orm.Loadable] struct {
|
|||
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Quicks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DistrictSubscribeEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DistrictSubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
User func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -9157,12 +8757,6 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
type QuicksCountInterface interface {
|
||||
LoadCountQuicks(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type DistrictSubscribeEmailsCountInterface interface {
|
||||
LoadCountDistrictSubscribeEmails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type DistrictSubscribePhonesCountInterface interface {
|
||||
LoadCountDistrictSubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type UserCountInterface interface {
|
||||
LoadCountUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -9396,18 +8990,6 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa
|
|||
return retrieved.LoadCountQuicks(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
DistrictSubscribeEmails: countThenLoadBuilder[Q](
|
||||
"DistrictSubscribeEmails",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DistrictSubscribeEmailsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountDistrictSubscribeEmails(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
DistrictSubscribePhones: countThenLoadBuilder[Q](
|
||||
"DistrictSubscribePhones",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DistrictSubscribePhonesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountDistrictSubscribePhones(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
User: countThenLoadBuilder[Q](
|
||||
"User",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved UserCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -10557,66 +10139,6 @@ func (os OrganizationSlice) LoadCountQuicks(ctx context.Context, exec bob.Execut
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountDistrictSubscribeEmails loads the count of DistrictSubscribeEmails into the C struct
|
||||
func (o *Organization) LoadCountDistrictSubscribeEmails(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.DistrictSubscribeEmails(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.DistrictSubscribeEmails = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountDistrictSubscribeEmails loads the count of DistrictSubscribeEmails for a slice
|
||||
func (os OrganizationSlice) LoadCountDistrictSubscribeEmails(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.LoadCountDistrictSubscribeEmails(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountDistrictSubscribePhones loads the count of DistrictSubscribePhones into the C struct
|
||||
func (o *Organization) LoadCountDistrictSubscribePhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.DistrictSubscribePhones(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.DistrictSubscribePhones = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountDistrictSubscribePhones loads the count of DistrictSubscribePhones for a slice
|
||||
func (os OrganizationSlice) LoadCountDistrictSubscribePhones(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.LoadCountDistrictSubscribePhones(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountUser loads the count of User into the C struct
|
||||
func (o *Organization) LoadCountUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -10688,8 +10210,6 @@ type organizationJoins[Q dialect.Joinable] struct {
|
|||
Nuisances modAs[Q, publicreportNuisanceColumns]
|
||||
PublicreportPool modAs[Q, publicreportPoolColumns]
|
||||
Quicks modAs[Q, publicreportQuickColumns]
|
||||
DistrictSubscribeEmails modAs[Q, publicreportSubscribeEmailColumns]
|
||||
DistrictSubscribePhones modAs[Q, publicreportSubscribePhoneColumns]
|
||||
User modAs[Q, userColumns]
|
||||
}
|
||||
|
||||
|
|
@ -11262,34 +10782,6 @@ func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ st
|
|||
return mods
|
||||
},
|
||||
},
|
||||
DistrictSubscribeEmails: modAs[Q, publicreportSubscribeEmailColumns]{
|
||||
c: PublicreportSubscribeEmails.Columns,
|
||||
f: func(to publicreportSubscribeEmailColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportSubscribeEmails.Name().As(to.Alias())).On(
|
||||
to.DistrictID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
DistrictSubscribePhones: modAs[Q, publicreportSubscribePhoneColumns]{
|
||||
c: PublicreportSubscribePhones.Columns,
|
||||
f: func(to publicreportSubscribePhoneColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, PublicreportSubscribePhones.Name().As(to.Alias())).On(
|
||||
to.DistrictID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
User: modAs[Q, userColumns]{
|
||||
c: Users.Columns,
|
||||
f: func(to userColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
|
|
@ -28,8 +27,7 @@ import (
|
|||
type PublicreportSubscribeEmail struct {
|
||||
Created time.Time `db:"created" `
|
||||
Deleted null.Val[time.Time] `db:"deleted" `
|
||||
DistrictID int32 `db:"district_id,pk" `
|
||||
EmailAddress string `db:"email_address,pk" `
|
||||
EmailAddress string `db:"email_address" `
|
||||
|
||||
R publicreportSubscribeEmailR `db:"-" `
|
||||
}
|
||||
|
|
@ -38,27 +36,25 @@ type PublicreportSubscribeEmail struct {
|
|||
// This should almost always be used instead of []*PublicreportSubscribeEmail.
|
||||
type PublicreportSubscribeEmailSlice []*PublicreportSubscribeEmail
|
||||
|
||||
// PublicreportSubscribeEmails contains methods to work with the subscribe_email table
|
||||
var PublicreportSubscribeEmails = psql.NewTablex[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice, *PublicreportSubscribeEmailSetter]("publicreport", "subscribe_email", buildPublicreportSubscribeEmailColumns("publicreport.subscribe_email"))
|
||||
// PublicreportSubscribeEmails contains methods to work with the subscribe_email view
|
||||
var PublicreportSubscribeEmails = psql.NewViewx[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice]("publicreport", "subscribe_email", buildPublicreportSubscribeEmailColumns("publicreport.subscribe_email"))
|
||||
|
||||
// PublicreportSubscribeEmailsQuery is a query on the subscribe_email table
|
||||
// PublicreportSubscribeEmailsQuery is a query on the subscribe_email view
|
||||
type PublicreportSubscribeEmailsQuery = *psql.ViewQuery[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice]
|
||||
|
||||
// publicreportSubscribeEmailR is where relationships are stored.
|
||||
type publicreportSubscribeEmailR struct {
|
||||
DistrictOrganization *Organization // publicreport.subscribe_email.subscribe_email_district_id_fkey
|
||||
EmailAddressEmailContact *CommsEmailContact // publicreport.subscribe_email.subscribe_email_email_address_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportSubscribeEmailColumns(alias string) publicreportSubscribeEmailColumns {
|
||||
return publicreportSubscribeEmailColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "deleted", "district_id", "email_address",
|
||||
"created", "deleted", "email_address",
|
||||
).WithParent("publicreport.subscribe_email"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Deleted: psql.Quote(alias, "deleted"),
|
||||
DistrictID: psql.Quote(alias, "district_id"),
|
||||
EmailAddress: psql.Quote(alias, "email_address"),
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +64,6 @@ type publicreportSubscribeEmailColumns struct {
|
|||
tableAlias string
|
||||
Created psql.Expression
|
||||
Deleted psql.Expression
|
||||
DistrictID psql.Expression
|
||||
EmailAddress psql.Expression
|
||||
}
|
||||
|
||||
|
|
@ -86,21 +81,17 @@ func (publicreportSubscribeEmailColumns) AliasedAs(alias string) publicreportSub
|
|||
type PublicreportSubscribeEmailSetter struct {
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
||||
DistrictID omit.Val[int32] `db:"district_id,pk" `
|
||||
EmailAddress omit.Val[string] `db:"email_address,pk" `
|
||||
EmailAddress omit.Val[string] `db:"email_address" `
|
||||
}
|
||||
|
||||
func (s PublicreportSubscribeEmailSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
vals := make([]string, 0, 3)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if !s.Deleted.IsUnset() {
|
||||
vals = append(vals, "deleted")
|
||||
}
|
||||
if s.DistrictID.IsValue() {
|
||||
vals = append(vals, "district_id")
|
||||
}
|
||||
if s.EmailAddress.IsValue() {
|
||||
vals = append(vals, "email_address")
|
||||
}
|
||||
|
|
@ -114,21 +105,14 @@ func (s PublicreportSubscribeEmailSetter) Overwrite(t *PublicreportSubscribeEmai
|
|||
if !s.Deleted.IsUnset() {
|
||||
t.Deleted = s.Deleted.MustGetNull()
|
||||
}
|
||||
if s.DistrictID.IsValue() {
|
||||
t.DistrictID = s.DistrictID.MustGet()
|
||||
}
|
||||
if s.EmailAddress.IsValue() {
|
||||
t.EmailAddress = s.EmailAddress.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportSubscribeEmailSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportSubscribeEmails.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 4)
|
||||
vals := make([]bob.Expression, 3)
|
||||
if s.Created.IsValue() {
|
||||
vals[0] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
|
|
@ -141,18 +125,12 @@ func (s *PublicreportSubscribeEmailSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.DistrictID.IsValue() {
|
||||
vals[2] = psql.Arg(s.DistrictID.MustGet())
|
||||
if s.EmailAddress.IsValue() {
|
||||
vals[2] = psql.Arg(s.EmailAddress.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.EmailAddress.IsValue() {
|
||||
vals[3] = psql.Arg(s.EmailAddress.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -162,7 +140,7 @@ func (s PublicreportSubscribeEmailSetter) UpdateMod() bob.Mod[*dialect.UpdateQue
|
|||
}
|
||||
|
||||
func (s PublicreportSubscribeEmailSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
exprs := make([]bob.Expression, 0, 3)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -178,13 +156,6 @@ func (s PublicreportSubscribeEmailSetter) Expressions(prefix ...string) []bob.Ex
|
|||
}})
|
||||
}
|
||||
|
||||
if s.DistrictID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "district_id")...),
|
||||
psql.Arg(s.DistrictID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.EmailAddress.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "email_address")...),
|
||||
|
|
@ -195,31 +166,6 @@ func (s PublicreportSubscribeEmailSetter) Expressions(prefix ...string) []bob.Ex
|
|||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportSubscribeEmail retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportSubscribeEmail(ctx context.Context, exec bob.Executor, DistrictIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportSubscribeEmail, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportSubscribeEmails.Query(
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.DistrictID.EQ(psql.Arg(DistrictIDPK))),
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportSubscribeEmails.Query(
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.DistrictID.EQ(psql.Arg(DistrictIDPK))),
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
|
||||
sm.Columns(PublicreportSubscribeEmails.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportSubscribeEmailExists checks the presence of a single record by primary key
|
||||
func PublicreportSubscribeEmailExists(ctx context.Context, exec bob.Executor, DistrictIDPK int32, EmailAddressPK string) (bool, error) {
|
||||
return PublicreportSubscribeEmails.Query(
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.DistrictID.EQ(psql.Arg(DistrictIDPK))),
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportSubscribeEmail is retrieved from the database
|
||||
func (o *PublicreportSubscribeEmail) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
|
@ -227,65 +173,11 @@ func (o *PublicreportSubscribeEmail) AfterQueryHook(ctx context.Context, exec bo
|
|||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterSelectHooks.RunHooks(ctx, exec, PublicreportSubscribeEmailSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterInsertHooks.RunHooks(ctx, exec, PublicreportSubscribeEmailSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportSubscribeEmailSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportSubscribeEmailSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportSubscribeEmail
|
||||
func (o *PublicreportSubscribeEmail) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.DistrictID,
|
||||
o.EmailAddress,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *PublicreportSubscribeEmail) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("publicreport.subscribe_email", "district_id"), psql.Quote("publicreport.subscribe_email", "email_address")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the PublicreportSubscribeEmail
|
||||
func (o *PublicreportSubscribeEmail) Update(ctx context.Context, exec bob.Executor, s *PublicreportSubscribeEmailSetter) error {
|
||||
v, err := PublicreportSubscribeEmails.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single PublicreportSubscribeEmail record with an executor
|
||||
func (o *PublicreportSubscribeEmail) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportSubscribeEmails.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportSubscribeEmail using the executor
|
||||
func (o *PublicreportSubscribeEmail) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportSubscribeEmails.Query(
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.DistrictID.EQ(psql.Arg(o.DistrictID))),
|
||||
sm.Where(PublicreportSubscribeEmails.Columns.EmailAddress.EQ(psql.Arg(o.EmailAddress))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportSubscribeEmailSlice is retrieved from the database
|
||||
func (o PublicreportSubscribeEmailSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
|
@ -293,165 +185,11 @@ func (o PublicreportSubscribeEmailSlice) AfterQueryHook(ctx context.Context, exe
|
|||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportSubscribeEmails.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribeEmailSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("publicreport.subscribe_email", "district_id"), psql.Quote("publicreport.subscribe_email", "email_address")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o PublicreportSubscribeEmailSlice) copyMatchingRows(from ...*PublicreportSubscribeEmail) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.DistrictID != old.DistrictID {
|
||||
continue
|
||||
}
|
||||
if new.EmailAddress != old.EmailAddress {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportSubscribeEmailSlice) 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 PublicreportSubscribeEmails.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 *PublicreportSubscribeEmail:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportSubscribeEmail:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportSubscribeEmailSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportSubscribeEmail or a slice of PublicreportSubscribeEmail
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportSubscribeEmails.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportSubscribeEmailSlice) 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 PublicreportSubscribeEmails.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 *PublicreportSubscribeEmail:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportSubscribeEmail:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportSubscribeEmailSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportSubscribeEmail or a slice of PublicreportSubscribeEmail
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportSubscribeEmails.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribeEmailSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportSubscribeEmailSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportSubscribeEmails.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribeEmailSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportSubscribeEmails.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribeEmailSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportSubscribeEmails.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DistrictOrganization starts a query for related objects on organization
|
||||
func (o *PublicreportSubscribeEmail) DistrictOrganization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.DistrictID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportSubscribeEmailSlice) DistrictOrganization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkDistrictID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkDistrictID = append(pkDistrictID, o.DistrictID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkDistrictID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// EmailAddressEmailContact starts a query for related objects on comms.email_contact
|
||||
func (o *PublicreportSubscribeEmail) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
|
||||
return CommsEmailContacts.Query(append(mods,
|
||||
|
|
@ -476,106 +214,9 @@ func (os PublicreportSubscribeEmailSlice) EmailAddressEmailContact(mods ...bob.M
|
|||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportSubscribeEmailDistrictOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribeEmail0 *PublicreportSubscribeEmail, organization1 *Organization) (*PublicreportSubscribeEmail, error) {
|
||||
setter := &PublicreportSubscribeEmailSetter{
|
||||
DistrictID: omit.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := publicreportSubscribeEmail0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportSubscribeEmailDistrictOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribeEmail0, nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribeEmail0 *PublicreportSubscribeEmail) InsertDistrictOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportSubscribeEmailDistrictOrganization0(ctx, exec, 1, publicreportSubscribeEmail0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribeEmail0.R.DistrictOrganization = organization1
|
||||
|
||||
organization1.R.DistrictSubscribeEmails = append(organization1.R.DistrictSubscribeEmails, publicreportSubscribeEmail0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribeEmail0 *PublicreportSubscribeEmail) AttachDistrictOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportSubscribeEmailDistrictOrganization0(ctx, exec, 1, publicreportSubscribeEmail0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribeEmail0.R.DistrictOrganization = organization1
|
||||
|
||||
organization1.R.DistrictSubscribeEmails = append(organization1.R.DistrictSubscribeEmails, publicreportSubscribeEmail0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportSubscribeEmailEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribeEmail0 *PublicreportSubscribeEmail, commsEmailContact1 *CommsEmailContact) (*PublicreportSubscribeEmail, error) {
|
||||
setter := &PublicreportSubscribeEmailSetter{
|
||||
EmailAddress: omit.From(commsEmailContact1.Address),
|
||||
}
|
||||
|
||||
err := publicreportSubscribeEmail0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportSubscribeEmailEmailAddressEmailContact0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribeEmail0, nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribeEmail0 *PublicreportSubscribeEmail) InsertEmailAddressEmailContact(ctx context.Context, exec bob.Executor, related *CommsEmailContactSetter) error {
|
||||
var err error
|
||||
|
||||
commsEmailContact1, err := CommsEmailContacts.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportSubscribeEmailEmailAddressEmailContact0(ctx, exec, 1, publicreportSubscribeEmail0, commsEmailContact1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribeEmail0.R.EmailAddressEmailContact = commsEmailContact1
|
||||
|
||||
commsEmailContact1.R.EmailAddressSubscribeEmails = append(commsEmailContact1.R.EmailAddressSubscribeEmails, publicreportSubscribeEmail0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribeEmail0 *PublicreportSubscribeEmail) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportSubscribeEmailEmailAddressEmailContact0(ctx, exec, 1, publicreportSubscribeEmail0, commsEmailContact1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribeEmail0.R.EmailAddressEmailContact = commsEmailContact1
|
||||
|
||||
commsEmailContact1.R.EmailAddressSubscribeEmails = append(commsEmailContact1.R.EmailAddressSubscribeEmails, publicreportSubscribeEmail0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportSubscribeEmailWhere[Q psql.Filterable] struct {
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Deleted psql.WhereNullMod[Q, time.Time]
|
||||
DistrictID psql.WhereMod[Q, int32]
|
||||
EmailAddress psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
|
|
@ -587,7 +228,6 @@ func buildPublicreportSubscribeEmailWhere[Q psql.Filterable](cols publicreportSu
|
|||
return publicreportSubscribeEmailWhere[Q]{
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
||||
DistrictID: psql.Where[Q, int32](cols.DistrictID),
|
||||
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
|
||||
}
|
||||
}
|
||||
|
|
@ -598,18 +238,6 @@ func (o *PublicreportSubscribeEmail) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "DistrictOrganization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportSubscribeEmail cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.DistrictOrganization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.DistrictSubscribeEmails = PublicreportSubscribeEmailSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "EmailAddressEmailContact":
|
||||
rel, ok := retrieved.(*CommsEmailContact)
|
||||
if !ok {
|
||||
|
|
@ -628,25 +256,11 @@ func (o *PublicreportSubscribeEmail) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
type publicreportSubscribeEmailPreloader struct {
|
||||
DistrictOrganization func(...psql.PreloadOption) psql.Preloader
|
||||
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportSubscribeEmailPreloader() publicreportSubscribeEmailPreloader {
|
||||
return publicreportSubscribeEmailPreloader{
|
||||
DistrictOrganization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "DistrictOrganization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportSubscribeEmails,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"district_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
|
||||
Name: "EmailAddressEmailContact",
|
||||
|
|
@ -664,25 +278,15 @@ func buildPublicreportSubscribeEmailPreloader() publicreportSubscribeEmailPreloa
|
|||
}
|
||||
|
||||
type publicreportSubscribeEmailThenLoader[Q orm.Loadable] struct {
|
||||
DistrictOrganization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportSubscribeEmailThenLoader[Q orm.Loadable]() publicreportSubscribeEmailThenLoader[Q] {
|
||||
type DistrictOrganizationLoadInterface interface {
|
||||
LoadDistrictOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type EmailAddressEmailContactLoadInterface interface {
|
||||
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportSubscribeEmailThenLoader[Q]{
|
||||
DistrictOrganization: thenLoadBuilder[Q](
|
||||
"DistrictOrganization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DistrictOrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadDistrictOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
EmailAddressEmailContact: thenLoadBuilder[Q](
|
||||
"EmailAddressEmailContact",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressEmailContactLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -692,58 +296,6 @@ func buildPublicreportSubscribeEmailThenLoader[Q orm.Loadable]() publicreportSub
|
|||
}
|
||||
}
|
||||
|
||||
// LoadDistrictOrganization loads the publicreportSubscribeEmail's DistrictOrganization into the .R struct
|
||||
func (o *PublicreportSubscribeEmail) LoadDistrictOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.DistrictOrganization = nil
|
||||
|
||||
related, err := o.DistrictOrganization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.DistrictSubscribeEmails = PublicreportSubscribeEmailSlice{o}
|
||||
|
||||
o.R.DistrictOrganization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDistrictOrganization loads the publicreportSubscribeEmail's DistrictOrganization into the .R struct
|
||||
func (os PublicreportSubscribeEmailSlice) LoadDistrictOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.DistrictOrganization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
|
||||
if !(o.DistrictID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.DistrictSubscribeEmails = append(rel.R.DistrictSubscribeEmails, o)
|
||||
|
||||
o.R.DistrictOrganization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadEmailAddressEmailContact loads the publicreportSubscribeEmail's EmailAddressEmailContact into the .R struct
|
||||
func (o *PublicreportSubscribeEmail) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -798,7 +350,6 @@ func (os PublicreportSubscribeEmailSlice) LoadEmailAddressEmailContact(ctx conte
|
|||
|
||||
type publicreportSubscribeEmailJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
DistrictOrganization modAs[Q, organizationColumns]
|
||||
EmailAddressEmailContact modAs[Q, commsEmailContactColumns]
|
||||
}
|
||||
|
||||
|
|
@ -809,20 +360,6 @@ func (j publicreportSubscribeEmailJoins[Q]) aliasedAs(alias string) publicreport
|
|||
func buildPublicreportSubscribeEmailJoins[Q dialect.Joinable](cols publicreportSubscribeEmailColumns, typ string) publicreportSubscribeEmailJoins[Q] {
|
||||
return publicreportSubscribeEmailJoins[Q]{
|
||||
typ: typ,
|
||||
DistrictOrganization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.DistrictID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
EmailAddressEmailContact: modAs[Q, commsEmailContactColumns]{
|
||||
c: CommsEmailContacts.Columns,
|
||||
f: func(to commsEmailContactColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
|
|
@ -26,10 +25,9 @@ import (
|
|||
|
||||
// PublicreportSubscribePhone is an object representing the database table.
|
||||
type PublicreportSubscribePhone struct {
|
||||
Created time.Time `db:"created" `
|
||||
Deleted null.Val[time.Time] `db:"deleted" `
|
||||
DistrictID int32 `db:"district_id,pk" `
|
||||
PhoneE164 string `db:"phone_e164,pk" `
|
||||
Created time.Time `db:"created" `
|
||||
Deleted null.Val[time.Time] `db:"deleted" `
|
||||
PhoneE164 string `db:"phone_e164" `
|
||||
|
||||
R publicreportSubscribePhoneR `db:"-" `
|
||||
}
|
||||
|
|
@ -38,27 +36,25 @@ type PublicreportSubscribePhone struct {
|
|||
// This should almost always be used instead of []*PublicreportSubscribePhone.
|
||||
type PublicreportSubscribePhoneSlice []*PublicreportSubscribePhone
|
||||
|
||||
// PublicreportSubscribePhones contains methods to work with the subscribe_phone table
|
||||
var PublicreportSubscribePhones = psql.NewTablex[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice, *PublicreportSubscribePhoneSetter]("publicreport", "subscribe_phone", buildPublicreportSubscribePhoneColumns("publicreport.subscribe_phone"))
|
||||
// PublicreportSubscribePhones contains methods to work with the subscribe_phone view
|
||||
var PublicreportSubscribePhones = psql.NewViewx[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice]("publicreport", "subscribe_phone", buildPublicreportSubscribePhoneColumns("publicreport.subscribe_phone"))
|
||||
|
||||
// PublicreportSubscribePhonesQuery is a query on the subscribe_phone table
|
||||
// PublicreportSubscribePhonesQuery is a query on the subscribe_phone view
|
||||
type PublicreportSubscribePhonesQuery = *psql.ViewQuery[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice]
|
||||
|
||||
// publicreportSubscribePhoneR is where relationships are stored.
|
||||
type publicreportSubscribePhoneR struct {
|
||||
DistrictOrganization *Organization // publicreport.subscribe_phone.subscribe_phone_district_id_fkey
|
||||
PhoneE164Phone *CommsPhone // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
|
||||
PhoneE164Phone *CommsPhone // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportSubscribePhoneColumns(alias string) publicreportSubscribePhoneColumns {
|
||||
return publicreportSubscribePhoneColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "deleted", "district_id", "phone_e164",
|
||||
"created", "deleted", "phone_e164",
|
||||
).WithParent("publicreport.subscribe_phone"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Deleted: psql.Quote(alias, "deleted"),
|
||||
DistrictID: psql.Quote(alias, "district_id"),
|
||||
PhoneE164: psql.Quote(alias, "phone_e164"),
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +64,6 @@ type publicreportSubscribePhoneColumns struct {
|
|||
tableAlias string
|
||||
Created psql.Expression
|
||||
Deleted psql.Expression
|
||||
DistrictID psql.Expression
|
||||
PhoneE164 psql.Expression
|
||||
}
|
||||
|
||||
|
|
@ -84,23 +79,19 @@ func (publicreportSubscribePhoneColumns) AliasedAs(alias string) publicreportSub
|
|||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportSubscribePhoneSetter struct {
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
||||
DistrictID omit.Val[int32] `db:"district_id,pk" `
|
||||
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
||||
PhoneE164 omit.Val[string] `db:"phone_e164" `
|
||||
}
|
||||
|
||||
func (s PublicreportSubscribePhoneSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
vals := make([]string, 0, 3)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if !s.Deleted.IsUnset() {
|
||||
vals = append(vals, "deleted")
|
||||
}
|
||||
if s.DistrictID.IsValue() {
|
||||
vals = append(vals, "district_id")
|
||||
}
|
||||
if s.PhoneE164.IsValue() {
|
||||
vals = append(vals, "phone_e164")
|
||||
}
|
||||
|
|
@ -114,21 +105,14 @@ func (s PublicreportSubscribePhoneSetter) Overwrite(t *PublicreportSubscribePhon
|
|||
if !s.Deleted.IsUnset() {
|
||||
t.Deleted = s.Deleted.MustGetNull()
|
||||
}
|
||||
if s.DistrictID.IsValue() {
|
||||
t.DistrictID = s.DistrictID.MustGet()
|
||||
}
|
||||
if s.PhoneE164.IsValue() {
|
||||
t.PhoneE164 = s.PhoneE164.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportSubscribePhoneSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return PublicreportSubscribePhones.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 4)
|
||||
vals := make([]bob.Expression, 3)
|
||||
if s.Created.IsValue() {
|
||||
vals[0] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
|
|
@ -141,18 +125,12 @@ func (s *PublicreportSubscribePhoneSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.DistrictID.IsValue() {
|
||||
vals[2] = psql.Arg(s.DistrictID.MustGet())
|
||||
if s.PhoneE164.IsValue() {
|
||||
vals[2] = psql.Arg(s.PhoneE164.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.PhoneE164.IsValue() {
|
||||
vals[3] = psql.Arg(s.PhoneE164.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -162,7 +140,7 @@ func (s PublicreportSubscribePhoneSetter) UpdateMod() bob.Mod[*dialect.UpdateQue
|
|||
}
|
||||
|
||||
func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
exprs := make([]bob.Expression, 0, 3)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -178,13 +156,6 @@ func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Ex
|
|||
}})
|
||||
}
|
||||
|
||||
if s.DistrictID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "district_id")...),
|
||||
psql.Arg(s.DistrictID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.PhoneE164.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "phone_e164")...),
|
||||
|
|
@ -195,31 +166,6 @@ func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Ex
|
|||
return exprs
|
||||
}
|
||||
|
||||
// FindPublicreportSubscribePhone retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindPublicreportSubscribePhone(ctx context.Context, exec bob.Executor, DistrictIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportSubscribePhone, error) {
|
||||
if len(cols) == 0 {
|
||||
return PublicreportSubscribePhones.Query(
|
||||
sm.Where(PublicreportSubscribePhones.Columns.DistrictID.EQ(psql.Arg(DistrictIDPK))),
|
||||
sm.Where(PublicreportSubscribePhones.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return PublicreportSubscribePhones.Query(
|
||||
sm.Where(PublicreportSubscribePhones.Columns.DistrictID.EQ(psql.Arg(DistrictIDPK))),
|
||||
sm.Where(PublicreportSubscribePhones.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
|
||||
sm.Columns(PublicreportSubscribePhones.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// PublicreportSubscribePhoneExists checks the presence of a single record by primary key
|
||||
func PublicreportSubscribePhoneExists(ctx context.Context, exec bob.Executor, DistrictIDPK int32, PhoneE164PK string) (bool, error) {
|
||||
return PublicreportSubscribePhones.Query(
|
||||
sm.Where(PublicreportSubscribePhones.Columns.DistrictID.EQ(psql.Arg(DistrictIDPK))),
|
||||
sm.Where(PublicreportSubscribePhones.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportSubscribePhone is retrieved from the database
|
||||
func (o *PublicreportSubscribePhone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
|
@ -227,65 +173,11 @@ func (o *PublicreportSubscribePhone) AfterQueryHook(ctx context.Context, exec bo
|
|||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportSubscribePhones.AfterSelectHooks.RunHooks(ctx, exec, PublicreportSubscribePhoneSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportSubscribePhones.AfterInsertHooks.RunHooks(ctx, exec, PublicreportSubscribePhoneSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportSubscribePhones.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportSubscribePhoneSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportSubscribePhones.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportSubscribePhoneSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the PublicreportSubscribePhone
|
||||
func (o *PublicreportSubscribePhone) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.DistrictID,
|
||||
o.PhoneE164,
|
||||
)
|
||||
}
|
||||
|
||||
func (o *PublicreportSubscribePhone) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("publicreport.subscribe_phone", "district_id"), psql.Quote("publicreport.subscribe_phone", "phone_e164")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the PublicreportSubscribePhone
|
||||
func (o *PublicreportSubscribePhone) Update(ctx context.Context, exec bob.Executor, s *PublicreportSubscribePhoneSetter) error {
|
||||
v, err := PublicreportSubscribePhones.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single PublicreportSubscribePhone record with an executor
|
||||
func (o *PublicreportSubscribePhone) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := PublicreportSubscribePhones.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the PublicreportSubscribePhone using the executor
|
||||
func (o *PublicreportSubscribePhone) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := PublicreportSubscribePhones.Query(
|
||||
sm.Where(PublicreportSubscribePhones.Columns.DistrictID.EQ(psql.Arg(o.DistrictID))),
|
||||
sm.Where(PublicreportSubscribePhones.Columns.PhoneE164.EQ(psql.Arg(o.PhoneE164))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportSubscribePhoneSlice is retrieved from the database
|
||||
func (o PublicreportSubscribePhoneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
|
@ -293,165 +185,11 @@ func (o PublicreportSubscribePhoneSlice) AfterQueryHook(ctx context.Context, exe
|
|||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportSubscribePhones.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = PublicreportSubscribePhones.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = PublicreportSubscribePhones.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = PublicreportSubscribePhones.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribePhoneSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("publicreport.subscribe_phone", "district_id"), psql.Quote("publicreport.subscribe_phone", "phone_e164")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o PublicreportSubscribePhoneSlice) copyMatchingRows(from ...*PublicreportSubscribePhone) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.DistrictID != old.DistrictID {
|
||||
continue
|
||||
}
|
||||
if new.PhoneE164 != old.PhoneE164 {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportSubscribePhoneSlice) 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 PublicreportSubscribePhones.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 *PublicreportSubscribePhone:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportSubscribePhone:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportSubscribePhoneSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportSubscribePhone or a slice of PublicreportSubscribePhone
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = PublicreportSubscribePhones.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o PublicreportSubscribePhoneSlice) 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 PublicreportSubscribePhones.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 *PublicreportSubscribePhone:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*PublicreportSubscribePhone:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case PublicreportSubscribePhoneSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a PublicreportSubscribePhone or a slice of PublicreportSubscribePhone
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = PublicreportSubscribePhones.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribePhoneSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportSubscribePhoneSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportSubscribePhones.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribePhoneSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := PublicreportSubscribePhones.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o PublicreportSubscribePhoneSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := PublicreportSubscribePhones.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DistrictOrganization starts a query for related objects on organization
|
||||
func (o *PublicreportSubscribePhone) DistrictOrganization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.DistrictID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportSubscribePhoneSlice) DistrictOrganization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkDistrictID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkDistrictID = append(pkDistrictID, o.DistrictID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkDistrictID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// PhoneE164Phone starts a query for related objects on comms.phone
|
||||
func (o *PublicreportSubscribePhone) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||
return CommsPhones.Query(append(mods,
|
||||
|
|
@ -476,107 +214,10 @@ func (os PublicreportSubscribePhoneSlice) PhoneE164Phone(mods ...bob.Mod[*dialec
|
|||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportSubscribePhoneDistrictOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribePhone0 *PublicreportSubscribePhone, organization1 *Organization) (*PublicreportSubscribePhone, error) {
|
||||
setter := &PublicreportSubscribePhoneSetter{
|
||||
DistrictID: omit.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := publicreportSubscribePhone0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportSubscribePhoneDistrictOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribePhone0, nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribePhone0 *PublicreportSubscribePhone) InsertDistrictOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportSubscribePhoneDistrictOrganization0(ctx, exec, 1, publicreportSubscribePhone0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribePhone0.R.DistrictOrganization = organization1
|
||||
|
||||
organization1.R.DistrictSubscribePhones = append(organization1.R.DistrictSubscribePhones, publicreportSubscribePhone0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribePhone0 *PublicreportSubscribePhone) AttachDistrictOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportSubscribePhoneDistrictOrganization0(ctx, exec, 1, publicreportSubscribePhone0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribePhone0.R.DistrictOrganization = organization1
|
||||
|
||||
organization1.R.DistrictSubscribePhones = append(organization1.R.DistrictSubscribePhones, publicreportSubscribePhone0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportSubscribePhonePhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportSubscribePhone0 *PublicreportSubscribePhone, commsPhone1 *CommsPhone) (*PublicreportSubscribePhone, error) {
|
||||
setter := &PublicreportSubscribePhoneSetter{
|
||||
PhoneE164: omit.From(commsPhone1.E164),
|
||||
}
|
||||
|
||||
err := publicreportSubscribePhone0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportSubscribePhonePhoneE164Phone0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportSubscribePhone0, nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribePhone0 *PublicreportSubscribePhone) InsertPhoneE164Phone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
|
||||
var err error
|
||||
|
||||
commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportSubscribePhonePhoneE164Phone0(ctx, exec, 1, publicreportSubscribePhone0, commsPhone1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribePhone0.R.PhoneE164Phone = commsPhone1
|
||||
|
||||
commsPhone1.R.PhoneE164SubscribePhones = append(commsPhone1.R.PhoneE164SubscribePhones, publicreportSubscribePhone0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportSubscribePhone0 *PublicreportSubscribePhone) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportSubscribePhonePhoneE164Phone0(ctx, exec, 1, publicreportSubscribePhone0, commsPhone1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportSubscribePhone0.R.PhoneE164Phone = commsPhone1
|
||||
|
||||
commsPhone1.R.PhoneE164SubscribePhones = append(commsPhone1.R.PhoneE164SubscribePhones, publicreportSubscribePhone0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportSubscribePhoneWhere[Q psql.Filterable] struct {
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Deleted psql.WhereNullMod[Q, time.Time]
|
||||
DistrictID psql.WhereMod[Q, int32]
|
||||
PhoneE164 psql.WhereMod[Q, string]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Deleted psql.WhereNullMod[Q, time.Time]
|
||||
PhoneE164 psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (publicreportSubscribePhoneWhere[Q]) AliasedAs(alias string) publicreportSubscribePhoneWhere[Q] {
|
||||
|
|
@ -585,10 +226,9 @@ func (publicreportSubscribePhoneWhere[Q]) AliasedAs(alias string) publicreportSu
|
|||
|
||||
func buildPublicreportSubscribePhoneWhere[Q psql.Filterable](cols publicreportSubscribePhoneColumns) publicreportSubscribePhoneWhere[Q] {
|
||||
return publicreportSubscribePhoneWhere[Q]{
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
||||
DistrictID: psql.Where[Q, int32](cols.DistrictID),
|
||||
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
||||
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -598,18 +238,6 @@ func (o *PublicreportSubscribePhone) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "DistrictOrganization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportSubscribePhone cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.DistrictOrganization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.DistrictSubscribePhones = PublicreportSubscribePhoneSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "PhoneE164Phone":
|
||||
rel, ok := retrieved.(*CommsPhone)
|
||||
if !ok {
|
||||
|
|
@ -628,25 +256,11 @@ func (o *PublicreportSubscribePhone) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
type publicreportSubscribePhonePreloader struct {
|
||||
DistrictOrganization func(...psql.PreloadOption) psql.Preloader
|
||||
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
|
||||
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportSubscribePhonePreloader() publicreportSubscribePhonePreloader {
|
||||
return publicreportSubscribePhonePreloader{
|
||||
DistrictOrganization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "DistrictOrganization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportSubscribePhones,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"district_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
|
||||
Name: "PhoneE164Phone",
|
||||
|
|
@ -664,25 +278,15 @@ func buildPublicreportSubscribePhonePreloader() publicreportSubscribePhonePreloa
|
|||
}
|
||||
|
||||
type publicreportSubscribePhoneThenLoader[Q orm.Loadable] struct {
|
||||
DistrictOrganization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportSubscribePhoneThenLoader[Q orm.Loadable]() publicreportSubscribePhoneThenLoader[Q] {
|
||||
type DistrictOrganizationLoadInterface interface {
|
||||
LoadDistrictOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PhoneE164PhoneLoadInterface interface {
|
||||
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportSubscribePhoneThenLoader[Q]{
|
||||
DistrictOrganization: thenLoadBuilder[Q](
|
||||
"DistrictOrganization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved DistrictOrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadDistrictOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
PhoneE164Phone: thenLoadBuilder[Q](
|
||||
"PhoneE164Phone",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -692,58 +296,6 @@ func buildPublicreportSubscribePhoneThenLoader[Q orm.Loadable]() publicreportSub
|
|||
}
|
||||
}
|
||||
|
||||
// LoadDistrictOrganization loads the publicreportSubscribePhone's DistrictOrganization into the .R struct
|
||||
func (o *PublicreportSubscribePhone) LoadDistrictOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.DistrictOrganization = nil
|
||||
|
||||
related, err := o.DistrictOrganization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.DistrictSubscribePhones = PublicreportSubscribePhoneSlice{o}
|
||||
|
||||
o.R.DistrictOrganization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadDistrictOrganization loads the publicreportSubscribePhone's DistrictOrganization into the .R struct
|
||||
func (os PublicreportSubscribePhoneSlice) LoadDistrictOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.DistrictOrganization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
|
||||
if !(o.DistrictID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.DistrictSubscribePhones = append(rel.R.DistrictSubscribePhones, o)
|
||||
|
||||
o.R.DistrictOrganization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPhoneE164Phone loads the publicreportSubscribePhone's PhoneE164Phone into the .R struct
|
||||
func (o *PublicreportSubscribePhone) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -797,9 +349,8 @@ func (os PublicreportSubscribePhoneSlice) LoadPhoneE164Phone(ctx context.Context
|
|||
}
|
||||
|
||||
type publicreportSubscribePhoneJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
DistrictOrganization modAs[Q, organizationColumns]
|
||||
PhoneE164Phone modAs[Q, commsPhoneColumns]
|
||||
typ string
|
||||
PhoneE164Phone modAs[Q, commsPhoneColumns]
|
||||
}
|
||||
|
||||
func (j publicreportSubscribePhoneJoins[Q]) aliasedAs(alias string) publicreportSubscribePhoneJoins[Q] {
|
||||
|
|
@ -809,20 +360,6 @@ func (j publicreportSubscribePhoneJoins[Q]) aliasedAs(alias string) publicreport
|
|||
func buildPublicreportSubscribePhoneJoins[Q dialect.Joinable](cols publicreportSubscribePhoneColumns, typ string) publicreportSubscribePhoneJoins[Q] {
|
||||
return publicreportSubscribePhoneJoins[Q]{
|
||||
typ: typ,
|
||||
DistrictOrganization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.DistrictID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
PhoneE164Phone: modAs[Q, commsPhoneColumns]{
|
||||
c: CommsPhones.Columns,
|
||||
f: func(to commsPhoneColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue