Alter report submission page to request reporter name and consent

This also adds the new mechanism for handling notifications on reports
This commit is contained in:
Eli Ribble 2026-02-06 15:39:49 +00:00
parent 9328e7a2f8
commit 57191fa222
No known key found for this signature in database
45 changed files with 10337 additions and 573 deletions

View 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 PublicreportNotifyEmailNuisanceErrors = &publicreportNotifyEmailNuisanceErrors{
ErrUniqueNotifyEmailNuisancePkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_email_nuisance",
columns: []string{"nuisance_id", "email_address"},
s: "notify_email_nuisance_pkey",
},
}
type publicreportNotifyEmailNuisanceErrors struct {
ErrUniqueNotifyEmailNuisancePkey *UniqueConstraintError
}

View 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 PublicreportNotifyEmailPoolErrors = &publicreportNotifyEmailPoolErrors{
ErrUniqueNotifyEmailPoolPkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_email_pool",
columns: []string{"pool_id", "email_address"},
s: "notify_email_pool_pkey",
},
}
type publicreportNotifyEmailPoolErrors struct {
ErrUniqueNotifyEmailPoolPkey *UniqueConstraintError
}

View 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 PublicreportNotifyPhoneNuisanceErrors = &publicreportNotifyPhoneNuisanceErrors{
ErrUniqueNotifyPhoneNuisancePkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_phone_nuisance",
columns: []string{"nuisance_id", "phone_e164"},
s: "notify_phone_nuisance_pkey",
},
}
type publicreportNotifyPhoneNuisanceErrors struct {
ErrUniqueNotifyPhoneNuisancePkey *UniqueConstraintError
}

View 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 PublicreportNotifyPhonePoolErrors = &publicreportNotifyPhonePoolErrors{
ErrUniqueNotifyPhonePoolPkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_phone_pool",
columns: []string{"pool_id", "phone_e164"},
s: "notify_phone_pool_pkey",
},
}
type publicreportNotifyPhonePoolErrors struct {
ErrUniqueNotifyPhonePoolPkey *UniqueConstraintError
}

View file

@ -0,0 +1,152 @@
// 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 dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyEmailNuisances = Table[
publicreportNotifyEmailNuisanceColumns,
publicreportNotifyEmailNuisanceIndexes,
publicreportNotifyEmailNuisanceForeignKeys,
publicreportNotifyEmailNuisanceUniques,
publicreportNotifyEmailNuisanceChecks,
]{
Schema: "publicreport",
Name: "notify_email_nuisance",
Columns: publicreportNotifyEmailNuisanceColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Deleted: column{
Name: "deleted",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
NuisanceID: column{
Name: "nuisance_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
EmailAddress: column{
Name: "email_address",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNotifyEmailNuisanceIndexes{
NotifyEmailNuisancePkey: index{
Type: "btree",
Name: "notify_email_nuisance_pkey",
Columns: []indexColumn{
{
Name: "nuisance_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "email_address",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "notify_email_nuisance_pkey",
Columns: []string{"nuisance_id", "email_address"},
Comment: "",
},
ForeignKeys: publicreportNotifyEmailNuisanceForeignKeys{
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceEmailAddressFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey",
Columns: []string{"email_address"},
Comment: "",
},
ForeignTable: "comms.email_contact",
ForeignColumns: []string{"address"},
},
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceNuisanceIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_nuisance.notify_email_nuisance_nuisance_id_fkey",
Columns: []string{"nuisance_id"},
Comment: "",
},
ForeignTable: "publicreport.nuisance",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type publicreportNotifyEmailNuisanceColumns struct {
Created column
Deleted column
NuisanceID column
EmailAddress column
}
func (c publicreportNotifyEmailNuisanceColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.NuisanceID, c.EmailAddress,
}
}
type publicreportNotifyEmailNuisanceIndexes struct {
NotifyEmailNuisancePkey index
}
func (i publicreportNotifyEmailNuisanceIndexes) AsSlice() []index {
return []index{
i.NotifyEmailNuisancePkey,
}
}
type publicreportNotifyEmailNuisanceForeignKeys struct {
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceEmailAddressFkey foreignKey
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceNuisanceIDFkey foreignKey
}
func (f publicreportNotifyEmailNuisanceForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyEmailNuisanceNotifyEmailNuisanceEmailAddressFkey, f.PublicreportNotifyEmailNuisanceNotifyEmailNuisanceNuisanceIDFkey,
}
}
type publicreportNotifyEmailNuisanceUniques struct{}
func (u publicreportNotifyEmailNuisanceUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyEmailNuisanceChecks struct{}
func (c publicreportNotifyEmailNuisanceChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,152 @@
// 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 dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyEmailPools = Table[
publicreportNotifyEmailPoolColumns,
publicreportNotifyEmailPoolIndexes,
publicreportNotifyEmailPoolForeignKeys,
publicreportNotifyEmailPoolUniques,
publicreportNotifyEmailPoolChecks,
]{
Schema: "publicreport",
Name: "notify_email_pool",
Columns: publicreportNotifyEmailPoolColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Deleted: column{
Name: "deleted",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
PoolID: column{
Name: "pool_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
EmailAddress: column{
Name: "email_address",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNotifyEmailPoolIndexes{
NotifyEmailPoolPkey: index{
Type: "btree",
Name: "notify_email_pool_pkey",
Columns: []indexColumn{
{
Name: "pool_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "email_address",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "notify_email_pool_pkey",
Columns: []string{"pool_id", "email_address"},
Comment: "",
},
ForeignKeys: publicreportNotifyEmailPoolForeignKeys{
PublicreportNotifyEmailPoolNotifyEmailPoolEmailAddressFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_pool.notify_email_pool_email_address_fkey",
Columns: []string{"email_address"},
Comment: "",
},
ForeignTable: "comms.email_contact",
ForeignColumns: []string{"address"},
},
PublicreportNotifyEmailPoolNotifyEmailPoolPoolIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_pool.notify_email_pool_pool_id_fkey",
Columns: []string{"pool_id"},
Comment: "",
},
ForeignTable: "publicreport.pool",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type publicreportNotifyEmailPoolColumns struct {
Created column
Deleted column
PoolID column
EmailAddress column
}
func (c publicreportNotifyEmailPoolColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.PoolID, c.EmailAddress,
}
}
type publicreportNotifyEmailPoolIndexes struct {
NotifyEmailPoolPkey index
}
func (i publicreportNotifyEmailPoolIndexes) AsSlice() []index {
return []index{
i.NotifyEmailPoolPkey,
}
}
type publicreportNotifyEmailPoolForeignKeys struct {
PublicreportNotifyEmailPoolNotifyEmailPoolEmailAddressFkey foreignKey
PublicreportNotifyEmailPoolNotifyEmailPoolPoolIDFkey foreignKey
}
func (f publicreportNotifyEmailPoolForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyEmailPoolNotifyEmailPoolEmailAddressFkey, f.PublicreportNotifyEmailPoolNotifyEmailPoolPoolIDFkey,
}
}
type publicreportNotifyEmailPoolUniques struct{}
func (u publicreportNotifyEmailPoolUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyEmailPoolChecks struct{}
func (c publicreportNotifyEmailPoolChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,152 @@
// 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 dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyPhoneNuisances = Table[
publicreportNotifyPhoneNuisanceColumns,
publicreportNotifyPhoneNuisanceIndexes,
publicreportNotifyPhoneNuisanceForeignKeys,
publicreportNotifyPhoneNuisanceUniques,
publicreportNotifyPhoneNuisanceChecks,
]{
Schema: "publicreport",
Name: "notify_phone_nuisance",
Columns: publicreportNotifyPhoneNuisanceColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Deleted: column{
Name: "deleted",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
NuisanceID: column{
Name: "nuisance_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PhoneE164: column{
Name: "phone_e164",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNotifyPhoneNuisanceIndexes{
NotifyPhoneNuisancePkey: index{
Type: "btree",
Name: "notify_phone_nuisance_pkey",
Columns: []indexColumn{
{
Name: "nuisance_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "phone_e164",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "notify_phone_nuisance_pkey",
Columns: []string{"nuisance_id", "phone_e164"},
Comment: "",
},
ForeignKeys: publicreportNotifyPhoneNuisanceForeignKeys{
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisanceNuisanceIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey",
Columns: []string{"nuisance_id"},
Comment: "",
},
ForeignTable: "publicreport.nuisance",
ForeignColumns: []string{"id"},
},
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisancePhoneE164Fkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey",
Columns: []string{"phone_e164"},
Comment: "",
},
ForeignTable: "comms.phone",
ForeignColumns: []string{"e164"},
},
},
Comment: "",
}
type publicreportNotifyPhoneNuisanceColumns struct {
Created column
Deleted column
NuisanceID column
PhoneE164 column
}
func (c publicreportNotifyPhoneNuisanceColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.NuisanceID, c.PhoneE164,
}
}
type publicreportNotifyPhoneNuisanceIndexes struct {
NotifyPhoneNuisancePkey index
}
func (i publicreportNotifyPhoneNuisanceIndexes) AsSlice() []index {
return []index{
i.NotifyPhoneNuisancePkey,
}
}
type publicreportNotifyPhoneNuisanceForeignKeys struct {
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisanceNuisanceIDFkey foreignKey
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisancePhoneE164Fkey foreignKey
}
func (f publicreportNotifyPhoneNuisanceForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyPhoneNuisanceNotifyPhoneNuisanceNuisanceIDFkey, f.PublicreportNotifyPhoneNuisanceNotifyPhoneNuisancePhoneE164Fkey,
}
}
type publicreportNotifyPhoneNuisanceUniques struct{}
func (u publicreportNotifyPhoneNuisanceUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyPhoneNuisanceChecks struct{}
func (c publicreportNotifyPhoneNuisanceChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,152 @@
// 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 dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyPhonePools = Table[
publicreportNotifyPhonePoolColumns,
publicreportNotifyPhonePoolIndexes,
publicreportNotifyPhonePoolForeignKeys,
publicreportNotifyPhonePoolUniques,
publicreportNotifyPhonePoolChecks,
]{
Schema: "publicreport",
Name: "notify_phone_pool",
Columns: publicreportNotifyPhonePoolColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Deleted: column{
Name: "deleted",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
PhoneE164: column{
Name: "phone_e164",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PoolID: column{
Name: "pool_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNotifyPhonePoolIndexes{
NotifyPhonePoolPkey: index{
Type: "btree",
Name: "notify_phone_pool_pkey",
Columns: []indexColumn{
{
Name: "pool_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "phone_e164",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "notify_phone_pool_pkey",
Columns: []string{"pool_id", "phone_e164"},
Comment: "",
},
ForeignKeys: publicreportNotifyPhonePoolForeignKeys{
PublicreportNotifyPhonePoolNotifyPhonePoolPhoneE164Fkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey",
Columns: []string{"phone_e164"},
Comment: "",
},
ForeignTable: "comms.phone",
ForeignColumns: []string{"e164"},
},
PublicreportNotifyPhonePoolNotifyPhonePoolPoolIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey",
Columns: []string{"pool_id"},
Comment: "",
},
ForeignTable: "publicreport.pool",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type publicreportNotifyPhonePoolColumns struct {
Created column
Deleted column
PhoneE164 column
PoolID column
}
func (c publicreportNotifyPhonePoolColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.PhoneE164, c.PoolID,
}
}
type publicreportNotifyPhonePoolIndexes struct {
NotifyPhonePoolPkey index
}
func (i publicreportNotifyPhonePoolIndexes) AsSlice() []index {
return []index{
i.NotifyPhonePoolPkey,
}
}
type publicreportNotifyPhonePoolForeignKeys struct {
PublicreportNotifyPhonePoolNotifyPhonePoolPhoneE164Fkey foreignKey
PublicreportNotifyPhonePoolNotifyPhonePoolPoolIDFkey foreignKey
}
func (f publicreportNotifyPhonePoolForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyPhonePoolNotifyPhonePoolPhoneE164Fkey, f.PublicreportNotifyPhonePoolNotifyPhonePoolPoolIDFkey,
}
}
type publicreportNotifyPhonePoolUniques struct{}
func (u publicreportNotifyPhonePoolUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyPhonePoolChecks struct{}
func (c publicreportNotifyPhonePoolChecks) AsSlice() []check {
return []check{}
}

View file

@ -321,6 +321,15 @@ var PublicreportNuisances = Table[
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNuisanceIndexes{
NuisancePkey: index{
@ -386,45 +395,46 @@ var PublicreportNuisances = Table[
}
type publicreportNuisanceColumns struct {
ID column
AdditionalInfo column
Created column
Duration column
SourceContainer column
SourceDescription column
SourceStagnant column
PublicID column
ReporterEmail column
ReporterName column
ReporterPhone column
Address column
Location column
Status column
OrganizationID column
SourceGutter column
H3cell column
AddressCountry column
AddressPlace column
AddressPostcode column
AddressRegion column
AddressStreet column
IsLocationBackyard column
IsLocationFrontyard column
IsLocationGarden column
IsLocationOther column
IsLocationPool column
MapZoom column
TodEarly column
TodDay column
TodEvening column
TodNight column
LatlngAccuracyType column
LatlngAccuracyValue column
ID column
AdditionalInfo column
Created column
Duration column
SourceContainer column
SourceDescription column
SourceStagnant column
PublicID column
ReporterEmail column
ReporterName column
ReporterPhone column
Address column
Location column
Status column
OrganizationID column
SourceGutter column
H3cell column
AddressCountry column
AddressPlace column
AddressPostcode column
AddressRegion column
AddressStreet column
IsLocationBackyard column
IsLocationFrontyard column
IsLocationGarden column
IsLocationOther column
IsLocationPool column
MapZoom column
TodEarly column
TodDay column
TodEvening column
TodNight column
LatlngAccuracyType column
LatlngAccuracyValue column
ReporterContactConsent column
}
func (c publicreportNuisanceColumns) AsSlice() []column {
return []column{
c.ID, c.AdditionalInfo, c.Created, c.Duration, c.SourceContainer, c.SourceDescription, c.SourceStagnant, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Address, c.Location, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressPlace, c.AddressPostcode, c.AddressRegion, c.AddressStreet, c.IsLocationBackyard, c.IsLocationFrontyard, c.IsLocationGarden, c.IsLocationOther, c.IsLocationPool, c.MapZoom, c.TodEarly, c.TodDay, c.TodEvening, c.TodNight, c.LatlngAccuracyType, c.LatlngAccuracyValue,
c.ID, c.AdditionalInfo, c.Created, c.Duration, c.SourceContainer, c.SourceDescription, c.SourceStagnant, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Address, c.Location, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressPlace, c.AddressPostcode, c.AddressRegion, c.AddressStreet, c.IsLocationBackyard, c.IsLocationFrontyard, c.IsLocationGarden, c.IsLocationOther, c.IsLocationPool, c.MapZoom, c.TodEarly, c.TodDay, c.TodEvening, c.TodNight, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.ReporterContactConsent,
}
}

View file

@ -312,6 +312,15 @@ var PublicreportPools = Table[
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportPoolIndexes{
PoolPkey: index{
@ -410,11 +419,12 @@ type publicreportPoolColumns struct {
HasBackyardPermission column
IsReporterConfidential column
IsReporterOwner column
ReporterContactConsent column
}
func (c publicreportPoolColumns) AsSlice() []column {
return []column{
c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.Address, c.AddressCountry, c.AddressPostCode, c.AddressPlace, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, c.Location, c.MapZoom, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Status, c.OrganizationID, c.HasBackyardPermission, c.IsReporterConfidential, c.IsReporterOwner,
c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.Address, c.AddressCountry, c.AddressPostCode, c.AddressPlace, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, c.Location, c.MapZoom, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Status, c.OrganizationID, c.HasBackyardPermission, c.IsReporterConfidential, c.IsReporterOwner, c.ReporterContactConsent,
}
}

View file

@ -18,9 +18,11 @@ var (
arcgisUserPrivilegeRelUserUserCtx = newContextual[bool]("arcgis.user_.arcgis.user_privilege.arcgis.user_privilege.user_privilege_user_id_fkey")
// Relationship Contexts for comms.email_contact
commsEmailContactWithParentsCascadingCtx = newContextual[bool]("commsEmailContactWithParentsCascading")
commsEmailContactRelDestinationEmailLogsCtx = newContextual[bool]("comms.email_contact.comms.email_log.comms.email_log.email_log_destination_fkey")
commsEmailContactRelOrganizationsCtx = newContextual[bool]("comms.email_contact.organization.district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey")
commsEmailContactWithParentsCascadingCtx = newContextual[bool]("commsEmailContactWithParentsCascading")
commsEmailContactRelDestinationEmailLogsCtx = newContextual[bool]("comms.email_contact.comms.email_log.comms.email_log.email_log_destination_fkey")
commsEmailContactRelOrganizationsCtx = newContextual[bool]("comms.email_contact.organization.district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey")
commsEmailContactRelEmailAddressNotifyEmailNuisancesCtx = newContextual[bool]("comms.email_contact.publicreport.notify_email_nuisance.publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey")
commsEmailContactRelEmailAddressNotifyEmailPoolsCtx = newContextual[bool]("comms.email_contact.publicreport.notify_email_pool.publicreport.notify_email_pool.notify_email_pool_email_address_fkey")
// Relationship Contexts for comms.email_log
commsEmailLogWithParentsCascadingCtx = newContextual[bool]("commsEmailLogWithParentsCascading")
@ -32,11 +34,13 @@ var (
commsEmailTemplateRelTemplateEmailLogsCtx = newContextual[bool]("comms.email_log.comms.email_template.comms.email_log.email_log_template_id_fkey")
// Relationship Contexts for comms.phone
commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading")
commsPhoneRelDestinationTextJobsCtx = newContextual[bool]("comms.phone.comms.text_job.comms.text_job.text_job_destination_fkey")
commsPhoneRelDestinationTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey")
commsPhoneRelSourceTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_source_fkey")
commsPhoneRelOrganizationsCtx = newContextual[bool]("comms.phone.organization.district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey")
commsPhoneWithParentsCascadingCtx = newContextual[bool]("commsPhoneWithParentsCascading")
commsPhoneRelDestinationTextJobsCtx = newContextual[bool]("comms.phone.comms.text_job.comms.text_job.text_job_destination_fkey")
commsPhoneRelDestinationTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_destination_fkey")
commsPhoneRelSourceTextLogsCtx = newContextual[bool]("comms.phone.comms.text_log.comms.text_log.text_log_source_fkey")
commsPhoneRelOrganizationsCtx = newContextual[bool]("comms.phone.organization.district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey")
commsPhoneRelPhoneE164NotifyPhoneNuisancesCtx = newContextual[bool]("comms.phone.publicreport.notify_phone_nuisance.publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey")
commsPhoneRelPhoneE164NotifyPhonePoolsCtx = newContextual[bool]("comms.phone.publicreport.notify_phone_pool.publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey")
// Relationship Contexts for comms.text_job
commsTextJobWithParentsCascadingCtx = newContextual[bool]("commsTextJobWithParentsCascading")
@ -278,10 +282,32 @@ var (
publicreportImageExifWithParentsCascadingCtx = newContextual[bool]("publicreportImageExifWithParentsCascading")
publicreportImageExifRelImageCtx = newContextual[bool]("publicreport.image.publicreport.image_exif.publicreport.image_exif.image_exif_image_id_fkey")
// Relationship Contexts for publicreport.notify_email_nuisance
publicreportNotifyEmailNuisanceWithParentsCascadingCtx = newContextual[bool]("publicreportNotifyEmailNuisanceWithParentsCascading")
publicreportNotifyEmailNuisanceRelEmailAddressEmailContactCtx = newContextual[bool]("comms.email_contact.publicreport.notify_email_nuisance.publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey")
publicreportNotifyEmailNuisanceRelNuisanceCtx = newContextual[bool]("publicreport.notify_email_nuisance.publicreport.nuisance.publicreport.notify_email_nuisance.notify_email_nuisance_nuisance_id_fkey")
// Relationship Contexts for publicreport.notify_email_pool
publicreportNotifyEmailPoolWithParentsCascadingCtx = newContextual[bool]("publicreportNotifyEmailPoolWithParentsCascading")
publicreportNotifyEmailPoolRelEmailAddressEmailContactCtx = newContextual[bool]("comms.email_contact.publicreport.notify_email_pool.publicreport.notify_email_pool.notify_email_pool_email_address_fkey")
publicreportNotifyEmailPoolRelPoolCtx = newContextual[bool]("publicreport.notify_email_pool.publicreport.pool.publicreport.notify_email_pool.notify_email_pool_pool_id_fkey")
// Relationship Contexts for publicreport.notify_phone_nuisance
publicreportNotifyPhoneNuisanceWithParentsCascadingCtx = newContextual[bool]("publicreportNotifyPhoneNuisanceWithParentsCascading")
publicreportNotifyPhoneNuisanceRelNuisanceCtx = newContextual[bool]("publicreport.notify_phone_nuisance.publicreport.nuisance.publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey")
publicreportNotifyPhoneNuisanceRelPhoneE164PhoneCtx = newContextual[bool]("comms.phone.publicreport.notify_phone_nuisance.publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey")
// Relationship Contexts for publicreport.notify_phone_pool
publicreportNotifyPhonePoolWithParentsCascadingCtx = newContextual[bool]("publicreportNotifyPhonePoolWithParentsCascading")
publicreportNotifyPhonePoolRelPhoneE164PhoneCtx = newContextual[bool]("comms.phone.publicreport.notify_phone_pool.publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey")
publicreportNotifyPhonePoolRelPoolCtx = newContextual[bool]("publicreport.notify_phone_pool.publicreport.pool.publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey")
// Relationship Contexts for publicreport.nuisance
publicreportNuisanceWithParentsCascadingCtx = newContextual[bool]("publicreportNuisanceWithParentsCascading")
publicreportNuisanceRelOrganizationCtx = newContextual[bool]("organization.publicreport.nuisance.publicreport.nuisance.nuisance_organization_id_fkey")
publicreportNuisanceRelImagesCtx = newContextual[bool]("publicreport.image.publicreport.nuisance.publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey")
publicreportNuisanceWithParentsCascadingCtx = newContextual[bool]("publicreportNuisanceWithParentsCascading")
publicreportNuisanceRelNotifyEmailNuisancesCtx = newContextual[bool]("publicreport.notify_email_nuisance.publicreport.nuisance.publicreport.notify_email_nuisance.notify_email_nuisance_nuisance_id_fkey")
publicreportNuisanceRelNotifyPhoneNuisancesCtx = newContextual[bool]("publicreport.notify_phone_nuisance.publicreport.nuisance.publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey")
publicreportNuisanceRelOrganizationCtx = newContextual[bool]("organization.publicreport.nuisance.publicreport.nuisance.nuisance_organization_id_fkey")
publicreportNuisanceRelImagesCtx = newContextual[bool]("publicreport.image.publicreport.nuisance.publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey")
// Relationship Contexts for publicreport.nuisance_image
publicreportNuisanceImageWithParentsCascadingCtx = newContextual[bool]("publicreportNuisanceImageWithParentsCascading")
@ -290,6 +316,8 @@ var (
// Relationship Contexts for publicreport.pool
publicreportPoolWithParentsCascadingCtx = newContextual[bool]("publicreportPoolWithParentsCascading")
publicreportPoolRelNotifyEmailPoolsCtx = newContextual[bool]("publicreport.notify_email_pool.publicreport.pool.publicreport.notify_email_pool.notify_email_pool_pool_id_fkey")
publicreportPoolRelNotifyPhonePoolsCtx = newContextual[bool]("publicreport.notify_phone_pool.publicreport.pool.publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey")
publicreportPoolRelOrganizationCtx = newContextual[bool]("organization.publicreport.pool.publicreport.pool.pool_organization_id_fkey")
publicreportPoolRelImagesCtx = newContextual[bool]("publicreport.image.publicreport.pool.publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey")

View file

@ -73,6 +73,10 @@ type Factory struct {
baseOrganizationMods OrganizationModSlice
basePublicreportImageMods PublicreportImageModSlice
basePublicreportImageExifMods PublicreportImageExifModSlice
basePublicreportNotifyEmailNuisanceMods PublicreportNotifyEmailNuisanceModSlice
basePublicreportNotifyEmailPoolMods PublicreportNotifyEmailPoolModSlice
basePublicreportNotifyPhoneNuisanceMods PublicreportNotifyPhoneNuisanceModSlice
basePublicreportNotifyPhonePoolMods PublicreportNotifyPhonePoolModSlice
basePublicreportNuisanceMods PublicreportNuisanceModSlice
basePublicreportNuisanceImageMods PublicreportNuisanceImageModSlice
basePublicreportPoolMods PublicreportPoolModSlice
@ -197,6 +201,12 @@ func (f *Factory) FromExistingCommsEmailContact(m *models.CommsEmailContact) *Co
if len(m.R.Organizations) > 0 {
CommsEmailContactMods.AddExistingOrganizations(m.R.Organizations...).Apply(ctx, o)
}
if len(m.R.EmailAddressNotifyEmailNuisances) > 0 {
CommsEmailContactMods.AddExistingEmailAddressNotifyEmailNuisances(m.R.EmailAddressNotifyEmailNuisances...).Apply(ctx, o)
}
if len(m.R.EmailAddressNotifyEmailPools) > 0 {
CommsEmailContactMods.AddExistingEmailAddressNotifyEmailPools(m.R.EmailAddressNotifyEmailPools...).Apply(ctx, o)
}
return o
}
@ -315,6 +325,12 @@ func (f *Factory) FromExistingCommsPhone(m *models.CommsPhone) *CommsPhoneTempla
if len(m.R.Organizations) > 0 {
CommsPhoneMods.AddExistingOrganizations(m.R.Organizations...).Apply(ctx, o)
}
if len(m.R.PhoneE164NotifyPhoneNuisances) > 0 {
CommsPhoneMods.AddExistingPhoneE164NotifyPhoneNuisances(m.R.PhoneE164NotifyPhoneNuisances...).Apply(ctx, o)
}
if len(m.R.PhoneE164NotifyPhonePools) > 0 {
CommsPhoneMods.AddExistingPhoneE164NotifyPhonePools(m.R.PhoneE164NotifyPhonePools...).Apply(ctx, o)
}
return o
}
@ -2913,6 +2929,146 @@ func (f *Factory) FromExistingPublicreportImageExif(m *models.PublicreportImageE
return o
}
func (f *Factory) NewPublicreportNotifyEmailNuisance(mods ...PublicreportNotifyEmailNuisanceMod) *PublicreportNotifyEmailNuisanceTemplate {
return f.NewPublicreportNotifyEmailNuisanceWithContext(context.Background(), mods...)
}
func (f *Factory) NewPublicreportNotifyEmailNuisanceWithContext(ctx context.Context, mods ...PublicreportNotifyEmailNuisanceMod) *PublicreportNotifyEmailNuisanceTemplate {
o := &PublicreportNotifyEmailNuisanceTemplate{f: f}
if f != nil {
f.basePublicreportNotifyEmailNuisanceMods.Apply(ctx, o)
}
PublicreportNotifyEmailNuisanceModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingPublicreportNotifyEmailNuisance(m *models.PublicreportNotifyEmailNuisance) *PublicreportNotifyEmailNuisanceTemplate {
o := &PublicreportNotifyEmailNuisanceTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
o.NuisanceID = func() int32 { return m.NuisanceID }
o.EmailAddress = func() string { return m.EmailAddress }
ctx := context.Background()
if m.R.EmailAddressEmailContact != nil {
PublicreportNotifyEmailNuisanceMods.WithExistingEmailAddressEmailContact(m.R.EmailAddressEmailContact).Apply(ctx, o)
}
if m.R.Nuisance != nil {
PublicreportNotifyEmailNuisanceMods.WithExistingNuisance(m.R.Nuisance).Apply(ctx, o)
}
return o
}
func (f *Factory) NewPublicreportNotifyEmailPool(mods ...PublicreportNotifyEmailPoolMod) *PublicreportNotifyEmailPoolTemplate {
return f.NewPublicreportNotifyEmailPoolWithContext(context.Background(), mods...)
}
func (f *Factory) NewPublicreportNotifyEmailPoolWithContext(ctx context.Context, mods ...PublicreportNotifyEmailPoolMod) *PublicreportNotifyEmailPoolTemplate {
o := &PublicreportNotifyEmailPoolTemplate{f: f}
if f != nil {
f.basePublicreportNotifyEmailPoolMods.Apply(ctx, o)
}
PublicreportNotifyEmailPoolModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingPublicreportNotifyEmailPool(m *models.PublicreportNotifyEmailPool) *PublicreportNotifyEmailPoolTemplate {
o := &PublicreportNotifyEmailPoolTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
o.PoolID = func() int32 { return m.PoolID }
o.EmailAddress = func() string { return m.EmailAddress }
ctx := context.Background()
if m.R.EmailAddressEmailContact != nil {
PublicreportNotifyEmailPoolMods.WithExistingEmailAddressEmailContact(m.R.EmailAddressEmailContact).Apply(ctx, o)
}
if m.R.Pool != nil {
PublicreportNotifyEmailPoolMods.WithExistingPool(m.R.Pool).Apply(ctx, o)
}
return o
}
func (f *Factory) NewPublicreportNotifyPhoneNuisance(mods ...PublicreportNotifyPhoneNuisanceMod) *PublicreportNotifyPhoneNuisanceTemplate {
return f.NewPublicreportNotifyPhoneNuisanceWithContext(context.Background(), mods...)
}
func (f *Factory) NewPublicreportNotifyPhoneNuisanceWithContext(ctx context.Context, mods ...PublicreportNotifyPhoneNuisanceMod) *PublicreportNotifyPhoneNuisanceTemplate {
o := &PublicreportNotifyPhoneNuisanceTemplate{f: f}
if f != nil {
f.basePublicreportNotifyPhoneNuisanceMods.Apply(ctx, o)
}
PublicreportNotifyPhoneNuisanceModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingPublicreportNotifyPhoneNuisance(m *models.PublicreportNotifyPhoneNuisance) *PublicreportNotifyPhoneNuisanceTemplate {
o := &PublicreportNotifyPhoneNuisanceTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
o.NuisanceID = func() int32 { return m.NuisanceID }
o.PhoneE164 = func() string { return m.PhoneE164 }
ctx := context.Background()
if m.R.Nuisance != nil {
PublicreportNotifyPhoneNuisanceMods.WithExistingNuisance(m.R.Nuisance).Apply(ctx, o)
}
if m.R.PhoneE164Phone != nil {
PublicreportNotifyPhoneNuisanceMods.WithExistingPhoneE164Phone(m.R.PhoneE164Phone).Apply(ctx, o)
}
return o
}
func (f *Factory) NewPublicreportNotifyPhonePool(mods ...PublicreportNotifyPhonePoolMod) *PublicreportNotifyPhonePoolTemplate {
return f.NewPublicreportNotifyPhonePoolWithContext(context.Background(), mods...)
}
func (f *Factory) NewPublicreportNotifyPhonePoolWithContext(ctx context.Context, mods ...PublicreportNotifyPhonePoolMod) *PublicreportNotifyPhonePoolTemplate {
o := &PublicreportNotifyPhonePoolTemplate{f: f}
if f != nil {
f.basePublicreportNotifyPhonePoolMods.Apply(ctx, o)
}
PublicreportNotifyPhonePoolModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingPublicreportNotifyPhonePool(m *models.PublicreportNotifyPhonePool) *PublicreportNotifyPhonePoolTemplate {
o := &PublicreportNotifyPhonePoolTemplate{f: f, alreadyPersisted: true}
o.Created = func() time.Time { return m.Created }
o.Deleted = func() null.Val[time.Time] { return m.Deleted }
o.PhoneE164 = func() string { return m.PhoneE164 }
o.PoolID = func() int32 { return m.PoolID }
ctx := context.Background()
if m.R.PhoneE164Phone != nil {
PublicreportNotifyPhonePoolMods.WithExistingPhoneE164Phone(m.R.PhoneE164Phone).Apply(ctx, o)
}
if m.R.Pool != nil {
PublicreportNotifyPhonePoolMods.WithExistingPool(m.R.Pool).Apply(ctx, o)
}
return o
}
func (f *Factory) NewPublicreportNuisance(mods ...PublicreportNuisanceMod) *PublicreportNuisanceTemplate {
return f.NewPublicreportNuisanceWithContext(context.Background(), mods...)
}
@ -2966,8 +3122,15 @@ func (f *Factory) FromExistingPublicreportNuisance(m *models.PublicreportNuisanc
o.TodNight = func() bool { return m.TodNight }
o.LatlngAccuracyType = func() enums.PublicreportAccuracytype { return m.LatlngAccuracyType }
o.LatlngAccuracyValue = func() float32 { return m.LatlngAccuracyValue }
o.ReporterContactConsent = func() null.Val[bool] { return m.ReporterContactConsent }
ctx := context.Background()
if len(m.R.NotifyEmailNuisances) > 0 {
PublicreportNuisanceMods.AddExistingNotifyEmailNuisances(m.R.NotifyEmailNuisances...).Apply(ctx, o)
}
if len(m.R.NotifyPhoneNuisances) > 0 {
PublicreportNuisanceMods.AddExistingNotifyPhoneNuisances(m.R.NotifyPhoneNuisances...).Apply(ctx, o)
}
if m.R.Organization != nil {
PublicreportNuisanceMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o)
}
@ -3063,8 +3226,15 @@ func (f *Factory) FromExistingPublicreportPool(m *models.PublicreportPool) *Publ
o.HasBackyardPermission = func() bool { return m.HasBackyardPermission }
o.IsReporterConfidential = func() bool { return m.IsReporterConfidential }
o.IsReporterOwner = func() bool { return m.IsReporterOwner }
o.ReporterContactConsent = func() null.Val[bool] { return m.ReporterContactConsent }
ctx := context.Background()
if len(m.R.NotifyEmailPools) > 0 {
PublicreportPoolMods.AddExistingNotifyEmailPools(m.R.NotifyEmailPools...).Apply(ctx, o)
}
if len(m.R.NotifyPhonePools) > 0 {
PublicreportPoolMods.AddExistingNotifyPhonePools(m.R.NotifyPhonePools...).Apply(ctx, o)
}
if m.R.Organization != nil {
PublicreportPoolMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o)
}
@ -3832,6 +4002,38 @@ func (f *Factory) AddBasePublicreportImageExifMod(mods ...PublicreportImageExifM
f.basePublicreportImageExifMods = append(f.basePublicreportImageExifMods, mods...)
}
func (f *Factory) ClearBasePublicreportNotifyEmailNuisanceMods() {
f.basePublicreportNotifyEmailNuisanceMods = nil
}
func (f *Factory) AddBasePublicreportNotifyEmailNuisanceMod(mods ...PublicreportNotifyEmailNuisanceMod) {
f.basePublicreportNotifyEmailNuisanceMods = append(f.basePublicreportNotifyEmailNuisanceMods, mods...)
}
func (f *Factory) ClearBasePublicreportNotifyEmailPoolMods() {
f.basePublicreportNotifyEmailPoolMods = nil
}
func (f *Factory) AddBasePublicreportNotifyEmailPoolMod(mods ...PublicreportNotifyEmailPoolMod) {
f.basePublicreportNotifyEmailPoolMods = append(f.basePublicreportNotifyEmailPoolMods, mods...)
}
func (f *Factory) ClearBasePublicreportNotifyPhoneNuisanceMods() {
f.basePublicreportNotifyPhoneNuisanceMods = nil
}
func (f *Factory) AddBasePublicreportNotifyPhoneNuisanceMod(mods ...PublicreportNotifyPhoneNuisanceMod) {
f.basePublicreportNotifyPhoneNuisanceMods = append(f.basePublicreportNotifyPhoneNuisanceMods, mods...)
}
func (f *Factory) ClearBasePublicreportNotifyPhonePoolMods() {
f.basePublicreportNotifyPhonePoolMods = nil
}
func (f *Factory) AddBasePublicreportNotifyPhonePoolMod(mods ...PublicreportNotifyPhonePoolMod) {
f.basePublicreportNotifyPhonePoolMods = append(f.basePublicreportNotifyPhonePoolMods, mods...)
}
func (f *Factory) ClearBasePublicreportNuisanceMods() {
f.basePublicreportNuisanceMods = nil
}

View file

@ -46,8 +46,10 @@ type CommsEmailContactTemplate struct {
}
type commsEmailContactR struct {
DestinationEmailLogs []*commsEmailContactRDestinationEmailLogsR
Organizations []*commsEmailContactROrganizationsR
DestinationEmailLogs []*commsEmailContactRDestinationEmailLogsR
Organizations []*commsEmailContactROrganizationsR
EmailAddressNotifyEmailNuisances []*commsEmailContactREmailAddressNotifyEmailNuisancesR
EmailAddressNotifyEmailPools []*commsEmailContactREmailAddressNotifyEmailPoolsR
}
type commsEmailContactRDestinationEmailLogsR struct {
@ -58,6 +60,14 @@ type commsEmailContactROrganizationsR struct {
number int
o *OrganizationTemplate
}
type commsEmailContactREmailAddressNotifyEmailNuisancesR struct {
number int
o *PublicreportNotifyEmailNuisanceTemplate
}
type commsEmailContactREmailAddressNotifyEmailPoolsR struct {
number int
o *PublicreportNotifyEmailPoolTemplate
}
// Apply mods to the CommsEmailContactTemplate
func (o *CommsEmailContactTemplate) Apply(ctx context.Context, mods ...CommsEmailContactMod) {
@ -93,6 +103,32 @@ func (t CommsEmailContactTemplate) setModelRels(o *models.CommsEmailContact) {
}
o.R.Organizations = rel
}
if t.r.EmailAddressNotifyEmailNuisances != nil {
rel := models.PublicreportNotifyEmailNuisanceSlice{}
for _, r := range t.r.EmailAddressNotifyEmailNuisances {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.EmailAddress = o.Address // h2
rel.R.EmailAddressEmailContact = o
}
rel = append(rel, related...)
}
o.R.EmailAddressNotifyEmailNuisances = rel
}
if t.r.EmailAddressNotifyEmailPools != nil {
rel := models.PublicreportNotifyEmailPoolSlice{}
for _, r := range t.r.EmailAddressNotifyEmailPools {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.EmailAddress = o.Address // h2
rel.R.EmailAddressEmailContact = o
}
rel = append(rel, related...)
}
o.R.EmailAddressNotifyEmailPools = rel
}
}
// BuildSetter returns an *models.CommsEmailContactSetter
@ -234,6 +270,46 @@ func (o *CommsEmailContactTemplate) insertOptRels(ctx context.Context, exec bob.
}
}
isEmailAddressNotifyEmailNuisancesDone, _ := commsEmailContactRelEmailAddressNotifyEmailNuisancesCtx.Value(ctx)
if !isEmailAddressNotifyEmailNuisancesDone && o.r.EmailAddressNotifyEmailNuisances != nil {
ctx = commsEmailContactRelEmailAddressNotifyEmailNuisancesCtx.WithValue(ctx, true)
for _, r := range o.r.EmailAddressNotifyEmailNuisances {
if r.o.alreadyPersisted {
m.R.EmailAddressNotifyEmailNuisances = append(m.R.EmailAddressNotifyEmailNuisances, r.o.Build())
} else {
rel2, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachEmailAddressNotifyEmailNuisances(ctx, exec, rel2...)
if err != nil {
return err
}
}
}
}
isEmailAddressNotifyEmailPoolsDone, _ := commsEmailContactRelEmailAddressNotifyEmailPoolsCtx.Value(ctx)
if !isEmailAddressNotifyEmailPoolsDone && o.r.EmailAddressNotifyEmailPools != nil {
ctx = commsEmailContactRelEmailAddressNotifyEmailPoolsCtx.WithValue(ctx, true)
for _, r := range o.r.EmailAddressNotifyEmailPools {
if r.o.alreadyPersisted {
m.R.EmailAddressNotifyEmailPools = append(m.R.EmailAddressNotifyEmailPools, r.o.Build())
} else {
rel3, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachEmailAddressNotifyEmailPools(ctx, exec, rel3...)
if err != nil {
return err
}
}
}
}
return err
}
@ -561,3 +637,99 @@ func (m commsEmailContactMods) WithoutOrganizations() CommsEmailContactMod {
o.r.Organizations = nil
})
}
func (m commsEmailContactMods) WithEmailAddressNotifyEmailNuisances(number int, related *PublicreportNotifyEmailNuisanceTemplate) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
o.r.EmailAddressNotifyEmailNuisances = []*commsEmailContactREmailAddressNotifyEmailNuisancesR{{
number: number,
o: related,
}}
})
}
func (m commsEmailContactMods) WithNewEmailAddressNotifyEmailNuisances(number int, mods ...PublicreportNotifyEmailNuisanceMod) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
related := o.f.NewPublicreportNotifyEmailNuisanceWithContext(ctx, mods...)
m.WithEmailAddressNotifyEmailNuisances(number, related).Apply(ctx, o)
})
}
func (m commsEmailContactMods) AddEmailAddressNotifyEmailNuisances(number int, related *PublicreportNotifyEmailNuisanceTemplate) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
o.r.EmailAddressNotifyEmailNuisances = append(o.r.EmailAddressNotifyEmailNuisances, &commsEmailContactREmailAddressNotifyEmailNuisancesR{
number: number,
o: related,
})
})
}
func (m commsEmailContactMods) AddNewEmailAddressNotifyEmailNuisances(number int, mods ...PublicreportNotifyEmailNuisanceMod) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
related := o.f.NewPublicreportNotifyEmailNuisanceWithContext(ctx, mods...)
m.AddEmailAddressNotifyEmailNuisances(number, related).Apply(ctx, o)
})
}
func (m commsEmailContactMods) AddExistingEmailAddressNotifyEmailNuisances(existingModels ...*models.PublicreportNotifyEmailNuisance) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
for _, em := range existingModels {
o.r.EmailAddressNotifyEmailNuisances = append(o.r.EmailAddressNotifyEmailNuisances, &commsEmailContactREmailAddressNotifyEmailNuisancesR{
o: o.f.FromExistingPublicreportNotifyEmailNuisance(em),
})
}
})
}
func (m commsEmailContactMods) WithoutEmailAddressNotifyEmailNuisances() CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
o.r.EmailAddressNotifyEmailNuisances = nil
})
}
func (m commsEmailContactMods) WithEmailAddressNotifyEmailPools(number int, related *PublicreportNotifyEmailPoolTemplate) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
o.r.EmailAddressNotifyEmailPools = []*commsEmailContactREmailAddressNotifyEmailPoolsR{{
number: number,
o: related,
}}
})
}
func (m commsEmailContactMods) WithNewEmailAddressNotifyEmailPools(number int, mods ...PublicreportNotifyEmailPoolMod) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
related := o.f.NewPublicreportNotifyEmailPoolWithContext(ctx, mods...)
m.WithEmailAddressNotifyEmailPools(number, related).Apply(ctx, o)
})
}
func (m commsEmailContactMods) AddEmailAddressNotifyEmailPools(number int, related *PublicreportNotifyEmailPoolTemplate) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
o.r.EmailAddressNotifyEmailPools = append(o.r.EmailAddressNotifyEmailPools, &commsEmailContactREmailAddressNotifyEmailPoolsR{
number: number,
o: related,
})
})
}
func (m commsEmailContactMods) AddNewEmailAddressNotifyEmailPools(number int, mods ...PublicreportNotifyEmailPoolMod) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
related := o.f.NewPublicreportNotifyEmailPoolWithContext(ctx, mods...)
m.AddEmailAddressNotifyEmailPools(number, related).Apply(ctx, o)
})
}
func (m commsEmailContactMods) AddExistingEmailAddressNotifyEmailPools(existingModels ...*models.PublicreportNotifyEmailPool) CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
for _, em := range existingModels {
o.r.EmailAddressNotifyEmailPools = append(o.r.EmailAddressNotifyEmailPools, &commsEmailContactREmailAddressNotifyEmailPoolsR{
o: o.f.FromExistingPublicreportNotifyEmailPool(em),
})
}
})
}
func (m commsEmailContactMods) WithoutEmailAddressNotifyEmailPools() CommsEmailContactMod {
return CommsEmailContactModFunc(func(ctx context.Context, o *CommsEmailContactTemplate) {
o.r.EmailAddressNotifyEmailPools = nil
})
}

View file

@ -46,10 +46,12 @@ type CommsPhoneTemplate struct {
}
type commsPhoneR struct {
DestinationTextJobs []*commsPhoneRDestinationTextJobsR
DestinationTextLogs []*commsPhoneRDestinationTextLogsR
SourceTextLogs []*commsPhoneRSourceTextLogsR
Organizations []*commsPhoneROrganizationsR
DestinationTextJobs []*commsPhoneRDestinationTextJobsR
DestinationTextLogs []*commsPhoneRDestinationTextLogsR
SourceTextLogs []*commsPhoneRSourceTextLogsR
Organizations []*commsPhoneROrganizationsR
PhoneE164NotifyPhoneNuisances []*commsPhoneRPhoneE164NotifyPhoneNuisancesR
PhoneE164NotifyPhonePools []*commsPhoneRPhoneE164NotifyPhonePoolsR
}
type commsPhoneRDestinationTextJobsR struct {
@ -68,6 +70,14 @@ type commsPhoneROrganizationsR struct {
number int
o *OrganizationTemplate
}
type commsPhoneRPhoneE164NotifyPhoneNuisancesR struct {
number int
o *PublicreportNotifyPhoneNuisanceTemplate
}
type commsPhoneRPhoneE164NotifyPhonePoolsR struct {
number int
o *PublicreportNotifyPhonePoolTemplate
}
// Apply mods to the CommsPhoneTemplate
func (o *CommsPhoneTemplate) Apply(ctx context.Context, mods ...CommsPhoneMod) {
@ -129,6 +139,32 @@ func (t CommsPhoneTemplate) setModelRels(o *models.CommsPhone) {
}
o.R.Organizations = rel
}
if t.r.PhoneE164NotifyPhoneNuisances != nil {
rel := models.PublicreportNotifyPhoneNuisanceSlice{}
for _, r := range t.r.PhoneE164NotifyPhoneNuisances {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.PhoneE164 = o.E164 // h2
rel.R.PhoneE164Phone = o
}
rel = append(rel, related...)
}
o.R.PhoneE164NotifyPhoneNuisances = rel
}
if t.r.PhoneE164NotifyPhonePools != nil {
rel := models.PublicreportNotifyPhonePoolSlice{}
for _, r := range t.r.PhoneE164NotifyPhonePools {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.PhoneE164 = o.E164 // h2
rel.R.PhoneE164Phone = o
}
rel = append(rel, related...)
}
o.R.PhoneE164NotifyPhonePools = rel
}
}
// BuildSetter returns an *models.CommsPhoneSetter
@ -299,6 +335,46 @@ func (o *CommsPhoneTemplate) insertOptRels(ctx context.Context, exec bob.Executo
}
}
isPhoneE164NotifyPhoneNuisancesDone, _ := commsPhoneRelPhoneE164NotifyPhoneNuisancesCtx.Value(ctx)
if !isPhoneE164NotifyPhoneNuisancesDone && o.r.PhoneE164NotifyPhoneNuisances != nil {
ctx = commsPhoneRelPhoneE164NotifyPhoneNuisancesCtx.WithValue(ctx, true)
for _, r := range o.r.PhoneE164NotifyPhoneNuisances {
if r.o.alreadyPersisted {
m.R.PhoneE164NotifyPhoneNuisances = append(m.R.PhoneE164NotifyPhoneNuisances, r.o.Build())
} else {
rel4, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachPhoneE164NotifyPhoneNuisances(ctx, exec, rel4...)
if err != nil {
return err
}
}
}
}
isPhoneE164NotifyPhonePoolsDone, _ := commsPhoneRelPhoneE164NotifyPhonePoolsCtx.Value(ctx)
if !isPhoneE164NotifyPhonePoolsDone && o.r.PhoneE164NotifyPhonePools != nil {
ctx = commsPhoneRelPhoneE164NotifyPhonePoolsCtx.WithValue(ctx, true)
for _, r := range o.r.PhoneE164NotifyPhonePools {
if r.o.alreadyPersisted {
m.R.PhoneE164NotifyPhonePools = append(m.R.PhoneE164NotifyPhonePools, r.o.Build())
} else {
rel5, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachPhoneE164NotifyPhonePools(ctx, exec, rel5...)
if err != nil {
return err
}
}
}
}
return err
}
@ -690,3 +766,99 @@ func (m commsPhoneMods) WithoutOrganizations() CommsPhoneMod {
o.r.Organizations = nil
})
}
func (m commsPhoneMods) WithPhoneE164NotifyPhoneNuisances(number int, related *PublicreportNotifyPhoneNuisanceTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneE164NotifyPhoneNuisances = []*commsPhoneRPhoneE164NotifyPhoneNuisancesR{{
number: number,
o: related,
}}
})
}
func (m commsPhoneMods) WithNewPhoneE164NotifyPhoneNuisances(number int, mods ...PublicreportNotifyPhoneNuisanceMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewPublicreportNotifyPhoneNuisanceWithContext(ctx, mods...)
m.WithPhoneE164NotifyPhoneNuisances(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddPhoneE164NotifyPhoneNuisances(number int, related *PublicreportNotifyPhoneNuisanceTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneE164NotifyPhoneNuisances = append(o.r.PhoneE164NotifyPhoneNuisances, &commsPhoneRPhoneE164NotifyPhoneNuisancesR{
number: number,
o: related,
})
})
}
func (m commsPhoneMods) AddNewPhoneE164NotifyPhoneNuisances(number int, mods ...PublicreportNotifyPhoneNuisanceMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewPublicreportNotifyPhoneNuisanceWithContext(ctx, mods...)
m.AddPhoneE164NotifyPhoneNuisances(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddExistingPhoneE164NotifyPhoneNuisances(existingModels ...*models.PublicreportNotifyPhoneNuisance) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
for _, em := range existingModels {
o.r.PhoneE164NotifyPhoneNuisances = append(o.r.PhoneE164NotifyPhoneNuisances, &commsPhoneRPhoneE164NotifyPhoneNuisancesR{
o: o.f.FromExistingPublicreportNotifyPhoneNuisance(em),
})
}
})
}
func (m commsPhoneMods) WithoutPhoneE164NotifyPhoneNuisances() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneE164NotifyPhoneNuisances = nil
})
}
func (m commsPhoneMods) WithPhoneE164NotifyPhonePools(number int, related *PublicreportNotifyPhonePoolTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneE164NotifyPhonePools = []*commsPhoneRPhoneE164NotifyPhonePoolsR{{
number: number,
o: related,
}}
})
}
func (m commsPhoneMods) WithNewPhoneE164NotifyPhonePools(number int, mods ...PublicreportNotifyPhonePoolMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewPublicreportNotifyPhonePoolWithContext(ctx, mods...)
m.WithPhoneE164NotifyPhonePools(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddPhoneE164NotifyPhonePools(number int, related *PublicreportNotifyPhonePoolTemplate) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneE164NotifyPhonePools = append(o.r.PhoneE164NotifyPhonePools, &commsPhoneRPhoneE164NotifyPhonePoolsR{
number: number,
o: related,
})
})
}
func (m commsPhoneMods) AddNewPhoneE164NotifyPhonePools(number int, mods ...PublicreportNotifyPhonePoolMod) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
related := o.f.NewPublicreportNotifyPhonePoolWithContext(ctx, mods...)
m.AddPhoneE164NotifyPhonePools(number, related).Apply(ctx, o)
})
}
func (m commsPhoneMods) AddExistingPhoneE164NotifyPhonePools(existingModels ...*models.PublicreportNotifyPhonePool) CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
for _, em := range existingModels {
o.r.PhoneE164NotifyPhonePools = append(o.r.PhoneE164NotifyPhonePools, &commsPhoneRPhoneE164NotifyPhonePoolsR{
o: o.f.FromExistingPublicreportNotifyPhonePool(em),
})
}
})
}
func (m commsPhoneMods) WithoutPhoneE164NotifyPhonePools() CommsPhoneMod {
return CommsPhoneModFunc(func(ctx context.Context, o *CommsPhoneTemplate) {
o.r.PhoneE164NotifyPhonePools = nil
})
}

View file

@ -0,0 +1,542 @@
// 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 factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type PublicreportNotifyEmailNuisanceMod interface {
Apply(context.Context, *PublicreportNotifyEmailNuisanceTemplate)
}
type PublicreportNotifyEmailNuisanceModFunc func(context.Context, *PublicreportNotifyEmailNuisanceTemplate)
func (f PublicreportNotifyEmailNuisanceModFunc) Apply(ctx context.Context, n *PublicreportNotifyEmailNuisanceTemplate) {
f(ctx, n)
}
type PublicreportNotifyEmailNuisanceModSlice []PublicreportNotifyEmailNuisanceMod
func (mods PublicreportNotifyEmailNuisanceModSlice) Apply(ctx context.Context, n *PublicreportNotifyEmailNuisanceTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// PublicreportNotifyEmailNuisanceTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type PublicreportNotifyEmailNuisanceTemplate struct {
Created func() time.Time
Deleted func() null.Val[time.Time]
NuisanceID func() int32
EmailAddress func() string
r publicreportNotifyEmailNuisanceR
f *Factory
alreadyPersisted bool
}
type publicreportNotifyEmailNuisanceR struct {
EmailAddressEmailContact *publicreportNotifyEmailNuisanceREmailAddressEmailContactR
Nuisance *publicreportNotifyEmailNuisanceRNuisanceR
}
type publicreportNotifyEmailNuisanceREmailAddressEmailContactR struct {
o *CommsEmailContactTemplate
}
type publicreportNotifyEmailNuisanceRNuisanceR struct {
o *PublicreportNuisanceTemplate
}
// Apply mods to the PublicreportNotifyEmailNuisanceTemplate
func (o *PublicreportNotifyEmailNuisanceTemplate) Apply(ctx context.Context, mods ...PublicreportNotifyEmailNuisanceMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.PublicreportNotifyEmailNuisance
// according to the relationships in the template. Nothing is inserted into the db
func (t PublicreportNotifyEmailNuisanceTemplate) setModelRels(o *models.PublicreportNotifyEmailNuisance) {
if t.r.EmailAddressEmailContact != nil {
rel := t.r.EmailAddressEmailContact.o.Build()
rel.R.EmailAddressNotifyEmailNuisances = append(rel.R.EmailAddressNotifyEmailNuisances, o)
o.EmailAddress = rel.Address // h2
o.R.EmailAddressEmailContact = rel
}
if t.r.Nuisance != nil {
rel := t.r.Nuisance.o.Build()
rel.R.NotifyEmailNuisances = append(rel.R.NotifyEmailNuisances, o)
o.NuisanceID = rel.ID // h2
o.R.Nuisance = rel
}
}
// BuildSetter returns an *models.PublicreportNotifyEmailNuisanceSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyEmailNuisanceTemplate) BuildSetter() *models.PublicreportNotifyEmailNuisanceSetter {
m := &models.PublicreportNotifyEmailNuisanceSetter{}
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.NuisanceID != nil {
val := o.NuisanceID()
m.NuisanceID = omit.From(val)
}
if o.EmailAddress != nil {
val := o.EmailAddress()
m.EmailAddress = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.PublicreportNotifyEmailNuisanceSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyEmailNuisanceTemplate) BuildManySetter(number int) []*models.PublicreportNotifyEmailNuisanceSetter {
m := make([]*models.PublicreportNotifyEmailNuisanceSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.PublicreportNotifyEmailNuisance
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyEmailNuisanceTemplate.Create
func (o PublicreportNotifyEmailNuisanceTemplate) Build() *models.PublicreportNotifyEmailNuisance {
m := &models.PublicreportNotifyEmailNuisance{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Deleted != nil {
m.Deleted = o.Deleted()
}
if o.NuisanceID != nil {
m.NuisanceID = o.NuisanceID()
}
if o.EmailAddress != nil {
m.EmailAddress = o.EmailAddress()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.PublicreportNotifyEmailNuisanceSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyEmailNuisanceTemplate.CreateMany
func (o PublicreportNotifyEmailNuisanceTemplate) BuildMany(number int) models.PublicreportNotifyEmailNuisanceSlice {
m := make(models.PublicreportNotifyEmailNuisanceSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatablePublicreportNotifyEmailNuisance(m *models.PublicreportNotifyEmailNuisanceSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.NuisanceID.IsValue()) {
val := random_int32(nil)
m.NuisanceID = 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.PublicreportNotifyEmailNuisance
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *PublicreportNotifyEmailNuisanceTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportNotifyEmailNuisance) error {
var err error
return err
}
// Create builds a publicreportNotifyEmailNuisance and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *PublicreportNotifyEmailNuisanceTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportNotifyEmailNuisance, error) {
var err error
opt := o.BuildSetter()
ensureCreatablePublicreportNotifyEmailNuisance(opt)
if o.r.EmailAddressEmailContact == nil {
PublicreportNotifyEmailNuisanceMods.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)
if o.r.Nuisance == nil {
PublicreportNotifyEmailNuisanceMods.WithNewNuisance().Apply(ctx, o)
}
var rel1 *models.PublicreportNuisance
if o.r.Nuisance.o.alreadyPersisted {
rel1 = o.r.Nuisance.o.Build()
} else {
rel1, err = o.r.Nuisance.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.NuisanceID = omit.From(rel1.ID)
m, err := models.PublicreportNotifyEmailNuisances.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.EmailAddressEmailContact = rel0
m.R.Nuisance = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a publicreportNotifyEmailNuisance and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *PublicreportNotifyEmailNuisanceTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportNotifyEmailNuisance {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a publicreportNotifyEmailNuisance 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 *PublicreportNotifyEmailNuisanceTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportNotifyEmailNuisance {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple publicreportNotifyEmailNuisances and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o PublicreportNotifyEmailNuisanceTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportNotifyEmailNuisanceSlice, error) {
var err error
m := make(models.PublicreportNotifyEmailNuisanceSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple publicreportNotifyEmailNuisances and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o PublicreportNotifyEmailNuisanceTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportNotifyEmailNuisanceSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple publicreportNotifyEmailNuisances 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 PublicreportNotifyEmailNuisanceTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportNotifyEmailNuisanceSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// PublicreportNotifyEmailNuisance has methods that act as mods for the PublicreportNotifyEmailNuisanceTemplate
var PublicreportNotifyEmailNuisanceMods publicreportNotifyEmailNuisanceMods
type publicreportNotifyEmailNuisanceMods struct{}
func (m publicreportNotifyEmailNuisanceMods) RandomizeAllColumns(f *faker.Faker) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModSlice{
PublicreportNotifyEmailNuisanceMods.RandomCreated(f),
PublicreportNotifyEmailNuisanceMods.RandomDeleted(f),
PublicreportNotifyEmailNuisanceMods.RandomNuisanceID(f),
PublicreportNotifyEmailNuisanceMods.RandomEmailAddress(f),
}
}
// Set the model columns to this value
func (m publicreportNotifyEmailNuisanceMods) Created(val time.Time) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailNuisanceMods) CreatedFunc(f func() time.Time) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailNuisanceMods) UnsetCreated() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyEmailNuisanceMods) RandomCreated(f *faker.Faker) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyEmailNuisanceMods) Deleted(val null.Val[time.Time]) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Deleted = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailNuisanceMods) DeletedFunc(f func() null.Val[time.Time]) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Deleted = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailNuisanceMods) UnsetDeleted() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Deleted = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m publicreportNotifyEmailNuisanceMods) RandomDeleted(f *faker.Faker) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m publicreportNotifyEmailNuisanceMods) RandomDeletedNotNull(f *faker.Faker) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyEmailNuisanceMods) NuisanceID(val int32) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.NuisanceID = func() int32 { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailNuisanceMods) NuisanceIDFunc(f func() int32) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.NuisanceID = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailNuisanceMods) UnsetNuisanceID() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.NuisanceID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyEmailNuisanceMods) RandomNuisanceID(f *faker.Faker) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.NuisanceID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyEmailNuisanceMods) EmailAddress(val string) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.EmailAddress = func() string { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailNuisanceMods) EmailAddressFunc(f func() string) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.EmailAddress = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailNuisanceMods) UnsetEmailAddress() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.EmailAddress = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyEmailNuisanceMods) RandomEmailAddress(f *faker.Faker) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.EmailAddress = func() string {
return random_string(f)
}
})
}
func (m publicreportNotifyEmailNuisanceMods) WithParentsCascading() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
if isDone, _ := publicreportNotifyEmailNuisanceWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = publicreportNotifyEmailNuisanceWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewCommsEmailContactWithContext(ctx, CommsEmailContactMods.WithParentsCascading())
m.WithEmailAddressEmailContact(related).Apply(ctx, o)
}
{
related := o.f.NewPublicreportNuisanceWithContext(ctx, PublicreportNuisanceMods.WithParentsCascading())
m.WithNuisance(related).Apply(ctx, o)
}
})
}
func (m publicreportNotifyEmailNuisanceMods) WithEmailAddressEmailContact(rel *CommsEmailContactTemplate) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.r.EmailAddressEmailContact = &publicreportNotifyEmailNuisanceREmailAddressEmailContactR{
o: rel,
}
})
}
func (m publicreportNotifyEmailNuisanceMods) WithNewEmailAddressEmailContact(mods ...CommsEmailContactMod) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
related := o.f.NewCommsEmailContactWithContext(ctx, mods...)
m.WithEmailAddressEmailContact(related).Apply(ctx, o)
})
}
func (m publicreportNotifyEmailNuisanceMods) WithExistingEmailAddressEmailContact(em *models.CommsEmailContact) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.r.EmailAddressEmailContact = &publicreportNotifyEmailNuisanceREmailAddressEmailContactR{
o: o.f.FromExistingCommsEmailContact(em),
}
})
}
func (m publicreportNotifyEmailNuisanceMods) WithoutEmailAddressEmailContact() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.r.EmailAddressEmailContact = nil
})
}
func (m publicreportNotifyEmailNuisanceMods) WithNuisance(rel *PublicreportNuisanceTemplate) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.r.Nuisance = &publicreportNotifyEmailNuisanceRNuisanceR{
o: rel,
}
})
}
func (m publicreportNotifyEmailNuisanceMods) WithNewNuisance(mods ...PublicreportNuisanceMod) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
related := o.f.NewPublicreportNuisanceWithContext(ctx, mods...)
m.WithNuisance(related).Apply(ctx, o)
})
}
func (m publicreportNotifyEmailNuisanceMods) WithExistingNuisance(em *models.PublicreportNuisance) PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.r.Nuisance = &publicreportNotifyEmailNuisanceRNuisanceR{
o: o.f.FromExistingPublicreportNuisance(em),
}
})
}
func (m publicreportNotifyEmailNuisanceMods) WithoutNuisance() PublicreportNotifyEmailNuisanceMod {
return PublicreportNotifyEmailNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyEmailNuisanceTemplate) {
o.r.Nuisance = nil
})
}

View file

@ -0,0 +1,542 @@
// 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 factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type PublicreportNotifyEmailPoolMod interface {
Apply(context.Context, *PublicreportNotifyEmailPoolTemplate)
}
type PublicreportNotifyEmailPoolModFunc func(context.Context, *PublicreportNotifyEmailPoolTemplate)
func (f PublicreportNotifyEmailPoolModFunc) Apply(ctx context.Context, n *PublicreportNotifyEmailPoolTemplate) {
f(ctx, n)
}
type PublicreportNotifyEmailPoolModSlice []PublicreportNotifyEmailPoolMod
func (mods PublicreportNotifyEmailPoolModSlice) Apply(ctx context.Context, n *PublicreportNotifyEmailPoolTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// PublicreportNotifyEmailPoolTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type PublicreportNotifyEmailPoolTemplate struct {
Created func() time.Time
Deleted func() null.Val[time.Time]
PoolID func() int32
EmailAddress func() string
r publicreportNotifyEmailPoolR
f *Factory
alreadyPersisted bool
}
type publicreportNotifyEmailPoolR struct {
EmailAddressEmailContact *publicreportNotifyEmailPoolREmailAddressEmailContactR
Pool *publicreportNotifyEmailPoolRPoolR
}
type publicreportNotifyEmailPoolREmailAddressEmailContactR struct {
o *CommsEmailContactTemplate
}
type publicreportNotifyEmailPoolRPoolR struct {
o *PublicreportPoolTemplate
}
// Apply mods to the PublicreportNotifyEmailPoolTemplate
func (o *PublicreportNotifyEmailPoolTemplate) Apply(ctx context.Context, mods ...PublicreportNotifyEmailPoolMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.PublicreportNotifyEmailPool
// according to the relationships in the template. Nothing is inserted into the db
func (t PublicreportNotifyEmailPoolTemplate) setModelRels(o *models.PublicreportNotifyEmailPool) {
if t.r.EmailAddressEmailContact != nil {
rel := t.r.EmailAddressEmailContact.o.Build()
rel.R.EmailAddressNotifyEmailPools = append(rel.R.EmailAddressNotifyEmailPools, o)
o.EmailAddress = rel.Address // h2
o.R.EmailAddressEmailContact = rel
}
if t.r.Pool != nil {
rel := t.r.Pool.o.Build()
rel.R.NotifyEmailPools = append(rel.R.NotifyEmailPools, o)
o.PoolID = rel.ID // h2
o.R.Pool = rel
}
}
// BuildSetter returns an *models.PublicreportNotifyEmailPoolSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyEmailPoolTemplate) BuildSetter() *models.PublicreportNotifyEmailPoolSetter {
m := &models.PublicreportNotifyEmailPoolSetter{}
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.PoolID != nil {
val := o.PoolID()
m.PoolID = omit.From(val)
}
if o.EmailAddress != nil {
val := o.EmailAddress()
m.EmailAddress = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.PublicreportNotifyEmailPoolSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyEmailPoolTemplate) BuildManySetter(number int) []*models.PublicreportNotifyEmailPoolSetter {
m := make([]*models.PublicreportNotifyEmailPoolSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.PublicreportNotifyEmailPool
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyEmailPoolTemplate.Create
func (o PublicreportNotifyEmailPoolTemplate) Build() *models.PublicreportNotifyEmailPool {
m := &models.PublicreportNotifyEmailPool{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Deleted != nil {
m.Deleted = o.Deleted()
}
if o.PoolID != nil {
m.PoolID = o.PoolID()
}
if o.EmailAddress != nil {
m.EmailAddress = o.EmailAddress()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.PublicreportNotifyEmailPoolSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyEmailPoolTemplate.CreateMany
func (o PublicreportNotifyEmailPoolTemplate) BuildMany(number int) models.PublicreportNotifyEmailPoolSlice {
m := make(models.PublicreportNotifyEmailPoolSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatablePublicreportNotifyEmailPool(m *models.PublicreportNotifyEmailPoolSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.PoolID.IsValue()) {
val := random_int32(nil)
m.PoolID = 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.PublicreportNotifyEmailPool
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *PublicreportNotifyEmailPoolTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportNotifyEmailPool) error {
var err error
return err
}
// Create builds a publicreportNotifyEmailPool and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *PublicreportNotifyEmailPoolTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportNotifyEmailPool, error) {
var err error
opt := o.BuildSetter()
ensureCreatablePublicreportNotifyEmailPool(opt)
if o.r.EmailAddressEmailContact == nil {
PublicreportNotifyEmailPoolMods.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)
if o.r.Pool == nil {
PublicreportNotifyEmailPoolMods.WithNewPool().Apply(ctx, o)
}
var rel1 *models.PublicreportPool
if o.r.Pool.o.alreadyPersisted {
rel1 = o.r.Pool.o.Build()
} else {
rel1, err = o.r.Pool.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.PoolID = omit.From(rel1.ID)
m, err := models.PublicreportNotifyEmailPools.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.EmailAddressEmailContact = rel0
m.R.Pool = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a publicreportNotifyEmailPool and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *PublicreportNotifyEmailPoolTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportNotifyEmailPool {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a publicreportNotifyEmailPool 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 *PublicreportNotifyEmailPoolTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportNotifyEmailPool {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple publicreportNotifyEmailPools and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o PublicreportNotifyEmailPoolTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportNotifyEmailPoolSlice, error) {
var err error
m := make(models.PublicreportNotifyEmailPoolSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple publicreportNotifyEmailPools and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o PublicreportNotifyEmailPoolTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportNotifyEmailPoolSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple publicreportNotifyEmailPools 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 PublicreportNotifyEmailPoolTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportNotifyEmailPoolSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// PublicreportNotifyEmailPool has methods that act as mods for the PublicreportNotifyEmailPoolTemplate
var PublicreportNotifyEmailPoolMods publicreportNotifyEmailPoolMods
type publicreportNotifyEmailPoolMods struct{}
func (m publicreportNotifyEmailPoolMods) RandomizeAllColumns(f *faker.Faker) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModSlice{
PublicreportNotifyEmailPoolMods.RandomCreated(f),
PublicreportNotifyEmailPoolMods.RandomDeleted(f),
PublicreportNotifyEmailPoolMods.RandomPoolID(f),
PublicreportNotifyEmailPoolMods.RandomEmailAddress(f),
}
}
// Set the model columns to this value
func (m publicreportNotifyEmailPoolMods) Created(val time.Time) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailPoolMods) CreatedFunc(f func() time.Time) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailPoolMods) UnsetCreated() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyEmailPoolMods) RandomCreated(f *faker.Faker) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyEmailPoolMods) Deleted(val null.Val[time.Time]) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Deleted = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailPoolMods) DeletedFunc(f func() null.Val[time.Time]) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Deleted = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailPoolMods) UnsetDeleted() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Deleted = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m publicreportNotifyEmailPoolMods) RandomDeleted(f *faker.Faker) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m publicreportNotifyEmailPoolMods) RandomDeletedNotNull(f *faker.Faker) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyEmailPoolMods) PoolID(val int32) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.PoolID = func() int32 { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailPoolMods) PoolIDFunc(f func() int32) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.PoolID = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailPoolMods) UnsetPoolID() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.PoolID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyEmailPoolMods) RandomPoolID(f *faker.Faker) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.PoolID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyEmailPoolMods) EmailAddress(val string) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.EmailAddress = func() string { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyEmailPoolMods) EmailAddressFunc(f func() string) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.EmailAddress = f
})
}
// Clear any values for the column
func (m publicreportNotifyEmailPoolMods) UnsetEmailAddress() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.EmailAddress = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyEmailPoolMods) RandomEmailAddress(f *faker.Faker) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(_ context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.EmailAddress = func() string {
return random_string(f)
}
})
}
func (m publicreportNotifyEmailPoolMods) WithParentsCascading() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
if isDone, _ := publicreportNotifyEmailPoolWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = publicreportNotifyEmailPoolWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewCommsEmailContactWithContext(ctx, CommsEmailContactMods.WithParentsCascading())
m.WithEmailAddressEmailContact(related).Apply(ctx, o)
}
{
related := o.f.NewPublicreportPoolWithContext(ctx, PublicreportPoolMods.WithParentsCascading())
m.WithPool(related).Apply(ctx, o)
}
})
}
func (m publicreportNotifyEmailPoolMods) WithEmailAddressEmailContact(rel *CommsEmailContactTemplate) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.r.EmailAddressEmailContact = &publicreportNotifyEmailPoolREmailAddressEmailContactR{
o: rel,
}
})
}
func (m publicreportNotifyEmailPoolMods) WithNewEmailAddressEmailContact(mods ...CommsEmailContactMod) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
related := o.f.NewCommsEmailContactWithContext(ctx, mods...)
m.WithEmailAddressEmailContact(related).Apply(ctx, o)
})
}
func (m publicreportNotifyEmailPoolMods) WithExistingEmailAddressEmailContact(em *models.CommsEmailContact) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.r.EmailAddressEmailContact = &publicreportNotifyEmailPoolREmailAddressEmailContactR{
o: o.f.FromExistingCommsEmailContact(em),
}
})
}
func (m publicreportNotifyEmailPoolMods) WithoutEmailAddressEmailContact() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.r.EmailAddressEmailContact = nil
})
}
func (m publicreportNotifyEmailPoolMods) WithPool(rel *PublicreportPoolTemplate) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.r.Pool = &publicreportNotifyEmailPoolRPoolR{
o: rel,
}
})
}
func (m publicreportNotifyEmailPoolMods) WithNewPool(mods ...PublicreportPoolMod) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
m.WithPool(related).Apply(ctx, o)
})
}
func (m publicreportNotifyEmailPoolMods) WithExistingPool(em *models.PublicreportPool) PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.r.Pool = &publicreportNotifyEmailPoolRPoolR{
o: o.f.FromExistingPublicreportPool(em),
}
})
}
func (m publicreportNotifyEmailPoolMods) WithoutPool() PublicreportNotifyEmailPoolMod {
return PublicreportNotifyEmailPoolModFunc(func(ctx context.Context, o *PublicreportNotifyEmailPoolTemplate) {
o.r.Pool = nil
})
}

View file

@ -0,0 +1,542 @@
// 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 factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type PublicreportNotifyPhoneNuisanceMod interface {
Apply(context.Context, *PublicreportNotifyPhoneNuisanceTemplate)
}
type PublicreportNotifyPhoneNuisanceModFunc func(context.Context, *PublicreportNotifyPhoneNuisanceTemplate)
func (f PublicreportNotifyPhoneNuisanceModFunc) Apply(ctx context.Context, n *PublicreportNotifyPhoneNuisanceTemplate) {
f(ctx, n)
}
type PublicreportNotifyPhoneNuisanceModSlice []PublicreportNotifyPhoneNuisanceMod
func (mods PublicreportNotifyPhoneNuisanceModSlice) Apply(ctx context.Context, n *PublicreportNotifyPhoneNuisanceTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// PublicreportNotifyPhoneNuisanceTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type PublicreportNotifyPhoneNuisanceTemplate struct {
Created func() time.Time
Deleted func() null.Val[time.Time]
NuisanceID func() int32
PhoneE164 func() string
r publicreportNotifyPhoneNuisanceR
f *Factory
alreadyPersisted bool
}
type publicreportNotifyPhoneNuisanceR struct {
Nuisance *publicreportNotifyPhoneNuisanceRNuisanceR
PhoneE164Phone *publicreportNotifyPhoneNuisanceRPhoneE164PhoneR
}
type publicreportNotifyPhoneNuisanceRNuisanceR struct {
o *PublicreportNuisanceTemplate
}
type publicreportNotifyPhoneNuisanceRPhoneE164PhoneR struct {
o *CommsPhoneTemplate
}
// Apply mods to the PublicreportNotifyPhoneNuisanceTemplate
func (o *PublicreportNotifyPhoneNuisanceTemplate) Apply(ctx context.Context, mods ...PublicreportNotifyPhoneNuisanceMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.PublicreportNotifyPhoneNuisance
// according to the relationships in the template. Nothing is inserted into the db
func (t PublicreportNotifyPhoneNuisanceTemplate) setModelRels(o *models.PublicreportNotifyPhoneNuisance) {
if t.r.Nuisance != nil {
rel := t.r.Nuisance.o.Build()
rel.R.NotifyPhoneNuisances = append(rel.R.NotifyPhoneNuisances, o)
o.NuisanceID = rel.ID // h2
o.R.Nuisance = rel
}
if t.r.PhoneE164Phone != nil {
rel := t.r.PhoneE164Phone.o.Build()
rel.R.PhoneE164NotifyPhoneNuisances = append(rel.R.PhoneE164NotifyPhoneNuisances, o)
o.PhoneE164 = rel.E164 // h2
o.R.PhoneE164Phone = rel
}
}
// BuildSetter returns an *models.PublicreportNotifyPhoneNuisanceSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyPhoneNuisanceTemplate) BuildSetter() *models.PublicreportNotifyPhoneNuisanceSetter {
m := &models.PublicreportNotifyPhoneNuisanceSetter{}
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.NuisanceID != nil {
val := o.NuisanceID()
m.NuisanceID = omit.From(val)
}
if o.PhoneE164 != nil {
val := o.PhoneE164()
m.PhoneE164 = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.PublicreportNotifyPhoneNuisanceSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyPhoneNuisanceTemplate) BuildManySetter(number int) []*models.PublicreportNotifyPhoneNuisanceSetter {
m := make([]*models.PublicreportNotifyPhoneNuisanceSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.PublicreportNotifyPhoneNuisance
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyPhoneNuisanceTemplate.Create
func (o PublicreportNotifyPhoneNuisanceTemplate) Build() *models.PublicreportNotifyPhoneNuisance {
m := &models.PublicreportNotifyPhoneNuisance{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Deleted != nil {
m.Deleted = o.Deleted()
}
if o.NuisanceID != nil {
m.NuisanceID = o.NuisanceID()
}
if o.PhoneE164 != nil {
m.PhoneE164 = o.PhoneE164()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.PublicreportNotifyPhoneNuisanceSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyPhoneNuisanceTemplate.CreateMany
func (o PublicreportNotifyPhoneNuisanceTemplate) BuildMany(number int) models.PublicreportNotifyPhoneNuisanceSlice {
m := make(models.PublicreportNotifyPhoneNuisanceSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatablePublicreportNotifyPhoneNuisance(m *models.PublicreportNotifyPhoneNuisanceSetter) {
if !(m.Created.IsValue()) {
val := random_time_Time(nil)
m.Created = omit.From(val)
}
if !(m.NuisanceID.IsValue()) {
val := random_int32(nil)
m.NuisanceID = 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.PublicreportNotifyPhoneNuisance
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *PublicreportNotifyPhoneNuisanceTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportNotifyPhoneNuisance) error {
var err error
return err
}
// Create builds a publicreportNotifyPhoneNuisance and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *PublicreportNotifyPhoneNuisanceTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportNotifyPhoneNuisance, error) {
var err error
opt := o.BuildSetter()
ensureCreatablePublicreportNotifyPhoneNuisance(opt)
if o.r.Nuisance == nil {
PublicreportNotifyPhoneNuisanceMods.WithNewNuisance().Apply(ctx, o)
}
var rel0 *models.PublicreportNuisance
if o.r.Nuisance.o.alreadyPersisted {
rel0 = o.r.Nuisance.o.Build()
} else {
rel0, err = o.r.Nuisance.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.NuisanceID = omit.From(rel0.ID)
if o.r.PhoneE164Phone == nil {
PublicreportNotifyPhoneNuisanceMods.WithNewPhoneE164Phone().Apply(ctx, o)
}
var rel1 *models.CommsPhone
if o.r.PhoneE164Phone.o.alreadyPersisted {
rel1 = o.r.PhoneE164Phone.o.Build()
} else {
rel1, err = o.r.PhoneE164Phone.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.PhoneE164 = omit.From(rel1.E164)
m, err := models.PublicreportNotifyPhoneNuisances.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.Nuisance = rel0
m.R.PhoneE164Phone = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a publicreportNotifyPhoneNuisance and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *PublicreportNotifyPhoneNuisanceTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportNotifyPhoneNuisance {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a publicreportNotifyPhoneNuisance 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 *PublicreportNotifyPhoneNuisanceTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportNotifyPhoneNuisance {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple publicreportNotifyPhoneNuisances and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o PublicreportNotifyPhoneNuisanceTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportNotifyPhoneNuisanceSlice, error) {
var err error
m := make(models.PublicreportNotifyPhoneNuisanceSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple publicreportNotifyPhoneNuisances and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o PublicreportNotifyPhoneNuisanceTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportNotifyPhoneNuisanceSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple publicreportNotifyPhoneNuisances 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 PublicreportNotifyPhoneNuisanceTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportNotifyPhoneNuisanceSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// PublicreportNotifyPhoneNuisance has methods that act as mods for the PublicreportNotifyPhoneNuisanceTemplate
var PublicreportNotifyPhoneNuisanceMods publicreportNotifyPhoneNuisanceMods
type publicreportNotifyPhoneNuisanceMods struct{}
func (m publicreportNotifyPhoneNuisanceMods) RandomizeAllColumns(f *faker.Faker) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModSlice{
PublicreportNotifyPhoneNuisanceMods.RandomCreated(f),
PublicreportNotifyPhoneNuisanceMods.RandomDeleted(f),
PublicreportNotifyPhoneNuisanceMods.RandomNuisanceID(f),
PublicreportNotifyPhoneNuisanceMods.RandomPhoneE164(f),
}
}
// Set the model columns to this value
func (m publicreportNotifyPhoneNuisanceMods) Created(val time.Time) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhoneNuisanceMods) CreatedFunc(f func() time.Time) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhoneNuisanceMods) UnsetCreated() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyPhoneNuisanceMods) RandomCreated(f *faker.Faker) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyPhoneNuisanceMods) Deleted(val null.Val[time.Time]) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Deleted = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhoneNuisanceMods) DeletedFunc(f func() null.Val[time.Time]) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Deleted = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhoneNuisanceMods) UnsetDeleted() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Deleted = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m publicreportNotifyPhoneNuisanceMods) RandomDeleted(f *faker.Faker) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m publicreportNotifyPhoneNuisanceMods) RandomDeletedNotNull(f *faker.Faker) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyPhoneNuisanceMods) NuisanceID(val int32) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.NuisanceID = func() int32 { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhoneNuisanceMods) NuisanceIDFunc(f func() int32) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.NuisanceID = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhoneNuisanceMods) UnsetNuisanceID() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.NuisanceID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyPhoneNuisanceMods) RandomNuisanceID(f *faker.Faker) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.NuisanceID = func() int32 {
return random_int32(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyPhoneNuisanceMods) PhoneE164(val string) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.PhoneE164 = func() string { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhoneNuisanceMods) PhoneE164Func(f func() string) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.PhoneE164 = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhoneNuisanceMods) UnsetPhoneE164() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.PhoneE164 = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyPhoneNuisanceMods) RandomPhoneE164(f *faker.Faker) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(_ context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.PhoneE164 = func() string {
return random_string(f)
}
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithParentsCascading() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
if isDone, _ := publicreportNotifyPhoneNuisanceWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = publicreportNotifyPhoneNuisanceWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewPublicreportNuisanceWithContext(ctx, PublicreportNuisanceMods.WithParentsCascading())
m.WithNuisance(related).Apply(ctx, o)
}
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithPhoneE164Phone(related).Apply(ctx, o)
}
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithNuisance(rel *PublicreportNuisanceTemplate) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.r.Nuisance = &publicreportNotifyPhoneNuisanceRNuisanceR{
o: rel,
}
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithNewNuisance(mods ...PublicreportNuisanceMod) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
related := o.f.NewPublicreportNuisanceWithContext(ctx, mods...)
m.WithNuisance(related).Apply(ctx, o)
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithExistingNuisance(em *models.PublicreportNuisance) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.r.Nuisance = &publicreportNotifyPhoneNuisanceRNuisanceR{
o: o.f.FromExistingPublicreportNuisance(em),
}
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithoutNuisance() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.r.Nuisance = nil
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithPhoneE164Phone(rel *CommsPhoneTemplate) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.r.PhoneE164Phone = &publicreportNotifyPhoneNuisanceRPhoneE164PhoneR{
o: rel,
}
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithNewPhoneE164Phone(mods ...CommsPhoneMod) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithPhoneE164Phone(related).Apply(ctx, o)
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithExistingPhoneE164Phone(em *models.CommsPhone) PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.r.PhoneE164Phone = &publicreportNotifyPhoneNuisanceRPhoneE164PhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m publicreportNotifyPhoneNuisanceMods) WithoutPhoneE164Phone() PublicreportNotifyPhoneNuisanceMod {
return PublicreportNotifyPhoneNuisanceModFunc(func(ctx context.Context, o *PublicreportNotifyPhoneNuisanceTemplate) {
o.r.PhoneE164Phone = nil
})
}

View file

@ -0,0 +1,542 @@
// 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 factory
import (
"context"
"testing"
"time"
"github.com/Gleipnir-Technology/bob"
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/jaswdr/faker/v2"
)
type PublicreportNotifyPhonePoolMod interface {
Apply(context.Context, *PublicreportNotifyPhonePoolTemplate)
}
type PublicreportNotifyPhonePoolModFunc func(context.Context, *PublicreportNotifyPhonePoolTemplate)
func (f PublicreportNotifyPhonePoolModFunc) Apply(ctx context.Context, n *PublicreportNotifyPhonePoolTemplate) {
f(ctx, n)
}
type PublicreportNotifyPhonePoolModSlice []PublicreportNotifyPhonePoolMod
func (mods PublicreportNotifyPhonePoolModSlice) Apply(ctx context.Context, n *PublicreportNotifyPhonePoolTemplate) {
for _, f := range mods {
f.Apply(ctx, n)
}
}
// PublicreportNotifyPhonePoolTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type PublicreportNotifyPhonePoolTemplate struct {
Created func() time.Time
Deleted func() null.Val[time.Time]
PhoneE164 func() string
PoolID func() int32
r publicreportNotifyPhonePoolR
f *Factory
alreadyPersisted bool
}
type publicreportNotifyPhonePoolR struct {
PhoneE164Phone *publicreportNotifyPhonePoolRPhoneE164PhoneR
Pool *publicreportNotifyPhonePoolRPoolR
}
type publicreportNotifyPhonePoolRPhoneE164PhoneR struct {
o *CommsPhoneTemplate
}
type publicreportNotifyPhonePoolRPoolR struct {
o *PublicreportPoolTemplate
}
// Apply mods to the PublicreportNotifyPhonePoolTemplate
func (o *PublicreportNotifyPhonePoolTemplate) Apply(ctx context.Context, mods ...PublicreportNotifyPhonePoolMod) {
for _, mod := range mods {
mod.Apply(ctx, o)
}
}
// setModelRels creates and sets the relationships on *models.PublicreportNotifyPhonePool
// according to the relationships in the template. Nothing is inserted into the db
func (t PublicreportNotifyPhonePoolTemplate) setModelRels(o *models.PublicreportNotifyPhonePool) {
if t.r.PhoneE164Phone != nil {
rel := t.r.PhoneE164Phone.o.Build()
rel.R.PhoneE164NotifyPhonePools = append(rel.R.PhoneE164NotifyPhonePools, o)
o.PhoneE164 = rel.E164 // h2
o.R.PhoneE164Phone = rel
}
if t.r.Pool != nil {
rel := t.r.Pool.o.Build()
rel.R.NotifyPhonePools = append(rel.R.NotifyPhonePools, o)
o.PoolID = rel.ID // h2
o.R.Pool = rel
}
}
// BuildSetter returns an *models.PublicreportNotifyPhonePoolSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyPhonePoolTemplate) BuildSetter() *models.PublicreportNotifyPhonePoolSetter {
m := &models.PublicreportNotifyPhonePoolSetter{}
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.PhoneE164 != nil {
val := o.PhoneE164()
m.PhoneE164 = omit.From(val)
}
if o.PoolID != nil {
val := o.PoolID()
m.PoolID = omit.From(val)
}
return m
}
// BuildManySetter returns an []*models.PublicreportNotifyPhonePoolSetter
// this does nothing with the relationship templates
func (o PublicreportNotifyPhonePoolTemplate) BuildManySetter(number int) []*models.PublicreportNotifyPhonePoolSetter {
m := make([]*models.PublicreportNotifyPhonePoolSetter, number)
for i := range m {
m[i] = o.BuildSetter()
}
return m
}
// Build returns an *models.PublicreportNotifyPhonePool
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyPhonePoolTemplate.Create
func (o PublicreportNotifyPhonePoolTemplate) Build() *models.PublicreportNotifyPhonePool {
m := &models.PublicreportNotifyPhonePool{}
if o.Created != nil {
m.Created = o.Created()
}
if o.Deleted != nil {
m.Deleted = o.Deleted()
}
if o.PhoneE164 != nil {
m.PhoneE164 = o.PhoneE164()
}
if o.PoolID != nil {
m.PoolID = o.PoolID()
}
o.setModelRels(m)
return m
}
// BuildMany returns an models.PublicreportNotifyPhonePoolSlice
// Related objects are also created and placed in the .R field
// NOTE: Objects are not inserted into the database. Use PublicreportNotifyPhonePoolTemplate.CreateMany
func (o PublicreportNotifyPhonePoolTemplate) BuildMany(number int) models.PublicreportNotifyPhonePoolSlice {
m := make(models.PublicreportNotifyPhonePoolSlice, number)
for i := range m {
m[i] = o.Build()
}
return m
}
func ensureCreatablePublicreportNotifyPhonePool(m *models.PublicreportNotifyPhonePoolSetter) {
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)
}
if !(m.PoolID.IsValue()) {
val := random_int32(nil)
m.PoolID = omit.From(val)
}
}
// insertOptRels creates and inserts any optional the relationships on *models.PublicreportNotifyPhonePool
// according to the relationships in the template.
// any required relationship should have already exist on the model
func (o *PublicreportNotifyPhonePoolTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportNotifyPhonePool) error {
var err error
return err
}
// Create builds a publicreportNotifyPhonePool and inserts it into the database
// Relations objects are also inserted and placed in the .R field
func (o *PublicreportNotifyPhonePoolTemplate) Create(ctx context.Context, exec bob.Executor) (*models.PublicreportNotifyPhonePool, error) {
var err error
opt := o.BuildSetter()
ensureCreatablePublicreportNotifyPhonePool(opt)
if o.r.PhoneE164Phone == nil {
PublicreportNotifyPhonePoolMods.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)
if o.r.Pool == nil {
PublicreportNotifyPhonePoolMods.WithNewPool().Apply(ctx, o)
}
var rel1 *models.PublicreportPool
if o.r.Pool.o.alreadyPersisted {
rel1 = o.r.Pool.o.Build()
} else {
rel1, err = o.r.Pool.o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
opt.PoolID = omit.From(rel1.ID)
m, err := models.PublicreportNotifyPhonePools.Insert(opt).One(ctx, exec)
if err != nil {
return nil, err
}
m.R.PhoneE164Phone = rel0
m.R.Pool = rel1
if err := o.insertOptRels(ctx, exec, m); err != nil {
return nil, err
}
return m, err
}
// MustCreate builds a publicreportNotifyPhonePool and inserts it into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o *PublicreportNotifyPhonePoolTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.PublicreportNotifyPhonePool {
m, err := o.Create(ctx, exec)
if err != nil {
panic(err)
}
return m
}
// CreateOrFail builds a publicreportNotifyPhonePool 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 *PublicreportNotifyPhonePoolTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.PublicreportNotifyPhonePool {
tb.Helper()
m, err := o.Create(ctx, exec)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// CreateMany builds multiple publicreportNotifyPhonePools and inserts them into the database
// Relations objects are also inserted and placed in the .R field
func (o PublicreportNotifyPhonePoolTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PublicreportNotifyPhonePoolSlice, error) {
var err error
m := make(models.PublicreportNotifyPhonePoolSlice, number)
for i := range m {
m[i], err = o.Create(ctx, exec)
if err != nil {
return nil, err
}
}
return m, nil
}
// MustCreateMany builds multiple publicreportNotifyPhonePools and inserts them into the database
// Relations objects are also inserted and placed in the .R field
// panics if an error occurs
func (o PublicreportNotifyPhonePoolTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PublicreportNotifyPhonePoolSlice {
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
panic(err)
}
return m
}
// CreateManyOrFail builds multiple publicreportNotifyPhonePools 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 PublicreportNotifyPhonePoolTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PublicreportNotifyPhonePoolSlice {
tb.Helper()
m, err := o.CreateMany(ctx, exec, number)
if err != nil {
tb.Fatal(err)
return nil
}
return m
}
// PublicreportNotifyPhonePool has methods that act as mods for the PublicreportNotifyPhonePoolTemplate
var PublicreportNotifyPhonePoolMods publicreportNotifyPhonePoolMods
type publicreportNotifyPhonePoolMods struct{}
func (m publicreportNotifyPhonePoolMods) RandomizeAllColumns(f *faker.Faker) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModSlice{
PublicreportNotifyPhonePoolMods.RandomCreated(f),
PublicreportNotifyPhonePoolMods.RandomDeleted(f),
PublicreportNotifyPhonePoolMods.RandomPhoneE164(f),
PublicreportNotifyPhonePoolMods.RandomPoolID(f),
}
}
// Set the model columns to this value
func (m publicreportNotifyPhonePoolMods) Created(val time.Time) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Created = func() time.Time { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhonePoolMods) CreatedFunc(f func() time.Time) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Created = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhonePoolMods) UnsetCreated() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Created = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyPhonePoolMods) RandomCreated(f *faker.Faker) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Created = func() time.Time {
return random_time_Time(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyPhonePoolMods) Deleted(val null.Val[time.Time]) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Deleted = func() null.Val[time.Time] { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhonePoolMods) DeletedFunc(f func() null.Val[time.Time]) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Deleted = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhonePoolMods) UnsetDeleted() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Deleted = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m publicreportNotifyPhonePoolMods) RandomDeleted(f *faker.Faker) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m publicreportNotifyPhonePoolMods) RandomDeletedNotNull(f *faker.Faker) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.Deleted = func() null.Val[time.Time] {
if f == nil {
f = &defaultFaker
}
val := random_time_Time(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyPhonePoolMods) PhoneE164(val string) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PhoneE164 = func() string { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhonePoolMods) PhoneE164Func(f func() string) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PhoneE164 = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhonePoolMods) UnsetPhoneE164() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PhoneE164 = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyPhonePoolMods) RandomPhoneE164(f *faker.Faker) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PhoneE164 = func() string {
return random_string(f)
}
})
}
// Set the model columns to this value
func (m publicreportNotifyPhonePoolMods) PoolID(val int32) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PoolID = func() int32 { return val }
})
}
// Set the Column from the function
func (m publicreportNotifyPhonePoolMods) PoolIDFunc(f func() int32) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PoolID = f
})
}
// Clear any values for the column
func (m publicreportNotifyPhonePoolMods) UnsetPoolID() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PoolID = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
func (m publicreportNotifyPhonePoolMods) RandomPoolID(f *faker.Faker) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(_ context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.PoolID = func() int32 {
return random_int32(f)
}
})
}
func (m publicreportNotifyPhonePoolMods) WithParentsCascading() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
if isDone, _ := publicreportNotifyPhonePoolWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = publicreportNotifyPhonePoolWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewCommsPhoneWithContext(ctx, CommsPhoneMods.WithParentsCascading())
m.WithPhoneE164Phone(related).Apply(ctx, o)
}
{
related := o.f.NewPublicreportPoolWithContext(ctx, PublicreportPoolMods.WithParentsCascading())
m.WithPool(related).Apply(ctx, o)
}
})
}
func (m publicreportNotifyPhonePoolMods) WithPhoneE164Phone(rel *CommsPhoneTemplate) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.r.PhoneE164Phone = &publicreportNotifyPhonePoolRPhoneE164PhoneR{
o: rel,
}
})
}
func (m publicreportNotifyPhonePoolMods) WithNewPhoneE164Phone(mods ...CommsPhoneMod) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
related := o.f.NewCommsPhoneWithContext(ctx, mods...)
m.WithPhoneE164Phone(related).Apply(ctx, o)
})
}
func (m publicreportNotifyPhonePoolMods) WithExistingPhoneE164Phone(em *models.CommsPhone) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.r.PhoneE164Phone = &publicreportNotifyPhonePoolRPhoneE164PhoneR{
o: o.f.FromExistingCommsPhone(em),
}
})
}
func (m publicreportNotifyPhonePoolMods) WithoutPhoneE164Phone() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.r.PhoneE164Phone = nil
})
}
func (m publicreportNotifyPhonePoolMods) WithPool(rel *PublicreportPoolTemplate) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.r.Pool = &publicreportNotifyPhonePoolRPoolR{
o: rel,
}
})
}
func (m publicreportNotifyPhonePoolMods) WithNewPool(mods ...PublicreportPoolMod) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
related := o.f.NewPublicreportPoolWithContext(ctx, mods...)
m.WithPool(related).Apply(ctx, o)
})
}
func (m publicreportNotifyPhonePoolMods) WithExistingPool(em *models.PublicreportPool) PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.r.Pool = &publicreportNotifyPhonePoolRPoolR{
o: o.f.FromExistingPublicreportPool(em),
}
})
}
func (m publicreportNotifyPhonePoolMods) WithoutPool() PublicreportNotifyPhonePoolMod {
return PublicreportNotifyPhonePoolModFunc(func(ctx context.Context, o *PublicreportNotifyPhonePoolTemplate) {
o.r.Pool = nil
})
}

View file

@ -38,40 +38,41 @@ func (mods PublicreportNuisanceModSlice) Apply(ctx context.Context, n *Publicrep
// PublicreportNuisanceTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type PublicreportNuisanceTemplate struct {
ID func() int32
AdditionalInfo func() string
Created func() time.Time
Duration func() enums.PublicreportNuisancedurationtype
SourceContainer func() bool
SourceDescription func() string
SourceStagnant func() bool
PublicID func() string
ReporterEmail func() null.Val[string]
ReporterName func() null.Val[string]
ReporterPhone func() null.Val[string]
Address func() string
Location func() null.Val[string]
Status func() enums.PublicreportReportstatustype
OrganizationID func() null.Val[int32]
SourceGutter func() bool
H3cell func() null.Val[string]
AddressCountry func() string
AddressPlace func() string
AddressPostcode func() string
AddressRegion func() string
AddressStreet func() string
IsLocationBackyard func() bool
IsLocationFrontyard func() bool
IsLocationGarden func() bool
IsLocationOther func() bool
IsLocationPool func() bool
MapZoom func() float32
TodEarly func() bool
TodDay func() bool
TodEvening func() bool
TodNight func() bool
LatlngAccuracyType func() enums.PublicreportAccuracytype
LatlngAccuracyValue func() float32
ID func() int32
AdditionalInfo func() string
Created func() time.Time
Duration func() enums.PublicreportNuisancedurationtype
SourceContainer func() bool
SourceDescription func() string
SourceStagnant func() bool
PublicID func() string
ReporterEmail func() null.Val[string]
ReporterName func() null.Val[string]
ReporterPhone func() null.Val[string]
Address func() string
Location func() null.Val[string]
Status func() enums.PublicreportReportstatustype
OrganizationID func() null.Val[int32]
SourceGutter func() bool
H3cell func() null.Val[string]
AddressCountry func() string
AddressPlace func() string
AddressPostcode func() string
AddressRegion func() string
AddressStreet func() string
IsLocationBackyard func() bool
IsLocationFrontyard func() bool
IsLocationGarden func() bool
IsLocationOther func() bool
IsLocationPool func() bool
MapZoom func() float32
TodEarly func() bool
TodDay func() bool
TodEvening func() bool
TodNight func() bool
LatlngAccuracyType func() enums.PublicreportAccuracytype
LatlngAccuracyValue func() float32
ReporterContactConsent func() null.Val[bool]
r publicreportNuisanceR
f *Factory
@ -80,10 +81,20 @@ type PublicreportNuisanceTemplate struct {
}
type publicreportNuisanceR struct {
Organization *publicreportNuisanceROrganizationR
Images []*publicreportNuisanceRImagesR
NotifyEmailNuisances []*publicreportNuisanceRNotifyEmailNuisancesR
NotifyPhoneNuisances []*publicreportNuisanceRNotifyPhoneNuisancesR
Organization *publicreportNuisanceROrganizationR
Images []*publicreportNuisanceRImagesR
}
type publicreportNuisanceRNotifyEmailNuisancesR struct {
number int
o *PublicreportNotifyEmailNuisanceTemplate
}
type publicreportNuisanceRNotifyPhoneNuisancesR struct {
number int
o *PublicreportNotifyPhoneNuisanceTemplate
}
type publicreportNuisanceROrganizationR struct {
o *OrganizationTemplate
}
@ -102,6 +113,32 @@ func (o *PublicreportNuisanceTemplate) Apply(ctx context.Context, mods ...Public
// setModelRels creates and sets the relationships on *models.PublicreportNuisance
// according to the relationships in the template. Nothing is inserted into the db
func (t PublicreportNuisanceTemplate) setModelRels(o *models.PublicreportNuisance) {
if t.r.NotifyEmailNuisances != nil {
rel := models.PublicreportNotifyEmailNuisanceSlice{}
for _, r := range t.r.NotifyEmailNuisances {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.NuisanceID = o.ID // h2
rel.R.Nuisance = o
}
rel = append(rel, related...)
}
o.R.NotifyEmailNuisances = rel
}
if t.r.NotifyPhoneNuisances != nil {
rel := models.PublicreportNotifyPhoneNuisanceSlice{}
for _, r := range t.r.NotifyPhoneNuisances {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.NuisanceID = o.ID // h2
rel.R.Nuisance = o
}
rel = append(rel, related...)
}
o.R.NotifyPhoneNuisances = rel
}
if t.r.Organization != nil {
rel := t.r.Organization.o.Build()
rel.R.Nuisances = append(rel.R.Nuisances, o)
@ -263,6 +300,10 @@ func (o PublicreportNuisanceTemplate) BuildSetter() *models.PublicreportNuisance
val := o.LatlngAccuracyValue()
m.LatlngAccuracyValue = omit.From(val)
}
if o.ReporterContactConsent != nil {
val := o.ReporterContactConsent()
m.ReporterContactConsent = omitnull.FromNull(val)
}
return m
}
@ -387,6 +428,9 @@ func (o PublicreportNuisanceTemplate) Build() *models.PublicreportNuisance {
if o.LatlngAccuracyValue != nil {
m.LatlngAccuracyValue = o.LatlngAccuracyValue()
}
if o.ReporterContactConsent != nil {
m.ReporterContactConsent = o.ReporterContactConsent()
}
o.setModelRels(m)
@ -523,18 +567,58 @@ func ensureCreatablePublicreportNuisance(m *models.PublicreportNuisanceSetter) {
func (o *PublicreportNuisanceTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportNuisance) error {
var err error
isNotifyEmailNuisancesDone, _ := publicreportNuisanceRelNotifyEmailNuisancesCtx.Value(ctx)
if !isNotifyEmailNuisancesDone && o.r.NotifyEmailNuisances != nil {
ctx = publicreportNuisanceRelNotifyEmailNuisancesCtx.WithValue(ctx, true)
for _, r := range o.r.NotifyEmailNuisances {
if r.o.alreadyPersisted {
m.R.NotifyEmailNuisances = append(m.R.NotifyEmailNuisances, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachNotifyEmailNuisances(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isNotifyPhoneNuisancesDone, _ := publicreportNuisanceRelNotifyPhoneNuisancesCtx.Value(ctx)
if !isNotifyPhoneNuisancesDone && o.r.NotifyPhoneNuisances != nil {
ctx = publicreportNuisanceRelNotifyPhoneNuisancesCtx.WithValue(ctx, true)
for _, r := range o.r.NotifyPhoneNuisances {
if r.o.alreadyPersisted {
m.R.NotifyPhoneNuisances = append(m.R.NotifyPhoneNuisances, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachNotifyPhoneNuisances(ctx, exec, rel1...)
if err != nil {
return err
}
}
}
}
isOrganizationDone, _ := publicreportNuisanceRelOrganizationCtx.Value(ctx)
if !isOrganizationDone && o.r.Organization != nil {
ctx = publicreportNuisanceRelOrganizationCtx.WithValue(ctx, true)
if o.r.Organization.o.alreadyPersisted {
m.R.Organization = o.r.Organization.o.Build()
} else {
var rel0 *models.Organization
rel0, err = o.r.Organization.o.Create(ctx, exec)
var rel2 *models.Organization
rel2, err = o.r.Organization.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachOrganization(ctx, exec, rel0)
err = m.AttachOrganization(ctx, exec, rel2)
if err != nil {
return err
}
@ -549,12 +633,12 @@ func (o *PublicreportNuisanceTemplate) insertOptRels(ctx context.Context, exec b
if r.o.alreadyPersisted {
m.R.Images = append(m.R.Images, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
rel3, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachImages(ctx, exec, rel1...)
err = m.AttachImages(ctx, exec, rel3...)
if err != nil {
return err
}
@ -688,6 +772,7 @@ func (m publicreportNuisanceMods) RandomizeAllColumns(f *faker.Faker) Publicrepo
PublicreportNuisanceMods.RandomTodNight(f),
PublicreportNuisanceMods.RandomLatlngAccuracyType(f),
PublicreportNuisanceMods.RandomLatlngAccuracyValue(f),
PublicreportNuisanceMods.RandomReporterContactConsent(f),
}
}
@ -1877,6 +1962,59 @@ func (m publicreportNuisanceMods) RandomLatlngAccuracyValue(f *faker.Faker) Publ
})
}
// Set the model columns to this value
func (m publicreportNuisanceMods) ReporterContactConsent(val null.Val[bool]) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(_ context.Context, o *PublicreportNuisanceTemplate) {
o.ReporterContactConsent = func() null.Val[bool] { return val }
})
}
// Set the Column from the function
func (m publicreportNuisanceMods) ReporterContactConsentFunc(f func() null.Val[bool]) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(_ context.Context, o *PublicreportNuisanceTemplate) {
o.ReporterContactConsent = f
})
}
// Clear any values for the column
func (m publicreportNuisanceMods) UnsetReporterContactConsent() PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(_ context.Context, o *PublicreportNuisanceTemplate) {
o.ReporterContactConsent = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m publicreportNuisanceMods) RandomReporterContactConsent(f *faker.Faker) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(_ context.Context, o *PublicreportNuisanceTemplate) {
o.ReporterContactConsent = func() null.Val[bool] {
if f == nil {
f = &defaultFaker
}
val := random_bool(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m publicreportNuisanceMods) RandomReporterContactConsentNotNull(f *faker.Faker) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(_ context.Context, o *PublicreportNuisanceTemplate) {
o.ReporterContactConsent = func() null.Val[bool] {
if f == nil {
f = &defaultFaker
}
val := random_bool(f)
return null.From(val)
}
})
}
func (m publicreportNuisanceMods) WithParentsCascading() PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
if isDone, _ := publicreportNuisanceWithParentsCascadingCtx.Value(ctx); isDone {
@ -1921,6 +2059,102 @@ func (m publicreportNuisanceMods) WithoutOrganization() PublicreportNuisanceMod
})
}
func (m publicreportNuisanceMods) WithNotifyEmailNuisances(number int, related *PublicreportNotifyEmailNuisanceTemplate) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.NotifyEmailNuisances = []*publicreportNuisanceRNotifyEmailNuisancesR{{
number: number,
o: related,
}}
})
}
func (m publicreportNuisanceMods) WithNewNotifyEmailNuisances(number int, mods ...PublicreportNotifyEmailNuisanceMod) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
related := o.f.NewPublicreportNotifyEmailNuisanceWithContext(ctx, mods...)
m.WithNotifyEmailNuisances(number, related).Apply(ctx, o)
})
}
func (m publicreportNuisanceMods) AddNotifyEmailNuisances(number int, related *PublicreportNotifyEmailNuisanceTemplate) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.NotifyEmailNuisances = append(o.r.NotifyEmailNuisances, &publicreportNuisanceRNotifyEmailNuisancesR{
number: number,
o: related,
})
})
}
func (m publicreportNuisanceMods) AddNewNotifyEmailNuisances(number int, mods ...PublicreportNotifyEmailNuisanceMod) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
related := o.f.NewPublicreportNotifyEmailNuisanceWithContext(ctx, mods...)
m.AddNotifyEmailNuisances(number, related).Apply(ctx, o)
})
}
func (m publicreportNuisanceMods) AddExistingNotifyEmailNuisances(existingModels ...*models.PublicreportNotifyEmailNuisance) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
for _, em := range existingModels {
o.r.NotifyEmailNuisances = append(o.r.NotifyEmailNuisances, &publicreportNuisanceRNotifyEmailNuisancesR{
o: o.f.FromExistingPublicreportNotifyEmailNuisance(em),
})
}
})
}
func (m publicreportNuisanceMods) WithoutNotifyEmailNuisances() PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.NotifyEmailNuisances = nil
})
}
func (m publicreportNuisanceMods) WithNotifyPhoneNuisances(number int, related *PublicreportNotifyPhoneNuisanceTemplate) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.NotifyPhoneNuisances = []*publicreportNuisanceRNotifyPhoneNuisancesR{{
number: number,
o: related,
}}
})
}
func (m publicreportNuisanceMods) WithNewNotifyPhoneNuisances(number int, mods ...PublicreportNotifyPhoneNuisanceMod) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
related := o.f.NewPublicreportNotifyPhoneNuisanceWithContext(ctx, mods...)
m.WithNotifyPhoneNuisances(number, related).Apply(ctx, o)
})
}
func (m publicreportNuisanceMods) AddNotifyPhoneNuisances(number int, related *PublicreportNotifyPhoneNuisanceTemplate) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.NotifyPhoneNuisances = append(o.r.NotifyPhoneNuisances, &publicreportNuisanceRNotifyPhoneNuisancesR{
number: number,
o: related,
})
})
}
func (m publicreportNuisanceMods) AddNewNotifyPhoneNuisances(number int, mods ...PublicreportNotifyPhoneNuisanceMod) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
related := o.f.NewPublicreportNotifyPhoneNuisanceWithContext(ctx, mods...)
m.AddNotifyPhoneNuisances(number, related).Apply(ctx, o)
})
}
func (m publicreportNuisanceMods) AddExistingNotifyPhoneNuisances(existingModels ...*models.PublicreportNotifyPhoneNuisance) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
for _, em := range existingModels {
o.r.NotifyPhoneNuisances = append(o.r.NotifyPhoneNuisances, &publicreportNuisanceRNotifyPhoneNuisancesR{
o: o.f.FromExistingPublicreportNotifyPhoneNuisance(em),
})
}
})
}
func (m publicreportNuisanceMods) WithoutNotifyPhoneNuisances() PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.NotifyPhoneNuisances = nil
})
}
func (m publicreportNuisanceMods) WithImages(number int, related *PublicreportImageTemplate) PublicreportNuisanceMod {
return PublicreportNuisanceModFunc(func(ctx context.Context, o *PublicreportNuisanceTemplate) {
o.r.Images = []*publicreportNuisanceRImagesR{{

View file

@ -71,6 +71,7 @@ type PublicreportPoolTemplate struct {
HasBackyardPermission func() bool
IsReporterConfidential func() bool
IsReporterOwner func() bool
ReporterContactConsent func() null.Val[bool]
r publicreportPoolR
f *Factory
@ -79,10 +80,20 @@ type PublicreportPoolTemplate struct {
}
type publicreportPoolR struct {
Organization *publicreportPoolROrganizationR
Images []*publicreportPoolRImagesR
NotifyEmailPools []*publicreportPoolRNotifyEmailPoolsR
NotifyPhonePools []*publicreportPoolRNotifyPhonePoolsR
Organization *publicreportPoolROrganizationR
Images []*publicreportPoolRImagesR
}
type publicreportPoolRNotifyEmailPoolsR struct {
number int
o *PublicreportNotifyEmailPoolTemplate
}
type publicreportPoolRNotifyPhonePoolsR struct {
number int
o *PublicreportNotifyPhonePoolTemplate
}
type publicreportPoolROrganizationR struct {
o *OrganizationTemplate
}
@ -101,6 +112,32 @@ func (o *PublicreportPoolTemplate) Apply(ctx context.Context, mods ...Publicrepo
// setModelRels creates and sets the relationships on *models.PublicreportPool
// according to the relationships in the template. Nothing is inserted into the db
func (t PublicreportPoolTemplate) setModelRels(o *models.PublicreportPool) {
if t.r.NotifyEmailPools != nil {
rel := models.PublicreportNotifyEmailPoolSlice{}
for _, r := range t.r.NotifyEmailPools {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.PoolID = o.ID // h2
rel.R.Pool = o
}
rel = append(rel, related...)
}
o.R.NotifyEmailPools = rel
}
if t.r.NotifyPhonePools != nil {
rel := models.PublicreportNotifyPhonePoolSlice{}
for _, r := range t.r.NotifyPhonePools {
related := r.o.BuildMany(r.number)
for _, rel := range related {
rel.PoolID = o.ID // h2
rel.R.Pool = o
}
rel = append(rel, related...)
}
o.R.NotifyPhonePools = rel
}
if t.r.Organization != nil {
rel := t.r.Organization.o.Build()
rel.R.PublicreportPool = append(rel.R.PublicreportPool, o)
@ -258,6 +295,10 @@ func (o PublicreportPoolTemplate) BuildSetter() *models.PublicreportPoolSetter {
val := o.IsReporterOwner()
m.IsReporterOwner = omit.From(val)
}
if o.ReporterContactConsent != nil {
val := o.ReporterContactConsent()
m.ReporterContactConsent = omitnull.FromNull(val)
}
return m
}
@ -379,6 +420,9 @@ func (o PublicreportPoolTemplate) Build() *models.PublicreportPool {
if o.IsReporterOwner != nil {
m.IsReporterOwner = o.IsReporterOwner()
}
if o.ReporterContactConsent != nil {
m.ReporterContactConsent = o.ReporterContactConsent()
}
o.setModelRels(m)
@ -523,18 +567,58 @@ func ensureCreatablePublicreportPool(m *models.PublicreportPoolSetter) {
func (o *PublicreportPoolTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.PublicreportPool) error {
var err error
isNotifyEmailPoolsDone, _ := publicreportPoolRelNotifyEmailPoolsCtx.Value(ctx)
if !isNotifyEmailPoolsDone && o.r.NotifyEmailPools != nil {
ctx = publicreportPoolRelNotifyEmailPoolsCtx.WithValue(ctx, true)
for _, r := range o.r.NotifyEmailPools {
if r.o.alreadyPersisted {
m.R.NotifyEmailPools = append(m.R.NotifyEmailPools, r.o.Build())
} else {
rel0, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachNotifyEmailPools(ctx, exec, rel0...)
if err != nil {
return err
}
}
}
}
isNotifyPhonePoolsDone, _ := publicreportPoolRelNotifyPhonePoolsCtx.Value(ctx)
if !isNotifyPhonePoolsDone && o.r.NotifyPhonePools != nil {
ctx = publicreportPoolRelNotifyPhonePoolsCtx.WithValue(ctx, true)
for _, r := range o.r.NotifyPhonePools {
if r.o.alreadyPersisted {
m.R.NotifyPhonePools = append(m.R.NotifyPhonePools, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachNotifyPhonePools(ctx, exec, rel1...)
if err != nil {
return err
}
}
}
}
isOrganizationDone, _ := publicreportPoolRelOrganizationCtx.Value(ctx)
if !isOrganizationDone && o.r.Organization != nil {
ctx = publicreportPoolRelOrganizationCtx.WithValue(ctx, true)
if o.r.Organization.o.alreadyPersisted {
m.R.Organization = o.r.Organization.o.Build()
} else {
var rel0 *models.Organization
rel0, err = o.r.Organization.o.Create(ctx, exec)
var rel2 *models.Organization
rel2, err = o.r.Organization.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachOrganization(ctx, exec, rel0)
err = m.AttachOrganization(ctx, exec, rel2)
if err != nil {
return err
}
@ -549,12 +633,12 @@ func (o *PublicreportPoolTemplate) insertOptRels(ctx context.Context, exec bob.E
if r.o.alreadyPersisted {
m.R.Images = append(m.R.Images, r.o.Build())
} else {
rel1, err := r.o.CreateMany(ctx, exec, r.number)
rel3, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachImages(ctx, exec, rel1...)
err = m.AttachImages(ctx, exec, rel3...)
if err != nil {
return err
}
@ -687,6 +771,7 @@ func (m publicreportPoolMods) RandomizeAllColumns(f *faker.Faker) PublicreportPo
PublicreportPoolMods.RandomHasBackyardPermission(f),
PublicreportPoolMods.RandomIsReporterConfidential(f),
PublicreportPoolMods.RandomIsReporterOwner(f),
PublicreportPoolMods.RandomReporterContactConsent(f),
}
}
@ -1779,6 +1864,59 @@ func (m publicreportPoolMods) RandomIsReporterOwner(f *faker.Faker) Publicreport
})
}
// Set the model columns to this value
func (m publicreportPoolMods) ReporterContactConsent(val null.Val[bool]) PublicreportPoolMod {
return PublicreportPoolModFunc(func(_ context.Context, o *PublicreportPoolTemplate) {
o.ReporterContactConsent = func() null.Val[bool] { return val }
})
}
// Set the Column from the function
func (m publicreportPoolMods) ReporterContactConsentFunc(f func() null.Val[bool]) PublicreportPoolMod {
return PublicreportPoolModFunc(func(_ context.Context, o *PublicreportPoolTemplate) {
o.ReporterContactConsent = f
})
}
// Clear any values for the column
func (m publicreportPoolMods) UnsetReporterContactConsent() PublicreportPoolMod {
return PublicreportPoolModFunc(func(_ context.Context, o *PublicreportPoolTemplate) {
o.ReporterContactConsent = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m publicreportPoolMods) RandomReporterContactConsent(f *faker.Faker) PublicreportPoolMod {
return PublicreportPoolModFunc(func(_ context.Context, o *PublicreportPoolTemplate) {
o.ReporterContactConsent = func() null.Val[bool] {
if f == nil {
f = &defaultFaker
}
val := random_bool(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m publicreportPoolMods) RandomReporterContactConsentNotNull(f *faker.Faker) PublicreportPoolMod {
return PublicreportPoolModFunc(func(_ context.Context, o *PublicreportPoolTemplate) {
o.ReporterContactConsent = func() null.Val[bool] {
if f == nil {
f = &defaultFaker
}
val := random_bool(f)
return null.From(val)
}
})
}
func (m publicreportPoolMods) WithParentsCascading() PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
if isDone, _ := publicreportPoolWithParentsCascadingCtx.Value(ctx); isDone {
@ -1823,6 +1961,102 @@ func (m publicreportPoolMods) WithoutOrganization() PublicreportPoolMod {
})
}
func (m publicreportPoolMods) WithNotifyEmailPools(number int, related *PublicreportNotifyEmailPoolTemplate) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.NotifyEmailPools = []*publicreportPoolRNotifyEmailPoolsR{{
number: number,
o: related,
}}
})
}
func (m publicreportPoolMods) WithNewNotifyEmailPools(number int, mods ...PublicreportNotifyEmailPoolMod) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
related := o.f.NewPublicreportNotifyEmailPoolWithContext(ctx, mods...)
m.WithNotifyEmailPools(number, related).Apply(ctx, o)
})
}
func (m publicreportPoolMods) AddNotifyEmailPools(number int, related *PublicreportNotifyEmailPoolTemplate) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.NotifyEmailPools = append(o.r.NotifyEmailPools, &publicreportPoolRNotifyEmailPoolsR{
number: number,
o: related,
})
})
}
func (m publicreportPoolMods) AddNewNotifyEmailPools(number int, mods ...PublicreportNotifyEmailPoolMod) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
related := o.f.NewPublicreportNotifyEmailPoolWithContext(ctx, mods...)
m.AddNotifyEmailPools(number, related).Apply(ctx, o)
})
}
func (m publicreportPoolMods) AddExistingNotifyEmailPools(existingModels ...*models.PublicreportNotifyEmailPool) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
for _, em := range existingModels {
o.r.NotifyEmailPools = append(o.r.NotifyEmailPools, &publicreportPoolRNotifyEmailPoolsR{
o: o.f.FromExistingPublicreportNotifyEmailPool(em),
})
}
})
}
func (m publicreportPoolMods) WithoutNotifyEmailPools() PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.NotifyEmailPools = nil
})
}
func (m publicreportPoolMods) WithNotifyPhonePools(number int, related *PublicreportNotifyPhonePoolTemplate) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.NotifyPhonePools = []*publicreportPoolRNotifyPhonePoolsR{{
number: number,
o: related,
}}
})
}
func (m publicreportPoolMods) WithNewNotifyPhonePools(number int, mods ...PublicreportNotifyPhonePoolMod) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
related := o.f.NewPublicreportNotifyPhonePoolWithContext(ctx, mods...)
m.WithNotifyPhonePools(number, related).Apply(ctx, o)
})
}
func (m publicreportPoolMods) AddNotifyPhonePools(number int, related *PublicreportNotifyPhonePoolTemplate) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.NotifyPhonePools = append(o.r.NotifyPhonePools, &publicreportPoolRNotifyPhonePoolsR{
number: number,
o: related,
})
})
}
func (m publicreportPoolMods) AddNewNotifyPhonePools(number int, mods ...PublicreportNotifyPhonePoolMod) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
related := o.f.NewPublicreportNotifyPhonePoolWithContext(ctx, mods...)
m.AddNotifyPhonePools(number, related).Apply(ctx, o)
})
}
func (m publicreportPoolMods) AddExistingNotifyPhonePools(existingModels ...*models.PublicreportNotifyPhonePool) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
for _, em := range existingModels {
o.r.NotifyPhonePools = append(o.r.NotifyPhonePools, &publicreportPoolRNotifyPhonePoolsR{
o: o.f.FromExistingPublicreportNotifyPhonePool(em),
})
}
})
}
func (m publicreportPoolMods) WithoutNotifyPhonePools() PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.NotifyPhonePools = nil
})
}
func (m publicreportPoolMods) WithImages(number int, related *PublicreportImageTemplate) PublicreportPoolMod {
return PublicreportPoolModFunc(func(ctx context.Context, o *PublicreportPoolTemplate) {
o.r.Images = []*publicreportPoolRImagesR{{

View file

@ -0,0 +1,34 @@
-- +goose Up
CREATE TABLE publicreport.notify_phone_nuisance (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
deleted TIMESTAMP WITHOUT TIME ZONE,
nuisance_id INTEGER NOT NULL REFERENCES publicreport.nuisance(id),
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
PRIMARY KEY(nuisance_id, phone_e164)
);
CREATE TABLE publicreport.notify_phone_pool (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
deleted TIMESTAMP WITHOUT TIME ZONE,
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
pool_id INTEGER NOT NULL REFERENCES publicreport.pool(id),
PRIMARY KEY(pool_id, phone_e164)
);
CREATE TABLE publicreport.notify_email_nuisance (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
deleted TIMESTAMP WITHOUT TIME ZONE,
nuisance_id INTEGER NOT NULL REFERENCES publicreport.nuisance(id),
email_address TEXT NOT NULL REFERENCES comms.email_contact(address),
PRIMARY KEY(nuisance_id, email_address)
);
CREATE TABLE publicreport.notify_email_pool (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
deleted TIMESTAMP WITHOUT TIME ZONE,
pool_id INTEGER NOT NULL REFERENCES publicreport.pool(id),
email_address TEXT NOT NULL REFERENCES comms.email_contact(address),
PRIMARY KEY(pool_id, email_address)
);
-- +goose Down
DROP TABLE publicreport.notify_email_pool;
DROP TABLE publicreport.notify_email_nuisance;
DROP TABLE publicreport.notify_phone_pool;
DROP TABLE publicreport.notify_phone_nuisance;

View file

@ -0,0 +1,7 @@
-- +goose Up
ALTER TABLE publicreport.nuisance ADD COLUMN reporter_contact_consent BOOLEAN;
ALTER TABLE publicreport.pool ADD COLUMN reporter_contact_consent BOOLEAN;
-- +goose Down
ALTER TABLE publicreport.pool DROP COLUMN reporter_contact_consent;
ALTER TABLE publicreport.nuisance DROP COLUMN reporter_contact_consent;

View file

@ -83,6 +83,10 @@ type joins[Q dialect.Joinable] struct {
Organizations joinSet[organizationJoins[Q]]
PublicreportImages joinSet[publicreportImageJoins[Q]]
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
PublicreportNotifyEmailNuisances joinSet[publicreportNotifyEmailNuisanceJoins[Q]]
PublicreportNotifyEmailPools joinSet[publicreportNotifyEmailPoolJoins[Q]]
PublicreportNotifyPhoneNuisances joinSet[publicreportNotifyPhoneNuisanceJoins[Q]]
PublicreportNotifyPhonePools joinSet[publicreportNotifyPhonePoolJoins[Q]]
PublicreportNuisances joinSet[publicreportNuisanceJoins[Q]]
PublicreportNuisanceImages joinSet[publicreportNuisanceImageJoins[Q]]
PublicreportPools joinSet[publicreportPoolJoins[Q]]
@ -153,6 +157,10 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
PublicreportNotifyEmailNuisances: buildJoinSet[publicreportNotifyEmailNuisanceJoins[Q]](PublicreportNotifyEmailNuisances.Columns, buildPublicreportNotifyEmailNuisanceJoins),
PublicreportNotifyEmailPools: buildJoinSet[publicreportNotifyEmailPoolJoins[Q]](PublicreportNotifyEmailPools.Columns, buildPublicreportNotifyEmailPoolJoins),
PublicreportNotifyPhoneNuisances: buildJoinSet[publicreportNotifyPhoneNuisanceJoins[Q]](PublicreportNotifyPhoneNuisances.Columns, buildPublicreportNotifyPhoneNuisanceJoins),
PublicreportNotifyPhonePools: buildJoinSet[publicreportNotifyPhonePoolJoins[Q]](PublicreportNotifyPhonePools.Columns, buildPublicreportNotifyPhonePoolJoins),
PublicreportNuisances: buildJoinSet[publicreportNuisanceJoins[Q]](PublicreportNuisances.Columns, buildPublicreportNuisanceJoins),
PublicreportNuisanceImages: buildJoinSet[publicreportNuisanceImageJoins[Q]](PublicreportNuisanceImages.Columns, buildPublicreportNuisanceImageJoins),
PublicreportPools: buildJoinSet[publicreportPoolJoins[Q]](PublicreportPools.Columns, buildPublicreportPoolJoins),

View file

@ -68,6 +68,10 @@ type preloaders struct {
Organization organizationPreloader
PublicreportImage publicreportImagePreloader
PublicreportImageExif publicreportImageExifPreloader
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisancePreloader
PublicreportNotifyEmailPool publicreportNotifyEmailPoolPreloader
PublicreportNotifyPhoneNuisance publicreportNotifyPhoneNuisancePreloader
PublicreportNotifyPhonePool publicreportNotifyPhonePoolPreloader
PublicreportNuisance publicreportNuisancePreloader
PublicreportNuisanceImage publicreportNuisanceImagePreloader
PublicreportPool publicreportPoolPreloader
@ -130,6 +134,10 @@ func getPreloaders() preloaders {
Organization: buildOrganizationPreloader(),
PublicreportImage: buildPublicreportImagePreloader(),
PublicreportImageExif: buildPublicreportImageExifPreloader(),
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisancePreloader(),
PublicreportNotifyEmailPool: buildPublicreportNotifyEmailPoolPreloader(),
PublicreportNotifyPhoneNuisance: buildPublicreportNotifyPhoneNuisancePreloader(),
PublicreportNotifyPhonePool: buildPublicreportNotifyPhonePoolPreloader(),
PublicreportNuisance: buildPublicreportNuisancePreloader(),
PublicreportNuisanceImage: buildPublicreportNuisanceImagePreloader(),
PublicreportPool: buildPublicreportPoolPreloader(),
@ -198,6 +206,10 @@ type thenLoaders[Q orm.Loadable] struct {
Organization organizationThenLoader[Q]
PublicreportImage publicreportImageThenLoader[Q]
PublicreportImageExif publicreportImageExifThenLoader[Q]
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisanceThenLoader[Q]
PublicreportNotifyEmailPool publicreportNotifyEmailPoolThenLoader[Q]
PublicreportNotifyPhoneNuisance publicreportNotifyPhoneNuisanceThenLoader[Q]
PublicreportNotifyPhonePool publicreportNotifyPhonePoolThenLoader[Q]
PublicreportNuisance publicreportNuisanceThenLoader[Q]
PublicreportNuisanceImage publicreportNuisanceImageThenLoader[Q]
PublicreportPool publicreportPoolThenLoader[Q]
@ -260,6 +272,10 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
Organization: buildOrganizationThenLoader[Q](),
PublicreportImage: buildPublicreportImageThenLoader[Q](),
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisanceThenLoader[Q](),
PublicreportNotifyEmailPool: buildPublicreportNotifyEmailPoolThenLoader[Q](),
PublicreportNotifyPhoneNuisance: buildPublicreportNotifyPhoneNuisanceThenLoader[Q](),
PublicreportNotifyPhonePool: buildPublicreportNotifyPhonePoolThenLoader[Q](),
PublicreportNuisance: buildPublicreportNuisanceThenLoader[Q](),
PublicreportNuisanceImage: buildPublicreportNuisanceImageThenLoader[Q](),
PublicreportPool: buildPublicreportPoolThenLoader[Q](),

View file

@ -71,6 +71,10 @@ func Where[Q psql.Filterable]() struct {
Organizations organizationWhere[Q]
PublicreportImages publicreportImageWhere[Q]
PublicreportImageExifs publicreportImageExifWhere[Q]
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
PublicreportNotifyEmailPools publicreportNotifyEmailPoolWhere[Q]
PublicreportNotifyPhoneNuisances publicreportNotifyPhoneNuisanceWhere[Q]
PublicreportNotifyPhonePools publicreportNotifyPhonePoolWhere[Q]
PublicreportNuisances publicreportNuisanceWhere[Q]
PublicreportNuisanceImages publicreportNuisanceImageWhere[Q]
PublicreportPools publicreportPoolWhere[Q]
@ -139,6 +143,10 @@ func Where[Q psql.Filterable]() struct {
Organizations organizationWhere[Q]
PublicreportImages publicreportImageWhere[Q]
PublicreportImageExifs publicreportImageExifWhere[Q]
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
PublicreportNotifyEmailPools publicreportNotifyEmailPoolWhere[Q]
PublicreportNotifyPhoneNuisances publicreportNotifyPhoneNuisanceWhere[Q]
PublicreportNotifyPhonePools publicreportNotifyPhonePoolWhere[Q]
PublicreportNuisances publicreportNuisanceWhere[Q]
PublicreportNuisanceImages publicreportNuisanceImageWhere[Q]
PublicreportPools publicreportPoolWhere[Q]
@ -206,6 +214,10 @@ func Where[Q psql.Filterable]() struct {
Organizations: buildOrganizationWhere[Q](Organizations.Columns),
PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns),
PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns),
PublicreportNotifyEmailNuisances: buildPublicreportNotifyEmailNuisanceWhere[Q](PublicreportNotifyEmailNuisances.Columns),
PublicreportNotifyEmailPools: buildPublicreportNotifyEmailPoolWhere[Q](PublicreportNotifyEmailPools.Columns),
PublicreportNotifyPhoneNuisances: buildPublicreportNotifyPhoneNuisanceWhere[Q](PublicreportNotifyPhoneNuisances.Columns),
PublicreportNotifyPhonePools: buildPublicreportNotifyPhonePoolWhere[Q](PublicreportNotifyPhonePools.Columns),
PublicreportNuisances: buildPublicreportNuisanceWhere[Q](PublicreportNuisances.Columns),
PublicreportNuisanceImages: buildPublicreportNuisanceImageWhere[Q](PublicreportNuisanceImages.Columns),
PublicreportPools: buildPublicreportPoolWhere[Q](PublicreportPools.Columns),

View file

@ -47,8 +47,10 @@ type CommsEmailContactsQuery = *psql.ViewQuery[*CommsEmailContact, CommsEmailCon
// commsEmailContactR is where relationships are stored.
type commsEmailContactR struct {
DestinationEmailLogs CommsEmailLogSlice // comms.email_log.email_log_destination_fkey
Organizations OrganizationSlice // district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey
DestinationEmailLogs CommsEmailLogSlice // comms.email_log.email_log_destination_fkey
Organizations OrganizationSlice // district_subscription_email.district_subscription_email_email_contact_address_fkeydistrict_subscription_email.district_subscription_email_organization_id_fkey
EmailAddressNotifyEmailNuisances PublicreportNotifyEmailNuisanceSlice // publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey
EmailAddressNotifyEmailPools PublicreportNotifyEmailPoolSlice // publicreport.notify_email_pool.notify_email_pool_email_address_fkey
}
func buildCommsEmailContactColumns(alias string) commsEmailContactColumns {
@ -472,6 +474,54 @@ func (os CommsEmailContactSlice) Organizations(mods ...bob.Mod[*dialect.SelectQu
)...)
}
// EmailAddressNotifyEmailNuisances starts a query for related objects on publicreport.notify_email_nuisance
func (o *CommsEmailContact) EmailAddressNotifyEmailNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisancesQuery {
return PublicreportNotifyEmailNuisances.Query(append(mods,
sm.Where(PublicreportNotifyEmailNuisances.Columns.EmailAddress.EQ(psql.Arg(o.Address))),
)...)
}
func (os CommsEmailContactSlice) EmailAddressNotifyEmailNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisancesQuery {
pkAddress := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkAddress = append(pkAddress, o.Address)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkAddress), "text[]")),
))
return PublicreportNotifyEmailNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailNuisances.Columns.EmailAddress).OP("IN", PKArgExpr)),
)...)
}
// EmailAddressNotifyEmailPools starts a query for related objects on publicreport.notify_email_pool
func (o *CommsEmailContact) EmailAddressNotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery {
return PublicreportNotifyEmailPools.Query(append(mods,
sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(o.Address))),
)...)
}
func (os CommsEmailContactSlice) EmailAddressNotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery {
pkAddress := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkAddress = append(pkAddress, o.Address)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkAddress), "text[]")),
))
return PublicreportNotifyEmailPools.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailPools.Columns.EmailAddress).OP("IN", PKArgExpr)),
)...)
}
func insertCommsEmailContactDestinationEmailLogs0(ctx context.Context, exec bob.Executor, commsEmailLogs1 []*CommsEmailLogSetter, commsEmailContact0 *CommsEmailContact) (CommsEmailLogSlice, error) {
for i := range commsEmailLogs1 {
commsEmailLogs1[i].Destination = omit.From(commsEmailContact0.Address)
@ -605,6 +655,142 @@ func (commsEmailContact0 *CommsEmailContact) AttachOrganizations(ctx context.Con
return nil
}
func insertCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailNuisances1 []*PublicreportNotifyEmailNuisanceSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailNuisanceSlice, error) {
for i := range publicreportNotifyEmailNuisances1 {
publicreportNotifyEmailNuisances1[i].EmailAddress = omit.From(commsEmailContact0.Address)
}
ret, err := PublicreportNotifyEmailNuisances.Insert(bob.ToMods(publicreportNotifyEmailNuisances1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailNuisances0: %w", err)
}
return ret, nil
}
func attachCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisances1 PublicreportNotifyEmailNuisanceSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailNuisanceSlice, error) {
setter := &PublicreportNotifyEmailNuisanceSetter{
EmailAddress: omit.From(commsEmailContact0.Address),
}
err := publicreportNotifyEmailNuisances1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailNuisances0: %w", err)
}
return publicreportNotifyEmailNuisances1, nil
}
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailNuisances1, err := insertCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx, exec, related, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailNuisances = append(commsEmailContact0.R.EmailAddressNotifyEmailNuisances, publicreportNotifyEmailNuisances1...)
for _, rel := range publicreportNotifyEmailNuisances1 {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisance) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailNuisances1 := PublicreportNotifyEmailNuisanceSlice(related)
_, err = attachCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx, exec, len(related), publicreportNotifyEmailNuisances1, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailNuisances = append(commsEmailContact0.R.EmailAddressNotifyEmailNuisances, publicreportNotifyEmailNuisances1...)
for _, rel := range related {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func insertCommsEmailContactEmailAddressNotifyEmailPools0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailPools1 []*PublicreportNotifyEmailPoolSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailPoolSlice, error) {
for i := range publicreportNotifyEmailPools1 {
publicreportNotifyEmailPools1[i].EmailAddress = omit.From(commsEmailContact0.Address)
}
ret, err := PublicreportNotifyEmailPools.Insert(bob.ToMods(publicreportNotifyEmailPools1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailPools0: %w", err)
}
return ret, nil
}
func attachCommsEmailContactEmailAddressNotifyEmailPools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPools1 PublicreportNotifyEmailPoolSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailPoolSlice, error) {
setter := &PublicreportNotifyEmailPoolSetter{
EmailAddress: omit.From(commsEmailContact0.Address),
}
err := publicreportNotifyEmailPools1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailPools0: %w", err)
}
return publicreportNotifyEmailPools1, nil
}
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPoolSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailPools1, err := insertCommsEmailContactEmailAddressNotifyEmailPools0(ctx, exec, related, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailPools = append(commsEmailContact0.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPools1...)
for _, rel := range publicreportNotifyEmailPools1 {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPool) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailPools1 := PublicreportNotifyEmailPoolSlice(related)
_, err = attachCommsEmailContactEmailAddressNotifyEmailPools0(ctx, exec, len(related), publicreportNotifyEmailPools1, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailPools = append(commsEmailContact0.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPools1...)
for _, rel := range related {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
type commsEmailContactWhere[Q psql.Filterable] struct {
Address psql.WhereMod[Q, string]
Confirmed psql.WhereMod[Q, bool]
@ -659,6 +845,34 @@ func (o *CommsEmailContact) Preload(name string, retrieved any) error {
}
}
return nil
case "EmailAddressNotifyEmailNuisances":
rels, ok := retrieved.(PublicreportNotifyEmailNuisanceSlice)
if !ok {
return fmt.Errorf("commsEmailContact cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressNotifyEmailNuisances = rels
for _, rel := range rels {
if rel != nil {
rel.R.EmailAddressEmailContact = o
}
}
return nil
case "EmailAddressNotifyEmailPools":
rels, ok := retrieved.(PublicreportNotifyEmailPoolSlice)
if !ok {
return fmt.Errorf("commsEmailContact cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressNotifyEmailPools = rels
for _, rel := range rels {
if rel != nil {
rel.R.EmailAddressEmailContact = o
}
}
return nil
default:
return fmt.Errorf("commsEmailContact has no relationship %q", name)
}
@ -671,8 +885,10 @@ func buildCommsEmailContactPreloader() commsEmailContactPreloader {
}
type commsEmailContactThenLoader[Q orm.Loadable] struct {
DestinationEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsEmailContactThenLoader[Q orm.Loadable]() commsEmailContactThenLoader[Q] {
@ -682,6 +898,12 @@ func buildCommsEmailContactThenLoader[Q orm.Loadable]() commsEmailContactThenLoa
type OrganizationsLoadInterface interface {
LoadOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressNotifyEmailNuisancesLoadInterface interface {
LoadEmailAddressNotifyEmailNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressNotifyEmailPoolsLoadInterface interface {
LoadEmailAddressNotifyEmailPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsEmailContactThenLoader[Q]{
DestinationEmailLogs: thenLoadBuilder[Q](
@ -696,6 +918,18 @@ func buildCommsEmailContactThenLoader[Q orm.Loadable]() commsEmailContactThenLoa
return retrieved.LoadOrganizations(ctx, exec, mods...)
},
),
EmailAddressNotifyEmailNuisances: thenLoadBuilder[Q](
"EmailAddressNotifyEmailNuisances",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressNotifyEmailNuisances(ctx, exec, mods...)
},
),
EmailAddressNotifyEmailPools: thenLoadBuilder[Q](
"EmailAddressNotifyEmailPools",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressNotifyEmailPools(ctx, exec, mods...)
},
),
}
}
@ -841,10 +1075,134 @@ func (os CommsEmailContactSlice) LoadOrganizations(ctx context.Context, exec bob
return nil
}
// LoadEmailAddressNotifyEmailNuisances loads the commsEmailContact's EmailAddressNotifyEmailNuisances into the .R struct
func (o *CommsEmailContact) LoadEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressNotifyEmailNuisances = nil
related, err := o.EmailAddressNotifyEmailNuisances(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.EmailAddressEmailContact = o
}
o.R.EmailAddressNotifyEmailNuisances = related
return nil
}
// LoadEmailAddressNotifyEmailNuisances loads the commsEmailContact's EmailAddressNotifyEmailNuisances into the .R struct
func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyEmailNuisances, err := os.EmailAddressNotifyEmailNuisances(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.EmailAddressNotifyEmailNuisances = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyEmailNuisances {
if !(o.Address == rel.EmailAddress) {
continue
}
rel.R.EmailAddressEmailContact = o
o.R.EmailAddressNotifyEmailNuisances = append(o.R.EmailAddressNotifyEmailNuisances, rel)
}
}
return nil
}
// LoadEmailAddressNotifyEmailPools loads the commsEmailContact's EmailAddressNotifyEmailPools into the .R struct
func (o *CommsEmailContact) LoadEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressNotifyEmailPools = nil
related, err := o.EmailAddressNotifyEmailPools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.EmailAddressEmailContact = o
}
o.R.EmailAddressNotifyEmailPools = related
return nil
}
// LoadEmailAddressNotifyEmailPools loads the commsEmailContact's EmailAddressNotifyEmailPools into the .R struct
func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyEmailPools, err := os.EmailAddressNotifyEmailPools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.EmailAddressNotifyEmailPools = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyEmailPools {
if !(o.Address == rel.EmailAddress) {
continue
}
rel.R.EmailAddressEmailContact = o
o.R.EmailAddressNotifyEmailPools = append(o.R.EmailAddressNotifyEmailPools, rel)
}
}
return nil
}
// commsEmailContactC is where relationship counts are stored.
type commsEmailContactC struct {
DestinationEmailLogs *int64
Organizations *int64
DestinationEmailLogs *int64
Organizations *int64
EmailAddressNotifyEmailNuisances *int64
EmailAddressNotifyEmailPools *int64
}
// PreloadCount sets a count in the C struct by name
@ -858,13 +1216,19 @@ func (o *CommsEmailContact) PreloadCount(name string, count int64) error {
o.C.DestinationEmailLogs = &count
case "Organizations":
o.C.Organizations = &count
case "EmailAddressNotifyEmailNuisances":
o.C.EmailAddressNotifyEmailNuisances = &count
case "EmailAddressNotifyEmailPools":
o.C.EmailAddressNotifyEmailPools = &count
}
return nil
}
type commsEmailContactCountPreloader struct {
DestinationEmailLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
Organizations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
DestinationEmailLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
Organizations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
EmailAddressNotifyEmailNuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
EmailAddressNotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildCommsEmailContactCountPreloader() commsEmailContactCountPreloader {
@ -906,12 +1270,48 @@ func buildCommsEmailContactCountPreloader() commsEmailContactCountPreloader {
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
EmailAddressNotifyEmailNuisances: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsEmailContact]("EmailAddressNotifyEmailNuisances", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsEmailContacts.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyEmailNuisances.Name()),
sm.Where(psql.Quote(PublicreportNotifyEmailNuisances.Alias(), "email_address").EQ(psql.Quote(parent, "address"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
EmailAddressNotifyEmailPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsEmailContact]("EmailAddressNotifyEmailPools", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsEmailContacts.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyEmailPools.Name()),
sm.Where(psql.Quote(PublicreportNotifyEmailPools.Alias(), "email_address").EQ(psql.Quote(parent, "address"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
}
}
type commsEmailContactCountThenLoader[Q orm.Loadable] struct {
DestinationEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationEmailLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsEmailContactCountThenLoader[Q orm.Loadable]() commsEmailContactCountThenLoader[Q] {
@ -921,6 +1321,12 @@ func buildCommsEmailContactCountThenLoader[Q orm.Loadable]() commsEmailContactCo
type OrganizationsCountInterface interface {
LoadCountOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressNotifyEmailNuisancesCountInterface interface {
LoadCountEmailAddressNotifyEmailNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressNotifyEmailPoolsCountInterface interface {
LoadCountEmailAddressNotifyEmailPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsEmailContactCountThenLoader[Q]{
DestinationEmailLogs: countThenLoadBuilder[Q](
@ -935,6 +1341,18 @@ func buildCommsEmailContactCountThenLoader[Q orm.Loadable]() commsEmailContactCo
return retrieved.LoadCountOrganizations(ctx, exec, mods...)
},
),
EmailAddressNotifyEmailNuisances: countThenLoadBuilder[Q](
"EmailAddressNotifyEmailNuisances",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailNuisancesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountEmailAddressNotifyEmailNuisances(ctx, exec, mods...)
},
),
EmailAddressNotifyEmailPools: countThenLoadBuilder[Q](
"EmailAddressNotifyEmailPools",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountEmailAddressNotifyEmailPools(ctx, exec, mods...)
},
),
}
}
@ -998,10 +1416,72 @@ func (os CommsEmailContactSlice) LoadCountOrganizations(ctx context.Context, exe
return nil
}
// LoadCountEmailAddressNotifyEmailNuisances loads the count of EmailAddressNotifyEmailNuisances into the C struct
func (o *CommsEmailContact) LoadCountEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.EmailAddressNotifyEmailNuisances(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.EmailAddressNotifyEmailNuisances = &count
return nil
}
// LoadCountEmailAddressNotifyEmailNuisances loads the count of EmailAddressNotifyEmailNuisances for a slice
func (os CommsEmailContactSlice) LoadCountEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountEmailAddressNotifyEmailNuisances(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountEmailAddressNotifyEmailPools loads the count of EmailAddressNotifyEmailPools into the C struct
func (o *CommsEmailContact) LoadCountEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.EmailAddressNotifyEmailPools(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.EmailAddressNotifyEmailPools = &count
return nil
}
// LoadCountEmailAddressNotifyEmailPools loads the count of EmailAddressNotifyEmailPools for a slice
func (os CommsEmailContactSlice) LoadCountEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountEmailAddressNotifyEmailPools(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
type commsEmailContactJoins[Q dialect.Joinable] struct {
typ string
DestinationEmailLogs modAs[Q, commsEmailLogColumns]
Organizations modAs[Q, organizationColumns]
typ string
DestinationEmailLogs modAs[Q, commsEmailLogColumns]
Organizations modAs[Q, organizationColumns]
EmailAddressNotifyEmailNuisances modAs[Q, publicreportNotifyEmailNuisanceColumns]
EmailAddressNotifyEmailPools modAs[Q, publicreportNotifyEmailPoolColumns]
}
func (j commsEmailContactJoins[Q]) aliasedAs(alias string) commsEmailContactJoins[Q] {
@ -1044,6 +1524,34 @@ func buildCommsEmailContactJoins[Q dialect.Joinable](cols commsEmailContactColum
))
}
return mods
},
},
EmailAddressNotifyEmailNuisances: modAs[Q, publicreportNotifyEmailNuisanceColumns]{
c: PublicreportNotifyEmailNuisances.Columns,
f: func(to publicreportNotifyEmailNuisanceColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyEmailNuisances.Name().As(to.Alias())).On(
to.EmailAddress.EQ(cols.Address),
))
}
return mods
},
},
EmailAddressNotifyEmailPools: modAs[Q, publicreportNotifyEmailPoolColumns]{
c: PublicreportNotifyEmailPools.Columns,
f: func(to publicreportNotifyEmailPoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyEmailPools.Name().As(to.Alias())).On(
to.EmailAddress.EQ(cols.Address),
))
}
return mods
},
},

View file

@ -47,10 +47,12 @@ type CommsPhonesQuery = *psql.ViewQuery[*CommsPhone, CommsPhoneSlice]
// commsPhoneR is where relationships are stored.
type commsPhoneR struct {
DestinationTextJobs CommsTextJobSlice // comms.text_job.text_job_destination_fkey
DestinationTextLogs CommsTextLogSlice // comms.text_log.text_log_destination_fkey
SourceTextLogs CommsTextLogSlice // comms.text_log.text_log_source_fkey
Organizations OrganizationSlice // district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey
DestinationTextJobs CommsTextJobSlice // comms.text_job.text_job_destination_fkey
DestinationTextLogs CommsTextLogSlice // comms.text_log.text_log_destination_fkey
SourceTextLogs CommsTextLogSlice // comms.text_log.text_log_source_fkey
Organizations OrganizationSlice // district_subscription_phone.district_subscription_phone_organization_id_fkeydistrict_subscription_phone.district_subscription_phone_phone_e164_fkey
PhoneE164NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey
PhoneE164NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey
}
func buildCommsPhoneColumns(alias string) commsPhoneColumns {
@ -500,6 +502,54 @@ func (os CommsPhoneSlice) Organizations(mods ...bob.Mod[*dialect.SelectQuery]) O
)...)
}
// PhoneE164NotifyPhoneNuisances starts a query for related objects on publicreport.notify_phone_nuisance
func (o *CommsPhone) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery {
return PublicreportNotifyPhoneNuisances.Query(append(mods,
sm.Where(PublicreportNotifyPhoneNuisances.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportNotifyPhoneNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhoneNuisances.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164NotifyPhonePools starts a query for related objects on publicreport.notify_phone_pool
func (o *CommsPhone) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery {
return PublicreportNotifyPhonePools.Query(append(mods,
sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkE164 = append(pkE164, o.E164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportNotifyPhonePools.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhonePools.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
func insertCommsPhoneDestinationTextJobs0(ctx context.Context, exec bob.Executor, commsTextJobs1 []*CommsTextJobSetter, commsPhone0 *CommsPhone) (CommsTextJobSlice, error) {
for i := range commsTextJobs1 {
commsTextJobs1[i].Destination = omit.From(commsPhone0.E164)
@ -769,6 +819,142 @@ func (commsPhone0 *CommsPhone) AttachOrganizations(ctx context.Context, exec bob
return nil
}
func insertCommsPhonePhoneE164NotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneNuisances1 []*PublicreportNotifyPhoneNuisanceSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceSlice, error) {
for i := range publicreportNotifyPhoneNuisances1 {
publicreportNotifyPhoneNuisances1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhoneNuisances.Insert(bob.ToMods(publicreportNotifyPhoneNuisances1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneNuisances0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisances1 PublicreportNotifyPhoneNuisanceSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceSlice, error) {
setter := &PublicreportNotifyPhoneNuisanceSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhoneNuisances1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneNuisances0: %w", err)
}
return publicreportNotifyPhoneNuisances1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneNuisances1, err := insertCommsPhonePhoneE164NotifyPhoneNuisances0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneNuisances = append(commsPhone0.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...)
for _, rel := range publicreportNotifyPhoneNuisances1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisance) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneNuisances1 := PublicreportNotifyPhoneNuisanceSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhoneNuisances0(ctx, exec, len(related), publicreportNotifyPhoneNuisances1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneNuisances = append(commsPhone0.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func insertCommsPhonePhoneE164NotifyPhonePools0(ctx context.Context, exec bob.Executor, publicreportNotifyPhonePools1 []*PublicreportNotifyPhonePoolSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhonePoolSlice, error) {
for i := range publicreportNotifyPhonePools1 {
publicreportNotifyPhonePools1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhonePools.Insert(bob.ToMods(publicreportNotifyPhonePools1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhonePools0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhonePools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePools1 PublicreportNotifyPhonePoolSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhonePoolSlice, error) {
setter := &PublicreportNotifyPhonePoolSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhonePools1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhonePools0: %w", err)
}
return publicreportNotifyPhonePools1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePoolSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhonePools1, err := insertCommsPhonePhoneE164NotifyPhonePools0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhonePools = append(commsPhone0.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePools1...)
for _, rel := range publicreportNotifyPhonePools1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePool) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhonePools1 := PublicreportNotifyPhonePoolSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhonePools0(ctx, exec, len(related), publicreportNotifyPhonePools1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhonePools = append(commsPhone0.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePools1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
type commsPhoneWhere[Q psql.Filterable] struct {
E164 psql.WhereMod[Q, string]
IsSubscribed psql.WhereMod[Q, bool]
@ -849,6 +1035,34 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
}
}
return nil
case "PhoneE164NotifyPhoneNuisances":
rels, ok := retrieved.(PublicreportNotifyPhoneNuisanceSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhoneNuisances = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneE164Phone = o
}
}
return nil
case "PhoneE164NotifyPhonePools":
rels, ok := retrieved.(PublicreportNotifyPhonePoolSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhonePools = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneE164Phone = o
}
}
return nil
default:
return fmt.Errorf("commsPhone has no relationship %q", name)
}
@ -861,10 +1075,12 @@ func buildCommsPhonePreloader() commsPhonePreloader {
}
type commsPhoneThenLoader[Q orm.Loadable] struct {
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
@ -880,6 +1096,12 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
type OrganizationsLoadInterface interface {
LoadOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneNuisancesLoadInterface interface {
LoadPhoneE164NotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhonePoolsLoadInterface interface {
LoadPhoneE164NotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsPhoneThenLoader[Q]{
DestinationTextJobs: thenLoadBuilder[Q](
@ -906,6 +1128,18 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
return retrieved.LoadOrganizations(ctx, exec, mods...)
},
),
PhoneE164NotifyPhoneNuisances: thenLoadBuilder[Q](
"PhoneE164NotifyPhoneNuisances",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhoneNuisances(ctx, exec, mods...)
},
),
PhoneE164NotifyPhonePools: thenLoadBuilder[Q](
"PhoneE164NotifyPhonePools",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhonePoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhonePools(ctx, exec, mods...)
},
),
}
}
@ -1173,12 +1407,136 @@ func (os CommsPhoneSlice) LoadOrganizations(ctx context.Context, exec bob.Execut
return nil
}
// LoadPhoneE164NotifyPhoneNuisances loads the commsPhone's PhoneE164NotifyPhoneNuisances into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhoneNuisances = nil
related, err := o.PhoneE164NotifyPhoneNuisances(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhoneNuisances = related
return nil
}
// LoadPhoneE164NotifyPhoneNuisances loads the commsPhone's PhoneE164NotifyPhoneNuisances into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhoneNuisances, err := os.PhoneE164NotifyPhoneNuisances(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneE164NotifyPhoneNuisances = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyPhoneNuisances {
if !(o.E164 == rel.PhoneE164) {
continue
}
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhoneNuisances = append(o.R.PhoneE164NotifyPhoneNuisances, rel)
}
}
return nil
}
// LoadPhoneE164NotifyPhonePools loads the commsPhone's PhoneE164NotifyPhonePools into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhonePools = nil
related, err := o.PhoneE164NotifyPhonePools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhonePools = related
return nil
}
// LoadPhoneE164NotifyPhonePools loads the commsPhone's PhoneE164NotifyPhonePools into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhonePools, err := os.PhoneE164NotifyPhonePools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneE164NotifyPhonePools = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyPhonePools {
if !(o.E164 == rel.PhoneE164) {
continue
}
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhonePools = append(o.R.PhoneE164NotifyPhonePools, rel)
}
}
return nil
}
// commsPhoneC is where relationship counts are stored.
type commsPhoneC struct {
DestinationTextJobs *int64
DestinationTextLogs *int64
SourceTextLogs *int64
Organizations *int64
DestinationTextJobs *int64
DestinationTextLogs *int64
SourceTextLogs *int64
Organizations *int64
PhoneE164NotifyPhoneNuisances *int64
PhoneE164NotifyPhonePools *int64
}
// PreloadCount sets a count in the C struct by name
@ -1196,15 +1554,21 @@ func (o *CommsPhone) PreloadCount(name string, count int64) error {
o.C.SourceTextLogs = &count
case "Organizations":
o.C.Organizations = &count
case "PhoneE164NotifyPhoneNuisances":
o.C.PhoneE164NotifyPhoneNuisances = &count
case "PhoneE164NotifyPhonePools":
o.C.PhoneE164NotifyPhonePools = &count
}
return nil
}
type commsPhoneCountPreloader struct {
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
Organizations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
Organizations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
@ -1280,14 +1644,50 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
PhoneE164NotifyPhoneNuisances: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("PhoneE164NotifyPhoneNuisances", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyPhoneNuisances.Name()),
sm.Where(psql.Quote(PublicreportNotifyPhoneNuisances.Alias(), "phone_e164").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
PhoneE164NotifyPhonePools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*CommsPhone]("PhoneE164NotifyPhonePools", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = CommsPhones.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyPhonePools.Name()),
sm.Where(psql.Quote(PublicreportNotifyPhonePools.Alias(), "phone_e164").EQ(psql.Quote(parent, "e164"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
}
}
type commsPhoneCountThenLoader[Q orm.Loadable] struct {
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourceTextLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[Q] {
@ -1303,6 +1703,12 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
type OrganizationsCountInterface interface {
LoadCountOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneNuisancesCountInterface interface {
LoadCountPhoneE164NotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhonePoolsCountInterface interface {
LoadCountPhoneE164NotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsPhoneCountThenLoader[Q]{
DestinationTextJobs: countThenLoadBuilder[Q](
@ -1329,6 +1735,18 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
return retrieved.LoadCountOrganizations(ctx, exec, mods...)
},
),
PhoneE164NotifyPhoneNuisances: countThenLoadBuilder[Q](
"PhoneE164NotifyPhoneNuisances",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneNuisancesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountPhoneE164NotifyPhoneNuisances(ctx, exec, mods...)
},
),
PhoneE164NotifyPhonePools: countThenLoadBuilder[Q](
"PhoneE164NotifyPhonePools",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhonePoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountPhoneE164NotifyPhonePools(ctx, exec, mods...)
},
),
}
}
@ -1452,12 +1870,74 @@ func (os CommsPhoneSlice) LoadCountOrganizations(ctx context.Context, exec bob.E
return nil
}
// LoadCountPhoneE164NotifyPhoneNuisances loads the count of PhoneE164NotifyPhoneNuisances into the C struct
func (o *CommsPhone) LoadCountPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.PhoneE164NotifyPhoneNuisances(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.PhoneE164NotifyPhoneNuisances = &count
return nil
}
// LoadCountPhoneE164NotifyPhoneNuisances loads the count of PhoneE164NotifyPhoneNuisances for a slice
func (os CommsPhoneSlice) LoadCountPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountPhoneE164NotifyPhoneNuisances(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountPhoneE164NotifyPhonePools loads the count of PhoneE164NotifyPhonePools into the C struct
func (o *CommsPhone) LoadCountPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.PhoneE164NotifyPhonePools(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.PhoneE164NotifyPhonePools = &count
return nil
}
// LoadCountPhoneE164NotifyPhonePools loads the count of PhoneE164NotifyPhonePools for a slice
func (os CommsPhoneSlice) LoadCountPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountPhoneE164NotifyPhonePools(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
type commsPhoneJoins[Q dialect.Joinable] struct {
typ string
DestinationTextJobs modAs[Q, commsTextJobColumns]
DestinationTextLogs modAs[Q, commsTextLogColumns]
SourceTextLogs modAs[Q, commsTextLogColumns]
Organizations modAs[Q, organizationColumns]
typ string
DestinationTextJobs modAs[Q, commsTextJobColumns]
DestinationTextLogs modAs[Q, commsTextLogColumns]
SourceTextLogs modAs[Q, commsTextLogColumns]
Organizations modAs[Q, organizationColumns]
PhoneE164NotifyPhoneNuisances modAs[Q, publicreportNotifyPhoneNuisanceColumns]
PhoneE164NotifyPhonePools modAs[Q, publicreportNotifyPhonePoolColumns]
}
func (j commsPhoneJoins[Q]) aliasedAs(alias string) commsPhoneJoins[Q] {
@ -1528,6 +2008,34 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string
))
}
return mods
},
},
PhoneE164NotifyPhoneNuisances: modAs[Q, publicreportNotifyPhoneNuisanceColumns]{
c: PublicreportNotifyPhoneNuisances.Columns,
f: func(to publicreportNotifyPhoneNuisanceColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyPhoneNuisances.Name().As(to.Alias())).On(
to.PhoneE164.EQ(cols.E164),
))
}
return mods
},
},
PhoneE164NotifyPhonePools: modAs[Q, publicreportNotifyPhonePoolColumns]{
c: PublicreportNotifyPhonePools.Columns,
f: func(to publicreportNotifyPhonePoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyPhonePools.Name().As(to.Alias())).On(
to.PhoneE164.EQ(cols.E164),
))
}
return mods
},
},

View file

@ -0,0 +1,841 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyEmailNuisance is an object representing the database table.
type PublicreportNotifyEmailNuisance struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
NuisanceID int32 `db:"nuisance_id,pk" `
EmailAddress string `db:"email_address,pk" `
R publicreportNotifyEmailNuisanceR `db:"-" `
}
// PublicreportNotifyEmailNuisanceSlice is an alias for a slice of pointers to PublicreportNotifyEmailNuisance.
// This should almost always be used instead of []*PublicreportNotifyEmailNuisance.
type PublicreportNotifyEmailNuisanceSlice []*PublicreportNotifyEmailNuisance
// PublicreportNotifyEmailNuisances contains methods to work with the notify_email_nuisance table
var PublicreportNotifyEmailNuisances = psql.NewTablex[*PublicreportNotifyEmailNuisance, PublicreportNotifyEmailNuisanceSlice, *PublicreportNotifyEmailNuisanceSetter]("publicreport", "notify_email_nuisance", buildPublicreportNotifyEmailNuisanceColumns("publicreport.notify_email_nuisance"))
// PublicreportNotifyEmailNuisancesQuery is a query on the notify_email_nuisance table
type PublicreportNotifyEmailNuisancesQuery = *psql.ViewQuery[*PublicreportNotifyEmailNuisance, PublicreportNotifyEmailNuisanceSlice]
// publicreportNotifyEmailNuisanceR is where relationships are stored.
type publicreportNotifyEmailNuisanceR struct {
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey
Nuisance *PublicreportNuisance // publicreport.notify_email_nuisance.notify_email_nuisance_nuisance_id_fkey
}
func buildPublicreportNotifyEmailNuisanceColumns(alias string) publicreportNotifyEmailNuisanceColumns {
return publicreportNotifyEmailNuisanceColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "nuisance_id", "email_address",
).WithParent("publicreport.notify_email_nuisance"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
NuisanceID: psql.Quote(alias, "nuisance_id"),
EmailAddress: psql.Quote(alias, "email_address"),
}
}
type publicreportNotifyEmailNuisanceColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
NuisanceID psql.Expression
EmailAddress psql.Expression
}
func (c publicreportNotifyEmailNuisanceColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyEmailNuisanceColumns) AliasedAs(alias string) publicreportNotifyEmailNuisanceColumns {
return buildPublicreportNotifyEmailNuisanceColumns(alias)
}
// PublicreportNotifyEmailNuisanceSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyEmailNuisanceSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
NuisanceID omit.Val[int32] `db:"nuisance_id,pk" `
EmailAddress omit.Val[string] `db:"email_address,pk" `
}
func (s PublicreportNotifyEmailNuisanceSetter) SetColumns() []string {
vals := make([]string, 0, 4)
if s.Created.IsValue() {
vals = append(vals, "created")
}
if !s.Deleted.IsUnset() {
vals = append(vals, "deleted")
}
if s.NuisanceID.IsValue() {
vals = append(vals, "nuisance_id")
}
if s.EmailAddress.IsValue() {
vals = append(vals, "email_address")
}
return vals
}
func (s PublicreportNotifyEmailNuisanceSetter) Overwrite(t *PublicreportNotifyEmailNuisance) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.NuisanceID.IsValue() {
t.NuisanceID = s.NuisanceID.MustGet()
}
if s.EmailAddress.IsValue() {
t.EmailAddress = s.EmailAddress.MustGet()
}
}
func (s *PublicreportNotifyEmailNuisanceSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyEmailNuisances.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 4)
if s.Created.IsValue() {
vals[0] = psql.Arg(s.Created.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if !s.Deleted.IsUnset() {
vals[1] = psql.Arg(s.Deleted.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.NuisanceID.IsValue() {
vals[2] = psql.Arg(s.NuisanceID.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.EmailAddress.IsValue() {
vals[3] = psql.Arg(s.EmailAddress.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyEmailNuisanceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyEmailNuisanceSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 4)
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if !s.Deleted.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "deleted")...),
psql.Arg(s.Deleted),
}})
}
if s.NuisanceID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "nuisance_id")...),
psql.Arg(s.NuisanceID),
}})
}
if s.EmailAddress.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "email_address")...),
psql.Arg(s.EmailAddress),
}})
}
return exprs
}
// FindPublicreportNotifyEmailNuisance retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyEmailNuisance(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailNuisance, error) {
if len(cols) == 0 {
return PublicreportNotifyEmailNuisances.Query(
sm.Where(PublicreportNotifyEmailNuisances.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyEmailNuisances.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).One(ctx, exec)
}
return PublicreportNotifyEmailNuisances.Query(
sm.Where(PublicreportNotifyEmailNuisances.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyEmailNuisances.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
sm.Columns(PublicreportNotifyEmailNuisances.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyEmailNuisanceExists checks the presence of a single record by primary key
func PublicreportNotifyEmailNuisanceExists(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, EmailAddressPK string) (bool, error) {
return PublicreportNotifyEmailNuisances.Query(
sm.Where(PublicreportNotifyEmailNuisances.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyEmailNuisances.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyEmailNuisance is retrieved from the database
func (o *PublicreportNotifyEmailNuisance) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailNuisances.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailNuisances.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailNuisances.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailNuisances.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailNuisance
func (o *PublicreportNotifyEmailNuisance) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.NuisanceID,
o.EmailAddress,
)
}
func (o *PublicreportNotifyEmailNuisance) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_email_nuisance", "nuisance_id"), psql.Quote("publicreport.notify_email_nuisance", "email_address")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNotifyEmailNuisance
func (o *PublicreportNotifyEmailNuisance) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailNuisanceSetter) error {
v, err := PublicreportNotifyEmailNuisances.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 PublicreportNotifyEmailNuisance record with an executor
func (o *PublicreportNotifyEmailNuisance) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyEmailNuisances.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyEmailNuisance using the executor
func (o *PublicreportNotifyEmailNuisance) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyEmailNuisances.Query(
sm.Where(PublicreportNotifyEmailNuisances.Columns.NuisanceID.EQ(psql.Arg(o.NuisanceID))),
sm.Where(PublicreportNotifyEmailNuisances.Columns.EmailAddress.EQ(psql.Arg(o.EmailAddress))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportNotifyEmailNuisanceSlice is retrieved from the database
func (o PublicreportNotifyEmailNuisanceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailNuisances.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailNuisances.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailNuisances.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailNuisances.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyEmailNuisanceSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_email_nuisance", "nuisance_id"), psql.Quote("publicreport.notify_email_nuisance", "email_address")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNotifyEmailNuisanceSlice) copyMatchingRows(from ...*PublicreportNotifyEmailNuisance) {
for i, old := range o {
for _, new := range from {
if new.NuisanceID != old.NuisanceID {
continue
}
if new.EmailAddress != old.EmailAddress {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailNuisanceSlice) 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 PublicreportNotifyEmailNuisances.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 *PublicreportNotifyEmailNuisance:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailNuisance:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailNuisanceSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailNuisance or a slice of PublicreportNotifyEmailNuisance
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyEmailNuisances.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailNuisanceSlice) 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 PublicreportNotifyEmailNuisances.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 *PublicreportNotifyEmailNuisance:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailNuisance:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailNuisanceSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailNuisance or a slice of PublicreportNotifyEmailNuisance
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyEmailNuisances.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyEmailNuisanceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailNuisanceSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailNuisances.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyEmailNuisanceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailNuisances.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyEmailNuisanceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyEmailNuisances.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
func (o *PublicreportNotifyEmailNuisance) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
return CommsEmailContacts.Query(append(mods,
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
)...)
}
func (os PublicreportNotifyEmailNuisanceSlice) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
pkEmailAddress := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkEmailAddress = append(pkEmailAddress, o.EmailAddress)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkEmailAddress), "text[]")),
))
return CommsEmailContacts.Query(append(mods,
sm.Where(psql.Group(CommsEmailContacts.Columns.Address).OP("IN", PKArgExpr)),
)...)
}
// Nuisance starts a query for related objects on publicreport.nuisance
func (o *PublicreportNotifyEmailNuisance) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
return PublicreportNuisances.Query(append(mods,
sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(o.NuisanceID))),
)...)
}
func (os PublicreportNotifyEmailNuisanceSlice) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
pkNuisanceID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkNuisanceID = append(pkNuisanceID, o.NuisanceID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkNuisanceID), "integer[]")),
))
return PublicreportNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisances.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyEmailNuisanceEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisance0 *PublicreportNotifyEmailNuisance, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailNuisance, error) {
setter := &PublicreportNotifyEmailNuisanceSetter{
EmailAddress: omit.From(commsEmailContact1.Address),
}
err := publicreportNotifyEmailNuisance0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailNuisanceEmailAddressEmailContact0: %w", err)
}
return publicreportNotifyEmailNuisance0, nil
}
func (publicreportNotifyEmailNuisance0 *PublicreportNotifyEmailNuisance) 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 = attachPublicreportNotifyEmailNuisanceEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailNuisance0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailNuisance0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailNuisances = append(commsEmailContact1.R.EmailAddressNotifyEmailNuisances, publicreportNotifyEmailNuisance0)
return nil
}
func (publicreportNotifyEmailNuisance0 *PublicreportNotifyEmailNuisance) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
var err error
_, err = attachPublicreportNotifyEmailNuisanceEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailNuisance0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailNuisance0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailNuisances = append(commsEmailContact1.R.EmailAddressNotifyEmailNuisances, publicreportNotifyEmailNuisance0)
return nil
}
func attachPublicreportNotifyEmailNuisanceNuisance0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisance0 *PublicreportNotifyEmailNuisance, publicreportNuisance1 *PublicreportNuisance) (*PublicreportNotifyEmailNuisance, error) {
setter := &PublicreportNotifyEmailNuisanceSetter{
NuisanceID: omit.From(publicreportNuisance1.ID),
}
err := publicreportNotifyEmailNuisance0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailNuisanceNuisance0: %w", err)
}
return publicreportNotifyEmailNuisance0, nil
}
func (publicreportNotifyEmailNuisance0 *PublicreportNotifyEmailNuisance) InsertNuisance(ctx context.Context, exec bob.Executor, related *PublicreportNuisanceSetter) error {
var err error
publicreportNuisance1, err := PublicreportNuisances.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyEmailNuisanceNuisance0(ctx, exec, 1, publicreportNotifyEmailNuisance0, publicreportNuisance1)
if err != nil {
return err
}
publicreportNotifyEmailNuisance0.R.Nuisance = publicreportNuisance1
publicreportNuisance1.R.NotifyEmailNuisances = append(publicreportNuisance1.R.NotifyEmailNuisances, publicreportNotifyEmailNuisance0)
return nil
}
func (publicreportNotifyEmailNuisance0 *PublicreportNotifyEmailNuisance) AttachNuisance(ctx context.Context, exec bob.Executor, publicreportNuisance1 *PublicreportNuisance) error {
var err error
_, err = attachPublicreportNotifyEmailNuisanceNuisance0(ctx, exec, 1, publicreportNotifyEmailNuisance0, publicreportNuisance1)
if err != nil {
return err
}
publicreportNotifyEmailNuisance0.R.Nuisance = publicreportNuisance1
publicreportNuisance1.R.NotifyEmailNuisances = append(publicreportNuisance1.R.NotifyEmailNuisances, publicreportNotifyEmailNuisance0)
return nil
}
type publicreportNotifyEmailNuisanceWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
NuisanceID psql.WhereMod[Q, int32]
EmailAddress psql.WhereMod[Q, string]
}
func (publicreportNotifyEmailNuisanceWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailNuisanceWhere[Q] {
return buildPublicreportNotifyEmailNuisanceWhere[Q](buildPublicreportNotifyEmailNuisanceColumns(alias))
}
func buildPublicreportNotifyEmailNuisanceWhere[Q psql.Filterable](cols publicreportNotifyEmailNuisanceColumns) publicreportNotifyEmailNuisanceWhere[Q] {
return publicreportNotifyEmailNuisanceWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
NuisanceID: psql.Where[Q, int32](cols.NuisanceID),
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
}
}
func (o *PublicreportNotifyEmailNuisance) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "EmailAddressEmailContact":
rel, ok := retrieved.(*CommsEmailContact)
if !ok {
return fmt.Errorf("publicreportNotifyEmailNuisance cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressEmailContact = rel
if rel != nil {
rel.R.EmailAddressNotifyEmailNuisances = PublicreportNotifyEmailNuisanceSlice{o}
}
return nil
case "Nuisance":
rel, ok := retrieved.(*PublicreportNuisance)
if !ok {
return fmt.Errorf("publicreportNotifyEmailNuisance cannot load %T as %q", retrieved, name)
}
o.R.Nuisance = rel
if rel != nil {
rel.R.NotifyEmailNuisances = PublicreportNotifyEmailNuisanceSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyEmailNuisance has no relationship %q", name)
}
}
type publicreportNotifyEmailNuisancePreloader struct {
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
Nuisance func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyEmailNuisancePreloader() publicreportNotifyEmailNuisancePreloader {
return publicreportNotifyEmailNuisancePreloader{
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
Name: "EmailAddressEmailContact",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailNuisances,
To: CommsEmailContacts,
FromColumns: []string{"email_address"},
ToColumns: []string{"address"},
},
},
}, CommsEmailContacts.Columns.Names(), opts...)
},
Nuisance: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportNuisance, PublicreportNuisanceSlice](psql.PreloadRel{
Name: "Nuisance",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailNuisances,
To: PublicreportNuisances,
FromColumns: []string{"nuisance_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportNuisances.Columns.Names(), opts...)
},
}
}
type publicreportNotifyEmailNuisanceThenLoader[Q orm.Loadable] struct {
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Nuisance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyEmailNuisanceThenLoader[Q orm.Loadable]() publicreportNotifyEmailNuisanceThenLoader[Q] {
type EmailAddressEmailContactLoadInterface interface {
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisanceLoadInterface interface {
LoadNuisance(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyEmailNuisanceThenLoader[Q]{
EmailAddressEmailContact: thenLoadBuilder[Q](
"EmailAddressEmailContact",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressEmailContactLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressEmailContact(ctx, exec, mods...)
},
),
Nuisance: thenLoadBuilder[Q](
"Nuisance",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisance(ctx, exec, mods...)
},
),
}
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailNuisance's EmailAddressEmailContact into the .R struct
func (o *PublicreportNotifyEmailNuisance) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressEmailContact = nil
related, err := o.EmailAddressEmailContact(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.EmailAddressNotifyEmailNuisances = PublicreportNotifyEmailNuisanceSlice{o}
o.R.EmailAddressEmailContact = related
return nil
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailNuisance's EmailAddressEmailContact into the .R struct
func (os PublicreportNotifyEmailNuisanceSlice) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsEmailContacts, err := os.EmailAddressEmailContact(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsEmailContacts {
if !(o.EmailAddress == rel.Address) {
continue
}
rel.R.EmailAddressNotifyEmailNuisances = append(rel.R.EmailAddressNotifyEmailNuisances, o)
o.R.EmailAddressEmailContact = rel
break
}
}
return nil
}
// LoadNuisance loads the publicreportNotifyEmailNuisance's Nuisance into the .R struct
func (o *PublicreportNotifyEmailNuisance) LoadNuisance(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Nuisance = nil
related, err := o.Nuisance(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyEmailNuisances = PublicreportNotifyEmailNuisanceSlice{o}
o.R.Nuisance = related
return nil
}
// LoadNuisance loads the publicreportNotifyEmailNuisance's Nuisance into the .R struct
func (os PublicreportNotifyEmailNuisanceSlice) LoadNuisance(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisances, err := os.Nuisance(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNuisances {
if !(o.NuisanceID == rel.ID) {
continue
}
rel.R.NotifyEmailNuisances = append(rel.R.NotifyEmailNuisances, o)
o.R.Nuisance = rel
break
}
}
return nil
}
type publicreportNotifyEmailNuisanceJoins[Q dialect.Joinable] struct {
typ string
EmailAddressEmailContact modAs[Q, commsEmailContactColumns]
Nuisance modAs[Q, publicreportNuisanceColumns]
}
func (j publicreportNotifyEmailNuisanceJoins[Q]) aliasedAs(alias string) publicreportNotifyEmailNuisanceJoins[Q] {
return buildPublicreportNotifyEmailNuisanceJoins[Q](buildPublicreportNotifyEmailNuisanceColumns(alias), j.typ)
}
func buildPublicreportNotifyEmailNuisanceJoins[Q dialect.Joinable](cols publicreportNotifyEmailNuisanceColumns, typ string) publicreportNotifyEmailNuisanceJoins[Q] {
return publicreportNotifyEmailNuisanceJoins[Q]{
typ: typ,
EmailAddressEmailContact: modAs[Q, commsEmailContactColumns]{
c: CommsEmailContacts.Columns,
f: func(to commsEmailContactColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsEmailContacts.Name().As(to.Alias())).On(
to.Address.EQ(cols.EmailAddress),
))
}
return mods
},
},
Nuisance: modAs[Q, publicreportNuisanceColumns]{
c: PublicreportNuisances.Columns,
f: func(to publicreportNuisanceColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNuisances.Name().As(to.Alias())).On(
to.ID.EQ(cols.NuisanceID),
))
}
return mods
},
},
}
}

View file

@ -0,0 +1,841 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyEmailPool is an object representing the database table.
type PublicreportNotifyEmailPool struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
PoolID int32 `db:"pool_id,pk" `
EmailAddress string `db:"email_address,pk" `
R publicreportNotifyEmailPoolR `db:"-" `
}
// PublicreportNotifyEmailPoolSlice is an alias for a slice of pointers to PublicreportNotifyEmailPool.
// This should almost always be used instead of []*PublicreportNotifyEmailPool.
type PublicreportNotifyEmailPoolSlice []*PublicreportNotifyEmailPool
// PublicreportNotifyEmailPools contains methods to work with the notify_email_pool table
var PublicreportNotifyEmailPools = psql.NewTablex[*PublicreportNotifyEmailPool, PublicreportNotifyEmailPoolSlice, *PublicreportNotifyEmailPoolSetter]("publicreport", "notify_email_pool", buildPublicreportNotifyEmailPoolColumns("publicreport.notify_email_pool"))
// PublicreportNotifyEmailPoolsQuery is a query on the notify_email_pool table
type PublicreportNotifyEmailPoolsQuery = *psql.ViewQuery[*PublicreportNotifyEmailPool, PublicreportNotifyEmailPoolSlice]
// publicreportNotifyEmailPoolR is where relationships are stored.
type publicreportNotifyEmailPoolR struct {
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_pool.notify_email_pool_email_address_fkey
Pool *PublicreportPool // publicreport.notify_email_pool.notify_email_pool_pool_id_fkey
}
func buildPublicreportNotifyEmailPoolColumns(alias string) publicreportNotifyEmailPoolColumns {
return publicreportNotifyEmailPoolColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "pool_id", "email_address",
).WithParent("publicreport.notify_email_pool"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
PoolID: psql.Quote(alias, "pool_id"),
EmailAddress: psql.Quote(alias, "email_address"),
}
}
type publicreportNotifyEmailPoolColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
PoolID psql.Expression
EmailAddress psql.Expression
}
func (c publicreportNotifyEmailPoolColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyEmailPoolColumns) AliasedAs(alias string) publicreportNotifyEmailPoolColumns {
return buildPublicreportNotifyEmailPoolColumns(alias)
}
// PublicreportNotifyEmailPoolSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyEmailPoolSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
PoolID omit.Val[int32] `db:"pool_id,pk" `
EmailAddress omit.Val[string] `db:"email_address,pk" `
}
func (s PublicreportNotifyEmailPoolSetter) SetColumns() []string {
vals := make([]string, 0, 4)
if s.Created.IsValue() {
vals = append(vals, "created")
}
if !s.Deleted.IsUnset() {
vals = append(vals, "deleted")
}
if s.PoolID.IsValue() {
vals = append(vals, "pool_id")
}
if s.EmailAddress.IsValue() {
vals = append(vals, "email_address")
}
return vals
}
func (s PublicreportNotifyEmailPoolSetter) Overwrite(t *PublicreportNotifyEmailPool) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.PoolID.IsValue() {
t.PoolID = s.PoolID.MustGet()
}
if s.EmailAddress.IsValue() {
t.EmailAddress = s.EmailAddress.MustGet()
}
}
func (s *PublicreportNotifyEmailPoolSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyEmailPools.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 4)
if s.Created.IsValue() {
vals[0] = psql.Arg(s.Created.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if !s.Deleted.IsUnset() {
vals[1] = psql.Arg(s.Deleted.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.PoolID.IsValue() {
vals[2] = psql.Arg(s.PoolID.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.EmailAddress.IsValue() {
vals[3] = psql.Arg(s.EmailAddress.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyEmailPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyEmailPoolSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 4)
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if !s.Deleted.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "deleted")...),
psql.Arg(s.Deleted),
}})
}
if s.PoolID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "pool_id")...),
psql.Arg(s.PoolID),
}})
}
if s.EmailAddress.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "email_address")...),
psql.Arg(s.EmailAddress),
}})
}
return exprs
}
// FindPublicreportNotifyEmailPool retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyEmailPool(ctx context.Context, exec bob.Executor, PoolIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailPool, error) {
if len(cols) == 0 {
return PublicreportNotifyEmailPools.Query(
sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).One(ctx, exec)
}
return PublicreportNotifyEmailPools.Query(
sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
sm.Columns(PublicreportNotifyEmailPools.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyEmailPoolExists checks the presence of a single record by primary key
func PublicreportNotifyEmailPoolExists(ctx context.Context, exec bob.Executor, PoolIDPK int32, EmailAddressPK string) (bool, error) {
return PublicreportNotifyEmailPools.Query(
sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyEmailPool is retrieved from the database
func (o *PublicreportNotifyEmailPool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailPools.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailPools.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailPools.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailPools.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailPool
func (o *PublicreportNotifyEmailPool) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.PoolID,
o.EmailAddress,
)
}
func (o *PublicreportNotifyEmailPool) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_email_pool", "pool_id"), psql.Quote("publicreport.notify_email_pool", "email_address")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNotifyEmailPool
func (o *PublicreportNotifyEmailPool) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailPoolSetter) error {
v, err := PublicreportNotifyEmailPools.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 PublicreportNotifyEmailPool record with an executor
func (o *PublicreportNotifyEmailPool) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyEmailPools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyEmailPool using the executor
func (o *PublicreportNotifyEmailPool) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyEmailPools.Query(
sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(o.PoolID))),
sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(o.EmailAddress))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportNotifyEmailPoolSlice is retrieved from the database
func (o PublicreportNotifyEmailPoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailPools.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailPools.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailPools.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailPools.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyEmailPoolSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_email_pool", "pool_id"), psql.Quote("publicreport.notify_email_pool", "email_address")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNotifyEmailPoolSlice) copyMatchingRows(from ...*PublicreportNotifyEmailPool) {
for i, old := range o {
for _, new := range from {
if new.PoolID != old.PoolID {
continue
}
if new.EmailAddress != old.EmailAddress {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailPoolSlice) 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 PublicreportNotifyEmailPools.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 *PublicreportNotifyEmailPool:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailPool:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailPoolSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailPool or a slice of PublicreportNotifyEmailPool
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyEmailPools.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailPoolSlice) 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 PublicreportNotifyEmailPools.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 *PublicreportNotifyEmailPool:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailPool:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailPoolSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailPool or a slice of PublicreportNotifyEmailPool
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyEmailPools.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyEmailPoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailPoolSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailPools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyEmailPoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailPools.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyEmailPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyEmailPools.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
func (o *PublicreportNotifyEmailPool) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
return CommsEmailContacts.Query(append(mods,
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
)...)
}
func (os PublicreportNotifyEmailPoolSlice) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
pkEmailAddress := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkEmailAddress = append(pkEmailAddress, o.EmailAddress)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkEmailAddress), "text[]")),
))
return CommsEmailContacts.Query(append(mods,
sm.Where(psql.Group(CommsEmailContacts.Columns.Address).OP("IN", PKArgExpr)),
)...)
}
// Pool starts a query for related objects on publicreport.pool
func (o *PublicreportNotifyEmailPool) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
return PublicreportPools.Query(append(mods,
sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))),
)...)
}
func (os PublicreportNotifyEmailPoolSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
pkPoolID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkPoolID = append(pkPoolID, o.PoolID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")),
))
return PublicreportPools.Query(append(mods,
sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyEmailPoolEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailPool, error) {
setter := &PublicreportNotifyEmailPoolSetter{
EmailAddress: omit.From(commsEmailContact1.Address),
}
err := publicreportNotifyEmailPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailPoolEmailAddressEmailContact0: %w", err)
}
return publicreportNotifyEmailPool0, nil
}
func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) 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 = attachPublicreportNotifyEmailPoolEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailPool0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailPool0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailPools = append(commsEmailContact1.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPool0)
return nil
}
func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
var err error
_, err = attachPublicreportNotifyEmailPoolEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailPool0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailPool0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailPools = append(commsEmailContact1.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPool0)
return nil
}
func attachPublicreportNotifyEmailPoolPool0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool, publicreportPool1 *PublicreportPool) (*PublicreportNotifyEmailPool, error) {
setter := &PublicreportNotifyEmailPoolSetter{
PoolID: omit.From(publicreportPool1.ID),
}
err := publicreportNotifyEmailPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailPoolPool0: %w", err)
}
return publicreportNotifyEmailPool0, nil
}
func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error {
var err error
publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyEmailPoolPool0(ctx, exec, 1, publicreportNotifyEmailPool0, publicreportPool1)
if err != nil {
return err
}
publicreportNotifyEmailPool0.R.Pool = publicreportPool1
publicreportPool1.R.NotifyEmailPools = append(publicreportPool1.R.NotifyEmailPools, publicreportNotifyEmailPool0)
return nil
}
func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error {
var err error
_, err = attachPublicreportNotifyEmailPoolPool0(ctx, exec, 1, publicreportNotifyEmailPool0, publicreportPool1)
if err != nil {
return err
}
publicreportNotifyEmailPool0.R.Pool = publicreportPool1
publicreportPool1.R.NotifyEmailPools = append(publicreportPool1.R.NotifyEmailPools, publicreportNotifyEmailPool0)
return nil
}
type publicreportNotifyEmailPoolWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
PoolID psql.WhereMod[Q, int32]
EmailAddress psql.WhereMod[Q, string]
}
func (publicreportNotifyEmailPoolWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailPoolWhere[Q] {
return buildPublicreportNotifyEmailPoolWhere[Q](buildPublicreportNotifyEmailPoolColumns(alias))
}
func buildPublicreportNotifyEmailPoolWhere[Q psql.Filterable](cols publicreportNotifyEmailPoolColumns) publicreportNotifyEmailPoolWhere[Q] {
return publicreportNotifyEmailPoolWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
PoolID: psql.Where[Q, int32](cols.PoolID),
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
}
}
func (o *PublicreportNotifyEmailPool) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "EmailAddressEmailContact":
rel, ok := retrieved.(*CommsEmailContact)
if !ok {
return fmt.Errorf("publicreportNotifyEmailPool cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressEmailContact = rel
if rel != nil {
rel.R.EmailAddressNotifyEmailPools = PublicreportNotifyEmailPoolSlice{o}
}
return nil
case "Pool":
rel, ok := retrieved.(*PublicreportPool)
if !ok {
return fmt.Errorf("publicreportNotifyEmailPool cannot load %T as %q", retrieved, name)
}
o.R.Pool = rel
if rel != nil {
rel.R.NotifyEmailPools = PublicreportNotifyEmailPoolSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyEmailPool has no relationship %q", name)
}
}
type publicreportNotifyEmailPoolPreloader struct {
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
Pool func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyEmailPoolPreloader() publicreportNotifyEmailPoolPreloader {
return publicreportNotifyEmailPoolPreloader{
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
Name: "EmailAddressEmailContact",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailPools,
To: CommsEmailContacts,
FromColumns: []string{"email_address"},
ToColumns: []string{"address"},
},
},
}, CommsEmailContacts.Columns.Names(), opts...)
},
Pool: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{
Name: "Pool",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailPools,
To: PublicreportPools,
FromColumns: []string{"pool_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportPools.Columns.Names(), opts...)
},
}
}
type publicreportNotifyEmailPoolThenLoader[Q orm.Loadable] struct {
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyEmailPoolThenLoader[Q orm.Loadable]() publicreportNotifyEmailPoolThenLoader[Q] {
type EmailAddressEmailContactLoadInterface interface {
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PoolLoadInterface interface {
LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyEmailPoolThenLoader[Q]{
EmailAddressEmailContact: thenLoadBuilder[Q](
"EmailAddressEmailContact",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressEmailContactLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressEmailContact(ctx, exec, mods...)
},
),
Pool: thenLoadBuilder[Q](
"Pool",
func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPool(ctx, exec, mods...)
},
),
}
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailPool's EmailAddressEmailContact into the .R struct
func (o *PublicreportNotifyEmailPool) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressEmailContact = nil
related, err := o.EmailAddressEmailContact(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.EmailAddressNotifyEmailPools = PublicreportNotifyEmailPoolSlice{o}
o.R.EmailAddressEmailContact = related
return nil
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailPool's EmailAddressEmailContact into the .R struct
func (os PublicreportNotifyEmailPoolSlice) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsEmailContacts, err := os.EmailAddressEmailContact(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsEmailContacts {
if !(o.EmailAddress == rel.Address) {
continue
}
rel.R.EmailAddressNotifyEmailPools = append(rel.R.EmailAddressNotifyEmailPools, o)
o.R.EmailAddressEmailContact = rel
break
}
}
return nil
}
// LoadPool loads the publicreportNotifyEmailPool's Pool into the .R struct
func (o *PublicreportNotifyEmailPool) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Pool = nil
related, err := o.Pool(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyEmailPools = PublicreportNotifyEmailPoolSlice{o}
o.R.Pool = related
return nil
}
// LoadPool loads the publicreportNotifyEmailPool's Pool into the .R struct
func (os PublicreportNotifyEmailPoolSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportPools, err := os.Pool(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportPools {
if !(o.PoolID == rel.ID) {
continue
}
rel.R.NotifyEmailPools = append(rel.R.NotifyEmailPools, o)
o.R.Pool = rel
break
}
}
return nil
}
type publicreportNotifyEmailPoolJoins[Q dialect.Joinable] struct {
typ string
EmailAddressEmailContact modAs[Q, commsEmailContactColumns]
Pool modAs[Q, publicreportPoolColumns]
}
func (j publicreportNotifyEmailPoolJoins[Q]) aliasedAs(alias string) publicreportNotifyEmailPoolJoins[Q] {
return buildPublicreportNotifyEmailPoolJoins[Q](buildPublicreportNotifyEmailPoolColumns(alias), j.typ)
}
func buildPublicreportNotifyEmailPoolJoins[Q dialect.Joinable](cols publicreportNotifyEmailPoolColumns, typ string) publicreportNotifyEmailPoolJoins[Q] {
return publicreportNotifyEmailPoolJoins[Q]{
typ: typ,
EmailAddressEmailContact: modAs[Q, commsEmailContactColumns]{
c: CommsEmailContacts.Columns,
f: func(to commsEmailContactColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsEmailContacts.Name().As(to.Alias())).On(
to.Address.EQ(cols.EmailAddress),
))
}
return mods
},
},
Pool: modAs[Q, publicreportPoolColumns]{
c: PublicreportPools.Columns,
f: func(to publicreportPoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportPools.Name().As(to.Alias())).On(
to.ID.EQ(cols.PoolID),
))
}
return mods
},
},
}
}

View file

@ -0,0 +1,841 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyPhoneNuisance is an object representing the database table.
type PublicreportNotifyPhoneNuisance struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
NuisanceID int32 `db:"nuisance_id,pk" `
PhoneE164 string `db:"phone_e164,pk" `
R publicreportNotifyPhoneNuisanceR `db:"-" `
}
// PublicreportNotifyPhoneNuisanceSlice is an alias for a slice of pointers to PublicreportNotifyPhoneNuisance.
// This should almost always be used instead of []*PublicreportNotifyPhoneNuisance.
type PublicreportNotifyPhoneNuisanceSlice []*PublicreportNotifyPhoneNuisance
// PublicreportNotifyPhoneNuisances contains methods to work with the notify_phone_nuisance table
var PublicreportNotifyPhoneNuisances = psql.NewTablex[*PublicreportNotifyPhoneNuisance, PublicreportNotifyPhoneNuisanceSlice, *PublicreportNotifyPhoneNuisanceSetter]("publicreport", "notify_phone_nuisance", buildPublicreportNotifyPhoneNuisanceColumns("publicreport.notify_phone_nuisance"))
// PublicreportNotifyPhoneNuisancesQuery is a query on the notify_phone_nuisance table
type PublicreportNotifyPhoneNuisancesQuery = *psql.ViewQuery[*PublicreportNotifyPhoneNuisance, PublicreportNotifyPhoneNuisanceSlice]
// publicreportNotifyPhoneNuisanceR is where relationships are stored.
type publicreportNotifyPhoneNuisanceR struct {
Nuisance *PublicreportNuisance // publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey
PhoneE164Phone *CommsPhone // publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey
}
func buildPublicreportNotifyPhoneNuisanceColumns(alias string) publicreportNotifyPhoneNuisanceColumns {
return publicreportNotifyPhoneNuisanceColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "nuisance_id", "phone_e164",
).WithParent("publicreport.notify_phone_nuisance"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
NuisanceID: psql.Quote(alias, "nuisance_id"),
PhoneE164: psql.Quote(alias, "phone_e164"),
}
}
type publicreportNotifyPhoneNuisanceColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
NuisanceID psql.Expression
PhoneE164 psql.Expression
}
func (c publicreportNotifyPhoneNuisanceColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyPhoneNuisanceColumns) AliasedAs(alias string) publicreportNotifyPhoneNuisanceColumns {
return buildPublicreportNotifyPhoneNuisanceColumns(alias)
}
// PublicreportNotifyPhoneNuisanceSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyPhoneNuisanceSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
NuisanceID omit.Val[int32] `db:"nuisance_id,pk" `
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
}
func (s PublicreportNotifyPhoneNuisanceSetter) SetColumns() []string {
vals := make([]string, 0, 4)
if s.Created.IsValue() {
vals = append(vals, "created")
}
if !s.Deleted.IsUnset() {
vals = append(vals, "deleted")
}
if s.NuisanceID.IsValue() {
vals = append(vals, "nuisance_id")
}
if s.PhoneE164.IsValue() {
vals = append(vals, "phone_e164")
}
return vals
}
func (s PublicreportNotifyPhoneNuisanceSetter) Overwrite(t *PublicreportNotifyPhoneNuisance) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.NuisanceID.IsValue() {
t.NuisanceID = s.NuisanceID.MustGet()
}
if s.PhoneE164.IsValue() {
t.PhoneE164 = s.PhoneE164.MustGet()
}
}
func (s *PublicreportNotifyPhoneNuisanceSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyPhoneNuisances.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 4)
if s.Created.IsValue() {
vals[0] = psql.Arg(s.Created.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if !s.Deleted.IsUnset() {
vals[1] = psql.Arg(s.Deleted.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.NuisanceID.IsValue() {
vals[2] = psql.Arg(s.NuisanceID.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.PhoneE164.IsValue() {
vals[3] = psql.Arg(s.PhoneE164.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyPhoneNuisanceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyPhoneNuisanceSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 4)
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if !s.Deleted.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "deleted")...),
psql.Arg(s.Deleted),
}})
}
if s.NuisanceID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "nuisance_id")...),
psql.Arg(s.NuisanceID),
}})
}
if s.PhoneE164.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "phone_e164")...),
psql.Arg(s.PhoneE164),
}})
}
return exprs
}
// FindPublicreportNotifyPhoneNuisance retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyPhoneNuisance(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhoneNuisance, error) {
if len(cols) == 0 {
return PublicreportNotifyPhoneNuisances.Query(
sm.Where(PublicreportNotifyPhoneNuisances.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyPhoneNuisances.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).One(ctx, exec)
}
return PublicreportNotifyPhoneNuisances.Query(
sm.Where(PublicreportNotifyPhoneNuisances.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyPhoneNuisances.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
sm.Columns(PublicreportNotifyPhoneNuisances.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyPhoneNuisanceExists checks the presence of a single record by primary key
func PublicreportNotifyPhoneNuisanceExists(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, PhoneE164PK string) (bool, error) {
return PublicreportNotifyPhoneNuisances.Query(
sm.Where(PublicreportNotifyPhoneNuisances.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyPhoneNuisances.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyPhoneNuisance is retrieved from the database
func (o *PublicreportNotifyPhoneNuisance) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneNuisances.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneNuisances.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneNuisances.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneNuisances.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhoneNuisance
func (o *PublicreportNotifyPhoneNuisance) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.NuisanceID,
o.PhoneE164,
)
}
func (o *PublicreportNotifyPhoneNuisance) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_phone_nuisance", "nuisance_id"), psql.Quote("publicreport.notify_phone_nuisance", "phone_e164")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNotifyPhoneNuisance
func (o *PublicreportNotifyPhoneNuisance) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhoneNuisanceSetter) error {
v, err := PublicreportNotifyPhoneNuisances.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 PublicreportNotifyPhoneNuisance record with an executor
func (o *PublicreportNotifyPhoneNuisance) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyPhoneNuisances.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyPhoneNuisance using the executor
func (o *PublicreportNotifyPhoneNuisance) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyPhoneNuisances.Query(
sm.Where(PublicreportNotifyPhoneNuisances.Columns.NuisanceID.EQ(psql.Arg(o.NuisanceID))),
sm.Where(PublicreportNotifyPhoneNuisances.Columns.PhoneE164.EQ(psql.Arg(o.PhoneE164))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportNotifyPhoneNuisanceSlice is retrieved from the database
func (o PublicreportNotifyPhoneNuisanceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneNuisances.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneNuisances.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneNuisances.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneNuisances.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyPhoneNuisanceSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_phone_nuisance", "nuisance_id"), psql.Quote("publicreport.notify_phone_nuisance", "phone_e164")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNotifyPhoneNuisanceSlice) copyMatchingRows(from ...*PublicreportNotifyPhoneNuisance) {
for i, old := range o {
for _, new := range from {
if new.NuisanceID != old.NuisanceID {
continue
}
if new.PhoneE164 != old.PhoneE164 {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhoneNuisanceSlice) 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 PublicreportNotifyPhoneNuisances.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 *PublicreportNotifyPhoneNuisance:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneNuisance:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneNuisanceSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneNuisance or a slice of PublicreportNotifyPhoneNuisance
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyPhoneNuisances.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhoneNuisanceSlice) 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 PublicreportNotifyPhoneNuisances.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 *PublicreportNotifyPhoneNuisance:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneNuisance:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneNuisanceSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneNuisance or a slice of PublicreportNotifyPhoneNuisance
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyPhoneNuisances.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyPhoneNuisanceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhoneNuisanceSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneNuisances.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneNuisanceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneNuisances.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneNuisanceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyPhoneNuisances.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Nuisance starts a query for related objects on publicreport.nuisance
func (o *PublicreportNotifyPhoneNuisance) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
return PublicreportNuisances.Query(append(mods,
sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(o.NuisanceID))),
)...)
}
func (os PublicreportNotifyPhoneNuisanceSlice) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
pkNuisanceID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkNuisanceID = append(pkNuisanceID, o.NuisanceID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkNuisanceID), "integer[]")),
))
return PublicreportNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisances.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164Phone starts a query for related objects on comms.phone
func (o *PublicreportNotifyPhoneNuisance) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
)...)
}
func (os PublicreportNotifyPhoneNuisanceSlice) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
pkPhoneE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkPhoneE164 = append(pkPhoneE164, o.PhoneE164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkPhoneE164), "text[]")),
))
return CommsPhones.Query(append(mods,
sm.Where(psql.Group(CommsPhones.Columns.E164).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyPhoneNuisanceNuisance0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisance0 *PublicreportNotifyPhoneNuisance, publicreportNuisance1 *PublicreportNuisance) (*PublicreportNotifyPhoneNuisance, error) {
setter := &PublicreportNotifyPhoneNuisanceSetter{
NuisanceID: omit.From(publicreportNuisance1.ID),
}
err := publicreportNotifyPhoneNuisance0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneNuisanceNuisance0: %w", err)
}
return publicreportNotifyPhoneNuisance0, nil
}
func (publicreportNotifyPhoneNuisance0 *PublicreportNotifyPhoneNuisance) InsertNuisance(ctx context.Context, exec bob.Executor, related *PublicreportNuisanceSetter) error {
var err error
publicreportNuisance1, err := PublicreportNuisances.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyPhoneNuisanceNuisance0(ctx, exec, 1, publicreportNotifyPhoneNuisance0, publicreportNuisance1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisance0.R.Nuisance = publicreportNuisance1
publicreportNuisance1.R.NotifyPhoneNuisances = append(publicreportNuisance1.R.NotifyPhoneNuisances, publicreportNotifyPhoneNuisance0)
return nil
}
func (publicreportNotifyPhoneNuisance0 *PublicreportNotifyPhoneNuisance) AttachNuisance(ctx context.Context, exec bob.Executor, publicreportNuisance1 *PublicreportNuisance) error {
var err error
_, err = attachPublicreportNotifyPhoneNuisanceNuisance0(ctx, exec, 1, publicreportNotifyPhoneNuisance0, publicreportNuisance1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisance0.R.Nuisance = publicreportNuisance1
publicreportNuisance1.R.NotifyPhoneNuisances = append(publicreportNuisance1.R.NotifyPhoneNuisances, publicreportNotifyPhoneNuisance0)
return nil
}
func attachPublicreportNotifyPhoneNuisancePhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisance0 *PublicreportNotifyPhoneNuisance, commsPhone1 *CommsPhone) (*PublicreportNotifyPhoneNuisance, error) {
setter := &PublicreportNotifyPhoneNuisanceSetter{
PhoneE164: omit.From(commsPhone1.E164),
}
err := publicreportNotifyPhoneNuisance0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneNuisancePhoneE164Phone0: %w", err)
}
return publicreportNotifyPhoneNuisance0, nil
}
func (publicreportNotifyPhoneNuisance0 *PublicreportNotifyPhoneNuisance) 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 = attachPublicreportNotifyPhoneNuisancePhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneNuisance0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisance0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneNuisances = append(commsPhone1.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisance0)
return nil
}
func (publicreportNotifyPhoneNuisance0 *PublicreportNotifyPhoneNuisance) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachPublicreportNotifyPhoneNuisancePhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneNuisance0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisance0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneNuisances = append(commsPhone1.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisance0)
return nil
}
type publicreportNotifyPhoneNuisanceWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
NuisanceID psql.WhereMod[Q, int32]
PhoneE164 psql.WhereMod[Q, string]
}
func (publicreportNotifyPhoneNuisanceWhere[Q]) AliasedAs(alias string) publicreportNotifyPhoneNuisanceWhere[Q] {
return buildPublicreportNotifyPhoneNuisanceWhere[Q](buildPublicreportNotifyPhoneNuisanceColumns(alias))
}
func buildPublicreportNotifyPhoneNuisanceWhere[Q psql.Filterable](cols publicreportNotifyPhoneNuisanceColumns) publicreportNotifyPhoneNuisanceWhere[Q] {
return publicreportNotifyPhoneNuisanceWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
NuisanceID: psql.Where[Q, int32](cols.NuisanceID),
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
}
}
func (o *PublicreportNotifyPhoneNuisance) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Nuisance":
rel, ok := retrieved.(*PublicreportNuisance)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneNuisance cannot load %T as %q", retrieved, name)
}
o.R.Nuisance = rel
if rel != nil {
rel.R.NotifyPhoneNuisances = PublicreportNotifyPhoneNuisanceSlice{o}
}
return nil
case "PhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneNuisance cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164Phone = rel
if rel != nil {
rel.R.PhoneE164NotifyPhoneNuisances = PublicreportNotifyPhoneNuisanceSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyPhoneNuisance has no relationship %q", name)
}
}
type publicreportNotifyPhoneNuisancePreloader struct {
Nuisance func(...psql.PreloadOption) psql.Preloader
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyPhoneNuisancePreloader() publicreportNotifyPhoneNuisancePreloader {
return publicreportNotifyPhoneNuisancePreloader{
Nuisance: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportNuisance, PublicreportNuisanceSlice](psql.PreloadRel{
Name: "Nuisance",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneNuisances,
To: PublicreportNuisances,
FromColumns: []string{"nuisance_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportNuisances.Columns.Names(), opts...)
},
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneNuisances,
To: CommsPhones,
FromColumns: []string{"phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
}
}
type publicreportNotifyPhoneNuisanceThenLoader[Q orm.Loadable] struct {
Nuisance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyPhoneNuisanceThenLoader[Q orm.Loadable]() publicreportNotifyPhoneNuisanceThenLoader[Q] {
type NuisanceLoadInterface interface {
LoadNuisance(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164PhoneLoadInterface interface {
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyPhoneNuisanceThenLoader[Q]{
Nuisance: thenLoadBuilder[Q](
"Nuisance",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisance(ctx, exec, mods...)
},
),
PhoneE164Phone: thenLoadBuilder[Q](
"PhoneE164Phone",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164Phone(ctx, exec, mods...)
},
),
}
}
// LoadNuisance loads the publicreportNotifyPhoneNuisance's Nuisance into the .R struct
func (o *PublicreportNotifyPhoneNuisance) LoadNuisance(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Nuisance = nil
related, err := o.Nuisance(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyPhoneNuisances = PublicreportNotifyPhoneNuisanceSlice{o}
o.R.Nuisance = related
return nil
}
// LoadNuisance loads the publicreportNotifyPhoneNuisance's Nuisance into the .R struct
func (os PublicreportNotifyPhoneNuisanceSlice) LoadNuisance(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisances, err := os.Nuisance(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNuisances {
if !(o.NuisanceID == rel.ID) {
continue
}
rel.R.NotifyPhoneNuisances = append(rel.R.NotifyPhoneNuisances, o)
o.R.Nuisance = rel
break
}
}
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneNuisance's PhoneE164Phone into the .R struct
func (o *PublicreportNotifyPhoneNuisance) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164Phone = nil
related, err := o.PhoneE164Phone(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.PhoneE164NotifyPhoneNuisances = PublicreportNotifyPhoneNuisanceSlice{o}
o.R.PhoneE164Phone = related
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneNuisance's PhoneE164Phone into the .R struct
func (os PublicreportNotifyPhoneNuisanceSlice) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsPhones, err := os.PhoneE164Phone(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsPhones {
if !(o.PhoneE164 == rel.E164) {
continue
}
rel.R.PhoneE164NotifyPhoneNuisances = append(rel.R.PhoneE164NotifyPhoneNuisances, o)
o.R.PhoneE164Phone = rel
break
}
}
return nil
}
type publicreportNotifyPhoneNuisanceJoins[Q dialect.Joinable] struct {
typ string
Nuisance modAs[Q, publicreportNuisanceColumns]
PhoneE164Phone modAs[Q, commsPhoneColumns]
}
func (j publicreportNotifyPhoneNuisanceJoins[Q]) aliasedAs(alias string) publicreportNotifyPhoneNuisanceJoins[Q] {
return buildPublicreportNotifyPhoneNuisanceJoins[Q](buildPublicreportNotifyPhoneNuisanceColumns(alias), j.typ)
}
func buildPublicreportNotifyPhoneNuisanceJoins[Q dialect.Joinable](cols publicreportNotifyPhoneNuisanceColumns, typ string) publicreportNotifyPhoneNuisanceJoins[Q] {
return publicreportNotifyPhoneNuisanceJoins[Q]{
typ: typ,
Nuisance: modAs[Q, publicreportNuisanceColumns]{
c: PublicreportNuisances.Columns,
f: func(to publicreportNuisanceColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNuisances.Name().As(to.Alias())).On(
to.ID.EQ(cols.NuisanceID),
))
}
return mods
},
},
PhoneE164Phone: modAs[Q, commsPhoneColumns]{
c: CommsPhones.Columns,
f: func(to commsPhoneColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsPhones.Name().As(to.Alias())).On(
to.E164.EQ(cols.PhoneE164),
))
}
return mods
},
},
}
}

View file

@ -0,0 +1,841 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/bob/expr"
"github.com/Gleipnir-Technology/bob/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyPhonePool is an object representing the database table.
type PublicreportNotifyPhonePool struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
PhoneE164 string `db:"phone_e164,pk" `
PoolID int32 `db:"pool_id,pk" `
R publicreportNotifyPhonePoolR `db:"-" `
}
// PublicreportNotifyPhonePoolSlice is an alias for a slice of pointers to PublicreportNotifyPhonePool.
// This should almost always be used instead of []*PublicreportNotifyPhonePool.
type PublicreportNotifyPhonePoolSlice []*PublicreportNotifyPhonePool
// PublicreportNotifyPhonePools contains methods to work with the notify_phone_pool table
var PublicreportNotifyPhonePools = psql.NewTablex[*PublicreportNotifyPhonePool, PublicreportNotifyPhonePoolSlice, *PublicreportNotifyPhonePoolSetter]("publicreport", "notify_phone_pool", buildPublicreportNotifyPhonePoolColumns("publicreport.notify_phone_pool"))
// PublicreportNotifyPhonePoolsQuery is a query on the notify_phone_pool table
type PublicreportNotifyPhonePoolsQuery = *psql.ViewQuery[*PublicreportNotifyPhonePool, PublicreportNotifyPhonePoolSlice]
// publicreportNotifyPhonePoolR is where relationships are stored.
type publicreportNotifyPhonePoolR struct {
PhoneE164Phone *CommsPhone // publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey
Pool *PublicreportPool // publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey
}
func buildPublicreportNotifyPhonePoolColumns(alias string) publicreportNotifyPhonePoolColumns {
return publicreportNotifyPhonePoolColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "phone_e164", "pool_id",
).WithParent("publicreport.notify_phone_pool"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
PhoneE164: psql.Quote(alias, "phone_e164"),
PoolID: psql.Quote(alias, "pool_id"),
}
}
type publicreportNotifyPhonePoolColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
PhoneE164 psql.Expression
PoolID psql.Expression
}
func (c publicreportNotifyPhonePoolColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyPhonePoolColumns) AliasedAs(alias string) publicreportNotifyPhonePoolColumns {
return buildPublicreportNotifyPhonePoolColumns(alias)
}
// PublicreportNotifyPhonePoolSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyPhonePoolSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
PoolID omit.Val[int32] `db:"pool_id,pk" `
}
func (s PublicreportNotifyPhonePoolSetter) SetColumns() []string {
vals := make([]string, 0, 4)
if s.Created.IsValue() {
vals = append(vals, "created")
}
if !s.Deleted.IsUnset() {
vals = append(vals, "deleted")
}
if s.PhoneE164.IsValue() {
vals = append(vals, "phone_e164")
}
if s.PoolID.IsValue() {
vals = append(vals, "pool_id")
}
return vals
}
func (s PublicreportNotifyPhonePoolSetter) Overwrite(t *PublicreportNotifyPhonePool) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.PhoneE164.IsValue() {
t.PhoneE164 = s.PhoneE164.MustGet()
}
if s.PoolID.IsValue() {
t.PoolID = s.PoolID.MustGet()
}
}
func (s *PublicreportNotifyPhonePoolSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyPhonePools.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 4)
if s.Created.IsValue() {
vals[0] = psql.Arg(s.Created.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if !s.Deleted.IsUnset() {
vals[1] = psql.Arg(s.Deleted.MustGetNull())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.PhoneE164.IsValue() {
vals[2] = psql.Arg(s.PhoneE164.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.PoolID.IsValue() {
vals[3] = psql.Arg(s.PoolID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyPhonePoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyPhonePoolSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 4)
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if !s.Deleted.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "deleted")...),
psql.Arg(s.Deleted),
}})
}
if s.PhoneE164.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "phone_e164")...),
psql.Arg(s.PhoneE164),
}})
}
if s.PoolID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "pool_id")...),
psql.Arg(s.PoolID),
}})
}
return exprs
}
// FindPublicreportNotifyPhonePool retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyPhonePool(ctx context.Context, exec bob.Executor, PoolIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhonePool, error) {
if len(cols) == 0 {
return PublicreportNotifyPhonePools.Query(
sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).One(ctx, exec)
}
return PublicreportNotifyPhonePools.Query(
sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
sm.Columns(PublicreportNotifyPhonePools.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyPhonePoolExists checks the presence of a single record by primary key
func PublicreportNotifyPhonePoolExists(ctx context.Context, exec bob.Executor, PoolIDPK int32, PhoneE164PK string) (bool, error) {
return PublicreportNotifyPhonePools.Query(
sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))),
sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyPhonePool is retrieved from the database
func (o *PublicreportNotifyPhonePool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhonePools.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhonePools.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhonePools.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhonePools.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhonePool
func (o *PublicreportNotifyPhonePool) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.PoolID,
o.PhoneE164,
)
}
func (o *PublicreportNotifyPhonePool) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_phone_pool", "pool_id"), psql.Quote("publicreport.notify_phone_pool", "phone_e164")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNotifyPhonePool
func (o *PublicreportNotifyPhonePool) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhonePoolSetter) error {
v, err := PublicreportNotifyPhonePools.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 PublicreportNotifyPhonePool record with an executor
func (o *PublicreportNotifyPhonePool) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyPhonePools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyPhonePool using the executor
func (o *PublicreportNotifyPhonePool) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyPhonePools.Query(
sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(o.PoolID))),
sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(o.PhoneE164))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportNotifyPhonePoolSlice is retrieved from the database
func (o PublicreportNotifyPhonePoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhonePools.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhonePools.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhonePools.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhonePools.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyPhonePoolSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_phone_pool", "pool_id"), psql.Quote("publicreport.notify_phone_pool", "phone_e164")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNotifyPhonePoolSlice) copyMatchingRows(from ...*PublicreportNotifyPhonePool) {
for i, old := range o {
for _, new := range from {
if new.PoolID != old.PoolID {
continue
}
if new.PhoneE164 != old.PhoneE164 {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhonePoolSlice) 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 PublicreportNotifyPhonePools.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 *PublicreportNotifyPhonePool:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhonePool:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhonePoolSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhonePool or a slice of PublicreportNotifyPhonePool
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyPhonePools.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhonePoolSlice) 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 PublicreportNotifyPhonePools.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 *PublicreportNotifyPhonePool:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhonePool:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhonePoolSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhonePool or a slice of PublicreportNotifyPhonePool
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyPhonePools.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyPhonePoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhonePoolSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhonePools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyPhonePoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhonePools.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyPhonePoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyPhonePools.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
func (o *PublicreportNotifyPhonePool) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
)...)
}
func (os PublicreportNotifyPhonePoolSlice) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
pkPhoneE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkPhoneE164 = append(pkPhoneE164, o.PhoneE164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkPhoneE164), "text[]")),
))
return CommsPhones.Query(append(mods,
sm.Where(psql.Group(CommsPhones.Columns.E164).OP("IN", PKArgExpr)),
)...)
}
// Pool starts a query for related objects on publicreport.pool
func (o *PublicreportNotifyPhonePool) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
return PublicreportPools.Query(append(mods,
sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))),
)...)
}
func (os PublicreportNotifyPhonePoolSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
pkPoolID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkPoolID = append(pkPoolID, o.PoolID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")),
))
return PublicreportPools.Query(append(mods,
sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyPhonePoolPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool, commsPhone1 *CommsPhone) (*PublicreportNotifyPhonePool, error) {
setter := &PublicreportNotifyPhonePoolSetter{
PhoneE164: omit.From(commsPhone1.E164),
}
err := publicreportNotifyPhonePool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhonePoolPhoneE164Phone0: %w", err)
}
return publicreportNotifyPhonePool0, nil
}
func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) 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 = attachPublicreportNotifyPhonePoolPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhonePool0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhonePool0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhonePools = append(commsPhone1.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePool0)
return nil
}
func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachPublicreportNotifyPhonePoolPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhonePool0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhonePool0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhonePools = append(commsPhone1.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePool0)
return nil
}
func attachPublicreportNotifyPhonePoolPool0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool, publicreportPool1 *PublicreportPool) (*PublicreportNotifyPhonePool, error) {
setter := &PublicreportNotifyPhonePoolSetter{
PoolID: omit.From(publicreportPool1.ID),
}
err := publicreportNotifyPhonePool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhonePoolPool0: %w", err)
}
return publicreportNotifyPhonePool0, nil
}
func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error {
var err error
publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyPhonePoolPool0(ctx, exec, 1, publicreportNotifyPhonePool0, publicreportPool1)
if err != nil {
return err
}
publicreportNotifyPhonePool0.R.Pool = publicreportPool1
publicreportPool1.R.NotifyPhonePools = append(publicreportPool1.R.NotifyPhonePools, publicreportNotifyPhonePool0)
return nil
}
func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error {
var err error
_, err = attachPublicreportNotifyPhonePoolPool0(ctx, exec, 1, publicreportNotifyPhonePool0, publicreportPool1)
if err != nil {
return err
}
publicreportNotifyPhonePool0.R.Pool = publicreportPool1
publicreportPool1.R.NotifyPhonePools = append(publicreportPool1.R.NotifyPhonePools, publicreportNotifyPhonePool0)
return nil
}
type publicreportNotifyPhonePoolWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
PhoneE164 psql.WhereMod[Q, string]
PoolID psql.WhereMod[Q, int32]
}
func (publicreportNotifyPhonePoolWhere[Q]) AliasedAs(alias string) publicreportNotifyPhonePoolWhere[Q] {
return buildPublicreportNotifyPhonePoolWhere[Q](buildPublicreportNotifyPhonePoolColumns(alias))
}
func buildPublicreportNotifyPhonePoolWhere[Q psql.Filterable](cols publicreportNotifyPhonePoolColumns) publicreportNotifyPhonePoolWhere[Q] {
return publicreportNotifyPhonePoolWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
PoolID: psql.Where[Q, int32](cols.PoolID),
}
}
func (o *PublicreportNotifyPhonePool) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "PhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("publicreportNotifyPhonePool cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164Phone = rel
if rel != nil {
rel.R.PhoneE164NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o}
}
return nil
case "Pool":
rel, ok := retrieved.(*PublicreportPool)
if !ok {
return fmt.Errorf("publicreportNotifyPhonePool cannot load %T as %q", retrieved, name)
}
o.R.Pool = rel
if rel != nil {
rel.R.NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyPhonePool has no relationship %q", name)
}
}
type publicreportNotifyPhonePoolPreloader struct {
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
Pool func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyPhonePoolPreloader() publicreportNotifyPhonePoolPreloader {
return publicreportNotifyPhonePoolPreloader{
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhonePools,
To: CommsPhones,
FromColumns: []string{"phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
Pool: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{
Name: "Pool",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhonePools,
To: PublicreportPools,
FromColumns: []string{"pool_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportPools.Columns.Names(), opts...)
},
}
}
type publicreportNotifyPhonePoolThenLoader[Q orm.Loadable] struct {
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyPhonePoolThenLoader[Q orm.Loadable]() publicreportNotifyPhonePoolThenLoader[Q] {
type PhoneE164PhoneLoadInterface interface {
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PoolLoadInterface interface {
LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyPhonePoolThenLoader[Q]{
PhoneE164Phone: thenLoadBuilder[Q](
"PhoneE164Phone",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164Phone(ctx, exec, mods...)
},
),
Pool: thenLoadBuilder[Q](
"Pool",
func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPool(ctx, exec, mods...)
},
),
}
}
// LoadPhoneE164Phone loads the publicreportNotifyPhonePool's PhoneE164Phone into the .R struct
func (o *PublicreportNotifyPhonePool) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164Phone = nil
related, err := o.PhoneE164Phone(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.PhoneE164NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o}
o.R.PhoneE164Phone = related
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhonePool's PhoneE164Phone into the .R struct
func (os PublicreportNotifyPhonePoolSlice) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsPhones, err := os.PhoneE164Phone(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsPhones {
if !(o.PhoneE164 == rel.E164) {
continue
}
rel.R.PhoneE164NotifyPhonePools = append(rel.R.PhoneE164NotifyPhonePools, o)
o.R.PhoneE164Phone = rel
break
}
}
return nil
}
// LoadPool loads the publicreportNotifyPhonePool's Pool into the .R struct
func (o *PublicreportNotifyPhonePool) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Pool = nil
related, err := o.Pool(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o}
o.R.Pool = related
return nil
}
// LoadPool loads the publicreportNotifyPhonePool's Pool into the .R struct
func (os PublicreportNotifyPhonePoolSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportPools, err := os.Pool(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportPools {
if !(o.PoolID == rel.ID) {
continue
}
rel.R.NotifyPhonePools = append(rel.R.NotifyPhonePools, o)
o.R.Pool = rel
break
}
}
return nil
}
type publicreportNotifyPhonePoolJoins[Q dialect.Joinable] struct {
typ string
PhoneE164Phone modAs[Q, commsPhoneColumns]
Pool modAs[Q, publicreportPoolColumns]
}
func (j publicreportNotifyPhonePoolJoins[Q]) aliasedAs(alias string) publicreportNotifyPhonePoolJoins[Q] {
return buildPublicreportNotifyPhonePoolJoins[Q](buildPublicreportNotifyPhonePoolColumns(alias), j.typ)
}
func buildPublicreportNotifyPhonePoolJoins[Q dialect.Joinable](cols publicreportNotifyPhonePoolColumns, typ string) publicreportNotifyPhonePoolJoins[Q] {
return publicreportNotifyPhonePoolJoins[Q]{
typ: typ,
PhoneE164Phone: modAs[Q, commsPhoneColumns]{
c: CommsPhones.Columns,
f: func(to commsPhoneColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsPhones.Name().As(to.Alias())).On(
to.E164.EQ(cols.PhoneE164),
))
}
return mods
},
},
Pool: modAs[Q, publicreportPoolColumns]{
c: PublicreportPools.Columns,
f: func(to publicreportPoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportPools.Name().As(to.Alias())).On(
to.ID.EQ(cols.PoolID),
))
}
return mods
},
},
}
}

File diff suppressed because it is too large Load diff

View file

@ -62,6 +62,7 @@ type PublicreportPool struct {
HasBackyardPermission bool `db:"has_backyard_permission" `
IsReporterConfidential bool `db:"is_reporter_confidential" `
IsReporterOwner bool `db:"is_reporter_owner" `
ReporterContactConsent null.Val[bool] `db:"reporter_contact_consent" `
R publicreportPoolR `db:"-" `
@ -80,14 +81,16 @@ type PublicreportPoolsQuery = *psql.ViewQuery[*PublicreportPool, PublicreportPoo
// publicreportPoolR is where relationships are stored.
type publicreportPoolR struct {
Organization *Organization // publicreport.pool.pool_organization_id_fkey
Images PublicreportImageSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey
NotifyEmailPools PublicreportNotifyEmailPoolSlice // publicreport.notify_email_pool.notify_email_pool_pool_id_fkey
NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey
Organization *Organization // publicreport.pool.pool_organization_id_fkey
Images PublicreportImageSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey
}
func buildPublicreportPoolColumns(alias string) publicreportPoolColumns {
return publicreportPoolColumns{
ColumnsExpr: expr.NewColumnsExpr(
"id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address", "address_country", "address_post_code", "address_place", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "location", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "status", "organization_id", "has_backyard_permission", "is_reporter_confidential", "is_reporter_owner",
"id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address", "address_country", "address_post_code", "address_place", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "location", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "status", "organization_id", "has_backyard_permission", "is_reporter_confidential", "is_reporter_owner", "reporter_contact_consent",
).WithParent("publicreport.pool"),
tableAlias: alias,
ID: psql.Quote(alias, "id"),
@ -123,6 +126,7 @@ func buildPublicreportPoolColumns(alias string) publicreportPoolColumns {
HasBackyardPermission: psql.Quote(alias, "has_backyard_permission"),
IsReporterConfidential: psql.Quote(alias, "is_reporter_confidential"),
IsReporterOwner: psql.Quote(alias, "is_reporter_owner"),
ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"),
}
}
@ -162,6 +166,7 @@ type publicreportPoolColumns struct {
HasBackyardPermission psql.Expression
IsReporterConfidential psql.Expression
IsReporterOwner psql.Expression
ReporterContactConsent psql.Expression
}
func (c publicreportPoolColumns) Alias() string {
@ -209,10 +214,11 @@ type PublicreportPoolSetter struct {
HasBackyardPermission omit.Val[bool] `db:"has_backyard_permission" `
IsReporterConfidential omit.Val[bool] `db:"is_reporter_confidential" `
IsReporterOwner omit.Val[bool] `db:"is_reporter_owner" `
ReporterContactConsent omitnull.Val[bool] `db:"reporter_contact_consent" `
}
func (s PublicreportPoolSetter) SetColumns() []string {
vals := make([]string, 0, 33)
vals := make([]string, 0, 34)
if s.ID.IsValue() {
vals = append(vals, "id")
}
@ -312,6 +318,9 @@ func (s PublicreportPoolSetter) SetColumns() []string {
if s.IsReporterOwner.IsValue() {
vals = append(vals, "is_reporter_owner")
}
if !s.ReporterContactConsent.IsUnset() {
vals = append(vals, "reporter_contact_consent")
}
return vals
}
@ -415,6 +424,9 @@ func (s PublicreportPoolSetter) Overwrite(t *PublicreportPool) {
if s.IsReporterOwner.IsValue() {
t.IsReporterOwner = s.IsReporterOwner.MustGet()
}
if !s.ReporterContactConsent.IsUnset() {
t.ReporterContactConsent = s.ReporterContactConsent.MustGetNull()
}
}
func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) {
@ -423,7 +435,7 @@ func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) {
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
vals := make([]bob.Expression, 33)
vals := make([]bob.Expression, 34)
if s.ID.IsValue() {
vals[0] = psql.Arg(s.ID.MustGet())
} else {
@ -622,6 +634,12 @@ func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) {
vals[32] = psql.Raw("DEFAULT")
}
if !s.ReporterContactConsent.IsUnset() {
vals[33] = psql.Arg(s.ReporterContactConsent.MustGetNull())
} else {
vals[33] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
@ -631,7 +649,7 @@ func (s PublicreportPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
}
func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 33)
exprs := make([]bob.Expression, 0, 34)
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -864,6 +882,13 @@ func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression {
}})
}
if !s.ReporterContactConsent.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "reporter_contact_consent")...),
psql.Arg(s.ReporterContactConsent),
}})
}
return exprs
}
@ -1090,6 +1115,54 @@ func (o PublicreportPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor)
return nil
}
// NotifyEmailPools starts a query for related objects on publicreport.notify_email_pool
func (o *PublicreportPool) NotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery {
return PublicreportNotifyEmailPools.Query(append(mods,
sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(o.ID))),
)...)
}
func (os PublicreportPoolSlice) NotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkID = append(pkID, o.ID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportNotifyEmailPools.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailPools.Columns.PoolID).OP("IN", PKArgExpr)),
)...)
}
// NotifyPhonePools starts a query for related objects on publicreport.notify_phone_pool
func (o *PublicreportPool) NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery {
return PublicreportNotifyPhonePools.Query(append(mods,
sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(o.ID))),
)...)
}
func (os PublicreportPoolSlice) NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkID = append(pkID, o.ID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportNotifyPhonePools.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhonePools.Columns.PoolID).OP("IN", PKArgExpr)),
)...)
}
// Organization starts a query for related objects on organization
func (o *PublicreportPool) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
return Organizations.Query(append(mods,
@ -1143,6 +1216,142 @@ func (os PublicreportPoolSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) Pu
)...)
}
func insertPublicreportPoolNotifyEmailPools0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailPools1 []*PublicreportNotifyEmailPoolSetter, publicreportPool0 *PublicreportPool) (PublicreportNotifyEmailPoolSlice, error) {
for i := range publicreportNotifyEmailPools1 {
publicreportNotifyEmailPools1[i].PoolID = omit.From(publicreportPool0.ID)
}
ret, err := PublicreportNotifyEmailPools.Insert(bob.ToMods(publicreportNotifyEmailPools1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertPublicreportPoolNotifyEmailPools0: %w", err)
}
return ret, nil
}
func attachPublicreportPoolNotifyEmailPools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPools1 PublicreportNotifyEmailPoolSlice, publicreportPool0 *PublicreportPool) (PublicreportNotifyEmailPoolSlice, error) {
setter := &PublicreportNotifyEmailPoolSetter{
PoolID: omit.From(publicreportPool0.ID),
}
err := publicreportNotifyEmailPools1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportPoolNotifyEmailPools0: %w", err)
}
return publicreportNotifyEmailPools1, nil
}
func (publicreportPool0 *PublicreportPool) InsertNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPoolSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailPools1, err := insertPublicreportPoolNotifyEmailPools0(ctx, exec, related, publicreportPool0)
if err != nil {
return err
}
publicreportPool0.R.NotifyEmailPools = append(publicreportPool0.R.NotifyEmailPools, publicreportNotifyEmailPools1...)
for _, rel := range publicreportNotifyEmailPools1 {
rel.R.Pool = publicreportPool0
}
return nil
}
func (publicreportPool0 *PublicreportPool) AttachNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPool) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailPools1 := PublicreportNotifyEmailPoolSlice(related)
_, err = attachPublicreportPoolNotifyEmailPools0(ctx, exec, len(related), publicreportNotifyEmailPools1, publicreportPool0)
if err != nil {
return err
}
publicreportPool0.R.NotifyEmailPools = append(publicreportPool0.R.NotifyEmailPools, publicreportNotifyEmailPools1...)
for _, rel := range related {
rel.R.Pool = publicreportPool0
}
return nil
}
func insertPublicreportPoolNotifyPhonePools0(ctx context.Context, exec bob.Executor, publicreportNotifyPhonePools1 []*PublicreportNotifyPhonePoolSetter, publicreportPool0 *PublicreportPool) (PublicreportNotifyPhonePoolSlice, error) {
for i := range publicreportNotifyPhonePools1 {
publicreportNotifyPhonePools1[i].PoolID = omit.From(publicreportPool0.ID)
}
ret, err := PublicreportNotifyPhonePools.Insert(bob.ToMods(publicreportNotifyPhonePools1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertPublicreportPoolNotifyPhonePools0: %w", err)
}
return ret, nil
}
func attachPublicreportPoolNotifyPhonePools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePools1 PublicreportNotifyPhonePoolSlice, publicreportPool0 *PublicreportPool) (PublicreportNotifyPhonePoolSlice, error) {
setter := &PublicreportNotifyPhonePoolSetter{
PoolID: omit.From(publicreportPool0.ID),
}
err := publicreportNotifyPhonePools1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportPoolNotifyPhonePools0: %w", err)
}
return publicreportNotifyPhonePools1, nil
}
func (publicreportPool0 *PublicreportPool) InsertNotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePoolSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhonePools1, err := insertPublicreportPoolNotifyPhonePools0(ctx, exec, related, publicreportPool0)
if err != nil {
return err
}
publicreportPool0.R.NotifyPhonePools = append(publicreportPool0.R.NotifyPhonePools, publicreportNotifyPhonePools1...)
for _, rel := range publicreportNotifyPhonePools1 {
rel.R.Pool = publicreportPool0
}
return nil
}
func (publicreportPool0 *PublicreportPool) AttachNotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePool) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhonePools1 := PublicreportNotifyPhonePoolSlice(related)
_, err = attachPublicreportPoolNotifyPhonePools0(ctx, exec, len(related), publicreportNotifyPhonePools1, publicreportPool0)
if err != nil {
return err
}
publicreportPool0.R.NotifyPhonePools = append(publicreportPool0.R.NotifyPhonePools, publicreportNotifyPhonePools1...)
for _, rel := range related {
rel.R.Pool = publicreportPool0
}
return nil
}
func attachPublicreportPoolOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportPool0 *PublicreportPool, organization1 *Organization) (*PublicreportPool, error) {
setter := &PublicreportPoolSetter{
OrganizationID: omitnull.From(organization1.ID),
@ -1290,6 +1499,7 @@ type publicreportPoolWhere[Q psql.Filterable] struct {
HasBackyardPermission psql.WhereMod[Q, bool]
IsReporterConfidential psql.WhereMod[Q, bool]
IsReporterOwner psql.WhereMod[Q, bool]
ReporterContactConsent psql.WhereNullMod[Q, bool]
}
func (publicreportPoolWhere[Q]) AliasedAs(alias string) publicreportPoolWhere[Q] {
@ -1331,6 +1541,7 @@ func buildPublicreportPoolWhere[Q psql.Filterable](cols publicreportPoolColumns)
HasBackyardPermission: psql.Where[Q, bool](cols.HasBackyardPermission),
IsReporterConfidential: psql.Where[Q, bool](cols.IsReporterConfidential),
IsReporterOwner: psql.Where[Q, bool](cols.IsReporterOwner),
ReporterContactConsent: psql.WhereNull[Q, bool](cols.ReporterContactConsent),
}
}
@ -1340,6 +1551,34 @@ func (o *PublicreportPool) Preload(name string, retrieved any) error {
}
switch name {
case "NotifyEmailPools":
rels, ok := retrieved.(PublicreportNotifyEmailPoolSlice)
if !ok {
return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name)
}
o.R.NotifyEmailPools = rels
for _, rel := range rels {
if rel != nil {
rel.R.Pool = o
}
}
return nil
case "NotifyPhonePools":
rels, ok := retrieved.(PublicreportNotifyPhonePoolSlice)
if !ok {
return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name)
}
o.R.NotifyPhonePools = rels
for _, rel := range rels {
if rel != nil {
rel.R.Pool = o
}
}
return nil
case "Organization":
rel, ok := retrieved.(*Organization)
if !ok {
@ -1394,11 +1633,19 @@ func buildPublicreportPoolPreloader() publicreportPoolPreloader {
}
type publicreportPoolThenLoader[Q orm.Loadable] struct {
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoader[Q] {
type NotifyEmailPoolsLoadInterface interface {
LoadNotifyEmailPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NotifyPhonePoolsLoadInterface interface {
LoadNotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type OrganizationLoadInterface interface {
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
@ -1407,6 +1654,18 @@ func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoade
}
return publicreportPoolThenLoader[Q]{
NotifyEmailPools: thenLoadBuilder[Q](
"NotifyEmailPools",
func(ctx context.Context, exec bob.Executor, retrieved NotifyEmailPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNotifyEmailPools(ctx, exec, mods...)
},
),
NotifyPhonePools: thenLoadBuilder[Q](
"NotifyPhonePools",
func(ctx context.Context, exec bob.Executor, retrieved NotifyPhonePoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNotifyPhonePools(ctx, exec, mods...)
},
),
Organization: thenLoadBuilder[Q](
"Organization",
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
@ -1422,6 +1681,128 @@ func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoade
}
}
// LoadNotifyEmailPools loads the publicreportPool's NotifyEmailPools into the .R struct
func (o *PublicreportPool) LoadNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.NotifyEmailPools = nil
related, err := o.NotifyEmailPools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Pool = o
}
o.R.NotifyEmailPools = related
return nil
}
// LoadNotifyEmailPools loads the publicreportPool's NotifyEmailPools into the .R struct
func (os PublicreportPoolSlice) LoadNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyEmailPools, err := os.NotifyEmailPools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.NotifyEmailPools = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyEmailPools {
if !(o.ID == rel.PoolID) {
continue
}
rel.R.Pool = o
o.R.NotifyEmailPools = append(o.R.NotifyEmailPools, rel)
}
}
return nil
}
// LoadNotifyPhonePools loads the publicreportPool's NotifyPhonePools into the .R struct
func (o *PublicreportPool) LoadNotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.NotifyPhonePools = nil
related, err := o.NotifyPhonePools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Pool = o
}
o.R.NotifyPhonePools = related
return nil
}
// LoadNotifyPhonePools loads the publicreportPool's NotifyPhonePools into the .R struct
func (os PublicreportPoolSlice) LoadNotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhonePools, err := os.NotifyPhonePools(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.NotifyPhonePools = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyPhonePools {
if !(o.ID == rel.PoolID) {
continue
}
rel.R.Pool = o
o.R.NotifyPhonePools = append(o.R.NotifyPhonePools, rel)
}
}
return nil
}
// LoadOrganization loads the publicreportPool's Organization into the .R struct
func (o *PublicreportPool) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
@ -1560,7 +1941,9 @@ func (os PublicreportPoolSlice) LoadImages(ctx context.Context, exec bob.Executo
// publicreportPoolC is where relationship counts are stored.
type publicreportPoolC struct {
Images *int64
NotifyEmailPools *int64
NotifyPhonePools *int64
Images *int64
}
// PreloadCount sets a count in the C struct by name
@ -1570,6 +1953,10 @@ func (o *PublicreportPool) PreloadCount(name string, count int64) error {
}
switch name {
case "NotifyEmailPools":
o.C.NotifyEmailPools = &count
case "NotifyPhonePools":
o.C.NotifyPhonePools = &count
case "Images":
o.C.Images = &count
}
@ -1577,11 +1964,47 @@ func (o *PublicreportPool) PreloadCount(name string, count int64) error {
}
type publicreportPoolCountPreloader struct {
Images func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
NotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
Images func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
}
func buildPublicreportPoolCountPreloader() publicreportPoolCountPreloader {
return publicreportPoolCountPreloader{
NotifyEmailPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*PublicreportPool]("NotifyEmailPools", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = PublicreportPools.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyEmailPools.Name()),
sm.Where(psql.Quote(PublicreportNotifyEmailPools.Alias(), "pool_id").EQ(psql.Quote(parent, "id"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
NotifyPhonePools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*PublicreportPool]("NotifyPhonePools", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
if parent == "" {
parent = PublicreportPools.Alias()
}
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
sm.Columns(psql.Raw("count(*)")),
sm.From(PublicreportNotifyPhonePools.Name()),
sm.Where(psql.Quote(PublicreportNotifyPhonePools.Alias(), "pool_id").EQ(psql.Quote(parent, "id"))),
}
subqueryMods = append(subqueryMods, mods...)
return psql.Group(psql.Select(subqueryMods...).Expression)
})
},
Images: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
return countPreloader[*PublicreportPool]("Images", func(parent string) bob.Expression {
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
@ -1606,15 +2029,35 @@ func buildPublicreportPoolCountPreloader() publicreportPoolCountPreloader {
}
type publicreportPoolCountThenLoader[Q orm.Loadable] struct {
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportPoolCountThenLoader[Q orm.Loadable]() publicreportPoolCountThenLoader[Q] {
type NotifyEmailPoolsCountInterface interface {
LoadCountNotifyEmailPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NotifyPhonePoolsCountInterface interface {
LoadCountNotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ImagesCountInterface interface {
LoadCountImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportPoolCountThenLoader[Q]{
NotifyEmailPools: countThenLoadBuilder[Q](
"NotifyEmailPools",
func(ctx context.Context, exec bob.Executor, retrieved NotifyEmailPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountNotifyEmailPools(ctx, exec, mods...)
},
),
NotifyPhonePools: countThenLoadBuilder[Q](
"NotifyPhonePools",
func(ctx context.Context, exec bob.Executor, retrieved NotifyPhonePoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCountNotifyPhonePools(ctx, exec, mods...)
},
),
Images: countThenLoadBuilder[Q](
"Images",
func(ctx context.Context, exec bob.Executor, retrieved ImagesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
@ -1624,6 +2067,66 @@ func buildPublicreportPoolCountThenLoader[Q orm.Loadable]() publicreportPoolCoun
}
}
// LoadCountNotifyEmailPools loads the count of NotifyEmailPools into the C struct
func (o *PublicreportPool) LoadCountNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.NotifyEmailPools(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.NotifyEmailPools = &count
return nil
}
// LoadCountNotifyEmailPools loads the count of NotifyEmailPools for a slice
func (os PublicreportPoolSlice) LoadCountNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountNotifyEmailPools(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountNotifyPhonePools loads the count of NotifyPhonePools into the C struct
func (o *PublicreportPool) LoadCountNotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
count, err := o.NotifyPhonePools(mods...).Count(ctx, exec)
if err != nil {
return err
}
o.C.NotifyPhonePools = &count
return nil
}
// LoadCountNotifyPhonePools loads the count of NotifyPhonePools for a slice
func (os PublicreportPoolSlice) LoadCountNotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
for _, o := range os {
if err := o.LoadCountNotifyPhonePools(ctx, exec, mods...); err != nil {
return err
}
}
return nil
}
// LoadCountImages loads the count of Images into the C struct
func (o *PublicreportPool) LoadCountImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
@ -1655,9 +2158,11 @@ func (os PublicreportPoolSlice) LoadCountImages(ctx context.Context, exec bob.Ex
}
type publicreportPoolJoins[Q dialect.Joinable] struct {
typ string
Organization modAs[Q, organizationColumns]
Images modAs[Q, publicreportImageColumns]
typ string
NotifyEmailPools modAs[Q, publicreportNotifyEmailPoolColumns]
NotifyPhonePools modAs[Q, publicreportNotifyPhonePoolColumns]
Organization modAs[Q, organizationColumns]
Images modAs[Q, publicreportImageColumns]
}
func (j publicreportPoolJoins[Q]) aliasedAs(alias string) publicreportPoolJoins[Q] {
@ -1667,6 +2172,34 @@ func (j publicreportPoolJoins[Q]) aliasedAs(alias string) publicreportPoolJoins[
func buildPublicreportPoolJoins[Q dialect.Joinable](cols publicreportPoolColumns, typ string) publicreportPoolJoins[Q] {
return publicreportPoolJoins[Q]{
typ: typ,
NotifyEmailPools: modAs[Q, publicreportNotifyEmailPoolColumns]{
c: PublicreportNotifyEmailPools.Columns,
f: func(to publicreportNotifyEmailPoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyEmailPools.Name().As(to.Alias())).On(
to.PoolID.EQ(cols.ID),
))
}
return mods
},
},
NotifyPhonePools: modAs[Q, publicreportNotifyPhonePoolColumns]{
c: PublicreportNotifyPhonePools.Columns,
f: func(to publicreportNotifyPhonePoolColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, PublicreportNotifyPhonePools.Name().As(to.Alias())).On(
to.PoolID.EQ(cols.ID),
))
}
return mods
},
},
Organization: modAs[Q, organizationColumns]{
c: Organizations.Columns,
f: func(to organizationColumns) bob.Mod[Q] {

View file

@ -22,7 +22,7 @@ import (
//go:embed publicreport_image_with_json_by_nuisance_id.bob.sql
var formattedQueries_publicreport_image_with_json_by_nuisance_id string
var publicreportImageWithJSONByNuisanceIDSQL = formattedQueries_publicreport_image_with_json_by_nuisance_id[175:983]
var publicreportImageWithJSONByNuisanceIDSQL = formattedQueries_publicreport_image_with_json_by_nuisance_id[175:999]
type PublicreportImageWithJSONByNuisanceIDQuery = orm.ModQuery[*dialect.SelectQuery, publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer]
@ -60,9 +60,9 @@ func PublicreportImageWithJSONByNuisanceID(NuisanceID int32) *PublicreportImageW
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(9, 549))
q.SetTable(expressionTypArgs.subExpr(555, 751))
q.AppendWhere(expressionTypArgs.subExpr(759, 807))
q.AppendSelect(expressionTypArgs.subExpr(9, 565))
q.SetTable(expressionTypArgs.subExpr(571, 767))
q.AppendWhere(expressionTypArgs.subExpr(775, 823))
}),
}
}
@ -90,8 +90,8 @@ func (o publicreportImageWithJSONByNuisanceID) args() iter.Seq[orm.ArgWithPositi
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "nuisanceID",
Start: 805,
Stop: 807,
Start: 821,
Stop: 823,
Expression: o.NuisanceID,
}) {
return

View file

@ -20,7 +20,7 @@ import (
//go:embed publicreport_publicid_table.bob.sql
var formattedQueries_publicreport_publicid_table string
var publicreportIDTableSQL = formattedQueries_publicreport_publicid_table[157:624]
var publicreportIDTableSQL = formattedQueries_publicreport_publicid_table[157:638]
type PublicreportIDTableQuery = orm.ModQuery[*dialect.SelectQuery, publicreportIDTable, PublicreportIDTableRow, []PublicreportIDTableRow, publicreportIDTableTransformer]
@ -43,6 +43,7 @@ func PublicreportIDTable(PublicID string) *PublicreportIDTableQuery {
var t PublicreportIDTableRow
row.ScheduleScanByIndex(0, &t.ExistsSomewhere)
row.ScheduleScanByIndex(1, &t.FoundInTables)
row.ScheduleScanByIndex(2, &t.ReportIds)
return &t, nil
}, func(v any) (PublicreportIDTableRow, error) {
return *(v.(*PublicreportIDTableRow)), nil
@ -50,9 +51,9 @@ func PublicreportIDTable(PublicID string) *PublicreportIDTableQuery {
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendCTE(expressionTypArgs.subExpr(5, 335))
q.AppendSelect(expressionTypArgs.subExpr(348, 449))
q.SetTable(expressionTypArgs.subExpr(455, 467))
q.AppendCTE(expressionTypArgs.subExpr(5, 325))
q.AppendSelect(expressionTypArgs.subExpr(335, 463))
q.SetTable(expressionTypArgs.subExpr(469, 481))
}),
}
}
@ -60,6 +61,7 @@ func PublicreportIDTable(PublicID string) *PublicreportIDTableQuery {
type PublicreportIDTableRow = struct {
ExistsSomewhere bool `db:"exists_somewhere"`
FoundInTables pq.StringArray `db:"found_in_tables"`
ReportIds pq.StringArray `db:"report_ids"`
}
type publicreportIDTableTransformer = bob.SliceTransformer[PublicreportIDTableRow, []PublicreportIDTableRow]
@ -81,8 +83,8 @@ func (o publicreportIDTable) args() iter.Seq[orm.ArgWithPosition] {
if !yield(orm.ArgWithPosition{
Name: "publicID",
Start: 221,
Stop: 223,
Start: 217,
Stop: 219,
Expression: o.PublicID,
}) {
return
@ -90,8 +92,8 @@ func (o publicreportIDTable) args() iter.Seq[orm.ArgWithPosition] {
if !yield(orm.ArgWithPosition{
Name: "publicID",
Start: 331,
Stop: 333,
Start: 321,
Stop: 323,
Expression: o.PublicID,
}) {
return

View file

@ -3,23 +3,29 @@
-- PublicreportIDTable
WITH found_tables AS (
SELECT 'nuisance' as table_name
FROM publicreport.nuisance
WHERE public_id = $1
SELECT
'nuisance' as table_name,
id
FROM publicreport.nuisance
WHERE public_id = $1
UNION ALL
UNION ALL
SELECT 'pool' as table_name
FROM publicreport.pool
WHERE public_id = $2
SELECT
'pool' as table_name,
id
FROM publicreport.pool
WHERE public_id = $2
UNION ALL
UNION ALL
SELECT 'quick' as table_name
FROM publicreport.quick
WHERE public_id = $3
SELECT 'quick' as table_name,
id
FROM publicreport.quick
WHERE public_id = $3
)
SELECT
EXISTS (SELECT 1 FROM found_tables) as exists_somewhere,
array_agg(table_name) as found_in_tables
EXISTS (SELECT 1 FROM found_tables) as exists_somewhere,
array_agg(table_name) as found_in_tables,
array_agg(id) as report_ids
FROM found_tables;

View file

@ -1,22 +1,28 @@
-- PublicreportIDTable
WITH found_tables AS (
SELECT 'nuisance' as table_name
FROM publicreport.nuisance
WHERE public_id = $1
SELECT
'nuisance' as table_name,
id
FROM publicreport.nuisance
WHERE public_id = $1
UNION ALL
UNION ALL
SELECT 'pool' as table_name
FROM publicreport.pool
WHERE public_id = $1
SELECT
'pool' as table_name,
id
FROM publicreport.pool
WHERE public_id = $1
UNION ALL
UNION ALL
SELECT 'quick' as table_name
FROM publicreport.quick
WHERE public_id = $1
SELECT 'quick' as table_name,
id
FROM publicreport.quick
WHERE public_id = $1
)
SELECT
EXISTS (SELECT 1 FROM found_tables) as exists_somewhere,
array_agg(table_name) as found_in_tables
EXISTS (SELECT 1 FROM found_tables) as exists_somewhere,
array_agg(table_name) as found_in_tables,
array_agg(id) as report_ids
FROM found_tables;

View file

@ -0,0 +1,33 @@
package report
import (
"fmt"
)
type ErrorWithCode struct {
code string
err error
message string
}
func (e *ErrorWithCode) Code() string {
return e.code
}
func (e *ErrorWithCode) Error() string {
return e.message
}
func newErrorWithCode(code string, format string, args ...any) *ErrorWithCode {
if len(args) > 0 {
return &ErrorWithCode{
err: fmt.Errorf(format, args...),
code: code,
}
} else {
return &ErrorWithCode{
code: code,
err: nil,
message: format,
}
}
}

View file

@ -5,119 +5,25 @@ import (
"crypto/rand"
"fmt"
"math/big"
"strconv"
"strings"
//"time"
//"github.com/aarondl/opt/omit"
//"github.com/aarondl/opt/omitnull"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
//"github.com/Gleipnir-Technology/bob/dialect/psql"
//"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
//"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/Gleipnir-Technology/nidus-sync/background"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/db/sql"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
//"github.com/stephenafamo/scan"
)
type ErrorWithCode struct {
code string
err error
message string
}
func (e *ErrorWithCode) Code() string {
return e.code
}
func (e *ErrorWithCode) Error() string {
return e.message
}
type SomeReport struct {
reportID string
tableName string
}
func (sr SomeReport) districtID(ctx context.Context) *int32 {
type _Row struct {
OrganizationID *int32
}
from := sm.From("no-such-table")
switch sr.tableName {
case "nuisance":
from = sm.From("publicreport.nuisance")
case "pool":
from = sm.From("publicreport.pool")
default:
log.Error().Str("table-name", sr.tableName).Msg("Programmer error, non-exhaustive switch statement in SomeReport.districtID")
}
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
from,
sm.Columns("organization_id"),
sm.Where(psql.Quote("public_id").EQ(psql.Arg(sr.reportID))),
), scan.StructMapper[_Row]())
if err != nil {
log.Warn().Err(err).Msg("Failed to query for organization_id")
return nil
}
return row.OrganizationID
}
func (sr SomeReport) updateReporterEmail(ctx context.Context, email string) *ErrorWithCode {
table := um.Table("so-such-table")
switch sr.tableName {
case "nuisance":
table = um.Table("publicreport.nuisance")
case "pool":
table = um.Table("publicreport.pool")
default:
return newErrorWithCode("internal-error", "Programmer error: unrecognized table")
}
result, err := psql.Update(
table,
um.SetCol("reporter_email").ToArg(email),
um.Where(psql.Quote("public_id").EQ(psql.Arg(sr.reportID))),
).Exec(ctx, db.PGInstance.BobDB)
if err != nil {
return newErrorWithCode("internal-error", "Failed to update report: %w", err)
}
rowcount, err := result.RowsAffected()
if err != nil {
return newErrorWithCode("internal-error", "Failed to get rows affected: %w", err)
}
if rowcount != 1 {
log.Warn().Str("report_id", sr.reportID).Msg("updated more than one row, which is a programmer error")
}
return nil
}
func (sr SomeReport) updateReporterPhone(ctx context.Context, phone text.E164) *ErrorWithCode {
table := um.Table("so-such-table")
switch sr.tableName {
case "nuisance":
table = um.Table("publicreport.nuisance")
case "pool":
table = um.Table("publicreport.pool")
default:
return newErrorWithCode("internal-error", "Programmer error: unrecognized table")
}
result, err := psql.Update(
table,
um.SetCol("reporter_phone").ToArg(text.PhoneString(phone)),
um.Where(psql.Quote("public_id").EQ(psql.Arg(sr.reportID))),
).Exec(ctx, db.PGInstance.BobDB)
if err != nil {
return newErrorWithCode("internal-error", "Failed to update report: %w", err)
}
rowcount, err := result.RowsAffected()
if err != nil {
return newErrorWithCode("internal-error", "Failed to get rows affected: %w", err)
}
if rowcount != 1 {
log.Warn().Str("report_id", sr.reportID).Msg("updated more than one row, which is a programmer error")
}
return nil
}
func DistrictForReport(ctx context.Context, report_id string) (*models.Organization, error) {
some_report, err := findSomeReport(ctx, report_id)
if err != nil {
@ -159,12 +65,12 @@ func GenerateReportID() (string, error) {
return builder.String(), nil
}
func RegisterNotificationEmail(ctx context.Context, report_id string, email string) *ErrorWithCode {
func RegisterNotificationEmail(ctx context.Context, txn bob.Tx, report_id string, email string) *ErrorWithCode {
some_report, err := findSomeReport(ctx, report_id)
if err != nil {
return err
}
err = some_report.updateReporterEmail(ctx, email)
err = some_report.addNotificationEmail(ctx, txn, email)
if err != nil {
return err
}
@ -172,12 +78,12 @@ func RegisterNotificationEmail(ctx context.Context, report_id string, email stri
return nil
}
func RegisterNotificationPhone(ctx context.Context, report_id string, phone text.E164) *ErrorWithCode {
func RegisterNotificationPhone(ctx context.Context, txn bob.Tx, report_id string, phone text.E164) *ErrorWithCode {
some_report, err := findSomeReport(ctx, report_id)
if err != nil {
return err
}
err = some_report.updateReporterPhone(ctx, phone)
err = some_report.addNotificationPhone(ctx, txn, phone)
if err != nil {
return err
}
@ -185,18 +91,48 @@ func RegisterNotificationPhone(ctx context.Context, report_id string, phone text
return nil
}
func RegisterSubscriptionEmail(ctx context.Context, email string) *ErrorWithCode {
func RegisterSubscriptionEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode {
log.Warn().Msg("RegisterSubscription not implemented yet")
return nil
}
func RegisterSubscriptionPhone(ctx context.Context, phone text.E164) *ErrorWithCode {
func RegisterSubscriptionPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode {
log.Warn().Msg("RegisterSubscription not implemented yet")
return nil
}
func SaveReporter(ctx context.Context, txn bob.Tx, report_id string, name string, email string, phone *text.E164, has_consent bool) *ErrorWithCode {
some_report, err := findSomeReport(ctx, report_id)
if err != nil {
return err
}
if name != "" {
err = some_report.updateReporterName(ctx, txn, name)
if err != nil {
return err
}
}
if phone != nil {
err = some_report.updateReporterPhone(ctx, txn, *phone)
if err != nil {
return err
}
}
if email != "" {
err = some_report.updateReporterEmail(ctx, txn, email)
if err != nil {
return err
}
}
err = some_report.updateReporterConsent(ctx, txn, has_consent)
if err != nil {
return err
}
return nil
}
func findSomeReport(ctx context.Context, report_id string) (result SomeReport, err *ErrorWithCode) {
rows, e := sql.PublicreportIDTable(report_id).All(ctx, db.PGInstance.BobDB)
if e != nil {
log.Error().Err(e).Str("report_id", report_id).Msg("failed to query report ID table")
return result, newErrorWithCode("internal-error", "Failed to query report ID table: %w", e)
}
switch len(rows) {
@ -205,25 +141,24 @@ func findSomeReport(ctx context.Context, report_id string) (result SomeReport, e
case 1:
break
default:
log.Error().Err(e).Str("report_id", report_id).Msg("More than one report with the provided ID, which shouldn't happen")
return result, newErrorWithCode("internal-error", "More than one report with the provided ID, which shouldn't happen")
}
row := rows[0]
result.reportID = report_id
result.tableName = row.FoundInTables[0]
return result, nil
}
report_id_str := row.ReportIds[0]
t, e := strconv.ParseInt(report_id_str, 10, 32)
if e != nil {
log.Error().Err(e).Str("report_id_str", report_id_str).Msg("Unable to parse integer reponse from database")
return result, newErrorWithCode("internal-error", "Unable to parse integer response from database")
}
func newErrorWithCode(code string, format string, args ...any) *ErrorWithCode {
if len(args) > 0 {
return &ErrorWithCode{
err: fmt.Errorf(format, args...),
code: code,
}
} else {
return &ErrorWithCode{
code: code,
err: nil,
message: format,
}
switch row.FoundInTables[0] {
case "nuisance":
return newNuisance(ctx, report_id, int32(t))
case "pool":
return newPool(ctx, report_id, int32(t))
default:
log.Error().Err(e).Str("table_name", row.FoundInTables[0]).Msg("Unrecognized table")
return Nuisance{}, newErrorWithCode("internal-error", fmt.Sprintf("Unrecognized table '%s'", row.FoundInTables[0]))
}
}

View file

@ -0,0 +1,156 @@
package report
import (
"context"
//"crypto/rand"
//"fmt"
//"math/big"
//"strconv"
//"strings"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
//"github.com/Gleipnir-Technology/nidus-sync/background"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
//"github.com/Gleipnir-Technology/nidus-sync/db/sql"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
)
type Nuisance struct {
id int32
publicReportID string
row *models.PublicreportNuisance
}
func (sr Nuisance) PublicReportID() string {
return sr.publicReportID
}
func (sr Nuisance) addNotificationEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode {
setter := models.PublicreportNotifyEmailNuisanceSetter{
Created: omit.From(time.Now()),
Deleted: omitnull.FromPtr[time.Time](nil),
NuisanceID: omit.From(sr.id),
EmailAddress: omit.From(email),
}
_, err := models.PublicreportNotifyPhoneNuisances.Insert(&setter).Exec(ctx, txn)
if err != nil {
return newErrorWithCode("internal-error", "Failed to save new notification row")
}
return nil
}
func (sr Nuisance) addNotificationPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode {
var err error
setter := models.PublicreportNotifyPhoneNuisanceSetter{
Created: omit.From(time.Now()),
Deleted: omitnull.FromPtr[time.Time](nil),
NuisanceID: omit.From(sr.id),
PhoneE164: omit.From(text.PhoneString(phone)),
}
_, err = models.PublicreportNotifyPhoneNuisances.Insert(&setter).Exec(ctx, txn)
if err != nil {
return newErrorWithCode("internal-error", "Failed to save new notification row")
}
return nil
}
func (sr Nuisance) districtID(ctx context.Context) *int32 {
type _Row struct {
OrganizationID *int32
}
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
sm.From("publicreport.nuisance"),
sm.Columns("organization_id"),
sm.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))),
), scan.StructMapper[_Row]())
if err != nil {
log.Warn().Err(err).Msg("Failed to query for organization_id")
return nil
}
return row.OrganizationID
}
func (sr Nuisance) reportID() int32 {
return sr.id
}
func (sr Nuisance) updateReporterConsent(ctx context.Context, txn bob.Tx, has_consent bool) *ErrorWithCode {
setter := models.PublicreportNuisanceSetter{
ReporterContactConsent: omitnull.From(has_consent),
}
_, err := models.PublicreportNotifyPhoneNuisances.Insert(&setter).Exec(ctx, txn)
if err != nil {
return newErrorWithCode("internal-error", "Failed to save new notification row")
}
return nil
}
func (sr Nuisance) updateReporterEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode {
result, err := psql.Update(
um.Table("publicreport.nuisance"),
um.SetCol("reporter_email").ToArg(email),
um.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))),
).Exec(ctx, txn)
if err != nil {
return newErrorWithCode("internal-error", "Failed to update report: %w", err)
}
rowcount, err := result.RowsAffected()
if err != nil {
return newErrorWithCode("internal-error", "Failed to get rows affected: %w", err)
}
if rowcount != 1 {
log.Warn().Str("public_report_id", sr.publicReportID).Msg("updated more than one row, which is a programmer error")
}
return nil
}
func (sr Nuisance) updateReporterName(ctx context.Context, txn bob.Tx, name string) *ErrorWithCode {
result, err := psql.Update(
um.Table("publicreport.nuisance"),
um.SetCol("reporter_name").ToArg(name),
um.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))),
).Exec(ctx, txn)
if err != nil {
return newErrorWithCode("internal-error", "Failed to update report: %w", err)
}
rowcount, err := result.RowsAffected()
if err != nil {
return newErrorWithCode("internal-error", "Failed to get rows affected: %w", err)
}
if rowcount != 1 {
log.Warn().Str("public_report_id", sr.publicReportID).Msg("updated more than one row, which is a programmer error")
}
return nil
}
func (sr Nuisance) updateReporterPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode {
result, err := psql.Update(
um.Table("publicreport.nuisance"),
um.SetCol("reporter_phone").ToArg(text.PhoneString(phone)),
um.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))),
).Exec(ctx, txn)
if err != nil {
return newErrorWithCode("internal-error", "Failed to update report: %w", err)
}
rowcount, err := result.RowsAffected()
if err != nil {
return newErrorWithCode("internal-error", "Failed to get rows affected: %w", err)
}
if rowcount != 1 {
log.Warn().Str("public_report_id", sr.publicReportID).Msg("updated more than one row, which is a programmer error")
}
return nil
}
func newNuisance(ctx context.Context, public_id string, report_id int32) (Nuisance, *ErrorWithCode) {
row, err := models.FindPublicreportNuisance(ctx, db.PGInstance.BobDB, report_id)
if err != nil {
return Nuisance{}, newErrorWithCode("internal-error", "Failed to find nuisance report %d: %w", public_id, err)
}
return Nuisance{
id: report_id,
publicReportID: public_id,
row: row,
}, nil
}

View file

@ -0,0 +1,119 @@
package report
import (
"context"
//"crypto/rand"
//"fmt"
//"math/big"
//"strconv"
//"strings"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
"github.com/rs/zerolog/log"
"github.com/stephenafamo/scan"
)
type Pool struct {
id int32
publicReportID string
row *models.PublicreportPool
}
func (sr Pool) PublicReportID() string {
return sr.publicReportID
}
func (sr Pool) addNotificationEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode {
setter := models.PublicreportNotifyEmailPoolSetter{
Created: omit.From(time.Now()),
Deleted: omitnull.FromPtr[time.Time](nil),
PoolID: omit.From(sr.id),
EmailAddress: omit.From(email),
}
_, err := models.PublicreportNotifyEmailPools.Insert(&setter).Exec(ctx, txn)
if err != nil {
log.Error().Err(err).Msg("Failed to save new notification email row")
return newErrorWithCode("internal-error", "Failed to save new notification email row")
}
return nil
}
func (sr Pool) addNotificationPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode {
setter := models.PublicreportNotifyPhonePoolSetter{
Created: omit.From(time.Now()),
Deleted: omitnull.FromPtr[time.Time](nil),
PoolID: omit.From(sr.id),
PhoneE164: omit.From(text.PhoneString(phone)),
}
_, err := models.PublicreportNotifyPhonePools.Insert(&setter).Exec(ctx, txn)
if err != nil {
log.Error().Err(err).Msg("Failed to save new notification phone row")
return newErrorWithCode("internal-error", "Failed to save new notification phone row")
}
return nil
}
func (sr Pool) districtID(ctx context.Context) *int32 {
type _Row struct {
OrganizationID *int32
}
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
sm.From("publicreport.pool"),
sm.Columns("organization_id"),
sm.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))),
), scan.StructMapper[_Row]())
if err != nil {
log.Warn().Err(err).Msg("Failed to query for organization_id")
return nil
}
return row.OrganizationID
}
func (sr Pool) reportID() int32 {
return sr.id
}
func (sr Pool) updateReporterConsent(ctx context.Context, txn bob.Tx, has_consent bool) *ErrorWithCode {
return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{
ReporterContactConsent: omitnull.From(has_consent),
})
}
func (sr Pool) updateReporterEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode {
return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{
ReporterEmail: omit.From(email),
})
}
func (sr Pool) updateReporterName(ctx context.Context, txn bob.Tx, name string) *ErrorWithCode {
return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{
ReporterName: omit.From(name),
})
}
func (sr Pool) updateReportCol(ctx context.Context, txn bob.Tx, setter *models.PublicreportPoolSetter) *ErrorWithCode {
err := sr.row.Update(ctx, txn, setter)
if err != nil {
log.Error().Err(err).Str("public_id", sr.publicReportID).Int32("report_id", sr.id).Msg("Failed to update report")
return newErrorWithCode("internal-error", "Failed to update pool report in the database")
}
return nil
}
func (sr Pool) updateReporterPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode {
return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{
ReporterPhone: omit.From(text.PhoneString(phone)),
})
}
func newPool(ctx context.Context, public_id string, report_id int32) (Pool, *ErrorWithCode) {
row, err := models.FindPublicreportPool(ctx, db.PGInstance.BobDB, report_id)
if err != nil {
log.Error().Err(err).Msg("Failed to find pool report")
return Pool{}, newErrorWithCode("internal-error", "Failed to find pool report %d: %w", public_id, err)
}
return Pool{
id: report_id,
publicReportID: public_id,
row: row,
}, nil
}

View file

@ -0,0 +1,37 @@
package report
import (
"context"
//"crypto/rand"
//"fmt"
//"math/big"
//"strconv"
//"strings"
//"time"
//"github.com/aarondl/opt/omit"
//"github.com/aarondl/opt/omitnull"
"github.com/Gleipnir-Technology/bob"
//"github.com/Gleipnir-Technology/bob/dialect/psql"
//"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
//"github.com/Gleipnir-Technology/bob/dialect/psql/um"
//"github.com/Gleipnir-Technology/nidus-sync/background"
//"github.com/Gleipnir-Technology/nidus-sync/db"
//"github.com/Gleipnir-Technology/nidus-sync/db/models"
//"github.com/Gleipnir-Technology/nidus-sync/db/sql"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
//"github.com/rs/zerolog/log"
//"github.com/stephenafamo/scan"
)
type SomeReport interface {
addNotificationEmail(context.Context, bob.Tx, string) *ErrorWithCode
addNotificationPhone(context.Context, bob.Tx, text.E164) *ErrorWithCode
districtID(context.Context) *int32
updateReporterConsent(context.Context, bob.Tx, bool) *ErrorWithCode
updateReporterEmail(context.Context, bob.Tx, string) *ErrorWithCode
updateReporterName(context.Context, bob.Tx, string) *ErrorWithCode
updateReporterPhone(context.Context, bob.Tx, text.E164) *ErrorWithCode
PublicReportID() string
reportID() int32
}

View file

@ -4,8 +4,10 @@ import (
"fmt"
"net/http"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/platform/report"
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
"github.com/rs/zerolog/log"
)
var (
@ -18,19 +20,14 @@ func postRegisterNotifications(w http.ResponseWriter, r *http.Request) {
respondError(w, "Failed to parse form", err, http.StatusBadRequest)
return
}
consent := r.PostFormValue("consent")
has_consent := boolFromForm(r, "consent")
has_notification := boolFromForm(r, "notification")
has_subscribe := boolFromForm(r, "subscribe")
email := r.PostFormValue("email")
name := r.PostFormValue("name")
phone_str := r.PostFormValue("phone")
report_id := r.PostFormValue("report_id")
subscribe := postFormBool(r, "subscribe")
if consent != "on" {
respondError(w, "You must consent", nil, http.StatusBadRequest)
return
}
if email == "" && phone_str == "" {
http.Redirect(w, r, fmt.Sprintf("/submit-complete?report=%s", report_id), http.StatusFound)
return
}
var phone *text.E164
if phone_str != "" {
phone, err = text.ParsePhoneNumber(phone_str)
@ -41,28 +38,43 @@ func postRegisterNotifications(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil)
if err != nil {
log.Error().Err(err).Msg("Failed to begin transaction")
http.Redirect(w, r, fmt.Sprintf("/error?code=transaction-failed&report=%s", report_id), http.StatusFound)
return
}
e := report.SaveReporter(ctx, txn, report_id, name, email, phone, has_consent)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", e.Code(), report_id), http.StatusFound)
return
}
if email != "" {
if subscribe != nil && *subscribe {
e := report.RegisterSubscriptionEmail(ctx, email)
if has_subscribe {
e := report.RegisterSubscriptionEmail(ctx, txn, email)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", report_id, e.Code()), http.StatusFound)
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", e.Code(), report_id), http.StatusFound)
}
}
e := report.RegisterNotificationEmail(ctx, report_id, email)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", report_id, e.Code()), http.StatusFound)
if has_notification {
e := report.RegisterNotificationEmail(ctx, txn, report_id, email)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", e.Code(), report_id), http.StatusFound)
}
}
}
if phone != nil {
if subscribe != nil && *subscribe {
e := report.RegisterSubscriptionPhone(ctx, *phone)
if has_subscribe {
e := report.RegisterSubscriptionPhone(ctx, txn, *phone)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", report_id, e.Code()), http.StatusFound)
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", e.Code(), report_id), http.StatusFound)
}
}
e := report.RegisterNotificationPhone(ctx, report_id, *phone)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", report_id, e.Code()), http.StatusFound)
if has_notification {
e := report.RegisterNotificationPhone(ctx, txn, report_id, *phone)
if e != nil {
http.Redirect(w, r, fmt.Sprintf("/error?code=%s&report=%s", e.Code(), report_id), http.StatusFound)
}
}
}
http.Redirect(w, r, fmt.Sprintf("/register-notifications-complete?report=%s", report_id), http.StatusFound)

View file

@ -13,6 +13,22 @@
<!-- favicon -->
<link rel="icon" href="/static/favicon-rmo.ico" type="image/x-icon"/>
{{block "extraheader" .}} {{end}}
<script>
document.addEventListener("DOMContentLoaded", function() {
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
});
console.log("Initialized ", popoverTriggerList.length, " popovers");
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
console.log("Initialized ", tooltipTriggerList.length, " tooltips");
});
</script>
</head>
<body>
{{template "content" .}}

View file

@ -33,16 +33,22 @@
<div>
<h4 class="mb-3">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-bell me-2" viewBox="0 0 16 16">
<path d="M8 16a2 2 0 0 0 2-2H6a2 2 0 0 0 2 2zM8 1.918l-.797.161A4.002 4.002 0 0 0 4 6c0 .628-.134 2.197-.459 3.742-.16.767-.376 1.566-.663 2.258h10.244c-.287-.692-.502-1.49-.663-2.258C12.134 8.197 12 6.628 12 6a4.002 4.002 0 0 0-3.203-3.92L8 1.917zM14.22 12c.223.447.481.801.78 1H1c.299-.199.557-.553.78-1C2.68 10.2 3 6.88 3 6c0-2.42 1.72-4.44 4.005-4.901a1 1 0 1 1 1.99 0A5.002 5.002 0 0 1 13 6c0 .88.32 4.2 1.22 6z"/>
</svg>
Get Updates
<i class="bi bi-person-rolodex"></i>
Follow-up
</h4>
<p>Provide your contact information to receive updates about your report.</p>
<p>Please provide your contact information in case the district has any follow-up questions.</p>
<form id="notificationForm" action="/register-notifications" method="post" class="needs-validation">
<input type="hidden" name="report_id" value="{{.ReportID}}">
<div class="mb-3">
<label class="form-label" for="name">Name</label>
<div class="input-group">
<span class="input-group-text">
<i class="bi bi-person-lines-fill"></i>
</span>
<input type="text" class="form-control" id="name" name="name" placeholder="Adam Smith">
</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<div class="input-group">
@ -56,7 +62,7 @@
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone Number (for SMS updates)</label>
<label for="phone" class="form-label">Phone Number</label>
<div class="input-group">
<span class="input-group-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-phone" viewBox="0 0 16 16">
@ -69,16 +75,23 @@
</div>
<div class="form-check mb-3 form-check">
<input class="form-check-input" type="checkbox" name="consent" required>
<input class="form-check-input" id="consent" type="checkbox" name="consent" checked>
<label class="form-check-label" for="consent">
I consent to receiving updates about this report
I consent to being contacted at my email address or phone number above just for the purposes of this report.
<i class="bi bi-info-circle-fill text-primary ms-1"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="We will never sell your information. We'll send you notifications, but only if you ask us to. We'll share your information with the district that is in change of mosquito control in the area you've reported, but not with anybody else."></i>
</label>
<div class="invalid-feedback">
You must consent to receive notifications.
</div>
</div>
<div class="form-check mb-3 form-check">
<input class="form-check-input" type="checkbox" name="subscribe"/>
<input class="form-check-input" id="notification" type="checkbox" name="notification"/>
<label class="form-check-label" for="notification">
I'd like to get updates about my report as it gets handled.
</label>
</div>
<div class="form-check mb-3 form-check">
<input class="form-check-input" id="subscribe" type="checkbox" name="subscribe"/>
<label class="form-check-label" for="subscribe">
{{ if eq .District nil }}
I'd like to subscribe to periodic updates from my mosquito control district.
@ -88,7 +101,7 @@
</label>
</div>
<button type="submit" class="btn btn-primary">Register for Updates</button>
<button type="submit" class="btn btn-primary">Update report</button>
</form>
</div>