Modify email subscription table to drop district ID
I don't have time to work out all the behavior, this is just to get to where I can release
This commit is contained in:
parent
d93cdbef41
commit
e40fe55eaf
15 changed files with 1302 additions and 26 deletions
17
db/dberrors/publicreport.subscribe_email.bob.go
Normal file
17
db/dberrors/publicreport.subscribe_email.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
// 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{"id"},
|
||||||
|
s: "subscribe_email_pkey",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
type publicreportSubscribeEmailErrors struct {
|
||||||
|
ErrUniqueSubscribeEmailPkey *UniqueConstraintError
|
||||||
|
}
|
||||||
17
db/dberrors/publicreport.subscribe_phone.bob.go
Normal file
17
db/dberrors/publicreport.subscribe_phone.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
// 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{"id"},
|
||||||
|
s: "subscribe_phone_pkey",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
type publicreportSubscribePhoneErrors struct {
|
||||||
|
ErrUniqueSubscribePhonePkey *UniqueConstraintError
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
package dbinfo
|
package dbinfo
|
||||||
|
|
||||||
|
import "github.com/aarondl/opt/null"
|
||||||
|
|
||||||
var PublicreportSubscribeEmails = Table[
|
var PublicreportSubscribeEmails = Table[
|
||||||
publicreportSubscribeEmailColumns,
|
publicreportSubscribeEmailColumns,
|
||||||
publicreportSubscribeEmailIndexes,
|
publicreportSubscribeEmailIndexes,
|
||||||
|
|
@ -40,8 +42,40 @@ var PublicreportSubscribeEmails = Table[
|
||||||
Generated: false,
|
Generated: false,
|
||||||
AutoIncr: false,
|
AutoIncr: false,
|
||||||
},
|
},
|
||||||
|
ID: column{
|
||||||
|
Name: "id",
|
||||||
|
DBType: "integer",
|
||||||
|
Default: "nextval('publicreport.subscribe_email_id_seq'::regclass)",
|
||||||
|
Comment: "",
|
||||||
|
Nullable: false,
|
||||||
|
Generated: false,
|
||||||
|
AutoIncr: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Indexes: publicreportSubscribeEmailIndexes{
|
||||||
|
SubscribeEmailPkey: index{
|
||||||
|
Type: "btree",
|
||||||
|
Name: "subscribe_email_pkey",
|
||||||
|
Columns: []indexColumn{
|
||||||
|
{
|
||||||
|
Name: "id",
|
||||||
|
Desc: null.FromCond(false, true),
|
||||||
|
IsExpression: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Unique: true,
|
||||||
|
Comment: "",
|
||||||
|
NullsFirst: []bool{false},
|
||||||
|
NullsDistinct: false,
|
||||||
|
Where: "",
|
||||||
|
Include: []string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PrimaryKey: &constraint{
|
||||||
|
Name: "subscribe_email_pkey",
|
||||||
|
Columns: []string{"id"},
|
||||||
|
Comment: "",
|
||||||
},
|
},
|
||||||
|
|
||||||
ForeignKeys: publicreportSubscribeEmailForeignKeys{
|
ForeignKeys: publicreportSubscribeEmailForeignKeys{
|
||||||
PublicreportSubscribeEmailSubscribeEmailEmailAddressFkey: foreignKey{
|
PublicreportSubscribeEmailSubscribeEmailEmailAddressFkey: foreignKey{
|
||||||
constraint: constraint{
|
constraint: constraint{
|
||||||
|
|
@ -61,18 +95,23 @@ type publicreportSubscribeEmailColumns struct {
|
||||||
Created column
|
Created column
|
||||||
Deleted column
|
Deleted column
|
||||||
EmailAddress column
|
EmailAddress column
|
||||||
|
ID column
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c publicreportSubscribeEmailColumns) AsSlice() []column {
|
func (c publicreportSubscribeEmailColumns) AsSlice() []column {
|
||||||
return []column{
|
return []column{
|
||||||
c.Created, c.Deleted, c.EmailAddress,
|
c.Created, c.Deleted, c.EmailAddress, c.ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type publicreportSubscribeEmailIndexes struct{}
|
type publicreportSubscribeEmailIndexes struct {
|
||||||
|
SubscribeEmailPkey index
|
||||||
|
}
|
||||||
|
|
||||||
func (i publicreportSubscribeEmailIndexes) AsSlice() []index {
|
func (i publicreportSubscribeEmailIndexes) AsSlice() []index {
|
||||||
return []index{}
|
return []index{
|
||||||
|
i.SubscribeEmailPkey,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type publicreportSubscribeEmailForeignKeys struct {
|
type publicreportSubscribeEmailForeignKeys struct {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
package dbinfo
|
package dbinfo
|
||||||
|
|
||||||
|
import "github.com/aarondl/opt/null"
|
||||||
|
|
||||||
var PublicreportSubscribePhones = Table[
|
var PublicreportSubscribePhones = Table[
|
||||||
publicreportSubscribePhoneColumns,
|
publicreportSubscribePhoneColumns,
|
||||||
publicreportSubscribePhoneIndexes,
|
publicreportSubscribePhoneIndexes,
|
||||||
|
|
@ -31,6 +33,15 @@ var PublicreportSubscribePhones = Table[
|
||||||
Generated: false,
|
Generated: false,
|
||||||
AutoIncr: false,
|
AutoIncr: false,
|
||||||
},
|
},
|
||||||
|
ID: column{
|
||||||
|
Name: "id",
|
||||||
|
DBType: "integer",
|
||||||
|
Default: "nextval('publicreport.subscribe_phone_id_seq'::regclass)",
|
||||||
|
Comment: "",
|
||||||
|
Nullable: false,
|
||||||
|
Generated: false,
|
||||||
|
AutoIncr: false,
|
||||||
|
},
|
||||||
PhoneE164: column{
|
PhoneE164: column{
|
||||||
Name: "phone_e164",
|
Name: "phone_e164",
|
||||||
DBType: "text",
|
DBType: "text",
|
||||||
|
|
@ -41,7 +52,30 @@ var PublicreportSubscribePhones = Table[
|
||||||
AutoIncr: false,
|
AutoIncr: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Indexes: publicreportSubscribePhoneIndexes{
|
||||||
|
SubscribePhonePkey: index{
|
||||||
|
Type: "btree",
|
||||||
|
Name: "subscribe_phone_pkey",
|
||||||
|
Columns: []indexColumn{
|
||||||
|
{
|
||||||
|
Name: "id",
|
||||||
|
Desc: null.FromCond(false, true),
|
||||||
|
IsExpression: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Unique: true,
|
||||||
|
Comment: "",
|
||||||
|
NullsFirst: []bool{false},
|
||||||
|
NullsDistinct: false,
|
||||||
|
Where: "",
|
||||||
|
Include: []string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PrimaryKey: &constraint{
|
||||||
|
Name: "subscribe_phone_pkey",
|
||||||
|
Columns: []string{"id"},
|
||||||
|
Comment: "",
|
||||||
|
},
|
||||||
ForeignKeys: publicreportSubscribePhoneForeignKeys{
|
ForeignKeys: publicreportSubscribePhoneForeignKeys{
|
||||||
PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey: foreignKey{
|
PublicreportSubscribePhoneSubscribePhonePhoneE164Fkey: foreignKey{
|
||||||
constraint: constraint{
|
constraint: constraint{
|
||||||
|
|
@ -60,19 +94,24 @@ var PublicreportSubscribePhones = Table[
|
||||||
type publicreportSubscribePhoneColumns struct {
|
type publicreportSubscribePhoneColumns struct {
|
||||||
Created column
|
Created column
|
||||||
Deleted column
|
Deleted column
|
||||||
|
ID column
|
||||||
PhoneE164 column
|
PhoneE164 column
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c publicreportSubscribePhoneColumns) AsSlice() []column {
|
func (c publicreportSubscribePhoneColumns) AsSlice() []column {
|
||||||
return []column{
|
return []column{
|
||||||
c.Created, c.Deleted, c.PhoneE164,
|
c.Created, c.Deleted, c.ID, c.PhoneE164,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type publicreportSubscribePhoneIndexes struct{}
|
type publicreportSubscribePhoneIndexes struct {
|
||||||
|
SubscribePhonePkey index
|
||||||
|
}
|
||||||
|
|
||||||
func (i publicreportSubscribePhoneIndexes) AsSlice() []index {
|
func (i publicreportSubscribePhoneIndexes) AsSlice() []index {
|
||||||
return []index{}
|
return []index{
|
||||||
|
i.SubscribePhonePkey,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type publicreportSubscribePhoneForeignKeys struct {
|
type publicreportSubscribePhoneForeignKeys struct {
|
||||||
|
|
|
||||||
|
|
@ -3628,6 +3628,7 @@ func (f *Factory) FromExistingPublicreportSubscribeEmail(m *models.PublicreportS
|
||||||
o.Created = func() time.Time { return m.Created }
|
o.Created = func() time.Time { return m.Created }
|
||||||
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
|
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
|
||||||
o.EmailAddress = func() string { return m.EmailAddress }
|
o.EmailAddress = func() string { return m.EmailAddress }
|
||||||
|
o.ID = func() int32 { return m.ID }
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
if m.R.EmailAddressEmailContact != nil {
|
if m.R.EmailAddressEmailContact != nil {
|
||||||
|
|
@ -3658,6 +3659,7 @@ func (f *Factory) FromExistingPublicreportSubscribePhone(m *models.PublicreportS
|
||||||
|
|
||||||
o.Created = func() time.Time { return m.Created }
|
o.Created = func() time.Time { return m.Created }
|
||||||
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
|
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
|
||||||
|
o.ID = func() int32 { return m.ID }
|
||||||
o.PhoneE164 = func() string { return m.PhoneE164 }
|
o.PhoneE164 = func() string { return m.PhoneE164 }
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
|
|
@ -328,6 +328,26 @@ 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -393,6 +393,26 @@ 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,14 @@ package factory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Gleipnir-Technology/bob"
|
||||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||||
"github.com/aarondl/opt/null"
|
"github.com/aarondl/opt/null"
|
||||||
|
"github.com/aarondl/opt/omit"
|
||||||
|
"github.com/aarondl/opt/omitnull"
|
||||||
"github.com/jaswdr/faker/v2"
|
"github.com/jaswdr/faker/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -36,6 +40,7 @@ type PublicreportSubscribeEmailTemplate struct {
|
||||||
Created func() time.Time
|
Created func() time.Time
|
||||||
Deleted func() null.Val[time.Time]
|
Deleted func() null.Val[time.Time]
|
||||||
EmailAddress func() string
|
EmailAddress func() string
|
||||||
|
ID func() int32
|
||||||
|
|
||||||
r publicreportSubscribeEmailR
|
r publicreportSubscribeEmailR
|
||||||
f *Factory
|
f *Factory
|
||||||
|
|
@ -69,6 +74,43 @@ 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.EmailAddress != nil {
|
||||||
|
val := o.EmailAddress()
|
||||||
|
m.EmailAddress = omit.From(val)
|
||||||
|
}
|
||||||
|
if o.ID != nil {
|
||||||
|
val := o.ID()
|
||||||
|
m.ID = 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
|
// Build returns an *models.PublicreportSubscribeEmail
|
||||||
// Related objects are also created and placed in the .R field
|
// Related objects are also created and placed in the .R field
|
||||||
// NOTE: Objects are not inserted into the database. Use PublicreportSubscribeEmailTemplate.Create
|
// NOTE: Objects are not inserted into the database. Use PublicreportSubscribeEmailTemplate.Create
|
||||||
|
|
@ -84,6 +126,9 @@ func (o PublicreportSubscribeEmailTemplate) Build() *models.PublicreportSubscrib
|
||||||
if o.EmailAddress != nil {
|
if o.EmailAddress != nil {
|
||||||
m.EmailAddress = o.EmailAddress()
|
m.EmailAddress = o.EmailAddress()
|
||||||
}
|
}
|
||||||
|
if o.ID != nil {
|
||||||
|
m.ID = o.ID()
|
||||||
|
}
|
||||||
|
|
||||||
o.setModelRels(m)
|
o.setModelRels(m)
|
||||||
|
|
||||||
|
|
@ -103,6 +148,127 @@ func (o PublicreportSubscribeEmailTemplate) BuildMany(number int) models.Publicr
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureCreatablePublicreportSubscribeEmail(m *models.PublicreportSubscribeEmailSetter) {
|
||||||
|
if !(m.Created.IsValue()) {
|
||||||
|
val := random_time_Time(nil)
|
||||||
|
m.Created = 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.EmailAddressEmailContact == nil {
|
||||||
|
PublicreportSubscribeEmailMods.WithNewEmailAddressEmailContact().Apply(ctx, o)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rel0 *models.CommsEmailContact
|
||||||
|
|
||||||
|
if o.r.EmailAddressEmailContact.o.alreadyPersisted {
|
||||||
|
rel0 = o.r.EmailAddressEmailContact.o.Build()
|
||||||
|
} else {
|
||||||
|
rel0, err = o.r.EmailAddressEmailContact.o.Create(ctx, exec)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.EmailAddress = omit.From(rel0.Address)
|
||||||
|
|
||||||
|
m, err := models.PublicreportSubscribeEmails.Insert(opt).One(ctx, exec)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.R.EmailAddressEmailContact = rel0
|
||||||
|
|
||||||
|
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
|
// PublicreportSubscribeEmail has methods that act as mods for the PublicreportSubscribeEmailTemplate
|
||||||
var PublicreportSubscribeEmailMods publicreportSubscribeEmailMods
|
var PublicreportSubscribeEmailMods publicreportSubscribeEmailMods
|
||||||
|
|
||||||
|
|
@ -113,6 +279,7 @@ func (m publicreportSubscribeEmailMods) RandomizeAllColumns(f *faker.Faker) Publ
|
||||||
PublicreportSubscribeEmailMods.RandomCreated(f),
|
PublicreportSubscribeEmailMods.RandomCreated(f),
|
||||||
PublicreportSubscribeEmailMods.RandomDeleted(f),
|
PublicreportSubscribeEmailMods.RandomDeleted(f),
|
||||||
PublicreportSubscribeEmailMods.RandomEmailAddress(f),
|
PublicreportSubscribeEmailMods.RandomEmailAddress(f),
|
||||||
|
PublicreportSubscribeEmailMods.RandomID(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,6 +398,37 @@ func (m publicreportSubscribeEmailMods) RandomEmailAddress(f *faker.Faker) Publi
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the model columns to this value
|
||||||
|
func (m publicreportSubscribeEmailMods) ID(val int32) PublicreportSubscribeEmailMod {
|
||||||
|
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||||
|
o.ID = func() int32 { return val }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the Column from the function
|
||||||
|
func (m publicreportSubscribeEmailMods) IDFunc(f func() int32) PublicreportSubscribeEmailMod {
|
||||||
|
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||||
|
o.ID = f
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear any values for the column
|
||||||
|
func (m publicreportSubscribeEmailMods) UnsetID() PublicreportSubscribeEmailMod {
|
||||||
|
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||||
|
o.ID = nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates a random value for the column using the given faker
|
||||||
|
// if faker is nil, a default faker is used
|
||||||
|
func (m publicreportSubscribeEmailMods) RandomID(f *faker.Faker) PublicreportSubscribeEmailMod {
|
||||||
|
return PublicreportSubscribeEmailModFunc(func(_ context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||||
|
o.ID = func() int32 {
|
||||||
|
return random_int32(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (m publicreportSubscribeEmailMods) WithParentsCascading() PublicreportSubscribeEmailMod {
|
func (m publicreportSubscribeEmailMods) WithParentsCascading() PublicreportSubscribeEmailMod {
|
||||||
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
return PublicreportSubscribeEmailModFunc(func(ctx context.Context, o *PublicreportSubscribeEmailTemplate) {
|
||||||
if isDone, _ := publicreportSubscribeEmailWithParentsCascadingCtx.Value(ctx); isDone {
|
if isDone, _ := publicreportSubscribeEmailWithParentsCascadingCtx.Value(ctx); isDone {
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,14 @@ package factory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Gleipnir-Technology/bob"
|
||||||
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||||
"github.com/aarondl/opt/null"
|
"github.com/aarondl/opt/null"
|
||||||
|
"github.com/aarondl/opt/omit"
|
||||||
|
"github.com/aarondl/opt/omitnull"
|
||||||
"github.com/jaswdr/faker/v2"
|
"github.com/jaswdr/faker/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -35,6 +39,7 @@ func (mods PublicreportSubscribePhoneModSlice) Apply(ctx context.Context, n *Pub
|
||||||
type PublicreportSubscribePhoneTemplate struct {
|
type PublicreportSubscribePhoneTemplate struct {
|
||||||
Created func() time.Time
|
Created func() time.Time
|
||||||
Deleted func() null.Val[time.Time]
|
Deleted func() null.Val[time.Time]
|
||||||
|
ID func() int32
|
||||||
PhoneE164 func() string
|
PhoneE164 func() string
|
||||||
|
|
||||||
r publicreportSubscribePhoneR
|
r publicreportSubscribePhoneR
|
||||||
|
|
@ -69,6 +74,43 @@ 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.ID != nil {
|
||||||
|
val := o.ID()
|
||||||
|
m.ID = 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
|
// Build returns an *models.PublicreportSubscribePhone
|
||||||
// Related objects are also created and placed in the .R field
|
// Related objects are also created and placed in the .R field
|
||||||
// NOTE: Objects are not inserted into the database. Use PublicreportSubscribePhoneTemplate.Create
|
// NOTE: Objects are not inserted into the database. Use PublicreportSubscribePhoneTemplate.Create
|
||||||
|
|
@ -81,6 +123,9 @@ func (o PublicreportSubscribePhoneTemplate) Build() *models.PublicreportSubscrib
|
||||||
if o.Deleted != nil {
|
if o.Deleted != nil {
|
||||||
m.Deleted = o.Deleted()
|
m.Deleted = o.Deleted()
|
||||||
}
|
}
|
||||||
|
if o.ID != nil {
|
||||||
|
m.ID = o.ID()
|
||||||
|
}
|
||||||
if o.PhoneE164 != nil {
|
if o.PhoneE164 != nil {
|
||||||
m.PhoneE164 = o.PhoneE164()
|
m.PhoneE164 = o.PhoneE164()
|
||||||
}
|
}
|
||||||
|
|
@ -103,6 +148,127 @@ func (o PublicreportSubscribePhoneTemplate) BuildMany(number int) models.Publicr
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ensureCreatablePublicreportSubscribePhone(m *models.PublicreportSubscribePhoneSetter) {
|
||||||
|
if !(m.Created.IsValue()) {
|
||||||
|
val := random_time_Time(nil)
|
||||||
|
m.Created = 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.PhoneE164Phone == nil {
|
||||||
|
PublicreportSubscribePhoneMods.WithNewPhoneE164Phone().Apply(ctx, o)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rel0 *models.CommsPhone
|
||||||
|
|
||||||
|
if o.r.PhoneE164Phone.o.alreadyPersisted {
|
||||||
|
rel0 = o.r.PhoneE164Phone.o.Build()
|
||||||
|
} else {
|
||||||
|
rel0, err = o.r.PhoneE164Phone.o.Create(ctx, exec)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.PhoneE164 = omit.From(rel0.E164)
|
||||||
|
|
||||||
|
m, err := models.PublicreportSubscribePhones.Insert(opt).One(ctx, exec)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.R.PhoneE164Phone = rel0
|
||||||
|
|
||||||
|
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
|
// PublicreportSubscribePhone has methods that act as mods for the PublicreportSubscribePhoneTemplate
|
||||||
var PublicreportSubscribePhoneMods publicreportSubscribePhoneMods
|
var PublicreportSubscribePhoneMods publicreportSubscribePhoneMods
|
||||||
|
|
||||||
|
|
@ -112,6 +278,7 @@ func (m publicreportSubscribePhoneMods) RandomizeAllColumns(f *faker.Faker) Publ
|
||||||
return PublicreportSubscribePhoneModSlice{
|
return PublicreportSubscribePhoneModSlice{
|
||||||
PublicreportSubscribePhoneMods.RandomCreated(f),
|
PublicreportSubscribePhoneMods.RandomCreated(f),
|
||||||
PublicreportSubscribePhoneMods.RandomDeleted(f),
|
PublicreportSubscribePhoneMods.RandomDeleted(f),
|
||||||
|
PublicreportSubscribePhoneMods.RandomID(f),
|
||||||
PublicreportSubscribePhoneMods.RandomPhoneE164(f),
|
PublicreportSubscribePhoneMods.RandomPhoneE164(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -200,6 +367,37 @@ func (m publicreportSubscribePhoneMods) RandomDeletedNotNull(f *faker.Faker) Pub
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the model columns to this value
|
||||||
|
func (m publicreportSubscribePhoneMods) ID(val int32) PublicreportSubscribePhoneMod {
|
||||||
|
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||||
|
o.ID = func() int32 { return val }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the Column from the function
|
||||||
|
func (m publicreportSubscribePhoneMods) IDFunc(f func() int32) PublicreportSubscribePhoneMod {
|
||||||
|
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||||
|
o.ID = f
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear any values for the column
|
||||||
|
func (m publicreportSubscribePhoneMods) UnsetID() PublicreportSubscribePhoneMod {
|
||||||
|
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||||
|
o.ID = nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates a random value for the column using the given faker
|
||||||
|
// if faker is nil, a default faker is used
|
||||||
|
func (m publicreportSubscribePhoneMods) RandomID(f *faker.Faker) PublicreportSubscribePhoneMod {
|
||||||
|
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||||
|
o.ID = func() int32 {
|
||||||
|
return random_int32(f)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Set the model columns to this value
|
// Set the model columns to this value
|
||||||
func (m publicreportSubscribePhoneMods) PhoneE164(val string) PublicreportSubscribePhoneMod {
|
func (m publicreportSubscribePhoneMods) PhoneE164(val string) PublicreportSubscribePhoneMod {
|
||||||
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
return PublicreportSubscribePhoneModFunc(func(_ context.Context, o *PublicreportSubscribePhoneTemplate) {
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,6 @@ CREATE TABLE publicreport.subscribe_phone (
|
||||||
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
|
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
|
||||||
PRIMARY KEY(district_id, phone_e164)
|
PRIMARY KEY(district_id, phone_e164)
|
||||||
);
|
);
|
||||||
|
-- +goose Down
|
||||||
|
DROP TABLE publicreport.subscribe_phone;
|
||||||
|
DROP TABLE publicreport.subscribe_email;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,36 @@
|
||||||
-- +goose Up
|
-- +goose Up
|
||||||
ALTER TABLE publicreport.subscribe_email DROP COLUMN district_id;
|
DROP TABLE publicreport.subscribe_email;
|
||||||
ALTER TABLE publicreport.subscribe_phone DROP COLUMN district_id;
|
DROP TABLE publicreport.subscribe_phone;
|
||||||
|
|
||||||
|
CREATE TABLE publicreport.subscribe_email (
|
||||||
|
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||||
|
deleted TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
email_address TEXT NOT NULL REFERENCES comms.email_contact(address),
|
||||||
|
id SERIAL,
|
||||||
|
PRIMARY KEY(id)
|
||||||
|
);
|
||||||
|
CREATE TABLE publicreport.subscribe_phone (
|
||||||
|
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||||
|
deleted TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
id SERIAL,
|
||||||
|
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
|
||||||
|
PRIMARY KEY(id)
|
||||||
|
);
|
||||||
|
-- +goose Down
|
||||||
|
DROP TABLE publicreport.subscribe_email;
|
||||||
|
DROP TABLE publicreport.subscribe_phone;
|
||||||
|
|
||||||
|
CREATE TABLE publicreport.subscribe_email (
|
||||||
|
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||||
|
deleted TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
district_id INTEGER REFERENCES organization(id),
|
||||||
|
email_address TEXT NOT NULL REFERENCES comms.email_contact(address),
|
||||||
|
PRIMARY KEY(district_id, email_address)
|
||||||
|
);
|
||||||
|
CREATE TABLE publicreport.subscribe_phone (
|
||||||
|
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||||
|
deleted TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
district_id INTEGER REFERENCES organization(id),
|
||||||
|
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
|
||||||
|
PRIMARY KEY(district_id, phone_e164)
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -816,6 +816,74 @@ func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailPools(
|
||||||
return nil
|
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 {
|
type commsEmailContactWhere[Q psql.Filterable] struct {
|
||||||
Address psql.WhereMod[Q, string]
|
Address psql.WhereMod[Q, string]
|
||||||
Confirmed psql.WhereMod[Q, bool]
|
Confirmed psql.WhereMod[Q, bool]
|
||||||
|
|
|
||||||
|
|
@ -980,6 +980,74 @@ func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhonePools(ctx context.Conte
|
||||||
return nil
|
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 {
|
type commsPhoneWhere[Q psql.Filterable] struct {
|
||||||
E164 psql.WhereMod[Q, string]
|
E164 psql.WhereMod[Q, string]
|
||||||
IsSubscribed psql.WhereMod[Q, bool]
|
IsSubscribed psql.WhereMod[Q, bool]
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/Gleipnir-Technology/bob"
|
"github.com/Gleipnir-Technology/bob"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
"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/sm"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||||
"github.com/Gleipnir-Technology/bob/expr"
|
"github.com/Gleipnir-Technology/bob/expr"
|
||||||
|
|
@ -28,6 +29,7 @@ type PublicreportSubscribeEmail struct {
|
||||||
Created time.Time `db:"created" `
|
Created time.Time `db:"created" `
|
||||||
Deleted null.Val[time.Time] `db:"deleted" `
|
Deleted null.Val[time.Time] `db:"deleted" `
|
||||||
EmailAddress string `db:"email_address" `
|
EmailAddress string `db:"email_address" `
|
||||||
|
ID int32 `db:"id,pk" `
|
||||||
|
|
||||||
R publicreportSubscribeEmailR `db:"-" `
|
R publicreportSubscribeEmailR `db:"-" `
|
||||||
}
|
}
|
||||||
|
|
@ -36,10 +38,10 @@ type PublicreportSubscribeEmail struct {
|
||||||
// This should almost always be used instead of []*PublicreportSubscribeEmail.
|
// This should almost always be used instead of []*PublicreportSubscribeEmail.
|
||||||
type PublicreportSubscribeEmailSlice []*PublicreportSubscribeEmail
|
type PublicreportSubscribeEmailSlice []*PublicreportSubscribeEmail
|
||||||
|
|
||||||
// PublicreportSubscribeEmails contains methods to work with the subscribe_email view
|
// PublicreportSubscribeEmails contains methods to work with the subscribe_email table
|
||||||
var PublicreportSubscribeEmails = psql.NewViewx[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice]("publicreport", "subscribe_email", buildPublicreportSubscribeEmailColumns("publicreport.subscribe_email"))
|
var PublicreportSubscribeEmails = psql.NewTablex[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice, *PublicreportSubscribeEmailSetter]("publicreport", "subscribe_email", buildPublicreportSubscribeEmailColumns("publicreport.subscribe_email"))
|
||||||
|
|
||||||
// PublicreportSubscribeEmailsQuery is a query on the subscribe_email view
|
// PublicreportSubscribeEmailsQuery is a query on the subscribe_email table
|
||||||
type PublicreportSubscribeEmailsQuery = *psql.ViewQuery[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice]
|
type PublicreportSubscribeEmailsQuery = *psql.ViewQuery[*PublicreportSubscribeEmail, PublicreportSubscribeEmailSlice]
|
||||||
|
|
||||||
// publicreportSubscribeEmailR is where relationships are stored.
|
// publicreportSubscribeEmailR is where relationships are stored.
|
||||||
|
|
@ -50,12 +52,13 @@ type publicreportSubscribeEmailR struct {
|
||||||
func buildPublicreportSubscribeEmailColumns(alias string) publicreportSubscribeEmailColumns {
|
func buildPublicreportSubscribeEmailColumns(alias string) publicreportSubscribeEmailColumns {
|
||||||
return publicreportSubscribeEmailColumns{
|
return publicreportSubscribeEmailColumns{
|
||||||
ColumnsExpr: expr.NewColumnsExpr(
|
ColumnsExpr: expr.NewColumnsExpr(
|
||||||
"created", "deleted", "email_address",
|
"created", "deleted", "email_address", "id",
|
||||||
).WithParent("publicreport.subscribe_email"),
|
).WithParent("publicreport.subscribe_email"),
|
||||||
tableAlias: alias,
|
tableAlias: alias,
|
||||||
Created: psql.Quote(alias, "created"),
|
Created: psql.Quote(alias, "created"),
|
||||||
Deleted: psql.Quote(alias, "deleted"),
|
Deleted: psql.Quote(alias, "deleted"),
|
||||||
EmailAddress: psql.Quote(alias, "email_address"),
|
EmailAddress: psql.Quote(alias, "email_address"),
|
||||||
|
ID: psql.Quote(alias, "id"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,6 +68,7 @@ type publicreportSubscribeEmailColumns struct {
|
||||||
Created psql.Expression
|
Created psql.Expression
|
||||||
Deleted psql.Expression
|
Deleted psql.Expression
|
||||||
EmailAddress psql.Expression
|
EmailAddress psql.Expression
|
||||||
|
ID psql.Expression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c publicreportSubscribeEmailColumns) Alias() string {
|
func (c publicreportSubscribeEmailColumns) Alias() string {
|
||||||
|
|
@ -82,10 +86,11 @@ type PublicreportSubscribeEmailSetter struct {
|
||||||
Created omit.Val[time.Time] `db:"created" `
|
Created omit.Val[time.Time] `db:"created" `
|
||||||
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
||||||
EmailAddress omit.Val[string] `db:"email_address" `
|
EmailAddress omit.Val[string] `db:"email_address" `
|
||||||
|
ID omit.Val[int32] `db:"id,pk" `
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PublicreportSubscribeEmailSetter) SetColumns() []string {
|
func (s PublicreportSubscribeEmailSetter) SetColumns() []string {
|
||||||
vals := make([]string, 0, 3)
|
vals := make([]string, 0, 4)
|
||||||
if s.Created.IsValue() {
|
if s.Created.IsValue() {
|
||||||
vals = append(vals, "created")
|
vals = append(vals, "created")
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +100,9 @@ func (s PublicreportSubscribeEmailSetter) SetColumns() []string {
|
||||||
if s.EmailAddress.IsValue() {
|
if s.EmailAddress.IsValue() {
|
||||||
vals = append(vals, "email_address")
|
vals = append(vals, "email_address")
|
||||||
}
|
}
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
vals = append(vals, "id")
|
||||||
|
}
|
||||||
return vals
|
return vals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,11 +116,18 @@ func (s PublicreportSubscribeEmailSetter) Overwrite(t *PublicreportSubscribeEmai
|
||||||
if s.EmailAddress.IsValue() {
|
if s.EmailAddress.IsValue() {
|
||||||
t.EmailAddress = s.EmailAddress.MustGet()
|
t.EmailAddress = s.EmailAddress.MustGet()
|
||||||
}
|
}
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
t.ID = s.ID.MustGet()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PublicreportSubscribeEmailSetter) Apply(q *dialect.InsertQuery) {
|
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) {
|
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||||
vals := make([]bob.Expression, 3)
|
vals := make([]bob.Expression, 4)
|
||||||
if s.Created.IsValue() {
|
if s.Created.IsValue() {
|
||||||
vals[0] = psql.Arg(s.Created.MustGet())
|
vals[0] = psql.Arg(s.Created.MustGet())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -131,6 +146,12 @@ func (s *PublicreportSubscribeEmailSetter) Apply(q *dialect.InsertQuery) {
|
||||||
vals[2] = psql.Raw("DEFAULT")
|
vals[2] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
vals[3] = psql.Arg(s.ID.MustGet())
|
||||||
|
} else {
|
||||||
|
vals[3] = psql.Raw("DEFAULT")
|
||||||
|
}
|
||||||
|
|
||||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +161,7 @@ func (s PublicreportSubscribeEmailSetter) UpdateMod() bob.Mod[*dialect.UpdateQue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PublicreportSubscribeEmailSetter) Expressions(prefix ...string) []bob.Expression {
|
func (s PublicreportSubscribeEmailSetter) Expressions(prefix ...string) []bob.Expression {
|
||||||
exprs := make([]bob.Expression, 0, 3)
|
exprs := make([]bob.Expression, 0, 4)
|
||||||
|
|
||||||
if s.Created.IsValue() {
|
if s.Created.IsValue() {
|
||||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
|
|
@ -163,9 +184,38 @@ func (s PublicreportSubscribeEmailSetter) Expressions(prefix ...string) []bob.Ex
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
|
psql.Quote(append(prefix, "id")...),
|
||||||
|
psql.Arg(s.ID),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
return exprs
|
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, IDPK int32, cols ...string) (*PublicreportSubscribeEmail, error) {
|
||||||
|
if len(cols) == 0 {
|
||||||
|
return PublicreportSubscribeEmails.Query(
|
||||||
|
sm.Where(PublicreportSubscribeEmails.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||||
|
).One(ctx, exec)
|
||||||
|
}
|
||||||
|
|
||||||
|
return PublicreportSubscribeEmails.Query(
|
||||||
|
sm.Where(PublicreportSubscribeEmails.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||||
|
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, IDPK int32) (bool, error) {
|
||||||
|
return PublicreportSubscribeEmails.Query(
|
||||||
|
sm.Where(PublicreportSubscribeEmails.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||||
|
).Exists(ctx, exec)
|
||||||
|
}
|
||||||
|
|
||||||
// AfterQueryHook is called after PublicreportSubscribeEmail is retrieved from the database
|
// AfterQueryHook is called after PublicreportSubscribeEmail is retrieved from the database
|
||||||
func (o *PublicreportSubscribeEmail) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
func (o *PublicreportSubscribeEmail) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -173,11 +223,61 @@ func (o *PublicreportSubscribeEmail) AfterQueryHook(ctx context.Context, exec bo
|
||||||
switch queryType {
|
switch queryType {
|
||||||
case bob.QueryTypeSelect:
|
case bob.QueryTypeSelect:
|
||||||
ctx, err = PublicreportSubscribeEmails.AfterSelectHooks.RunHooks(ctx, exec, PublicreportSubscribeEmailSlice{o})
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// primaryKeyVals returns the primary key values of the PublicreportSubscribeEmail
|
||||||
|
func (o *PublicreportSubscribeEmail) primaryKeyVals() bob.Expression {
|
||||||
|
return psql.Arg(o.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *PublicreportSubscribeEmail) pkEQ() dialect.Expression {
|
||||||
|
return psql.Quote("publicreport.subscribe_email", "id").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.ID.EQ(psql.Arg(o.ID))),
|
||||||
|
).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
|
// AfterQueryHook is called after PublicreportSubscribeEmailSlice is retrieved from the database
|
||||||
func (o PublicreportSubscribeEmailSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
func (o PublicreportSubscribeEmailSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -185,11 +285,138 @@ func (o PublicreportSubscribeEmailSlice) AfterQueryHook(ctx context.Context, exe
|
||||||
switch queryType {
|
switch queryType {
|
||||||
case bob.QueryTypeSelect:
|
case bob.QueryTypeSelect:
|
||||||
ctx, err = PublicreportSubscribeEmails.AfterSelectHooks.RunHooks(ctx, exec, o)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o PublicreportSubscribeEmailSlice) pkIN() dialect.Expression {
|
||||||
|
if len(o) == 0 {
|
||||||
|
return psql.Raw("NULL")
|
||||||
|
}
|
||||||
|
|
||||||
|
return psql.Quote("publicreport.subscribe_email", "id").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.ID != old.ID {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// EmailAddressEmailContact starts a query for related objects on comms.email_contact
|
// EmailAddressEmailContact starts a query for related objects on comms.email_contact
|
||||||
func (o *PublicreportSubscribeEmail) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
|
func (o *PublicreportSubscribeEmail) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
|
||||||
return CommsEmailContacts.Query(append(mods,
|
return CommsEmailContacts.Query(append(mods,
|
||||||
|
|
@ -214,10 +441,59 @@ func (os PublicreportSubscribeEmailSlice) EmailAddressEmailContact(mods ...bob.M
|
||||||
)...)
|
)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
type publicreportSubscribeEmailWhere[Q psql.Filterable] struct {
|
||||||
Created psql.WhereMod[Q, time.Time]
|
Created psql.WhereMod[Q, time.Time]
|
||||||
Deleted psql.WhereNullMod[Q, time.Time]
|
Deleted psql.WhereNullMod[Q, time.Time]
|
||||||
EmailAddress psql.WhereMod[Q, string]
|
EmailAddress psql.WhereMod[Q, string]
|
||||||
|
ID psql.WhereMod[Q, int32]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (publicreportSubscribeEmailWhere[Q]) AliasedAs(alias string) publicreportSubscribeEmailWhere[Q] {
|
func (publicreportSubscribeEmailWhere[Q]) AliasedAs(alias string) publicreportSubscribeEmailWhere[Q] {
|
||||||
|
|
@ -229,6 +505,7 @@ func buildPublicreportSubscribeEmailWhere[Q psql.Filterable](cols publicreportSu
|
||||||
Created: psql.Where[Q, time.Time](cols.Created),
|
Created: psql.Where[Q, time.Time](cols.Created),
|
||||||
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
||||||
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
|
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
|
||||||
|
ID: psql.Where[Q, int32](cols.ID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/Gleipnir-Technology/bob"
|
"github.com/Gleipnir-Technology/bob"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
"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/sm"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||||
"github.com/Gleipnir-Technology/bob/expr"
|
"github.com/Gleipnir-Technology/bob/expr"
|
||||||
|
|
@ -27,6 +28,7 @@ import (
|
||||||
type PublicreportSubscribePhone struct {
|
type PublicreportSubscribePhone struct {
|
||||||
Created time.Time `db:"created" `
|
Created time.Time `db:"created" `
|
||||||
Deleted null.Val[time.Time] `db:"deleted" `
|
Deleted null.Val[time.Time] `db:"deleted" `
|
||||||
|
ID int32 `db:"id,pk" `
|
||||||
PhoneE164 string `db:"phone_e164" `
|
PhoneE164 string `db:"phone_e164" `
|
||||||
|
|
||||||
R publicreportSubscribePhoneR `db:"-" `
|
R publicreportSubscribePhoneR `db:"-" `
|
||||||
|
|
@ -36,10 +38,10 @@ type PublicreportSubscribePhone struct {
|
||||||
// This should almost always be used instead of []*PublicreportSubscribePhone.
|
// This should almost always be used instead of []*PublicreportSubscribePhone.
|
||||||
type PublicreportSubscribePhoneSlice []*PublicreportSubscribePhone
|
type PublicreportSubscribePhoneSlice []*PublicreportSubscribePhone
|
||||||
|
|
||||||
// PublicreportSubscribePhones contains methods to work with the subscribe_phone view
|
// PublicreportSubscribePhones contains methods to work with the subscribe_phone table
|
||||||
var PublicreportSubscribePhones = psql.NewViewx[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice]("publicreport", "subscribe_phone", buildPublicreportSubscribePhoneColumns("publicreport.subscribe_phone"))
|
var PublicreportSubscribePhones = psql.NewTablex[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice, *PublicreportSubscribePhoneSetter]("publicreport", "subscribe_phone", buildPublicreportSubscribePhoneColumns("publicreport.subscribe_phone"))
|
||||||
|
|
||||||
// PublicreportSubscribePhonesQuery is a query on the subscribe_phone view
|
// PublicreportSubscribePhonesQuery is a query on the subscribe_phone table
|
||||||
type PublicreportSubscribePhonesQuery = *psql.ViewQuery[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice]
|
type PublicreportSubscribePhonesQuery = *psql.ViewQuery[*PublicreportSubscribePhone, PublicreportSubscribePhoneSlice]
|
||||||
|
|
||||||
// publicreportSubscribePhoneR is where relationships are stored.
|
// publicreportSubscribePhoneR is where relationships are stored.
|
||||||
|
|
@ -50,11 +52,12 @@ type publicreportSubscribePhoneR struct {
|
||||||
func buildPublicreportSubscribePhoneColumns(alias string) publicreportSubscribePhoneColumns {
|
func buildPublicreportSubscribePhoneColumns(alias string) publicreportSubscribePhoneColumns {
|
||||||
return publicreportSubscribePhoneColumns{
|
return publicreportSubscribePhoneColumns{
|
||||||
ColumnsExpr: expr.NewColumnsExpr(
|
ColumnsExpr: expr.NewColumnsExpr(
|
||||||
"created", "deleted", "phone_e164",
|
"created", "deleted", "id", "phone_e164",
|
||||||
).WithParent("publicreport.subscribe_phone"),
|
).WithParent("publicreport.subscribe_phone"),
|
||||||
tableAlias: alias,
|
tableAlias: alias,
|
||||||
Created: psql.Quote(alias, "created"),
|
Created: psql.Quote(alias, "created"),
|
||||||
Deleted: psql.Quote(alias, "deleted"),
|
Deleted: psql.Quote(alias, "deleted"),
|
||||||
|
ID: psql.Quote(alias, "id"),
|
||||||
PhoneE164: psql.Quote(alias, "phone_e164"),
|
PhoneE164: psql.Quote(alias, "phone_e164"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,6 +67,7 @@ type publicreportSubscribePhoneColumns struct {
|
||||||
tableAlias string
|
tableAlias string
|
||||||
Created psql.Expression
|
Created psql.Expression
|
||||||
Deleted psql.Expression
|
Deleted psql.Expression
|
||||||
|
ID psql.Expression
|
||||||
PhoneE164 psql.Expression
|
PhoneE164 psql.Expression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,17 +85,21 @@ func (publicreportSubscribePhoneColumns) AliasedAs(alias string) publicreportSub
|
||||||
type PublicreportSubscribePhoneSetter struct {
|
type PublicreportSubscribePhoneSetter struct {
|
||||||
Created omit.Val[time.Time] `db:"created" `
|
Created omit.Val[time.Time] `db:"created" `
|
||||||
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
Deleted omitnull.Val[time.Time] `db:"deleted" `
|
||||||
|
ID omit.Val[int32] `db:"id,pk" `
|
||||||
PhoneE164 omit.Val[string] `db:"phone_e164" `
|
PhoneE164 omit.Val[string] `db:"phone_e164" `
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PublicreportSubscribePhoneSetter) SetColumns() []string {
|
func (s PublicreportSubscribePhoneSetter) SetColumns() []string {
|
||||||
vals := make([]string, 0, 3)
|
vals := make([]string, 0, 4)
|
||||||
if s.Created.IsValue() {
|
if s.Created.IsValue() {
|
||||||
vals = append(vals, "created")
|
vals = append(vals, "created")
|
||||||
}
|
}
|
||||||
if !s.Deleted.IsUnset() {
|
if !s.Deleted.IsUnset() {
|
||||||
vals = append(vals, "deleted")
|
vals = append(vals, "deleted")
|
||||||
}
|
}
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
vals = append(vals, "id")
|
||||||
|
}
|
||||||
if s.PhoneE164.IsValue() {
|
if s.PhoneE164.IsValue() {
|
||||||
vals = append(vals, "phone_e164")
|
vals = append(vals, "phone_e164")
|
||||||
}
|
}
|
||||||
|
|
@ -105,14 +113,21 @@ func (s PublicreportSubscribePhoneSetter) Overwrite(t *PublicreportSubscribePhon
|
||||||
if !s.Deleted.IsUnset() {
|
if !s.Deleted.IsUnset() {
|
||||||
t.Deleted = s.Deleted.MustGetNull()
|
t.Deleted = s.Deleted.MustGetNull()
|
||||||
}
|
}
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
t.ID = s.ID.MustGet()
|
||||||
|
}
|
||||||
if s.PhoneE164.IsValue() {
|
if s.PhoneE164.IsValue() {
|
||||||
t.PhoneE164 = s.PhoneE164.MustGet()
|
t.PhoneE164 = s.PhoneE164.MustGet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PublicreportSubscribePhoneSetter) Apply(q *dialect.InsertQuery) {
|
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) {
|
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||||
vals := make([]bob.Expression, 3)
|
vals := make([]bob.Expression, 4)
|
||||||
if s.Created.IsValue() {
|
if s.Created.IsValue() {
|
||||||
vals[0] = psql.Arg(s.Created.MustGet())
|
vals[0] = psql.Arg(s.Created.MustGet())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -125,12 +140,18 @@ func (s *PublicreportSubscribePhoneSetter) Apply(q *dialect.InsertQuery) {
|
||||||
vals[1] = psql.Raw("DEFAULT")
|
vals[1] = psql.Raw("DEFAULT")
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.PhoneE164.IsValue() {
|
if s.ID.IsValue() {
|
||||||
vals[2] = psql.Arg(s.PhoneE164.MustGet())
|
vals[2] = psql.Arg(s.ID.MustGet())
|
||||||
} else {
|
} else {
|
||||||
vals[2] = psql.Raw("DEFAULT")
|
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, "", ", ", "")
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +161,7 @@ func (s PublicreportSubscribePhoneSetter) UpdateMod() bob.Mod[*dialect.UpdateQue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Expression {
|
func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Expression {
|
||||||
exprs := make([]bob.Expression, 0, 3)
|
exprs := make([]bob.Expression, 0, 4)
|
||||||
|
|
||||||
if s.Created.IsValue() {
|
if s.Created.IsValue() {
|
||||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
|
|
@ -156,6 +177,13 @@ func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Ex
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.ID.IsValue() {
|
||||||
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
|
psql.Quote(append(prefix, "id")...),
|
||||||
|
psql.Arg(s.ID),
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
if s.PhoneE164.IsValue() {
|
if s.PhoneE164.IsValue() {
|
||||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||||
psql.Quote(append(prefix, "phone_e164")...),
|
psql.Quote(append(prefix, "phone_e164")...),
|
||||||
|
|
@ -166,6 +194,28 @@ func (s PublicreportSubscribePhoneSetter) Expressions(prefix ...string) []bob.Ex
|
||||||
return exprs
|
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, IDPK int32, cols ...string) (*PublicreportSubscribePhone, error) {
|
||||||
|
if len(cols) == 0 {
|
||||||
|
return PublicreportSubscribePhones.Query(
|
||||||
|
sm.Where(PublicreportSubscribePhones.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||||
|
).One(ctx, exec)
|
||||||
|
}
|
||||||
|
|
||||||
|
return PublicreportSubscribePhones.Query(
|
||||||
|
sm.Where(PublicreportSubscribePhones.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||||
|
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, IDPK int32) (bool, error) {
|
||||||
|
return PublicreportSubscribePhones.Query(
|
||||||
|
sm.Where(PublicreportSubscribePhones.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||||
|
).Exists(ctx, exec)
|
||||||
|
}
|
||||||
|
|
||||||
// AfterQueryHook is called after PublicreportSubscribePhone is retrieved from the database
|
// AfterQueryHook is called after PublicreportSubscribePhone is retrieved from the database
|
||||||
func (o *PublicreportSubscribePhone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
func (o *PublicreportSubscribePhone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -173,11 +223,61 @@ func (o *PublicreportSubscribePhone) AfterQueryHook(ctx context.Context, exec bo
|
||||||
switch queryType {
|
switch queryType {
|
||||||
case bob.QueryTypeSelect:
|
case bob.QueryTypeSelect:
|
||||||
ctx, err = PublicreportSubscribePhones.AfterSelectHooks.RunHooks(ctx, exec, PublicreportSubscribePhoneSlice{o})
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// primaryKeyVals returns the primary key values of the PublicreportSubscribePhone
|
||||||
|
func (o *PublicreportSubscribePhone) primaryKeyVals() bob.Expression {
|
||||||
|
return psql.Arg(o.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *PublicreportSubscribePhone) pkEQ() dialect.Expression {
|
||||||
|
return psql.Quote("publicreport.subscribe_phone", "id").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.ID.EQ(psql.Arg(o.ID))),
|
||||||
|
).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
|
// AfterQueryHook is called after PublicreportSubscribePhoneSlice is retrieved from the database
|
||||||
func (o PublicreportSubscribePhoneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
func (o PublicreportSubscribePhoneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -185,11 +285,138 @@ func (o PublicreportSubscribePhoneSlice) AfterQueryHook(ctx context.Context, exe
|
||||||
switch queryType {
|
switch queryType {
|
||||||
case bob.QueryTypeSelect:
|
case bob.QueryTypeSelect:
|
||||||
ctx, err = PublicreportSubscribePhones.AfterSelectHooks.RunHooks(ctx, exec, o)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o PublicreportSubscribePhoneSlice) pkIN() dialect.Expression {
|
||||||
|
if len(o) == 0 {
|
||||||
|
return psql.Raw("NULL")
|
||||||
|
}
|
||||||
|
|
||||||
|
return psql.Quote("publicreport.subscribe_phone", "id").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.ID != old.ID {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// PhoneE164Phone starts a query for related objects on comms.phone
|
// PhoneE164Phone starts a query for related objects on comms.phone
|
||||||
func (o *PublicreportSubscribePhone) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
func (o *PublicreportSubscribePhone) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
|
||||||
return CommsPhones.Query(append(mods,
|
return CommsPhones.Query(append(mods,
|
||||||
|
|
@ -214,9 +441,58 @@ func (os PublicreportSubscribePhoneSlice) PhoneE164Phone(mods ...bob.Mod[*dialec
|
||||||
)...)
|
)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
type publicreportSubscribePhoneWhere[Q psql.Filterable] struct {
|
||||||
Created psql.WhereMod[Q, time.Time]
|
Created psql.WhereMod[Q, time.Time]
|
||||||
Deleted psql.WhereNullMod[Q, time.Time]
|
Deleted psql.WhereNullMod[Q, time.Time]
|
||||||
|
ID psql.WhereMod[Q, int32]
|
||||||
PhoneE164 psql.WhereMod[Q, string]
|
PhoneE164 psql.WhereMod[Q, string]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,6 +504,7 @@ func buildPublicreportSubscribePhoneWhere[Q psql.Filterable](cols publicreportSu
|
||||||
return publicreportSubscribePhoneWhere[Q]{
|
return publicreportSubscribePhoneWhere[Q]{
|
||||||
Created: psql.Where[Q, time.Time](cols.Created),
|
Created: psql.Where[Q, time.Time](cols.Created),
|
||||||
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
|
||||||
|
ID: psql.Where[Q, int32](cols.ID),
|
||||||
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
|
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue