Overhaul publicreport storage layer, create unified tables

This is a huge change. I was getting really sick of the split between
nuisance/water tables when more than half of the data they store is
common. I finally bit off the big work of switching it all.

This creates a single unified table, publicreport.report and copies the
existing report data into it. It also ports existing data from the
original tables into the new table.

Along with all of this I also overhauled the system for handling
asynchronous work to use a LISTEN/NOTIFY connection from the database
and a single cache table to avoid ever losing work.
This commit is contained in:
Eli Ribble 2026-03-18 15:36:20 +00:00
parent 2538638c9d
commit 1e071d5ce5
No known key found for this signature in database
109 changed files with 22903 additions and 11713 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 PublicreportNotifyEmailErrors = &publicreportNotifyEmailErrors{
ErrUniqueNotifyEmailPkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_email",
columns: []string{"report_id", "email_address"},
s: "notify_email_pkey",
},
}
type publicreportNotifyEmailErrors struct {
ErrUniqueNotifyEmailPkey *UniqueConstraintError
}

View file

@ -3,15 +3,15 @@
package dberrors
var PublicreportNotifyEmailNuisanceErrors = &publicreportNotifyEmailNuisanceErrors{
var PublicreportNotifyEmailNuisanceOldErrors = &publicreportNotifyEmailNuisanceOldErrors{
ErrUniqueNotifyEmailNuisancePkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_email_nuisance",
table: "notify_email_nuisance_old",
columns: []string{"nuisance_id", "email_address"},
s: "notify_email_nuisance_pkey",
},
}
type publicreportNotifyEmailNuisanceErrors struct {
type publicreportNotifyEmailNuisanceOldErrors struct {
ErrUniqueNotifyEmailNuisancePkey *UniqueConstraintError
}

View file

@ -3,15 +3,15 @@
package dberrors
var PublicreportNotifyEmailWaterErrors = &publicreportNotifyEmailWaterErrors{
var PublicreportNotifyEmailWaterOldErrors = &publicreportNotifyEmailWaterOldErrors{
ErrUniqueNotifyEmailPoolPkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_email_water",
table: "notify_email_water_old",
columns: []string{"water_id", "email_address"},
s: "notify_email_pool_pkey",
},
}
type publicreportNotifyEmailWaterErrors struct {
type publicreportNotifyEmailWaterOldErrors 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 PublicreportNotifyPhoneErrors = &publicreportNotifyPhoneErrors{
ErrUniqueNotifyPhonePkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_phone",
columns: []string{"report_id", "phone_e164"},
s: "notify_phone_pkey",
},
}
type publicreportNotifyPhoneErrors struct {
ErrUniqueNotifyPhonePkey *UniqueConstraintError
}

View file

@ -3,15 +3,15 @@
package dberrors
var PublicreportNotifyPhoneNuisanceErrors = &publicreportNotifyPhoneNuisanceErrors{
var PublicreportNotifyPhoneNuisanceOldErrors = &publicreportNotifyPhoneNuisanceOldErrors{
ErrUniqueNotifyPhoneNuisancePkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_phone_nuisance",
table: "notify_phone_nuisance_old",
columns: []string{"nuisance_id", "phone_e164"},
s: "notify_phone_nuisance_pkey",
},
}
type publicreportNotifyPhoneNuisanceErrors struct {
type publicreportNotifyPhoneNuisanceOldErrors struct {
ErrUniqueNotifyPhoneNuisancePkey *UniqueConstraintError
}

View file

@ -3,15 +3,15 @@
package dberrors
var PublicreportNotifyPhoneWaterErrors = &publicreportNotifyPhoneWaterErrors{
var PublicreportNotifyPhoneWaterOldErrors = &publicreportNotifyPhoneWaterOldErrors{
ErrUniqueNotifyPhonePoolPkey: &UniqueConstraintError{
schema: "publicreport",
table: "notify_phone_water",
table: "notify_phone_water_old",
columns: []string{"water_id", "phone_e164"},
s: "notify_phone_pool_pkey",
},
}
type publicreportNotifyPhoneWaterErrors struct {
type publicreportNotifyPhoneWaterOldErrors struct {
ErrUniqueNotifyPhonePoolPkey *UniqueConstraintError
}

View file

@ -4,23 +4,14 @@
package dberrors
var PublicreportNuisanceErrors = &publicreportNuisanceErrors{
ErrUniqueNuisancePkey: &UniqueConstraintError{
ErrUniqueNuisancePkey1: &UniqueConstraintError{
schema: "publicreport",
table: "nuisance",
columns: []string{"id"},
s: "nuisance_pkey",
},
ErrUniqueNuisancePublicIdKey: &UniqueConstraintError{
schema: "publicreport",
table: "nuisance",
columns: []string{"public_id"},
s: "nuisance_public_id_key",
columns: []string{"report_id"},
s: "nuisance_pkey1",
},
}
type publicreportNuisanceErrors struct {
ErrUniqueNuisancePkey *UniqueConstraintError
ErrUniqueNuisancePublicIdKey *UniqueConstraintError
ErrUniqueNuisancePkey1 *UniqueConstraintError
}

View file

@ -3,15 +3,15 @@
package dberrors
var PublicreportNuisanceImageErrors = &publicreportNuisanceImageErrors{
var PublicreportNuisanceImageOldErrors = &publicreportNuisanceImageOldErrors{
ErrUniqueNuisanceImagePkey: &UniqueConstraintError{
schema: "publicreport",
table: "nuisance_image",
table: "nuisance_image_old",
columns: []string{"image_id", "nuisance_id"},
s: "nuisance_image_pkey",
},
}
type publicreportNuisanceImageErrors struct {
type publicreportNuisanceImageOldErrors struct {
ErrUniqueNuisanceImagePkey *UniqueConstraintError
}

View file

@ -0,0 +1,26 @@
// 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 PublicreportNuisanceOldErrors = &publicreportNuisanceOldErrors{
ErrUniqueNuisancePkey: &UniqueConstraintError{
schema: "publicreport",
table: "nuisance_old",
columns: []string{"id"},
s: "nuisance_pkey",
},
ErrUniqueNuisancePublicIdKey: &UniqueConstraintError{
schema: "publicreport",
table: "nuisance_old",
columns: []string{"public_id"},
s: "nuisance_public_id_key",
},
}
type publicreportNuisanceOldErrors struct {
ErrUniqueNuisancePkey *UniqueConstraintError
ErrUniqueNuisancePublicIdKey *UniqueConstraintError
}

View file

@ -0,0 +1,26 @@
// 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 PublicreportReportErrors = &publicreportReportErrors{
ErrUniqueReportPkey: &UniqueConstraintError{
schema: "publicreport",
table: "report",
columns: []string{"id"},
s: "report_pkey",
},
ErrUniqueReportPublicIdKey: &UniqueConstraintError{
schema: "publicreport",
table: "report",
columns: []string{"public_id"},
s: "report_public_id_key",
},
}
type publicreportReportErrors struct {
ErrUniqueReportPkey *UniqueConstraintError
ErrUniqueReportPublicIdKey *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 PublicreportReportImageErrors = &publicreportReportImageErrors{
ErrUniqueReportImagePkey: &UniqueConstraintError{
schema: "publicreport",
table: "report_image",
columns: []string{"image_id", "report_id"},
s: "report_image_pkey",
},
}
type publicreportReportImageErrors struct {
ErrUniqueReportImagePkey *UniqueConstraintError
}

View file

@ -4,23 +4,14 @@
package dberrors
var PublicreportWaterErrors = &publicreportWaterErrors{
ErrUniquePoolPkey: &UniqueConstraintError{
ErrUniqueWaterPkey: &UniqueConstraintError{
schema: "publicreport",
table: "water",
columns: []string{"id"},
s: "pool_pkey",
},
ErrUniquePoolPublicIdKey: &UniqueConstraintError{
schema: "publicreport",
table: "water",
columns: []string{"public_id"},
s: "pool_public_id_key",
columns: []string{"report_id"},
s: "water_pkey",
},
}
type publicreportWaterErrors struct {
ErrUniquePoolPkey *UniqueConstraintError
ErrUniquePoolPublicIdKey *UniqueConstraintError
ErrUniqueWaterPkey *UniqueConstraintError
}

View file

@ -3,15 +3,15 @@
package dberrors
var PublicreportWaterImageErrors = &publicreportWaterImageErrors{
var PublicreportWaterImageOldErrors = &publicreportWaterImageOldErrors{
ErrUniquePoolImagePkey: &UniqueConstraintError{
schema: "publicreport",
table: "water_image",
table: "water_image_old",
columns: []string{"image_id", "water_id"},
s: "pool_image_pkey",
},
}
type publicreportWaterImageErrors struct {
type publicreportWaterImageOldErrors struct {
ErrUniquePoolImagePkey *UniqueConstraintError
}

View file

@ -0,0 +1,26 @@
// 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 PublicreportWaterOldErrors = &publicreportWaterOldErrors{
ErrUniquePoolPkey: &UniqueConstraintError{
schema: "publicreport",
table: "water_old",
columns: []string{"id"},
s: "pool_pkey",
},
ErrUniquePoolPublicIdKey: &UniqueConstraintError{
schema: "publicreport",
table: "water_old",
columns: []string{"public_id"},
s: "pool_public_id_key",
},
}
type publicreportWaterOldErrors struct {
ErrUniquePoolPkey *UniqueConstraintError
ErrUniquePoolPublicIdKey *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 ReportTextErrors = &reportTextErrors{
ErrUniqueReportTextPkey: &UniqueConstraintError{
schema: "",
table: "report_text",
columns: []string{"creator_id", "report_id", "text_log_id"},
s: "report_text_pkey",
},
}
type reportTextErrors struct {
ErrUniqueReportTextPkey *UniqueConstraintError
}

View file

@ -78,6 +78,24 @@ var CommsTextJobs = Table[
Generated: false,
AutoIncr: false,
},
CreatorID: column{
Name: "creator_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: commsTextJobIndexes{
TextJobPkey: index{
@ -104,6 +122,15 @@ var CommsTextJobs = Table[
Comment: "",
},
ForeignKeys: commsTextJobForeignKeys{
CommsTextJobTextJobCreatorIDFkey: foreignKey{
constraint: constraint{
Name: "comms.text_job.text_job_creator_id_fkey",
Columns: []string{"creator_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
CommsTextJobTextJobDestinationFkey: foreignKey{
constraint: constraint{
Name: "comms.text_job.text_job_destination_fkey",
@ -113,6 +140,15 @@ var CommsTextJobs = Table[
ForeignTable: "comms.phone",
ForeignColumns: []string{"e164"},
},
CommsTextJobTextJobReportIDFkey: foreignKey{
constraint: constraint{
Name: "comms.text_job.text_job_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
},
Comment: "Used to track text messages that should be sent later",
@ -126,11 +162,13 @@ type commsTextJobColumns struct {
Type column
Source column
Completed column
CreatorID column
ReportID column
}
func (c commsTextJobColumns) AsSlice() []column {
return []column{
c.Content, c.Created, c.Destination, c.ID, c.Type, c.Source, c.Completed,
c.Content, c.Created, c.Destination, c.ID, c.Type, c.Source, c.Completed, c.CreatorID, c.ReportID,
}
}
@ -145,12 +183,14 @@ func (i commsTextJobIndexes) AsSlice() []index {
}
type commsTextJobForeignKeys struct {
CommsTextJobTextJobCreatorIDFkey foreignKey
CommsTextJobTextJobDestinationFkey foreignKey
CommsTextJobTextJobReportIDFkey foreignKey
}
func (f commsTextJobForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.CommsTextJobTextJobDestinationFkey,
f.CommsTextJobTextJobCreatorIDFkey, f.CommsTextJobTextJobDestinationFkey, f.CommsTextJobTextJobReportIDFkey,
}
}

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 PublicreportNotifyEmails = Table[
publicreportNotifyEmailColumns,
publicreportNotifyEmailIndexes,
publicreportNotifyEmailForeignKeys,
publicreportNotifyEmailUniques,
publicreportNotifyEmailChecks,
]{
Schema: "publicreport",
Name: "notify_email",
Columns: publicreportNotifyEmailColumns{
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,
},
EmailAddress: column{
Name: "email_address",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNotifyEmailIndexes{
NotifyEmailPkey: index{
Type: "btree",
Name: "notify_email_pkey",
Columns: []indexColumn{
{
Name: "report_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_pkey",
Columns: []string{"report_id", "email_address"},
Comment: "",
},
ForeignKeys: publicreportNotifyEmailForeignKeys{
PublicreportNotifyEmailNotifyEmailEmailAddressFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email.notify_email_email_address_fkey",
Columns: []string{"email_address"},
Comment: "",
},
ForeignTable: "comms.email_contact",
ForeignColumns: []string{"address"},
},
PublicreportNotifyEmailNotifyEmailReportIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email.notify_email_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type publicreportNotifyEmailColumns struct {
Created column
Deleted column
EmailAddress column
ReportID column
}
func (c publicreportNotifyEmailColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.EmailAddress, c.ReportID,
}
}
type publicreportNotifyEmailIndexes struct {
NotifyEmailPkey index
}
func (i publicreportNotifyEmailIndexes) AsSlice() []index {
return []index{
i.NotifyEmailPkey,
}
}
type publicreportNotifyEmailForeignKeys struct {
PublicreportNotifyEmailNotifyEmailEmailAddressFkey foreignKey
PublicreportNotifyEmailNotifyEmailReportIDFkey foreignKey
}
func (f publicreportNotifyEmailForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyEmailNotifyEmailEmailAddressFkey, f.PublicreportNotifyEmailNotifyEmailReportIDFkey,
}
}
type publicreportNotifyEmailUniques struct{}
func (u publicreportNotifyEmailUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyEmailChecks struct{}
func (c publicreportNotifyEmailChecks) AsSlice() []check {
return []check{}
}

View file

@ -5,16 +5,16 @@ package dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyEmailNuisances = Table[
publicreportNotifyEmailNuisanceColumns,
publicreportNotifyEmailNuisanceIndexes,
publicreportNotifyEmailNuisanceForeignKeys,
publicreportNotifyEmailNuisanceUniques,
publicreportNotifyEmailNuisanceChecks,
var PublicreportNotifyEmailNuisanceOlds = Table[
publicreportNotifyEmailNuisanceOldColumns,
publicreportNotifyEmailNuisanceOldIndexes,
publicreportNotifyEmailNuisanceOldForeignKeys,
publicreportNotifyEmailNuisanceOldUniques,
publicreportNotifyEmailNuisanceOldChecks,
]{
Schema: "publicreport",
Name: "notify_email_nuisance",
Columns: publicreportNotifyEmailNuisanceColumns{
Name: "notify_email_nuisance_old",
Columns: publicreportNotifyEmailNuisanceOldColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
@ -52,7 +52,7 @@ var PublicreportNotifyEmailNuisances = Table[
AutoIncr: false,
},
},
Indexes: publicreportNotifyEmailNuisanceIndexes{
Indexes: publicreportNotifyEmailNuisanceOldIndexes{
NotifyEmailNuisancePkey: index{
Type: "btree",
Name: "notify_email_nuisance_pkey",
@ -81,23 +81,23 @@ var PublicreportNotifyEmailNuisances = Table[
Columns: []string{"nuisance_id", "email_address"},
Comment: "",
},
ForeignKeys: publicreportNotifyEmailNuisanceForeignKeys{
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceEmailAddressFkey: foreignKey{
ForeignKeys: publicreportNotifyEmailNuisanceOldForeignKeys{
PublicreportNotifyEmailNuisanceOldNotifyEmailNuisanceEmailAddressFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey",
Name: "publicreport.notify_email_nuisance_old.notify_email_nuisance_email_address_fkey",
Columns: []string{"email_address"},
Comment: "",
},
ForeignTable: "comms.email_contact",
ForeignColumns: []string{"address"},
},
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceNuisanceIDFkey: foreignKey{
PublicreportNotifyEmailNuisanceOldNotifyEmailNuisanceNuisanceIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_nuisance.notify_email_nuisance_nuisance_id_fkey",
Name: "publicreport.notify_email_nuisance_old.notify_email_nuisance_nuisance_id_fkey",
Columns: []string{"nuisance_id"},
Comment: "",
},
ForeignTable: "publicreport.nuisance",
ForeignTable: "publicreport.nuisance_old",
ForeignColumns: []string{"id"},
},
},
@ -105,48 +105,48 @@ var PublicreportNotifyEmailNuisances = Table[
Comment: "",
}
type publicreportNotifyEmailNuisanceColumns struct {
type publicreportNotifyEmailNuisanceOldColumns struct {
Created column
Deleted column
NuisanceID column
EmailAddress column
}
func (c publicreportNotifyEmailNuisanceColumns) AsSlice() []column {
func (c publicreportNotifyEmailNuisanceOldColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.NuisanceID, c.EmailAddress,
}
}
type publicreportNotifyEmailNuisanceIndexes struct {
type publicreportNotifyEmailNuisanceOldIndexes struct {
NotifyEmailNuisancePkey index
}
func (i publicreportNotifyEmailNuisanceIndexes) AsSlice() []index {
func (i publicreportNotifyEmailNuisanceOldIndexes) AsSlice() []index {
return []index{
i.NotifyEmailNuisancePkey,
}
}
type publicreportNotifyEmailNuisanceForeignKeys struct {
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceEmailAddressFkey foreignKey
PublicreportNotifyEmailNuisanceNotifyEmailNuisanceNuisanceIDFkey foreignKey
type publicreportNotifyEmailNuisanceOldForeignKeys struct {
PublicreportNotifyEmailNuisanceOldNotifyEmailNuisanceEmailAddressFkey foreignKey
PublicreportNotifyEmailNuisanceOldNotifyEmailNuisanceNuisanceIDFkey foreignKey
}
func (f publicreportNotifyEmailNuisanceForeignKeys) AsSlice() []foreignKey {
func (f publicreportNotifyEmailNuisanceOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyEmailNuisanceNotifyEmailNuisanceEmailAddressFkey, f.PublicreportNotifyEmailNuisanceNotifyEmailNuisanceNuisanceIDFkey,
f.PublicreportNotifyEmailNuisanceOldNotifyEmailNuisanceEmailAddressFkey, f.PublicreportNotifyEmailNuisanceOldNotifyEmailNuisanceNuisanceIDFkey,
}
}
type publicreportNotifyEmailNuisanceUniques struct{}
type publicreportNotifyEmailNuisanceOldUniques struct{}
func (u publicreportNotifyEmailNuisanceUniques) AsSlice() []constraint {
func (u publicreportNotifyEmailNuisanceOldUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyEmailNuisanceChecks struct{}
type publicreportNotifyEmailNuisanceOldChecks struct{}
func (c publicreportNotifyEmailNuisanceChecks) AsSlice() []check {
func (c publicreportNotifyEmailNuisanceOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -5,16 +5,16 @@ package dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyEmailWaters = Table[
publicreportNotifyEmailWaterColumns,
publicreportNotifyEmailWaterIndexes,
publicreportNotifyEmailWaterForeignKeys,
publicreportNotifyEmailWaterUniques,
publicreportNotifyEmailWaterChecks,
var PublicreportNotifyEmailWaterOlds = Table[
publicreportNotifyEmailWaterOldColumns,
publicreportNotifyEmailWaterOldIndexes,
publicreportNotifyEmailWaterOldForeignKeys,
publicreportNotifyEmailWaterOldUniques,
publicreportNotifyEmailWaterOldChecks,
]{
Schema: "publicreport",
Name: "notify_email_water",
Columns: publicreportNotifyEmailWaterColumns{
Name: "notify_email_water_old",
Columns: publicreportNotifyEmailWaterOldColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
@ -52,7 +52,7 @@ var PublicreportNotifyEmailWaters = Table[
AutoIncr: false,
},
},
Indexes: publicreportNotifyEmailWaterIndexes{
Indexes: publicreportNotifyEmailWaterOldIndexes{
NotifyEmailPoolPkey: index{
Type: "btree",
Name: "notify_email_pool_pkey",
@ -81,23 +81,23 @@ var PublicreportNotifyEmailWaters = Table[
Columns: []string{"water_id", "email_address"},
Comment: "",
},
ForeignKeys: publicreportNotifyEmailWaterForeignKeys{
PublicreportNotifyEmailWaterNotifyEmailPoolEmailAddressFkey: foreignKey{
ForeignKeys: publicreportNotifyEmailWaterOldForeignKeys{
PublicreportNotifyEmailWaterOldNotifyEmailPoolEmailAddressFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_water.notify_email_pool_email_address_fkey",
Name: "publicreport.notify_email_water_old.notify_email_pool_email_address_fkey",
Columns: []string{"email_address"},
Comment: "",
},
ForeignTable: "comms.email_contact",
ForeignColumns: []string{"address"},
},
PublicreportNotifyEmailWaterNotifyEmailPoolPoolIDFkey: foreignKey{
PublicreportNotifyEmailWaterOldNotifyEmailPoolPoolIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_email_water.notify_email_pool_pool_id_fkey",
Name: "publicreport.notify_email_water_old.notify_email_pool_pool_id_fkey",
Columns: []string{"water_id"},
Comment: "",
},
ForeignTable: "publicreport.water",
ForeignTable: "publicreport.water_old",
ForeignColumns: []string{"id"},
},
},
@ -105,48 +105,48 @@ var PublicreportNotifyEmailWaters = Table[
Comment: "",
}
type publicreportNotifyEmailWaterColumns struct {
type publicreportNotifyEmailWaterOldColumns struct {
Created column
Deleted column
WaterID column
EmailAddress column
}
func (c publicreportNotifyEmailWaterColumns) AsSlice() []column {
func (c publicreportNotifyEmailWaterOldColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.WaterID, c.EmailAddress,
}
}
type publicreportNotifyEmailWaterIndexes struct {
type publicreportNotifyEmailWaterOldIndexes struct {
NotifyEmailPoolPkey index
}
func (i publicreportNotifyEmailWaterIndexes) AsSlice() []index {
func (i publicreportNotifyEmailWaterOldIndexes) AsSlice() []index {
return []index{
i.NotifyEmailPoolPkey,
}
}
type publicreportNotifyEmailWaterForeignKeys struct {
PublicreportNotifyEmailWaterNotifyEmailPoolEmailAddressFkey foreignKey
PublicreportNotifyEmailWaterNotifyEmailPoolPoolIDFkey foreignKey
type publicreportNotifyEmailWaterOldForeignKeys struct {
PublicreportNotifyEmailWaterOldNotifyEmailPoolEmailAddressFkey foreignKey
PublicreportNotifyEmailWaterOldNotifyEmailPoolPoolIDFkey foreignKey
}
func (f publicreportNotifyEmailWaterForeignKeys) AsSlice() []foreignKey {
func (f publicreportNotifyEmailWaterOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyEmailWaterNotifyEmailPoolEmailAddressFkey, f.PublicreportNotifyEmailWaterNotifyEmailPoolPoolIDFkey,
f.PublicreportNotifyEmailWaterOldNotifyEmailPoolEmailAddressFkey, f.PublicreportNotifyEmailWaterOldNotifyEmailPoolPoolIDFkey,
}
}
type publicreportNotifyEmailWaterUniques struct{}
type publicreportNotifyEmailWaterOldUniques struct{}
func (u publicreportNotifyEmailWaterUniques) AsSlice() []constraint {
func (u publicreportNotifyEmailWaterOldUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyEmailWaterChecks struct{}
type publicreportNotifyEmailWaterOldChecks struct{}
func (c publicreportNotifyEmailWaterChecks) AsSlice() []check {
func (c publicreportNotifyEmailWaterOldChecks) 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 PublicreportNotifyPhones = Table[
publicreportNotifyPhoneColumns,
publicreportNotifyPhoneIndexes,
publicreportNotifyPhoneForeignKeys,
publicreportNotifyPhoneUniques,
publicreportNotifyPhoneChecks,
]{
Schema: "publicreport",
Name: "notify_phone",
Columns: publicreportNotifyPhoneColumns{
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,
},
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNotifyPhoneIndexes{
NotifyPhonePkey: index{
Type: "btree",
Name: "notify_phone_pkey",
Columns: []indexColumn{
{
Name: "report_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_pkey",
Columns: []string{"report_id", "phone_e164"},
Comment: "",
},
ForeignKeys: publicreportNotifyPhoneForeignKeys{
PublicreportNotifyPhoneNotifyPhonePhoneE164Fkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone.notify_phone_phone_e164_fkey",
Columns: []string{"phone_e164"},
Comment: "",
},
ForeignTable: "comms.phone",
ForeignColumns: []string{"e164"},
},
PublicreportNotifyPhoneNotifyPhoneReportIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone.notify_phone_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type publicreportNotifyPhoneColumns struct {
Created column
Deleted column
PhoneE164 column
ReportID column
}
func (c publicreportNotifyPhoneColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.PhoneE164, c.ReportID,
}
}
type publicreportNotifyPhoneIndexes struct {
NotifyPhonePkey index
}
func (i publicreportNotifyPhoneIndexes) AsSlice() []index {
return []index{
i.NotifyPhonePkey,
}
}
type publicreportNotifyPhoneForeignKeys struct {
PublicreportNotifyPhoneNotifyPhonePhoneE164Fkey foreignKey
PublicreportNotifyPhoneNotifyPhoneReportIDFkey foreignKey
}
func (f publicreportNotifyPhoneForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyPhoneNotifyPhonePhoneE164Fkey, f.PublicreportNotifyPhoneNotifyPhoneReportIDFkey,
}
}
type publicreportNotifyPhoneUniques struct{}
func (u publicreportNotifyPhoneUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyPhoneChecks struct{}
func (c publicreportNotifyPhoneChecks) AsSlice() []check {
return []check{}
}

View file

@ -5,16 +5,16 @@ package dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyPhoneNuisances = Table[
publicreportNotifyPhoneNuisanceColumns,
publicreportNotifyPhoneNuisanceIndexes,
publicreportNotifyPhoneNuisanceForeignKeys,
publicreportNotifyPhoneNuisanceUniques,
publicreportNotifyPhoneNuisanceChecks,
var PublicreportNotifyPhoneNuisanceOlds = Table[
publicreportNotifyPhoneNuisanceOldColumns,
publicreportNotifyPhoneNuisanceOldIndexes,
publicreportNotifyPhoneNuisanceOldForeignKeys,
publicreportNotifyPhoneNuisanceOldUniques,
publicreportNotifyPhoneNuisanceOldChecks,
]{
Schema: "publicreport",
Name: "notify_phone_nuisance",
Columns: publicreportNotifyPhoneNuisanceColumns{
Name: "notify_phone_nuisance_old",
Columns: publicreportNotifyPhoneNuisanceOldColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
@ -52,7 +52,7 @@ var PublicreportNotifyPhoneNuisances = Table[
AutoIncr: false,
},
},
Indexes: publicreportNotifyPhoneNuisanceIndexes{
Indexes: publicreportNotifyPhoneNuisanceOldIndexes{
NotifyPhoneNuisancePkey: index{
Type: "btree",
Name: "notify_phone_nuisance_pkey",
@ -81,19 +81,19 @@ var PublicreportNotifyPhoneNuisances = Table[
Columns: []string{"nuisance_id", "phone_e164"},
Comment: "",
},
ForeignKeys: publicreportNotifyPhoneNuisanceForeignKeys{
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisanceNuisanceIDFkey: foreignKey{
ForeignKeys: publicreportNotifyPhoneNuisanceOldForeignKeys{
PublicreportNotifyPhoneNuisanceOldNotifyPhoneNuisanceNuisanceIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey",
Name: "publicreport.notify_phone_nuisance_old.notify_phone_nuisance_nuisance_id_fkey",
Columns: []string{"nuisance_id"},
Comment: "",
},
ForeignTable: "publicreport.nuisance",
ForeignTable: "publicreport.nuisance_old",
ForeignColumns: []string{"id"},
},
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisancePhoneE164Fkey: foreignKey{
PublicreportNotifyPhoneNuisanceOldNotifyPhoneNuisancePhoneE164Fkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey",
Name: "publicreport.notify_phone_nuisance_old.notify_phone_nuisance_phone_e164_fkey",
Columns: []string{"phone_e164"},
Comment: "",
},
@ -105,48 +105,48 @@ var PublicreportNotifyPhoneNuisances = Table[
Comment: "",
}
type publicreportNotifyPhoneNuisanceColumns struct {
type publicreportNotifyPhoneNuisanceOldColumns struct {
Created column
Deleted column
NuisanceID column
PhoneE164 column
}
func (c publicreportNotifyPhoneNuisanceColumns) AsSlice() []column {
func (c publicreportNotifyPhoneNuisanceOldColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.NuisanceID, c.PhoneE164,
}
}
type publicreportNotifyPhoneNuisanceIndexes struct {
type publicreportNotifyPhoneNuisanceOldIndexes struct {
NotifyPhoneNuisancePkey index
}
func (i publicreportNotifyPhoneNuisanceIndexes) AsSlice() []index {
func (i publicreportNotifyPhoneNuisanceOldIndexes) AsSlice() []index {
return []index{
i.NotifyPhoneNuisancePkey,
}
}
type publicreportNotifyPhoneNuisanceForeignKeys struct {
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisanceNuisanceIDFkey foreignKey
PublicreportNotifyPhoneNuisanceNotifyPhoneNuisancePhoneE164Fkey foreignKey
type publicreportNotifyPhoneNuisanceOldForeignKeys struct {
PublicreportNotifyPhoneNuisanceOldNotifyPhoneNuisanceNuisanceIDFkey foreignKey
PublicreportNotifyPhoneNuisanceOldNotifyPhoneNuisancePhoneE164Fkey foreignKey
}
func (f publicreportNotifyPhoneNuisanceForeignKeys) AsSlice() []foreignKey {
func (f publicreportNotifyPhoneNuisanceOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyPhoneNuisanceNotifyPhoneNuisanceNuisanceIDFkey, f.PublicreportNotifyPhoneNuisanceNotifyPhoneNuisancePhoneE164Fkey,
f.PublicreportNotifyPhoneNuisanceOldNotifyPhoneNuisanceNuisanceIDFkey, f.PublicreportNotifyPhoneNuisanceOldNotifyPhoneNuisancePhoneE164Fkey,
}
}
type publicreportNotifyPhoneNuisanceUniques struct{}
type publicreportNotifyPhoneNuisanceOldUniques struct{}
func (u publicreportNotifyPhoneNuisanceUniques) AsSlice() []constraint {
func (u publicreportNotifyPhoneNuisanceOldUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyPhoneNuisanceChecks struct{}
type publicreportNotifyPhoneNuisanceOldChecks struct{}
func (c publicreportNotifyPhoneNuisanceChecks) AsSlice() []check {
func (c publicreportNotifyPhoneNuisanceOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -5,16 +5,16 @@ package dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNotifyPhoneWaters = Table[
publicreportNotifyPhoneWaterColumns,
publicreportNotifyPhoneWaterIndexes,
publicreportNotifyPhoneWaterForeignKeys,
publicreportNotifyPhoneWaterUniques,
publicreportNotifyPhoneWaterChecks,
var PublicreportNotifyPhoneWaterOlds = Table[
publicreportNotifyPhoneWaterOldColumns,
publicreportNotifyPhoneWaterOldIndexes,
publicreportNotifyPhoneWaterOldForeignKeys,
publicreportNotifyPhoneWaterOldUniques,
publicreportNotifyPhoneWaterOldChecks,
]{
Schema: "publicreport",
Name: "notify_phone_water",
Columns: publicreportNotifyPhoneWaterColumns{
Name: "notify_phone_water_old",
Columns: publicreportNotifyPhoneWaterOldColumns{
Created: column{
Name: "created",
DBType: "timestamp without time zone",
@ -52,7 +52,7 @@ var PublicreportNotifyPhoneWaters = Table[
AutoIncr: false,
},
},
Indexes: publicreportNotifyPhoneWaterIndexes{
Indexes: publicreportNotifyPhoneWaterOldIndexes{
NotifyPhonePoolPkey: index{
Type: "btree",
Name: "notify_phone_pool_pkey",
@ -81,23 +81,23 @@ var PublicreportNotifyPhoneWaters = Table[
Columns: []string{"water_id", "phone_e164"},
Comment: "",
},
ForeignKeys: publicreportNotifyPhoneWaterForeignKeys{
PublicreportNotifyPhoneWaterNotifyPhonePoolPhoneE164Fkey: foreignKey{
ForeignKeys: publicreportNotifyPhoneWaterOldForeignKeys{
PublicreportNotifyPhoneWaterOldNotifyPhonePoolPhoneE164Fkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_water.notify_phone_pool_phone_e164_fkey",
Name: "publicreport.notify_phone_water_old.notify_phone_pool_phone_e164_fkey",
Columns: []string{"phone_e164"},
Comment: "",
},
ForeignTable: "comms.phone",
ForeignColumns: []string{"e164"},
},
PublicreportNotifyPhoneWaterNotifyPhonePoolPoolIDFkey: foreignKey{
PublicreportNotifyPhoneWaterOldNotifyPhonePoolPoolIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.notify_phone_water.notify_phone_pool_pool_id_fkey",
Name: "publicreport.notify_phone_water_old.notify_phone_pool_pool_id_fkey",
Columns: []string{"water_id"},
Comment: "",
},
ForeignTable: "publicreport.water",
ForeignTable: "publicreport.water_old",
ForeignColumns: []string{"id"},
},
},
@ -105,48 +105,48 @@ var PublicreportNotifyPhoneWaters = Table[
Comment: "",
}
type publicreportNotifyPhoneWaterColumns struct {
type publicreportNotifyPhoneWaterOldColumns struct {
Created column
Deleted column
PhoneE164 column
WaterID column
}
func (c publicreportNotifyPhoneWaterColumns) AsSlice() []column {
func (c publicreportNotifyPhoneWaterOldColumns) AsSlice() []column {
return []column{
c.Created, c.Deleted, c.PhoneE164, c.WaterID,
}
}
type publicreportNotifyPhoneWaterIndexes struct {
type publicreportNotifyPhoneWaterOldIndexes struct {
NotifyPhonePoolPkey index
}
func (i publicreportNotifyPhoneWaterIndexes) AsSlice() []index {
func (i publicreportNotifyPhoneWaterOldIndexes) AsSlice() []index {
return []index{
i.NotifyPhonePoolPkey,
}
}
type publicreportNotifyPhoneWaterForeignKeys struct {
PublicreportNotifyPhoneWaterNotifyPhonePoolPhoneE164Fkey foreignKey
PublicreportNotifyPhoneWaterNotifyPhonePoolPoolIDFkey foreignKey
type publicreportNotifyPhoneWaterOldForeignKeys struct {
PublicreportNotifyPhoneWaterOldNotifyPhonePoolPhoneE164Fkey foreignKey
PublicreportNotifyPhoneWaterOldNotifyPhonePoolPoolIDFkey foreignKey
}
func (f publicreportNotifyPhoneWaterForeignKeys) AsSlice() []foreignKey {
func (f publicreportNotifyPhoneWaterOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNotifyPhoneWaterNotifyPhonePoolPhoneE164Fkey, f.PublicreportNotifyPhoneWaterNotifyPhonePoolPoolIDFkey,
f.PublicreportNotifyPhoneWaterOldNotifyPhonePoolPhoneE164Fkey, f.PublicreportNotifyPhoneWaterOldNotifyPhonePoolPoolIDFkey,
}
}
type publicreportNotifyPhoneWaterUniques struct{}
type publicreportNotifyPhoneWaterOldUniques struct{}
func (u publicreportNotifyPhoneWaterUniques) AsSlice() []constraint {
func (u publicreportNotifyPhoneWaterOldUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNotifyPhoneWaterChecks struct{}
type publicreportNotifyPhoneWaterOldChecks struct{}
func (c publicreportNotifyPhoneWaterChecks) AsSlice() []check {
func (c publicreportNotifyPhoneWaterOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -15,15 +15,6 @@ var PublicreportNuisances = Table[
Schema: "publicreport",
Name: "nuisance",
Columns: publicreportNuisanceColumns{
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('publicreport.nuisance_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AdditionalInfo: column{
Name: "additional_info",
DBType: "text",
@ -33,15 +24,6 @@ var PublicreportNuisances = Table[
Generated: false,
AutoIncr: false,
},
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Duration: column{
Name: "duration",
DBType: "publicreport.nuisancedurationtype",
@ -51,159 +33,6 @@ var PublicreportNuisances = Table[
Generated: false,
AutoIncr: false,
},
SourceContainer: column{
Name: "source_container",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceDescription: column{
Name: "source_description",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceStagnant: column{
Name: "source_stagnant",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PublicID: column{
Name: "public_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterEmail: column{
Name: "reporter_email",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReporterName: column{
Name: "reporter_name",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReporterPhone: column{
Name: "reporter_phone",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressRaw: column{
Name: "address_raw",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Status: column{
Name: "status",
DBType: "publicreport.reportstatustype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OrganizationID: column{
Name: "organization_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceGutter: column{
Name: "source_gutter",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
H3cell: column{
Name: "h3cell",
DBType: "h3index",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressCountry: column{
Name: "address_country",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressLocality: column{
Name: "address_locality",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressPostalCode: column{
Name: "address_postal_code",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressRegion: column{
Name: "address_region",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressStreet: column{
Name: "address_street",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsLocationBackyard: column{
Name: "is_location_backyard",
DBType: "boolean",
@ -249,9 +78,45 @@ var PublicreportNuisances = Table[
Generated: false,
AutoIncr: false,
},
MapZoom: column{
Name: "map_zoom",
DBType: "real",
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceContainer: column{
Name: "source_container",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceDescription: column{
Name: "source_description",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceStagnant: column{
Name: "source_stagnant",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceGutter: column{
Name: "source_gutter",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
@ -294,103 +159,14 @@ var PublicreportNuisances = Table[
Generated: false,
AutoIncr: false,
},
LatlngAccuracyType: column{
Name: "latlng_accuracy_type",
DBType: "publicreport.accuracytype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
LatlngAccuracyValue: column{
Name: "latlng_accuracy_value",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Location: column{
Name: "location",
DBType: "geometry",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressNumber: column{
Name: "address_number",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressID: column{
Name: "address_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Reviewed: column{
Name: "reviewed",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReviewerID: column{
Name: "reviewer_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNuisanceIndexes{
NuisancePkey: index{
NuisancePkey1: index{
Type: "btree",
Name: "nuisance_pkey",
Name: "nuisance_pkey1",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
NuisancePublicIDKey: index{
Type: "btree",
Name: "nuisance_public_id_key",
Columns: []indexColumn{
{
Name: "public_id",
Name: "report_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
@ -404,129 +180,74 @@ var PublicreportNuisances = Table[
},
},
PrimaryKey: &constraint{
Name: "nuisance_pkey",
Columns: []string{"id"},
Name: "nuisance_pkey1",
Columns: []string{"report_id"},
Comment: "",
},
ForeignKeys: publicreportNuisanceForeignKeys{
PublicreportNuisanceNuisanceAddressIDFkey: foreignKey{
PublicreportNuisanceNuisanceReportIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance.nuisance_address_id_fkey",
Columns: []string{"address_id"},
Name: "publicreport.nuisance.nuisance_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "address",
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
PublicreportNuisanceNuisanceOrganizationIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance.nuisance_organization_id_fkey",
Columns: []string{"organization_id"},
Comment: "",
},
ForeignTable: "organization",
ForeignColumns: []string{"id"},
},
PublicreportNuisanceNuisanceReviewerIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance.nuisance_reviewer_id_fkey",
Columns: []string{"reviewer_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Uniques: publicreportNuisanceUniques{
NuisancePublicIDKey: constraint{
Name: "nuisance_public_id_key",
Columns: []string{"public_id"},
Comment: "",
},
},
Comment: "",
}
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
AddressRaw column
Status column
OrganizationID column
SourceGutter column
H3cell column
AddressCountry column
AddressLocality column
AddressPostalCode 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
Location column
AddressNumber column
AddressID column
Reviewed column
ReviewerID column
AdditionalInfo column
Duration column
IsLocationBackyard column
IsLocationFrontyard column
IsLocationGarden column
IsLocationOther column
IsLocationPool column
ReportID column
SourceContainer column
SourceDescription column
SourceStagnant column
SourceGutter column
TodEarly column
TodDay column
TodEvening column
TodNight 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.AddressRaw, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressLocality, c.AddressPostalCode, 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, c.Location, c.AddressNumber, c.AddressID, c.Reviewed, c.ReviewerID,
c.AdditionalInfo, c.Duration, c.IsLocationBackyard, c.IsLocationFrontyard, c.IsLocationGarden, c.IsLocationOther, c.IsLocationPool, c.ReportID, c.SourceContainer, c.SourceDescription, c.SourceStagnant, c.SourceGutter, c.TodEarly, c.TodDay, c.TodEvening, c.TodNight,
}
}
type publicreportNuisanceIndexes struct {
NuisancePkey index
NuisancePublicIDKey index
NuisancePkey1 index
}
func (i publicreportNuisanceIndexes) AsSlice() []index {
return []index{
i.NuisancePkey, i.NuisancePublicIDKey,
i.NuisancePkey1,
}
}
type publicreportNuisanceForeignKeys struct {
PublicreportNuisanceNuisanceAddressIDFkey foreignKey
PublicreportNuisanceNuisanceOrganizationIDFkey foreignKey
PublicreportNuisanceNuisanceReviewerIDFkey foreignKey
PublicreportNuisanceNuisanceReportIDFkey foreignKey
}
func (f publicreportNuisanceForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNuisanceNuisanceAddressIDFkey, f.PublicreportNuisanceNuisanceOrganizationIDFkey, f.PublicreportNuisanceNuisanceReviewerIDFkey,
f.PublicreportNuisanceNuisanceReportIDFkey,
}
}
type publicreportNuisanceUniques struct {
NuisancePublicIDKey constraint
}
type publicreportNuisanceUniques struct{}
func (u publicreportNuisanceUniques) AsSlice() []constraint {
return []constraint{
u.NuisancePublicIDKey,
}
return []constraint{}
}
type publicreportNuisanceChecks struct{}

View file

@ -5,16 +5,16 @@ package dbinfo
import "github.com/aarondl/opt/null"
var PublicreportNuisanceImages = Table[
publicreportNuisanceImageColumns,
publicreportNuisanceImageIndexes,
publicreportNuisanceImageForeignKeys,
publicreportNuisanceImageUniques,
publicreportNuisanceImageChecks,
var PublicreportNuisanceImageOlds = Table[
publicreportNuisanceImageOldColumns,
publicreportNuisanceImageOldIndexes,
publicreportNuisanceImageOldForeignKeys,
publicreportNuisanceImageOldUniques,
publicreportNuisanceImageOldChecks,
]{
Schema: "publicreport",
Name: "nuisance_image",
Columns: publicreportNuisanceImageColumns{
Name: "nuisance_image_old",
Columns: publicreportNuisanceImageOldColumns{
ImageID: column{
Name: "image_id",
DBType: "integer",
@ -34,7 +34,7 @@ var PublicreportNuisanceImages = Table[
AutoIncr: false,
},
},
Indexes: publicreportNuisanceImageIndexes{
Indexes: publicreportNuisanceImageOldIndexes{
NuisanceImagePkey: index{
Type: "btree",
Name: "nuisance_image_pkey",
@ -63,23 +63,23 @@ var PublicreportNuisanceImages = Table[
Columns: []string{"image_id", "nuisance_id"},
Comment: "",
},
ForeignKeys: publicreportNuisanceImageForeignKeys{
PublicreportNuisanceImageNuisanceImageImageIDFkey: foreignKey{
ForeignKeys: publicreportNuisanceImageOldForeignKeys{
PublicreportNuisanceImageOldNuisanceImageImageIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance_image.nuisance_image_image_id_fkey",
Name: "publicreport.nuisance_image_old.nuisance_image_image_id_fkey",
Columns: []string{"image_id"},
Comment: "",
},
ForeignTable: "publicreport.image",
ForeignColumns: []string{"id"},
},
PublicreportNuisanceImageNuisanceImageNuisanceIDFkey: foreignKey{
PublicreportNuisanceImageOldNuisanceImageNuisanceIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance_image.nuisance_image_nuisance_id_fkey",
Name: "publicreport.nuisance_image_old.nuisance_image_nuisance_id_fkey",
Columns: []string{"nuisance_id"},
Comment: "",
},
ForeignTable: "publicreport.nuisance",
ForeignTable: "publicreport.nuisance_old",
ForeignColumns: []string{"id"},
},
},
@ -87,46 +87,46 @@ var PublicreportNuisanceImages = Table[
Comment: "",
}
type publicreportNuisanceImageColumns struct {
type publicreportNuisanceImageOldColumns struct {
ImageID column
NuisanceID column
}
func (c publicreportNuisanceImageColumns) AsSlice() []column {
func (c publicreportNuisanceImageOldColumns) AsSlice() []column {
return []column{
c.ImageID, c.NuisanceID,
}
}
type publicreportNuisanceImageIndexes struct {
type publicreportNuisanceImageOldIndexes struct {
NuisanceImagePkey index
}
func (i publicreportNuisanceImageIndexes) AsSlice() []index {
func (i publicreportNuisanceImageOldIndexes) AsSlice() []index {
return []index{
i.NuisanceImagePkey,
}
}
type publicreportNuisanceImageForeignKeys struct {
PublicreportNuisanceImageNuisanceImageImageIDFkey foreignKey
PublicreportNuisanceImageNuisanceImageNuisanceIDFkey foreignKey
type publicreportNuisanceImageOldForeignKeys struct {
PublicreportNuisanceImageOldNuisanceImageImageIDFkey foreignKey
PublicreportNuisanceImageOldNuisanceImageNuisanceIDFkey foreignKey
}
func (f publicreportNuisanceImageForeignKeys) AsSlice() []foreignKey {
func (f publicreportNuisanceImageOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNuisanceImageNuisanceImageImageIDFkey, f.PublicreportNuisanceImageNuisanceImageNuisanceIDFkey,
f.PublicreportNuisanceImageOldNuisanceImageImageIDFkey, f.PublicreportNuisanceImageOldNuisanceImageNuisanceIDFkey,
}
}
type publicreportNuisanceImageUniques struct{}
type publicreportNuisanceImageOldUniques struct{}
func (u publicreportNuisanceImageUniques) AsSlice() []constraint {
func (u publicreportNuisanceImageOldUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportNuisanceImageChecks struct{}
type publicreportNuisanceImageOldChecks struct{}
func (c publicreportNuisanceImageChecks) AsSlice() []check {
func (c publicreportNuisanceImageOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,536 @@
// 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 PublicreportNuisanceOlds = Table[
publicreportNuisanceOldColumns,
publicreportNuisanceOldIndexes,
publicreportNuisanceOldForeignKeys,
publicreportNuisanceOldUniques,
publicreportNuisanceOldChecks,
]{
Schema: "publicreport",
Name: "nuisance_old",
Columns: publicreportNuisanceOldColumns{
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('publicreport.nuisance_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AdditionalInfo: column{
Name: "additional_info",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Duration: column{
Name: "duration",
DBType: "publicreport.nuisancedurationtype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceContainer: column{
Name: "source_container",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceDescription: column{
Name: "source_description",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceStagnant: column{
Name: "source_stagnant",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PublicID: column{
Name: "public_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterEmail: column{
Name: "reporter_email",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReporterName: column{
Name: "reporter_name",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReporterPhone: column{
Name: "reporter_phone",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressRaw: column{
Name: "address_raw",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Status: column{
Name: "status",
DBType: "publicreport.reportstatustype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OrganizationID: column{
Name: "organization_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
SourceGutter: column{
Name: "source_gutter",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
H3cell: column{
Name: "h3cell",
DBType: "h3index",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressCountry: column{
Name: "address_country",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressLocality: column{
Name: "address_locality",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressPostalCode: column{
Name: "address_postal_code",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressRegion: column{
Name: "address_region",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressStreet: column{
Name: "address_street",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsLocationBackyard: column{
Name: "is_location_backyard",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsLocationFrontyard: column{
Name: "is_location_frontyard",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsLocationGarden: column{
Name: "is_location_garden",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsLocationOther: column{
Name: "is_location_other",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsLocationPool: column{
Name: "is_location_pool",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
MapZoom: column{
Name: "map_zoom",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
TodEarly: column{
Name: "tod_early",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
TodDay: column{
Name: "tod_day",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
TodEvening: column{
Name: "tod_evening",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
TodNight: column{
Name: "tod_night",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
LatlngAccuracyType: column{
Name: "latlng_accuracy_type",
DBType: "publicreport.accuracytype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
LatlngAccuracyValue: column{
Name: "latlng_accuracy_value",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Location: column{
Name: "location",
DBType: "geometry",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressNumber: column{
Name: "address_number",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressID: column{
Name: "address_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Reviewed: column{
Name: "reviewed",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReviewerID: column{
Name: "reviewer_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportNuisanceOldIndexes{
NuisancePkey: index{
Type: "btree",
Name: "nuisance_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
NuisancePublicIDKey: index{
Type: "btree",
Name: "nuisance_public_id_key",
Columns: []indexColumn{
{
Name: "public_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "nuisance_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: publicreportNuisanceOldForeignKeys{
PublicreportNuisanceOldNuisanceAddressIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance_old.nuisance_address_id_fkey",
Columns: []string{"address_id"},
Comment: "",
},
ForeignTable: "address",
ForeignColumns: []string{"id"},
},
PublicreportNuisanceOldNuisanceOrganizationIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance_old.nuisance_organization_id_fkey",
Columns: []string{"organization_id"},
Comment: "",
},
ForeignTable: "organization",
ForeignColumns: []string{"id"},
},
PublicreportNuisanceOldNuisanceReviewerIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.nuisance_old.nuisance_reviewer_id_fkey",
Columns: []string{"reviewer_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Uniques: publicreportNuisanceOldUniques{
NuisancePublicIDKey: constraint{
Name: "nuisance_public_id_key",
Columns: []string{"public_id"},
Comment: "",
},
},
Comment: "",
}
type publicreportNuisanceOldColumns struct {
ID column
AdditionalInfo column
Created column
Duration column
SourceContainer column
SourceDescription column
SourceStagnant column
PublicID column
ReporterEmail column
ReporterName column
ReporterPhone column
AddressRaw column
Status column
OrganizationID column
SourceGutter column
H3cell column
AddressCountry column
AddressLocality column
AddressPostalCode 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
Location column
AddressNumber column
AddressID column
Reviewed column
ReviewerID column
}
func (c publicreportNuisanceOldColumns) 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.AddressRaw, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressLocality, c.AddressPostalCode, 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, c.Location, c.AddressNumber, c.AddressID, c.Reviewed, c.ReviewerID,
}
}
type publicreportNuisanceOldIndexes struct {
NuisancePkey index
NuisancePublicIDKey index
}
func (i publicreportNuisanceOldIndexes) AsSlice() []index {
return []index{
i.NuisancePkey, i.NuisancePublicIDKey,
}
}
type publicreportNuisanceOldForeignKeys struct {
PublicreportNuisanceOldNuisanceAddressIDFkey foreignKey
PublicreportNuisanceOldNuisanceOrganizationIDFkey foreignKey
PublicreportNuisanceOldNuisanceReviewerIDFkey foreignKey
}
func (f publicreportNuisanceOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportNuisanceOldNuisanceAddressIDFkey, f.PublicreportNuisanceOldNuisanceOrganizationIDFkey, f.PublicreportNuisanceOldNuisanceReviewerIDFkey,
}
}
type publicreportNuisanceOldUniques struct {
NuisancePublicIDKey constraint
}
func (u publicreportNuisanceOldUniques) AsSlice() []constraint {
return []constraint{
u.NuisancePublicIDKey,
}
}
type publicreportNuisanceOldChecks struct{}
func (c publicreportNuisanceOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,409 @@
// 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 PublicreportReports = Table[
publicreportReportColumns,
publicreportReportIndexes,
publicreportReportForeignKeys,
publicreportReportUniques,
publicreportReportChecks,
]{
Schema: "publicreport",
Name: "report",
Columns: publicreportReportColumns{
AddressRaw: column{
Name: "address_raw",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressNumber: column{
Name: "address_number",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressStreet: column{
Name: "address_street",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressLocality: column{
Name: "address_locality",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressRegion: column{
Name: "address_region",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressPostalCode: column{
Name: "address_postal_code",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressCountry: column{
Name: "address_country",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressID: column{
Name: "address_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Location: column{
Name: "location",
DBType: "geometry",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
H3cell: column{
Name: "h3cell",
DBType: "h3index",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('publicreport.report_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
LatlngAccuracyType: column{
Name: "latlng_accuracy_type",
DBType: "publicreport.accuracytype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
LatlngAccuracyValue: column{
Name: "latlng_accuracy_value",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
MapZoom: column{
Name: "map_zoom",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OrganizationID: column{
Name: "organization_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PublicID: column{
Name: "public_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterName: column{
Name: "reporter_name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterEmail: column{
Name: "reporter_email",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterPhone: column{
Name: "reporter_phone",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReportType: column{
Name: "report_type",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Reviewed: column{
Name: "reviewed",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReviewerID: column{
Name: "reviewer_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Status: column{
Name: "status",
DBType: "publicreport.reportstatustype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportReportIndexes{
ReportPkey: index{
Type: "btree",
Name: "report_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
ReportPublicIDKey: index{
Type: "btree",
Name: "report_public_id_key",
Columns: []indexColumn{
{
Name: "public_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "report_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: publicreportReportForeignKeys{
PublicreportReportReportAddressIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.report.report_address_id_fkey",
Columns: []string{"address_id"},
Comment: "",
},
ForeignTable: "address",
ForeignColumns: []string{"id"},
},
PublicreportReportReportOrganizationIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.report.report_organization_id_fkey",
Columns: []string{"organization_id"},
Comment: "",
},
ForeignTable: "organization",
ForeignColumns: []string{"id"},
},
PublicreportReportReportReviewerIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.report.report_reviewer_id_fkey",
Columns: []string{"reviewer_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Uniques: publicreportReportUniques{
ReportPublicIDKey: constraint{
Name: "report_public_id_key",
Columns: []string{"public_id"},
Comment: "",
},
},
Checks: publicreportReportChecks{
ReportReportTypeCheck: check{
constraint: constraint{
Name: "report_report_type_check",
Columns: []string{"report_type"},
Comment: "",
},
Expression: "(report_type = ANY (ARRAY['nuisance'::text, 'water'::text]))",
},
},
Comment: "",
}
type publicreportReportColumns struct {
AddressRaw column
AddressNumber column
AddressStreet column
AddressLocality column
AddressRegion column
AddressPostalCode column
AddressCountry column
AddressID column
Created column
Location column
H3cell column
ID column
LatlngAccuracyType column
LatlngAccuracyValue column
MapZoom column
OrganizationID column
PublicID column
ReporterName column
ReporterEmail column
ReporterPhone column
ReporterContactConsent column
ReportType column
Reviewed column
ReviewerID column
Status column
}
func (c publicreportReportColumns) AsSlice() []column {
return []column{
c.AddressRaw, c.AddressNumber, c.AddressStreet, c.AddressLocality, c.AddressRegion, c.AddressPostalCode, c.AddressCountry, c.AddressID, c.Created, c.Location, c.H3cell, c.ID, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.MapZoom, c.OrganizationID, c.PublicID, c.ReporterName, c.ReporterEmail, c.ReporterPhone, c.ReporterContactConsent, c.ReportType, c.Reviewed, c.ReviewerID, c.Status,
}
}
type publicreportReportIndexes struct {
ReportPkey index
ReportPublicIDKey index
}
func (i publicreportReportIndexes) AsSlice() []index {
return []index{
i.ReportPkey, i.ReportPublicIDKey,
}
}
type publicreportReportForeignKeys struct {
PublicreportReportReportAddressIDFkey foreignKey
PublicreportReportReportOrganizationIDFkey foreignKey
PublicreportReportReportReviewerIDFkey foreignKey
}
func (f publicreportReportForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportReportReportAddressIDFkey, f.PublicreportReportReportOrganizationIDFkey, f.PublicreportReportReportReviewerIDFkey,
}
}
type publicreportReportUniques struct {
ReportPublicIDKey constraint
}
func (u publicreportReportUniques) AsSlice() []constraint {
return []constraint{
u.ReportPublicIDKey,
}
}
type publicreportReportChecks struct {
ReportReportTypeCheck check
}
func (c publicreportReportChecks) AsSlice() []check {
return []check{
c.ReportReportTypeCheck,
}
}

View file

@ -0,0 +1,132 @@
// 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 PublicreportReportImages = Table[
publicreportReportImageColumns,
publicreportReportImageIndexes,
publicreportReportImageForeignKeys,
publicreportReportImageUniques,
publicreportReportImageChecks,
]{
Schema: "publicreport",
Name: "report_image",
Columns: publicreportReportImageColumns{
ImageID: column{
Name: "image_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportReportImageIndexes{
ReportImagePkey: index{
Type: "btree",
Name: "report_image_pkey",
Columns: []indexColumn{
{
Name: "image_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "report_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "report_image_pkey",
Columns: []string{"image_id", "report_id"},
Comment: "",
},
ForeignKeys: publicreportReportImageForeignKeys{
PublicreportReportImageReportImageImageIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.report_image.report_image_image_id_fkey",
Columns: []string{"image_id"},
Comment: "",
},
ForeignTable: "publicreport.image",
ForeignColumns: []string{"id"},
},
PublicreportReportImageReportImageReportIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.report_image.report_image_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type publicreportReportImageColumns struct {
ImageID column
ReportID column
}
func (c publicreportReportImageColumns) AsSlice() []column {
return []column{
c.ImageID, c.ReportID,
}
}
type publicreportReportImageIndexes struct {
ReportImagePkey index
}
func (i publicreportReportImageIndexes) AsSlice() []index {
return []index{
i.ReportImagePkey,
}
}
type publicreportReportImageForeignKeys struct {
PublicreportReportImageReportImageImageIDFkey foreignKey
PublicreportReportImageReportImageReportIDFkey foreignKey
}
func (f publicreportReportImageForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportReportImageReportImageImageIDFkey, f.PublicreportReportImageReportImageReportIDFkey,
}
}
type publicreportReportImageUniques struct{}
func (u publicreportReportImageUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportReportImageChecks struct{}
func (c publicreportReportImageChecks) AsSlice() []check {
return []check{}
}

View file

@ -15,15 +15,6 @@ var PublicreportWaters = Table[
Schema: "publicreport",
Name: "water",
Columns: publicreportWaterColumns{
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('publicreport.pool_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessComments: column{
Name: "access_comments",
DBType: "text",
@ -78,60 +69,6 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
AddressRaw: column{
Name: "address_raw",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressCountry: column{
Name: "address_country",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressPostalCode: column{
Name: "address_postal_code",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressLocality: column{
Name: "address_locality",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressStreet: column{
Name: "address_street",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressRegion: column{
Name: "address_region",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Comments: column{
Name: "comments",
DBType: "text",
@ -141,21 +78,21 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
Created: column{
Name: "created",
DBType: "timestamp without time zone",
IsReporterConfidential: column{
Name: "is_reporter_confidential",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
H3cell: column{
Name: "h3cell",
DBType: "h3index",
Default: "NULL",
IsReporterOwner: column{
Name: "is_reporter_owner",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: true,
Nullable: false,
Generated: false,
AutoIncr: false,
},
@ -168,6 +105,15 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
HasBackyardPermission: column{
Name: "has_backyard_permission",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
HasLarvae: column{
Name: "has_larvae",
DBType: "boolean",
@ -186,15 +132,6 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
MapZoom: column{
Name: "map_zoom",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OwnerEmail: column{
Name: "owner_email",
DBType: "text",
@ -222,53 +159,8 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
PublicID: column{
Name: "public_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterEmail: column{
Name: "reporter_email",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterName: column{
Name: "reporter_name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterPhone: column{
Name: "reporter_phone",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Status: column{
Name: "status",
DBType: "publicreport.reportstatustype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OrganizationID: column{
Name: "organization_id",
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "",
Comment: "",
@ -276,112 +168,14 @@ var PublicreportWaters = Table[
Generated: false,
AutoIncr: false,
},
HasBackyardPermission: column{
Name: "has_backyard_permission",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsReporterConfidential: column{
Name: "is_reporter_confidential",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsReporterOwner: column{
Name: "is_reporter_owner",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Location: column{
Name: "location",
DBType: "geometry",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressNumber: column{
Name: "address_number",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressID: column{
Name: "address_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Reviewed: column{
Name: "reviewed",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReviewerID: column{
Name: "reviewer_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportWaterIndexes{
PoolPkey: index{
WaterPkey: index{
Type: "btree",
Name: "pool_pkey",
Name: "water_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
PoolPublicIDKey: index{
Type: "btree",
Name: "pool_public_id_key",
Columns: []indexColumn{
{
Name: "public_id",
Name: "report_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
@ -395,128 +189,75 @@ var PublicreportWaters = Table[
},
},
PrimaryKey: &constraint{
Name: "pool_pkey",
Columns: []string{"id"},
Name: "water_pkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignKeys: publicreportWaterForeignKeys{
PublicreportWaterPoolAddressIDFkey: foreignKey{
PublicreportWaterWaterReportIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water.pool_address_id_fkey",
Columns: []string{"address_id"},
Name: "publicreport.water.water_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "address",
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
PublicreportWaterPoolOrganizationIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water.pool_organization_id_fkey",
Columns: []string{"organization_id"},
Comment: "",
},
ForeignTable: "organization",
ForeignColumns: []string{"id"},
},
PublicreportWaterWaterReviewerIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water.water_reviewer_id_fkey",
Columns: []string{"reviewer_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Uniques: publicreportWaterUniques{
PoolPublicIDKey: constraint{
Name: "pool_public_id_key",
Columns: []string{"public_id"},
Comment: "",
},
},
Comment: "",
}
type publicreportWaterColumns struct {
ID column
AccessComments column
AccessGate column
AccessFence column
AccessLocked column
AccessDog column
AccessOther column
AddressRaw column
AddressCountry column
AddressPostalCode column
AddressLocality column
AddressStreet column
AddressRegion column
Comments column
Created column
H3cell column
IsReporterConfidential column
IsReporterOwner column
HasAdult column
HasBackyardPermission column
HasLarvae column
HasPupae column
MapZoom column
OwnerEmail column
OwnerName column
OwnerPhone column
PublicID column
ReporterEmail column
ReporterName column
ReporterPhone column
Status column
OrganizationID column
HasBackyardPermission column
IsReporterConfidential column
IsReporterOwner column
ReporterContactConsent column
Location column
AddressNumber column
AddressID column
Reviewed column
ReviewerID column
ReportID column
}
func (c publicreportWaterColumns) AsSlice() []column {
return []column{
c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.AddressRaw, c.AddressCountry, c.AddressPostalCode, c.AddressLocality, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, 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, c.Location, c.AddressNumber, c.AddressID, c.Reviewed, c.ReviewerID,
c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.Comments, c.IsReporterConfidential, c.IsReporterOwner, c.HasAdult, c.HasBackyardPermission, c.HasLarvae, c.HasPupae, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.ReportID,
}
}
type publicreportWaterIndexes struct {
PoolPkey index
PoolPublicIDKey index
WaterPkey index
}
func (i publicreportWaterIndexes) AsSlice() []index {
return []index{
i.PoolPkey, i.PoolPublicIDKey,
i.WaterPkey,
}
}
type publicreportWaterForeignKeys struct {
PublicreportWaterPoolAddressIDFkey foreignKey
PublicreportWaterPoolOrganizationIDFkey foreignKey
PublicreportWaterWaterReviewerIDFkey foreignKey
PublicreportWaterWaterReportIDFkey foreignKey
}
func (f publicreportWaterForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportWaterPoolAddressIDFkey, f.PublicreportWaterPoolOrganizationIDFkey, f.PublicreportWaterWaterReviewerIDFkey,
f.PublicreportWaterWaterReportIDFkey,
}
}
type publicreportWaterUniques struct {
PoolPublicIDKey constraint
}
type publicreportWaterUniques struct{}
func (u publicreportWaterUniques) AsSlice() []constraint {
return []constraint{
u.PoolPublicIDKey,
}
return []constraint{}
}
type publicreportWaterChecks struct{}

View file

@ -5,16 +5,16 @@ package dbinfo
import "github.com/aarondl/opt/null"
var PublicreportWaterImages = Table[
publicreportWaterImageColumns,
publicreportWaterImageIndexes,
publicreportWaterImageForeignKeys,
publicreportWaterImageUniques,
publicreportWaterImageChecks,
var PublicreportWaterImageOlds = Table[
publicreportWaterImageOldColumns,
publicreportWaterImageOldIndexes,
publicreportWaterImageOldForeignKeys,
publicreportWaterImageOldUniques,
publicreportWaterImageOldChecks,
]{
Schema: "publicreport",
Name: "water_image",
Columns: publicreportWaterImageColumns{
Name: "water_image_old",
Columns: publicreportWaterImageOldColumns{
ImageID: column{
Name: "image_id",
DBType: "integer",
@ -34,7 +34,7 @@ var PublicreportWaterImages = Table[
AutoIncr: false,
},
},
Indexes: publicreportWaterImageIndexes{
Indexes: publicreportWaterImageOldIndexes{
PoolImagePkey: index{
Type: "btree",
Name: "pool_image_pkey",
@ -63,23 +63,23 @@ var PublicreportWaterImages = Table[
Columns: []string{"image_id", "water_id"},
Comment: "",
},
ForeignKeys: publicreportWaterImageForeignKeys{
PublicreportWaterImagePoolImageImageIDFkey: foreignKey{
ForeignKeys: publicreportWaterImageOldForeignKeys{
PublicreportWaterImageOldPoolImageImageIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water_image.pool_image_image_id_fkey",
Name: "publicreport.water_image_old.pool_image_image_id_fkey",
Columns: []string{"image_id"},
Comment: "",
},
ForeignTable: "publicreport.image",
ForeignColumns: []string{"id"},
},
PublicreportWaterImagePoolImagePoolIDFkey: foreignKey{
PublicreportWaterImageOldPoolImagePoolIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water_image.pool_image_pool_id_fkey",
Name: "publicreport.water_image_old.pool_image_pool_id_fkey",
Columns: []string{"water_id"},
Comment: "",
},
ForeignTable: "publicreport.water",
ForeignTable: "publicreport.water_old",
ForeignColumns: []string{"id"},
},
},
@ -87,46 +87,46 @@ var PublicreportWaterImages = Table[
Comment: "",
}
type publicreportWaterImageColumns struct {
type publicreportWaterImageOldColumns struct {
ImageID column
WaterID column
}
func (c publicreportWaterImageColumns) AsSlice() []column {
func (c publicreportWaterImageOldColumns) AsSlice() []column {
return []column{
c.ImageID, c.WaterID,
}
}
type publicreportWaterImageIndexes struct {
type publicreportWaterImageOldIndexes struct {
PoolImagePkey index
}
func (i publicreportWaterImageIndexes) AsSlice() []index {
func (i publicreportWaterImageOldIndexes) AsSlice() []index {
return []index{
i.PoolImagePkey,
}
}
type publicreportWaterImageForeignKeys struct {
PublicreportWaterImagePoolImageImageIDFkey foreignKey
PublicreportWaterImagePoolImagePoolIDFkey foreignKey
type publicreportWaterImageOldForeignKeys struct {
PublicreportWaterImageOldPoolImageImageIDFkey foreignKey
PublicreportWaterImageOldPoolImagePoolIDFkey foreignKey
}
func (f publicreportWaterImageForeignKeys) AsSlice() []foreignKey {
func (f publicreportWaterImageOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportWaterImagePoolImageImageIDFkey, f.PublicreportWaterImagePoolImagePoolIDFkey,
f.PublicreportWaterImageOldPoolImageImageIDFkey, f.PublicreportWaterImageOldPoolImagePoolIDFkey,
}
}
type publicreportWaterImageUniques struct{}
type publicreportWaterImageOldUniques struct{}
func (u publicreportWaterImageUniques) AsSlice() []constraint {
func (u publicreportWaterImageOldUniques) AsSlice() []constraint {
return []constraint{}
}
type publicreportWaterImageChecks struct{}
type publicreportWaterImageOldChecks struct{}
func (c publicreportWaterImageChecks) AsSlice() []check {
func (c publicreportWaterImageOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,526 @@
// 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 PublicreportWaterOlds = Table[
publicreportWaterOldColumns,
publicreportWaterOldIndexes,
publicreportWaterOldForeignKeys,
publicreportWaterOldUniques,
publicreportWaterOldChecks,
]{
Schema: "publicreport",
Name: "water_old",
Columns: publicreportWaterOldColumns{
ID: column{
Name: "id",
DBType: "integer",
Default: "nextval('publicreport.pool_id_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessComments: column{
Name: "access_comments",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessGate: column{
Name: "access_gate",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessFence: column{
Name: "access_fence",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessLocked: column{
Name: "access_locked",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessDog: column{
Name: "access_dog",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AccessOther: column{
Name: "access_other",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressRaw: column{
Name: "address_raw",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressCountry: column{
Name: "address_country",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressPostalCode: column{
Name: "address_postal_code",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressLocality: column{
Name: "address_locality",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressStreet: column{
Name: "address_street",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressRegion: column{
Name: "address_region",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Comments: column{
Name: "comments",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Created: column{
Name: "created",
DBType: "timestamp without time zone",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
H3cell: column{
Name: "h3cell",
DBType: "h3index",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
HasAdult: column{
Name: "has_adult",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
HasLarvae: column{
Name: "has_larvae",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
HasPupae: column{
Name: "has_pupae",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
MapZoom: column{
Name: "map_zoom",
DBType: "real",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OwnerEmail: column{
Name: "owner_email",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OwnerName: column{
Name: "owner_name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OwnerPhone: column{
Name: "owner_phone",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
PublicID: column{
Name: "public_id",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterEmail: column{
Name: "reporter_email",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterName: column{
Name: "reporter_name",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterPhone: column{
Name: "reporter_phone",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
Status: column{
Name: "status",
DBType: "publicreport.reportstatustype",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
OrganizationID: column{
Name: "organization_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
HasBackyardPermission: column{
Name: "has_backyard_permission",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsReporterConfidential: column{
Name: "is_reporter_confidential",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
IsReporterOwner: column{
Name: "is_reporter_owner",
DBType: "boolean",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReporterContactConsent: column{
Name: "reporter_contact_consent",
DBType: "boolean",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Location: column{
Name: "location",
DBType: "geometry",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
AddressNumber: column{
Name: "address_number",
DBType: "text",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
AddressID: column{
Name: "address_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Reviewed: column{
Name: "reviewed",
DBType: "timestamp without time zone",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
ReviewerID: column{
Name: "reviewer_id",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: publicreportWaterOldIndexes{
PoolPkey: index{
Type: "btree",
Name: "pool_pkey",
Columns: []indexColumn{
{
Name: "id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
PoolPublicIDKey: index{
Type: "btree",
Name: "pool_public_id_key",
Columns: []indexColumn{
{
Name: "public_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "pool_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: publicreportWaterOldForeignKeys{
PublicreportWaterOldPoolAddressIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water_old.pool_address_id_fkey",
Columns: []string{"address_id"},
Comment: "",
},
ForeignTable: "address",
ForeignColumns: []string{"id"},
},
PublicreportWaterOldPoolOrganizationIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water_old.pool_organization_id_fkey",
Columns: []string{"organization_id"},
Comment: "",
},
ForeignTable: "organization",
ForeignColumns: []string{"id"},
},
PublicreportWaterOldWaterReviewerIDFkey: foreignKey{
constraint: constraint{
Name: "publicreport.water_old.water_reviewer_id_fkey",
Columns: []string{"reviewer_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
},
Uniques: publicreportWaterOldUniques{
PoolPublicIDKey: constraint{
Name: "pool_public_id_key",
Columns: []string{"public_id"},
Comment: "",
},
},
Comment: "",
}
type publicreportWaterOldColumns struct {
ID column
AccessComments column
AccessGate column
AccessFence column
AccessLocked column
AccessDog column
AccessOther column
AddressRaw column
AddressCountry column
AddressPostalCode column
AddressLocality column
AddressStreet column
AddressRegion column
Comments column
Created column
H3cell column
HasAdult column
HasLarvae column
HasPupae column
MapZoom column
OwnerEmail column
OwnerName column
OwnerPhone column
PublicID column
ReporterEmail column
ReporterName column
ReporterPhone column
Status column
OrganizationID column
HasBackyardPermission column
IsReporterConfidential column
IsReporterOwner column
ReporterContactConsent column
Location column
AddressNumber column
AddressID column
Reviewed column
ReviewerID column
}
func (c publicreportWaterOldColumns) AsSlice() []column {
return []column{
c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.AddressRaw, c.AddressCountry, c.AddressPostalCode, c.AddressLocality, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, 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, c.Location, c.AddressNumber, c.AddressID, c.Reviewed, c.ReviewerID,
}
}
type publicreportWaterOldIndexes struct {
PoolPkey index
PoolPublicIDKey index
}
func (i publicreportWaterOldIndexes) AsSlice() []index {
return []index{
i.PoolPkey, i.PoolPublicIDKey,
}
}
type publicreportWaterOldForeignKeys struct {
PublicreportWaterOldPoolAddressIDFkey foreignKey
PublicreportWaterOldPoolOrganizationIDFkey foreignKey
PublicreportWaterOldWaterReviewerIDFkey foreignKey
}
func (f publicreportWaterOldForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.PublicreportWaterOldPoolAddressIDFkey, f.PublicreportWaterOldPoolOrganizationIDFkey, f.PublicreportWaterOldWaterReviewerIDFkey,
}
}
type publicreportWaterOldUniques struct {
PoolPublicIDKey constraint
}
func (u publicreportWaterOldUniques) AsSlice() []constraint {
return []constraint{
u.PoolPublicIDKey,
}
}
type publicreportWaterOldChecks struct{}
func (c publicreportWaterOldChecks) AsSlice() []check {
return []check{}
}

View file

@ -0,0 +1,157 @@
// 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 ReportTexts = Table[
reportTextColumns,
reportTextIndexes,
reportTextForeignKeys,
reportTextUniques,
reportTextChecks,
]{
Schema: "",
Name: "report_text",
Columns: reportTextColumns{
CreatorID: column{
Name: "creator_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
ReportID: column{
Name: "report_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
TextLogID: column{
Name: "text_log_id",
DBType: "integer",
Default: "",
Comment: "",
Nullable: false,
Generated: false,
AutoIncr: false,
},
},
Indexes: reportTextIndexes{
ReportTextPkey: index{
Type: "btree",
Name: "report_text_pkey",
Columns: []indexColumn{
{
Name: "creator_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "report_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
{
Name: "text_log_id",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false, false, false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "report_text_pkey",
Columns: []string{"creator_id", "report_id", "text_log_id"},
Comment: "",
},
ForeignKeys: reportTextForeignKeys{
ReportTextReportTextCreatorIDFkey: foreignKey{
constraint: constraint{
Name: "report_text.report_text_creator_id_fkey",
Columns: []string{"creator_id"},
Comment: "",
},
ForeignTable: "user_",
ForeignColumns: []string{"id"},
},
ReportTextReportTextReportIDFkey: foreignKey{
constraint: constraint{
Name: "report_text.report_text_report_id_fkey",
Columns: []string{"report_id"},
Comment: "",
},
ForeignTable: "publicreport.report",
ForeignColumns: []string{"id"},
},
ReportTextReportTextTextLogIDFkey: foreignKey{
constraint: constraint{
Name: "report_text.report_text_text_log_id_fkey",
Columns: []string{"text_log_id"},
Comment: "",
},
ForeignTable: "comms.text_log",
ForeignColumns: []string{"id"},
},
},
Comment: "",
}
type reportTextColumns struct {
CreatorID column
ReportID column
TextLogID column
}
func (c reportTextColumns) AsSlice() []column {
return []column{
c.CreatorID, c.ReportID, c.TextLogID,
}
}
type reportTextIndexes struct {
ReportTextPkey index
}
func (i reportTextIndexes) AsSlice() []index {
return []index{
i.ReportTextPkey,
}
}
type reportTextForeignKeys struct {
ReportTextReportTextCreatorIDFkey foreignKey
ReportTextReportTextReportIDFkey foreignKey
ReportTextReportTextTextLogIDFkey foreignKey
}
func (f reportTextForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.ReportTextReportTextCreatorIDFkey, f.ReportTextReportTextReportIDFkey, f.ReportTextReportTextTextLogIDFkey,
}
}
type reportTextUniques struct{}
func (u reportTextUniques) AsSlice() []constraint {
return []constraint{}
}
type reportTextChecks struct{}
func (c reportTextChecks) AsSlice() []check {
return []check{}
}

View file

@ -691,11 +691,13 @@ func (e *CommsTextjobsource) Scan(value any) error {
// Enum values for CommsTextjobtype
const (
CommsTextjobtypeReportConfirmation CommsTextjobtype = "report-confirmation"
CommsTextjobtypeReportMessage CommsTextjobtype = "report-message"
)
func AllCommsTextjobtype() []CommsTextjobtype {
return []CommsTextjobtype{
CommsTextjobtypeReportConfirmation,
CommsTextjobtypeReportMessage,
}
}
@ -707,7 +709,8 @@ func (e CommsTextjobtype) String() string {
func (e CommsTextjobtype) Valid() bool {
switch e {
case CommsTextjobtypeReportConfirmation:
case CommsTextjobtypeReportConfirmation,
CommsTextjobtypeReportMessage:
return true
default:
return false
@ -1299,6 +1302,7 @@ const (
JobtypeCSVImport Jobtype = "csv-import"
JobtypeLabelStudioAudioCreate Jobtype = "label-studio-audio-create"
JobtypeEmailSend Jobtype = "email-send"
JobtypeTextRespond Jobtype = "text-respond"
JobtypeTextSend Jobtype = "text-send"
)
@ -1309,6 +1313,7 @@ func AllJobtype() []Jobtype {
JobtypeCSVImport,
JobtypeLabelStudioAudioCreate,
JobtypeEmailSend,
JobtypeTextRespond,
JobtypeTextSend,
}
}
@ -1326,6 +1331,7 @@ func (e Jobtype) Valid() bool {
JobtypeCSVImport,
JobtypeLabelStudioAudioCreate,
JobtypeEmailSend,
JobtypeTextRespond,
JobtypeTextSend:
return true
default:

View file

@ -5,9 +5,10 @@ CREATE TYPE JobType AS ENUM (
'csv-import',
'label-studio-audio-create',
'email-send',
'text-respond',
'text-send'
);
ALTER TYPE comms.TextJobType ADD VALUE 'report-message' AFTER 'report-confirmation';
CREATE TABLE job (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
id SERIAL NOT NULL,
@ -35,5 +36,6 @@ CREATE TRIGGER job_insert_trigger
-- +goose Down
DROP TRIGGER job_insert_trigger ON job;
DROP TABLE job;
-- ALTER TYPE comms.TextJobType DROP VALUE 'report-message';
DROP TYPE JobType;

View file

@ -0,0 +1,358 @@
-- +goose Up
CREATE TABLE publicreport.report (
-- Address fields
address_raw TEXT NOT NULL,
address_number TEXT NOT NULL,
address_street TEXT NOT NULL,
address_locality TEXT NOT NULL,
address_region TEXT NOT NULL,
address_postal_code TEXT NOT NULL,
address_country TEXT NOT NULL,
address_id INTEGER REFERENCES address(id),
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
-- Location fields
location GEOMETRY(Point, 4326),
h3cell h3index,
id SERIAL,
latlng_accuracy_type publicreport.accuracytype NOT NULL,
latlng_accuracy_value REAL NOT NULL,
map_zoom REAL NOT NULL,
-- Organization
organization_id INTEGER NOT NULL REFERENCES organization(id),
public_id TEXT NOT NULL UNIQUE,
-- Reporter information
reporter_name TEXT NOT NULL,
reporter_email TEXT NOT NULL,
reporter_phone TEXT NOT NULL,
reporter_contact_consent BOOLEAN,
-- Report type discriminator
report_type TEXT NOT NULL CHECK (report_type IN ('nuisance', 'water')),
-- Review fields
reviewed TIMESTAMP WITHOUT TIME ZONE,
reviewer_id INTEGER REFERENCES user_(id),
status publicreport.reportstatustype NOT NULL,
PRIMARY KEY(id)
);
-- Insert nuisance reports into the report table
INSERT INTO publicreport.report (
id,
public_id,
created,
status,
reporter_name,
reporter_email,
reporter_phone,
reporter_contact_consent,
address_raw,
address_number,
address_street,
address_locality,
address_region,
address_postal_code,
address_country,
address_id,
location,
h3cell,
map_zoom,
latlng_accuracy_type,
latlng_accuracy_value,
reviewed,
reviewer_id,
organization_id,
report_type
)
SELECT
id,
public_id,
created,
status,
COALESCE(reporter_name, ''),
COALESCE(reporter_email, ''),
COALESCE(reporter_phone, ''),
reporter_contact_consent,
address_raw,
address_number,
address_street,
address_locality,
address_region,
address_postal_code,
address_country,
address_id,
location,
h3cell,
map_zoom,
latlng_accuracy_type,
latlng_accuracy_value,
reviewed,
reviewer_id,
organization_id,
'nuisance' as report_type
FROM publicreport.nuisance;
-- Insert water reports into the report table
INSERT INTO publicreport.report (
id,
public_id,
created,
status,
COALESCE(reporter_name, ''),
COALESCE(reporter_email, ''),
COALESCE(reporter_phone, ''),
reporter_contact_consent,
address_raw,
address_number,
address_street,
address_locality,
address_region,
address_postal_code,
address_country,
address_id,
location,
h3cell,
map_zoom,
latlng_accuracy_type,
latlng_accuracy_value,
reviewed,
reviewer_id,
organization_id,
report_type
)
SELECT
id,
public_id,
created,
status,
reporter_name,
reporter_email,
reporter_phone,
reporter_contact_consent,
address_raw,
address_number,
address_street,
address_locality,
address_region,
address_postal_code,
address_country,
address_id,
location,
h3cell,
map_zoom,
-- Water table doesn't have these fields, so use defaults
'none'::publicreport.accuracytype as latlng_accuracy_type,
0.0 as latlng_accuracy_value,
reviewed,
reviewer_id,
organization_id,
'water' as report_type
FROM publicreport.water;
-- Rename existing tables
ALTER TABLE publicreport.nuisance RENAME TO nuisance_old;
ALTER TABLE publicreport.water RENAME TO water_old;
-- Create new nuisance table with only specific fields
CREATE TABLE publicreport.nuisance (
additional_info TEXT NOT NULL,
duration publicreport.nuisancedurationtype NOT NULL,
is_location_backyard BOOLEAN NOT NULL,
is_location_frontyard BOOLEAN NOT NULL,
is_location_garden BOOLEAN NOT NULL,
is_location_other BOOLEAN NOT NULL,
is_location_pool BOOLEAN NOT NULL,
report_id INTEGER REFERENCES publicreport.report(id),
source_container BOOLEAN NOT NULL,
source_description TEXT NOT NULL,
source_stagnant BOOLEAN NOT NULL,
source_gutter BOOLEAN NOT NULL,
tod_early BOOLEAN NOT NULL,
tod_day BOOLEAN NOT NULL,
tod_evening BOOLEAN NOT NULL,
tod_night BOOLEAN NOT NULL,
PRIMARY KEY(report_id)
);
-- Create new water table with only specific fields
CREATE TABLE publicreport.water (
access_comments TEXT NOT NULL,
access_gate BOOLEAN NOT NULL,
access_fence BOOLEAN NOT NULL,
access_locked BOOLEAN NOT NULL,
access_dog BOOLEAN NOT NULL,
access_other BOOLEAN NOT NULL,
comments TEXT NOT NULL,
is_reporter_confidential BOOLEAN NOT NULL,
is_reporter_owner BOOLEAN NOT NULL,
has_adult BOOLEAN NOT NULL,
has_backyard_permission BOOLEAN NOT NULL,
has_larvae BOOLEAN NOT NULL,
has_pupae BOOLEAN NOT NULL,
owner_email TEXT NOT NULL,
owner_name TEXT NOT NULL,
owner_phone TEXT NOT NULL,
report_id INTEGER REFERENCES publicreport.report(id),
PRIMARY KEY(report_id)
);
-- Migrate nuisance-specific data
INSERT INTO publicreport.nuisance (
report_id,
additional_info,
duration,
source_container,
source_description,
source_stagnant,
source_gutter,
is_location_backyard,
is_location_frontyard,
is_location_garden,
is_location_other,
is_location_pool,
tod_early,
tod_day,
tod_evening,
tod_night
)
SELECT
id,
additional_info,
duration,
source_container,
source_description,
source_stagnant,
source_gutter,
is_location_backyard,
is_location_frontyard,
is_location_garden,
is_location_other,
is_location_pool,
tod_early,
tod_day,
tod_evening,
tod_night
FROM publicreport.nuisance_old;
-- Migrate water-specific data
INSERT INTO publicreport.water (
report_id,
access_comments,
access_gate,
access_fence,
access_locked,
access_dog,
access_other,
comments,
has_adult,
has_larvae,
has_pupae,
owner_email,
owner_name,
owner_phone,
has_backyard_permission,
is_reporter_confidential,
is_reporter_owner
)
SELECT
id,
access_comments,
access_gate,
access_fence,
access_locked,
access_dog,
access_other,
comments,
has_adult,
has_larvae,
has_pupae,
owner_email,
owner_name,
owner_phone,
has_backyard_permission,
is_reporter_confidential,
is_reporter_owner
FROM publicreport.water_old;
-- Create new unified report_image junction table
CREATE TABLE publicreport.report_image (
image_id INTEGER NOT NULL REFERENCES publicreport.image(id),
report_id INTEGER NOT NULL REFERENCES publicreport.report(id),
PRIMARY KEY (image_id, report_id)
);
-- Update nuisance_image table
ALTER TABLE publicreport.nuisance_image RENAME TO nuisance_image_old;
INSERT INTO publicreport.report_image (image_id, report_id)
SELECT ni.image_id, r.id as report_id
FROM publicreport.nuisance_image_old ni
JOIN publicreport.nuisance_old n ON n.id = ni.nuisance_id
JOIN publicreport.report r ON r.public_id = n.public_id AND r.report_type = 'nuisance';
-- Update water_image table
ALTER TABLE publicreport.water_image RENAME TO water_image_old;
INSERT INTO publicreport.report_image (image_id, report_id)
SELECT wi.image_id, r.id as report_id
FROM publicreport.water_image_old wi
JOIN publicreport.water_old w ON w.id = wi.water_id
JOIN publicreport.report r ON r.public_id = w.public_id AND r.report_type = 'water';
-- Create new unified notify_report_email
CREATE TABLE publicreport.notify_email (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
deleted TIMESTAMP WITHOUT TIME ZONE,
email_address TEXT NOT NULL REFERENCES comms.email_contact(address),
report_id INTEGER NOT NULL REFERENCES publicreport.report(id),
PRIMARY KEY (report_id, email_address)
);
-- Update notify_email_nuisance table
ALTER TABLE publicreport.notify_email_nuisance RENAME TO notify_email_nuisance_old;
INSERT INTO publicreport.notify_email (created, deleted, report_id, email_address)
SELECT nen.created, nen.deleted, r.id as report_id, nen.email_address
FROM publicreport.notify_email_nuisance_old nen
JOIN publicreport.nuisance_old n ON n.id = nen.nuisance_id
JOIN publicreport.report r ON r.public_id = n.public_id AND r.report_type = 'nuisance';
-- Update notify_email_water table
ALTER TABLE publicreport.notify_email_water RENAME TO notify_email_water_old;
INSERT INTO publicreport.notify_email (created, deleted, report_id, email_address)
SELECT new.created, new.deleted, r.id as report_id, new.email_address
FROM publicreport.notify_email_water_old new
JOIN publicreport.water_old w ON w.id = new.water_id
JOIN publicreport.report r ON r.public_id = w.public_id AND r.report_type = 'water';
-- Update notify_phone_nuisance table
ALTER TABLE publicreport.notify_phone_nuisance RENAME TO notify_phone_nuisance_old;
CREATE TABLE publicreport.notify_phone (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
deleted TIMESTAMP WITHOUT TIME ZONE,
phone_e164 TEXT NOT NULL REFERENCES comms.phone(e164),
report_id INTEGER NOT NULL REFERENCES publicreport.report(id),
PRIMARY KEY (report_id, phone_e164)
);
INSERT INTO publicreport.notify_phone (created, deleted, report_id, phone_e164)
SELECT npn.created, npn.deleted, r.id as report_id, npn.phone_e164
FROM publicreport.notify_phone_nuisance_old npn
JOIN publicreport.nuisance_old n ON n.id = npn.nuisance_id
JOIN publicreport.report r ON r.public_id = n.public_id AND r.report_type = 'nuisance';
-- Update notify_phone_water table
ALTER TABLE publicreport.notify_phone_water RENAME TO notify_phone_water_old;
INSERT INTO publicreport.notify_phone (created, deleted, report_id, phone_e164)
SELECT npw.created, npw.deleted, r.id as report_id, npw.phone_e164
FROM publicreport.notify_phone_water_old npw
JOIN publicreport.water_old w ON w.id = npw.water_id
JOIN publicreport.report r ON r.public_id = w.public_id AND r.report_type = 'water';

View file

@ -0,0 +1,15 @@
-- +goose Up
ALTER TABLE comms.text_job ADD COLUMN creator_id INTEGER REFERENCES user_(id);
ALTER TABLE comms.text_job ADD COLUMN report_id INTEGER REFERENCES publicreport.report(id);
CREATE TABLE report_text (
creator_id INTEGER NOT NULL REFERENCES user_(id),
report_id INTEGER NOT NULL REFERENCES publicreport.report(id),
text_log_id INTEGER NOT NULL REFERENCES comms.text_log(id),
PRIMARY KEY(creator_id, report_id, text_log_id)
);
-- +goose Down
DROP TABLE report_text;
ALTER TABLE comms.text_job DROP COLUMN report_id;
ALTER TABLE comms.text_job DROP COLUMN creator_id;

View file

@ -52,11 +52,12 @@ type AddressesQuery = *psql.ViewQuery[*Address, AddressSlice]
// addressR is where relationships are stored.
type addressR struct {
Mailers CommsMailerSlice // comms.mailer.mailer_address_id_fkey
Nuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_address_id_fkey
Waters PublicreportWaterSlice // publicreport.water.pool_address_id_fkey
Residents ResidentSlice // resident.resident_address_id_fkey
Site *Site // site.site_address_id_fkey
Mailers CommsMailerSlice // comms.mailer.mailer_address_id_fkey
NuisanceOlds PublicreportNuisanceOldSlice // publicreport.nuisance_old.nuisance_address_id_fkey
Reports PublicreportReportSlice // publicreport.report.report_address_id_fkey
WaterOlds PublicreportWaterOldSlice // publicreport.water_old.pool_address_id_fkey
Residents ResidentSlice // resident.resident_address_id_fkey
Site *Site // site.site_address_id_fkey
}
func buildAddressColumns(alias string) addressColumns {
@ -605,14 +606,14 @@ func (os AddressSlice) Mailers(mods ...bob.Mod[*dialect.SelectQuery]) CommsMaile
)...)
}
// Nuisances starts a query for related objects on publicreport.nuisance
func (o *Address) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
return PublicreportNuisances.Query(append(mods,
sm.Where(PublicreportNuisances.Columns.AddressID.EQ(psql.Arg(o.ID))),
// NuisanceOlds starts a query for related objects on publicreport.nuisance_old
func (o *Address) NuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNuisanceOlds.Columns.AddressID.EQ(psql.Arg(o.ID))),
)...)
}
func (os AddressSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
func (os AddressSlice) NuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
@ -624,19 +625,19 @@ func (os AddressSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) Publicre
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisances.Columns.AddressID).OP("IN", PKArgExpr)),
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisanceOlds.Columns.AddressID).OP("IN", PKArgExpr)),
)...)
}
// Waters starts a query for related objects on publicreport.water
func (o *Address) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
return PublicreportWaters.Query(append(mods,
sm.Where(PublicreportWaters.Columns.AddressID.EQ(psql.Arg(o.ID))),
// Reports starts a query for related objects on publicreport.report
func (o *Address) Reports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.AddressID.EQ(psql.Arg(o.ID))),
)...)
}
func (os AddressSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
func (os AddressSlice) Reports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
@ -648,8 +649,32 @@ func (os AddressSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) Publicrepor
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportWaters.Columns.AddressID).OP("IN", PKArgExpr)),
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.AddressID).OP("IN", PKArgExpr)),
)...)
}
// WaterOlds starts a query for related objects on publicreport.water_old
func (o *Address) WaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
return PublicreportWaterOlds.Query(append(mods,
sm.Where(PublicreportWaterOlds.Columns.AddressID.EQ(psql.Arg(o.ID))),
)...)
}
func (os AddressSlice) WaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
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 PublicreportWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportWaterOlds.Columns.AddressID).OP("IN", PKArgExpr)),
)...)
}
@ -769,66 +794,66 @@ func (address0 *Address) AttachMailers(ctx context.Context, exec bob.Executor, r
return nil
}
func insertAddressNuisances0(ctx context.Context, exec bob.Executor, publicreportNuisances1 []*PublicreportNuisanceSetter, address0 *Address) (PublicreportNuisanceSlice, error) {
for i := range publicreportNuisances1 {
publicreportNuisances1[i].AddressID = omitnull.From(address0.ID)
func insertAddressNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNuisanceOlds1 []*PublicreportNuisanceOldSetter, address0 *Address) (PublicreportNuisanceOldSlice, error) {
for i := range publicreportNuisanceOlds1 {
publicreportNuisanceOlds1[i].AddressID = omitnull.From(address0.ID)
}
ret, err := PublicreportNuisances.Insert(bob.ToMods(publicreportNuisances1...)).All(ctx, exec)
ret, err := PublicreportNuisanceOlds.Insert(bob.ToMods(publicreportNuisanceOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertAddressNuisances0: %w", err)
return ret, fmt.Errorf("insertAddressNuisanceOlds0: %w", err)
}
return ret, nil
}
func attachAddressNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNuisances1 PublicreportNuisanceSlice, address0 *Address) (PublicreportNuisanceSlice, error) {
setter := &PublicreportNuisanceSetter{
func attachAddressNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOlds1 PublicreportNuisanceOldSlice, address0 *Address) (PublicreportNuisanceOldSlice, error) {
setter := &PublicreportNuisanceOldSetter{
AddressID: omitnull.From(address0.ID),
}
err := publicreportNuisances1.UpdateAll(ctx, exec, *setter)
err := publicreportNuisanceOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachAddressNuisances0: %w", err)
return nil, fmt.Errorf("attachAddressNuisanceOlds0: %w", err)
}
return publicreportNuisances1, nil
return publicreportNuisanceOlds1, nil
}
func (address0 *Address) InsertNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error {
func (address0 *Address) InsertNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNuisances1, err := insertAddressNuisances0(ctx, exec, related, address0)
publicreportNuisanceOlds1, err := insertAddressNuisanceOlds0(ctx, exec, related, address0)
if err != nil {
return err
}
address0.R.Nuisances = append(address0.R.Nuisances, publicreportNuisances1...)
address0.R.NuisanceOlds = append(address0.R.NuisanceOlds, publicreportNuisanceOlds1...)
for _, rel := range publicreportNuisances1 {
for _, rel := range publicreportNuisanceOlds1 {
rel.R.Address = address0
}
return nil
}
func (address0 *Address) AttachNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error {
func (address0 *Address) AttachNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNuisances1 := PublicreportNuisanceSlice(related)
publicreportNuisanceOlds1 := PublicreportNuisanceOldSlice(related)
_, err = attachAddressNuisances0(ctx, exec, len(related), publicreportNuisances1, address0)
_, err = attachAddressNuisanceOlds0(ctx, exec, len(related), publicreportNuisanceOlds1, address0)
if err != nil {
return err
}
address0.R.Nuisances = append(address0.R.Nuisances, publicreportNuisances1...)
address0.R.NuisanceOlds = append(address0.R.NuisanceOlds, publicreportNuisanceOlds1...)
for _, rel := range related {
rel.R.Address = address0
@ -837,66 +862,134 @@ func (address0 *Address) AttachNuisances(ctx context.Context, exec bob.Executor,
return nil
}
func insertAddressWaters0(ctx context.Context, exec bob.Executor, publicreportWaters1 []*PublicreportWaterSetter, address0 *Address) (PublicreportWaterSlice, error) {
for i := range publicreportWaters1 {
publicreportWaters1[i].AddressID = omitnull.From(address0.ID)
func insertAddressReports0(ctx context.Context, exec bob.Executor, publicreportReports1 []*PublicreportReportSetter, address0 *Address) (PublicreportReportSlice, error) {
for i := range publicreportReports1 {
publicreportReports1[i].AddressID = omitnull.From(address0.ID)
}
ret, err := PublicreportWaters.Insert(bob.ToMods(publicreportWaters1...)).All(ctx, exec)
ret, err := PublicreportReports.Insert(bob.ToMods(publicreportReports1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertAddressWaters0: %w", err)
return ret, fmt.Errorf("insertAddressReports0: %w", err)
}
return ret, nil
}
func attachAddressWaters0(ctx context.Context, exec bob.Executor, count int, publicreportWaters1 PublicreportWaterSlice, address0 *Address) (PublicreportWaterSlice, error) {
setter := &PublicreportWaterSetter{
func attachAddressReports0(ctx context.Context, exec bob.Executor, count int, publicreportReports1 PublicreportReportSlice, address0 *Address) (PublicreportReportSlice, error) {
setter := &PublicreportReportSetter{
AddressID: omitnull.From(address0.ID),
}
err := publicreportWaters1.UpdateAll(ctx, exec, *setter)
err := publicreportReports1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachAddressWaters0: %w", err)
return nil, fmt.Errorf("attachAddressReports0: %w", err)
}
return publicreportWaters1, nil
return publicreportReports1, nil
}
func (address0 *Address) InsertWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error {
func (address0 *Address) InsertReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReportSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaters1, err := insertAddressWaters0(ctx, exec, related, address0)
publicreportReports1, err := insertAddressReports0(ctx, exec, related, address0)
if err != nil {
return err
}
address0.R.Waters = append(address0.R.Waters, publicreportWaters1...)
address0.R.Reports = append(address0.R.Reports, publicreportReports1...)
for _, rel := range publicreportWaters1 {
for _, rel := range publicreportReports1 {
rel.R.Address = address0
}
return nil
}
func (address0 *Address) AttachWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error {
func (address0 *Address) AttachReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReport) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaters1 := PublicreportWaterSlice(related)
publicreportReports1 := PublicreportReportSlice(related)
_, err = attachAddressWaters0(ctx, exec, len(related), publicreportWaters1, address0)
_, err = attachAddressReports0(ctx, exec, len(related), publicreportReports1, address0)
if err != nil {
return err
}
address0.R.Waters = append(address0.R.Waters, publicreportWaters1...)
address0.R.Reports = append(address0.R.Reports, publicreportReports1...)
for _, rel := range related {
rel.R.Address = address0
}
return nil
}
func insertAddressWaterOlds0(ctx context.Context, exec bob.Executor, publicreportWaterOlds1 []*PublicreportWaterOldSetter, address0 *Address) (PublicreportWaterOldSlice, error) {
for i := range publicreportWaterOlds1 {
publicreportWaterOlds1[i].AddressID = omitnull.From(address0.ID)
}
ret, err := PublicreportWaterOlds.Insert(bob.ToMods(publicreportWaterOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertAddressWaterOlds0: %w", err)
}
return ret, nil
}
func attachAddressWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOlds1 PublicreportWaterOldSlice, address0 *Address) (PublicreportWaterOldSlice, error) {
setter := &PublicreportWaterOldSetter{
AddressID: omitnull.From(address0.ID),
}
err := publicreportWaterOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachAddressWaterOlds0: %w", err)
}
return publicreportWaterOlds1, nil
}
func (address0 *Address) InsertWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaterOlds1, err := insertAddressWaterOlds0(ctx, exec, related, address0)
if err != nil {
return err
}
address0.R.WaterOlds = append(address0.R.WaterOlds, publicreportWaterOlds1...)
for _, rel := range publicreportWaterOlds1 {
rel.R.Address = address0
}
return nil
}
func (address0 *Address) AttachWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaterOlds1 := PublicreportWaterOldSlice(related)
_, err = attachAddressWaterOlds0(ctx, exec, len(related), publicreportWaterOlds1, address0)
if err != nil {
return err
}
address0.R.WaterOlds = append(address0.R.WaterOlds, publicreportWaterOlds1...)
for _, rel := range related {
rel.R.Address = address0
@ -1081,13 +1174,13 @@ func (o *Address) Preload(name string, retrieved any) error {
}
}
return nil
case "Nuisances":
rels, ok := retrieved.(PublicreportNuisanceSlice)
case "NuisanceOlds":
rels, ok := retrieved.(PublicreportNuisanceOldSlice)
if !ok {
return fmt.Errorf("address cannot load %T as %q", retrieved, name)
}
o.R.Nuisances = rels
o.R.NuisanceOlds = rels
for _, rel := range rels {
if rel != nil {
@ -1095,13 +1188,27 @@ func (o *Address) Preload(name string, retrieved any) error {
}
}
return nil
case "Waters":
rels, ok := retrieved.(PublicreportWaterSlice)
case "Reports":
rels, ok := retrieved.(PublicreportReportSlice)
if !ok {
return fmt.Errorf("address cannot load %T as %q", retrieved, name)
}
o.R.Waters = rels
o.R.Reports = rels
for _, rel := range rels {
if rel != nil {
rel.R.Address = o
}
}
return nil
case "WaterOlds":
rels, ok := retrieved.(PublicreportWaterOldSlice)
if !ok {
return fmt.Errorf("address cannot load %T as %q", retrieved, name)
}
o.R.WaterOlds = rels
for _, rel := range rels {
if rel != nil {
@ -1163,22 +1270,26 @@ func buildAddressPreloader() addressPreloader {
}
type addressThenLoader[Q orm.Loadable] struct {
Mailers func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Waters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Residents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Mailers func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Reports func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
WaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Residents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
type MailersLoadInterface interface {
LoadMailers(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisancesLoadInterface interface {
LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type NuisanceOldsLoadInterface interface {
LoadNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WatersLoadInterface interface {
LoadWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type ReportsLoadInterface interface {
LoadReports(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterOldsLoadInterface interface {
LoadWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ResidentsLoadInterface interface {
LoadResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
@ -1194,16 +1305,22 @@ func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
return retrieved.LoadMailers(ctx, exec, mods...)
},
),
Nuisances: thenLoadBuilder[Q](
"Nuisances",
func(ctx context.Context, exec bob.Executor, retrieved NuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisances(ctx, exec, mods...)
NuisanceOlds: thenLoadBuilder[Q](
"NuisanceOlds",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisanceOlds(ctx, exec, mods...)
},
),
Waters: thenLoadBuilder[Q](
"Waters",
func(ctx context.Context, exec bob.Executor, retrieved WatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaters(ctx, exec, mods...)
Reports: thenLoadBuilder[Q](
"Reports",
func(ctx context.Context, exec bob.Executor, retrieved ReportsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReports(ctx, exec, mods...)
},
),
WaterOlds: thenLoadBuilder[Q](
"WaterOlds",
func(ctx context.Context, exec bob.Executor, retrieved WaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaterOlds(ctx, exec, mods...)
},
),
Residents: thenLoadBuilder[Q](
@ -1282,16 +1399,16 @@ func (os AddressSlice) LoadMailers(ctx context.Context, exec bob.Executor, mods
return nil
}
// LoadNuisances loads the address's Nuisances into the .R struct
func (o *Address) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadNuisanceOlds loads the address's NuisanceOlds into the .R struct
func (o *Address) LoadNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Nuisances = nil
o.R.NuisanceOlds = nil
related, err := o.Nuisances(mods...).All(ctx, exec)
related, err := o.NuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1300,17 +1417,17 @@ func (o *Address) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...
rel.R.Address = o
}
o.R.Nuisances = related
o.R.NuisanceOlds = related
return nil
}
// LoadNuisances loads the address's Nuisances into the .R struct
func (os AddressSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadNuisanceOlds loads the address's NuisanceOlds into the .R struct
func (os AddressSlice) LoadNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisances, err := os.Nuisances(mods...).All(ctx, exec)
publicreportNuisanceOlds, err := os.NuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1320,7 +1437,7 @@ func (os AddressSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mod
continue
}
o.R.Nuisances = nil
o.R.NuisanceOlds = nil
}
for _, o := range os {
@ -1328,7 +1445,7 @@ func (os AddressSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mod
continue
}
for _, rel := range publicreportNuisances {
for _, rel := range publicreportNuisanceOlds {
if !rel.AddressID.IsValue() {
continue
@ -1339,23 +1456,23 @@ func (os AddressSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mod
rel.R.Address = o
o.R.Nuisances = append(o.R.Nuisances, rel)
o.R.NuisanceOlds = append(o.R.NuisanceOlds, rel)
}
}
return nil
}
// LoadWaters loads the address's Waters into the .R struct
func (o *Address) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadReports loads the address's Reports into the .R struct
func (o *Address) LoadReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Waters = nil
o.R.Reports = nil
related, err := o.Waters(mods...).All(ctx, exec)
related, err := o.Reports(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1364,17 +1481,17 @@ func (o *Address) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob
rel.R.Address = o
}
o.R.Waters = related
o.R.Reports = related
return nil
}
// LoadWaters loads the address's Waters into the .R struct
func (os AddressSlice) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadReports loads the address's Reports into the .R struct
func (os AddressSlice) LoadReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaters, err := os.Waters(mods...).All(ctx, exec)
publicreportReports, err := os.Reports(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1384,7 +1501,7 @@ func (os AddressSlice) LoadWaters(ctx context.Context, exec bob.Executor, mods .
continue
}
o.R.Waters = nil
o.R.Reports = nil
}
for _, o := range os {
@ -1392,7 +1509,7 @@ func (os AddressSlice) LoadWaters(ctx context.Context, exec bob.Executor, mods .
continue
}
for _, rel := range publicreportWaters {
for _, rel := range publicreportReports {
if !rel.AddressID.IsValue() {
continue
@ -1403,7 +1520,71 @@ func (os AddressSlice) LoadWaters(ctx context.Context, exec bob.Executor, mods .
rel.R.Address = o
o.R.Waters = append(o.R.Waters, rel)
o.R.Reports = append(o.R.Reports, rel)
}
}
return nil
}
// LoadWaterOlds loads the address's WaterOlds into the .R struct
func (o *Address) LoadWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.WaterOlds = nil
related, err := o.WaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Address = o
}
o.R.WaterOlds = related
return nil
}
// LoadWaterOlds loads the address's WaterOlds into the .R struct
func (os AddressSlice) LoadWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaterOlds, err := os.WaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.WaterOlds = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaterOlds {
if !rel.AddressID.IsValue() {
continue
}
if !(rel.AddressID.IsValue() && o.ID == rel.AddressID.MustGet()) {
continue
}
rel.R.Address = o
o.R.WaterOlds = append(o.R.WaterOlds, rel)
}
}

View file

@ -17,184 +17,198 @@ import (
var Preload = getPreloaders()
type preloaders struct {
Address addressPreloader
ArcgisAccount arcgisAccountPreloader
ArcgisAddressMapping arcgisAddressMappingPreloader
ArcgisLayer arcgisLayerPreloader
ArcgisLayerField arcgisLayerFieldPreloader
ArcgisOauthToken arcgisOauthTokenPreloader
ArcgisParcelMapping arcgisParcelMappingPreloader
ArcgisServiceFeature arcgisServiceFeaturePreloader
ArcgisServiceMap arcgisServiceMapPreloader
ArcgisUser arcgisuserPreloader
ArcgisUserPrivilege arcgisUserPrivilegePreloader
CommsEmailContact commsEmailContactPreloader
CommsEmailLog commsEmailLogPreloader
CommsEmailTemplate commsEmailTemplatePreloader
CommsMailer commsMailerPreloader
CommsPhone commsPhonePreloader
CommsTextJob commsTextJobPreloader
CommsTextLog commsTextLogPreloader
ComplianceReportRequest complianceReportRequestPreloader
ComplianceReportRequestMailer complianceReportRequestMailerPreloader
DistrictSubscriptionEmail districtSubscriptionEmailPreloader
DistrictSubscriptionPhone districtSubscriptionPhonePreloader
Feature featurePreloader
FeaturePool featurePoolPreloader
FieldseekerContainerrelate fieldseekerContainerrelatePreloader
FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogPreloader
FieldseekerHabitatrelate fieldseekerHabitatrelatePreloader
FieldseekerInspectionsample fieldseekerInspectionsamplePreloader
FieldseekerInspectionsampledetail fieldseekerInspectionsampledetailPreloader
FieldseekerLinelocation fieldseekerLinelocationPreloader
FieldseekerLocationtracking fieldseekerLocationtrackingPreloader
FieldseekerMosquitoinspection fieldseekerMosquitoinspectionPreloader
FieldseekerPointlocation fieldseekerPointlocationPreloader
FieldseekerPolygonlocation fieldseekerPolygonlocationPreloader
FieldseekerPool fieldseekerPoolPreloader
FieldseekerPooldetail fieldseekerPooldetailPreloader
FieldseekerProposedtreatmentarea fieldseekerProposedtreatmentareaPreloader
FieldseekerQamosquitoinspection fieldseekerQamosquitoinspectionPreloader
FieldseekerRodentlocation fieldseekerRodentlocationPreloader
FieldseekerSamplecollection fieldseekerSamplecollectionPreloader
FieldseekerSamplelocation fieldseekerSamplelocationPreloader
FieldseekerServicerequest fieldseekerServicerequestPreloader
FieldseekerSpeciesabundance fieldseekerSpeciesabundancePreloader
FieldseekerStormdrain fieldseekerStormdrainPreloader
FieldseekerTimecard fieldseekerTimecardPreloader
FieldseekerTrapdatum fieldseekerTrapdatumPreloader
FieldseekerTraplocation fieldseekerTraplocationPreloader
FieldseekerTreatment fieldseekerTreatmentPreloader
FieldseekerTreatmentarea fieldseekerTreatmentareaPreloader
FieldseekerZone fieldseekerZonePreloader
FieldseekerZones2 fieldseekerZones2Preloader
FieldseekerSync fieldseekerSyncPreloader
FileuploadCSV fileuploadCSVPreloader
FileuploadErrorCSV fileuploadErrorCSVPreloader
FileuploadErrorFile fileuploadErrorFilePreloader
FileuploadFile fileuploadFilePreloader
FileuploadPool fileuploadPoolPreloader
H3Aggregation h3AggregationPreloader
Lead leadPreloader
NoteAudio noteAudioPreloader
NoteAudioBreadcrumb noteAudioBreadcrumbPreloader
NoteAudioDatum noteAudioDatumPreloader
NoteImage noteImagePreloader
NoteImageBreadcrumb noteImageBreadcrumbPreloader
NoteImageDatum noteImageDatumPreloader
Notification notificationPreloader
Organization organizationPreloader
Parcel parcelPreloader
PublicreportImage publicreportImagePreloader
PublicreportImageExif publicreportImageExifPreloader
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisancePreloader
PublicreportNotifyEmailWater publicreportNotifyEmailWaterPreloader
PublicreportNotifyPhoneNuisance publicreportNotifyPhoneNuisancePreloader
PublicreportNotifyPhoneWater publicreportNotifyPhoneWaterPreloader
PublicreportNuisance publicreportNuisancePreloader
PublicreportNuisanceImage publicreportNuisanceImagePreloader
PublicreportSubscribeEmail publicreportSubscribeEmailPreloader
PublicreportSubscribePhone publicreportSubscribePhonePreloader
PublicreportWater publicreportWaterPreloader
PublicreportWaterImage publicreportWaterImagePreloader
Resident residentPreloader
ReviewTask reviewTaskPreloader
ReviewTaskPool reviewTaskPoolPreloader
Signal signalPreloader
Site sitePreloader
TileCachedImage tileCachedImagePreloader
User userPreloader
Address addressPreloader
ArcgisAccount arcgisAccountPreloader
ArcgisAddressMapping arcgisAddressMappingPreloader
ArcgisLayer arcgisLayerPreloader
ArcgisLayerField arcgisLayerFieldPreloader
ArcgisOauthToken arcgisOauthTokenPreloader
ArcgisParcelMapping arcgisParcelMappingPreloader
ArcgisServiceFeature arcgisServiceFeaturePreloader
ArcgisServiceMap arcgisServiceMapPreloader
ArcgisUser arcgisuserPreloader
ArcgisUserPrivilege arcgisUserPrivilegePreloader
CommsEmailContact commsEmailContactPreloader
CommsEmailLog commsEmailLogPreloader
CommsEmailTemplate commsEmailTemplatePreloader
CommsMailer commsMailerPreloader
CommsPhone commsPhonePreloader
CommsTextJob commsTextJobPreloader
CommsTextLog commsTextLogPreloader
ComplianceReportRequest complianceReportRequestPreloader
ComplianceReportRequestMailer complianceReportRequestMailerPreloader
DistrictSubscriptionEmail districtSubscriptionEmailPreloader
DistrictSubscriptionPhone districtSubscriptionPhonePreloader
Feature featurePreloader
FeaturePool featurePoolPreloader
FieldseekerContainerrelate fieldseekerContainerrelatePreloader
FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogPreloader
FieldseekerHabitatrelate fieldseekerHabitatrelatePreloader
FieldseekerInspectionsample fieldseekerInspectionsamplePreloader
FieldseekerInspectionsampledetail fieldseekerInspectionsampledetailPreloader
FieldseekerLinelocation fieldseekerLinelocationPreloader
FieldseekerLocationtracking fieldseekerLocationtrackingPreloader
FieldseekerMosquitoinspection fieldseekerMosquitoinspectionPreloader
FieldseekerPointlocation fieldseekerPointlocationPreloader
FieldseekerPolygonlocation fieldseekerPolygonlocationPreloader
FieldseekerPool fieldseekerPoolPreloader
FieldseekerPooldetail fieldseekerPooldetailPreloader
FieldseekerProposedtreatmentarea fieldseekerProposedtreatmentareaPreloader
FieldseekerQamosquitoinspection fieldseekerQamosquitoinspectionPreloader
FieldseekerRodentlocation fieldseekerRodentlocationPreloader
FieldseekerSamplecollection fieldseekerSamplecollectionPreloader
FieldseekerSamplelocation fieldseekerSamplelocationPreloader
FieldseekerServicerequest fieldseekerServicerequestPreloader
FieldseekerSpeciesabundance fieldseekerSpeciesabundancePreloader
FieldseekerStormdrain fieldseekerStormdrainPreloader
FieldseekerTimecard fieldseekerTimecardPreloader
FieldseekerTrapdatum fieldseekerTrapdatumPreloader
FieldseekerTraplocation fieldseekerTraplocationPreloader
FieldseekerTreatment fieldseekerTreatmentPreloader
FieldseekerTreatmentarea fieldseekerTreatmentareaPreloader
FieldseekerZone fieldseekerZonePreloader
FieldseekerZones2 fieldseekerZones2Preloader
FieldseekerSync fieldseekerSyncPreloader
FileuploadCSV fileuploadCSVPreloader
FileuploadErrorCSV fileuploadErrorCSVPreloader
FileuploadErrorFile fileuploadErrorFilePreloader
FileuploadFile fileuploadFilePreloader
FileuploadPool fileuploadPoolPreloader
H3Aggregation h3AggregationPreloader
Lead leadPreloader
NoteAudio noteAudioPreloader
NoteAudioBreadcrumb noteAudioBreadcrumbPreloader
NoteAudioDatum noteAudioDatumPreloader
NoteImage noteImagePreloader
NoteImageBreadcrumb noteImageBreadcrumbPreloader
NoteImageDatum noteImageDatumPreloader
Notification notificationPreloader
Organization organizationPreloader
Parcel parcelPreloader
PublicreportImage publicreportImagePreloader
PublicreportImageExif publicreportImageExifPreloader
PublicreportNotifyEmail publicreportNotifyEmailPreloader
PublicreportNotifyEmailNuisanceOld publicreportNotifyEmailNuisanceOldPreloader
PublicreportNotifyEmailWaterOld publicreportNotifyEmailWaterOldPreloader
PublicreportNotifyPhone publicreportNotifyPhonePreloader
PublicreportNotifyPhoneNuisanceOld publicreportNotifyPhoneNuisanceOldPreloader
PublicreportNotifyPhoneWaterOld publicreportNotifyPhoneWaterOldPreloader
PublicreportNuisance publicreportNuisancePreloader
PublicreportNuisanceImageOld publicreportNuisanceImageOldPreloader
PublicreportNuisanceOld publicreportNuisanceOldPreloader
PublicreportReport publicreportReportPreloader
PublicreportReportImage publicreportReportImagePreloader
PublicreportSubscribeEmail publicreportSubscribeEmailPreloader
PublicreportSubscribePhone publicreportSubscribePhonePreloader
PublicreportWater publicreportWaterPreloader
PublicreportWaterImageOld publicreportWaterImageOldPreloader
PublicreportWaterOld publicreportWaterOldPreloader
ReportText reportTextPreloader
Resident residentPreloader
ReviewTask reviewTaskPreloader
ReviewTaskPool reviewTaskPoolPreloader
Signal signalPreloader
Site sitePreloader
TileCachedImage tileCachedImagePreloader
User userPreloader
}
func getPreloaders() preloaders {
return preloaders{
Address: buildAddressPreloader(),
ArcgisAccount: buildArcgisAccountPreloader(),
ArcgisAddressMapping: buildArcgisAddressMappingPreloader(),
ArcgisLayer: buildArcgisLayerPreloader(),
ArcgisLayerField: buildArcgisLayerFieldPreloader(),
ArcgisOauthToken: buildArcgisOauthTokenPreloader(),
ArcgisParcelMapping: buildArcgisParcelMappingPreloader(),
ArcgisServiceFeature: buildArcgisServiceFeaturePreloader(),
ArcgisServiceMap: buildArcgisServiceMapPreloader(),
ArcgisUser: buildArcgisUserPreloader(),
ArcgisUserPrivilege: buildArcgisUserPrivilegePreloader(),
CommsEmailContact: buildCommsEmailContactPreloader(),
CommsEmailLog: buildCommsEmailLogPreloader(),
CommsEmailTemplate: buildCommsEmailTemplatePreloader(),
CommsMailer: buildCommsMailerPreloader(),
CommsPhone: buildCommsPhonePreloader(),
CommsTextJob: buildCommsTextJobPreloader(),
CommsTextLog: buildCommsTextLogPreloader(),
ComplianceReportRequest: buildComplianceReportRequestPreloader(),
ComplianceReportRequestMailer: buildComplianceReportRequestMailerPreloader(),
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailPreloader(),
DistrictSubscriptionPhone: buildDistrictSubscriptionPhonePreloader(),
Feature: buildFeaturePreloader(),
FeaturePool: buildFeaturePoolPreloader(),
FieldseekerContainerrelate: buildFieldseekerContainerrelatePreloader(),
FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogPreloader(),
FieldseekerHabitatrelate: buildFieldseekerHabitatrelatePreloader(),
FieldseekerInspectionsample: buildFieldseekerInspectionsamplePreloader(),
FieldseekerInspectionsampledetail: buildFieldseekerInspectionsampledetailPreloader(),
FieldseekerLinelocation: buildFieldseekerLinelocationPreloader(),
FieldseekerLocationtracking: buildFieldseekerLocationtrackingPreloader(),
FieldseekerMosquitoinspection: buildFieldseekerMosquitoinspectionPreloader(),
FieldseekerPointlocation: buildFieldseekerPointlocationPreloader(),
FieldseekerPolygonlocation: buildFieldseekerPolygonlocationPreloader(),
FieldseekerPool: buildFieldseekerPoolPreloader(),
FieldseekerPooldetail: buildFieldseekerPooldetailPreloader(),
FieldseekerProposedtreatmentarea: buildFieldseekerProposedtreatmentareaPreloader(),
FieldseekerQamosquitoinspection: buildFieldseekerQamosquitoinspectionPreloader(),
FieldseekerRodentlocation: buildFieldseekerRodentlocationPreloader(),
FieldseekerSamplecollection: buildFieldseekerSamplecollectionPreloader(),
FieldseekerSamplelocation: buildFieldseekerSamplelocationPreloader(),
FieldseekerServicerequest: buildFieldseekerServicerequestPreloader(),
FieldseekerSpeciesabundance: buildFieldseekerSpeciesabundancePreloader(),
FieldseekerStormdrain: buildFieldseekerStormdrainPreloader(),
FieldseekerTimecard: buildFieldseekerTimecardPreloader(),
FieldseekerTrapdatum: buildFieldseekerTrapdatumPreloader(),
FieldseekerTraplocation: buildFieldseekerTraplocationPreloader(),
FieldseekerTreatment: buildFieldseekerTreatmentPreloader(),
FieldseekerTreatmentarea: buildFieldseekerTreatmentareaPreloader(),
FieldseekerZone: buildFieldseekerZonePreloader(),
FieldseekerZones2: buildFieldseekerZones2Preloader(),
FieldseekerSync: buildFieldseekerSyncPreloader(),
FileuploadCSV: buildFileuploadCSVPreloader(),
FileuploadErrorCSV: buildFileuploadErrorCSVPreloader(),
FileuploadErrorFile: buildFileuploadErrorFilePreloader(),
FileuploadFile: buildFileuploadFilePreloader(),
FileuploadPool: buildFileuploadPoolPreloader(),
H3Aggregation: buildH3AggregationPreloader(),
Lead: buildLeadPreloader(),
NoteAudio: buildNoteAudioPreloader(),
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbPreloader(),
NoteAudioDatum: buildNoteAudioDatumPreloader(),
NoteImage: buildNoteImagePreloader(),
NoteImageBreadcrumb: buildNoteImageBreadcrumbPreloader(),
NoteImageDatum: buildNoteImageDatumPreloader(),
Notification: buildNotificationPreloader(),
Organization: buildOrganizationPreloader(),
Parcel: buildParcelPreloader(),
PublicreportImage: buildPublicreportImagePreloader(),
PublicreportImageExif: buildPublicreportImageExifPreloader(),
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisancePreloader(),
PublicreportNotifyEmailWater: buildPublicreportNotifyEmailWaterPreloader(),
PublicreportNotifyPhoneNuisance: buildPublicreportNotifyPhoneNuisancePreloader(),
PublicreportNotifyPhoneWater: buildPublicreportNotifyPhoneWaterPreloader(),
PublicreportNuisance: buildPublicreportNuisancePreloader(),
PublicreportNuisanceImage: buildPublicreportNuisanceImagePreloader(),
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailPreloader(),
PublicreportSubscribePhone: buildPublicreportSubscribePhonePreloader(),
PublicreportWater: buildPublicreportWaterPreloader(),
PublicreportWaterImage: buildPublicreportWaterImagePreloader(),
Resident: buildResidentPreloader(),
ReviewTask: buildReviewTaskPreloader(),
ReviewTaskPool: buildReviewTaskPoolPreloader(),
Signal: buildSignalPreloader(),
Site: buildSitePreloader(),
TileCachedImage: buildTileCachedImagePreloader(),
User: buildUserPreloader(),
Address: buildAddressPreloader(),
ArcgisAccount: buildArcgisAccountPreloader(),
ArcgisAddressMapping: buildArcgisAddressMappingPreloader(),
ArcgisLayer: buildArcgisLayerPreloader(),
ArcgisLayerField: buildArcgisLayerFieldPreloader(),
ArcgisOauthToken: buildArcgisOauthTokenPreloader(),
ArcgisParcelMapping: buildArcgisParcelMappingPreloader(),
ArcgisServiceFeature: buildArcgisServiceFeaturePreloader(),
ArcgisServiceMap: buildArcgisServiceMapPreloader(),
ArcgisUser: buildArcgisUserPreloader(),
ArcgisUserPrivilege: buildArcgisUserPrivilegePreloader(),
CommsEmailContact: buildCommsEmailContactPreloader(),
CommsEmailLog: buildCommsEmailLogPreloader(),
CommsEmailTemplate: buildCommsEmailTemplatePreloader(),
CommsMailer: buildCommsMailerPreloader(),
CommsPhone: buildCommsPhonePreloader(),
CommsTextJob: buildCommsTextJobPreloader(),
CommsTextLog: buildCommsTextLogPreloader(),
ComplianceReportRequest: buildComplianceReportRequestPreloader(),
ComplianceReportRequestMailer: buildComplianceReportRequestMailerPreloader(),
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailPreloader(),
DistrictSubscriptionPhone: buildDistrictSubscriptionPhonePreloader(),
Feature: buildFeaturePreloader(),
FeaturePool: buildFeaturePoolPreloader(),
FieldseekerContainerrelate: buildFieldseekerContainerrelatePreloader(),
FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogPreloader(),
FieldseekerHabitatrelate: buildFieldseekerHabitatrelatePreloader(),
FieldseekerInspectionsample: buildFieldseekerInspectionsamplePreloader(),
FieldseekerInspectionsampledetail: buildFieldseekerInspectionsampledetailPreloader(),
FieldseekerLinelocation: buildFieldseekerLinelocationPreloader(),
FieldseekerLocationtracking: buildFieldseekerLocationtrackingPreloader(),
FieldseekerMosquitoinspection: buildFieldseekerMosquitoinspectionPreloader(),
FieldseekerPointlocation: buildFieldseekerPointlocationPreloader(),
FieldseekerPolygonlocation: buildFieldseekerPolygonlocationPreloader(),
FieldseekerPool: buildFieldseekerPoolPreloader(),
FieldseekerPooldetail: buildFieldseekerPooldetailPreloader(),
FieldseekerProposedtreatmentarea: buildFieldseekerProposedtreatmentareaPreloader(),
FieldseekerQamosquitoinspection: buildFieldseekerQamosquitoinspectionPreloader(),
FieldseekerRodentlocation: buildFieldseekerRodentlocationPreloader(),
FieldseekerSamplecollection: buildFieldseekerSamplecollectionPreloader(),
FieldseekerSamplelocation: buildFieldseekerSamplelocationPreloader(),
FieldseekerServicerequest: buildFieldseekerServicerequestPreloader(),
FieldseekerSpeciesabundance: buildFieldseekerSpeciesabundancePreloader(),
FieldseekerStormdrain: buildFieldseekerStormdrainPreloader(),
FieldseekerTimecard: buildFieldseekerTimecardPreloader(),
FieldseekerTrapdatum: buildFieldseekerTrapdatumPreloader(),
FieldseekerTraplocation: buildFieldseekerTraplocationPreloader(),
FieldseekerTreatment: buildFieldseekerTreatmentPreloader(),
FieldseekerTreatmentarea: buildFieldseekerTreatmentareaPreloader(),
FieldseekerZone: buildFieldseekerZonePreloader(),
FieldseekerZones2: buildFieldseekerZones2Preloader(),
FieldseekerSync: buildFieldseekerSyncPreloader(),
FileuploadCSV: buildFileuploadCSVPreloader(),
FileuploadErrorCSV: buildFileuploadErrorCSVPreloader(),
FileuploadErrorFile: buildFileuploadErrorFilePreloader(),
FileuploadFile: buildFileuploadFilePreloader(),
FileuploadPool: buildFileuploadPoolPreloader(),
H3Aggregation: buildH3AggregationPreloader(),
Lead: buildLeadPreloader(),
NoteAudio: buildNoteAudioPreloader(),
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbPreloader(),
NoteAudioDatum: buildNoteAudioDatumPreloader(),
NoteImage: buildNoteImagePreloader(),
NoteImageBreadcrumb: buildNoteImageBreadcrumbPreloader(),
NoteImageDatum: buildNoteImageDatumPreloader(),
Notification: buildNotificationPreloader(),
Organization: buildOrganizationPreloader(),
Parcel: buildParcelPreloader(),
PublicreportImage: buildPublicreportImagePreloader(),
PublicreportImageExif: buildPublicreportImageExifPreloader(),
PublicreportNotifyEmail: buildPublicreportNotifyEmailPreloader(),
PublicreportNotifyEmailNuisanceOld: buildPublicreportNotifyEmailNuisanceOldPreloader(),
PublicreportNotifyEmailWaterOld: buildPublicreportNotifyEmailWaterOldPreloader(),
PublicreportNotifyPhone: buildPublicreportNotifyPhonePreloader(),
PublicreportNotifyPhoneNuisanceOld: buildPublicreportNotifyPhoneNuisanceOldPreloader(),
PublicreportNotifyPhoneWaterOld: buildPublicreportNotifyPhoneWaterOldPreloader(),
PublicreportNuisance: buildPublicreportNuisancePreloader(),
PublicreportNuisanceImageOld: buildPublicreportNuisanceImageOldPreloader(),
PublicreportNuisanceOld: buildPublicreportNuisanceOldPreloader(),
PublicreportReport: buildPublicreportReportPreloader(),
PublicreportReportImage: buildPublicreportReportImagePreloader(),
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailPreloader(),
PublicreportSubscribePhone: buildPublicreportSubscribePhonePreloader(),
PublicreportWater: buildPublicreportWaterPreloader(),
PublicreportWaterImageOld: buildPublicreportWaterImageOldPreloader(),
PublicreportWaterOld: buildPublicreportWaterOldPreloader(),
ReportText: buildReportTextPreloader(),
Resident: buildResidentPreloader(),
ReviewTask: buildReviewTaskPreloader(),
ReviewTaskPool: buildReviewTaskPoolPreloader(),
Signal: buildSignalPreloader(),
Site: buildSitePreloader(),
TileCachedImage: buildTileCachedImagePreloader(),
User: buildUserPreloader(),
}
}
@ -205,184 +219,198 @@ var (
)
type thenLoaders[Q orm.Loadable] struct {
Address addressThenLoader[Q]
ArcgisAccount arcgisAccountThenLoader[Q]
ArcgisAddressMapping arcgisAddressMappingThenLoader[Q]
ArcgisLayer arcgisLayerThenLoader[Q]
ArcgisLayerField arcgisLayerFieldThenLoader[Q]
ArcgisOauthToken arcgisOauthTokenThenLoader[Q]
ArcgisParcelMapping arcgisParcelMappingThenLoader[Q]
ArcgisServiceFeature arcgisServiceFeatureThenLoader[Q]
ArcgisServiceMap arcgisServiceMapThenLoader[Q]
ArcgisUser arcgisuserThenLoader[Q]
ArcgisUserPrivilege arcgisUserPrivilegeThenLoader[Q]
CommsEmailContact commsEmailContactThenLoader[Q]
CommsEmailLog commsEmailLogThenLoader[Q]
CommsEmailTemplate commsEmailTemplateThenLoader[Q]
CommsMailer commsMailerThenLoader[Q]
CommsPhone commsPhoneThenLoader[Q]
CommsTextJob commsTextJobThenLoader[Q]
CommsTextLog commsTextLogThenLoader[Q]
ComplianceReportRequest complianceReportRequestThenLoader[Q]
ComplianceReportRequestMailer complianceReportRequestMailerThenLoader[Q]
DistrictSubscriptionEmail districtSubscriptionEmailThenLoader[Q]
DistrictSubscriptionPhone districtSubscriptionPhoneThenLoader[Q]
Feature featureThenLoader[Q]
FeaturePool featurePoolThenLoader[Q]
FieldseekerContainerrelate fieldseekerContainerrelateThenLoader[Q]
FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogThenLoader[Q]
FieldseekerHabitatrelate fieldseekerHabitatrelateThenLoader[Q]
FieldseekerInspectionsample fieldseekerInspectionsampleThenLoader[Q]
FieldseekerInspectionsampledetail fieldseekerInspectionsampledetailThenLoader[Q]
FieldseekerLinelocation fieldseekerLinelocationThenLoader[Q]
FieldseekerLocationtracking fieldseekerLocationtrackingThenLoader[Q]
FieldseekerMosquitoinspection fieldseekerMosquitoinspectionThenLoader[Q]
FieldseekerPointlocation fieldseekerPointlocationThenLoader[Q]
FieldseekerPolygonlocation fieldseekerPolygonlocationThenLoader[Q]
FieldseekerPool fieldseekerPoolThenLoader[Q]
FieldseekerPooldetail fieldseekerPooldetailThenLoader[Q]
FieldseekerProposedtreatmentarea fieldseekerProposedtreatmentareaThenLoader[Q]
FieldseekerQamosquitoinspection fieldseekerQamosquitoinspectionThenLoader[Q]
FieldseekerRodentlocation fieldseekerRodentlocationThenLoader[Q]
FieldseekerSamplecollection fieldseekerSamplecollectionThenLoader[Q]
FieldseekerSamplelocation fieldseekerSamplelocationThenLoader[Q]
FieldseekerServicerequest fieldseekerServicerequestThenLoader[Q]
FieldseekerSpeciesabundance fieldseekerSpeciesabundanceThenLoader[Q]
FieldseekerStormdrain fieldseekerStormdrainThenLoader[Q]
FieldseekerTimecard fieldseekerTimecardThenLoader[Q]
FieldseekerTrapdatum fieldseekerTrapdatumThenLoader[Q]
FieldseekerTraplocation fieldseekerTraplocationThenLoader[Q]
FieldseekerTreatment fieldseekerTreatmentThenLoader[Q]
FieldseekerTreatmentarea fieldseekerTreatmentareaThenLoader[Q]
FieldseekerZone fieldseekerZoneThenLoader[Q]
FieldseekerZones2 fieldseekerZones2ThenLoader[Q]
FieldseekerSync fieldseekerSyncThenLoader[Q]
FileuploadCSV fileuploadCSVThenLoader[Q]
FileuploadErrorCSV fileuploadErrorCSVThenLoader[Q]
FileuploadErrorFile fileuploadErrorFileThenLoader[Q]
FileuploadFile fileuploadFileThenLoader[Q]
FileuploadPool fileuploadPoolThenLoader[Q]
H3Aggregation h3AggregationThenLoader[Q]
Lead leadThenLoader[Q]
NoteAudio noteAudioThenLoader[Q]
NoteAudioBreadcrumb noteAudioBreadcrumbThenLoader[Q]
NoteAudioDatum noteAudioDatumThenLoader[Q]
NoteImage noteImageThenLoader[Q]
NoteImageBreadcrumb noteImageBreadcrumbThenLoader[Q]
NoteImageDatum noteImageDatumThenLoader[Q]
Notification notificationThenLoader[Q]
Organization organizationThenLoader[Q]
Parcel parcelThenLoader[Q]
PublicreportImage publicreportImageThenLoader[Q]
PublicreportImageExif publicreportImageExifThenLoader[Q]
PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisanceThenLoader[Q]
PublicreportNotifyEmailWater publicreportNotifyEmailWaterThenLoader[Q]
PublicreportNotifyPhoneNuisance publicreportNotifyPhoneNuisanceThenLoader[Q]
PublicreportNotifyPhoneWater publicreportNotifyPhoneWaterThenLoader[Q]
PublicreportNuisance publicreportNuisanceThenLoader[Q]
PublicreportNuisanceImage publicreportNuisanceImageThenLoader[Q]
PublicreportSubscribeEmail publicreportSubscribeEmailThenLoader[Q]
PublicreportSubscribePhone publicreportSubscribePhoneThenLoader[Q]
PublicreportWater publicreportWaterThenLoader[Q]
PublicreportWaterImage publicreportWaterImageThenLoader[Q]
Resident residentThenLoader[Q]
ReviewTask reviewTaskThenLoader[Q]
ReviewTaskPool reviewTaskPoolThenLoader[Q]
Signal signalThenLoader[Q]
Site siteThenLoader[Q]
TileCachedImage tileCachedImageThenLoader[Q]
User userThenLoader[Q]
Address addressThenLoader[Q]
ArcgisAccount arcgisAccountThenLoader[Q]
ArcgisAddressMapping arcgisAddressMappingThenLoader[Q]
ArcgisLayer arcgisLayerThenLoader[Q]
ArcgisLayerField arcgisLayerFieldThenLoader[Q]
ArcgisOauthToken arcgisOauthTokenThenLoader[Q]
ArcgisParcelMapping arcgisParcelMappingThenLoader[Q]
ArcgisServiceFeature arcgisServiceFeatureThenLoader[Q]
ArcgisServiceMap arcgisServiceMapThenLoader[Q]
ArcgisUser arcgisuserThenLoader[Q]
ArcgisUserPrivilege arcgisUserPrivilegeThenLoader[Q]
CommsEmailContact commsEmailContactThenLoader[Q]
CommsEmailLog commsEmailLogThenLoader[Q]
CommsEmailTemplate commsEmailTemplateThenLoader[Q]
CommsMailer commsMailerThenLoader[Q]
CommsPhone commsPhoneThenLoader[Q]
CommsTextJob commsTextJobThenLoader[Q]
CommsTextLog commsTextLogThenLoader[Q]
ComplianceReportRequest complianceReportRequestThenLoader[Q]
ComplianceReportRequestMailer complianceReportRequestMailerThenLoader[Q]
DistrictSubscriptionEmail districtSubscriptionEmailThenLoader[Q]
DistrictSubscriptionPhone districtSubscriptionPhoneThenLoader[Q]
Feature featureThenLoader[Q]
FeaturePool featurePoolThenLoader[Q]
FieldseekerContainerrelate fieldseekerContainerrelateThenLoader[Q]
FieldseekerFieldscoutinglog fieldseekerFieldscoutinglogThenLoader[Q]
FieldseekerHabitatrelate fieldseekerHabitatrelateThenLoader[Q]
FieldseekerInspectionsample fieldseekerInspectionsampleThenLoader[Q]
FieldseekerInspectionsampledetail fieldseekerInspectionsampledetailThenLoader[Q]
FieldseekerLinelocation fieldseekerLinelocationThenLoader[Q]
FieldseekerLocationtracking fieldseekerLocationtrackingThenLoader[Q]
FieldseekerMosquitoinspection fieldseekerMosquitoinspectionThenLoader[Q]
FieldseekerPointlocation fieldseekerPointlocationThenLoader[Q]
FieldseekerPolygonlocation fieldseekerPolygonlocationThenLoader[Q]
FieldseekerPool fieldseekerPoolThenLoader[Q]
FieldseekerPooldetail fieldseekerPooldetailThenLoader[Q]
FieldseekerProposedtreatmentarea fieldseekerProposedtreatmentareaThenLoader[Q]
FieldseekerQamosquitoinspection fieldseekerQamosquitoinspectionThenLoader[Q]
FieldseekerRodentlocation fieldseekerRodentlocationThenLoader[Q]
FieldseekerSamplecollection fieldseekerSamplecollectionThenLoader[Q]
FieldseekerSamplelocation fieldseekerSamplelocationThenLoader[Q]
FieldseekerServicerequest fieldseekerServicerequestThenLoader[Q]
FieldseekerSpeciesabundance fieldseekerSpeciesabundanceThenLoader[Q]
FieldseekerStormdrain fieldseekerStormdrainThenLoader[Q]
FieldseekerTimecard fieldseekerTimecardThenLoader[Q]
FieldseekerTrapdatum fieldseekerTrapdatumThenLoader[Q]
FieldseekerTraplocation fieldseekerTraplocationThenLoader[Q]
FieldseekerTreatment fieldseekerTreatmentThenLoader[Q]
FieldseekerTreatmentarea fieldseekerTreatmentareaThenLoader[Q]
FieldseekerZone fieldseekerZoneThenLoader[Q]
FieldseekerZones2 fieldseekerZones2ThenLoader[Q]
FieldseekerSync fieldseekerSyncThenLoader[Q]
FileuploadCSV fileuploadCSVThenLoader[Q]
FileuploadErrorCSV fileuploadErrorCSVThenLoader[Q]
FileuploadErrorFile fileuploadErrorFileThenLoader[Q]
FileuploadFile fileuploadFileThenLoader[Q]
FileuploadPool fileuploadPoolThenLoader[Q]
H3Aggregation h3AggregationThenLoader[Q]
Lead leadThenLoader[Q]
NoteAudio noteAudioThenLoader[Q]
NoteAudioBreadcrumb noteAudioBreadcrumbThenLoader[Q]
NoteAudioDatum noteAudioDatumThenLoader[Q]
NoteImage noteImageThenLoader[Q]
NoteImageBreadcrumb noteImageBreadcrumbThenLoader[Q]
NoteImageDatum noteImageDatumThenLoader[Q]
Notification notificationThenLoader[Q]
Organization organizationThenLoader[Q]
Parcel parcelThenLoader[Q]
PublicreportImage publicreportImageThenLoader[Q]
PublicreportImageExif publicreportImageExifThenLoader[Q]
PublicreportNotifyEmail publicreportNotifyEmailThenLoader[Q]
PublicreportNotifyEmailNuisanceOld publicreportNotifyEmailNuisanceOldThenLoader[Q]
PublicreportNotifyEmailWaterOld publicreportNotifyEmailWaterOldThenLoader[Q]
PublicreportNotifyPhone publicreportNotifyPhoneThenLoader[Q]
PublicreportNotifyPhoneNuisanceOld publicreportNotifyPhoneNuisanceOldThenLoader[Q]
PublicreportNotifyPhoneWaterOld publicreportNotifyPhoneWaterOldThenLoader[Q]
PublicreportNuisance publicreportNuisanceThenLoader[Q]
PublicreportNuisanceImageOld publicreportNuisanceImageOldThenLoader[Q]
PublicreportNuisanceOld publicreportNuisanceOldThenLoader[Q]
PublicreportReport publicreportReportThenLoader[Q]
PublicreportReportImage publicreportReportImageThenLoader[Q]
PublicreportSubscribeEmail publicreportSubscribeEmailThenLoader[Q]
PublicreportSubscribePhone publicreportSubscribePhoneThenLoader[Q]
PublicreportWater publicreportWaterThenLoader[Q]
PublicreportWaterImageOld publicreportWaterImageOldThenLoader[Q]
PublicreportWaterOld publicreportWaterOldThenLoader[Q]
ReportText reportTextThenLoader[Q]
Resident residentThenLoader[Q]
ReviewTask reviewTaskThenLoader[Q]
ReviewTaskPool reviewTaskPoolThenLoader[Q]
Signal signalThenLoader[Q]
Site siteThenLoader[Q]
TileCachedImage tileCachedImageThenLoader[Q]
User userThenLoader[Q]
}
func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
return thenLoaders[Q]{
Address: buildAddressThenLoader[Q](),
ArcgisAccount: buildArcgisAccountThenLoader[Q](),
ArcgisAddressMapping: buildArcgisAddressMappingThenLoader[Q](),
ArcgisLayer: buildArcgisLayerThenLoader[Q](),
ArcgisLayerField: buildArcgisLayerFieldThenLoader[Q](),
ArcgisOauthToken: buildArcgisOauthTokenThenLoader[Q](),
ArcgisParcelMapping: buildArcgisParcelMappingThenLoader[Q](),
ArcgisServiceFeature: buildArcgisServiceFeatureThenLoader[Q](),
ArcgisServiceMap: buildArcgisServiceMapThenLoader[Q](),
ArcgisUser: buildArcgisUserThenLoader[Q](),
ArcgisUserPrivilege: buildArcgisUserPrivilegeThenLoader[Q](),
CommsEmailContact: buildCommsEmailContactThenLoader[Q](),
CommsEmailLog: buildCommsEmailLogThenLoader[Q](),
CommsEmailTemplate: buildCommsEmailTemplateThenLoader[Q](),
CommsMailer: buildCommsMailerThenLoader[Q](),
CommsPhone: buildCommsPhoneThenLoader[Q](),
CommsTextJob: buildCommsTextJobThenLoader[Q](),
CommsTextLog: buildCommsTextLogThenLoader[Q](),
ComplianceReportRequest: buildComplianceReportRequestThenLoader[Q](),
ComplianceReportRequestMailer: buildComplianceReportRequestMailerThenLoader[Q](),
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailThenLoader[Q](),
DistrictSubscriptionPhone: buildDistrictSubscriptionPhoneThenLoader[Q](),
Feature: buildFeatureThenLoader[Q](),
FeaturePool: buildFeaturePoolThenLoader[Q](),
FieldseekerContainerrelate: buildFieldseekerContainerrelateThenLoader[Q](),
FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogThenLoader[Q](),
FieldseekerHabitatrelate: buildFieldseekerHabitatrelateThenLoader[Q](),
FieldseekerInspectionsample: buildFieldseekerInspectionsampleThenLoader[Q](),
FieldseekerInspectionsampledetail: buildFieldseekerInspectionsampledetailThenLoader[Q](),
FieldseekerLinelocation: buildFieldseekerLinelocationThenLoader[Q](),
FieldseekerLocationtracking: buildFieldseekerLocationtrackingThenLoader[Q](),
FieldseekerMosquitoinspection: buildFieldseekerMosquitoinspectionThenLoader[Q](),
FieldseekerPointlocation: buildFieldseekerPointlocationThenLoader[Q](),
FieldseekerPolygonlocation: buildFieldseekerPolygonlocationThenLoader[Q](),
FieldseekerPool: buildFieldseekerPoolThenLoader[Q](),
FieldseekerPooldetail: buildFieldseekerPooldetailThenLoader[Q](),
FieldseekerProposedtreatmentarea: buildFieldseekerProposedtreatmentareaThenLoader[Q](),
FieldseekerQamosquitoinspection: buildFieldseekerQamosquitoinspectionThenLoader[Q](),
FieldseekerRodentlocation: buildFieldseekerRodentlocationThenLoader[Q](),
FieldseekerSamplecollection: buildFieldseekerSamplecollectionThenLoader[Q](),
FieldseekerSamplelocation: buildFieldseekerSamplelocationThenLoader[Q](),
FieldseekerServicerequest: buildFieldseekerServicerequestThenLoader[Q](),
FieldseekerSpeciesabundance: buildFieldseekerSpeciesabundanceThenLoader[Q](),
FieldseekerStormdrain: buildFieldseekerStormdrainThenLoader[Q](),
FieldseekerTimecard: buildFieldseekerTimecardThenLoader[Q](),
FieldseekerTrapdatum: buildFieldseekerTrapdatumThenLoader[Q](),
FieldseekerTraplocation: buildFieldseekerTraplocationThenLoader[Q](),
FieldseekerTreatment: buildFieldseekerTreatmentThenLoader[Q](),
FieldseekerTreatmentarea: buildFieldseekerTreatmentareaThenLoader[Q](),
FieldseekerZone: buildFieldseekerZoneThenLoader[Q](),
FieldseekerZones2: buildFieldseekerZones2ThenLoader[Q](),
FieldseekerSync: buildFieldseekerSyncThenLoader[Q](),
FileuploadCSV: buildFileuploadCSVThenLoader[Q](),
FileuploadErrorCSV: buildFileuploadErrorCSVThenLoader[Q](),
FileuploadErrorFile: buildFileuploadErrorFileThenLoader[Q](),
FileuploadFile: buildFileuploadFileThenLoader[Q](),
FileuploadPool: buildFileuploadPoolThenLoader[Q](),
H3Aggregation: buildH3AggregationThenLoader[Q](),
Lead: buildLeadThenLoader[Q](),
NoteAudio: buildNoteAudioThenLoader[Q](),
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbThenLoader[Q](),
NoteAudioDatum: buildNoteAudioDatumThenLoader[Q](),
NoteImage: buildNoteImageThenLoader[Q](),
NoteImageBreadcrumb: buildNoteImageBreadcrumbThenLoader[Q](),
NoteImageDatum: buildNoteImageDatumThenLoader[Q](),
Notification: buildNotificationThenLoader[Q](),
Organization: buildOrganizationThenLoader[Q](),
Parcel: buildParcelThenLoader[Q](),
PublicreportImage: buildPublicreportImageThenLoader[Q](),
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisanceThenLoader[Q](),
PublicreportNotifyEmailWater: buildPublicreportNotifyEmailWaterThenLoader[Q](),
PublicreportNotifyPhoneNuisance: buildPublicreportNotifyPhoneNuisanceThenLoader[Q](),
PublicreportNotifyPhoneWater: buildPublicreportNotifyPhoneWaterThenLoader[Q](),
PublicreportNuisance: buildPublicreportNuisanceThenLoader[Q](),
PublicreportNuisanceImage: buildPublicreportNuisanceImageThenLoader[Q](),
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailThenLoader[Q](),
PublicreportSubscribePhone: buildPublicreportSubscribePhoneThenLoader[Q](),
PublicreportWater: buildPublicreportWaterThenLoader[Q](),
PublicreportWaterImage: buildPublicreportWaterImageThenLoader[Q](),
Resident: buildResidentThenLoader[Q](),
ReviewTask: buildReviewTaskThenLoader[Q](),
ReviewTaskPool: buildReviewTaskPoolThenLoader[Q](),
Signal: buildSignalThenLoader[Q](),
Site: buildSiteThenLoader[Q](),
TileCachedImage: buildTileCachedImageThenLoader[Q](),
User: buildUserThenLoader[Q](),
Address: buildAddressThenLoader[Q](),
ArcgisAccount: buildArcgisAccountThenLoader[Q](),
ArcgisAddressMapping: buildArcgisAddressMappingThenLoader[Q](),
ArcgisLayer: buildArcgisLayerThenLoader[Q](),
ArcgisLayerField: buildArcgisLayerFieldThenLoader[Q](),
ArcgisOauthToken: buildArcgisOauthTokenThenLoader[Q](),
ArcgisParcelMapping: buildArcgisParcelMappingThenLoader[Q](),
ArcgisServiceFeature: buildArcgisServiceFeatureThenLoader[Q](),
ArcgisServiceMap: buildArcgisServiceMapThenLoader[Q](),
ArcgisUser: buildArcgisUserThenLoader[Q](),
ArcgisUserPrivilege: buildArcgisUserPrivilegeThenLoader[Q](),
CommsEmailContact: buildCommsEmailContactThenLoader[Q](),
CommsEmailLog: buildCommsEmailLogThenLoader[Q](),
CommsEmailTemplate: buildCommsEmailTemplateThenLoader[Q](),
CommsMailer: buildCommsMailerThenLoader[Q](),
CommsPhone: buildCommsPhoneThenLoader[Q](),
CommsTextJob: buildCommsTextJobThenLoader[Q](),
CommsTextLog: buildCommsTextLogThenLoader[Q](),
ComplianceReportRequest: buildComplianceReportRequestThenLoader[Q](),
ComplianceReportRequestMailer: buildComplianceReportRequestMailerThenLoader[Q](),
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailThenLoader[Q](),
DistrictSubscriptionPhone: buildDistrictSubscriptionPhoneThenLoader[Q](),
Feature: buildFeatureThenLoader[Q](),
FeaturePool: buildFeaturePoolThenLoader[Q](),
FieldseekerContainerrelate: buildFieldseekerContainerrelateThenLoader[Q](),
FieldseekerFieldscoutinglog: buildFieldseekerFieldscoutinglogThenLoader[Q](),
FieldseekerHabitatrelate: buildFieldseekerHabitatrelateThenLoader[Q](),
FieldseekerInspectionsample: buildFieldseekerInspectionsampleThenLoader[Q](),
FieldseekerInspectionsampledetail: buildFieldseekerInspectionsampledetailThenLoader[Q](),
FieldseekerLinelocation: buildFieldseekerLinelocationThenLoader[Q](),
FieldseekerLocationtracking: buildFieldseekerLocationtrackingThenLoader[Q](),
FieldseekerMosquitoinspection: buildFieldseekerMosquitoinspectionThenLoader[Q](),
FieldseekerPointlocation: buildFieldseekerPointlocationThenLoader[Q](),
FieldseekerPolygonlocation: buildFieldseekerPolygonlocationThenLoader[Q](),
FieldseekerPool: buildFieldseekerPoolThenLoader[Q](),
FieldseekerPooldetail: buildFieldseekerPooldetailThenLoader[Q](),
FieldseekerProposedtreatmentarea: buildFieldseekerProposedtreatmentareaThenLoader[Q](),
FieldseekerQamosquitoinspection: buildFieldseekerQamosquitoinspectionThenLoader[Q](),
FieldseekerRodentlocation: buildFieldseekerRodentlocationThenLoader[Q](),
FieldseekerSamplecollection: buildFieldseekerSamplecollectionThenLoader[Q](),
FieldseekerSamplelocation: buildFieldseekerSamplelocationThenLoader[Q](),
FieldseekerServicerequest: buildFieldseekerServicerequestThenLoader[Q](),
FieldseekerSpeciesabundance: buildFieldseekerSpeciesabundanceThenLoader[Q](),
FieldseekerStormdrain: buildFieldseekerStormdrainThenLoader[Q](),
FieldseekerTimecard: buildFieldseekerTimecardThenLoader[Q](),
FieldseekerTrapdatum: buildFieldseekerTrapdatumThenLoader[Q](),
FieldseekerTraplocation: buildFieldseekerTraplocationThenLoader[Q](),
FieldseekerTreatment: buildFieldseekerTreatmentThenLoader[Q](),
FieldseekerTreatmentarea: buildFieldseekerTreatmentareaThenLoader[Q](),
FieldseekerZone: buildFieldseekerZoneThenLoader[Q](),
FieldseekerZones2: buildFieldseekerZones2ThenLoader[Q](),
FieldseekerSync: buildFieldseekerSyncThenLoader[Q](),
FileuploadCSV: buildFileuploadCSVThenLoader[Q](),
FileuploadErrorCSV: buildFileuploadErrorCSVThenLoader[Q](),
FileuploadErrorFile: buildFileuploadErrorFileThenLoader[Q](),
FileuploadFile: buildFileuploadFileThenLoader[Q](),
FileuploadPool: buildFileuploadPoolThenLoader[Q](),
H3Aggregation: buildH3AggregationThenLoader[Q](),
Lead: buildLeadThenLoader[Q](),
NoteAudio: buildNoteAudioThenLoader[Q](),
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbThenLoader[Q](),
NoteAudioDatum: buildNoteAudioDatumThenLoader[Q](),
NoteImage: buildNoteImageThenLoader[Q](),
NoteImageBreadcrumb: buildNoteImageBreadcrumbThenLoader[Q](),
NoteImageDatum: buildNoteImageDatumThenLoader[Q](),
Notification: buildNotificationThenLoader[Q](),
Organization: buildOrganizationThenLoader[Q](),
Parcel: buildParcelThenLoader[Q](),
PublicreportImage: buildPublicreportImageThenLoader[Q](),
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
PublicreportNotifyEmail: buildPublicreportNotifyEmailThenLoader[Q](),
PublicreportNotifyEmailNuisanceOld: buildPublicreportNotifyEmailNuisanceOldThenLoader[Q](),
PublicreportNotifyEmailWaterOld: buildPublicreportNotifyEmailWaterOldThenLoader[Q](),
PublicreportNotifyPhone: buildPublicreportNotifyPhoneThenLoader[Q](),
PublicreportNotifyPhoneNuisanceOld: buildPublicreportNotifyPhoneNuisanceOldThenLoader[Q](),
PublicreportNotifyPhoneWaterOld: buildPublicreportNotifyPhoneWaterOldThenLoader[Q](),
PublicreportNuisance: buildPublicreportNuisanceThenLoader[Q](),
PublicreportNuisanceImageOld: buildPublicreportNuisanceImageOldThenLoader[Q](),
PublicreportNuisanceOld: buildPublicreportNuisanceOldThenLoader[Q](),
PublicreportReport: buildPublicreportReportThenLoader[Q](),
PublicreportReportImage: buildPublicreportReportImageThenLoader[Q](),
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailThenLoader[Q](),
PublicreportSubscribePhone: buildPublicreportSubscribePhoneThenLoader[Q](),
PublicreportWater: buildPublicreportWaterThenLoader[Q](),
PublicreportWaterImageOld: buildPublicreportWaterImageOldThenLoader[Q](),
PublicreportWaterOld: buildPublicreportWaterOldThenLoader[Q](),
ReportText: buildReportTextThenLoader[Q](),
Resident: buildResidentThenLoader[Q](),
ReviewTask: buildReviewTaskThenLoader[Q](),
ReviewTaskPool: buildReviewTaskPoolThenLoader[Q](),
Signal: buildSignalThenLoader[Q](),
Site: buildSiteThenLoader[Q](),
TileCachedImage: buildTileCachedImageThenLoader[Q](),
User: buildUserThenLoader[Q](),
}
}

View file

@ -91,20 +91,27 @@ func Where[Q psql.Filterable]() struct {
Parcels parcelWhere[Q]
PublicreportImages publicreportImageWhere[Q]
PublicreportImageExifs publicreportImageExifWhere[Q]
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
PublicreportNotifyEmailWaters publicreportNotifyEmailWaterWhere[Q]
PublicreportNotifyPhoneNuisances publicreportNotifyPhoneNuisanceWhere[Q]
PublicreportNotifyPhoneWaters publicreportNotifyPhoneWaterWhere[Q]
PublicreportNotifyEmails publicreportNotifyEmailWhere[Q]
PublicreportNotifyEmailNuisanceOlds publicreportNotifyEmailNuisanceOldWhere[Q]
PublicreportNotifyEmailWaterOlds publicreportNotifyEmailWaterOldWhere[Q]
PublicreportNotifyPhones publicreportNotifyPhoneWhere[Q]
PublicreportNotifyPhoneNuisanceOlds publicreportNotifyPhoneNuisanceOldWhere[Q]
PublicreportNotifyPhoneWaterOlds publicreportNotifyPhoneWaterOldWhere[Q]
PublicreportNuisances publicreportNuisanceWhere[Q]
PublicreportNuisanceImages publicreportNuisanceImageWhere[Q]
PublicreportNuisanceImageOlds publicreportNuisanceImageOldWhere[Q]
PublicreportNuisanceOlds publicreportNuisanceOldWhere[Q]
PublicreportOrganizationReportCounts publicreportOrganizationReportCountWhere[Q]
PublicreportReports publicreportReportWhere[Q]
PublicreportReportImages publicreportReportImageWhere[Q]
PublicreportReportLocations publicreportReportLocationWhere[Q]
PublicreportSubscribeEmails publicreportSubscribeEmailWhere[Q]
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
PublicreportWaters publicreportWaterWhere[Q]
PublicreportWaterImages publicreportWaterImageWhere[Q]
PublicreportWaterImageOlds publicreportWaterImageOldWhere[Q]
PublicreportWaterOlds publicreportWaterOldWhere[Q]
RasterColumns rasterColumnWhere[Q]
RasterOverviews rasterOverviewWhere[Q]
ReportTexts reportTextWhere[Q]
Residents residentWhere[Q]
ReviewTasks reviewTaskWhere[Q]
ReviewTaskPools reviewTaskPoolWhere[Q]
@ -190,20 +197,27 @@ func Where[Q psql.Filterable]() struct {
Parcels parcelWhere[Q]
PublicreportImages publicreportImageWhere[Q]
PublicreportImageExifs publicreportImageExifWhere[Q]
PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q]
PublicreportNotifyEmailWaters publicreportNotifyEmailWaterWhere[Q]
PublicreportNotifyPhoneNuisances publicreportNotifyPhoneNuisanceWhere[Q]
PublicreportNotifyPhoneWaters publicreportNotifyPhoneWaterWhere[Q]
PublicreportNotifyEmails publicreportNotifyEmailWhere[Q]
PublicreportNotifyEmailNuisanceOlds publicreportNotifyEmailNuisanceOldWhere[Q]
PublicreportNotifyEmailWaterOlds publicreportNotifyEmailWaterOldWhere[Q]
PublicreportNotifyPhones publicreportNotifyPhoneWhere[Q]
PublicreportNotifyPhoneNuisanceOlds publicreportNotifyPhoneNuisanceOldWhere[Q]
PublicreportNotifyPhoneWaterOlds publicreportNotifyPhoneWaterOldWhere[Q]
PublicreportNuisances publicreportNuisanceWhere[Q]
PublicreportNuisanceImages publicreportNuisanceImageWhere[Q]
PublicreportNuisanceImageOlds publicreportNuisanceImageOldWhere[Q]
PublicreportNuisanceOlds publicreportNuisanceOldWhere[Q]
PublicreportOrganizationReportCounts publicreportOrganizationReportCountWhere[Q]
PublicreportReports publicreportReportWhere[Q]
PublicreportReportImages publicreportReportImageWhere[Q]
PublicreportReportLocations publicreportReportLocationWhere[Q]
PublicreportSubscribeEmails publicreportSubscribeEmailWhere[Q]
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
PublicreportWaters publicreportWaterWhere[Q]
PublicreportWaterImages publicreportWaterImageWhere[Q]
PublicreportWaterImageOlds publicreportWaterImageOldWhere[Q]
PublicreportWaterOlds publicreportWaterOldWhere[Q]
RasterColumns rasterColumnWhere[Q]
RasterOverviews rasterOverviewWhere[Q]
ReportTexts reportTextWhere[Q]
Residents residentWhere[Q]
ReviewTasks reviewTaskWhere[Q]
ReviewTaskPools reviewTaskPoolWhere[Q]
@ -288,20 +302,27 @@ func Where[Q psql.Filterable]() struct {
Parcels: buildParcelWhere[Q](Parcels.Columns),
PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns),
PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns),
PublicreportNotifyEmailNuisances: buildPublicreportNotifyEmailNuisanceWhere[Q](PublicreportNotifyEmailNuisances.Columns),
PublicreportNotifyEmailWaters: buildPublicreportNotifyEmailWaterWhere[Q](PublicreportNotifyEmailWaters.Columns),
PublicreportNotifyPhoneNuisances: buildPublicreportNotifyPhoneNuisanceWhere[Q](PublicreportNotifyPhoneNuisances.Columns),
PublicreportNotifyPhoneWaters: buildPublicreportNotifyPhoneWaterWhere[Q](PublicreportNotifyPhoneWaters.Columns),
PublicreportNotifyEmails: buildPublicreportNotifyEmailWhere[Q](PublicreportNotifyEmails.Columns),
PublicreportNotifyEmailNuisanceOlds: buildPublicreportNotifyEmailNuisanceOldWhere[Q](PublicreportNotifyEmailNuisanceOlds.Columns),
PublicreportNotifyEmailWaterOlds: buildPublicreportNotifyEmailWaterOldWhere[Q](PublicreportNotifyEmailWaterOlds.Columns),
PublicreportNotifyPhones: buildPublicreportNotifyPhoneWhere[Q](PublicreportNotifyPhones.Columns),
PublicreportNotifyPhoneNuisanceOlds: buildPublicreportNotifyPhoneNuisanceOldWhere[Q](PublicreportNotifyPhoneNuisanceOlds.Columns),
PublicreportNotifyPhoneWaterOlds: buildPublicreportNotifyPhoneWaterOldWhere[Q](PublicreportNotifyPhoneWaterOlds.Columns),
PublicreportNuisances: buildPublicreportNuisanceWhere[Q](PublicreportNuisances.Columns),
PublicreportNuisanceImages: buildPublicreportNuisanceImageWhere[Q](PublicreportNuisanceImages.Columns),
PublicreportNuisanceImageOlds: buildPublicreportNuisanceImageOldWhere[Q](PublicreportNuisanceImageOlds.Columns),
PublicreportNuisanceOlds: buildPublicreportNuisanceOldWhere[Q](PublicreportNuisanceOlds.Columns),
PublicreportOrganizationReportCounts: buildPublicreportOrganizationReportCountWhere[Q](PublicreportOrganizationReportCounts.Columns),
PublicreportReports: buildPublicreportReportWhere[Q](PublicreportReports.Columns),
PublicreportReportImages: buildPublicreportReportImageWhere[Q](PublicreportReportImages.Columns),
PublicreportReportLocations: buildPublicreportReportLocationWhere[Q](PublicreportReportLocations.Columns),
PublicreportSubscribeEmails: buildPublicreportSubscribeEmailWhere[Q](PublicreportSubscribeEmails.Columns),
PublicreportSubscribePhones: buildPublicreportSubscribePhoneWhere[Q](PublicreportSubscribePhones.Columns),
PublicreportWaters: buildPublicreportWaterWhere[Q](PublicreportWaters.Columns),
PublicreportWaterImages: buildPublicreportWaterImageWhere[Q](PublicreportWaterImages.Columns),
PublicreportWaterImageOlds: buildPublicreportWaterImageOldWhere[Q](PublicreportWaterImageOlds.Columns),
PublicreportWaterOlds: buildPublicreportWaterOldWhere[Q](PublicreportWaterOlds.Columns),
RasterColumns: buildRasterColumnWhere[Q](RasterColumns.Columns),
RasterOverviews: buildRasterOverviewWhere[Q](RasterOverviews.Columns),
ReportTexts: buildReportTextWhere[Q](ReportTexts.Columns),
Residents: buildResidentWhere[Q](Residents.Columns),
ReviewTasks: buildReviewTaskWhere[Q](ReviewTasks.Columns),
ReviewTaskPools: buildReviewTaskPoolWhere[Q](ReviewTaskPools.Columns),

View file

@ -43,11 +43,12 @@ 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
EmailAddressNotifyEmailNuisances PublicreportNotifyEmailNuisanceSlice // publicreport.notify_email_nuisance.notify_email_nuisance_email_address_fkey
EmailAddressNotifyEmailWaters PublicreportNotifyEmailWaterSlice // publicreport.notify_email_water.notify_email_pool_email_address_fkey
EmailAddressSubscribeEmails PublicreportSubscribeEmailSlice // publicreport.subscribe_email.subscribe_email_email_address_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
EmailAddressNotifyEmails PublicreportNotifyEmailSlice // publicreport.notify_email.notify_email_email_address_fkey
EmailAddressNotifyEmailNuisanceOlds PublicreportNotifyEmailNuisanceOldSlice // publicreport.notify_email_nuisance_old.notify_email_nuisance_email_address_fkey
EmailAddressNotifyEmailWaterOlds PublicreportNotifyEmailWaterOldSlice // publicreport.notify_email_water_old.notify_email_pool_email_address_fkey
EmailAddressSubscribeEmails PublicreportSubscribeEmailSlice // publicreport.subscribe_email.subscribe_email_email_address_fkey
}
func buildCommsEmailContactColumns(alias string) commsEmailContactColumns {
@ -471,14 +472,14 @@ 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))),
// EmailAddressNotifyEmails starts a query for related objects on publicreport.notify_email
func (o *CommsEmailContact) EmailAddressNotifyEmails(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailsQuery {
return PublicreportNotifyEmails.Query(append(mods,
sm.Where(PublicreportNotifyEmails.Columns.EmailAddress.EQ(psql.Arg(o.Address))),
)...)
}
func (os CommsEmailContactSlice) EmailAddressNotifyEmailNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisancesQuery {
func (os CommsEmailContactSlice) EmailAddressNotifyEmails(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailsQuery {
pkAddress := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
@ -490,19 +491,19 @@ func (os CommsEmailContactSlice) EmailAddressNotifyEmailNuisances(mods ...bob.Mo
psql.F("unnest", psql.Cast(psql.Arg(pkAddress), "text[]")),
))
return PublicreportNotifyEmailNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailNuisances.Columns.EmailAddress).OP("IN", PKArgExpr)),
return PublicreportNotifyEmails.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmails.Columns.EmailAddress).OP("IN", PKArgExpr)),
)...)
}
// EmailAddressNotifyEmailWaters starts a query for related objects on publicreport.notify_email_water
func (o *CommsEmailContact) EmailAddressNotifyEmailWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWatersQuery {
return PublicreportNotifyEmailWaters.Query(append(mods,
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(o.Address))),
// EmailAddressNotifyEmailNuisanceOlds starts a query for related objects on publicreport.notify_email_nuisance_old
func (o *CommsEmailContact) EmailAddressNotifyEmailNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisanceOldsQuery {
return PublicreportNotifyEmailNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.EmailAddress.EQ(psql.Arg(o.Address))),
)...)
}
func (os CommsEmailContactSlice) EmailAddressNotifyEmailWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWatersQuery {
func (os CommsEmailContactSlice) EmailAddressNotifyEmailNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisanceOldsQuery {
pkAddress := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
@ -514,8 +515,32 @@ func (os CommsEmailContactSlice) EmailAddressNotifyEmailWaters(mods ...bob.Mod[*
psql.F("unnest", psql.Cast(psql.Arg(pkAddress), "text[]")),
))
return PublicreportNotifyEmailWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailWaters.Columns.EmailAddress).OP("IN", PKArgExpr)),
return PublicreportNotifyEmailNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailNuisanceOlds.Columns.EmailAddress).OP("IN", PKArgExpr)),
)...)
}
// EmailAddressNotifyEmailWaterOlds starts a query for related objects on publicreport.notify_email_water_old
func (o *CommsEmailContact) EmailAddressNotifyEmailWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWaterOldsQuery {
return PublicreportNotifyEmailWaterOlds.Query(append(mods,
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.EmailAddress.EQ(psql.Arg(o.Address))),
)...)
}
func (os CommsEmailContactSlice) EmailAddressNotifyEmailWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWaterOldsQuery {
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 PublicreportNotifyEmailWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyEmailWaterOlds.Columns.EmailAddress).OP("IN", PKArgExpr)),
)...)
}
@ -676,66 +701,66 @@ 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)
func insertCommsEmailContactEmailAddressNotifyEmails0(ctx context.Context, exec bob.Executor, publicreportNotifyEmails1 []*PublicreportNotifyEmailSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailSlice, error) {
for i := range publicreportNotifyEmails1 {
publicreportNotifyEmails1[i].EmailAddress = omit.From(commsEmailContact0.Address)
}
ret, err := PublicreportNotifyEmailNuisances.Insert(bob.ToMods(publicreportNotifyEmailNuisances1...)).All(ctx, exec)
ret, err := PublicreportNotifyEmails.Insert(bob.ToMods(publicreportNotifyEmails1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailNuisances0: %w", err)
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmails0: %w", err)
}
return ret, nil
}
func attachCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisances1 PublicreportNotifyEmailNuisanceSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailNuisanceSlice, error) {
setter := &PublicreportNotifyEmailNuisanceSetter{
func attachCommsEmailContactEmailAddressNotifyEmails0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmails1 PublicreportNotifyEmailSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailSlice, error) {
setter := &PublicreportNotifyEmailSetter{
EmailAddress: omit.From(commsEmailContact0.Address),
}
err := publicreportNotifyEmailNuisances1.UpdateAll(ctx, exec, *setter)
err := publicreportNotifyEmails1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailNuisances0: %w", err)
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmails0: %w", err)
}
return publicreportNotifyEmailNuisances1, nil
return publicreportNotifyEmails1, nil
}
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceSetter) error {
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailNuisances1, err := insertCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx, exec, related, commsEmailContact0)
publicreportNotifyEmails1, err := insertCommsEmailContactEmailAddressNotifyEmails0(ctx, exec, related, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailNuisances = append(commsEmailContact0.R.EmailAddressNotifyEmailNuisances, publicreportNotifyEmailNuisances1...)
commsEmailContact0.R.EmailAddressNotifyEmails = append(commsEmailContact0.R.EmailAddressNotifyEmails, publicreportNotifyEmails1...)
for _, rel := range publicreportNotifyEmailNuisances1 {
for _, rel := range publicreportNotifyEmails1 {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisance) error {
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmail) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailNuisances1 := PublicreportNotifyEmailNuisanceSlice(related)
publicreportNotifyEmails1 := PublicreportNotifyEmailSlice(related)
_, err = attachCommsEmailContactEmailAddressNotifyEmailNuisances0(ctx, exec, len(related), publicreportNotifyEmailNuisances1, commsEmailContact0)
_, err = attachCommsEmailContactEmailAddressNotifyEmails0(ctx, exec, len(related), publicreportNotifyEmails1, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailNuisances = append(commsEmailContact0.R.EmailAddressNotifyEmailNuisances, publicreportNotifyEmailNuisances1...)
commsEmailContact0.R.EmailAddressNotifyEmails = append(commsEmailContact0.R.EmailAddressNotifyEmails, publicreportNotifyEmails1...)
for _, rel := range related {
rel.R.EmailAddressEmailContact = commsEmailContact0
@ -744,66 +769,134 @@ func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailNuisan
return nil
}
func insertCommsEmailContactEmailAddressNotifyEmailWaters0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailWaters1 []*PublicreportNotifyEmailWaterSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailWaterSlice, error) {
for i := range publicreportNotifyEmailWaters1 {
publicreportNotifyEmailWaters1[i].EmailAddress = omit.From(commsEmailContact0.Address)
func insertCommsEmailContactEmailAddressNotifyEmailNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailNuisanceOlds1 []*PublicreportNotifyEmailNuisanceOldSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailNuisanceOldSlice, error) {
for i := range publicreportNotifyEmailNuisanceOlds1 {
publicreportNotifyEmailNuisanceOlds1[i].EmailAddress = omit.From(commsEmailContact0.Address)
}
ret, err := PublicreportNotifyEmailWaters.Insert(bob.ToMods(publicreportNotifyEmailWaters1...)).All(ctx, exec)
ret, err := PublicreportNotifyEmailNuisanceOlds.Insert(bob.ToMods(publicreportNotifyEmailNuisanceOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailWaters0: %w", err)
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailNuisanceOlds0: %w", err)
}
return ret, nil
}
func attachCommsEmailContactEmailAddressNotifyEmailWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaters1 PublicreportNotifyEmailWaterSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailWaterSlice, error) {
setter := &PublicreportNotifyEmailWaterSetter{
func attachCommsEmailContactEmailAddressNotifyEmailNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisanceOlds1 PublicreportNotifyEmailNuisanceOldSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailNuisanceOldSlice, error) {
setter := &PublicreportNotifyEmailNuisanceOldSetter{
EmailAddress: omit.From(commsEmailContact0.Address),
}
err := publicreportNotifyEmailWaters1.UpdateAll(ctx, exec, *setter)
err := publicreportNotifyEmailNuisanceOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailWaters0: %w", err)
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailNuisanceOlds0: %w", err)
}
return publicreportNotifyEmailWaters1, nil
return publicreportNotifyEmailNuisanceOlds1, nil
}
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterSetter) error {
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailWaters1, err := insertCommsEmailContactEmailAddressNotifyEmailWaters0(ctx, exec, related, commsEmailContact0)
publicreportNotifyEmailNuisanceOlds1, err := insertCommsEmailContactEmailAddressNotifyEmailNuisanceOlds0(ctx, exec, related, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailWaters = append(commsEmailContact0.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWaters1...)
commsEmailContact0.R.EmailAddressNotifyEmailNuisanceOlds = append(commsEmailContact0.R.EmailAddressNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOlds1...)
for _, rel := range publicreportNotifyEmailWaters1 {
for _, rel := range publicreportNotifyEmailNuisanceOlds1 {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWater) error {
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailWaters1 := PublicreportNotifyEmailWaterSlice(related)
publicreportNotifyEmailNuisanceOlds1 := PublicreportNotifyEmailNuisanceOldSlice(related)
_, err = attachCommsEmailContactEmailAddressNotifyEmailWaters0(ctx, exec, len(related), publicreportNotifyEmailWaters1, commsEmailContact0)
_, err = attachCommsEmailContactEmailAddressNotifyEmailNuisanceOlds0(ctx, exec, len(related), publicreportNotifyEmailNuisanceOlds1, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailWaters = append(commsEmailContact0.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWaters1...)
commsEmailContact0.R.EmailAddressNotifyEmailNuisanceOlds = append(commsEmailContact0.R.EmailAddressNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOlds1...)
for _, rel := range related {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func insertCommsEmailContactEmailAddressNotifyEmailWaterOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailWaterOlds1 []*PublicreportNotifyEmailWaterOldSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailWaterOldSlice, error) {
for i := range publicreportNotifyEmailWaterOlds1 {
publicreportNotifyEmailWaterOlds1[i].EmailAddress = omit.From(commsEmailContact0.Address)
}
ret, err := PublicreportNotifyEmailWaterOlds.Insert(bob.ToMods(publicreportNotifyEmailWaterOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailWaterOlds0: %w", err)
}
return ret, nil
}
func attachCommsEmailContactEmailAddressNotifyEmailWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaterOlds1 PublicreportNotifyEmailWaterOldSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailWaterOldSlice, error) {
setter := &PublicreportNotifyEmailWaterOldSetter{
EmailAddress: omit.From(commsEmailContact0.Address),
}
err := publicreportNotifyEmailWaterOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailWaterOlds0: %w", err)
}
return publicreportNotifyEmailWaterOlds1, nil
}
func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailWaterOlds1, err := insertCommsEmailContactEmailAddressNotifyEmailWaterOlds0(ctx, exec, related, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailWaterOlds = append(commsEmailContact0.R.EmailAddressNotifyEmailWaterOlds, publicreportNotifyEmailWaterOlds1...)
for _, rel := range publicreportNotifyEmailWaterOlds1 {
rel.R.EmailAddressEmailContact = commsEmailContact0
}
return nil
}
func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyEmailWaterOlds1 := PublicreportNotifyEmailWaterOldSlice(related)
_, err = attachCommsEmailContactEmailAddressNotifyEmailWaterOlds0(ctx, exec, len(related), publicreportNotifyEmailWaterOlds1, commsEmailContact0)
if err != nil {
return err
}
commsEmailContact0.R.EmailAddressNotifyEmailWaterOlds = append(commsEmailContact0.R.EmailAddressNotifyEmailWaterOlds, publicreportNotifyEmailWaterOlds1...)
for _, rel := range related {
rel.R.EmailAddressEmailContact = commsEmailContact0
@ -934,13 +1027,13 @@ func (o *CommsEmailContact) Preload(name string, retrieved any) error {
}
}
return nil
case "EmailAddressNotifyEmailNuisances":
rels, ok := retrieved.(PublicreportNotifyEmailNuisanceSlice)
case "EmailAddressNotifyEmails":
rels, ok := retrieved.(PublicreportNotifyEmailSlice)
if !ok {
return fmt.Errorf("commsEmailContact cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressNotifyEmailNuisances = rels
o.R.EmailAddressNotifyEmails = rels
for _, rel := range rels {
if rel != nil {
@ -948,13 +1041,27 @@ func (o *CommsEmailContact) Preload(name string, retrieved any) error {
}
}
return nil
case "EmailAddressNotifyEmailWaters":
rels, ok := retrieved.(PublicreportNotifyEmailWaterSlice)
case "EmailAddressNotifyEmailNuisanceOlds":
rels, ok := retrieved.(PublicreportNotifyEmailNuisanceOldSlice)
if !ok {
return fmt.Errorf("commsEmailContact cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressNotifyEmailWaters = rels
o.R.EmailAddressNotifyEmailNuisanceOlds = rels
for _, rel := range rels {
if rel != nil {
rel.R.EmailAddressEmailContact = o
}
}
return nil
case "EmailAddressNotifyEmailWaterOlds":
rels, ok := retrieved.(PublicreportNotifyEmailWaterOldSlice)
if !ok {
return fmt.Errorf("commsEmailContact cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressNotifyEmailWaterOlds = rels
for _, rel := range rels {
if rel != nil {
@ -988,11 +1095,12 @@ 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]
EmailAddressNotifyEmailNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressSubscribeEmails 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]
EmailAddressNotifyEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailNuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressNotifyEmailWaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
EmailAddressSubscribeEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsEmailContactThenLoader[Q orm.Loadable]() commsEmailContactThenLoader[Q] {
@ -1002,11 +1110,14 @@ 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 EmailAddressNotifyEmailsLoadInterface interface {
LoadEmailAddressNotifyEmails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressNotifyEmailWatersLoadInterface interface {
LoadEmailAddressNotifyEmailWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type EmailAddressNotifyEmailNuisanceOldsLoadInterface interface {
LoadEmailAddressNotifyEmailNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressNotifyEmailWaterOldsLoadInterface interface {
LoadEmailAddressNotifyEmailWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type EmailAddressSubscribeEmailsLoadInterface interface {
LoadEmailAddressSubscribeEmails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
@ -1025,16 +1136,22 @@ 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...)
EmailAddressNotifyEmails: thenLoadBuilder[Q](
"EmailAddressNotifyEmails",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressNotifyEmails(ctx, exec, mods...)
},
),
EmailAddressNotifyEmailWaters: thenLoadBuilder[Q](
"EmailAddressNotifyEmailWaters",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailWatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressNotifyEmailWaters(ctx, exec, mods...)
EmailAddressNotifyEmailNuisanceOlds: thenLoadBuilder[Q](
"EmailAddressNotifyEmailNuisanceOlds",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailNuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressNotifyEmailNuisanceOlds(ctx, exec, mods...)
},
),
EmailAddressNotifyEmailWaterOlds: thenLoadBuilder[Q](
"EmailAddressNotifyEmailWaterOlds",
func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailWaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadEmailAddressNotifyEmailWaterOlds(ctx, exec, mods...)
},
),
EmailAddressSubscribeEmails: thenLoadBuilder[Q](
@ -1188,16 +1305,16 @@ 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 {
// LoadEmailAddressNotifyEmails loads the commsEmailContact's EmailAddressNotifyEmails into the .R struct
func (o *CommsEmailContact) LoadEmailAddressNotifyEmails(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressNotifyEmailNuisances = nil
o.R.EmailAddressNotifyEmails = nil
related, err := o.EmailAddressNotifyEmailNuisances(mods...).All(ctx, exec)
related, err := o.EmailAddressNotifyEmails(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1206,17 +1323,17 @@ func (o *CommsEmailContact) LoadEmailAddressNotifyEmailNuisances(ctx context.Con
rel.R.EmailAddressEmailContact = o
}
o.R.EmailAddressNotifyEmailNuisances = related
o.R.EmailAddressNotifyEmails = 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 {
// LoadEmailAddressNotifyEmails loads the commsEmailContact's EmailAddressNotifyEmails into the .R struct
func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmails(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)
publicreportNotifyEmails, err := os.EmailAddressNotifyEmails(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1226,7 +1343,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailNuisances(ctx contex
continue
}
o.R.EmailAddressNotifyEmailNuisances = nil
o.R.EmailAddressNotifyEmails = nil
}
for _, o := range os {
@ -1234,7 +1351,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailNuisances(ctx contex
continue
}
for _, rel := range publicreportNotifyEmailNuisances {
for _, rel := range publicreportNotifyEmails {
if !(o.Address == rel.EmailAddress) {
continue
@ -1242,23 +1359,23 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailNuisances(ctx contex
rel.R.EmailAddressEmailContact = o
o.R.EmailAddressNotifyEmailNuisances = append(o.R.EmailAddressNotifyEmailNuisances, rel)
o.R.EmailAddressNotifyEmails = append(o.R.EmailAddressNotifyEmails, rel)
}
}
return nil
}
// LoadEmailAddressNotifyEmailWaters loads the commsEmailContact's EmailAddressNotifyEmailWaters into the .R struct
func (o *CommsEmailContact) LoadEmailAddressNotifyEmailWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadEmailAddressNotifyEmailNuisanceOlds loads the commsEmailContact's EmailAddressNotifyEmailNuisanceOlds into the .R struct
func (o *CommsEmailContact) LoadEmailAddressNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressNotifyEmailWaters = nil
o.R.EmailAddressNotifyEmailNuisanceOlds = nil
related, err := o.EmailAddressNotifyEmailWaters(mods...).All(ctx, exec)
related, err := o.EmailAddressNotifyEmailNuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1267,17 +1384,17 @@ func (o *CommsEmailContact) LoadEmailAddressNotifyEmailWaters(ctx context.Contex
rel.R.EmailAddressEmailContact = o
}
o.R.EmailAddressNotifyEmailWaters = related
o.R.EmailAddressNotifyEmailNuisanceOlds = related
return nil
}
// LoadEmailAddressNotifyEmailWaters loads the commsEmailContact's EmailAddressNotifyEmailWaters into the .R struct
func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadEmailAddressNotifyEmailNuisanceOlds loads the commsEmailContact's EmailAddressNotifyEmailNuisanceOlds into the .R struct
func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyEmailWaters, err := os.EmailAddressNotifyEmailWaters(mods...).All(ctx, exec)
publicreportNotifyEmailNuisanceOlds, err := os.EmailAddressNotifyEmailNuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1287,7 +1404,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailWaters(ctx context.C
continue
}
o.R.EmailAddressNotifyEmailWaters = nil
o.R.EmailAddressNotifyEmailNuisanceOlds = nil
}
for _, o := range os {
@ -1295,7 +1412,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailWaters(ctx context.C
continue
}
for _, rel := range publicreportNotifyEmailWaters {
for _, rel := range publicreportNotifyEmailNuisanceOlds {
if !(o.Address == rel.EmailAddress) {
continue
@ -1303,7 +1420,68 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailWaters(ctx context.C
rel.R.EmailAddressEmailContact = o
o.R.EmailAddressNotifyEmailWaters = append(o.R.EmailAddressNotifyEmailWaters, rel)
o.R.EmailAddressNotifyEmailNuisanceOlds = append(o.R.EmailAddressNotifyEmailNuisanceOlds, rel)
}
}
return nil
}
// LoadEmailAddressNotifyEmailWaterOlds loads the commsEmailContact's EmailAddressNotifyEmailWaterOlds into the .R struct
func (o *CommsEmailContact) LoadEmailAddressNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.EmailAddressNotifyEmailWaterOlds = nil
related, err := o.EmailAddressNotifyEmailWaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.EmailAddressEmailContact = o
}
o.R.EmailAddressNotifyEmailWaterOlds = related
return nil
}
// LoadEmailAddressNotifyEmailWaterOlds loads the commsEmailContact's EmailAddressNotifyEmailWaterOlds into the .R struct
func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyEmailWaterOlds, err := os.EmailAddressNotifyEmailWaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.EmailAddressNotifyEmailWaterOlds = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyEmailWaterOlds {
if !(o.Address == rel.EmailAddress) {
continue
}
rel.R.EmailAddressEmailContact = o
o.R.EmailAddressNotifyEmailWaterOlds = append(o.R.EmailAddressNotifyEmailWaterOlds, rel)
}
}

View file

@ -44,16 +44,17 @@ 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
PropertyOwnerPhoneE164Pools FileuploadPoolSlice // fileupload.pool.pool_property_owner_phone_e164_fkey
ResidentPhoneE164Pools FileuploadPoolSlice // fileupload.pool.pool_resident_phone_e164_fkey
PhoneE164NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey
PhoneE164NotifyPhoneWaters PublicreportNotifyPhoneWaterSlice // publicreport.notify_phone_water.notify_phone_pool_phone_e164_fkey
PhoneE164SubscribePhones PublicreportSubscribePhoneSlice // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
PhoneMobileResidents ResidentSlice // resident.resident_phone_mobile_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
PropertyOwnerPhoneE164Pools FileuploadPoolSlice // fileupload.pool.pool_property_owner_phone_e164_fkey
ResidentPhoneE164Pools FileuploadPoolSlice // fileupload.pool.pool_resident_phone_e164_fkey
PhoneE164NotifyPhones PublicreportNotifyPhoneSlice // publicreport.notify_phone.notify_phone_phone_e164_fkey
PhoneE164NotifyPhoneNuisanceOlds PublicreportNotifyPhoneNuisanceOldSlice // publicreport.notify_phone_nuisance_old.notify_phone_nuisance_phone_e164_fkey
PhoneE164NotifyPhoneWaterOlds PublicreportNotifyPhoneWaterOldSlice // publicreport.notify_phone_water_old.notify_phone_pool_phone_e164_fkey
PhoneE164SubscribePhones PublicreportSubscribePhoneSlice // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
PhoneMobileResidents ResidentSlice // resident.resident_phone_mobile_fkey
}
func buildCommsPhoneColumns(alias string) commsPhoneColumns {
@ -551,14 +552,14 @@ func (os CommsPhoneSlice) ResidentPhoneE164Pools(mods ...bob.Mod[*dialect.Select
)...)
}
// 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))),
// PhoneE164NotifyPhones starts a query for related objects on publicreport.notify_phone
func (o *CommsPhone) PhoneE164NotifyPhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonesQuery {
return PublicreportNotifyPhones.Query(append(mods,
sm.Where(PublicreportNotifyPhones.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery {
func (os CommsPhoneSlice) PhoneE164NotifyPhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonesQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
@ -570,19 +571,19 @@ func (os CommsPhoneSlice) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportNotifyPhoneNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhoneNuisances.Columns.PhoneE164).OP("IN", PKArgExpr)),
return PublicreportNotifyPhones.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhones.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164NotifyPhoneWaters starts a query for related objects on publicreport.notify_phone_water
func (o *CommsPhone) PhoneE164NotifyPhoneWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWatersQuery {
return PublicreportNotifyPhoneWaters.Query(append(mods,
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
// PhoneE164NotifyPhoneNuisanceOlds starts a query for related objects on publicreport.notify_phone_nuisance_old
func (o *CommsPhone) PhoneE164NotifyPhoneNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisanceOldsQuery {
return PublicreportNotifyPhoneNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhoneWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWatersQuery {
func (os CommsPhoneSlice) PhoneE164NotifyPhoneNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisanceOldsQuery {
pkE164 := make(pgtypes.Array[string], 0, len(os))
for _, o := range os {
if o == nil {
@ -594,8 +595,32 @@ func (os CommsPhoneSlice) PhoneE164NotifyPhoneWaters(mods ...bob.Mod[*dialect.Se
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
))
return PublicreportNotifyPhoneWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhoneWaters.Columns.PhoneE164).OP("IN", PKArgExpr)),
return PublicreportNotifyPhoneNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhoneNuisanceOlds.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164NotifyPhoneWaterOlds starts a query for related objects on publicreport.notify_phone_water_old
func (o *CommsPhone) PhoneE164NotifyPhoneWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWaterOldsQuery {
return PublicreportNotifyPhoneWaterOlds.Query(append(mods,
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.PhoneE164.EQ(psql.Arg(o.E164))),
)...)
}
func (os CommsPhoneSlice) PhoneE164NotifyPhoneWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWaterOldsQuery {
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 PublicreportNotifyPhoneWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNotifyPhoneWaterOlds.Columns.PhoneE164).OP("IN", PKArgExpr)),
)...)
}
@ -1052,66 +1077,66 @@ func (commsPhone0 *CommsPhone) AttachResidentPhoneE164Pools(ctx context.Context,
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)
func insertCommsPhonePhoneE164NotifyPhones0(ctx context.Context, exec bob.Executor, publicreportNotifyPhones1 []*PublicreportNotifyPhoneSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneSlice, error) {
for i := range publicreportNotifyPhones1 {
publicreportNotifyPhones1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhoneNuisances.Insert(bob.ToMods(publicreportNotifyPhoneNuisances1...)).All(ctx, exec)
ret, err := PublicreportNotifyPhones.Insert(bob.ToMods(publicreportNotifyPhones1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneNuisances0: %w", err)
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhones0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisances1 PublicreportNotifyPhoneNuisanceSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceSlice, error) {
setter := &PublicreportNotifyPhoneNuisanceSetter{
func attachCommsPhonePhoneE164NotifyPhones0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhones1 PublicreportNotifyPhoneSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneSlice, error) {
setter := &PublicreportNotifyPhoneSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhoneNuisances1.UpdateAll(ctx, exec, *setter)
err := publicreportNotifyPhones1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneNuisances0: %w", err)
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhones0: %w", err)
}
return publicreportNotifyPhoneNuisances1, nil
return publicreportNotifyPhones1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceSetter) error {
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhones(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneNuisances1, err := insertCommsPhonePhoneE164NotifyPhoneNuisances0(ctx, exec, related, commsPhone0)
publicreportNotifyPhones1, err := insertCommsPhonePhoneE164NotifyPhones0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneNuisances = append(commsPhone0.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...)
commsPhone0.R.PhoneE164NotifyPhones = append(commsPhone0.R.PhoneE164NotifyPhones, publicreportNotifyPhones1...)
for _, rel := range publicreportNotifyPhoneNuisances1 {
for _, rel := range publicreportNotifyPhones1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisance) error {
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhones(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhone) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneNuisances1 := PublicreportNotifyPhoneNuisanceSlice(related)
publicreportNotifyPhones1 := PublicreportNotifyPhoneSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhoneNuisances0(ctx, exec, len(related), publicreportNotifyPhoneNuisances1, commsPhone0)
_, err = attachCommsPhonePhoneE164NotifyPhones0(ctx, exec, len(related), publicreportNotifyPhones1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneNuisances = append(commsPhone0.R.PhoneE164NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...)
commsPhone0.R.PhoneE164NotifyPhones = append(commsPhone0.R.PhoneE164NotifyPhones, publicreportNotifyPhones1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
@ -1120,66 +1145,134 @@ func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneNuisances(ctx context.C
return nil
}
func insertCommsPhonePhoneE164NotifyPhoneWaters0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneWaters1 []*PublicreportNotifyPhoneWaterSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneWaterSlice, error) {
for i := range publicreportNotifyPhoneWaters1 {
publicreportNotifyPhoneWaters1[i].PhoneE164 = omit.From(commsPhone0.E164)
func insertCommsPhonePhoneE164NotifyPhoneNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneNuisanceOlds1 []*PublicreportNotifyPhoneNuisanceOldSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceOldSlice, error) {
for i := range publicreportNotifyPhoneNuisanceOlds1 {
publicreportNotifyPhoneNuisanceOlds1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhoneWaters.Insert(bob.ToMods(publicreportNotifyPhoneWaters1...)).All(ctx, exec)
ret, err := PublicreportNotifyPhoneNuisanceOlds.Insert(bob.ToMods(publicreportNotifyPhoneNuisanceOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneWaters0: %w", err)
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneNuisanceOlds0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhoneWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaters1 PublicreportNotifyPhoneWaterSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneWaterSlice, error) {
setter := &PublicreportNotifyPhoneWaterSetter{
func attachCommsPhonePhoneE164NotifyPhoneNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisanceOlds1 PublicreportNotifyPhoneNuisanceOldSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneNuisanceOldSlice, error) {
setter := &PublicreportNotifyPhoneNuisanceOldSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhoneWaters1.UpdateAll(ctx, exec, *setter)
err := publicreportNotifyPhoneNuisanceOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneWaters0: %w", err)
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneNuisanceOlds0: %w", err)
}
return publicreportNotifyPhoneWaters1, nil
return publicreportNotifyPhoneNuisanceOlds1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterSetter) error {
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneWaters1, err := insertCommsPhonePhoneE164NotifyPhoneWaters0(ctx, exec, related, commsPhone0)
publicreportNotifyPhoneNuisanceOlds1, err := insertCommsPhonePhoneE164NotifyPhoneNuisanceOlds0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneWaters = append(commsPhone0.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWaters1...)
commsPhone0.R.PhoneE164NotifyPhoneNuisanceOlds = append(commsPhone0.R.PhoneE164NotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOlds1...)
for _, rel := range publicreportNotifyPhoneWaters1 {
for _, rel := range publicreportNotifyPhoneNuisanceOlds1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWater) error {
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneWaters1 := PublicreportNotifyPhoneWaterSlice(related)
publicreportNotifyPhoneNuisanceOlds1 := PublicreportNotifyPhoneNuisanceOldSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhoneWaters0(ctx, exec, len(related), publicreportNotifyPhoneWaters1, commsPhone0)
_, err = attachCommsPhonePhoneE164NotifyPhoneNuisanceOlds0(ctx, exec, len(related), publicreportNotifyPhoneNuisanceOlds1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneWaters = append(commsPhone0.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWaters1...)
commsPhone0.R.PhoneE164NotifyPhoneNuisanceOlds = append(commsPhone0.R.PhoneE164NotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOlds1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func insertCommsPhonePhoneE164NotifyPhoneWaterOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneWaterOlds1 []*PublicreportNotifyPhoneWaterOldSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneWaterOldSlice, error) {
for i := range publicreportNotifyPhoneWaterOlds1 {
publicreportNotifyPhoneWaterOlds1[i].PhoneE164 = omit.From(commsPhone0.E164)
}
ret, err := PublicreportNotifyPhoneWaterOlds.Insert(bob.ToMods(publicreportNotifyPhoneWaterOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneWaterOlds0: %w", err)
}
return ret, nil
}
func attachCommsPhonePhoneE164NotifyPhoneWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaterOlds1 PublicreportNotifyPhoneWaterOldSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneWaterOldSlice, error) {
setter := &PublicreportNotifyPhoneWaterOldSetter{
PhoneE164: omit.From(commsPhone0.E164),
}
err := publicreportNotifyPhoneWaterOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneWaterOlds0: %w", err)
}
return publicreportNotifyPhoneWaterOlds1, nil
}
func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneWaterOlds1, err := insertCommsPhonePhoneE164NotifyPhoneWaterOlds0(ctx, exec, related, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneWaterOlds = append(commsPhone0.R.PhoneE164NotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOlds1...)
for _, rel := range publicreportNotifyPhoneWaterOlds1 {
rel.R.PhoneE164Phone = commsPhone0
}
return nil
}
func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNotifyPhoneWaterOlds1 := PublicreportNotifyPhoneWaterOldSlice(related)
_, err = attachCommsPhonePhoneE164NotifyPhoneWaterOlds0(ctx, exec, len(related), publicreportNotifyPhoneWaterOlds1, commsPhone0)
if err != nil {
return err
}
commsPhone0.R.PhoneE164NotifyPhoneWaterOlds = append(commsPhone0.R.PhoneE164NotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOlds1...)
for _, rel := range related {
rel.R.PhoneE164Phone = commsPhone0
@ -1432,13 +1525,13 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
}
}
return nil
case "PhoneE164NotifyPhoneNuisances":
rels, ok := retrieved.(PublicreportNotifyPhoneNuisanceSlice)
case "PhoneE164NotifyPhones":
rels, ok := retrieved.(PublicreportNotifyPhoneSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhoneNuisances = rels
o.R.PhoneE164NotifyPhones = rels
for _, rel := range rels {
if rel != nil {
@ -1446,13 +1539,27 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
}
}
return nil
case "PhoneE164NotifyPhoneWaters":
rels, ok := retrieved.(PublicreportNotifyPhoneWaterSlice)
case "PhoneE164NotifyPhoneNuisanceOlds":
rels, ok := retrieved.(PublicreportNotifyPhoneNuisanceOldSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhoneWaters = rels
o.R.PhoneE164NotifyPhoneNuisanceOlds = rels
for _, rel := range rels {
if rel != nil {
rel.R.PhoneE164Phone = o
}
}
return nil
case "PhoneE164NotifyPhoneWaterOlds":
rels, ok := retrieved.(PublicreportNotifyPhoneWaterOldSlice)
if !ok {
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164NotifyPhoneWaterOlds = rels
for _, rel := range rels {
if rel != nil {
@ -1500,16 +1607,17 @@ 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]
PropertyOwnerPhoneE164Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ResidentPhoneE164Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneMobileResidents 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]
PropertyOwnerPhoneE164Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ResidentPhoneE164Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneNuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164NotifyPhoneWaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
@ -1531,11 +1639,14 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
type ResidentPhoneE164PoolsLoadInterface interface {
LoadResidentPhoneE164Pools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneNuisancesLoadInterface interface {
LoadPhoneE164NotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type PhoneE164NotifyPhonesLoadInterface interface {
LoadPhoneE164NotifyPhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneWatersLoadInterface interface {
LoadPhoneE164NotifyPhoneWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type PhoneE164NotifyPhoneNuisanceOldsLoadInterface interface {
LoadPhoneE164NotifyPhoneNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164NotifyPhoneWaterOldsLoadInterface interface {
LoadPhoneE164NotifyPhoneWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164SubscribePhonesLoadInterface interface {
LoadPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
@ -1581,16 +1692,22 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
return retrieved.LoadResidentPhoneE164Pools(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...)
PhoneE164NotifyPhones: thenLoadBuilder[Q](
"PhoneE164NotifyPhones",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhonesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhones(ctx, exec, mods...)
},
),
PhoneE164NotifyPhoneWaters: thenLoadBuilder[Q](
"PhoneE164NotifyPhoneWaters",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneWatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhoneWaters(ctx, exec, mods...)
PhoneE164NotifyPhoneNuisanceOlds: thenLoadBuilder[Q](
"PhoneE164NotifyPhoneNuisanceOlds",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneNuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhoneNuisanceOlds(ctx, exec, mods...)
},
),
PhoneE164NotifyPhoneWaterOlds: thenLoadBuilder[Q](
"PhoneE164NotifyPhoneWaterOlds",
func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhoneWaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPhoneE164NotifyPhoneWaterOlds(ctx, exec, mods...)
},
),
PhoneE164SubscribePhones: thenLoadBuilder[Q](
@ -2000,16 +2117,16 @@ func (os CommsPhoneSlice) LoadResidentPhoneE164Pools(ctx context.Context, exec b
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 {
// LoadPhoneE164NotifyPhones loads the commsPhone's PhoneE164NotifyPhones into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhoneNuisances = nil
o.R.PhoneE164NotifyPhones = nil
related, err := o.PhoneE164NotifyPhoneNuisances(mods...).All(ctx, exec)
related, err := o.PhoneE164NotifyPhones(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -2018,17 +2135,17 @@ func (o *CommsPhone) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context, exec
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhoneNuisances = related
o.R.PhoneE164NotifyPhones = 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 {
// LoadPhoneE164NotifyPhones loads the commsPhone's PhoneE164NotifyPhones into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhones(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)
publicreportNotifyPhones, err := os.PhoneE164NotifyPhones(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -2038,7 +2155,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context,
continue
}
o.R.PhoneE164NotifyPhoneNuisances = nil
o.R.PhoneE164NotifyPhones = nil
}
for _, o := range os {
@ -2046,7 +2163,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context,
continue
}
for _, rel := range publicreportNotifyPhoneNuisances {
for _, rel := range publicreportNotifyPhones {
if !(o.E164 == rel.PhoneE164) {
continue
@ -2054,23 +2171,23 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context,
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhoneNuisances = append(o.R.PhoneE164NotifyPhoneNuisances, rel)
o.R.PhoneE164NotifyPhones = append(o.R.PhoneE164NotifyPhones, rel)
}
}
return nil
}
// LoadPhoneE164NotifyPhoneWaters loads the commsPhone's PhoneE164NotifyPhoneWaters into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhoneWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadPhoneE164NotifyPhoneNuisanceOlds loads the commsPhone's PhoneE164NotifyPhoneNuisanceOlds into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhoneWaters = nil
o.R.PhoneE164NotifyPhoneNuisanceOlds = nil
related, err := o.PhoneE164NotifyPhoneWaters(mods...).All(ctx, exec)
related, err := o.PhoneE164NotifyPhoneNuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -2079,17 +2196,17 @@ func (o *CommsPhone) LoadPhoneE164NotifyPhoneWaters(ctx context.Context, exec bo
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhoneWaters = related
o.R.PhoneE164NotifyPhoneNuisanceOlds = related
return nil
}
// LoadPhoneE164NotifyPhoneWaters loads the commsPhone's PhoneE164NotifyPhoneWaters into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadPhoneE164NotifyPhoneNuisanceOlds loads the commsPhone's PhoneE164NotifyPhoneNuisanceOlds into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhoneWaters, err := os.PhoneE164NotifyPhoneWaters(mods...).All(ctx, exec)
publicreportNotifyPhoneNuisanceOlds, err := os.PhoneE164NotifyPhoneNuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -2099,7 +2216,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneWaters(ctx context.Context, ex
continue
}
o.R.PhoneE164NotifyPhoneWaters = nil
o.R.PhoneE164NotifyPhoneNuisanceOlds = nil
}
for _, o := range os {
@ -2107,7 +2224,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneWaters(ctx context.Context, ex
continue
}
for _, rel := range publicreportNotifyPhoneWaters {
for _, rel := range publicreportNotifyPhoneNuisanceOlds {
if !(o.E164 == rel.PhoneE164) {
continue
@ -2115,7 +2232,68 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneWaters(ctx context.Context, ex
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhoneWaters = append(o.R.PhoneE164NotifyPhoneWaters, rel)
o.R.PhoneE164NotifyPhoneNuisanceOlds = append(o.R.PhoneE164NotifyPhoneNuisanceOlds, rel)
}
}
return nil
}
// LoadPhoneE164NotifyPhoneWaterOlds loads the commsPhone's PhoneE164NotifyPhoneWaterOlds into the .R struct
func (o *CommsPhone) LoadPhoneE164NotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PhoneE164NotifyPhoneWaterOlds = nil
related, err := o.PhoneE164NotifyPhoneWaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.PhoneE164Phone = o
}
o.R.PhoneE164NotifyPhoneWaterOlds = related
return nil
}
// LoadPhoneE164NotifyPhoneWaterOlds loads the commsPhone's PhoneE164NotifyPhoneWaterOlds into the .R struct
func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNotifyPhoneWaterOlds, err := os.PhoneE164NotifyPhoneWaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.PhoneE164NotifyPhoneWaterOlds = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNotifyPhoneWaterOlds {
if !(o.E164 == rel.PhoneE164) {
continue
}
rel.R.PhoneE164Phone = o
o.R.PhoneE164NotifyPhoneWaterOlds = append(o.R.PhoneE164NotifyPhoneWaterOlds, rel)
}
}

View file

@ -33,6 +33,8 @@ type CommsTextJob struct {
Type enums.CommsTextjobtype `db:"type_" `
Source enums.CommsTextjobsource `db:"source" `
Completed null.Val[time.Time] `db:"completed" `
CreatorID null.Val[int32] `db:"creator_id" `
ReportID null.Val[int32] `db:"report_id" `
R commsTextJobR `db:"-" `
}
@ -49,13 +51,15 @@ type CommsTextJobsQuery = *psql.ViewQuery[*CommsTextJob, CommsTextJobSlice]
// commsTextJobR is where relationships are stored.
type commsTextJobR struct {
DestinationPhone *CommsPhone // comms.text_job.text_job_destination_fkey
CreatorUser *User // comms.text_job.text_job_creator_id_fkey
DestinationPhone *CommsPhone // comms.text_job.text_job_destination_fkey
Report *PublicreportReport // comms.text_job.text_job_report_id_fkey
}
func buildCommsTextJobColumns(alias string) commsTextJobColumns {
return commsTextJobColumns{
ColumnsExpr: expr.NewColumnsExpr(
"content", "created", "destination", "id", "type_", "source", "completed",
"content", "created", "destination", "id", "type_", "source", "completed", "creator_id", "report_id",
).WithParent("comms.text_job"),
tableAlias: alias,
Content: psql.Quote(alias, "content"),
@ -65,6 +69,8 @@ func buildCommsTextJobColumns(alias string) commsTextJobColumns {
Type: psql.Quote(alias, "type_"),
Source: psql.Quote(alias, "source"),
Completed: psql.Quote(alias, "completed"),
CreatorID: psql.Quote(alias, "creator_id"),
ReportID: psql.Quote(alias, "report_id"),
}
}
@ -78,6 +84,8 @@ type commsTextJobColumns struct {
Type psql.Expression
Source psql.Expression
Completed psql.Expression
CreatorID psql.Expression
ReportID psql.Expression
}
func (c commsTextJobColumns) Alias() string {
@ -99,10 +107,12 @@ type CommsTextJobSetter struct {
Type omit.Val[enums.CommsTextjobtype] `db:"type_" `
Source omit.Val[enums.CommsTextjobsource] `db:"source" `
Completed omitnull.Val[time.Time] `db:"completed" `
CreatorID omitnull.Val[int32] `db:"creator_id" `
ReportID omitnull.Val[int32] `db:"report_id" `
}
func (s CommsTextJobSetter) SetColumns() []string {
vals := make([]string, 0, 7)
vals := make([]string, 0, 9)
if s.Content.IsValue() {
vals = append(vals, "content")
}
@ -124,6 +134,12 @@ func (s CommsTextJobSetter) SetColumns() []string {
if !s.Completed.IsUnset() {
vals = append(vals, "completed")
}
if !s.CreatorID.IsUnset() {
vals = append(vals, "creator_id")
}
if !s.ReportID.IsUnset() {
vals = append(vals, "report_id")
}
return vals
}
@ -149,6 +165,12 @@ func (s CommsTextJobSetter) Overwrite(t *CommsTextJob) {
if !s.Completed.IsUnset() {
t.Completed = s.Completed.MustGetNull()
}
if !s.CreatorID.IsUnset() {
t.CreatorID = s.CreatorID.MustGetNull()
}
if !s.ReportID.IsUnset() {
t.ReportID = s.ReportID.MustGetNull()
}
}
func (s *CommsTextJobSetter) Apply(q *dialect.InsertQuery) {
@ -157,7 +179,7 @@ func (s *CommsTextJobSetter) 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, 7)
vals := make([]bob.Expression, 9)
if s.Content.IsValue() {
vals[0] = psql.Arg(s.Content.MustGet())
} else {
@ -200,6 +222,18 @@ func (s *CommsTextJobSetter) Apply(q *dialect.InsertQuery) {
vals[6] = psql.Raw("DEFAULT")
}
if !s.CreatorID.IsUnset() {
vals[7] = psql.Arg(s.CreatorID.MustGetNull())
} else {
vals[7] = psql.Raw("DEFAULT")
}
if !s.ReportID.IsUnset() {
vals[8] = psql.Arg(s.ReportID.MustGetNull())
} else {
vals[8] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
@ -209,7 +243,7 @@ func (s CommsTextJobSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
}
func (s CommsTextJobSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 7)
exprs := make([]bob.Expression, 0, 9)
if s.Content.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -260,6 +294,20 @@ func (s CommsTextJobSetter) Expressions(prefix ...string) []bob.Expression {
}})
}
if !s.CreatorID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "creator_id")...),
psql.Arg(s.CreatorID),
}})
}
if !s.ReportID.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "report_id")...),
psql.Arg(s.ReportID),
}})
}
return exprs
}
@ -486,6 +534,30 @@ func (o CommsTextJobSlice) ReloadAll(ctx context.Context, exec bob.Executor) err
return nil
}
// CreatorUser starts a query for related objects on user_
func (o *CommsTextJob) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.CreatorID))),
)...)
}
func (os CommsTextJobSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkCreatorID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkCreatorID = append(pkCreatorID, o.CreatorID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkCreatorID), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// DestinationPhone starts a query for related objects on comms.phone
func (o *CommsTextJob) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
@ -510,6 +582,78 @@ func (os CommsTextJobSlice) DestinationPhone(mods ...bob.Mod[*dialect.SelectQuer
)...)
}
// Report starts a query for related objects on publicreport.report
func (o *CommsTextJob) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))),
)...)
}
func (os CommsTextJobSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkReportID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkReportID = append(pkReportID, o.ReportID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")),
))
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachCommsTextJobCreatorUser0(ctx context.Context, exec bob.Executor, count int, commsTextJob0 *CommsTextJob, user1 *User) (*CommsTextJob, error) {
setter := &CommsTextJobSetter{
CreatorID: omitnull.From(user1.ID),
}
err := commsTextJob0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommsTextJobCreatorUser0: %w", err)
}
return commsTextJob0, nil
}
func (commsTextJob0 *CommsTextJob) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommsTextJobCreatorUser0(ctx, exec, 1, commsTextJob0, user1)
if err != nil {
return err
}
commsTextJob0.R.CreatorUser = user1
user1.R.CreatorTextJobs = append(user1.R.CreatorTextJobs, commsTextJob0)
return nil
}
func (commsTextJob0 *CommsTextJob) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachCommsTextJobCreatorUser0(ctx, exec, 1, commsTextJob0, user1)
if err != nil {
return err
}
commsTextJob0.R.CreatorUser = user1
user1.R.CreatorTextJobs = append(user1.R.CreatorTextJobs, commsTextJob0)
return nil
}
func attachCommsTextJobDestinationPhone0(ctx context.Context, exec bob.Executor, count int, commsTextJob0 *CommsTextJob, commsPhone1 *CommsPhone) (*CommsTextJob, error) {
setter := &CommsTextJobSetter{
Destination: omit.From(commsPhone1.E164),
@ -558,6 +702,54 @@ func (commsTextJob0 *CommsTextJob) AttachDestinationPhone(ctx context.Context, e
return nil
}
func attachCommsTextJobReport0(ctx context.Context, exec bob.Executor, count int, commsTextJob0 *CommsTextJob, publicreportReport1 *PublicreportReport) (*CommsTextJob, error) {
setter := &CommsTextJobSetter{
ReportID: omitnull.From(publicreportReport1.ID),
}
err := commsTextJob0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachCommsTextJobReport0: %w", err)
}
return commsTextJob0, nil
}
func (commsTextJob0 *CommsTextJob) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error {
var err error
publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachCommsTextJobReport0(ctx, exec, 1, commsTextJob0, publicreportReport1)
if err != nil {
return err
}
commsTextJob0.R.Report = publicreportReport1
publicreportReport1.R.TextJobs = append(publicreportReport1.R.TextJobs, commsTextJob0)
return nil
}
func (commsTextJob0 *CommsTextJob) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error {
var err error
_, err = attachCommsTextJobReport0(ctx, exec, 1, commsTextJob0, publicreportReport1)
if err != nil {
return err
}
commsTextJob0.R.Report = publicreportReport1
publicreportReport1.R.TextJobs = append(publicreportReport1.R.TextJobs, commsTextJob0)
return nil
}
type commsTextJobWhere[Q psql.Filterable] struct {
Content psql.WhereMod[Q, string]
Created psql.WhereMod[Q, time.Time]
@ -566,6 +758,8 @@ type commsTextJobWhere[Q psql.Filterable] struct {
Type psql.WhereMod[Q, enums.CommsTextjobtype]
Source psql.WhereMod[Q, enums.CommsTextjobsource]
Completed psql.WhereNullMod[Q, time.Time]
CreatorID psql.WhereNullMod[Q, int32]
ReportID psql.WhereNullMod[Q, int32]
}
func (commsTextJobWhere[Q]) AliasedAs(alias string) commsTextJobWhere[Q] {
@ -581,6 +775,8 @@ func buildCommsTextJobWhere[Q psql.Filterable](cols commsTextJobColumns) commsTe
Type: psql.Where[Q, enums.CommsTextjobtype](cols.Type),
Source: psql.Where[Q, enums.CommsTextjobsource](cols.Source),
Completed: psql.WhereNull[Q, time.Time](cols.Completed),
CreatorID: psql.WhereNull[Q, int32](cols.CreatorID),
ReportID: psql.WhereNull[Q, int32](cols.ReportID),
}
}
@ -590,6 +786,18 @@ func (o *CommsTextJob) Preload(name string, retrieved any) error {
}
switch name {
case "CreatorUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("commsTextJob cannot load %T as %q", retrieved, name)
}
o.R.CreatorUser = rel
if rel != nil {
rel.R.CreatorTextJobs = CommsTextJobSlice{o}
}
return nil
case "DestinationPhone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
@ -602,17 +810,44 @@ func (o *CommsTextJob) Preload(name string, retrieved any) error {
rel.R.DestinationTextJobs = CommsTextJobSlice{o}
}
return nil
case "Report":
rel, ok := retrieved.(*PublicreportReport)
if !ok {
return fmt.Errorf("commsTextJob cannot load %T as %q", retrieved, name)
}
o.R.Report = rel
if rel != nil {
rel.R.TextJobs = CommsTextJobSlice{o}
}
return nil
default:
return fmt.Errorf("commsTextJob has no relationship %q", name)
}
}
type commsTextJobPreloader struct {
CreatorUser func(...psql.PreloadOption) psql.Preloader
DestinationPhone func(...psql.PreloadOption) psql.Preloader
Report func(...psql.PreloadOption) psql.Preloader
}
func buildCommsTextJobPreloader() commsTextJobPreloader {
return commsTextJobPreloader{
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "CreatorUser",
Sides: []psql.PreloadSide{
{
From: CommsTextJobs,
To: Users,
FromColumns: []string{"creator_id"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
DestinationPhone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "DestinationPhone",
@ -626,28 +861,116 @@ func buildCommsTextJobPreloader() commsTextJobPreloader {
},
}, CommsPhones.Columns.Names(), opts...)
},
Report: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{
Name: "Report",
Sides: []psql.PreloadSide{
{
From: CommsTextJobs,
To: PublicreportReports,
FromColumns: []string{"report_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportReports.Columns.Names(), opts...)
},
}
}
type commsTextJobThenLoader[Q orm.Loadable] struct {
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
DestinationPhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsTextJobThenLoader[Q orm.Loadable]() commsTextJobThenLoader[Q] {
type CreatorUserLoadInterface interface {
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type DestinationPhoneLoadInterface interface {
LoadDestinationPhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReportLoadInterface interface {
LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsTextJobThenLoader[Q]{
CreatorUser: thenLoadBuilder[Q](
"CreatorUser",
func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCreatorUser(ctx, exec, mods...)
},
),
DestinationPhone: thenLoadBuilder[Q](
"DestinationPhone",
func(ctx context.Context, exec bob.Executor, retrieved DestinationPhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadDestinationPhone(ctx, exec, mods...)
},
),
Report: thenLoadBuilder[Q](
"Report",
func(ctx context.Context, exec bob.Executor, retrieved ReportLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReport(ctx, exec, mods...)
},
),
}
}
// LoadCreatorUser loads the commsTextJob's CreatorUser into the .R struct
func (o *CommsTextJob) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.CreatorUser = nil
related, err := o.CreatorUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.CreatorTextJobs = CommsTextJobSlice{o}
o.R.CreatorUser = related
return nil
}
// LoadCreatorUser loads the commsTextJob's CreatorUser into the .R struct
func (os CommsTextJobSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.CreatorUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !o.CreatorID.IsValue() {
continue
}
if !(o.CreatorID.IsValue() && o.CreatorID.MustGet() == rel.ID) {
continue
}
rel.R.CreatorTextJobs = append(rel.R.CreatorTextJobs, o)
o.R.CreatorUser = rel
break
}
}
return nil
}
// LoadDestinationPhone loads the commsTextJob's DestinationPhone into the .R struct
func (o *CommsTextJob) LoadDestinationPhone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
@ -699,3 +1022,58 @@ func (os CommsTextJobSlice) LoadDestinationPhone(ctx context.Context, exec bob.E
return nil
}
// LoadReport loads the commsTextJob's Report into the .R struct
func (o *CommsTextJob) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Report = nil
related, err := o.Report(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.TextJobs = CommsTextJobSlice{o}
o.R.Report = related
return nil
}
// LoadReport loads the commsTextJob's Report into the .R struct
func (os CommsTextJobSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportReports, err := os.Report(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportReports {
if !o.ReportID.IsValue() {
continue
}
if !(o.ReportID.IsValue() && o.ReportID.MustGet() == rel.ID) {
continue
}
rel.R.TextJobs = append(rel.R.TextJobs, o)
o.R.Report = rel
break
}
}
return nil
}

View file

@ -52,8 +52,9 @@ type CommsTextLogsQuery = *psql.ViewQuery[*CommsTextLog, CommsTextLogSlice]
// commsTextLogR is where relationships are stored.
type commsTextLogR struct {
DestinationPhone *CommsPhone // comms.text_log.text_log_destination_fkey
SourcePhone *CommsPhone // comms.text_log.text_log_source_fkey
DestinationPhone *CommsPhone // comms.text_log.text_log_destination_fkey
SourcePhone *CommsPhone // comms.text_log.text_log_source_fkey
ReportTexts ReportTextSlice // report_text.report_text_text_log_id_fkey
}
func buildCommsTextLogColumns(alias string) commsTextLogColumns {
@ -604,6 +605,30 @@ func (os CommsTextLogSlice) SourcePhone(mods ...bob.Mod[*dialect.SelectQuery]) C
)...)
}
// ReportTexts starts a query for related objects on report_text
func (o *CommsTextLog) ReportTexts(mods ...bob.Mod[*dialect.SelectQuery]) ReportTextsQuery {
return ReportTexts.Query(append(mods,
sm.Where(ReportTexts.Columns.TextLogID.EQ(psql.Arg(o.ID))),
)...)
}
func (os CommsTextLogSlice) ReportTexts(mods ...bob.Mod[*dialect.SelectQuery]) ReportTextsQuery {
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 ReportTexts.Query(append(mods,
sm.Where(psql.Group(ReportTexts.Columns.TextLogID).OP("IN", PKArgExpr)),
)...)
}
func attachCommsTextLogDestinationPhone0(ctx context.Context, exec bob.Executor, count int, commsTextLog0 *CommsTextLog, commsPhone1 *CommsPhone) (*CommsTextLog, error) {
setter := &CommsTextLogSetter{
Destination: omit.From(commsPhone1.E164),
@ -700,6 +725,74 @@ func (commsTextLog0 *CommsTextLog) AttachSourcePhone(ctx context.Context, exec b
return nil
}
func insertCommsTextLogReportTexts0(ctx context.Context, exec bob.Executor, reportTexts1 []*ReportTextSetter, commsTextLog0 *CommsTextLog) (ReportTextSlice, error) {
for i := range reportTexts1 {
reportTexts1[i].TextLogID = omit.From(commsTextLog0.ID)
}
ret, err := ReportTexts.Insert(bob.ToMods(reportTexts1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertCommsTextLogReportTexts0: %w", err)
}
return ret, nil
}
func attachCommsTextLogReportTexts0(ctx context.Context, exec bob.Executor, count int, reportTexts1 ReportTextSlice, commsTextLog0 *CommsTextLog) (ReportTextSlice, error) {
setter := &ReportTextSetter{
TextLogID: omit.From(commsTextLog0.ID),
}
err := reportTexts1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachCommsTextLogReportTexts0: %w", err)
}
return reportTexts1, nil
}
func (commsTextLog0 *CommsTextLog) InsertReportTexts(ctx context.Context, exec bob.Executor, related ...*ReportTextSetter) error {
if len(related) == 0 {
return nil
}
var err error
reportTexts1, err := insertCommsTextLogReportTexts0(ctx, exec, related, commsTextLog0)
if err != nil {
return err
}
commsTextLog0.R.ReportTexts = append(commsTextLog0.R.ReportTexts, reportTexts1...)
for _, rel := range reportTexts1 {
rel.R.TextLog = commsTextLog0
}
return nil
}
func (commsTextLog0 *CommsTextLog) AttachReportTexts(ctx context.Context, exec bob.Executor, related ...*ReportText) error {
if len(related) == 0 {
return nil
}
var err error
reportTexts1 := ReportTextSlice(related)
_, err = attachCommsTextLogReportTexts0(ctx, exec, len(related), reportTexts1, commsTextLog0)
if err != nil {
return err
}
commsTextLog0.R.ReportTexts = append(commsTextLog0.R.ReportTexts, reportTexts1...)
for _, rel := range related {
rel.R.TextLog = commsTextLog0
}
return nil
}
type commsTextLogWhere[Q psql.Filterable] struct {
Content psql.WhereMod[Q, string]
Created psql.WhereMod[Q, time.Time]
@ -762,6 +855,20 @@ func (o *CommsTextLog) Preload(name string, retrieved any) error {
rel.R.SourceTextLogs = CommsTextLogSlice{o}
}
return nil
case "ReportTexts":
rels, ok := retrieved.(ReportTextSlice)
if !ok {
return fmt.Errorf("commsTextLog cannot load %T as %q", retrieved, name)
}
o.R.ReportTexts = rels
for _, rel := range rels {
if rel != nil {
rel.R.TextLog = o
}
}
return nil
default:
return fmt.Errorf("commsTextLog has no relationship %q", name)
}
@ -806,6 +913,7 @@ func buildCommsTextLogPreloader() commsTextLogPreloader {
type commsTextLogThenLoader[Q orm.Loadable] struct {
DestinationPhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
SourcePhone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] {
@ -815,6 +923,9 @@ func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] {
type SourcePhoneLoadInterface interface {
LoadSourcePhone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReportTextsLoadInterface interface {
LoadReportTexts(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return commsTextLogThenLoader[Q]{
DestinationPhone: thenLoadBuilder[Q](
@ -829,6 +940,12 @@ func buildCommsTextLogThenLoader[Q orm.Loadable]() commsTextLogThenLoader[Q] {
return retrieved.LoadSourcePhone(ctx, exec, mods...)
},
),
ReportTexts: thenLoadBuilder[Q](
"ReportTexts",
func(ctx context.Context, exec bob.Executor, retrieved ReportTextsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReportTexts(ctx, exec, mods...)
},
),
}
}
@ -935,3 +1052,64 @@ func (os CommsTextLogSlice) LoadSourcePhone(ctx context.Context, exec bob.Execut
return nil
}
// LoadReportTexts loads the commsTextLog's ReportTexts into the .R struct
func (o *CommsTextLog) LoadReportTexts(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ReportTexts = nil
related, err := o.ReportTexts(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.TextLog = o
}
o.R.ReportTexts = related
return nil
}
// LoadReportTexts loads the commsTextLog's ReportTexts into the .R struct
func (os CommsTextLogSlice) LoadReportTexts(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
reportTexts, err := os.ReportTexts(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.ReportTexts = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range reportTexts {
if !(o.ID == rel.TextLogID) {
continue
}
rel.R.TextLog = o
o.R.ReportTexts = append(o.R.ReportTexts, rel)
}
}
return nil
}

View file

@ -119,8 +119,9 @@ type organizationR struct {
ArcgisAccountAccount *ArcgisAccount // organization.organization_arcgis_account_id_fkey
ArcgisMapServiceServiceMap *ArcgisServiceMap // organization.organization_arcgis_map_service_id_fkey
FieldseekerServiceFeatureItemServiceFeature *ArcgisServiceFeature // organization.organization_fieldseeker_service_feature_item_id_fkey
Nuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_organization_id_fkey
Waters PublicreportWaterSlice // publicreport.water.pool_organization_id_fkey
NuisanceOlds PublicreportNuisanceOldSlice // publicreport.nuisance_old.nuisance_organization_id_fkey
Reports PublicreportReportSlice // publicreport.report.report_organization_id_fkey
WaterOlds PublicreportWaterOldSlice // publicreport.water_old.pool_organization_id_fkey
ReviewTasks ReviewTaskSlice // review_task.review_task_organization_id_fkey
Signals SignalSlice // signal.signal_organization_id_fkey
User UserSlice // user_.user__organization_id_fkey
@ -1972,14 +1973,14 @@ func (os OrganizationSlice) FieldseekerServiceFeatureItemServiceFeature(mods ...
)...)
}
// Nuisances starts a query for related objects on publicreport.nuisance
func (o *Organization) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
return PublicreportNuisances.Query(append(mods,
sm.Where(PublicreportNuisances.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
// NuisanceOlds starts a query for related objects on publicreport.nuisance_old
func (o *Organization) NuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNuisanceOlds.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
)...)
}
func (os OrganizationSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
func (os OrganizationSlice) NuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
@ -1991,19 +1992,19 @@ func (os OrganizationSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) Pub
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportNuisances.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisances.Columns.OrganizationID).OP("IN", PKArgExpr)),
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisanceOlds.Columns.OrganizationID).OP("IN", PKArgExpr)),
)...)
}
// Waters starts a query for related objects on publicreport.water
func (o *Organization) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
return PublicreportWaters.Query(append(mods,
sm.Where(PublicreportWaters.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
// Reports starts a query for related objects on publicreport.report
func (o *Organization) Reports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
)...)
}
func (os OrganizationSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
func (os OrganizationSlice) Reports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
@ -2015,8 +2016,32 @@ func (os OrganizationSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) Public
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportWaters.Columns.OrganizationID).OP("IN", PKArgExpr)),
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.OrganizationID).OP("IN", PKArgExpr)),
)...)
}
// WaterOlds starts a query for related objects on publicreport.water_old
func (o *Organization) WaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
return PublicreportWaterOlds.Query(append(mods,
sm.Where(PublicreportWaterOlds.Columns.OrganizationID.EQ(psql.Arg(o.ID))),
)...)
}
func (os OrganizationSlice) WaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
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 PublicreportWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportWaterOlds.Columns.OrganizationID).OP("IN", PKArgExpr)),
)...)
}
@ -4882,66 +4907,66 @@ func (organization0 *Organization) AttachFieldseekerServiceFeatureItemServiceFea
return nil
}
func insertOrganizationNuisances0(ctx context.Context, exec bob.Executor, publicreportNuisances1 []*PublicreportNuisanceSetter, organization0 *Organization) (PublicreportNuisanceSlice, error) {
for i := range publicreportNuisances1 {
publicreportNuisances1[i].OrganizationID = omit.From(organization0.ID)
func insertOrganizationNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNuisanceOlds1 []*PublicreportNuisanceOldSetter, organization0 *Organization) (PublicreportNuisanceOldSlice, error) {
for i := range publicreportNuisanceOlds1 {
publicreportNuisanceOlds1[i].OrganizationID = omit.From(organization0.ID)
}
ret, err := PublicreportNuisances.Insert(bob.ToMods(publicreportNuisances1...)).All(ctx, exec)
ret, err := PublicreportNuisanceOlds.Insert(bob.ToMods(publicreportNuisanceOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertOrganizationNuisances0: %w", err)
return ret, fmt.Errorf("insertOrganizationNuisanceOlds0: %w", err)
}
return ret, nil
}
func attachOrganizationNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNuisances1 PublicreportNuisanceSlice, organization0 *Organization) (PublicreportNuisanceSlice, error) {
setter := &PublicreportNuisanceSetter{
func attachOrganizationNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOlds1 PublicreportNuisanceOldSlice, organization0 *Organization) (PublicreportNuisanceOldSlice, error) {
setter := &PublicreportNuisanceOldSetter{
OrganizationID: omit.From(organization0.ID),
}
err := publicreportNuisances1.UpdateAll(ctx, exec, *setter)
err := publicreportNuisanceOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachOrganizationNuisances0: %w", err)
return nil, fmt.Errorf("attachOrganizationNuisanceOlds0: %w", err)
}
return publicreportNuisances1, nil
return publicreportNuisanceOlds1, nil
}
func (organization0 *Organization) InsertNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error {
func (organization0 *Organization) InsertNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNuisances1, err := insertOrganizationNuisances0(ctx, exec, related, organization0)
publicreportNuisanceOlds1, err := insertOrganizationNuisanceOlds0(ctx, exec, related, organization0)
if err != nil {
return err
}
organization0.R.Nuisances = append(organization0.R.Nuisances, publicreportNuisances1...)
organization0.R.NuisanceOlds = append(organization0.R.NuisanceOlds, publicreportNuisanceOlds1...)
for _, rel := range publicreportNuisances1 {
for _, rel := range publicreportNuisanceOlds1 {
rel.R.Organization = organization0
}
return nil
}
func (organization0 *Organization) AttachNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error {
func (organization0 *Organization) AttachNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNuisances1 := PublicreportNuisanceSlice(related)
publicreportNuisanceOlds1 := PublicreportNuisanceOldSlice(related)
_, err = attachOrganizationNuisances0(ctx, exec, len(related), publicreportNuisances1, organization0)
_, err = attachOrganizationNuisanceOlds0(ctx, exec, len(related), publicreportNuisanceOlds1, organization0)
if err != nil {
return err
}
organization0.R.Nuisances = append(organization0.R.Nuisances, publicreportNuisances1...)
organization0.R.NuisanceOlds = append(organization0.R.NuisanceOlds, publicreportNuisanceOlds1...)
for _, rel := range related {
rel.R.Organization = organization0
@ -4950,66 +4975,134 @@ func (organization0 *Organization) AttachNuisances(ctx context.Context, exec bob
return nil
}
func insertOrganizationWaters0(ctx context.Context, exec bob.Executor, publicreportWaters1 []*PublicreportWaterSetter, organization0 *Organization) (PublicreportWaterSlice, error) {
for i := range publicreportWaters1 {
publicreportWaters1[i].OrganizationID = omit.From(organization0.ID)
func insertOrganizationReports0(ctx context.Context, exec bob.Executor, publicreportReports1 []*PublicreportReportSetter, organization0 *Organization) (PublicreportReportSlice, error) {
for i := range publicreportReports1 {
publicreportReports1[i].OrganizationID = omit.From(organization0.ID)
}
ret, err := PublicreportWaters.Insert(bob.ToMods(publicreportWaters1...)).All(ctx, exec)
ret, err := PublicreportReports.Insert(bob.ToMods(publicreportReports1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertOrganizationWaters0: %w", err)
return ret, fmt.Errorf("insertOrganizationReports0: %w", err)
}
return ret, nil
}
func attachOrganizationWaters0(ctx context.Context, exec bob.Executor, count int, publicreportWaters1 PublicreportWaterSlice, organization0 *Organization) (PublicreportWaterSlice, error) {
setter := &PublicreportWaterSetter{
func attachOrganizationReports0(ctx context.Context, exec bob.Executor, count int, publicreportReports1 PublicreportReportSlice, organization0 *Organization) (PublicreportReportSlice, error) {
setter := &PublicreportReportSetter{
OrganizationID: omit.From(organization0.ID),
}
err := publicreportWaters1.UpdateAll(ctx, exec, *setter)
err := publicreportReports1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachOrganizationWaters0: %w", err)
return nil, fmt.Errorf("attachOrganizationReports0: %w", err)
}
return publicreportWaters1, nil
return publicreportReports1, nil
}
func (organization0 *Organization) InsertWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error {
func (organization0 *Organization) InsertReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReportSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaters1, err := insertOrganizationWaters0(ctx, exec, related, organization0)
publicreportReports1, err := insertOrganizationReports0(ctx, exec, related, organization0)
if err != nil {
return err
}
organization0.R.Waters = append(organization0.R.Waters, publicreportWaters1...)
organization0.R.Reports = append(organization0.R.Reports, publicreportReports1...)
for _, rel := range publicreportWaters1 {
for _, rel := range publicreportReports1 {
rel.R.Organization = organization0
}
return nil
}
func (organization0 *Organization) AttachWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error {
func (organization0 *Organization) AttachReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReport) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaters1 := PublicreportWaterSlice(related)
publicreportReports1 := PublicreportReportSlice(related)
_, err = attachOrganizationWaters0(ctx, exec, len(related), publicreportWaters1, organization0)
_, err = attachOrganizationReports0(ctx, exec, len(related), publicreportReports1, organization0)
if err != nil {
return err
}
organization0.R.Waters = append(organization0.R.Waters, publicreportWaters1...)
organization0.R.Reports = append(organization0.R.Reports, publicreportReports1...)
for _, rel := range related {
rel.R.Organization = organization0
}
return nil
}
func insertOrganizationWaterOlds0(ctx context.Context, exec bob.Executor, publicreportWaterOlds1 []*PublicreportWaterOldSetter, organization0 *Organization) (PublicreportWaterOldSlice, error) {
for i := range publicreportWaterOlds1 {
publicreportWaterOlds1[i].OrganizationID = omit.From(organization0.ID)
}
ret, err := PublicreportWaterOlds.Insert(bob.ToMods(publicreportWaterOlds1...)).All(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertOrganizationWaterOlds0: %w", err)
}
return ret, nil
}
func attachOrganizationWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOlds1 PublicreportWaterOldSlice, organization0 *Organization) (PublicreportWaterOldSlice, error) {
setter := &PublicreportWaterOldSetter{
OrganizationID: omit.From(organization0.ID),
}
err := publicreportWaterOlds1.UpdateAll(ctx, exec, *setter)
if err != nil {
return nil, fmt.Errorf("attachOrganizationWaterOlds0: %w", err)
}
return publicreportWaterOlds1, nil
}
func (organization0 *Organization) InsertWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaterOlds1, err := insertOrganizationWaterOlds0(ctx, exec, related, organization0)
if err != nil {
return err
}
organization0.R.WaterOlds = append(organization0.R.WaterOlds, publicreportWaterOlds1...)
for _, rel := range publicreportWaterOlds1 {
rel.R.Organization = organization0
}
return nil
}
func (organization0 *Organization) AttachWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaterOlds1 := PublicreportWaterOldSlice(related)
_, err = attachOrganizationWaterOlds0(ctx, exec, len(related), publicreportWaterOlds1, organization0)
if err != nil {
return err
}
organization0.R.WaterOlds = append(organization0.R.WaterOlds, publicreportWaterOlds1...)
for _, rel := range related {
rel.R.Organization = organization0
@ -5890,13 +5983,13 @@ func (o *Organization) Preload(name string, retrieved any) error {
rel.R.FieldseekerServiceFeatureItemOrganizations = OrganizationSlice{o}
}
return nil
case "Nuisances":
rels, ok := retrieved.(PublicreportNuisanceSlice)
case "NuisanceOlds":
rels, ok := retrieved.(PublicreportNuisanceOldSlice)
if !ok {
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
}
o.R.Nuisances = rels
o.R.NuisanceOlds = rels
for _, rel := range rels {
if rel != nil {
@ -5904,13 +5997,27 @@ func (o *Organization) Preload(name string, retrieved any) error {
}
}
return nil
case "Waters":
rels, ok := retrieved.(PublicreportWaterSlice)
case "Reports":
rels, ok := retrieved.(PublicreportReportSlice)
if !ok {
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
}
o.R.Waters = rels
o.R.Reports = rels
for _, rel := range rels {
if rel != nil {
rel.R.Organization = o
}
}
return nil
case "WaterOlds":
rels, ok := retrieved.(PublicreportWaterOldSlice)
if !ok {
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
}
o.R.WaterOlds = rels
for _, rel := range rels {
if rel != nil {
@ -6058,8 +6165,9 @@ type organizationThenLoader[Q orm.Loadable] struct {
ArcgisAccountAccount func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ArcgisMapServiceServiceMap func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
FieldseekerServiceFeatureItemServiceFeature func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Waters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Reports func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
WaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ReviewTasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Signals func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
User func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
@ -6192,11 +6300,14 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
type FieldseekerServiceFeatureItemServiceFeatureLoadInterface interface {
LoadFieldseekerServiceFeatureItemServiceFeature(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisancesLoadInterface interface {
LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type NuisanceOldsLoadInterface interface {
LoadNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WatersLoadInterface interface {
LoadWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type ReportsLoadInterface interface {
LoadReports(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterOldsLoadInterface interface {
LoadWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReviewTasksLoadInterface interface {
LoadReviewTasks(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
@ -6461,16 +6572,22 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
return retrieved.LoadFieldseekerServiceFeatureItemServiceFeature(ctx, exec, mods...)
},
),
Nuisances: thenLoadBuilder[Q](
"Nuisances",
func(ctx context.Context, exec bob.Executor, retrieved NuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisances(ctx, exec, mods...)
NuisanceOlds: thenLoadBuilder[Q](
"NuisanceOlds",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisanceOlds(ctx, exec, mods...)
},
),
Waters: thenLoadBuilder[Q](
"Waters",
func(ctx context.Context, exec bob.Executor, retrieved WatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaters(ctx, exec, mods...)
Reports: thenLoadBuilder[Q](
"Reports",
func(ctx context.Context, exec bob.Executor, retrieved ReportsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReports(ctx, exec, mods...)
},
),
WaterOlds: thenLoadBuilder[Q](
"WaterOlds",
func(ctx context.Context, exec bob.Executor, retrieved WaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaterOlds(ctx, exec, mods...)
},
),
ReviewTasks: thenLoadBuilder[Q](
@ -9078,16 +9195,16 @@ func (os OrganizationSlice) LoadFieldseekerServiceFeatureItemServiceFeature(ctx
return nil
}
// LoadNuisances loads the organization's Nuisances into the .R struct
func (o *Organization) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadNuisanceOlds loads the organization's NuisanceOlds into the .R struct
func (o *Organization) LoadNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Nuisances = nil
o.R.NuisanceOlds = nil
related, err := o.Nuisances(mods...).All(ctx, exec)
related, err := o.NuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -9096,17 +9213,17 @@ func (o *Organization) LoadNuisances(ctx context.Context, exec bob.Executor, mod
rel.R.Organization = o
}
o.R.Nuisances = related
o.R.NuisanceOlds = related
return nil
}
// LoadNuisances loads the organization's Nuisances into the .R struct
func (os OrganizationSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadNuisanceOlds loads the organization's NuisanceOlds into the .R struct
func (os OrganizationSlice) LoadNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisances, err := os.Nuisances(mods...).All(ctx, exec)
publicreportNuisanceOlds, err := os.NuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -9116,7 +9233,7 @@ func (os OrganizationSlice) LoadNuisances(ctx context.Context, exec bob.Executor
continue
}
o.R.Nuisances = nil
o.R.NuisanceOlds = nil
}
for _, o := range os {
@ -9124,7 +9241,7 @@ func (os OrganizationSlice) LoadNuisances(ctx context.Context, exec bob.Executor
continue
}
for _, rel := range publicreportNuisances {
for _, rel := range publicreportNuisanceOlds {
if !(o.ID == rel.OrganizationID) {
continue
@ -9132,23 +9249,23 @@ func (os OrganizationSlice) LoadNuisances(ctx context.Context, exec bob.Executor
rel.R.Organization = o
o.R.Nuisances = append(o.R.Nuisances, rel)
o.R.NuisanceOlds = append(o.R.NuisanceOlds, rel)
}
}
return nil
}
// LoadWaters loads the organization's Waters into the .R struct
func (o *Organization) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadReports loads the organization's Reports into the .R struct
func (o *Organization) LoadReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Waters = nil
o.R.Reports = nil
related, err := o.Waters(mods...).All(ctx, exec)
related, err := o.Reports(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -9157,17 +9274,17 @@ func (o *Organization) LoadWaters(ctx context.Context, exec bob.Executor, mods .
rel.R.Organization = o
}
o.R.Waters = related
o.R.Reports = related
return nil
}
// LoadWaters loads the organization's Waters into the .R struct
func (os OrganizationSlice) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadReports loads the organization's Reports into the .R struct
func (os OrganizationSlice) LoadReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaters, err := os.Waters(mods...).All(ctx, exec)
publicreportReports, err := os.Reports(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -9177,7 +9294,7 @@ func (os OrganizationSlice) LoadWaters(ctx context.Context, exec bob.Executor, m
continue
}
o.R.Waters = nil
o.R.Reports = nil
}
for _, o := range os {
@ -9185,7 +9302,7 @@ func (os OrganizationSlice) LoadWaters(ctx context.Context, exec bob.Executor, m
continue
}
for _, rel := range publicreportWaters {
for _, rel := range publicreportReports {
if !(o.ID == rel.OrganizationID) {
continue
@ -9193,7 +9310,68 @@ func (os OrganizationSlice) LoadWaters(ctx context.Context, exec bob.Executor, m
rel.R.Organization = o
o.R.Waters = append(o.R.Waters, rel)
o.R.Reports = append(o.R.Reports, rel)
}
}
return nil
}
// LoadWaterOlds loads the organization's WaterOlds into the .R struct
func (o *Organization) LoadWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.WaterOlds = nil
related, err := o.WaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Organization = o
}
o.R.WaterOlds = related
return nil
}
// LoadWaterOlds loads the organization's WaterOlds into the .R struct
func (os OrganizationSlice) LoadWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaterOlds, err := os.WaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
o.R.WaterOlds = nil
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaterOlds {
if !(o.ID == rel.OrganizationID) {
continue
}
rel.R.Organization = o
o.R.WaterOlds = append(o.R.WaterOlds, rel)
}
}

View file

@ -52,9 +52,10 @@ type PublicreportImagesQuery = *psql.ViewQuery[*PublicreportImage, PublicreportI
// publicreportImageR is where relationships are stored.
type publicreportImageR struct {
ImageExifs PublicreportImageExifSlice // publicreport.image_exif.image_exif_image_id_fkey
Nuisances PublicreportNuisanceSlice // publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey
Waters PublicreportWaterSlice // publicreport.water_image.pool_image_image_id_fkeypublicreport.water_image.pool_image_pool_id_fkey
ImageExifs PublicreportImageExifSlice // publicreport.image_exif.image_exif_image_id_fkey
NuisanceOlds PublicreportNuisanceOldSlice // publicreport.nuisance_image_old.nuisance_image_image_id_fkeypublicreport.nuisance_image_old.nuisance_image_nuisance_id_fkey
Reports PublicreportReportSlice // publicreport.report_image.report_image_image_id_fkeypublicreport.report_image.report_image_report_id_fkey
WaterOlds PublicreportWaterOldSlice // publicreport.water_image_old.pool_image_image_id_fkeypublicreport.water_image_old.pool_image_pool_id_fkey
}
func buildPublicreportImageColumns(alias string) publicreportImageColumns {
@ -559,16 +560,16 @@ func (os PublicreportImageSlice) ImageExifs(mods ...bob.Mod[*dialect.SelectQuery
)...)
}
// Nuisances starts a query for related objects on publicreport.nuisance
func (o *PublicreportImage) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
return PublicreportNuisances.Query(append(mods,
sm.InnerJoin(PublicreportNuisanceImages.NameAs()).On(
PublicreportNuisances.Columns.ID.EQ(PublicreportNuisanceImages.Columns.NuisanceID)),
sm.Where(PublicreportNuisanceImages.Columns.ImageID.EQ(psql.Arg(o.ID))),
// NuisanceOlds starts a query for related objects on publicreport.nuisance_old
func (o *PublicreportImage) NuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
return PublicreportNuisanceOlds.Query(append(mods,
sm.InnerJoin(PublicreportNuisanceImageOlds.NameAs()).On(
PublicreportNuisanceOlds.Columns.ID.EQ(PublicreportNuisanceImageOlds.Columns.NuisanceID)),
sm.Where(PublicreportNuisanceImageOlds.Columns.ImageID.EQ(psql.Arg(o.ID))),
)...)
}
func (os PublicreportImageSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
func (os PublicreportImageSlice) NuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
@ -580,24 +581,24 @@ func (os PublicreportImageSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportNuisances.Query(append(mods,
sm.InnerJoin(PublicreportNuisanceImages.NameAs()).On(
PublicreportNuisances.Columns.ID.EQ(PublicreportNuisanceImages.Columns.NuisanceID),
return PublicreportNuisanceOlds.Query(append(mods,
sm.InnerJoin(PublicreportNuisanceImageOlds.NameAs()).On(
PublicreportNuisanceOlds.Columns.ID.EQ(PublicreportNuisanceImageOlds.Columns.NuisanceID),
),
sm.Where(psql.Group(PublicreportNuisanceImages.Columns.ImageID).OP("IN", PKArgExpr)),
sm.Where(psql.Group(PublicreportNuisanceImageOlds.Columns.ImageID).OP("IN", PKArgExpr)),
)...)
}
// Waters starts a query for related objects on publicreport.water
func (o *PublicreportImage) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
return PublicreportWaters.Query(append(mods,
sm.InnerJoin(PublicreportWaterImages.NameAs()).On(
PublicreportWaters.Columns.ID.EQ(PublicreportWaterImages.Columns.WaterID)),
sm.Where(PublicreportWaterImages.Columns.ImageID.EQ(psql.Arg(o.ID))),
// Reports starts a query for related objects on publicreport.report
func (o *PublicreportImage) Reports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.InnerJoin(PublicreportReportImages.NameAs()).On(
PublicreportReports.Columns.ID.EQ(PublicreportReportImages.Columns.ReportID)),
sm.Where(PublicreportReportImages.Columns.ImageID.EQ(psql.Arg(o.ID))),
)...)
}
func (os PublicreportImageSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
func (os PublicreportImageSlice) Reports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
@ -609,11 +610,40 @@ func (os PublicreportImageSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) P
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
))
return PublicreportWaters.Query(append(mods,
sm.InnerJoin(PublicreportWaterImages.NameAs()).On(
PublicreportWaters.Columns.ID.EQ(PublicreportWaterImages.Columns.WaterID),
return PublicreportReports.Query(append(mods,
sm.InnerJoin(PublicreportReportImages.NameAs()).On(
PublicreportReports.Columns.ID.EQ(PublicreportReportImages.Columns.ReportID),
),
sm.Where(psql.Group(PublicreportWaterImages.Columns.ImageID).OP("IN", PKArgExpr)),
sm.Where(psql.Group(PublicreportReportImages.Columns.ImageID).OP("IN", PKArgExpr)),
)...)
}
// WaterOlds starts a query for related objects on publicreport.water_old
func (o *PublicreportImage) WaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
return PublicreportWaterOlds.Query(append(mods,
sm.InnerJoin(PublicreportWaterImageOlds.NameAs()).On(
PublicreportWaterOlds.Columns.ID.EQ(PublicreportWaterImageOlds.Columns.WaterID)),
sm.Where(PublicreportWaterImageOlds.Columns.ImageID.EQ(psql.Arg(o.ID))),
)...)
}
func (os PublicreportImageSlice) WaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
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 PublicreportWaterOlds.Query(append(mods,
sm.InnerJoin(PublicreportWaterImageOlds.NameAs()).On(
PublicreportWaterOlds.Columns.ID.EQ(PublicreportWaterImageOlds.Columns.WaterID),
),
sm.Where(psql.Group(PublicreportWaterImageOlds.Columns.ImageID).OP("IN", PKArgExpr)),
)...)
}
@ -685,63 +715,63 @@ func (publicreportImage0 *PublicreportImage) AttachImageExifs(ctx context.Contex
return nil
}
func attachPublicreportImageNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportNuisances2 PublicreportNuisanceSlice) (PublicreportNuisanceImageSlice, error) {
setters := make([]*PublicreportNuisanceImageSetter, count)
func attachPublicreportImageNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportNuisanceOlds2 PublicreportNuisanceOldSlice) (PublicreportNuisanceImageOldSlice, error) {
setters := make([]*PublicreportNuisanceImageOldSetter, count)
for i := range count {
setters[i] = &PublicreportNuisanceImageSetter{
setters[i] = &PublicreportNuisanceImageOldSetter{
ImageID: omit.From(publicreportImage0.ID),
NuisanceID: omit.From(publicreportNuisances2[i].ID),
NuisanceID: omit.From(publicreportNuisanceOlds2[i].ID),
}
}
publicreportNuisanceImages1, err := PublicreportNuisanceImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
publicreportNuisanceImageOlds1, err := PublicreportNuisanceImageOlds.Insert(bob.ToMods(setters...)).All(ctx, exec)
if err != nil {
return nil, fmt.Errorf("attachPublicreportImageNuisances0: %w", err)
return nil, fmt.Errorf("attachPublicreportImageNuisanceOlds0: %w", err)
}
return publicreportNuisanceImages1, nil
return publicreportNuisanceImageOlds1, nil
}
func (publicreportImage0 *PublicreportImage) InsertNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error {
func (publicreportImage0 *PublicreportImage) InsertNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
inserted, err := PublicreportNuisances.Insert(bob.ToMods(related...)).All(ctx, exec)
inserted, err := PublicreportNuisanceOlds.Insert(bob.ToMods(related...)).All(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
publicreportNuisances2 := PublicreportNuisanceSlice(inserted)
publicreportNuisanceOlds2 := PublicreportNuisanceOldSlice(inserted)
_, err = attachPublicreportImageNuisances0(ctx, exec, len(related), publicreportImage0, publicreportNuisances2)
_, err = attachPublicreportImageNuisanceOlds0(ctx, exec, len(related), publicreportImage0, publicreportNuisanceOlds2)
if err != nil {
return err
}
publicreportImage0.R.Nuisances = append(publicreportImage0.R.Nuisances, publicreportNuisances2...)
publicreportImage0.R.NuisanceOlds = append(publicreportImage0.R.NuisanceOlds, publicreportNuisanceOlds2...)
for _, rel := range publicreportNuisances2 {
for _, rel := range publicreportNuisanceOlds2 {
rel.R.Images = append(rel.R.Images, publicreportImage0)
}
return nil
}
func (publicreportImage0 *PublicreportImage) AttachNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error {
func (publicreportImage0 *PublicreportImage) AttachNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportNuisances2 := PublicreportNuisanceSlice(related)
publicreportNuisanceOlds2 := PublicreportNuisanceOldSlice(related)
_, err = attachPublicreportImageNuisances0(ctx, exec, len(related), publicreportImage0, publicreportNuisances2)
_, err = attachPublicreportImageNuisanceOlds0(ctx, exec, len(related), publicreportImage0, publicreportNuisanceOlds2)
if err != nil {
return err
}
publicreportImage0.R.Nuisances = append(publicreportImage0.R.Nuisances, publicreportNuisances2...)
publicreportImage0.R.NuisanceOlds = append(publicreportImage0.R.NuisanceOlds, publicreportNuisanceOlds2...)
for _, rel := range related {
rel.R.Images = append(rel.R.Images, publicreportImage0)
@ -750,63 +780,128 @@ func (publicreportImage0 *PublicreportImage) AttachNuisances(ctx context.Context
return nil
}
func attachPublicreportImageWaters0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportWaters2 PublicreportWaterSlice) (PublicreportWaterImageSlice, error) {
setters := make([]*PublicreportWaterImageSetter, count)
func attachPublicreportImageReports0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportReports2 PublicreportReportSlice) (PublicreportReportImageSlice, error) {
setters := make([]*PublicreportReportImageSetter, count)
for i := range count {
setters[i] = &PublicreportWaterImageSetter{
ImageID: omit.From(publicreportImage0.ID),
WaterID: omit.From(publicreportWaters2[i].ID),
setters[i] = &PublicreportReportImageSetter{
ImageID: omit.From(publicreportImage0.ID),
ReportID: omit.From(publicreportReports2[i].ID),
}
}
publicreportWaterImages1, err := PublicreportWaterImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
publicreportReportImages1, err := PublicreportReportImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
if err != nil {
return nil, fmt.Errorf("attachPublicreportImageWaters0: %w", err)
return nil, fmt.Errorf("attachPublicreportImageReports0: %w", err)
}
return publicreportWaterImages1, nil
return publicreportReportImages1, nil
}
func (publicreportImage0 *PublicreportImage) InsertWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error {
func (publicreportImage0 *PublicreportImage) InsertReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReportSetter) error {
if len(related) == 0 {
return nil
}
var err error
inserted, err := PublicreportWaters.Insert(bob.ToMods(related...)).All(ctx, exec)
inserted, err := PublicreportReports.Insert(bob.ToMods(related...)).All(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
publicreportWaters2 := PublicreportWaterSlice(inserted)
publicreportReports2 := PublicreportReportSlice(inserted)
_, err = attachPublicreportImageWaters0(ctx, exec, len(related), publicreportImage0, publicreportWaters2)
_, err = attachPublicreportImageReports0(ctx, exec, len(related), publicreportImage0, publicreportReports2)
if err != nil {
return err
}
publicreportImage0.R.Waters = append(publicreportImage0.R.Waters, publicreportWaters2...)
publicreportImage0.R.Reports = append(publicreportImage0.R.Reports, publicreportReports2...)
for _, rel := range publicreportWaters2 {
for _, rel := range publicreportReports2 {
rel.R.Images = append(rel.R.Images, publicreportImage0)
}
return nil
}
func (publicreportImage0 *PublicreportImage) AttachWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error {
func (publicreportImage0 *PublicreportImage) AttachReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReport) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaters2 := PublicreportWaterSlice(related)
publicreportReports2 := PublicreportReportSlice(related)
_, err = attachPublicreportImageWaters0(ctx, exec, len(related), publicreportImage0, publicreportWaters2)
_, err = attachPublicreportImageReports0(ctx, exec, len(related), publicreportImage0, publicreportReports2)
if err != nil {
return err
}
publicreportImage0.R.Waters = append(publicreportImage0.R.Waters, publicreportWaters2...)
publicreportImage0.R.Reports = append(publicreportImage0.R.Reports, publicreportReports2...)
for _, rel := range related {
rel.R.Images = append(rel.R.Images, publicreportImage0)
}
return nil
}
func attachPublicreportImageWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportWaterOlds2 PublicreportWaterOldSlice) (PublicreportWaterImageOldSlice, error) {
setters := make([]*PublicreportWaterImageOldSetter, count)
for i := range count {
setters[i] = &PublicreportWaterImageOldSetter{
ImageID: omit.From(publicreportImage0.ID),
WaterID: omit.From(publicreportWaterOlds2[i].ID),
}
}
publicreportWaterImageOlds1, err := PublicreportWaterImageOlds.Insert(bob.ToMods(setters...)).All(ctx, exec)
if err != nil {
return nil, fmt.Errorf("attachPublicreportImageWaterOlds0: %w", err)
}
return publicreportWaterImageOlds1, nil
}
func (publicreportImage0 *PublicreportImage) InsertWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOldSetter) error {
if len(related) == 0 {
return nil
}
var err error
inserted, err := PublicreportWaterOlds.Insert(bob.ToMods(related...)).All(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
publicreportWaterOlds2 := PublicreportWaterOldSlice(inserted)
_, err = attachPublicreportImageWaterOlds0(ctx, exec, len(related), publicreportImage0, publicreportWaterOlds2)
if err != nil {
return err
}
publicreportImage0.R.WaterOlds = append(publicreportImage0.R.WaterOlds, publicreportWaterOlds2...)
for _, rel := range publicreportWaterOlds2 {
rel.R.Images = append(rel.R.Images, publicreportImage0)
}
return nil
}
func (publicreportImage0 *PublicreportImage) AttachWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOld) error {
if len(related) == 0 {
return nil
}
var err error
publicreportWaterOlds2 := PublicreportWaterOldSlice(related)
_, err = attachPublicreportImageWaterOlds0(ctx, exec, len(related), publicreportImage0, publicreportWaterOlds2)
if err != nil {
return err
}
publicreportImage0.R.WaterOlds = append(publicreportImage0.R.WaterOlds, publicreportWaterOlds2...)
for _, rel := range related {
rel.R.Images = append(rel.R.Images, publicreportImage0)
@ -865,13 +960,13 @@ func (o *PublicreportImage) Preload(name string, retrieved any) error {
}
}
return nil
case "Nuisances":
rels, ok := retrieved.(PublicreportNuisanceSlice)
case "NuisanceOlds":
rels, ok := retrieved.(PublicreportNuisanceOldSlice)
if !ok {
return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name)
}
o.R.Nuisances = rels
o.R.NuisanceOlds = rels
for _, rel := range rels {
if rel != nil {
@ -879,13 +974,27 @@ func (o *PublicreportImage) Preload(name string, retrieved any) error {
}
}
return nil
case "Waters":
rels, ok := retrieved.(PublicreportWaterSlice)
case "Reports":
rels, ok := retrieved.(PublicreportReportSlice)
if !ok {
return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name)
}
o.R.Waters = rels
o.R.Reports = rels
for _, rel := range rels {
if rel != nil {
rel.R.Images = PublicreportImageSlice{o}
}
}
return nil
case "WaterOlds":
rels, ok := retrieved.(PublicreportWaterOldSlice)
if !ok {
return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name)
}
o.R.WaterOlds = rels
for _, rel := range rels {
if rel != nil {
@ -905,20 +1014,24 @@ func buildPublicreportImagePreloader() publicreportImagePreloader {
}
type publicreportImageThenLoader[Q orm.Loadable] struct {
ImageExifs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Waters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ImageExifs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Reports func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
WaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportImageThenLoader[Q orm.Loadable]() publicreportImageThenLoader[Q] {
type ImageExifsLoadInterface interface {
LoadImageExifs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisancesLoadInterface interface {
LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type NuisanceOldsLoadInterface interface {
LoadNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WatersLoadInterface interface {
LoadWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
type ReportsLoadInterface interface {
LoadReports(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterOldsLoadInterface interface {
LoadWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportImageThenLoader[Q]{
@ -928,16 +1041,22 @@ func buildPublicreportImageThenLoader[Q orm.Loadable]() publicreportImageThenLoa
return retrieved.LoadImageExifs(ctx, exec, mods...)
},
),
Nuisances: thenLoadBuilder[Q](
"Nuisances",
func(ctx context.Context, exec bob.Executor, retrieved NuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisances(ctx, exec, mods...)
NuisanceOlds: thenLoadBuilder[Q](
"NuisanceOlds",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisanceOlds(ctx, exec, mods...)
},
),
Waters: thenLoadBuilder[Q](
"Waters",
func(ctx context.Context, exec bob.Executor, retrieved WatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaters(ctx, exec, mods...)
Reports: thenLoadBuilder[Q](
"Reports",
func(ctx context.Context, exec bob.Executor, retrieved ReportsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReports(ctx, exec, mods...)
},
),
WaterOlds: thenLoadBuilder[Q](
"WaterOlds",
func(ctx context.Context, exec bob.Executor, retrieved WaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaterOlds(ctx, exec, mods...)
},
),
}
@ -1004,16 +1123,16 @@ func (os PublicreportImageSlice) LoadImageExifs(ctx context.Context, exec bob.Ex
return nil
}
// LoadNuisances loads the publicreportImage's Nuisances into the .R struct
func (o *PublicreportImage) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadNuisanceOlds loads the publicreportImage's NuisanceOlds into the .R struct
func (o *PublicreportImage) LoadNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Nuisances = nil
o.R.NuisanceOlds = nil
related, err := o.Nuisances(mods...).All(ctx, exec)
related, err := o.NuisanceOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1022,12 +1141,12 @@ func (o *PublicreportImage) LoadNuisances(ctx context.Context, exec bob.Executor
rel.R.Images = PublicreportImageSlice{o}
}
o.R.Nuisances = related
o.R.NuisanceOlds = related
return nil
}
// LoadNuisances loads the publicreportImage's Nuisances into the .R struct
func (os PublicreportImageSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadNuisanceOlds loads the publicreportImage's NuisanceOlds into the .R struct
func (os PublicreportImageSlice) LoadNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
@ -1039,17 +1158,17 @@ func (os PublicreportImageSlice) LoadNuisances(ctx context.Context, exec bob.Exe
}
if len(sq.SelectList.Columns) == 0 {
mods = append(mods, sm.Columns(PublicreportNuisances.Columns))
mods = append(mods, sm.Columns(PublicreportNuisanceOlds.Columns))
}
q := os.Nuisances(append(
q := os.NuisanceOlds(append(
mods,
sm.Columns(PublicreportNuisanceImages.Columns.ImageID.As("related_publicreport.image.ID")),
sm.Columns(PublicreportNuisanceImageOlds.Columns.ImageID.As("related_publicreport.image.ID")),
)...)
IDSlice := []int32{}
mapper := scan.Mod(scan.StructMapper[*PublicreportNuisance](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
mapper := scan.Mod(scan.StructMapper[*PublicreportNuisanceOld](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
return func(row *scan.Row) (any, error) {
IDSlice = append(IDSlice, *new(int32))
row.ScheduleScanByName("related_publicreport.image.ID", &IDSlice[len(IDSlice)-1])
@ -1061,40 +1180,40 @@ func (os PublicreportImageSlice) LoadNuisances(ctx context.Context, exec bob.Exe
}
})
publicreportNuisances, err := bob.Allx[bob.SliceTransformer[*PublicreportNuisance, PublicreportNuisanceSlice]](ctx, exec, q, mapper)
publicreportNuisanceOlds, err := bob.Allx[bob.SliceTransformer[*PublicreportNuisanceOld, PublicreportNuisanceOldSlice]](ctx, exec, q, mapper)
if err != nil {
return err
}
for _, o := range os {
o.R.Nuisances = nil
o.R.NuisanceOlds = nil
}
for _, o := range os {
for i, rel := range publicreportNuisances {
for i, rel := range publicreportNuisanceOlds {
if !(o.ID == IDSlice[i]) {
continue
}
rel.R.Images = append(rel.R.Images, o)
o.R.Nuisances = append(o.R.Nuisances, rel)
o.R.NuisanceOlds = append(o.R.NuisanceOlds, rel)
}
}
return nil
}
// LoadWaters loads the publicreportImage's Waters into the .R struct
func (o *PublicreportImage) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadReports loads the publicreportImage's Reports into the .R struct
func (o *PublicreportImage) LoadReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Waters = nil
o.R.Reports = nil
related, err := o.Waters(mods...).All(ctx, exec)
related, err := o.Reports(mods...).All(ctx, exec)
if err != nil {
return err
}
@ -1103,12 +1222,12 @@ func (o *PublicreportImage) LoadWaters(ctx context.Context, exec bob.Executor, m
rel.R.Images = PublicreportImageSlice{o}
}
o.R.Waters = related
o.R.Reports = related
return nil
}
// LoadWaters loads the publicreportImage's Waters into the .R struct
func (os PublicreportImageSlice) LoadWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
// LoadReports loads the publicreportImage's Reports into the .R struct
func (os PublicreportImageSlice) LoadReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
@ -1120,17 +1239,17 @@ func (os PublicreportImageSlice) LoadWaters(ctx context.Context, exec bob.Execut
}
if len(sq.SelectList.Columns) == 0 {
mods = append(mods, sm.Columns(PublicreportWaters.Columns))
mods = append(mods, sm.Columns(PublicreportReports.Columns))
}
q := os.Waters(append(
q := os.Reports(append(
mods,
sm.Columns(PublicreportWaterImages.Columns.ImageID.As("related_publicreport.image.ID")),
sm.Columns(PublicreportReportImages.Columns.ImageID.As("related_publicreport.image.ID")),
)...)
IDSlice := []int32{}
mapper := scan.Mod(scan.StructMapper[*PublicreportWater](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
mapper := scan.Mod(scan.StructMapper[*PublicreportReport](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
return func(row *scan.Row) (any, error) {
IDSlice = append(IDSlice, *new(int32))
row.ScheduleScanByName("related_publicreport.image.ID", &IDSlice[len(IDSlice)-1])
@ -1142,24 +1261,105 @@ func (os PublicreportImageSlice) LoadWaters(ctx context.Context, exec bob.Execut
}
})
publicreportWaters, err := bob.Allx[bob.SliceTransformer[*PublicreportWater, PublicreportWaterSlice]](ctx, exec, q, mapper)
publicreportReports, err := bob.Allx[bob.SliceTransformer[*PublicreportReport, PublicreportReportSlice]](ctx, exec, q, mapper)
if err != nil {
return err
}
for _, o := range os {
o.R.Waters = nil
o.R.Reports = nil
}
for _, o := range os {
for i, rel := range publicreportWaters {
for i, rel := range publicreportReports {
if !(o.ID == IDSlice[i]) {
continue
}
rel.R.Images = append(rel.R.Images, o)
o.R.Waters = append(o.R.Waters, rel)
o.R.Reports = append(o.R.Reports, rel)
}
}
return nil
}
// LoadWaterOlds loads the publicreportImage's WaterOlds into the .R struct
func (o *PublicreportImage) LoadWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.WaterOlds = nil
related, err := o.WaterOlds(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, rel := range related {
rel.R.Images = PublicreportImageSlice{o}
}
o.R.WaterOlds = related
return nil
}
// LoadWaterOlds loads the publicreportImage's WaterOlds into the .R struct
func (os PublicreportImageSlice) LoadWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
// since we are changing the columns, we need to check if the original columns were set or add the defaults
sq := dialect.SelectQuery{}
for _, mod := range mods {
mod.Apply(&sq)
}
if len(sq.SelectList.Columns) == 0 {
mods = append(mods, sm.Columns(PublicreportWaterOlds.Columns))
}
q := os.WaterOlds(append(
mods,
sm.Columns(PublicreportWaterImageOlds.Columns.ImageID.As("related_publicreport.image.ID")),
)...)
IDSlice := []int32{}
mapper := scan.Mod(scan.StructMapper[*PublicreportWaterOld](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
return func(row *scan.Row) (any, error) {
IDSlice = append(IDSlice, *new(int32))
row.ScheduleScanByName("related_publicreport.image.ID", &IDSlice[len(IDSlice)-1])
return nil, nil
},
func(any, any) error {
return nil
}
})
publicreportWaterOlds, err := bob.Allx[bob.SliceTransformer[*PublicreportWaterOld, PublicreportWaterOldSlice]](ctx, exec, q, mapper)
if err != nil {
return err
}
for _, o := range os {
o.R.WaterOlds = nil
}
for _, o := range os {
for i, rel := range publicreportWaterOlds {
if !(o.ID == IDSlice[i]) {
continue
}
rel.R.Images = append(rel.R.Images, o)
o.R.WaterOlds = append(o.R.WaterOlds, rel)
}
}

View file

@ -0,0 +1,796 @@
// 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyEmail is an object representing the database table.
type PublicreportNotifyEmail struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
EmailAddress string `db:"email_address,pk" `
ReportID int32 `db:"report_id,pk" `
R publicreportNotifyEmailR `db:"-" `
}
// PublicreportNotifyEmailSlice is an alias for a slice of pointers to PublicreportNotifyEmail.
// This should almost always be used instead of []*PublicreportNotifyEmail.
type PublicreportNotifyEmailSlice []*PublicreportNotifyEmail
// PublicreportNotifyEmails contains methods to work with the notify_email table
var PublicreportNotifyEmails = psql.NewTablex[*PublicreportNotifyEmail, PublicreportNotifyEmailSlice, *PublicreportNotifyEmailSetter]("publicreport", "notify_email", buildPublicreportNotifyEmailColumns("publicreport.notify_email"))
// PublicreportNotifyEmailsQuery is a query on the notify_email table
type PublicreportNotifyEmailsQuery = *psql.ViewQuery[*PublicreportNotifyEmail, PublicreportNotifyEmailSlice]
// publicreportNotifyEmailR is where relationships are stored.
type publicreportNotifyEmailR struct {
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email.notify_email_email_address_fkey
Report *PublicreportReport // publicreport.notify_email.notify_email_report_id_fkey
}
func buildPublicreportNotifyEmailColumns(alias string) publicreportNotifyEmailColumns {
return publicreportNotifyEmailColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "email_address", "report_id",
).WithParent("publicreport.notify_email"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
EmailAddress: psql.Quote(alias, "email_address"),
ReportID: psql.Quote(alias, "report_id"),
}
}
type publicreportNotifyEmailColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
EmailAddress psql.Expression
ReportID psql.Expression
}
func (c publicreportNotifyEmailColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyEmailColumns) AliasedAs(alias string) publicreportNotifyEmailColumns {
return buildPublicreportNotifyEmailColumns(alias)
}
// PublicreportNotifyEmailSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyEmailSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
EmailAddress omit.Val[string] `db:"email_address,pk" `
ReportID omit.Val[int32] `db:"report_id,pk" `
}
func (s PublicreportNotifyEmailSetter) 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.EmailAddress.IsValue() {
vals = append(vals, "email_address")
}
if s.ReportID.IsValue() {
vals = append(vals, "report_id")
}
return vals
}
func (s PublicreportNotifyEmailSetter) Overwrite(t *PublicreportNotifyEmail) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.EmailAddress.IsValue() {
t.EmailAddress = s.EmailAddress.MustGet()
}
if s.ReportID.IsValue() {
t.ReportID = s.ReportID.MustGet()
}
}
func (s *PublicreportNotifyEmailSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyEmails.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.EmailAddress.IsValue() {
vals[2] = psql.Arg(s.EmailAddress.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.ReportID.IsValue() {
vals[3] = psql.Arg(s.ReportID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyEmailSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyEmailSetter) 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.EmailAddress.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "email_address")...),
psql.Arg(s.EmailAddress),
}})
}
if s.ReportID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "report_id")...),
psql.Arg(s.ReportID),
}})
}
return exprs
}
// FindPublicreportNotifyEmail retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyEmail(ctx context.Context, exec bob.Executor, ReportIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmail, error) {
if len(cols) == 0 {
return PublicreportNotifyEmails.Query(
sm.Where(PublicreportNotifyEmails.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(PublicreportNotifyEmails.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).One(ctx, exec)
}
return PublicreportNotifyEmails.Query(
sm.Where(PublicreportNotifyEmails.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(PublicreportNotifyEmails.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
sm.Columns(PublicreportNotifyEmails.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyEmailExists checks the presence of a single record by primary key
func PublicreportNotifyEmailExists(ctx context.Context, exec bob.Executor, ReportIDPK int32, EmailAddressPK string) (bool, error) {
return PublicreportNotifyEmails.Query(
sm.Where(PublicreportNotifyEmails.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(PublicreportNotifyEmails.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyEmail is retrieved from the database
func (o *PublicreportNotifyEmail) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmails.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmails.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmails.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmails.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmail
func (o *PublicreportNotifyEmail) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ReportID,
o.EmailAddress,
)
}
func (o *PublicreportNotifyEmail) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_email", "report_id"), psql.Quote("publicreport.notify_email", "email_address")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNotifyEmail
func (o *PublicreportNotifyEmail) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailSetter) error {
v, err := PublicreportNotifyEmails.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 PublicreportNotifyEmail record with an executor
func (o *PublicreportNotifyEmail) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyEmails.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyEmail using the executor
func (o *PublicreportNotifyEmail) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyEmails.Query(
sm.Where(PublicreportNotifyEmails.Columns.ReportID.EQ(psql.Arg(o.ReportID))),
sm.Where(PublicreportNotifyEmails.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 PublicreportNotifyEmailSlice is retrieved from the database
func (o PublicreportNotifyEmailSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmails.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmails.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmails.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmails.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyEmailSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_email", "report_id"), psql.Quote("publicreport.notify_email", "email_address")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNotifyEmailSlice) copyMatchingRows(from ...*PublicreportNotifyEmail) {
for i, old := range o {
for _, new := range from {
if new.ReportID != old.ReportID {
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 PublicreportNotifyEmailSlice) 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 PublicreportNotifyEmails.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 *PublicreportNotifyEmail:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmail:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmail or a slice of PublicreportNotifyEmail
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyEmails.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailSlice) 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 PublicreportNotifyEmails.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 *PublicreportNotifyEmail:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmail:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmail or a slice of PublicreportNotifyEmail
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyEmails.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyEmailSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmails.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyEmailSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmails.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyEmailSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyEmails.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 *PublicreportNotifyEmail) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
return CommsEmailContacts.Query(append(mods,
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
)...)
}
func (os PublicreportNotifyEmailSlice) 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)),
)...)
}
// Report starts a query for related objects on publicreport.report
func (o *PublicreportNotifyEmail) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))),
)...)
}
func (os PublicreportNotifyEmailSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkReportID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkReportID = append(pkReportID, o.ReportID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")),
))
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyEmailEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmail0 *PublicreportNotifyEmail, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmail, error) {
setter := &PublicreportNotifyEmailSetter{
EmailAddress: omit.From(commsEmailContact1.Address),
}
err := publicreportNotifyEmail0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailEmailAddressEmailContact0: %w", err)
}
return publicreportNotifyEmail0, nil
}
func (publicreportNotifyEmail0 *PublicreportNotifyEmail) 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 = attachPublicreportNotifyEmailEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmail0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmail0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmails = append(commsEmailContact1.R.EmailAddressNotifyEmails, publicreportNotifyEmail0)
return nil
}
func (publicreportNotifyEmail0 *PublicreportNotifyEmail) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
var err error
_, err = attachPublicreportNotifyEmailEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmail0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmail0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmails = append(commsEmailContact1.R.EmailAddressNotifyEmails, publicreportNotifyEmail0)
return nil
}
func attachPublicreportNotifyEmailReport0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmail0 *PublicreportNotifyEmail, publicreportReport1 *PublicreportReport) (*PublicreportNotifyEmail, error) {
setter := &PublicreportNotifyEmailSetter{
ReportID: omit.From(publicreportReport1.ID),
}
err := publicreportNotifyEmail0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailReport0: %w", err)
}
return publicreportNotifyEmail0, nil
}
func (publicreportNotifyEmail0 *PublicreportNotifyEmail) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error {
var err error
publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyEmailReport0(ctx, exec, 1, publicreportNotifyEmail0, publicreportReport1)
if err != nil {
return err
}
publicreportNotifyEmail0.R.Report = publicreportReport1
publicreportReport1.R.NotifyEmails = append(publicreportReport1.R.NotifyEmails, publicreportNotifyEmail0)
return nil
}
func (publicreportNotifyEmail0 *PublicreportNotifyEmail) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error {
var err error
_, err = attachPublicreportNotifyEmailReport0(ctx, exec, 1, publicreportNotifyEmail0, publicreportReport1)
if err != nil {
return err
}
publicreportNotifyEmail0.R.Report = publicreportReport1
publicreportReport1.R.NotifyEmails = append(publicreportReport1.R.NotifyEmails, publicreportNotifyEmail0)
return nil
}
type publicreportNotifyEmailWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
EmailAddress psql.WhereMod[Q, string]
ReportID psql.WhereMod[Q, int32]
}
func (publicreportNotifyEmailWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailWhere[Q] {
return buildPublicreportNotifyEmailWhere[Q](buildPublicreportNotifyEmailColumns(alias))
}
func buildPublicreportNotifyEmailWhere[Q psql.Filterable](cols publicreportNotifyEmailColumns) publicreportNotifyEmailWhere[Q] {
return publicreportNotifyEmailWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
ReportID: psql.Where[Q, int32](cols.ReportID),
}
}
func (o *PublicreportNotifyEmail) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "EmailAddressEmailContact":
rel, ok := retrieved.(*CommsEmailContact)
if !ok {
return fmt.Errorf("publicreportNotifyEmail cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressEmailContact = rel
if rel != nil {
rel.R.EmailAddressNotifyEmails = PublicreportNotifyEmailSlice{o}
}
return nil
case "Report":
rel, ok := retrieved.(*PublicreportReport)
if !ok {
return fmt.Errorf("publicreportNotifyEmail cannot load %T as %q", retrieved, name)
}
o.R.Report = rel
if rel != nil {
rel.R.NotifyEmails = PublicreportNotifyEmailSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyEmail has no relationship %q", name)
}
}
type publicreportNotifyEmailPreloader struct {
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
Report func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyEmailPreloader() publicreportNotifyEmailPreloader {
return publicreportNotifyEmailPreloader{
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
Name: "EmailAddressEmailContact",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmails,
To: CommsEmailContacts,
FromColumns: []string{"email_address"},
ToColumns: []string{"address"},
},
},
}, CommsEmailContacts.Columns.Names(), opts...)
},
Report: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{
Name: "Report",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmails,
To: PublicreportReports,
FromColumns: []string{"report_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportReports.Columns.Names(), opts...)
},
}
}
type publicreportNotifyEmailThenLoader[Q orm.Loadable] struct {
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyEmailThenLoader[Q orm.Loadable]() publicreportNotifyEmailThenLoader[Q] {
type EmailAddressEmailContactLoadInterface interface {
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReportLoadInterface interface {
LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyEmailThenLoader[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...)
},
),
Report: thenLoadBuilder[Q](
"Report",
func(ctx context.Context, exec bob.Executor, retrieved ReportLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReport(ctx, exec, mods...)
},
),
}
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmail's EmailAddressEmailContact into the .R struct
func (o *PublicreportNotifyEmail) 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.EmailAddressNotifyEmails = PublicreportNotifyEmailSlice{o}
o.R.EmailAddressEmailContact = related
return nil
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmail's EmailAddressEmailContact into the .R struct
func (os PublicreportNotifyEmailSlice) 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.EmailAddressNotifyEmails = append(rel.R.EmailAddressNotifyEmails, o)
o.R.EmailAddressEmailContact = rel
break
}
}
return nil
}
// LoadReport loads the publicreportNotifyEmail's Report into the .R struct
func (o *PublicreportNotifyEmail) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Report = nil
related, err := o.Report(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyEmails = PublicreportNotifyEmailSlice{o}
o.R.Report = related
return nil
}
// LoadReport loads the publicreportNotifyEmail's Report into the .R struct
func (os PublicreportNotifyEmailSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportReports, err := os.Report(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportReports {
if !(o.ReportID == rel.ID) {
continue
}
rel.R.NotifyEmails = append(rel.R.NotifyEmails, o)
o.R.Report = rel
break
}
}
return nil
}

View file

@ -1,796 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package 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/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
}

View file

@ -0,0 +1,796 @@
// 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyEmailNuisanceOld is an object representing the database table.
type PublicreportNotifyEmailNuisanceOld 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 publicreportNotifyEmailNuisanceOldR `db:"-" `
}
// PublicreportNotifyEmailNuisanceOldSlice is an alias for a slice of pointers to PublicreportNotifyEmailNuisanceOld.
// This should almost always be used instead of []*PublicreportNotifyEmailNuisanceOld.
type PublicreportNotifyEmailNuisanceOldSlice []*PublicreportNotifyEmailNuisanceOld
// PublicreportNotifyEmailNuisanceOlds contains methods to work with the notify_email_nuisance_old table
var PublicreportNotifyEmailNuisanceOlds = psql.NewTablex[*PublicreportNotifyEmailNuisanceOld, PublicreportNotifyEmailNuisanceOldSlice, *PublicreportNotifyEmailNuisanceOldSetter]("publicreport", "notify_email_nuisance_old", buildPublicreportNotifyEmailNuisanceOldColumns("publicreport.notify_email_nuisance_old"))
// PublicreportNotifyEmailNuisanceOldsQuery is a query on the notify_email_nuisance_old table
type PublicreportNotifyEmailNuisanceOldsQuery = *psql.ViewQuery[*PublicreportNotifyEmailNuisanceOld, PublicreportNotifyEmailNuisanceOldSlice]
// publicreportNotifyEmailNuisanceOldR is where relationships are stored.
type publicreportNotifyEmailNuisanceOldR struct {
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_nuisance_old.notify_email_nuisance_email_address_fkey
NuisanceNuisanceOld *PublicreportNuisanceOld // publicreport.notify_email_nuisance_old.notify_email_nuisance_nuisance_id_fkey
}
func buildPublicreportNotifyEmailNuisanceOldColumns(alias string) publicreportNotifyEmailNuisanceOldColumns {
return publicreportNotifyEmailNuisanceOldColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "nuisance_id", "email_address",
).WithParent("publicreport.notify_email_nuisance_old"),
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 publicreportNotifyEmailNuisanceOldColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
NuisanceID psql.Expression
EmailAddress psql.Expression
}
func (c publicreportNotifyEmailNuisanceOldColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyEmailNuisanceOldColumns) AliasedAs(alias string) publicreportNotifyEmailNuisanceOldColumns {
return buildPublicreportNotifyEmailNuisanceOldColumns(alias)
}
// PublicreportNotifyEmailNuisanceOldSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyEmailNuisanceOldSetter 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 PublicreportNotifyEmailNuisanceOldSetter) 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 PublicreportNotifyEmailNuisanceOldSetter) Overwrite(t *PublicreportNotifyEmailNuisanceOld) {
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 *PublicreportNotifyEmailNuisanceOldSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyEmailNuisanceOlds.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 PublicreportNotifyEmailNuisanceOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyEmailNuisanceOldSetter) 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
}
// FindPublicreportNotifyEmailNuisanceOld retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyEmailNuisanceOld(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailNuisanceOld, error) {
if len(cols) == 0 {
return PublicreportNotifyEmailNuisanceOlds.Query(
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).One(ctx, exec)
}
return PublicreportNotifyEmailNuisanceOlds.Query(
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
sm.Columns(PublicreportNotifyEmailNuisanceOlds.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyEmailNuisanceOldExists checks the presence of a single record by primary key
func PublicreportNotifyEmailNuisanceOldExists(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, EmailAddressPK string) (bool, error) {
return PublicreportNotifyEmailNuisanceOlds.Query(
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyEmailNuisanceOld is retrieved from the database
func (o *PublicreportNotifyEmailNuisanceOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceOldSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceOldSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceOldSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailNuisanceOldSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailNuisanceOld
func (o *PublicreportNotifyEmailNuisanceOld) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.NuisanceID,
o.EmailAddress,
)
}
func (o *PublicreportNotifyEmailNuisanceOld) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_email_nuisance_old", "nuisance_id"), psql.Quote("publicreport.notify_email_nuisance_old", "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 PublicreportNotifyEmailNuisanceOld
func (o *PublicreportNotifyEmailNuisanceOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailNuisanceOldSetter) error {
v, err := PublicreportNotifyEmailNuisanceOlds.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 PublicreportNotifyEmailNuisanceOld record with an executor
func (o *PublicreportNotifyEmailNuisanceOld) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyEmailNuisanceOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyEmailNuisanceOld using the executor
func (o *PublicreportNotifyEmailNuisanceOld) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyEmailNuisanceOlds.Query(
sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(o.NuisanceID))),
sm.Where(PublicreportNotifyEmailNuisanceOlds.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 PublicreportNotifyEmailNuisanceOldSlice is retrieved from the database
func (o PublicreportNotifyEmailNuisanceOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyEmailNuisanceOldSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_email_nuisance_old", "nuisance_id"), psql.Quote("publicreport.notify_email_nuisance_old", "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 PublicreportNotifyEmailNuisanceOldSlice) copyMatchingRows(from ...*PublicreportNotifyEmailNuisanceOld) {
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 PublicreportNotifyEmailNuisanceOldSlice) 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 PublicreportNotifyEmailNuisanceOlds.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 *PublicreportNotifyEmailNuisanceOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailNuisanceOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailNuisanceOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailNuisanceOld or a slice of PublicreportNotifyEmailNuisanceOld
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyEmailNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailNuisanceOldSlice) 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 PublicreportNotifyEmailNuisanceOlds.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 *PublicreportNotifyEmailNuisanceOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailNuisanceOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailNuisanceOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailNuisanceOld or a slice of PublicreportNotifyEmailNuisanceOld
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyEmailNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyEmailNuisanceOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailNuisanceOldSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailNuisanceOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyEmailNuisanceOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailNuisanceOlds.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyEmailNuisanceOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyEmailNuisanceOlds.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 *PublicreportNotifyEmailNuisanceOld) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
return CommsEmailContacts.Query(append(mods,
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
)...)
}
func (os PublicreportNotifyEmailNuisanceOldSlice) 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)),
)...)
}
// NuisanceNuisanceOld starts a query for related objects on publicreport.nuisance_old
func (o *PublicreportNotifyEmailNuisanceOld) NuisanceNuisanceOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(o.NuisanceID))),
)...)
}
func (os PublicreportNotifyEmailNuisanceOldSlice) NuisanceNuisanceOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
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 PublicreportNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisanceOlds.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyEmailNuisanceOldEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisanceOld0 *PublicreportNotifyEmailNuisanceOld, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailNuisanceOld, error) {
setter := &PublicreportNotifyEmailNuisanceOldSetter{
EmailAddress: omit.From(commsEmailContact1.Address),
}
err := publicreportNotifyEmailNuisanceOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailNuisanceOldEmailAddressEmailContact0: %w", err)
}
return publicreportNotifyEmailNuisanceOld0, nil
}
func (publicreportNotifyEmailNuisanceOld0 *PublicreportNotifyEmailNuisanceOld) 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 = attachPublicreportNotifyEmailNuisanceOldEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailNuisanceOld0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailNuisanceOld0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailNuisanceOlds = append(commsEmailContact1.R.EmailAddressNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOld0)
return nil
}
func (publicreportNotifyEmailNuisanceOld0 *PublicreportNotifyEmailNuisanceOld) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
var err error
_, err = attachPublicreportNotifyEmailNuisanceOldEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailNuisanceOld0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailNuisanceOld0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailNuisanceOlds = append(commsEmailContact1.R.EmailAddressNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOld0)
return nil
}
func attachPublicreportNotifyEmailNuisanceOldNuisanceNuisanceOld0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisanceOld0 *PublicreportNotifyEmailNuisanceOld, publicreportNuisanceOld1 *PublicreportNuisanceOld) (*PublicreportNotifyEmailNuisanceOld, error) {
setter := &PublicreportNotifyEmailNuisanceOldSetter{
NuisanceID: omit.From(publicreportNuisanceOld1.ID),
}
err := publicreportNotifyEmailNuisanceOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailNuisanceOldNuisanceNuisanceOld0: %w", err)
}
return publicreportNotifyEmailNuisanceOld0, nil
}
func (publicreportNotifyEmailNuisanceOld0 *PublicreportNotifyEmailNuisanceOld) InsertNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, related *PublicreportNuisanceOldSetter) error {
var err error
publicreportNuisanceOld1, err := PublicreportNuisanceOlds.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyEmailNuisanceOldNuisanceNuisanceOld0(ctx, exec, 1, publicreportNotifyEmailNuisanceOld0, publicreportNuisanceOld1)
if err != nil {
return err
}
publicreportNotifyEmailNuisanceOld0.R.NuisanceNuisanceOld = publicreportNuisanceOld1
publicreportNuisanceOld1.R.NuisanceNotifyEmailNuisanceOlds = append(publicreportNuisanceOld1.R.NuisanceNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOld0)
return nil
}
func (publicreportNotifyEmailNuisanceOld0 *PublicreportNotifyEmailNuisanceOld) AttachNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, publicreportNuisanceOld1 *PublicreportNuisanceOld) error {
var err error
_, err = attachPublicreportNotifyEmailNuisanceOldNuisanceNuisanceOld0(ctx, exec, 1, publicreportNotifyEmailNuisanceOld0, publicreportNuisanceOld1)
if err != nil {
return err
}
publicreportNotifyEmailNuisanceOld0.R.NuisanceNuisanceOld = publicreportNuisanceOld1
publicreportNuisanceOld1.R.NuisanceNotifyEmailNuisanceOlds = append(publicreportNuisanceOld1.R.NuisanceNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOld0)
return nil
}
type publicreportNotifyEmailNuisanceOldWhere[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 (publicreportNotifyEmailNuisanceOldWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailNuisanceOldWhere[Q] {
return buildPublicreportNotifyEmailNuisanceOldWhere[Q](buildPublicreportNotifyEmailNuisanceOldColumns(alias))
}
func buildPublicreportNotifyEmailNuisanceOldWhere[Q psql.Filterable](cols publicreportNotifyEmailNuisanceOldColumns) publicreportNotifyEmailNuisanceOldWhere[Q] {
return publicreportNotifyEmailNuisanceOldWhere[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 *PublicreportNotifyEmailNuisanceOld) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "EmailAddressEmailContact":
rel, ok := retrieved.(*CommsEmailContact)
if !ok {
return fmt.Errorf("publicreportNotifyEmailNuisanceOld cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressEmailContact = rel
if rel != nil {
rel.R.EmailAddressNotifyEmailNuisanceOlds = PublicreportNotifyEmailNuisanceOldSlice{o}
}
return nil
case "NuisanceNuisanceOld":
rel, ok := retrieved.(*PublicreportNuisanceOld)
if !ok {
return fmt.Errorf("publicreportNotifyEmailNuisanceOld cannot load %T as %q", retrieved, name)
}
o.R.NuisanceNuisanceOld = rel
if rel != nil {
rel.R.NuisanceNotifyEmailNuisanceOlds = PublicreportNotifyEmailNuisanceOldSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyEmailNuisanceOld has no relationship %q", name)
}
}
type publicreportNotifyEmailNuisanceOldPreloader struct {
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
NuisanceNuisanceOld func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyEmailNuisanceOldPreloader() publicreportNotifyEmailNuisanceOldPreloader {
return publicreportNotifyEmailNuisanceOldPreloader{
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
Name: "EmailAddressEmailContact",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailNuisanceOlds,
To: CommsEmailContacts,
FromColumns: []string{"email_address"},
ToColumns: []string{"address"},
},
},
}, CommsEmailContacts.Columns.Names(), opts...)
},
NuisanceNuisanceOld: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportNuisanceOld, PublicreportNuisanceOldSlice](psql.PreloadRel{
Name: "NuisanceNuisanceOld",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailNuisanceOlds,
To: PublicreportNuisanceOlds,
FromColumns: []string{"nuisance_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportNuisanceOlds.Columns.Names(), opts...)
},
}
}
type publicreportNotifyEmailNuisanceOldThenLoader[Q orm.Loadable] struct {
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NuisanceNuisanceOld func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyEmailNuisanceOldThenLoader[Q orm.Loadable]() publicreportNotifyEmailNuisanceOldThenLoader[Q] {
type EmailAddressEmailContactLoadInterface interface {
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisanceNuisanceOldLoadInterface interface {
LoadNuisanceNuisanceOld(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyEmailNuisanceOldThenLoader[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...)
},
),
NuisanceNuisanceOld: thenLoadBuilder[Q](
"NuisanceNuisanceOld",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceNuisanceOldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisanceNuisanceOld(ctx, exec, mods...)
},
),
}
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailNuisanceOld's EmailAddressEmailContact into the .R struct
func (o *PublicreportNotifyEmailNuisanceOld) 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.EmailAddressNotifyEmailNuisanceOlds = PublicreportNotifyEmailNuisanceOldSlice{o}
o.R.EmailAddressEmailContact = related
return nil
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailNuisanceOld's EmailAddressEmailContact into the .R struct
func (os PublicreportNotifyEmailNuisanceOldSlice) 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.EmailAddressNotifyEmailNuisanceOlds = append(rel.R.EmailAddressNotifyEmailNuisanceOlds, o)
o.R.EmailAddressEmailContact = rel
break
}
}
return nil
}
// LoadNuisanceNuisanceOld loads the publicreportNotifyEmailNuisanceOld's NuisanceNuisanceOld into the .R struct
func (o *PublicreportNotifyEmailNuisanceOld) LoadNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.NuisanceNuisanceOld = nil
related, err := o.NuisanceNuisanceOld(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NuisanceNotifyEmailNuisanceOlds = PublicreportNotifyEmailNuisanceOldSlice{o}
o.R.NuisanceNuisanceOld = related
return nil
}
// LoadNuisanceNuisanceOld loads the publicreportNotifyEmailNuisanceOld's NuisanceNuisanceOld into the .R struct
func (os PublicreportNotifyEmailNuisanceOldSlice) LoadNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisanceOlds, err := os.NuisanceNuisanceOld(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNuisanceOlds {
if !(o.NuisanceID == rel.ID) {
continue
}
rel.R.NuisanceNotifyEmailNuisanceOlds = append(rel.R.NuisanceNotifyEmailNuisanceOlds, o)
o.R.NuisanceNuisanceOld = rel
break
}
}
return nil
}

View file

@ -1,796 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyEmailWater is an object representing the database table.
type PublicreportNotifyEmailWater struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
WaterID int32 `db:"water_id,pk" `
EmailAddress string `db:"email_address,pk" `
R publicreportNotifyEmailWaterR `db:"-" `
}
// PublicreportNotifyEmailWaterSlice is an alias for a slice of pointers to PublicreportNotifyEmailWater.
// This should almost always be used instead of []*PublicreportNotifyEmailWater.
type PublicreportNotifyEmailWaterSlice []*PublicreportNotifyEmailWater
// PublicreportNotifyEmailWaters contains methods to work with the notify_email_water table
var PublicreportNotifyEmailWaters = psql.NewTablex[*PublicreportNotifyEmailWater, PublicreportNotifyEmailWaterSlice, *PublicreportNotifyEmailWaterSetter]("publicreport", "notify_email_water", buildPublicreportNotifyEmailWaterColumns("publicreport.notify_email_water"))
// PublicreportNotifyEmailWatersQuery is a query on the notify_email_water table
type PublicreportNotifyEmailWatersQuery = *psql.ViewQuery[*PublicreportNotifyEmailWater, PublicreportNotifyEmailWaterSlice]
// publicreportNotifyEmailWaterR is where relationships are stored.
type publicreportNotifyEmailWaterR struct {
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_water.notify_email_pool_email_address_fkey
Water *PublicreportWater // publicreport.notify_email_water.notify_email_pool_pool_id_fkey
}
func buildPublicreportNotifyEmailWaterColumns(alias string) publicreportNotifyEmailWaterColumns {
return publicreportNotifyEmailWaterColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "water_id", "email_address",
).WithParent("publicreport.notify_email_water"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
WaterID: psql.Quote(alias, "water_id"),
EmailAddress: psql.Quote(alias, "email_address"),
}
}
type publicreportNotifyEmailWaterColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
WaterID psql.Expression
EmailAddress psql.Expression
}
func (c publicreportNotifyEmailWaterColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyEmailWaterColumns) AliasedAs(alias string) publicreportNotifyEmailWaterColumns {
return buildPublicreportNotifyEmailWaterColumns(alias)
}
// PublicreportNotifyEmailWaterSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyEmailWaterSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
WaterID omit.Val[int32] `db:"water_id,pk" `
EmailAddress omit.Val[string] `db:"email_address,pk" `
}
func (s PublicreportNotifyEmailWaterSetter) 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.WaterID.IsValue() {
vals = append(vals, "water_id")
}
if s.EmailAddress.IsValue() {
vals = append(vals, "email_address")
}
return vals
}
func (s PublicreportNotifyEmailWaterSetter) Overwrite(t *PublicreportNotifyEmailWater) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.WaterID.IsValue() {
t.WaterID = s.WaterID.MustGet()
}
if s.EmailAddress.IsValue() {
t.EmailAddress = s.EmailAddress.MustGet()
}
}
func (s *PublicreportNotifyEmailWaterSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyEmailWaters.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.WaterID.IsValue() {
vals[2] = psql.Arg(s.WaterID.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 PublicreportNotifyEmailWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyEmailWaterSetter) 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.WaterID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "water_id")...),
psql.Arg(s.WaterID),
}})
}
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
}
// FindPublicreportNotifyEmailWater retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyEmailWater(ctx context.Context, exec bob.Executor, WaterIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailWater, error) {
if len(cols) == 0 {
return PublicreportNotifyEmailWaters.Query(
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).One(ctx, exec)
}
return PublicreportNotifyEmailWaters.Query(
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
sm.Columns(PublicreportNotifyEmailWaters.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyEmailWaterExists checks the presence of a single record by primary key
func PublicreportNotifyEmailWaterExists(ctx context.Context, exec bob.Executor, WaterIDPK int32, EmailAddressPK string) (bool, error) {
return PublicreportNotifyEmailWaters.Query(
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyEmailWaters.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyEmailWater is retrieved from the database
func (o *PublicreportNotifyEmailWater) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailWaters.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailWaters.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailWaters.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailWaters.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailWater
func (o *PublicreportNotifyEmailWater) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.WaterID,
o.EmailAddress,
)
}
func (o *PublicreportNotifyEmailWater) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_email_water", "water_id"), psql.Quote("publicreport.notify_email_water", "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 PublicreportNotifyEmailWater
func (o *PublicreportNotifyEmailWater) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailWaterSetter) error {
v, err := PublicreportNotifyEmailWaters.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 PublicreportNotifyEmailWater record with an executor
func (o *PublicreportNotifyEmailWater) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyEmailWaters.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyEmailWater using the executor
func (o *PublicreportNotifyEmailWater) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyEmailWaters.Query(
sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
sm.Where(PublicreportNotifyEmailWaters.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 PublicreportNotifyEmailWaterSlice is retrieved from the database
func (o PublicreportNotifyEmailWaterSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailWaters.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailWaters.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyEmailWaterSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_email_water", "water_id"), psql.Quote("publicreport.notify_email_water", "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 PublicreportNotifyEmailWaterSlice) copyMatchingRows(from ...*PublicreportNotifyEmailWater) {
for i, old := range o {
for _, new := range from {
if new.WaterID != old.WaterID {
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 PublicreportNotifyEmailWaterSlice) 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 PublicreportNotifyEmailWaters.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 *PublicreportNotifyEmailWater:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailWater:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailWaterSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailWater or a slice of PublicreportNotifyEmailWater
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyEmailWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailWaterSlice) 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 PublicreportNotifyEmailWaters.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 *PublicreportNotifyEmailWater:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailWater:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailWaterSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailWater or a slice of PublicreportNotifyEmailWater
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyEmailWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyEmailWaterSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailWaterSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailWaters.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyEmailWaterSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailWaters.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyEmailWaterSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyEmailWaters.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 *PublicreportNotifyEmailWater) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
return CommsEmailContacts.Query(append(mods,
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
)...)
}
func (os PublicreportNotifyEmailWaterSlice) 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)),
)...)
}
// Water starts a query for related objects on publicreport.water
func (o *PublicreportNotifyEmailWater) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
return PublicreportWaters.Query(append(mods,
sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(o.WaterID))),
)...)
}
func (os PublicreportNotifyEmailWaterSlice) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkWaterID = append(pkWaterID, o.WaterID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
))
return PublicreportWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportWaters.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyEmailWaterEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailWater, error) {
setter := &PublicreportNotifyEmailWaterSetter{
EmailAddress: omit.From(commsEmailContact1.Address),
}
err := publicreportNotifyEmailWater0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailWaterEmailAddressEmailContact0: %w", err)
}
return publicreportNotifyEmailWater0, nil
}
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) 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 = attachPublicreportNotifyEmailWaterEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailWater0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailWater0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailWaters = append(commsEmailContact1.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWater0)
return nil
}
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
var err error
_, err = attachPublicreportNotifyEmailWaterEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailWater0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailWater0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailWaters = append(commsEmailContact1.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWater0)
return nil
}
func attachPublicreportNotifyEmailWaterWater0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater, publicreportWater1 *PublicreportWater) (*PublicreportNotifyEmailWater, error) {
setter := &PublicreportNotifyEmailWaterSetter{
WaterID: omit.From(publicreportWater1.ID),
}
err := publicreportNotifyEmailWater0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailWaterWater0: %w", err)
}
return publicreportNotifyEmailWater0, nil
}
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) InsertWater(ctx context.Context, exec bob.Executor, related *PublicreportWaterSetter) error {
var err error
publicreportWater1, err := PublicreportWaters.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyEmailWaterWater0(ctx, exec, 1, publicreportNotifyEmailWater0, publicreportWater1)
if err != nil {
return err
}
publicreportNotifyEmailWater0.R.Water = publicreportWater1
publicreportWater1.R.NotifyEmailWaters = append(publicreportWater1.R.NotifyEmailWaters, publicreportNotifyEmailWater0)
return nil
}
func (publicreportNotifyEmailWater0 *PublicreportNotifyEmailWater) AttachWater(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWater) error {
var err error
_, err = attachPublicreportNotifyEmailWaterWater0(ctx, exec, 1, publicreportNotifyEmailWater0, publicreportWater1)
if err != nil {
return err
}
publicreportNotifyEmailWater0.R.Water = publicreportWater1
publicreportWater1.R.NotifyEmailWaters = append(publicreportWater1.R.NotifyEmailWaters, publicreportNotifyEmailWater0)
return nil
}
type publicreportNotifyEmailWaterWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
WaterID psql.WhereMod[Q, int32]
EmailAddress psql.WhereMod[Q, string]
}
func (publicreportNotifyEmailWaterWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailWaterWhere[Q] {
return buildPublicreportNotifyEmailWaterWhere[Q](buildPublicreportNotifyEmailWaterColumns(alias))
}
func buildPublicreportNotifyEmailWaterWhere[Q psql.Filterable](cols publicreportNotifyEmailWaterColumns) publicreportNotifyEmailWaterWhere[Q] {
return publicreportNotifyEmailWaterWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
WaterID: psql.Where[Q, int32](cols.WaterID),
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
}
}
func (o *PublicreportNotifyEmailWater) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "EmailAddressEmailContact":
rel, ok := retrieved.(*CommsEmailContact)
if !ok {
return fmt.Errorf("publicreportNotifyEmailWater cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressEmailContact = rel
if rel != nil {
rel.R.EmailAddressNotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
}
return nil
case "Water":
rel, ok := retrieved.(*PublicreportWater)
if !ok {
return fmt.Errorf("publicreportNotifyEmailWater cannot load %T as %q", retrieved, name)
}
o.R.Water = rel
if rel != nil {
rel.R.NotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyEmailWater has no relationship %q", name)
}
}
type publicreportNotifyEmailWaterPreloader struct {
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
Water func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyEmailWaterPreloader() publicreportNotifyEmailWaterPreloader {
return publicreportNotifyEmailWaterPreloader{
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
Name: "EmailAddressEmailContact",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailWaters,
To: CommsEmailContacts,
FromColumns: []string{"email_address"},
ToColumns: []string{"address"},
},
},
}, CommsEmailContacts.Columns.Names(), opts...)
},
Water: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportWater, PublicreportWaterSlice](psql.PreloadRel{
Name: "Water",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailWaters,
To: PublicreportWaters,
FromColumns: []string{"water_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportWaters.Columns.Names(), opts...)
},
}
}
type publicreportNotifyEmailWaterThenLoader[Q orm.Loadable] struct {
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyEmailWaterThenLoader[Q orm.Loadable]() publicreportNotifyEmailWaterThenLoader[Q] {
type EmailAddressEmailContactLoadInterface interface {
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterLoadInterface interface {
LoadWater(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyEmailWaterThenLoader[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...)
},
),
Water: thenLoadBuilder[Q](
"Water",
func(ctx context.Context, exec bob.Executor, retrieved WaterLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWater(ctx, exec, mods...)
},
),
}
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailWater's EmailAddressEmailContact into the .R struct
func (o *PublicreportNotifyEmailWater) 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.EmailAddressNotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
o.R.EmailAddressEmailContact = related
return nil
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailWater's EmailAddressEmailContact into the .R struct
func (os PublicreportNotifyEmailWaterSlice) 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.EmailAddressNotifyEmailWaters = append(rel.R.EmailAddressNotifyEmailWaters, o)
o.R.EmailAddressEmailContact = rel
break
}
}
return nil
}
// LoadWater loads the publicreportNotifyEmailWater's Water into the .R struct
func (o *PublicreportNotifyEmailWater) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Water = nil
related, err := o.Water(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyEmailWaters = PublicreportNotifyEmailWaterSlice{o}
o.R.Water = related
return nil
}
// LoadWater loads the publicreportNotifyEmailWater's Water into the .R struct
func (os PublicreportNotifyEmailWaterSlice) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaters, err := os.Water(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaters {
if !(o.WaterID == rel.ID) {
continue
}
rel.R.NotifyEmailWaters = append(rel.R.NotifyEmailWaters, o)
o.R.Water = rel
break
}
}
return nil
}

View file

@ -0,0 +1,796 @@
// 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyEmailWaterOld is an object representing the database table.
type PublicreportNotifyEmailWaterOld struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
WaterID int32 `db:"water_id,pk" `
EmailAddress string `db:"email_address,pk" `
R publicreportNotifyEmailWaterOldR `db:"-" `
}
// PublicreportNotifyEmailWaterOldSlice is an alias for a slice of pointers to PublicreportNotifyEmailWaterOld.
// This should almost always be used instead of []*PublicreportNotifyEmailWaterOld.
type PublicreportNotifyEmailWaterOldSlice []*PublicreportNotifyEmailWaterOld
// PublicreportNotifyEmailWaterOlds contains methods to work with the notify_email_water_old table
var PublicreportNotifyEmailWaterOlds = psql.NewTablex[*PublicreportNotifyEmailWaterOld, PublicreportNotifyEmailWaterOldSlice, *PublicreportNotifyEmailWaterOldSetter]("publicreport", "notify_email_water_old", buildPublicreportNotifyEmailWaterOldColumns("publicreport.notify_email_water_old"))
// PublicreportNotifyEmailWaterOldsQuery is a query on the notify_email_water_old table
type PublicreportNotifyEmailWaterOldsQuery = *psql.ViewQuery[*PublicreportNotifyEmailWaterOld, PublicreportNotifyEmailWaterOldSlice]
// publicreportNotifyEmailWaterOldR is where relationships are stored.
type publicreportNotifyEmailWaterOldR struct {
EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_water_old.notify_email_pool_email_address_fkey
WaterWaterOld *PublicreportWaterOld // publicreport.notify_email_water_old.notify_email_pool_pool_id_fkey
}
func buildPublicreportNotifyEmailWaterOldColumns(alias string) publicreportNotifyEmailWaterOldColumns {
return publicreportNotifyEmailWaterOldColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "water_id", "email_address",
).WithParent("publicreport.notify_email_water_old"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
WaterID: psql.Quote(alias, "water_id"),
EmailAddress: psql.Quote(alias, "email_address"),
}
}
type publicreportNotifyEmailWaterOldColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
WaterID psql.Expression
EmailAddress psql.Expression
}
func (c publicreportNotifyEmailWaterOldColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyEmailWaterOldColumns) AliasedAs(alias string) publicreportNotifyEmailWaterOldColumns {
return buildPublicreportNotifyEmailWaterOldColumns(alias)
}
// PublicreportNotifyEmailWaterOldSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyEmailWaterOldSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
WaterID omit.Val[int32] `db:"water_id,pk" `
EmailAddress omit.Val[string] `db:"email_address,pk" `
}
func (s PublicreportNotifyEmailWaterOldSetter) 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.WaterID.IsValue() {
vals = append(vals, "water_id")
}
if s.EmailAddress.IsValue() {
vals = append(vals, "email_address")
}
return vals
}
func (s PublicreportNotifyEmailWaterOldSetter) Overwrite(t *PublicreportNotifyEmailWaterOld) {
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if s.WaterID.IsValue() {
t.WaterID = s.WaterID.MustGet()
}
if s.EmailAddress.IsValue() {
t.EmailAddress = s.EmailAddress.MustGet()
}
}
func (s *PublicreportNotifyEmailWaterOldSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyEmailWaterOlds.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.WaterID.IsValue() {
vals[2] = psql.Arg(s.WaterID.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 PublicreportNotifyEmailWaterOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyEmailWaterOldSetter) 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.WaterID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "water_id")...),
psql.Arg(s.WaterID),
}})
}
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
}
// FindPublicreportNotifyEmailWaterOld retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyEmailWaterOld(ctx context.Context, exec bob.Executor, WaterIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailWaterOld, error) {
if len(cols) == 0 {
return PublicreportNotifyEmailWaterOlds.Query(
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).One(ctx, exec)
}
return PublicreportNotifyEmailWaterOlds.Query(
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
sm.Columns(PublicreportNotifyEmailWaterOlds.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyEmailWaterOldExists checks the presence of a single record by primary key
func PublicreportNotifyEmailWaterOldExists(ctx context.Context, exec bob.Executor, WaterIDPK int32, EmailAddressPK string) (bool, error) {
return PublicreportNotifyEmailWaterOlds.Query(
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyEmailWaterOld is retrieved from the database
func (o *PublicreportNotifyEmailWaterOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterOldSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterOldSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterOldSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailWaterOldSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailWaterOld
func (o *PublicreportNotifyEmailWaterOld) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.WaterID,
o.EmailAddress,
)
}
func (o *PublicreportNotifyEmailWaterOld) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_email_water_old", "water_id"), psql.Quote("publicreport.notify_email_water_old", "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 PublicreportNotifyEmailWaterOld
func (o *PublicreportNotifyEmailWaterOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailWaterOldSetter) error {
v, err := PublicreportNotifyEmailWaterOlds.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 PublicreportNotifyEmailWaterOld record with an executor
func (o *PublicreportNotifyEmailWaterOld) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyEmailWaterOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyEmailWaterOld using the executor
func (o *PublicreportNotifyEmailWaterOld) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyEmailWaterOlds.Query(
sm.Where(PublicreportNotifyEmailWaterOlds.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
sm.Where(PublicreportNotifyEmailWaterOlds.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 PublicreportNotifyEmailWaterOldSlice is retrieved from the database
func (o PublicreportNotifyEmailWaterOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyEmailWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyEmailWaterOldSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_email_water_old", "water_id"), psql.Quote("publicreport.notify_email_water_old", "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 PublicreportNotifyEmailWaterOldSlice) copyMatchingRows(from ...*PublicreportNotifyEmailWaterOld) {
for i, old := range o {
for _, new := range from {
if new.WaterID != old.WaterID {
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 PublicreportNotifyEmailWaterOldSlice) 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 PublicreportNotifyEmailWaterOlds.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 *PublicreportNotifyEmailWaterOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailWaterOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailWaterOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailWaterOld or a slice of PublicreportNotifyEmailWaterOld
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyEmailWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyEmailWaterOldSlice) 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 PublicreportNotifyEmailWaterOlds.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 *PublicreportNotifyEmailWaterOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyEmailWaterOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyEmailWaterOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyEmailWaterOld or a slice of PublicreportNotifyEmailWaterOld
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyEmailWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyEmailWaterOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailWaterOldSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailWaterOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyEmailWaterOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyEmailWaterOlds.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyEmailWaterOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyEmailWaterOlds.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 *PublicreportNotifyEmailWaterOld) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery {
return CommsEmailContacts.Query(append(mods,
sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))),
)...)
}
func (os PublicreportNotifyEmailWaterOldSlice) 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)),
)...)
}
// WaterWaterOld starts a query for related objects on publicreport.water_old
func (o *PublicreportNotifyEmailWaterOld) WaterWaterOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
return PublicreportWaterOlds.Query(append(mods,
sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(o.WaterID))),
)...)
}
func (os PublicreportNotifyEmailWaterOldSlice) WaterWaterOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkWaterID = append(pkWaterID, o.WaterID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
))
return PublicreportWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportWaterOlds.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyEmailWaterOldEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaterOld0 *PublicreportNotifyEmailWaterOld, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailWaterOld, error) {
setter := &PublicreportNotifyEmailWaterOldSetter{
EmailAddress: omit.From(commsEmailContact1.Address),
}
err := publicreportNotifyEmailWaterOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailWaterOldEmailAddressEmailContact0: %w", err)
}
return publicreportNotifyEmailWaterOld0, nil
}
func (publicreportNotifyEmailWaterOld0 *PublicreportNotifyEmailWaterOld) 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 = attachPublicreportNotifyEmailWaterOldEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailWaterOld0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailWaterOld0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailWaterOlds = append(commsEmailContact1.R.EmailAddressNotifyEmailWaterOlds, publicreportNotifyEmailWaterOld0)
return nil
}
func (publicreportNotifyEmailWaterOld0 *PublicreportNotifyEmailWaterOld) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error {
var err error
_, err = attachPublicreportNotifyEmailWaterOldEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailWaterOld0, commsEmailContact1)
if err != nil {
return err
}
publicreportNotifyEmailWaterOld0.R.EmailAddressEmailContact = commsEmailContact1
commsEmailContact1.R.EmailAddressNotifyEmailWaterOlds = append(commsEmailContact1.R.EmailAddressNotifyEmailWaterOlds, publicreportNotifyEmailWaterOld0)
return nil
}
func attachPublicreportNotifyEmailWaterOldWaterWaterOld0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaterOld0 *PublicreportNotifyEmailWaterOld, publicreportWaterOld1 *PublicreportWaterOld) (*PublicreportNotifyEmailWaterOld, error) {
setter := &PublicreportNotifyEmailWaterOldSetter{
WaterID: omit.From(publicreportWaterOld1.ID),
}
err := publicreportNotifyEmailWaterOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyEmailWaterOldWaterWaterOld0: %w", err)
}
return publicreportNotifyEmailWaterOld0, nil
}
func (publicreportNotifyEmailWaterOld0 *PublicreportNotifyEmailWaterOld) InsertWaterWaterOld(ctx context.Context, exec bob.Executor, related *PublicreportWaterOldSetter) error {
var err error
publicreportWaterOld1, err := PublicreportWaterOlds.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyEmailWaterOldWaterWaterOld0(ctx, exec, 1, publicreportNotifyEmailWaterOld0, publicreportWaterOld1)
if err != nil {
return err
}
publicreportNotifyEmailWaterOld0.R.WaterWaterOld = publicreportWaterOld1
publicreportWaterOld1.R.WaterNotifyEmailWaterOlds = append(publicreportWaterOld1.R.WaterNotifyEmailWaterOlds, publicreportNotifyEmailWaterOld0)
return nil
}
func (publicreportNotifyEmailWaterOld0 *PublicreportNotifyEmailWaterOld) AttachWaterWaterOld(ctx context.Context, exec bob.Executor, publicreportWaterOld1 *PublicreportWaterOld) error {
var err error
_, err = attachPublicreportNotifyEmailWaterOldWaterWaterOld0(ctx, exec, 1, publicreportNotifyEmailWaterOld0, publicreportWaterOld1)
if err != nil {
return err
}
publicreportNotifyEmailWaterOld0.R.WaterWaterOld = publicreportWaterOld1
publicreportWaterOld1.R.WaterNotifyEmailWaterOlds = append(publicreportWaterOld1.R.WaterNotifyEmailWaterOlds, publicreportNotifyEmailWaterOld0)
return nil
}
type publicreportNotifyEmailWaterOldWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
WaterID psql.WhereMod[Q, int32]
EmailAddress psql.WhereMod[Q, string]
}
func (publicreportNotifyEmailWaterOldWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailWaterOldWhere[Q] {
return buildPublicreportNotifyEmailWaterOldWhere[Q](buildPublicreportNotifyEmailWaterOldColumns(alias))
}
func buildPublicreportNotifyEmailWaterOldWhere[Q psql.Filterable](cols publicreportNotifyEmailWaterOldColumns) publicreportNotifyEmailWaterOldWhere[Q] {
return publicreportNotifyEmailWaterOldWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
WaterID: psql.Where[Q, int32](cols.WaterID),
EmailAddress: psql.Where[Q, string](cols.EmailAddress),
}
}
func (o *PublicreportNotifyEmailWaterOld) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "EmailAddressEmailContact":
rel, ok := retrieved.(*CommsEmailContact)
if !ok {
return fmt.Errorf("publicreportNotifyEmailWaterOld cannot load %T as %q", retrieved, name)
}
o.R.EmailAddressEmailContact = rel
if rel != nil {
rel.R.EmailAddressNotifyEmailWaterOlds = PublicreportNotifyEmailWaterOldSlice{o}
}
return nil
case "WaterWaterOld":
rel, ok := retrieved.(*PublicreportWaterOld)
if !ok {
return fmt.Errorf("publicreportNotifyEmailWaterOld cannot load %T as %q", retrieved, name)
}
o.R.WaterWaterOld = rel
if rel != nil {
rel.R.WaterNotifyEmailWaterOlds = PublicreportNotifyEmailWaterOldSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyEmailWaterOld has no relationship %q", name)
}
}
type publicreportNotifyEmailWaterOldPreloader struct {
EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader
WaterWaterOld func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyEmailWaterOldPreloader() publicreportNotifyEmailWaterOldPreloader {
return publicreportNotifyEmailWaterOldPreloader{
EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{
Name: "EmailAddressEmailContact",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailWaterOlds,
To: CommsEmailContacts,
FromColumns: []string{"email_address"},
ToColumns: []string{"address"},
},
},
}, CommsEmailContacts.Columns.Names(), opts...)
},
WaterWaterOld: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportWaterOld, PublicreportWaterOldSlice](psql.PreloadRel{
Name: "WaterWaterOld",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyEmailWaterOlds,
To: PublicreportWaterOlds,
FromColumns: []string{"water_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportWaterOlds.Columns.Names(), opts...)
},
}
}
type publicreportNotifyEmailWaterOldThenLoader[Q orm.Loadable] struct {
EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
WaterWaterOld func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyEmailWaterOldThenLoader[Q orm.Loadable]() publicreportNotifyEmailWaterOldThenLoader[Q] {
type EmailAddressEmailContactLoadInterface interface {
LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterWaterOldLoadInterface interface {
LoadWaterWaterOld(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyEmailWaterOldThenLoader[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...)
},
),
WaterWaterOld: thenLoadBuilder[Q](
"WaterWaterOld",
func(ctx context.Context, exec bob.Executor, retrieved WaterWaterOldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaterWaterOld(ctx, exec, mods...)
},
),
}
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailWaterOld's EmailAddressEmailContact into the .R struct
func (o *PublicreportNotifyEmailWaterOld) 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.EmailAddressNotifyEmailWaterOlds = PublicreportNotifyEmailWaterOldSlice{o}
o.R.EmailAddressEmailContact = related
return nil
}
// LoadEmailAddressEmailContact loads the publicreportNotifyEmailWaterOld's EmailAddressEmailContact into the .R struct
func (os PublicreportNotifyEmailWaterOldSlice) 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.EmailAddressNotifyEmailWaterOlds = append(rel.R.EmailAddressNotifyEmailWaterOlds, o)
o.R.EmailAddressEmailContact = rel
break
}
}
return nil
}
// LoadWaterWaterOld loads the publicreportNotifyEmailWaterOld's WaterWaterOld into the .R struct
func (o *PublicreportNotifyEmailWaterOld) LoadWaterWaterOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.WaterWaterOld = nil
related, err := o.WaterWaterOld(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.WaterNotifyEmailWaterOlds = PublicreportNotifyEmailWaterOldSlice{o}
o.R.WaterWaterOld = related
return nil
}
// LoadWaterWaterOld loads the publicreportNotifyEmailWaterOld's WaterWaterOld into the .R struct
func (os PublicreportNotifyEmailWaterOldSlice) LoadWaterWaterOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaterOlds, err := os.WaterWaterOld(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaterOlds {
if !(o.WaterID == rel.ID) {
continue
}
rel.R.WaterNotifyEmailWaterOlds = append(rel.R.WaterNotifyEmailWaterOlds, o)
o.R.WaterWaterOld = rel
break
}
}
return nil
}

View file

@ -0,0 +1,796 @@
// 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyPhone is an object representing the database table.
type PublicreportNotifyPhone struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
PhoneE164 string `db:"phone_e164,pk" `
ReportID int32 `db:"report_id,pk" `
R publicreportNotifyPhoneR `db:"-" `
}
// PublicreportNotifyPhoneSlice is an alias for a slice of pointers to PublicreportNotifyPhone.
// This should almost always be used instead of []*PublicreportNotifyPhone.
type PublicreportNotifyPhoneSlice []*PublicreportNotifyPhone
// PublicreportNotifyPhones contains methods to work with the notify_phone table
var PublicreportNotifyPhones = psql.NewTablex[*PublicreportNotifyPhone, PublicreportNotifyPhoneSlice, *PublicreportNotifyPhoneSetter]("publicreport", "notify_phone", buildPublicreportNotifyPhoneColumns("publicreport.notify_phone"))
// PublicreportNotifyPhonesQuery is a query on the notify_phone table
type PublicreportNotifyPhonesQuery = *psql.ViewQuery[*PublicreportNotifyPhone, PublicreportNotifyPhoneSlice]
// publicreportNotifyPhoneR is where relationships are stored.
type publicreportNotifyPhoneR struct {
PhoneE164Phone *CommsPhone // publicreport.notify_phone.notify_phone_phone_e164_fkey
Report *PublicreportReport // publicreport.notify_phone.notify_phone_report_id_fkey
}
func buildPublicreportNotifyPhoneColumns(alias string) publicreportNotifyPhoneColumns {
return publicreportNotifyPhoneColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "phone_e164", "report_id",
).WithParent("publicreport.notify_phone"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
PhoneE164: psql.Quote(alias, "phone_e164"),
ReportID: psql.Quote(alias, "report_id"),
}
}
type publicreportNotifyPhoneColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
PhoneE164 psql.Expression
ReportID psql.Expression
}
func (c publicreportNotifyPhoneColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyPhoneColumns) AliasedAs(alias string) publicreportNotifyPhoneColumns {
return buildPublicreportNotifyPhoneColumns(alias)
}
// PublicreportNotifyPhoneSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyPhoneSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
ReportID omit.Val[int32] `db:"report_id,pk" `
}
func (s PublicreportNotifyPhoneSetter) 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.ReportID.IsValue() {
vals = append(vals, "report_id")
}
return vals
}
func (s PublicreportNotifyPhoneSetter) Overwrite(t *PublicreportNotifyPhone) {
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.ReportID.IsValue() {
t.ReportID = s.ReportID.MustGet()
}
}
func (s *PublicreportNotifyPhoneSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyPhones.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.ReportID.IsValue() {
vals[3] = psql.Arg(s.ReportID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyPhoneSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyPhoneSetter) 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.ReportID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "report_id")...),
psql.Arg(s.ReportID),
}})
}
return exprs
}
// FindPublicreportNotifyPhone retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyPhone(ctx context.Context, exec bob.Executor, ReportIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhone, error) {
if len(cols) == 0 {
return PublicreportNotifyPhones.Query(
sm.Where(PublicreportNotifyPhones.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(PublicreportNotifyPhones.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).One(ctx, exec)
}
return PublicreportNotifyPhones.Query(
sm.Where(PublicreportNotifyPhones.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(PublicreportNotifyPhones.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
sm.Columns(PublicreportNotifyPhones.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyPhoneExists checks the presence of a single record by primary key
func PublicreportNotifyPhoneExists(ctx context.Context, exec bob.Executor, ReportIDPK int32, PhoneE164PK string) (bool, error) {
return PublicreportNotifyPhones.Query(
sm.Where(PublicreportNotifyPhones.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(PublicreportNotifyPhones.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyPhone is retrieved from the database
func (o *PublicreportNotifyPhone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhones.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhones.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhones.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhones.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhone
func (o *PublicreportNotifyPhone) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ReportID,
o.PhoneE164,
)
}
func (o *PublicreportNotifyPhone) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_phone", "report_id"), psql.Quote("publicreport.notify_phone", "phone_e164")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNotifyPhone
func (o *PublicreportNotifyPhone) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhoneSetter) error {
v, err := PublicreportNotifyPhones.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 PublicreportNotifyPhone record with an executor
func (o *PublicreportNotifyPhone) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyPhones.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyPhone using the executor
func (o *PublicreportNotifyPhone) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyPhones.Query(
sm.Where(PublicreportNotifyPhones.Columns.ReportID.EQ(psql.Arg(o.ReportID))),
sm.Where(PublicreportNotifyPhones.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 PublicreportNotifyPhoneSlice is retrieved from the database
func (o PublicreportNotifyPhoneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhones.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhones.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhones.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhones.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyPhoneSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_phone", "report_id"), psql.Quote("publicreport.notify_phone", "phone_e164")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNotifyPhoneSlice) copyMatchingRows(from ...*PublicreportNotifyPhone) {
for i, old := range o {
for _, new := range from {
if new.ReportID != old.ReportID {
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 PublicreportNotifyPhoneSlice) 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 PublicreportNotifyPhones.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 *PublicreportNotifyPhone:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhone:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhone or a slice of PublicreportNotifyPhone
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyPhones.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhoneSlice) 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 PublicreportNotifyPhones.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 *PublicreportNotifyPhone:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhone:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhone or a slice of PublicreportNotifyPhone
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyPhones.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyPhoneSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhoneSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhones.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhones.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyPhones.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 *PublicreportNotifyPhone) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
)...)
}
func (os PublicreportNotifyPhoneSlice) 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)),
)...)
}
// Report starts a query for related objects on publicreport.report
func (o *PublicreportNotifyPhone) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))),
)...)
}
func (os PublicreportNotifyPhoneSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkReportID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkReportID = append(pkReportID, o.ReportID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")),
))
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyPhonePhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhone0 *PublicreportNotifyPhone, commsPhone1 *CommsPhone) (*PublicreportNotifyPhone, error) {
setter := &PublicreportNotifyPhoneSetter{
PhoneE164: omit.From(commsPhone1.E164),
}
err := publicreportNotifyPhone0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhonePhoneE164Phone0: %w", err)
}
return publicreportNotifyPhone0, nil
}
func (publicreportNotifyPhone0 *PublicreportNotifyPhone) 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 = attachPublicreportNotifyPhonePhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhone0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhone0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhones = append(commsPhone1.R.PhoneE164NotifyPhones, publicreportNotifyPhone0)
return nil
}
func (publicreportNotifyPhone0 *PublicreportNotifyPhone) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachPublicreportNotifyPhonePhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhone0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhone0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhones = append(commsPhone1.R.PhoneE164NotifyPhones, publicreportNotifyPhone0)
return nil
}
func attachPublicreportNotifyPhoneReport0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhone0 *PublicreportNotifyPhone, publicreportReport1 *PublicreportReport) (*PublicreportNotifyPhone, error) {
setter := &PublicreportNotifyPhoneSetter{
ReportID: omit.From(publicreportReport1.ID),
}
err := publicreportNotifyPhone0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneReport0: %w", err)
}
return publicreportNotifyPhone0, nil
}
func (publicreportNotifyPhone0 *PublicreportNotifyPhone) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error {
var err error
publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyPhoneReport0(ctx, exec, 1, publicreportNotifyPhone0, publicreportReport1)
if err != nil {
return err
}
publicreportNotifyPhone0.R.Report = publicreportReport1
publicreportReport1.R.NotifyPhones = append(publicreportReport1.R.NotifyPhones, publicreportNotifyPhone0)
return nil
}
func (publicreportNotifyPhone0 *PublicreportNotifyPhone) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error {
var err error
_, err = attachPublicreportNotifyPhoneReport0(ctx, exec, 1, publicreportNotifyPhone0, publicreportReport1)
if err != nil {
return err
}
publicreportNotifyPhone0.R.Report = publicreportReport1
publicreportReport1.R.NotifyPhones = append(publicreportReport1.R.NotifyPhones, publicreportNotifyPhone0)
return nil
}
type publicreportNotifyPhoneWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
PhoneE164 psql.WhereMod[Q, string]
ReportID psql.WhereMod[Q, int32]
}
func (publicreportNotifyPhoneWhere[Q]) AliasedAs(alias string) publicreportNotifyPhoneWhere[Q] {
return buildPublicreportNotifyPhoneWhere[Q](buildPublicreportNotifyPhoneColumns(alias))
}
func buildPublicreportNotifyPhoneWhere[Q psql.Filterable](cols publicreportNotifyPhoneColumns) publicreportNotifyPhoneWhere[Q] {
return publicreportNotifyPhoneWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
ReportID: psql.Where[Q, int32](cols.ReportID),
}
}
func (o *PublicreportNotifyPhone) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "PhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("publicreportNotifyPhone cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164Phone = rel
if rel != nil {
rel.R.PhoneE164NotifyPhones = PublicreportNotifyPhoneSlice{o}
}
return nil
case "Report":
rel, ok := retrieved.(*PublicreportReport)
if !ok {
return fmt.Errorf("publicreportNotifyPhone cannot load %T as %q", retrieved, name)
}
o.R.Report = rel
if rel != nil {
rel.R.NotifyPhones = PublicreportNotifyPhoneSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyPhone has no relationship %q", name)
}
}
type publicreportNotifyPhonePreloader struct {
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
Report func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyPhonePreloader() publicreportNotifyPhonePreloader {
return publicreportNotifyPhonePreloader{
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhones,
To: CommsPhones,
FromColumns: []string{"phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
Report: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{
Name: "Report",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhones,
To: PublicreportReports,
FromColumns: []string{"report_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportReports.Columns.Names(), opts...)
},
}
}
type publicreportNotifyPhoneThenLoader[Q orm.Loadable] struct {
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyPhoneThenLoader[Q orm.Loadable]() publicreportNotifyPhoneThenLoader[Q] {
type PhoneE164PhoneLoadInterface interface {
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReportLoadInterface interface {
LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyPhoneThenLoader[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...)
},
),
Report: thenLoadBuilder[Q](
"Report",
func(ctx context.Context, exec bob.Executor, retrieved ReportLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReport(ctx, exec, mods...)
},
),
}
}
// LoadPhoneE164Phone loads the publicreportNotifyPhone's PhoneE164Phone into the .R struct
func (o *PublicreportNotifyPhone) 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.PhoneE164NotifyPhones = PublicreportNotifyPhoneSlice{o}
o.R.PhoneE164Phone = related
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhone's PhoneE164Phone into the .R struct
func (os PublicreportNotifyPhoneSlice) 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.PhoneE164NotifyPhones = append(rel.R.PhoneE164NotifyPhones, o)
o.R.PhoneE164Phone = rel
break
}
}
return nil
}
// LoadReport loads the publicreportNotifyPhone's Report into the .R struct
func (o *PublicreportNotifyPhone) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Report = nil
related, err := o.Report(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyPhones = PublicreportNotifyPhoneSlice{o}
o.R.Report = related
return nil
}
// LoadReport loads the publicreportNotifyPhone's Report into the .R struct
func (os PublicreportNotifyPhoneSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportReports, err := os.Report(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportReports {
if !(o.ReportID == rel.ID) {
continue
}
rel.R.NotifyPhones = append(rel.R.NotifyPhones, o)
o.R.Report = rel
break
}
}
return nil
}

View file

@ -1,796 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package 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/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
}

View file

@ -0,0 +1,796 @@
// 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyPhoneNuisanceOld is an object representing the database table.
type PublicreportNotifyPhoneNuisanceOld 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 publicreportNotifyPhoneNuisanceOldR `db:"-" `
}
// PublicreportNotifyPhoneNuisanceOldSlice is an alias for a slice of pointers to PublicreportNotifyPhoneNuisanceOld.
// This should almost always be used instead of []*PublicreportNotifyPhoneNuisanceOld.
type PublicreportNotifyPhoneNuisanceOldSlice []*PublicreportNotifyPhoneNuisanceOld
// PublicreportNotifyPhoneNuisanceOlds contains methods to work with the notify_phone_nuisance_old table
var PublicreportNotifyPhoneNuisanceOlds = psql.NewTablex[*PublicreportNotifyPhoneNuisanceOld, PublicreportNotifyPhoneNuisanceOldSlice, *PublicreportNotifyPhoneNuisanceOldSetter]("publicreport", "notify_phone_nuisance_old", buildPublicreportNotifyPhoneNuisanceOldColumns("publicreport.notify_phone_nuisance_old"))
// PublicreportNotifyPhoneNuisanceOldsQuery is a query on the notify_phone_nuisance_old table
type PublicreportNotifyPhoneNuisanceOldsQuery = *psql.ViewQuery[*PublicreportNotifyPhoneNuisanceOld, PublicreportNotifyPhoneNuisanceOldSlice]
// publicreportNotifyPhoneNuisanceOldR is where relationships are stored.
type publicreportNotifyPhoneNuisanceOldR struct {
NuisanceNuisanceOld *PublicreportNuisanceOld // publicreport.notify_phone_nuisance_old.notify_phone_nuisance_nuisance_id_fkey
PhoneE164Phone *CommsPhone // publicreport.notify_phone_nuisance_old.notify_phone_nuisance_phone_e164_fkey
}
func buildPublicreportNotifyPhoneNuisanceOldColumns(alias string) publicreportNotifyPhoneNuisanceOldColumns {
return publicreportNotifyPhoneNuisanceOldColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "nuisance_id", "phone_e164",
).WithParent("publicreport.notify_phone_nuisance_old"),
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 publicreportNotifyPhoneNuisanceOldColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
NuisanceID psql.Expression
PhoneE164 psql.Expression
}
func (c publicreportNotifyPhoneNuisanceOldColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyPhoneNuisanceOldColumns) AliasedAs(alias string) publicreportNotifyPhoneNuisanceOldColumns {
return buildPublicreportNotifyPhoneNuisanceOldColumns(alias)
}
// PublicreportNotifyPhoneNuisanceOldSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyPhoneNuisanceOldSetter 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 PublicreportNotifyPhoneNuisanceOldSetter) 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 PublicreportNotifyPhoneNuisanceOldSetter) Overwrite(t *PublicreportNotifyPhoneNuisanceOld) {
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 *PublicreportNotifyPhoneNuisanceOldSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyPhoneNuisanceOlds.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 PublicreportNotifyPhoneNuisanceOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyPhoneNuisanceOldSetter) 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
}
// FindPublicreportNotifyPhoneNuisanceOld retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyPhoneNuisanceOld(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhoneNuisanceOld, error) {
if len(cols) == 0 {
return PublicreportNotifyPhoneNuisanceOlds.Query(
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).One(ctx, exec)
}
return PublicreportNotifyPhoneNuisanceOlds.Query(
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
sm.Columns(PublicreportNotifyPhoneNuisanceOlds.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyPhoneNuisanceOldExists checks the presence of a single record by primary key
func PublicreportNotifyPhoneNuisanceOldExists(ctx context.Context, exec bob.Executor, NuisanceIDPK int32, PhoneE164PK string) (bool, error) {
return PublicreportNotifyPhoneNuisanceOlds.Query(
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyPhoneNuisanceOld is retrieved from the database
func (o *PublicreportNotifyPhoneNuisanceOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceOldSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceOldSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceOldSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneNuisanceOldSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhoneNuisanceOld
func (o *PublicreportNotifyPhoneNuisanceOld) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.NuisanceID,
o.PhoneE164,
)
}
func (o *PublicreportNotifyPhoneNuisanceOld) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_phone_nuisance_old", "nuisance_id"), psql.Quote("publicreport.notify_phone_nuisance_old", "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 PublicreportNotifyPhoneNuisanceOld
func (o *PublicreportNotifyPhoneNuisanceOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhoneNuisanceOldSetter) error {
v, err := PublicreportNotifyPhoneNuisanceOlds.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 PublicreportNotifyPhoneNuisanceOld record with an executor
func (o *PublicreportNotifyPhoneNuisanceOld) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyPhoneNuisanceOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyPhoneNuisanceOld using the executor
func (o *PublicreportNotifyPhoneNuisanceOld) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyPhoneNuisanceOlds.Query(
sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(o.NuisanceID))),
sm.Where(PublicreportNotifyPhoneNuisanceOlds.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 PublicreportNotifyPhoneNuisanceOldSlice is retrieved from the database
func (o PublicreportNotifyPhoneNuisanceOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyPhoneNuisanceOldSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_phone_nuisance_old", "nuisance_id"), psql.Quote("publicreport.notify_phone_nuisance_old", "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 PublicreportNotifyPhoneNuisanceOldSlice) copyMatchingRows(from ...*PublicreportNotifyPhoneNuisanceOld) {
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 PublicreportNotifyPhoneNuisanceOldSlice) 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 PublicreportNotifyPhoneNuisanceOlds.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 *PublicreportNotifyPhoneNuisanceOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneNuisanceOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneNuisanceOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneNuisanceOld or a slice of PublicreportNotifyPhoneNuisanceOld
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyPhoneNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhoneNuisanceOldSlice) 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 PublicreportNotifyPhoneNuisanceOlds.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 *PublicreportNotifyPhoneNuisanceOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneNuisanceOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneNuisanceOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneNuisanceOld or a slice of PublicreportNotifyPhoneNuisanceOld
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyPhoneNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyPhoneNuisanceOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhoneNuisanceOldSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneNuisanceOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneNuisanceOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneNuisanceOlds.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneNuisanceOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyPhoneNuisanceOlds.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// NuisanceNuisanceOld starts a query for related objects on publicreport.nuisance_old
func (o *PublicreportNotifyPhoneNuisanceOld) NuisanceNuisanceOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(o.NuisanceID))),
)...)
}
func (os PublicreportNotifyPhoneNuisanceOldSlice) NuisanceNuisanceOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
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 PublicreportNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisanceOlds.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// PhoneE164Phone starts a query for related objects on comms.phone
func (o *PublicreportNotifyPhoneNuisanceOld) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
)...)
}
func (os PublicreportNotifyPhoneNuisanceOldSlice) 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 attachPublicreportNotifyPhoneNuisanceOldNuisanceNuisanceOld0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisanceOld0 *PublicreportNotifyPhoneNuisanceOld, publicreportNuisanceOld1 *PublicreportNuisanceOld) (*PublicreportNotifyPhoneNuisanceOld, error) {
setter := &PublicreportNotifyPhoneNuisanceOldSetter{
NuisanceID: omit.From(publicreportNuisanceOld1.ID),
}
err := publicreportNotifyPhoneNuisanceOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneNuisanceOldNuisanceNuisanceOld0: %w", err)
}
return publicreportNotifyPhoneNuisanceOld0, nil
}
func (publicreportNotifyPhoneNuisanceOld0 *PublicreportNotifyPhoneNuisanceOld) InsertNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, related *PublicreportNuisanceOldSetter) error {
var err error
publicreportNuisanceOld1, err := PublicreportNuisanceOlds.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyPhoneNuisanceOldNuisanceNuisanceOld0(ctx, exec, 1, publicreportNotifyPhoneNuisanceOld0, publicreportNuisanceOld1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisanceOld0.R.NuisanceNuisanceOld = publicreportNuisanceOld1
publicreportNuisanceOld1.R.NuisanceNotifyPhoneNuisanceOlds = append(publicreportNuisanceOld1.R.NuisanceNotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOld0)
return nil
}
func (publicreportNotifyPhoneNuisanceOld0 *PublicreportNotifyPhoneNuisanceOld) AttachNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, publicreportNuisanceOld1 *PublicreportNuisanceOld) error {
var err error
_, err = attachPublicreportNotifyPhoneNuisanceOldNuisanceNuisanceOld0(ctx, exec, 1, publicreportNotifyPhoneNuisanceOld0, publicreportNuisanceOld1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisanceOld0.R.NuisanceNuisanceOld = publicreportNuisanceOld1
publicreportNuisanceOld1.R.NuisanceNotifyPhoneNuisanceOlds = append(publicreportNuisanceOld1.R.NuisanceNotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOld0)
return nil
}
func attachPublicreportNotifyPhoneNuisanceOldPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisanceOld0 *PublicreportNotifyPhoneNuisanceOld, commsPhone1 *CommsPhone) (*PublicreportNotifyPhoneNuisanceOld, error) {
setter := &PublicreportNotifyPhoneNuisanceOldSetter{
PhoneE164: omit.From(commsPhone1.E164),
}
err := publicreportNotifyPhoneNuisanceOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneNuisanceOldPhoneE164Phone0: %w", err)
}
return publicreportNotifyPhoneNuisanceOld0, nil
}
func (publicreportNotifyPhoneNuisanceOld0 *PublicreportNotifyPhoneNuisanceOld) 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 = attachPublicreportNotifyPhoneNuisanceOldPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneNuisanceOld0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisanceOld0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneNuisanceOlds = append(commsPhone1.R.PhoneE164NotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOld0)
return nil
}
func (publicreportNotifyPhoneNuisanceOld0 *PublicreportNotifyPhoneNuisanceOld) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachPublicreportNotifyPhoneNuisanceOldPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneNuisanceOld0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneNuisanceOld0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneNuisanceOlds = append(commsPhone1.R.PhoneE164NotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOld0)
return nil
}
type publicreportNotifyPhoneNuisanceOldWhere[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 (publicreportNotifyPhoneNuisanceOldWhere[Q]) AliasedAs(alias string) publicreportNotifyPhoneNuisanceOldWhere[Q] {
return buildPublicreportNotifyPhoneNuisanceOldWhere[Q](buildPublicreportNotifyPhoneNuisanceOldColumns(alias))
}
func buildPublicreportNotifyPhoneNuisanceOldWhere[Q psql.Filterable](cols publicreportNotifyPhoneNuisanceOldColumns) publicreportNotifyPhoneNuisanceOldWhere[Q] {
return publicreportNotifyPhoneNuisanceOldWhere[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 *PublicreportNotifyPhoneNuisanceOld) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "NuisanceNuisanceOld":
rel, ok := retrieved.(*PublicreportNuisanceOld)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneNuisanceOld cannot load %T as %q", retrieved, name)
}
o.R.NuisanceNuisanceOld = rel
if rel != nil {
rel.R.NuisanceNotifyPhoneNuisanceOlds = PublicreportNotifyPhoneNuisanceOldSlice{o}
}
return nil
case "PhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneNuisanceOld cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164Phone = rel
if rel != nil {
rel.R.PhoneE164NotifyPhoneNuisanceOlds = PublicreportNotifyPhoneNuisanceOldSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyPhoneNuisanceOld has no relationship %q", name)
}
}
type publicreportNotifyPhoneNuisanceOldPreloader struct {
NuisanceNuisanceOld func(...psql.PreloadOption) psql.Preloader
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyPhoneNuisanceOldPreloader() publicreportNotifyPhoneNuisanceOldPreloader {
return publicreportNotifyPhoneNuisanceOldPreloader{
NuisanceNuisanceOld: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportNuisanceOld, PublicreportNuisanceOldSlice](psql.PreloadRel{
Name: "NuisanceNuisanceOld",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneNuisanceOlds,
To: PublicreportNuisanceOlds,
FromColumns: []string{"nuisance_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportNuisanceOlds.Columns.Names(), opts...)
},
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneNuisanceOlds,
To: CommsPhones,
FromColumns: []string{"phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
}
}
type publicreportNotifyPhoneNuisanceOldThenLoader[Q orm.Loadable] struct {
NuisanceNuisanceOld func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyPhoneNuisanceOldThenLoader[Q orm.Loadable]() publicreportNotifyPhoneNuisanceOldThenLoader[Q] {
type NuisanceNuisanceOldLoadInterface interface {
LoadNuisanceNuisanceOld(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PhoneE164PhoneLoadInterface interface {
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyPhoneNuisanceOldThenLoader[Q]{
NuisanceNuisanceOld: thenLoadBuilder[Q](
"NuisanceNuisanceOld",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceNuisanceOldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisanceNuisanceOld(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...)
},
),
}
}
// LoadNuisanceNuisanceOld loads the publicreportNotifyPhoneNuisanceOld's NuisanceNuisanceOld into the .R struct
func (o *PublicreportNotifyPhoneNuisanceOld) LoadNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.NuisanceNuisanceOld = nil
related, err := o.NuisanceNuisanceOld(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NuisanceNotifyPhoneNuisanceOlds = PublicreportNotifyPhoneNuisanceOldSlice{o}
o.R.NuisanceNuisanceOld = related
return nil
}
// LoadNuisanceNuisanceOld loads the publicreportNotifyPhoneNuisanceOld's NuisanceNuisanceOld into the .R struct
func (os PublicreportNotifyPhoneNuisanceOldSlice) LoadNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisanceOlds, err := os.NuisanceNuisanceOld(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNuisanceOlds {
if !(o.NuisanceID == rel.ID) {
continue
}
rel.R.NuisanceNotifyPhoneNuisanceOlds = append(rel.R.NuisanceNotifyPhoneNuisanceOlds, o)
o.R.NuisanceNuisanceOld = rel
break
}
}
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneNuisanceOld's PhoneE164Phone into the .R struct
func (o *PublicreportNotifyPhoneNuisanceOld) 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.PhoneE164NotifyPhoneNuisanceOlds = PublicreportNotifyPhoneNuisanceOldSlice{o}
o.R.PhoneE164Phone = related
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneNuisanceOld's PhoneE164Phone into the .R struct
func (os PublicreportNotifyPhoneNuisanceOldSlice) 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.PhoneE164NotifyPhoneNuisanceOlds = append(rel.R.PhoneE164NotifyPhoneNuisanceOlds, o)
o.R.PhoneE164Phone = rel
break
}
}
return nil
}

View file

@ -1,796 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyPhoneWater is an object representing the database table.
type PublicreportNotifyPhoneWater struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
PhoneE164 string `db:"phone_e164,pk" `
WaterID int32 `db:"water_id,pk" `
R publicreportNotifyPhoneWaterR `db:"-" `
}
// PublicreportNotifyPhoneWaterSlice is an alias for a slice of pointers to PublicreportNotifyPhoneWater.
// This should almost always be used instead of []*PublicreportNotifyPhoneWater.
type PublicreportNotifyPhoneWaterSlice []*PublicreportNotifyPhoneWater
// PublicreportNotifyPhoneWaters contains methods to work with the notify_phone_water table
var PublicreportNotifyPhoneWaters = psql.NewTablex[*PublicreportNotifyPhoneWater, PublicreportNotifyPhoneWaterSlice, *PublicreportNotifyPhoneWaterSetter]("publicreport", "notify_phone_water", buildPublicreportNotifyPhoneWaterColumns("publicreport.notify_phone_water"))
// PublicreportNotifyPhoneWatersQuery is a query on the notify_phone_water table
type PublicreportNotifyPhoneWatersQuery = *psql.ViewQuery[*PublicreportNotifyPhoneWater, PublicreportNotifyPhoneWaterSlice]
// publicreportNotifyPhoneWaterR is where relationships are stored.
type publicreportNotifyPhoneWaterR struct {
PhoneE164Phone *CommsPhone // publicreport.notify_phone_water.notify_phone_pool_phone_e164_fkey
Water *PublicreportWater // publicreport.notify_phone_water.notify_phone_pool_pool_id_fkey
}
func buildPublicreportNotifyPhoneWaterColumns(alias string) publicreportNotifyPhoneWaterColumns {
return publicreportNotifyPhoneWaterColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "phone_e164", "water_id",
).WithParent("publicreport.notify_phone_water"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
PhoneE164: psql.Quote(alias, "phone_e164"),
WaterID: psql.Quote(alias, "water_id"),
}
}
type publicreportNotifyPhoneWaterColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
PhoneE164 psql.Expression
WaterID psql.Expression
}
func (c publicreportNotifyPhoneWaterColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyPhoneWaterColumns) AliasedAs(alias string) publicreportNotifyPhoneWaterColumns {
return buildPublicreportNotifyPhoneWaterColumns(alias)
}
// PublicreportNotifyPhoneWaterSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyPhoneWaterSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
WaterID omit.Val[int32] `db:"water_id,pk" `
}
func (s PublicreportNotifyPhoneWaterSetter) 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.WaterID.IsValue() {
vals = append(vals, "water_id")
}
return vals
}
func (s PublicreportNotifyPhoneWaterSetter) Overwrite(t *PublicreportNotifyPhoneWater) {
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.WaterID.IsValue() {
t.WaterID = s.WaterID.MustGet()
}
}
func (s *PublicreportNotifyPhoneWaterSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyPhoneWaters.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.WaterID.IsValue() {
vals[3] = psql.Arg(s.WaterID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyPhoneWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyPhoneWaterSetter) 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.WaterID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "water_id")...),
psql.Arg(s.WaterID),
}})
}
return exprs
}
// FindPublicreportNotifyPhoneWater retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyPhoneWater(ctx context.Context, exec bob.Executor, WaterIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhoneWater, error) {
if len(cols) == 0 {
return PublicreportNotifyPhoneWaters.Query(
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).One(ctx, exec)
}
return PublicreportNotifyPhoneWaters.Query(
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
sm.Columns(PublicreportNotifyPhoneWaters.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyPhoneWaterExists checks the presence of a single record by primary key
func PublicreportNotifyPhoneWaterExists(ctx context.Context, exec bob.Executor, WaterIDPK int32, PhoneE164PK string) (bool, error) {
return PublicreportNotifyPhoneWaters.Query(
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyPhoneWaters.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyPhoneWater is retrieved from the database
func (o *PublicreportNotifyPhoneWater) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneWaters.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneWaters.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneWaters.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneWaters.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhoneWater
func (o *PublicreportNotifyPhoneWater) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.WaterID,
o.PhoneE164,
)
}
func (o *PublicreportNotifyPhoneWater) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_phone_water", "water_id"), psql.Quote("publicreport.notify_phone_water", "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 PublicreportNotifyPhoneWater
func (o *PublicreportNotifyPhoneWater) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhoneWaterSetter) error {
v, err := PublicreportNotifyPhoneWaters.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 PublicreportNotifyPhoneWater record with an executor
func (o *PublicreportNotifyPhoneWater) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyPhoneWaters.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyPhoneWater using the executor
func (o *PublicreportNotifyPhoneWater) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyPhoneWaters.Query(
sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
sm.Where(PublicreportNotifyPhoneWaters.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 PublicreportNotifyPhoneWaterSlice is retrieved from the database
func (o PublicreportNotifyPhoneWaterSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneWaters.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneWaters.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyPhoneWaterSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_phone_water", "water_id"), psql.Quote("publicreport.notify_phone_water", "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 PublicreportNotifyPhoneWaterSlice) copyMatchingRows(from ...*PublicreportNotifyPhoneWater) {
for i, old := range o {
for _, new := range from {
if new.WaterID != old.WaterID {
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 PublicreportNotifyPhoneWaterSlice) 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 PublicreportNotifyPhoneWaters.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 *PublicreportNotifyPhoneWater:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneWater:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneWaterSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneWater or a slice of PublicreportNotifyPhoneWater
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyPhoneWaters.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhoneWaterSlice) 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 PublicreportNotifyPhoneWaters.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 *PublicreportNotifyPhoneWater:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneWater:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneWaterSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneWater or a slice of PublicreportNotifyPhoneWater
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyPhoneWaters.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyPhoneWaterSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhoneWaterSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneWaters.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneWaterSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneWaters.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneWaterSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyPhoneWaters.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 *PublicreportNotifyPhoneWater) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
)...)
}
func (os PublicreportNotifyPhoneWaterSlice) 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)),
)...)
}
// Water starts a query for related objects on publicreport.water
func (o *PublicreportNotifyPhoneWater) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
return PublicreportWaters.Query(append(mods,
sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(o.WaterID))),
)...)
}
func (os PublicreportNotifyPhoneWaterSlice) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkWaterID = append(pkWaterID, o.WaterID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
))
return PublicreportWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportWaters.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyPhoneWaterPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater, commsPhone1 *CommsPhone) (*PublicreportNotifyPhoneWater, error) {
setter := &PublicreportNotifyPhoneWaterSetter{
PhoneE164: omit.From(commsPhone1.E164),
}
err := publicreportNotifyPhoneWater0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneWaterPhoneE164Phone0: %w", err)
}
return publicreportNotifyPhoneWater0, nil
}
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) 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 = attachPublicreportNotifyPhoneWaterPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneWater0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneWater0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneWaters = append(commsPhone1.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWater0)
return nil
}
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachPublicreportNotifyPhoneWaterPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneWater0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneWater0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneWaters = append(commsPhone1.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWater0)
return nil
}
func attachPublicreportNotifyPhoneWaterWater0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater, publicreportWater1 *PublicreportWater) (*PublicreportNotifyPhoneWater, error) {
setter := &PublicreportNotifyPhoneWaterSetter{
WaterID: omit.From(publicreportWater1.ID),
}
err := publicreportNotifyPhoneWater0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneWaterWater0: %w", err)
}
return publicreportNotifyPhoneWater0, nil
}
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) InsertWater(ctx context.Context, exec bob.Executor, related *PublicreportWaterSetter) error {
var err error
publicreportWater1, err := PublicreportWaters.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyPhoneWaterWater0(ctx, exec, 1, publicreportNotifyPhoneWater0, publicreportWater1)
if err != nil {
return err
}
publicreportNotifyPhoneWater0.R.Water = publicreportWater1
publicreportWater1.R.NotifyPhoneWaters = append(publicreportWater1.R.NotifyPhoneWaters, publicreportNotifyPhoneWater0)
return nil
}
func (publicreportNotifyPhoneWater0 *PublicreportNotifyPhoneWater) AttachWater(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWater) error {
var err error
_, err = attachPublicreportNotifyPhoneWaterWater0(ctx, exec, 1, publicreportNotifyPhoneWater0, publicreportWater1)
if err != nil {
return err
}
publicreportNotifyPhoneWater0.R.Water = publicreportWater1
publicreportWater1.R.NotifyPhoneWaters = append(publicreportWater1.R.NotifyPhoneWaters, publicreportNotifyPhoneWater0)
return nil
}
type publicreportNotifyPhoneWaterWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
PhoneE164 psql.WhereMod[Q, string]
WaterID psql.WhereMod[Q, int32]
}
func (publicreportNotifyPhoneWaterWhere[Q]) AliasedAs(alias string) publicreportNotifyPhoneWaterWhere[Q] {
return buildPublicreportNotifyPhoneWaterWhere[Q](buildPublicreportNotifyPhoneWaterColumns(alias))
}
func buildPublicreportNotifyPhoneWaterWhere[Q psql.Filterable](cols publicreportNotifyPhoneWaterColumns) publicreportNotifyPhoneWaterWhere[Q] {
return publicreportNotifyPhoneWaterWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
WaterID: psql.Where[Q, int32](cols.WaterID),
}
}
func (o *PublicreportNotifyPhoneWater) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "PhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneWater cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164Phone = rel
if rel != nil {
rel.R.PhoneE164NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
}
return nil
case "Water":
rel, ok := retrieved.(*PublicreportWater)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneWater cannot load %T as %q", retrieved, name)
}
o.R.Water = rel
if rel != nil {
rel.R.NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyPhoneWater has no relationship %q", name)
}
}
type publicreportNotifyPhoneWaterPreloader struct {
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
Water func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyPhoneWaterPreloader() publicreportNotifyPhoneWaterPreloader {
return publicreportNotifyPhoneWaterPreloader{
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneWaters,
To: CommsPhones,
FromColumns: []string{"phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
Water: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportWater, PublicreportWaterSlice](psql.PreloadRel{
Name: "Water",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneWaters,
To: PublicreportWaters,
FromColumns: []string{"water_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportWaters.Columns.Names(), opts...)
},
}
}
type publicreportNotifyPhoneWaterThenLoader[Q orm.Loadable] struct {
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyPhoneWaterThenLoader[Q orm.Loadable]() publicreportNotifyPhoneWaterThenLoader[Q] {
type PhoneE164PhoneLoadInterface interface {
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterLoadInterface interface {
LoadWater(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyPhoneWaterThenLoader[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...)
},
),
Water: thenLoadBuilder[Q](
"Water",
func(ctx context.Context, exec bob.Executor, retrieved WaterLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWater(ctx, exec, mods...)
},
),
}
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneWater's PhoneE164Phone into the .R struct
func (o *PublicreportNotifyPhoneWater) 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.PhoneE164NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
o.R.PhoneE164Phone = related
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneWater's PhoneE164Phone into the .R struct
func (os PublicreportNotifyPhoneWaterSlice) 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.PhoneE164NotifyPhoneWaters = append(rel.R.PhoneE164NotifyPhoneWaters, o)
o.R.PhoneE164Phone = rel
break
}
}
return nil
}
// LoadWater loads the publicreportNotifyPhoneWater's Water into the .R struct
func (o *PublicreportNotifyPhoneWater) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Water = nil
related, err := o.Water(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.NotifyPhoneWaters = PublicreportNotifyPhoneWaterSlice{o}
o.R.Water = related
return nil
}
// LoadWater loads the publicreportNotifyPhoneWater's Water into the .R struct
func (os PublicreportNotifyPhoneWaterSlice) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaters, err := os.Water(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaters {
if !(o.WaterID == rel.ID) {
continue
}
rel.R.NotifyPhoneWaters = append(rel.R.NotifyPhoneWaters, o)
o.R.Water = rel
break
}
}
return nil
}

View file

@ -0,0 +1,796 @@
// 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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// PublicreportNotifyPhoneWaterOld is an object representing the database table.
type PublicreportNotifyPhoneWaterOld struct {
Created time.Time `db:"created" `
Deleted null.Val[time.Time] `db:"deleted" `
PhoneE164 string `db:"phone_e164,pk" `
WaterID int32 `db:"water_id,pk" `
R publicreportNotifyPhoneWaterOldR `db:"-" `
}
// PublicreportNotifyPhoneWaterOldSlice is an alias for a slice of pointers to PublicreportNotifyPhoneWaterOld.
// This should almost always be used instead of []*PublicreportNotifyPhoneWaterOld.
type PublicreportNotifyPhoneWaterOldSlice []*PublicreportNotifyPhoneWaterOld
// PublicreportNotifyPhoneWaterOlds contains methods to work with the notify_phone_water_old table
var PublicreportNotifyPhoneWaterOlds = psql.NewTablex[*PublicreportNotifyPhoneWaterOld, PublicreportNotifyPhoneWaterOldSlice, *PublicreportNotifyPhoneWaterOldSetter]("publicreport", "notify_phone_water_old", buildPublicreportNotifyPhoneWaterOldColumns("publicreport.notify_phone_water_old"))
// PublicreportNotifyPhoneWaterOldsQuery is a query on the notify_phone_water_old table
type PublicreportNotifyPhoneWaterOldsQuery = *psql.ViewQuery[*PublicreportNotifyPhoneWaterOld, PublicreportNotifyPhoneWaterOldSlice]
// publicreportNotifyPhoneWaterOldR is where relationships are stored.
type publicreportNotifyPhoneWaterOldR struct {
PhoneE164Phone *CommsPhone // publicreport.notify_phone_water_old.notify_phone_pool_phone_e164_fkey
WaterWaterOld *PublicreportWaterOld // publicreport.notify_phone_water_old.notify_phone_pool_pool_id_fkey
}
func buildPublicreportNotifyPhoneWaterOldColumns(alias string) publicreportNotifyPhoneWaterOldColumns {
return publicreportNotifyPhoneWaterOldColumns{
ColumnsExpr: expr.NewColumnsExpr(
"created", "deleted", "phone_e164", "water_id",
).WithParent("publicreport.notify_phone_water_old"),
tableAlias: alias,
Created: psql.Quote(alias, "created"),
Deleted: psql.Quote(alias, "deleted"),
PhoneE164: psql.Quote(alias, "phone_e164"),
WaterID: psql.Quote(alias, "water_id"),
}
}
type publicreportNotifyPhoneWaterOldColumns struct {
expr.ColumnsExpr
tableAlias string
Created psql.Expression
Deleted psql.Expression
PhoneE164 psql.Expression
WaterID psql.Expression
}
func (c publicreportNotifyPhoneWaterOldColumns) Alias() string {
return c.tableAlias
}
func (publicreportNotifyPhoneWaterOldColumns) AliasedAs(alias string) publicreportNotifyPhoneWaterOldColumns {
return buildPublicreportNotifyPhoneWaterOldColumns(alias)
}
// PublicreportNotifyPhoneWaterOldSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNotifyPhoneWaterOldSetter struct {
Created omit.Val[time.Time] `db:"created" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
PhoneE164 omit.Val[string] `db:"phone_e164,pk" `
WaterID omit.Val[int32] `db:"water_id,pk" `
}
func (s PublicreportNotifyPhoneWaterOldSetter) 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.WaterID.IsValue() {
vals = append(vals, "water_id")
}
return vals
}
func (s PublicreportNotifyPhoneWaterOldSetter) Overwrite(t *PublicreportNotifyPhoneWaterOld) {
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.WaterID.IsValue() {
t.WaterID = s.WaterID.MustGet()
}
}
func (s *PublicreportNotifyPhoneWaterOldSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNotifyPhoneWaterOlds.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.WaterID.IsValue() {
vals[3] = psql.Arg(s.WaterID.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNotifyPhoneWaterOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNotifyPhoneWaterOldSetter) 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.WaterID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "water_id")...),
psql.Arg(s.WaterID),
}})
}
return exprs
}
// FindPublicreportNotifyPhoneWaterOld retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNotifyPhoneWaterOld(ctx context.Context, exec bob.Executor, WaterIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhoneWaterOld, error) {
if len(cols) == 0 {
return PublicreportNotifyPhoneWaterOlds.Query(
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).One(ctx, exec)
}
return PublicreportNotifyPhoneWaterOlds.Query(
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
sm.Columns(PublicreportNotifyPhoneWaterOlds.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNotifyPhoneWaterOldExists checks the presence of a single record by primary key
func PublicreportNotifyPhoneWaterOldExists(ctx context.Context, exec bob.Executor, WaterIDPK int32, PhoneE164PK string) (bool, error) {
return PublicreportNotifyPhoneWaterOlds.Query(
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNotifyPhoneWaterOld is retrieved from the database
func (o *PublicreportNotifyPhoneWaterOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterOldSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterOldSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterOldSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhoneWaterOldSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNotifyPhoneWaterOld
func (o *PublicreportNotifyPhoneWaterOld) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.WaterID,
o.PhoneE164,
)
}
func (o *PublicreportNotifyPhoneWaterOld) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.notify_phone_water_old", "water_id"), psql.Quote("publicreport.notify_phone_water_old", "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 PublicreportNotifyPhoneWaterOld
func (o *PublicreportNotifyPhoneWaterOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhoneWaterOldSetter) error {
v, err := PublicreportNotifyPhoneWaterOlds.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 PublicreportNotifyPhoneWaterOld record with an executor
func (o *PublicreportNotifyPhoneWaterOld) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNotifyPhoneWaterOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNotifyPhoneWaterOld using the executor
func (o *PublicreportNotifyPhoneWaterOld) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNotifyPhoneWaterOlds.Query(
sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
sm.Where(PublicreportNotifyPhoneWaterOlds.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 PublicreportNotifyPhoneWaterOldSlice is retrieved from the database
func (o PublicreportNotifyPhoneWaterOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNotifyPhoneWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNotifyPhoneWaterOldSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.notify_phone_water_old", "water_id"), psql.Quote("publicreport.notify_phone_water_old", "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 PublicreportNotifyPhoneWaterOldSlice) copyMatchingRows(from ...*PublicreportNotifyPhoneWaterOld) {
for i, old := range o {
for _, new := range from {
if new.WaterID != old.WaterID {
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 PublicreportNotifyPhoneWaterOldSlice) 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 PublicreportNotifyPhoneWaterOlds.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 *PublicreportNotifyPhoneWaterOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneWaterOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneWaterOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneWaterOld or a slice of PublicreportNotifyPhoneWaterOld
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNotifyPhoneWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNotifyPhoneWaterOldSlice) 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 PublicreportNotifyPhoneWaterOlds.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 *PublicreportNotifyPhoneWaterOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNotifyPhoneWaterOld:
o.copyMatchingRows(retrieved...)
case PublicreportNotifyPhoneWaterOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNotifyPhoneWaterOld or a slice of PublicreportNotifyPhoneWaterOld
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNotifyPhoneWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNotifyPhoneWaterOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhoneWaterOldSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneWaterOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneWaterOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNotifyPhoneWaterOlds.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNotifyPhoneWaterOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNotifyPhoneWaterOlds.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 *PublicreportNotifyPhoneWaterOld) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))),
)...)
}
func (os PublicreportNotifyPhoneWaterOldSlice) 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)),
)...)
}
// WaterWaterOld starts a query for related objects on publicreport.water_old
func (o *PublicreportNotifyPhoneWaterOld) WaterWaterOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
return PublicreportWaterOlds.Query(append(mods,
sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(o.WaterID))),
)...)
}
func (os PublicreportNotifyPhoneWaterOldSlice) WaterWaterOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkWaterID = append(pkWaterID, o.WaterID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
))
return PublicreportWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportWaterOlds.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNotifyPhoneWaterOldPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaterOld0 *PublicreportNotifyPhoneWaterOld, commsPhone1 *CommsPhone) (*PublicreportNotifyPhoneWaterOld, error) {
setter := &PublicreportNotifyPhoneWaterOldSetter{
PhoneE164: omit.From(commsPhone1.E164),
}
err := publicreportNotifyPhoneWaterOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneWaterOldPhoneE164Phone0: %w", err)
}
return publicreportNotifyPhoneWaterOld0, nil
}
func (publicreportNotifyPhoneWaterOld0 *PublicreportNotifyPhoneWaterOld) 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 = attachPublicreportNotifyPhoneWaterOldPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneWaterOld0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneWaterOld0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneWaterOlds = append(commsPhone1.R.PhoneE164NotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOld0)
return nil
}
func (publicreportNotifyPhoneWaterOld0 *PublicreportNotifyPhoneWaterOld) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachPublicreportNotifyPhoneWaterOldPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhoneWaterOld0, commsPhone1)
if err != nil {
return err
}
publicreportNotifyPhoneWaterOld0.R.PhoneE164Phone = commsPhone1
commsPhone1.R.PhoneE164NotifyPhoneWaterOlds = append(commsPhone1.R.PhoneE164NotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOld0)
return nil
}
func attachPublicreportNotifyPhoneWaterOldWaterWaterOld0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaterOld0 *PublicreportNotifyPhoneWaterOld, publicreportWaterOld1 *PublicreportWaterOld) (*PublicreportNotifyPhoneWaterOld, error) {
setter := &PublicreportNotifyPhoneWaterOldSetter{
WaterID: omit.From(publicreportWaterOld1.ID),
}
err := publicreportNotifyPhoneWaterOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNotifyPhoneWaterOldWaterWaterOld0: %w", err)
}
return publicreportNotifyPhoneWaterOld0, nil
}
func (publicreportNotifyPhoneWaterOld0 *PublicreportNotifyPhoneWaterOld) InsertWaterWaterOld(ctx context.Context, exec bob.Executor, related *PublicreportWaterOldSetter) error {
var err error
publicreportWaterOld1, err := PublicreportWaterOlds.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNotifyPhoneWaterOldWaterWaterOld0(ctx, exec, 1, publicreportNotifyPhoneWaterOld0, publicreportWaterOld1)
if err != nil {
return err
}
publicreportNotifyPhoneWaterOld0.R.WaterWaterOld = publicreportWaterOld1
publicreportWaterOld1.R.WaterNotifyPhoneWaterOlds = append(publicreportWaterOld1.R.WaterNotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOld0)
return nil
}
func (publicreportNotifyPhoneWaterOld0 *PublicreportNotifyPhoneWaterOld) AttachWaterWaterOld(ctx context.Context, exec bob.Executor, publicreportWaterOld1 *PublicreportWaterOld) error {
var err error
_, err = attachPublicreportNotifyPhoneWaterOldWaterWaterOld0(ctx, exec, 1, publicreportNotifyPhoneWaterOld0, publicreportWaterOld1)
if err != nil {
return err
}
publicreportNotifyPhoneWaterOld0.R.WaterWaterOld = publicreportWaterOld1
publicreportWaterOld1.R.WaterNotifyPhoneWaterOlds = append(publicreportWaterOld1.R.WaterNotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOld0)
return nil
}
type publicreportNotifyPhoneWaterOldWhere[Q psql.Filterable] struct {
Created psql.WhereMod[Q, time.Time]
Deleted psql.WhereNullMod[Q, time.Time]
PhoneE164 psql.WhereMod[Q, string]
WaterID psql.WhereMod[Q, int32]
}
func (publicreportNotifyPhoneWaterOldWhere[Q]) AliasedAs(alias string) publicreportNotifyPhoneWaterOldWhere[Q] {
return buildPublicreportNotifyPhoneWaterOldWhere[Q](buildPublicreportNotifyPhoneWaterOldColumns(alias))
}
func buildPublicreportNotifyPhoneWaterOldWhere[Q psql.Filterable](cols publicreportNotifyPhoneWaterOldColumns) publicreportNotifyPhoneWaterOldWhere[Q] {
return publicreportNotifyPhoneWaterOldWhere[Q]{
Created: psql.Where[Q, time.Time](cols.Created),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
PhoneE164: psql.Where[Q, string](cols.PhoneE164),
WaterID: psql.Where[Q, int32](cols.WaterID),
}
}
func (o *PublicreportNotifyPhoneWaterOld) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "PhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneWaterOld cannot load %T as %q", retrieved, name)
}
o.R.PhoneE164Phone = rel
if rel != nil {
rel.R.PhoneE164NotifyPhoneWaterOlds = PublicreportNotifyPhoneWaterOldSlice{o}
}
return nil
case "WaterWaterOld":
rel, ok := retrieved.(*PublicreportWaterOld)
if !ok {
return fmt.Errorf("publicreportNotifyPhoneWaterOld cannot load %T as %q", retrieved, name)
}
o.R.WaterWaterOld = rel
if rel != nil {
rel.R.WaterNotifyPhoneWaterOlds = PublicreportNotifyPhoneWaterOldSlice{o}
}
return nil
default:
return fmt.Errorf("publicreportNotifyPhoneWaterOld has no relationship %q", name)
}
}
type publicreportNotifyPhoneWaterOldPreloader struct {
PhoneE164Phone func(...psql.PreloadOption) psql.Preloader
WaterWaterOld func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNotifyPhoneWaterOldPreloader() publicreportNotifyPhoneWaterOldPreloader {
return publicreportNotifyPhoneWaterOldPreloader{
PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneWaterOlds,
To: CommsPhones,
FromColumns: []string{"phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
WaterWaterOld: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportWaterOld, PublicreportWaterOldSlice](psql.PreloadRel{
Name: "WaterWaterOld",
Sides: []psql.PreloadSide{
{
From: PublicreportNotifyPhoneWaterOlds,
To: PublicreportWaterOlds,
FromColumns: []string{"water_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportWaterOlds.Columns.Names(), opts...)
},
}
}
type publicreportNotifyPhoneWaterOldThenLoader[Q orm.Loadable] struct {
PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
WaterWaterOld func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNotifyPhoneWaterOldThenLoader[Q orm.Loadable]() publicreportNotifyPhoneWaterOldThenLoader[Q] {
type PhoneE164PhoneLoadInterface interface {
LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterWaterOldLoadInterface interface {
LoadWaterWaterOld(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNotifyPhoneWaterOldThenLoader[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...)
},
),
WaterWaterOld: thenLoadBuilder[Q](
"WaterWaterOld",
func(ctx context.Context, exec bob.Executor, retrieved WaterWaterOldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaterWaterOld(ctx, exec, mods...)
},
),
}
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneWaterOld's PhoneE164Phone into the .R struct
func (o *PublicreportNotifyPhoneWaterOld) 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.PhoneE164NotifyPhoneWaterOlds = PublicreportNotifyPhoneWaterOldSlice{o}
o.R.PhoneE164Phone = related
return nil
}
// LoadPhoneE164Phone loads the publicreportNotifyPhoneWaterOld's PhoneE164Phone into the .R struct
func (os PublicreportNotifyPhoneWaterOldSlice) 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.PhoneE164NotifyPhoneWaterOlds = append(rel.R.PhoneE164NotifyPhoneWaterOlds, o)
o.R.PhoneE164Phone = rel
break
}
}
return nil
}
// LoadWaterWaterOld loads the publicreportNotifyPhoneWaterOld's WaterWaterOld into the .R struct
func (o *PublicreportNotifyPhoneWaterOld) LoadWaterWaterOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.WaterWaterOld = nil
related, err := o.WaterWaterOld(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.WaterNotifyPhoneWaterOlds = PublicreportNotifyPhoneWaterOldSlice{o}
o.R.WaterWaterOld = related
return nil
}
// LoadWaterWaterOld loads the publicreportNotifyPhoneWaterOld's WaterWaterOld into the .R struct
func (os PublicreportNotifyPhoneWaterOldSlice) LoadWaterWaterOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaterOlds, err := os.WaterWaterOld(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaterOlds {
if !(o.WaterID == rel.ID) {
continue
}
rel.R.WaterNotifyPhoneWaterOlds = append(rel.R.WaterNotifyPhoneWaterOlds, o)
o.R.WaterWaterOld = rel
break
}
}
return nil
}

File diff suppressed because it is too large Load diff

View file

@ -1,721 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// PublicreportNuisanceImage is an object representing the database table.
type PublicreportNuisanceImage struct {
ImageID int32 `db:"image_id,pk" `
NuisanceID int32 `db:"nuisance_id,pk" `
R publicreportNuisanceImageR `db:"-" `
}
// PublicreportNuisanceImageSlice is an alias for a slice of pointers to PublicreportNuisanceImage.
// This should almost always be used instead of []*PublicreportNuisanceImage.
type PublicreportNuisanceImageSlice []*PublicreportNuisanceImage
// PublicreportNuisanceImages contains methods to work with the nuisance_image table
var PublicreportNuisanceImages = psql.NewTablex[*PublicreportNuisanceImage, PublicreportNuisanceImageSlice, *PublicreportNuisanceImageSetter]("publicreport", "nuisance_image", buildPublicreportNuisanceImageColumns("publicreport.nuisance_image"))
// PublicreportNuisanceImagesQuery is a query on the nuisance_image table
type PublicreportNuisanceImagesQuery = *psql.ViewQuery[*PublicreportNuisanceImage, PublicreportNuisanceImageSlice]
// publicreportNuisanceImageR is where relationships are stored.
type publicreportNuisanceImageR struct {
Image *PublicreportImage // publicreport.nuisance_image.nuisance_image_image_id_fkey
Nuisance *PublicreportNuisance // publicreport.nuisance_image.nuisance_image_nuisance_id_fkey
}
func buildPublicreportNuisanceImageColumns(alias string) publicreportNuisanceImageColumns {
return publicreportNuisanceImageColumns{
ColumnsExpr: expr.NewColumnsExpr(
"image_id", "nuisance_id",
).WithParent("publicreport.nuisance_image"),
tableAlias: alias,
ImageID: psql.Quote(alias, "image_id"),
NuisanceID: psql.Quote(alias, "nuisance_id"),
}
}
type publicreportNuisanceImageColumns struct {
expr.ColumnsExpr
tableAlias string
ImageID psql.Expression
NuisanceID psql.Expression
}
func (c publicreportNuisanceImageColumns) Alias() string {
return c.tableAlias
}
func (publicreportNuisanceImageColumns) AliasedAs(alias string) publicreportNuisanceImageColumns {
return buildPublicreportNuisanceImageColumns(alias)
}
// PublicreportNuisanceImageSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNuisanceImageSetter struct {
ImageID omit.Val[int32] `db:"image_id,pk" `
NuisanceID omit.Val[int32] `db:"nuisance_id,pk" `
}
func (s PublicreportNuisanceImageSetter) SetColumns() []string {
vals := make([]string, 0, 2)
if s.ImageID.IsValue() {
vals = append(vals, "image_id")
}
if s.NuisanceID.IsValue() {
vals = append(vals, "nuisance_id")
}
return vals
}
func (s PublicreportNuisanceImageSetter) Overwrite(t *PublicreportNuisanceImage) {
if s.ImageID.IsValue() {
t.ImageID = s.ImageID.MustGet()
}
if s.NuisanceID.IsValue() {
t.NuisanceID = s.NuisanceID.MustGet()
}
}
func (s *PublicreportNuisanceImageSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNuisanceImages.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, 2)
if s.ImageID.IsValue() {
vals[0] = psql.Arg(s.ImageID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.NuisanceID.IsValue() {
vals[1] = psql.Arg(s.NuisanceID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNuisanceImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNuisanceImageSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 2)
if s.ImageID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "image_id")...),
psql.Arg(s.ImageID),
}})
}
if s.NuisanceID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "nuisance_id")...),
psql.Arg(s.NuisanceID),
}})
}
return exprs
}
// FindPublicreportNuisanceImage retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNuisanceImage(ctx context.Context, exec bob.Executor, ImageIDPK int32, NuisanceIDPK int32, cols ...string) (*PublicreportNuisanceImage, error) {
if len(cols) == 0 {
return PublicreportNuisanceImages.Query(
sm.Where(PublicreportNuisanceImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportNuisanceImages.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
).One(ctx, exec)
}
return PublicreportNuisanceImages.Query(
sm.Where(PublicreportNuisanceImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportNuisanceImages.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Columns(PublicreportNuisanceImages.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNuisanceImageExists checks the presence of a single record by primary key
func PublicreportNuisanceImageExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, NuisanceIDPK int32) (bool, error) {
return PublicreportNuisanceImages.Query(
sm.Where(PublicreportNuisanceImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportNuisanceImages.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNuisanceImage is retrieved from the database
func (o *PublicreportNuisanceImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNuisanceImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNuisanceImageSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNuisanceImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNuisanceImageSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNuisanceImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNuisanceImageSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNuisanceImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNuisanceImageSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNuisanceImage
func (o *PublicreportNuisanceImage) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ImageID,
o.NuisanceID,
)
}
func (o *PublicreportNuisanceImage) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.nuisance_image", "image_id"), psql.Quote("publicreport.nuisance_image", "nuisance_id")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNuisanceImage
func (o *PublicreportNuisanceImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportNuisanceImageSetter) error {
v, err := PublicreportNuisanceImages.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 PublicreportNuisanceImage record with an executor
func (o *PublicreportNuisanceImage) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNuisanceImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNuisanceImage using the executor
func (o *PublicreportNuisanceImage) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNuisanceImages.Query(
sm.Where(PublicreportNuisanceImages.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
sm.Where(PublicreportNuisanceImages.Columns.NuisanceID.EQ(psql.Arg(o.NuisanceID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportNuisanceImageSlice is retrieved from the database
func (o PublicreportNuisanceImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNuisanceImages.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNuisanceImages.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNuisanceImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNuisanceImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNuisanceImageSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.nuisance_image", "image_id"), psql.Quote("publicreport.nuisance_image", "nuisance_id")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNuisanceImageSlice) copyMatchingRows(from ...*PublicreportNuisanceImage) {
for i, old := range o {
for _, new := range from {
if new.ImageID != old.ImageID {
continue
}
if new.NuisanceID != old.NuisanceID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportNuisanceImageSlice) 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 PublicreportNuisanceImages.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 *PublicreportNuisanceImage:
o.copyMatchingRows(retrieved)
case []*PublicreportNuisanceImage:
o.copyMatchingRows(retrieved...)
case PublicreportNuisanceImageSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNuisanceImage or a slice of PublicreportNuisanceImage
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNuisanceImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNuisanceImageSlice) 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 PublicreportNuisanceImages.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 *PublicreportNuisanceImage:
o.copyMatchingRows(retrieved)
case []*PublicreportNuisanceImage:
o.copyMatchingRows(retrieved...)
case PublicreportNuisanceImageSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNuisanceImage or a slice of PublicreportNuisanceImage
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNuisanceImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNuisanceImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNuisanceImageSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNuisanceImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNuisanceImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNuisanceImages.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNuisanceImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNuisanceImages.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Image starts a query for related objects on publicreport.image
func (o *PublicreportNuisanceImage) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
return PublicreportImages.Query(append(mods,
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
)...)
}
func (os PublicreportNuisanceImageSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
pkImageID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkImageID = append(pkImageID, o.ImageID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
))
return PublicreportImages.Query(append(mods,
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// Nuisance starts a query for related objects on publicreport.nuisance
func (o *PublicreportNuisanceImage) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
return PublicreportNuisances.Query(append(mods,
sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(o.NuisanceID))),
)...)
}
func (os PublicreportNuisanceImageSlice) 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 attachPublicreportNuisanceImageImage0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceImage0 *PublicreportNuisanceImage, publicreportImage1 *PublicreportImage) (*PublicreportNuisanceImage, error) {
setter := &PublicreportNuisanceImageSetter{
ImageID: omit.From(publicreportImage1.ID),
}
err := publicreportNuisanceImage0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNuisanceImageImage0: %w", err)
}
return publicreportNuisanceImage0, nil
}
func (publicreportNuisanceImage0 *PublicreportNuisanceImage) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
var err error
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNuisanceImageImage0(ctx, exec, 1, publicreportNuisanceImage0, publicreportImage1)
if err != nil {
return err
}
publicreportNuisanceImage0.R.Image = publicreportImage1
return nil
}
func (publicreportNuisanceImage0 *PublicreportNuisanceImage) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
var err error
_, err = attachPublicreportNuisanceImageImage0(ctx, exec, 1, publicreportNuisanceImage0, publicreportImage1)
if err != nil {
return err
}
publicreportNuisanceImage0.R.Image = publicreportImage1
return nil
}
func attachPublicreportNuisanceImageNuisance0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceImage0 *PublicreportNuisanceImage, publicreportNuisance1 *PublicreportNuisance) (*PublicreportNuisanceImage, error) {
setter := &PublicreportNuisanceImageSetter{
NuisanceID: omit.From(publicreportNuisance1.ID),
}
err := publicreportNuisanceImage0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNuisanceImageNuisance0: %w", err)
}
return publicreportNuisanceImage0, nil
}
func (publicreportNuisanceImage0 *PublicreportNuisanceImage) 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 = attachPublicreportNuisanceImageNuisance0(ctx, exec, 1, publicreportNuisanceImage0, publicreportNuisance1)
if err != nil {
return err
}
publicreportNuisanceImage0.R.Nuisance = publicreportNuisance1
return nil
}
func (publicreportNuisanceImage0 *PublicreportNuisanceImage) AttachNuisance(ctx context.Context, exec bob.Executor, publicreportNuisance1 *PublicreportNuisance) error {
var err error
_, err = attachPublicreportNuisanceImageNuisance0(ctx, exec, 1, publicreportNuisanceImage0, publicreportNuisance1)
if err != nil {
return err
}
publicreportNuisanceImage0.R.Nuisance = publicreportNuisance1
return nil
}
type publicreportNuisanceImageWhere[Q psql.Filterable] struct {
ImageID psql.WhereMod[Q, int32]
NuisanceID psql.WhereMod[Q, int32]
}
func (publicreportNuisanceImageWhere[Q]) AliasedAs(alias string) publicreportNuisanceImageWhere[Q] {
return buildPublicreportNuisanceImageWhere[Q](buildPublicreportNuisanceImageColumns(alias))
}
func buildPublicreportNuisanceImageWhere[Q psql.Filterable](cols publicreportNuisanceImageColumns) publicreportNuisanceImageWhere[Q] {
return publicreportNuisanceImageWhere[Q]{
ImageID: psql.Where[Q, int32](cols.ImageID),
NuisanceID: psql.Where[Q, int32](cols.NuisanceID),
}
}
func (o *PublicreportNuisanceImage) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Image":
rel, ok := retrieved.(*PublicreportImage)
if !ok {
return fmt.Errorf("publicreportNuisanceImage cannot load %T as %q", retrieved, name)
}
o.R.Image = rel
return nil
case "Nuisance":
rel, ok := retrieved.(*PublicreportNuisance)
if !ok {
return fmt.Errorf("publicreportNuisanceImage cannot load %T as %q", retrieved, name)
}
o.R.Nuisance = rel
return nil
default:
return fmt.Errorf("publicreportNuisanceImage has no relationship %q", name)
}
}
type publicreportNuisanceImagePreloader struct {
Image func(...psql.PreloadOption) psql.Preloader
Nuisance func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNuisanceImagePreloader() publicreportNuisanceImagePreloader {
return publicreportNuisanceImagePreloader{
Image: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
Name: "Image",
Sides: []psql.PreloadSide{
{
From: PublicreportNuisanceImages,
To: PublicreportImages,
FromColumns: []string{"image_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportImages.Columns.Names(), opts...)
},
Nuisance: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportNuisance, PublicreportNuisanceSlice](psql.PreloadRel{
Name: "Nuisance",
Sides: []psql.PreloadSide{
{
From: PublicreportNuisanceImages,
To: PublicreportNuisances,
FromColumns: []string{"nuisance_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportNuisances.Columns.Names(), opts...)
},
}
}
type publicreportNuisanceImageThenLoader[Q orm.Loadable] struct {
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Nuisance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNuisanceImageThenLoader[Q orm.Loadable]() publicreportNuisanceImageThenLoader[Q] {
type ImageLoadInterface interface {
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisanceLoadInterface interface {
LoadNuisance(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNuisanceImageThenLoader[Q]{
Image: thenLoadBuilder[Q](
"Image",
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImage(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...)
},
),
}
}
// LoadImage loads the publicreportNuisanceImage's Image into the .R struct
func (o *PublicreportNuisanceImage) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Image = nil
related, err := o.Image(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Image = related
return nil
}
// LoadImage loads the publicreportNuisanceImage's Image into the .R struct
func (os PublicreportNuisanceImageSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportImages, err := os.Image(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportImages {
if !(o.ImageID == rel.ID) {
continue
}
o.R.Image = rel
break
}
}
return nil
}
// LoadNuisance loads the publicreportNuisanceImage's Nuisance into the .R struct
func (o *PublicreportNuisanceImage) 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
}
o.R.Nuisance = related
return nil
}
// LoadNuisance loads the publicreportNuisanceImage's Nuisance into the .R struct
func (os PublicreportNuisanceImageSlice) 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
}
o.R.Nuisance = rel
break
}
}
return nil
}

View file

@ -0,0 +1,721 @@
// 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"
"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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// PublicreportNuisanceImageOld is an object representing the database table.
type PublicreportNuisanceImageOld struct {
ImageID int32 `db:"image_id,pk" `
NuisanceID int32 `db:"nuisance_id,pk" `
R publicreportNuisanceImageOldR `db:"-" `
}
// PublicreportNuisanceImageOldSlice is an alias for a slice of pointers to PublicreportNuisanceImageOld.
// This should almost always be used instead of []*PublicreportNuisanceImageOld.
type PublicreportNuisanceImageOldSlice []*PublicreportNuisanceImageOld
// PublicreportNuisanceImageOlds contains methods to work with the nuisance_image_old table
var PublicreportNuisanceImageOlds = psql.NewTablex[*PublicreportNuisanceImageOld, PublicreportNuisanceImageOldSlice, *PublicreportNuisanceImageOldSetter]("publicreport", "nuisance_image_old", buildPublicreportNuisanceImageOldColumns("publicreport.nuisance_image_old"))
// PublicreportNuisanceImageOldsQuery is a query on the nuisance_image_old table
type PublicreportNuisanceImageOldsQuery = *psql.ViewQuery[*PublicreportNuisanceImageOld, PublicreportNuisanceImageOldSlice]
// publicreportNuisanceImageOldR is where relationships are stored.
type publicreportNuisanceImageOldR struct {
Image *PublicreportImage // publicreport.nuisance_image_old.nuisance_image_image_id_fkey
NuisanceNuisanceOld *PublicreportNuisanceOld // publicreport.nuisance_image_old.nuisance_image_nuisance_id_fkey
}
func buildPublicreportNuisanceImageOldColumns(alias string) publicreportNuisanceImageOldColumns {
return publicreportNuisanceImageOldColumns{
ColumnsExpr: expr.NewColumnsExpr(
"image_id", "nuisance_id",
).WithParent("publicreport.nuisance_image_old"),
tableAlias: alias,
ImageID: psql.Quote(alias, "image_id"),
NuisanceID: psql.Quote(alias, "nuisance_id"),
}
}
type publicreportNuisanceImageOldColumns struct {
expr.ColumnsExpr
tableAlias string
ImageID psql.Expression
NuisanceID psql.Expression
}
func (c publicreportNuisanceImageOldColumns) Alias() string {
return c.tableAlias
}
func (publicreportNuisanceImageOldColumns) AliasedAs(alias string) publicreportNuisanceImageOldColumns {
return buildPublicreportNuisanceImageOldColumns(alias)
}
// PublicreportNuisanceImageOldSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportNuisanceImageOldSetter struct {
ImageID omit.Val[int32] `db:"image_id,pk" `
NuisanceID omit.Val[int32] `db:"nuisance_id,pk" `
}
func (s PublicreportNuisanceImageOldSetter) SetColumns() []string {
vals := make([]string, 0, 2)
if s.ImageID.IsValue() {
vals = append(vals, "image_id")
}
if s.NuisanceID.IsValue() {
vals = append(vals, "nuisance_id")
}
return vals
}
func (s PublicreportNuisanceImageOldSetter) Overwrite(t *PublicreportNuisanceImageOld) {
if s.ImageID.IsValue() {
t.ImageID = s.ImageID.MustGet()
}
if s.NuisanceID.IsValue() {
t.NuisanceID = s.NuisanceID.MustGet()
}
}
func (s *PublicreportNuisanceImageOldSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportNuisanceImageOlds.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, 2)
if s.ImageID.IsValue() {
vals[0] = psql.Arg(s.ImageID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.NuisanceID.IsValue() {
vals[1] = psql.Arg(s.NuisanceID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportNuisanceImageOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportNuisanceImageOldSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 2)
if s.ImageID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "image_id")...),
psql.Arg(s.ImageID),
}})
}
if s.NuisanceID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "nuisance_id")...),
psql.Arg(s.NuisanceID),
}})
}
return exprs
}
// FindPublicreportNuisanceImageOld retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportNuisanceImageOld(ctx context.Context, exec bob.Executor, ImageIDPK int32, NuisanceIDPK int32, cols ...string) (*PublicreportNuisanceImageOld, error) {
if len(cols) == 0 {
return PublicreportNuisanceImageOlds.Query(
sm.Where(PublicreportNuisanceImageOlds.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportNuisanceImageOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
).One(ctx, exec)
}
return PublicreportNuisanceImageOlds.Query(
sm.Where(PublicreportNuisanceImageOlds.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportNuisanceImageOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
sm.Columns(PublicreportNuisanceImageOlds.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportNuisanceImageOldExists checks the presence of a single record by primary key
func PublicreportNuisanceImageOldExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, NuisanceIDPK int32) (bool, error) {
return PublicreportNuisanceImageOlds.Query(
sm.Where(PublicreportNuisanceImageOlds.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportNuisanceImageOlds.Columns.NuisanceID.EQ(psql.Arg(NuisanceIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportNuisanceImageOld is retrieved from the database
func (o *PublicreportNuisanceImageOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNuisanceImageOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNuisanceImageOldSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportNuisanceImageOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNuisanceImageOldSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportNuisanceImageOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNuisanceImageOldSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportNuisanceImageOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNuisanceImageOldSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportNuisanceImageOld
func (o *PublicreportNuisanceImageOld) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ImageID,
o.NuisanceID,
)
}
func (o *PublicreportNuisanceImageOld) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.nuisance_image_old", "image_id"), psql.Quote("publicreport.nuisance_image_old", "nuisance_id")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportNuisanceImageOld
func (o *PublicreportNuisanceImageOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportNuisanceImageOldSetter) error {
v, err := PublicreportNuisanceImageOlds.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 PublicreportNuisanceImageOld record with an executor
func (o *PublicreportNuisanceImageOld) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportNuisanceImageOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportNuisanceImageOld using the executor
func (o *PublicreportNuisanceImageOld) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportNuisanceImageOlds.Query(
sm.Where(PublicreportNuisanceImageOlds.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
sm.Where(PublicreportNuisanceImageOlds.Columns.NuisanceID.EQ(psql.Arg(o.NuisanceID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportNuisanceImageOldSlice is retrieved from the database
func (o PublicreportNuisanceImageOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportNuisanceImageOlds.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportNuisanceImageOlds.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportNuisanceImageOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportNuisanceImageOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportNuisanceImageOldSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.nuisance_image_old", "image_id"), psql.Quote("publicreport.nuisance_image_old", "nuisance_id")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportNuisanceImageOldSlice) copyMatchingRows(from ...*PublicreportNuisanceImageOld) {
for i, old := range o {
for _, new := range from {
if new.ImageID != old.ImageID {
continue
}
if new.NuisanceID != old.NuisanceID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportNuisanceImageOldSlice) 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 PublicreportNuisanceImageOlds.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 *PublicreportNuisanceImageOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNuisanceImageOld:
o.copyMatchingRows(retrieved...)
case PublicreportNuisanceImageOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNuisanceImageOld or a slice of PublicreportNuisanceImageOld
// then run the AfterUpdateHooks on the slice
_, err = PublicreportNuisanceImageOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportNuisanceImageOldSlice) 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 PublicreportNuisanceImageOlds.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 *PublicreportNuisanceImageOld:
o.copyMatchingRows(retrieved)
case []*PublicreportNuisanceImageOld:
o.copyMatchingRows(retrieved...)
case PublicreportNuisanceImageOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportNuisanceImageOld or a slice of PublicreportNuisanceImageOld
// then run the AfterDeleteHooks on the slice
_, err = PublicreportNuisanceImageOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportNuisanceImageOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNuisanceImageOldSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNuisanceImageOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportNuisanceImageOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportNuisanceImageOlds.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportNuisanceImageOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportNuisanceImageOlds.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Image starts a query for related objects on publicreport.image
func (o *PublicreportNuisanceImageOld) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
return PublicreportImages.Query(append(mods,
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
)...)
}
func (os PublicreportNuisanceImageOldSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
pkImageID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkImageID = append(pkImageID, o.ImageID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
))
return PublicreportImages.Query(append(mods,
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// NuisanceNuisanceOld starts a query for related objects on publicreport.nuisance_old
func (o *PublicreportNuisanceImageOld) NuisanceNuisanceOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
return PublicreportNuisanceOlds.Query(append(mods,
sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(o.NuisanceID))),
)...)
}
func (os PublicreportNuisanceImageOldSlice) NuisanceNuisanceOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery {
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 PublicreportNuisanceOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportNuisanceOlds.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportNuisanceImageOldImage0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceImageOld0 *PublicreportNuisanceImageOld, publicreportImage1 *PublicreportImage) (*PublicreportNuisanceImageOld, error) {
setter := &PublicreportNuisanceImageOldSetter{
ImageID: omit.From(publicreportImage1.ID),
}
err := publicreportNuisanceImageOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNuisanceImageOldImage0: %w", err)
}
return publicreportNuisanceImageOld0, nil
}
func (publicreportNuisanceImageOld0 *PublicreportNuisanceImageOld) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
var err error
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNuisanceImageOldImage0(ctx, exec, 1, publicreportNuisanceImageOld0, publicreportImage1)
if err != nil {
return err
}
publicreportNuisanceImageOld0.R.Image = publicreportImage1
return nil
}
func (publicreportNuisanceImageOld0 *PublicreportNuisanceImageOld) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
var err error
_, err = attachPublicreportNuisanceImageOldImage0(ctx, exec, 1, publicreportNuisanceImageOld0, publicreportImage1)
if err != nil {
return err
}
publicreportNuisanceImageOld0.R.Image = publicreportImage1
return nil
}
func attachPublicreportNuisanceImageOldNuisanceNuisanceOld0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceImageOld0 *PublicreportNuisanceImageOld, publicreportNuisanceOld1 *PublicreportNuisanceOld) (*PublicreportNuisanceImageOld, error) {
setter := &PublicreportNuisanceImageOldSetter{
NuisanceID: omit.From(publicreportNuisanceOld1.ID),
}
err := publicreportNuisanceImageOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportNuisanceImageOldNuisanceNuisanceOld0: %w", err)
}
return publicreportNuisanceImageOld0, nil
}
func (publicreportNuisanceImageOld0 *PublicreportNuisanceImageOld) InsertNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, related *PublicreportNuisanceOldSetter) error {
var err error
publicreportNuisanceOld1, err := PublicreportNuisanceOlds.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportNuisanceImageOldNuisanceNuisanceOld0(ctx, exec, 1, publicreportNuisanceImageOld0, publicreportNuisanceOld1)
if err != nil {
return err
}
publicreportNuisanceImageOld0.R.NuisanceNuisanceOld = publicreportNuisanceOld1
return nil
}
func (publicreportNuisanceImageOld0 *PublicreportNuisanceImageOld) AttachNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, publicreportNuisanceOld1 *PublicreportNuisanceOld) error {
var err error
_, err = attachPublicreportNuisanceImageOldNuisanceNuisanceOld0(ctx, exec, 1, publicreportNuisanceImageOld0, publicreportNuisanceOld1)
if err != nil {
return err
}
publicreportNuisanceImageOld0.R.NuisanceNuisanceOld = publicreportNuisanceOld1
return nil
}
type publicreportNuisanceImageOldWhere[Q psql.Filterable] struct {
ImageID psql.WhereMod[Q, int32]
NuisanceID psql.WhereMod[Q, int32]
}
func (publicreportNuisanceImageOldWhere[Q]) AliasedAs(alias string) publicreportNuisanceImageOldWhere[Q] {
return buildPublicreportNuisanceImageOldWhere[Q](buildPublicreportNuisanceImageOldColumns(alias))
}
func buildPublicreportNuisanceImageOldWhere[Q psql.Filterable](cols publicreportNuisanceImageOldColumns) publicreportNuisanceImageOldWhere[Q] {
return publicreportNuisanceImageOldWhere[Q]{
ImageID: psql.Where[Q, int32](cols.ImageID),
NuisanceID: psql.Where[Q, int32](cols.NuisanceID),
}
}
func (o *PublicreportNuisanceImageOld) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Image":
rel, ok := retrieved.(*PublicreportImage)
if !ok {
return fmt.Errorf("publicreportNuisanceImageOld cannot load %T as %q", retrieved, name)
}
o.R.Image = rel
return nil
case "NuisanceNuisanceOld":
rel, ok := retrieved.(*PublicreportNuisanceOld)
if !ok {
return fmt.Errorf("publicreportNuisanceImageOld cannot load %T as %q", retrieved, name)
}
o.R.NuisanceNuisanceOld = rel
return nil
default:
return fmt.Errorf("publicreportNuisanceImageOld has no relationship %q", name)
}
}
type publicreportNuisanceImageOldPreloader struct {
Image func(...psql.PreloadOption) psql.Preloader
NuisanceNuisanceOld func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportNuisanceImageOldPreloader() publicreportNuisanceImageOldPreloader {
return publicreportNuisanceImageOldPreloader{
Image: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
Name: "Image",
Sides: []psql.PreloadSide{
{
From: PublicreportNuisanceImageOlds,
To: PublicreportImages,
FromColumns: []string{"image_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportImages.Columns.Names(), opts...)
},
NuisanceNuisanceOld: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportNuisanceOld, PublicreportNuisanceOldSlice](psql.PreloadRel{
Name: "NuisanceNuisanceOld",
Sides: []psql.PreloadSide{
{
From: PublicreportNuisanceImageOlds,
To: PublicreportNuisanceOlds,
FromColumns: []string{"nuisance_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportNuisanceOlds.Columns.Names(), opts...)
},
}
}
type publicreportNuisanceImageOldThenLoader[Q orm.Loadable] struct {
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NuisanceNuisanceOld func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportNuisanceImageOldThenLoader[Q orm.Loadable]() publicreportNuisanceImageOldThenLoader[Q] {
type ImageLoadInterface interface {
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type NuisanceNuisanceOldLoadInterface interface {
LoadNuisanceNuisanceOld(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportNuisanceImageOldThenLoader[Q]{
Image: thenLoadBuilder[Q](
"Image",
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImage(ctx, exec, mods...)
},
),
NuisanceNuisanceOld: thenLoadBuilder[Q](
"NuisanceNuisanceOld",
func(ctx context.Context, exec bob.Executor, retrieved NuisanceNuisanceOldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadNuisanceNuisanceOld(ctx, exec, mods...)
},
),
}
}
// LoadImage loads the publicreportNuisanceImageOld's Image into the .R struct
func (o *PublicreportNuisanceImageOld) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Image = nil
related, err := o.Image(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Image = related
return nil
}
// LoadImage loads the publicreportNuisanceImageOld's Image into the .R struct
func (os PublicreportNuisanceImageOldSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportImages, err := os.Image(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportImages {
if !(o.ImageID == rel.ID) {
continue
}
o.R.Image = rel
break
}
}
return nil
}
// LoadNuisanceNuisanceOld loads the publicreportNuisanceImageOld's NuisanceNuisanceOld into the .R struct
func (o *PublicreportNuisanceImageOld) LoadNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.NuisanceNuisanceOld = nil
related, err := o.NuisanceNuisanceOld(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.NuisanceNuisanceOld = related
return nil
}
// LoadNuisanceNuisanceOld loads the publicreportNuisanceImageOld's NuisanceNuisanceOld into the .R struct
func (os PublicreportNuisanceImageOldSlice) LoadNuisanceNuisanceOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportNuisanceOlds, err := os.NuisanceNuisanceOld(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportNuisanceOlds {
if !(o.NuisanceID == rel.ID) {
continue
}
o.R.NuisanceNuisanceOld = rel
break
}
}
return nil
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,721 @@
// 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"
"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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// PublicreportReportImage is an object representing the database table.
type PublicreportReportImage struct {
ImageID int32 `db:"image_id,pk" `
ReportID int32 `db:"report_id,pk" `
R publicreportReportImageR `db:"-" `
}
// PublicreportReportImageSlice is an alias for a slice of pointers to PublicreportReportImage.
// This should almost always be used instead of []*PublicreportReportImage.
type PublicreportReportImageSlice []*PublicreportReportImage
// PublicreportReportImages contains methods to work with the report_image table
var PublicreportReportImages = psql.NewTablex[*PublicreportReportImage, PublicreportReportImageSlice, *PublicreportReportImageSetter]("publicreport", "report_image", buildPublicreportReportImageColumns("publicreport.report_image"))
// PublicreportReportImagesQuery is a query on the report_image table
type PublicreportReportImagesQuery = *psql.ViewQuery[*PublicreportReportImage, PublicreportReportImageSlice]
// publicreportReportImageR is where relationships are stored.
type publicreportReportImageR struct {
Image *PublicreportImage // publicreport.report_image.report_image_image_id_fkey
Report *PublicreportReport // publicreport.report_image.report_image_report_id_fkey
}
func buildPublicreportReportImageColumns(alias string) publicreportReportImageColumns {
return publicreportReportImageColumns{
ColumnsExpr: expr.NewColumnsExpr(
"image_id", "report_id",
).WithParent("publicreport.report_image"),
tableAlias: alias,
ImageID: psql.Quote(alias, "image_id"),
ReportID: psql.Quote(alias, "report_id"),
}
}
type publicreportReportImageColumns struct {
expr.ColumnsExpr
tableAlias string
ImageID psql.Expression
ReportID psql.Expression
}
func (c publicreportReportImageColumns) Alias() string {
return c.tableAlias
}
func (publicreportReportImageColumns) AliasedAs(alias string) publicreportReportImageColumns {
return buildPublicreportReportImageColumns(alias)
}
// PublicreportReportImageSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportReportImageSetter struct {
ImageID omit.Val[int32] `db:"image_id,pk" `
ReportID omit.Val[int32] `db:"report_id,pk" `
}
func (s PublicreportReportImageSetter) SetColumns() []string {
vals := make([]string, 0, 2)
if s.ImageID.IsValue() {
vals = append(vals, "image_id")
}
if s.ReportID.IsValue() {
vals = append(vals, "report_id")
}
return vals
}
func (s PublicreportReportImageSetter) Overwrite(t *PublicreportReportImage) {
if s.ImageID.IsValue() {
t.ImageID = s.ImageID.MustGet()
}
if s.ReportID.IsValue() {
t.ReportID = s.ReportID.MustGet()
}
}
func (s *PublicreportReportImageSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportReportImages.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, 2)
if s.ImageID.IsValue() {
vals[0] = psql.Arg(s.ImageID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.ReportID.IsValue() {
vals[1] = psql.Arg(s.ReportID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportReportImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportReportImageSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 2)
if s.ImageID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "image_id")...),
psql.Arg(s.ImageID),
}})
}
if s.ReportID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "report_id")...),
psql.Arg(s.ReportID),
}})
}
return exprs
}
// FindPublicreportReportImage retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportReportImage(ctx context.Context, exec bob.Executor, ImageIDPK int32, ReportIDPK int32, cols ...string) (*PublicreportReportImage, error) {
if len(cols) == 0 {
return PublicreportReportImages.Query(
sm.Where(PublicreportReportImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportReportImages.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
).One(ctx, exec)
}
return PublicreportReportImages.Query(
sm.Where(PublicreportReportImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportReportImages.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Columns(PublicreportReportImages.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportReportImageExists checks the presence of a single record by primary key
func PublicreportReportImageExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, ReportIDPK int32) (bool, error) {
return PublicreportReportImages.Query(
sm.Where(PublicreportReportImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportReportImages.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportReportImage is retrieved from the database
func (o *PublicreportReportImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportReportImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportReportImageSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportReportImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportReportImageSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportReportImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportReportImageSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportReportImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportReportImageSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportReportImage
func (o *PublicreportReportImage) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ImageID,
o.ReportID,
)
}
func (o *PublicreportReportImage) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.report_image", "image_id"), psql.Quote("publicreport.report_image", "report_id")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportReportImage
func (o *PublicreportReportImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportReportImageSetter) error {
v, err := PublicreportReportImages.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 PublicreportReportImage record with an executor
func (o *PublicreportReportImage) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportReportImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportReportImage using the executor
func (o *PublicreportReportImage) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportReportImages.Query(
sm.Where(PublicreportReportImages.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
sm.Where(PublicreportReportImages.Columns.ReportID.EQ(psql.Arg(o.ReportID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportReportImageSlice is retrieved from the database
func (o PublicreportReportImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportReportImages.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportReportImages.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportReportImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportReportImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportReportImageSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.report_image", "image_id"), psql.Quote("publicreport.report_image", "report_id")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportReportImageSlice) copyMatchingRows(from ...*PublicreportReportImage) {
for i, old := range o {
for _, new := range from {
if new.ImageID != old.ImageID {
continue
}
if new.ReportID != old.ReportID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportReportImageSlice) 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 PublicreportReportImages.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 *PublicreportReportImage:
o.copyMatchingRows(retrieved)
case []*PublicreportReportImage:
o.copyMatchingRows(retrieved...)
case PublicreportReportImageSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportReportImage or a slice of PublicreportReportImage
// then run the AfterUpdateHooks on the slice
_, err = PublicreportReportImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportReportImageSlice) 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 PublicreportReportImages.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 *PublicreportReportImage:
o.copyMatchingRows(retrieved)
case []*PublicreportReportImage:
o.copyMatchingRows(retrieved...)
case PublicreportReportImageSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportReportImage or a slice of PublicreportReportImage
// then run the AfterDeleteHooks on the slice
_, err = PublicreportReportImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportReportImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportReportImageSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportReportImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportReportImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportReportImages.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportReportImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportReportImages.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Image starts a query for related objects on publicreport.image
func (o *PublicreportReportImage) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
return PublicreportImages.Query(append(mods,
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
)...)
}
func (os PublicreportReportImageSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
pkImageID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkImageID = append(pkImageID, o.ImageID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
))
return PublicreportImages.Query(append(mods,
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// Report starts a query for related objects on publicreport.report
func (o *PublicreportReportImage) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))),
)...)
}
func (os PublicreportReportImageSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkReportID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkReportID = append(pkReportID, o.ReportID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")),
))
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportReportImageImage0(ctx context.Context, exec bob.Executor, count int, publicreportReportImage0 *PublicreportReportImage, publicreportImage1 *PublicreportImage) (*PublicreportReportImage, error) {
setter := &PublicreportReportImageSetter{
ImageID: omit.From(publicreportImage1.ID),
}
err := publicreportReportImage0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportReportImageImage0: %w", err)
}
return publicreportReportImage0, nil
}
func (publicreportReportImage0 *PublicreportReportImage) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
var err error
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportReportImageImage0(ctx, exec, 1, publicreportReportImage0, publicreportImage1)
if err != nil {
return err
}
publicreportReportImage0.R.Image = publicreportImage1
return nil
}
func (publicreportReportImage0 *PublicreportReportImage) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
var err error
_, err = attachPublicreportReportImageImage0(ctx, exec, 1, publicreportReportImage0, publicreportImage1)
if err != nil {
return err
}
publicreportReportImage0.R.Image = publicreportImage1
return nil
}
func attachPublicreportReportImageReport0(ctx context.Context, exec bob.Executor, count int, publicreportReportImage0 *PublicreportReportImage, publicreportReport1 *PublicreportReport) (*PublicreportReportImage, error) {
setter := &PublicreportReportImageSetter{
ReportID: omit.From(publicreportReport1.ID),
}
err := publicreportReportImage0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportReportImageReport0: %w", err)
}
return publicreportReportImage0, nil
}
func (publicreportReportImage0 *PublicreportReportImage) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error {
var err error
publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportReportImageReport0(ctx, exec, 1, publicreportReportImage0, publicreportReport1)
if err != nil {
return err
}
publicreportReportImage0.R.Report = publicreportReport1
return nil
}
func (publicreportReportImage0 *PublicreportReportImage) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error {
var err error
_, err = attachPublicreportReportImageReport0(ctx, exec, 1, publicreportReportImage0, publicreportReport1)
if err != nil {
return err
}
publicreportReportImage0.R.Report = publicreportReport1
return nil
}
type publicreportReportImageWhere[Q psql.Filterable] struct {
ImageID psql.WhereMod[Q, int32]
ReportID psql.WhereMod[Q, int32]
}
func (publicreportReportImageWhere[Q]) AliasedAs(alias string) publicreportReportImageWhere[Q] {
return buildPublicreportReportImageWhere[Q](buildPublicreportReportImageColumns(alias))
}
func buildPublicreportReportImageWhere[Q psql.Filterable](cols publicreportReportImageColumns) publicreportReportImageWhere[Q] {
return publicreportReportImageWhere[Q]{
ImageID: psql.Where[Q, int32](cols.ImageID),
ReportID: psql.Where[Q, int32](cols.ReportID),
}
}
func (o *PublicreportReportImage) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Image":
rel, ok := retrieved.(*PublicreportImage)
if !ok {
return fmt.Errorf("publicreportReportImage cannot load %T as %q", retrieved, name)
}
o.R.Image = rel
return nil
case "Report":
rel, ok := retrieved.(*PublicreportReport)
if !ok {
return fmt.Errorf("publicreportReportImage cannot load %T as %q", retrieved, name)
}
o.R.Report = rel
return nil
default:
return fmt.Errorf("publicreportReportImage has no relationship %q", name)
}
}
type publicreportReportImagePreloader struct {
Image func(...psql.PreloadOption) psql.Preloader
Report func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportReportImagePreloader() publicreportReportImagePreloader {
return publicreportReportImagePreloader{
Image: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
Name: "Image",
Sides: []psql.PreloadSide{
{
From: PublicreportReportImages,
To: PublicreportImages,
FromColumns: []string{"image_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportImages.Columns.Names(), opts...)
},
Report: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{
Name: "Report",
Sides: []psql.PreloadSide{
{
From: PublicreportReportImages,
To: PublicreportReports,
FromColumns: []string{"report_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportReports.Columns.Names(), opts...)
},
}
}
type publicreportReportImageThenLoader[Q orm.Loadable] struct {
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportReportImageThenLoader[Q orm.Loadable]() publicreportReportImageThenLoader[Q] {
type ImageLoadInterface interface {
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReportLoadInterface interface {
LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportReportImageThenLoader[Q]{
Image: thenLoadBuilder[Q](
"Image",
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImage(ctx, exec, mods...)
},
),
Report: thenLoadBuilder[Q](
"Report",
func(ctx context.Context, exec bob.Executor, retrieved ReportLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReport(ctx, exec, mods...)
},
),
}
}
// LoadImage loads the publicreportReportImage's Image into the .R struct
func (o *PublicreportReportImage) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Image = nil
related, err := o.Image(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Image = related
return nil
}
// LoadImage loads the publicreportReportImage's Image into the .R struct
func (os PublicreportReportImageSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportImages, err := os.Image(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportImages {
if !(o.ImageID == rel.ID) {
continue
}
o.R.Image = rel
break
}
}
return nil
}
// LoadReport loads the publicreportReportImage's Report into the .R struct
func (o *PublicreportReportImage) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Report = nil
related, err := o.Report(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Report = related
return nil
}
// LoadReport loads the publicreportReportImage's Report into the .R struct
func (os PublicreportReportImageSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportReports, err := os.Report(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportReports {
if !(o.ReportID == rel.ID) {
continue
}
o.R.Report = rel
break
}
}
return nil
}

File diff suppressed because it is too large Load diff

View file

@ -1,721 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"fmt"
"io"
"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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// PublicreportWaterImage is an object representing the database table.
type PublicreportWaterImage struct {
ImageID int32 `db:"image_id,pk" `
WaterID int32 `db:"water_id,pk" `
R publicreportWaterImageR `db:"-" `
}
// PublicreportWaterImageSlice is an alias for a slice of pointers to PublicreportWaterImage.
// This should almost always be used instead of []*PublicreportWaterImage.
type PublicreportWaterImageSlice []*PublicreportWaterImage
// PublicreportWaterImages contains methods to work with the water_image table
var PublicreportWaterImages = psql.NewTablex[*PublicreportWaterImage, PublicreportWaterImageSlice, *PublicreportWaterImageSetter]("publicreport", "water_image", buildPublicreportWaterImageColumns("publicreport.water_image"))
// PublicreportWaterImagesQuery is a query on the water_image table
type PublicreportWaterImagesQuery = *psql.ViewQuery[*PublicreportWaterImage, PublicreportWaterImageSlice]
// publicreportWaterImageR is where relationships are stored.
type publicreportWaterImageR struct {
Image *PublicreportImage // publicreport.water_image.pool_image_image_id_fkey
Water *PublicreportWater // publicreport.water_image.pool_image_pool_id_fkey
}
func buildPublicreportWaterImageColumns(alias string) publicreportWaterImageColumns {
return publicreportWaterImageColumns{
ColumnsExpr: expr.NewColumnsExpr(
"image_id", "water_id",
).WithParent("publicreport.water_image"),
tableAlias: alias,
ImageID: psql.Quote(alias, "image_id"),
WaterID: psql.Quote(alias, "water_id"),
}
}
type publicreportWaterImageColumns struct {
expr.ColumnsExpr
tableAlias string
ImageID psql.Expression
WaterID psql.Expression
}
func (c publicreportWaterImageColumns) Alias() string {
return c.tableAlias
}
func (publicreportWaterImageColumns) AliasedAs(alias string) publicreportWaterImageColumns {
return buildPublicreportWaterImageColumns(alias)
}
// PublicreportWaterImageSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportWaterImageSetter struct {
ImageID omit.Val[int32] `db:"image_id,pk" `
WaterID omit.Val[int32] `db:"water_id,pk" `
}
func (s PublicreportWaterImageSetter) SetColumns() []string {
vals := make([]string, 0, 2)
if s.ImageID.IsValue() {
vals = append(vals, "image_id")
}
if s.WaterID.IsValue() {
vals = append(vals, "water_id")
}
return vals
}
func (s PublicreportWaterImageSetter) Overwrite(t *PublicreportWaterImage) {
if s.ImageID.IsValue() {
t.ImageID = s.ImageID.MustGet()
}
if s.WaterID.IsValue() {
t.WaterID = s.WaterID.MustGet()
}
}
func (s *PublicreportWaterImageSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportWaterImages.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, 2)
if s.ImageID.IsValue() {
vals[0] = psql.Arg(s.ImageID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.WaterID.IsValue() {
vals[1] = psql.Arg(s.WaterID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportWaterImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportWaterImageSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 2)
if s.ImageID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "image_id")...),
psql.Arg(s.ImageID),
}})
}
if s.WaterID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "water_id")...),
psql.Arg(s.WaterID),
}})
}
return exprs
}
// FindPublicreportWaterImage retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportWaterImage(ctx context.Context, exec bob.Executor, ImageIDPK int32, WaterIDPK int32, cols ...string) (*PublicreportWaterImage, error) {
if len(cols) == 0 {
return PublicreportWaterImages.Query(
sm.Where(PublicreportWaterImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportWaterImages.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
).One(ctx, exec)
}
return PublicreportWaterImages.Query(
sm.Where(PublicreportWaterImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportWaterImages.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Columns(PublicreportWaterImages.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportWaterImageExists checks the presence of a single record by primary key
func PublicreportWaterImageExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, WaterIDPK int32) (bool, error) {
return PublicreportWaterImages.Query(
sm.Where(PublicreportWaterImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportWaterImages.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportWaterImage is retrieved from the database
func (o *PublicreportWaterImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportWaterImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportWaterImageSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportWaterImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportWaterImageSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportWaterImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportWaterImageSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportWaterImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportWaterImageSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportWaterImage
func (o *PublicreportWaterImage) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ImageID,
o.WaterID,
)
}
func (o *PublicreportWaterImage) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.water_image", "image_id"), psql.Quote("publicreport.water_image", "water_id")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportWaterImage
func (o *PublicreportWaterImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportWaterImageSetter) error {
v, err := PublicreportWaterImages.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 PublicreportWaterImage record with an executor
func (o *PublicreportWaterImage) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportWaterImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportWaterImage using the executor
func (o *PublicreportWaterImage) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportWaterImages.Query(
sm.Where(PublicreportWaterImages.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
sm.Where(PublicreportWaterImages.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportWaterImageSlice is retrieved from the database
func (o PublicreportWaterImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportWaterImages.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportWaterImages.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportWaterImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportWaterImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportWaterImageSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.water_image", "image_id"), psql.Quote("publicreport.water_image", "water_id")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportWaterImageSlice) copyMatchingRows(from ...*PublicreportWaterImage) {
for i, old := range o {
for _, new := range from {
if new.ImageID != old.ImageID {
continue
}
if new.WaterID != old.WaterID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportWaterImageSlice) 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 PublicreportWaterImages.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 *PublicreportWaterImage:
o.copyMatchingRows(retrieved)
case []*PublicreportWaterImage:
o.copyMatchingRows(retrieved...)
case PublicreportWaterImageSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportWaterImage or a slice of PublicreportWaterImage
// then run the AfterUpdateHooks on the slice
_, err = PublicreportWaterImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportWaterImageSlice) 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 PublicreportWaterImages.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 *PublicreportWaterImage:
o.copyMatchingRows(retrieved)
case []*PublicreportWaterImage:
o.copyMatchingRows(retrieved...)
case PublicreportWaterImageSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportWaterImage or a slice of PublicreportWaterImage
// then run the AfterDeleteHooks on the slice
_, err = PublicreportWaterImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportWaterImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportWaterImageSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportWaterImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportWaterImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportWaterImages.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportWaterImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportWaterImages.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Image starts a query for related objects on publicreport.image
func (o *PublicreportWaterImage) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
return PublicreportImages.Query(append(mods,
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
)...)
}
func (os PublicreportWaterImageSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
pkImageID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkImageID = append(pkImageID, o.ImageID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
))
return PublicreportImages.Query(append(mods,
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// Water starts a query for related objects on publicreport.water
func (o *PublicreportWaterImage) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
return PublicreportWaters.Query(append(mods,
sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(o.WaterID))),
)...)
}
func (os PublicreportWaterImageSlice) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkWaterID = append(pkWaterID, o.WaterID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
))
return PublicreportWaters.Query(append(mods,
sm.Where(psql.Group(PublicreportWaters.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportWaterImageImage0(ctx context.Context, exec bob.Executor, count int, publicreportWaterImage0 *PublicreportWaterImage, publicreportImage1 *PublicreportImage) (*PublicreportWaterImage, error) {
setter := &PublicreportWaterImageSetter{
ImageID: omit.From(publicreportImage1.ID),
}
err := publicreportWaterImage0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportWaterImageImage0: %w", err)
}
return publicreportWaterImage0, nil
}
func (publicreportWaterImage0 *PublicreportWaterImage) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
var err error
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportWaterImageImage0(ctx, exec, 1, publicreportWaterImage0, publicreportImage1)
if err != nil {
return err
}
publicreportWaterImage0.R.Image = publicreportImage1
return nil
}
func (publicreportWaterImage0 *PublicreportWaterImage) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
var err error
_, err = attachPublicreportWaterImageImage0(ctx, exec, 1, publicreportWaterImage0, publicreportImage1)
if err != nil {
return err
}
publicreportWaterImage0.R.Image = publicreportImage1
return nil
}
func attachPublicreportWaterImageWater0(ctx context.Context, exec bob.Executor, count int, publicreportWaterImage0 *PublicreportWaterImage, publicreportWater1 *PublicreportWater) (*PublicreportWaterImage, error) {
setter := &PublicreportWaterImageSetter{
WaterID: omit.From(publicreportWater1.ID),
}
err := publicreportWaterImage0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportWaterImageWater0: %w", err)
}
return publicreportWaterImage0, nil
}
func (publicreportWaterImage0 *PublicreportWaterImage) InsertWater(ctx context.Context, exec bob.Executor, related *PublicreportWaterSetter) error {
var err error
publicreportWater1, err := PublicreportWaters.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportWaterImageWater0(ctx, exec, 1, publicreportWaterImage0, publicreportWater1)
if err != nil {
return err
}
publicreportWaterImage0.R.Water = publicreportWater1
return nil
}
func (publicreportWaterImage0 *PublicreportWaterImage) AttachWater(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWater) error {
var err error
_, err = attachPublicreportWaterImageWater0(ctx, exec, 1, publicreportWaterImage0, publicreportWater1)
if err != nil {
return err
}
publicreportWaterImage0.R.Water = publicreportWater1
return nil
}
type publicreportWaterImageWhere[Q psql.Filterable] struct {
ImageID psql.WhereMod[Q, int32]
WaterID psql.WhereMod[Q, int32]
}
func (publicreportWaterImageWhere[Q]) AliasedAs(alias string) publicreportWaterImageWhere[Q] {
return buildPublicreportWaterImageWhere[Q](buildPublicreportWaterImageColumns(alias))
}
func buildPublicreportWaterImageWhere[Q psql.Filterable](cols publicreportWaterImageColumns) publicreportWaterImageWhere[Q] {
return publicreportWaterImageWhere[Q]{
ImageID: psql.Where[Q, int32](cols.ImageID),
WaterID: psql.Where[Q, int32](cols.WaterID),
}
}
func (o *PublicreportWaterImage) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Image":
rel, ok := retrieved.(*PublicreportImage)
if !ok {
return fmt.Errorf("publicreportWaterImage cannot load %T as %q", retrieved, name)
}
o.R.Image = rel
return nil
case "Water":
rel, ok := retrieved.(*PublicreportWater)
if !ok {
return fmt.Errorf("publicreportWaterImage cannot load %T as %q", retrieved, name)
}
o.R.Water = rel
return nil
default:
return fmt.Errorf("publicreportWaterImage has no relationship %q", name)
}
}
type publicreportWaterImagePreloader struct {
Image func(...psql.PreloadOption) psql.Preloader
Water func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportWaterImagePreloader() publicreportWaterImagePreloader {
return publicreportWaterImagePreloader{
Image: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
Name: "Image",
Sides: []psql.PreloadSide{
{
From: PublicreportWaterImages,
To: PublicreportImages,
FromColumns: []string{"image_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportImages.Columns.Names(), opts...)
},
Water: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportWater, PublicreportWaterSlice](psql.PreloadRel{
Name: "Water",
Sides: []psql.PreloadSide{
{
From: PublicreportWaterImages,
To: PublicreportWaters,
FromColumns: []string{"water_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportWaters.Columns.Names(), opts...)
},
}
}
type publicreportWaterImageThenLoader[Q orm.Loadable] struct {
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportWaterImageThenLoader[Q orm.Loadable]() publicreportWaterImageThenLoader[Q] {
type ImageLoadInterface interface {
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterLoadInterface interface {
LoadWater(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportWaterImageThenLoader[Q]{
Image: thenLoadBuilder[Q](
"Image",
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImage(ctx, exec, mods...)
},
),
Water: thenLoadBuilder[Q](
"Water",
func(ctx context.Context, exec bob.Executor, retrieved WaterLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWater(ctx, exec, mods...)
},
),
}
}
// LoadImage loads the publicreportWaterImage's Image into the .R struct
func (o *PublicreportWaterImage) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Image = nil
related, err := o.Image(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Image = related
return nil
}
// LoadImage loads the publicreportWaterImage's Image into the .R struct
func (os PublicreportWaterImageSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportImages, err := os.Image(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportImages {
if !(o.ImageID == rel.ID) {
continue
}
o.R.Image = rel
break
}
}
return nil
}
// LoadWater loads the publicreportWaterImage's Water into the .R struct
func (o *PublicreportWaterImage) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Water = nil
related, err := o.Water(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Water = related
return nil
}
// LoadWater loads the publicreportWaterImage's Water into the .R struct
func (os PublicreportWaterImageSlice) LoadWater(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaters, err := os.Water(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaters {
if !(o.WaterID == rel.ID) {
continue
}
o.R.Water = rel
break
}
}
return nil
}

View file

@ -0,0 +1,721 @@
// 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"
"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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// PublicreportWaterImageOld is an object representing the database table.
type PublicreportWaterImageOld struct {
ImageID int32 `db:"image_id,pk" `
WaterID int32 `db:"water_id,pk" `
R publicreportWaterImageOldR `db:"-" `
}
// PublicreportWaterImageOldSlice is an alias for a slice of pointers to PublicreportWaterImageOld.
// This should almost always be used instead of []*PublicreportWaterImageOld.
type PublicreportWaterImageOldSlice []*PublicreportWaterImageOld
// PublicreportWaterImageOlds contains methods to work with the water_image_old table
var PublicreportWaterImageOlds = psql.NewTablex[*PublicreportWaterImageOld, PublicreportWaterImageOldSlice, *PublicreportWaterImageOldSetter]("publicreport", "water_image_old", buildPublicreportWaterImageOldColumns("publicreport.water_image_old"))
// PublicreportWaterImageOldsQuery is a query on the water_image_old table
type PublicreportWaterImageOldsQuery = *psql.ViewQuery[*PublicreportWaterImageOld, PublicreportWaterImageOldSlice]
// publicreportWaterImageOldR is where relationships are stored.
type publicreportWaterImageOldR struct {
Image *PublicreportImage // publicreport.water_image_old.pool_image_image_id_fkey
WaterWaterOld *PublicreportWaterOld // publicreport.water_image_old.pool_image_pool_id_fkey
}
func buildPublicreportWaterImageOldColumns(alias string) publicreportWaterImageOldColumns {
return publicreportWaterImageOldColumns{
ColumnsExpr: expr.NewColumnsExpr(
"image_id", "water_id",
).WithParent("publicreport.water_image_old"),
tableAlias: alias,
ImageID: psql.Quote(alias, "image_id"),
WaterID: psql.Quote(alias, "water_id"),
}
}
type publicreportWaterImageOldColumns struct {
expr.ColumnsExpr
tableAlias string
ImageID psql.Expression
WaterID psql.Expression
}
func (c publicreportWaterImageOldColumns) Alias() string {
return c.tableAlias
}
func (publicreportWaterImageOldColumns) AliasedAs(alias string) publicreportWaterImageOldColumns {
return buildPublicreportWaterImageOldColumns(alias)
}
// PublicreportWaterImageOldSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type PublicreportWaterImageOldSetter struct {
ImageID omit.Val[int32] `db:"image_id,pk" `
WaterID omit.Val[int32] `db:"water_id,pk" `
}
func (s PublicreportWaterImageOldSetter) SetColumns() []string {
vals := make([]string, 0, 2)
if s.ImageID.IsValue() {
vals = append(vals, "image_id")
}
if s.WaterID.IsValue() {
vals = append(vals, "water_id")
}
return vals
}
func (s PublicreportWaterImageOldSetter) Overwrite(t *PublicreportWaterImageOld) {
if s.ImageID.IsValue() {
t.ImageID = s.ImageID.MustGet()
}
if s.WaterID.IsValue() {
t.WaterID = s.WaterID.MustGet()
}
}
func (s *PublicreportWaterImageOldSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return PublicreportWaterImageOlds.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, 2)
if s.ImageID.IsValue() {
vals[0] = psql.Arg(s.ImageID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.WaterID.IsValue() {
vals[1] = psql.Arg(s.WaterID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s PublicreportWaterImageOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s PublicreportWaterImageOldSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 2)
if s.ImageID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "image_id")...),
psql.Arg(s.ImageID),
}})
}
if s.WaterID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "water_id")...),
psql.Arg(s.WaterID),
}})
}
return exprs
}
// FindPublicreportWaterImageOld retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindPublicreportWaterImageOld(ctx context.Context, exec bob.Executor, ImageIDPK int32, WaterIDPK int32, cols ...string) (*PublicreportWaterImageOld, error) {
if len(cols) == 0 {
return PublicreportWaterImageOlds.Query(
sm.Where(PublicreportWaterImageOlds.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportWaterImageOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
).One(ctx, exec)
}
return PublicreportWaterImageOlds.Query(
sm.Where(PublicreportWaterImageOlds.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportWaterImageOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
sm.Columns(PublicreportWaterImageOlds.Columns.Only(cols...)),
).One(ctx, exec)
}
// PublicreportWaterImageOldExists checks the presence of a single record by primary key
func PublicreportWaterImageOldExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, WaterIDPK int32) (bool, error) {
return PublicreportWaterImageOlds.Query(
sm.Where(PublicreportWaterImageOlds.Columns.ImageID.EQ(psql.Arg(ImageIDPK))),
sm.Where(PublicreportWaterImageOlds.Columns.WaterID.EQ(psql.Arg(WaterIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after PublicreportWaterImageOld is retrieved from the database
func (o *PublicreportWaterImageOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportWaterImageOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportWaterImageOldSlice{o})
case bob.QueryTypeInsert:
ctx, err = PublicreportWaterImageOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportWaterImageOldSlice{o})
case bob.QueryTypeUpdate:
ctx, err = PublicreportWaterImageOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportWaterImageOldSlice{o})
case bob.QueryTypeDelete:
ctx, err = PublicreportWaterImageOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportWaterImageOldSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the PublicreportWaterImageOld
func (o *PublicreportWaterImageOld) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.ImageID,
o.WaterID,
)
}
func (o *PublicreportWaterImageOld) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("publicreport.water_image_old", "image_id"), psql.Quote("publicreport.water_image_old", "water_id")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the PublicreportWaterImageOld
func (o *PublicreportWaterImageOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportWaterImageOldSetter) error {
v, err := PublicreportWaterImageOlds.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 PublicreportWaterImageOld record with an executor
func (o *PublicreportWaterImageOld) Delete(ctx context.Context, exec bob.Executor) error {
_, err := PublicreportWaterImageOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the PublicreportWaterImageOld using the executor
func (o *PublicreportWaterImageOld) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := PublicreportWaterImageOlds.Query(
sm.Where(PublicreportWaterImageOlds.Columns.ImageID.EQ(psql.Arg(o.ImageID))),
sm.Where(PublicreportWaterImageOlds.Columns.WaterID.EQ(psql.Arg(o.WaterID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after PublicreportWaterImageOldSlice is retrieved from the database
func (o PublicreportWaterImageOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = PublicreportWaterImageOlds.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = PublicreportWaterImageOlds.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = PublicreportWaterImageOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = PublicreportWaterImageOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o PublicreportWaterImageOldSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("publicreport.water_image_old", "image_id"), psql.Quote("publicreport.water_image_old", "water_id")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o PublicreportWaterImageOldSlice) copyMatchingRows(from ...*PublicreportWaterImageOld) {
for i, old := range o {
for _, new := range from {
if new.ImageID != old.ImageID {
continue
}
if new.WaterID != old.WaterID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o PublicreportWaterImageOldSlice) 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 PublicreportWaterImageOlds.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 *PublicreportWaterImageOld:
o.copyMatchingRows(retrieved)
case []*PublicreportWaterImageOld:
o.copyMatchingRows(retrieved...)
case PublicreportWaterImageOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportWaterImageOld or a slice of PublicreportWaterImageOld
// then run the AfterUpdateHooks on the slice
_, err = PublicreportWaterImageOlds.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o PublicreportWaterImageOldSlice) 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 PublicreportWaterImageOlds.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 *PublicreportWaterImageOld:
o.copyMatchingRows(retrieved)
case []*PublicreportWaterImageOld:
o.copyMatchingRows(retrieved...)
case PublicreportWaterImageOldSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a PublicreportWaterImageOld or a slice of PublicreportWaterImageOld
// then run the AfterDeleteHooks on the slice
_, err = PublicreportWaterImageOlds.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o PublicreportWaterImageOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportWaterImageOldSetter) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportWaterImageOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o PublicreportWaterImageOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := PublicreportWaterImageOlds.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o PublicreportWaterImageOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := PublicreportWaterImageOlds.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// Image starts a query for related objects on publicreport.image
func (o *PublicreportWaterImageOld) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
return PublicreportImages.Query(append(mods,
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))),
)...)
}
func (os PublicreportWaterImageOldSlice) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
pkImageID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkImageID = append(pkImageID, o.ImageID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkImageID), "integer[]")),
))
return PublicreportImages.Query(append(mods,
sm.Where(psql.Group(PublicreportImages.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// WaterWaterOld starts a query for related objects on publicreport.water_old
func (o *PublicreportWaterImageOld) WaterWaterOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
return PublicreportWaterOlds.Query(append(mods,
sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(o.WaterID))),
)...)
}
func (os PublicreportWaterImageOldSlice) WaterWaterOld(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery {
pkWaterID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkWaterID = append(pkWaterID, o.WaterID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkWaterID), "integer[]")),
))
return PublicreportWaterOlds.Query(append(mods,
sm.Where(psql.Group(PublicreportWaterOlds.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachPublicreportWaterImageOldImage0(ctx context.Context, exec bob.Executor, count int, publicreportWaterImageOld0 *PublicreportWaterImageOld, publicreportImage1 *PublicreportImage) (*PublicreportWaterImageOld, error) {
setter := &PublicreportWaterImageOldSetter{
ImageID: omit.From(publicreportImage1.ID),
}
err := publicreportWaterImageOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportWaterImageOldImage0: %w", err)
}
return publicreportWaterImageOld0, nil
}
func (publicreportWaterImageOld0 *PublicreportWaterImageOld) InsertImage(ctx context.Context, exec bob.Executor, related *PublicreportImageSetter) error {
var err error
publicreportImage1, err := PublicreportImages.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportWaterImageOldImage0(ctx, exec, 1, publicreportWaterImageOld0, publicreportImage1)
if err != nil {
return err
}
publicreportWaterImageOld0.R.Image = publicreportImage1
return nil
}
func (publicreportWaterImageOld0 *PublicreportWaterImageOld) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error {
var err error
_, err = attachPublicreportWaterImageOldImage0(ctx, exec, 1, publicreportWaterImageOld0, publicreportImage1)
if err != nil {
return err
}
publicreportWaterImageOld0.R.Image = publicreportImage1
return nil
}
func attachPublicreportWaterImageOldWaterWaterOld0(ctx context.Context, exec bob.Executor, count int, publicreportWaterImageOld0 *PublicreportWaterImageOld, publicreportWaterOld1 *PublicreportWaterOld) (*PublicreportWaterImageOld, error) {
setter := &PublicreportWaterImageOldSetter{
WaterID: omit.From(publicreportWaterOld1.ID),
}
err := publicreportWaterImageOld0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachPublicreportWaterImageOldWaterWaterOld0: %w", err)
}
return publicreportWaterImageOld0, nil
}
func (publicreportWaterImageOld0 *PublicreportWaterImageOld) InsertWaterWaterOld(ctx context.Context, exec bob.Executor, related *PublicreportWaterOldSetter) error {
var err error
publicreportWaterOld1, err := PublicreportWaterOlds.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachPublicreportWaterImageOldWaterWaterOld0(ctx, exec, 1, publicreportWaterImageOld0, publicreportWaterOld1)
if err != nil {
return err
}
publicreportWaterImageOld0.R.WaterWaterOld = publicreportWaterOld1
return nil
}
func (publicreportWaterImageOld0 *PublicreportWaterImageOld) AttachWaterWaterOld(ctx context.Context, exec bob.Executor, publicreportWaterOld1 *PublicreportWaterOld) error {
var err error
_, err = attachPublicreportWaterImageOldWaterWaterOld0(ctx, exec, 1, publicreportWaterImageOld0, publicreportWaterOld1)
if err != nil {
return err
}
publicreportWaterImageOld0.R.WaterWaterOld = publicreportWaterOld1
return nil
}
type publicreportWaterImageOldWhere[Q psql.Filterable] struct {
ImageID psql.WhereMod[Q, int32]
WaterID psql.WhereMod[Q, int32]
}
func (publicreportWaterImageOldWhere[Q]) AliasedAs(alias string) publicreportWaterImageOldWhere[Q] {
return buildPublicreportWaterImageOldWhere[Q](buildPublicreportWaterImageOldColumns(alias))
}
func buildPublicreportWaterImageOldWhere[Q psql.Filterable](cols publicreportWaterImageOldColumns) publicreportWaterImageOldWhere[Q] {
return publicreportWaterImageOldWhere[Q]{
ImageID: psql.Where[Q, int32](cols.ImageID),
WaterID: psql.Where[Q, int32](cols.WaterID),
}
}
func (o *PublicreportWaterImageOld) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "Image":
rel, ok := retrieved.(*PublicreportImage)
if !ok {
return fmt.Errorf("publicreportWaterImageOld cannot load %T as %q", retrieved, name)
}
o.R.Image = rel
return nil
case "WaterWaterOld":
rel, ok := retrieved.(*PublicreportWaterOld)
if !ok {
return fmt.Errorf("publicreportWaterImageOld cannot load %T as %q", retrieved, name)
}
o.R.WaterWaterOld = rel
return nil
default:
return fmt.Errorf("publicreportWaterImageOld has no relationship %q", name)
}
}
type publicreportWaterImageOldPreloader struct {
Image func(...psql.PreloadOption) psql.Preloader
WaterWaterOld func(...psql.PreloadOption) psql.Preloader
}
func buildPublicreportWaterImageOldPreloader() publicreportWaterImageOldPreloader {
return publicreportWaterImageOldPreloader{
Image: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{
Name: "Image",
Sides: []psql.PreloadSide{
{
From: PublicreportWaterImageOlds,
To: PublicreportImages,
FromColumns: []string{"image_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportImages.Columns.Names(), opts...)
},
WaterWaterOld: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportWaterOld, PublicreportWaterOldSlice](psql.PreloadRel{
Name: "WaterWaterOld",
Sides: []psql.PreloadSide{
{
From: PublicreportWaterImageOlds,
To: PublicreportWaterOlds,
FromColumns: []string{"water_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportWaterOlds.Columns.Names(), opts...)
},
}
}
type publicreportWaterImageOldThenLoader[Q orm.Loadable] struct {
Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
WaterWaterOld func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildPublicreportWaterImageOldThenLoader[Q orm.Loadable]() publicreportWaterImageOldThenLoader[Q] {
type ImageLoadInterface interface {
LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type WaterWaterOldLoadInterface interface {
LoadWaterWaterOld(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return publicreportWaterImageOldThenLoader[Q]{
Image: thenLoadBuilder[Q](
"Image",
func(ctx context.Context, exec bob.Executor, retrieved ImageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImage(ctx, exec, mods...)
},
),
WaterWaterOld: thenLoadBuilder[Q](
"WaterWaterOld",
func(ctx context.Context, exec bob.Executor, retrieved WaterWaterOldLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadWaterWaterOld(ctx, exec, mods...)
},
),
}
}
// LoadImage loads the publicreportWaterImageOld's Image into the .R struct
func (o *PublicreportWaterImageOld) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Image = nil
related, err := o.Image(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.Image = related
return nil
}
// LoadImage loads the publicreportWaterImageOld's Image into the .R struct
func (os PublicreportWaterImageOldSlice) LoadImage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportImages, err := os.Image(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportImages {
if !(o.ImageID == rel.ID) {
continue
}
o.R.Image = rel
break
}
}
return nil
}
// LoadWaterWaterOld loads the publicreportWaterImageOld's WaterWaterOld into the .R struct
func (o *PublicreportWaterImageOld) LoadWaterWaterOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.WaterWaterOld = nil
related, err := o.WaterWaterOld(mods...).One(ctx, exec)
if err != nil {
return err
}
o.R.WaterWaterOld = related
return nil
}
// LoadWaterWaterOld loads the publicreportWaterImageOld's WaterWaterOld into the .R struct
func (os PublicreportWaterImageOldSlice) LoadWaterWaterOld(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportWaterOlds, err := os.WaterWaterOld(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportWaterOlds {
if !(o.WaterID == rel.ID) {
continue
}
o.R.WaterWaterOld = rel
break
}
}
return nil
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,937 @@
// 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"
"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/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
"github.com/aarondl/opt/omit"
)
// ReportText is an object representing the database table.
type ReportText struct {
CreatorID int32 `db:"creator_id,pk" `
ReportID int32 `db:"report_id,pk" `
TextLogID int32 `db:"text_log_id,pk" `
R reportTextR `db:"-" `
}
// ReportTextSlice is an alias for a slice of pointers to ReportText.
// This should almost always be used instead of []*ReportText.
type ReportTextSlice []*ReportText
// ReportTexts contains methods to work with the report_text table
var ReportTexts = psql.NewTablex[*ReportText, ReportTextSlice, *ReportTextSetter]("", "report_text", buildReportTextColumns("report_text"))
// ReportTextsQuery is a query on the report_text table
type ReportTextsQuery = *psql.ViewQuery[*ReportText, ReportTextSlice]
// reportTextR is where relationships are stored.
type reportTextR struct {
CreatorUser *User // report_text.report_text_creator_id_fkey
Report *PublicreportReport // report_text.report_text_report_id_fkey
TextLog *CommsTextLog // report_text.report_text_text_log_id_fkey
}
func buildReportTextColumns(alias string) reportTextColumns {
return reportTextColumns{
ColumnsExpr: expr.NewColumnsExpr(
"creator_id", "report_id", "text_log_id",
).WithParent("report_text"),
tableAlias: alias,
CreatorID: psql.Quote(alias, "creator_id"),
ReportID: psql.Quote(alias, "report_id"),
TextLogID: psql.Quote(alias, "text_log_id"),
}
}
type reportTextColumns struct {
expr.ColumnsExpr
tableAlias string
CreatorID psql.Expression
ReportID psql.Expression
TextLogID psql.Expression
}
func (c reportTextColumns) Alias() string {
return c.tableAlias
}
func (reportTextColumns) AliasedAs(alias string) reportTextColumns {
return buildReportTextColumns(alias)
}
// ReportTextSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type ReportTextSetter struct {
CreatorID omit.Val[int32] `db:"creator_id,pk" `
ReportID omit.Val[int32] `db:"report_id,pk" `
TextLogID omit.Val[int32] `db:"text_log_id,pk" `
}
func (s ReportTextSetter) SetColumns() []string {
vals := make([]string, 0, 3)
if s.CreatorID.IsValue() {
vals = append(vals, "creator_id")
}
if s.ReportID.IsValue() {
vals = append(vals, "report_id")
}
if s.TextLogID.IsValue() {
vals = append(vals, "text_log_id")
}
return vals
}
func (s ReportTextSetter) Overwrite(t *ReportText) {
if s.CreatorID.IsValue() {
t.CreatorID = s.CreatorID.MustGet()
}
if s.ReportID.IsValue() {
t.ReportID = s.ReportID.MustGet()
}
if s.TextLogID.IsValue() {
t.TextLogID = s.TextLogID.MustGet()
}
}
func (s *ReportTextSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return ReportTexts.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, 3)
if s.CreatorID.IsValue() {
vals[0] = psql.Arg(s.CreatorID.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.ReportID.IsValue() {
vals[1] = psql.Arg(s.ReportID.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.TextLogID.IsValue() {
vals[2] = psql.Arg(s.TextLogID.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s ReportTextSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s ReportTextSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 3)
if s.CreatorID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "creator_id")...),
psql.Arg(s.CreatorID),
}})
}
if s.ReportID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "report_id")...),
psql.Arg(s.ReportID),
}})
}
if s.TextLogID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "text_log_id")...),
psql.Arg(s.TextLogID),
}})
}
return exprs
}
// FindReportText retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindReportText(ctx context.Context, exec bob.Executor, CreatorIDPK int32, ReportIDPK int32, TextLogIDPK int32, cols ...string) (*ReportText, error) {
if len(cols) == 0 {
return ReportTexts.Query(
sm.Where(ReportTexts.Columns.CreatorID.EQ(psql.Arg(CreatorIDPK))),
sm.Where(ReportTexts.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(ReportTexts.Columns.TextLogID.EQ(psql.Arg(TextLogIDPK))),
).One(ctx, exec)
}
return ReportTexts.Query(
sm.Where(ReportTexts.Columns.CreatorID.EQ(psql.Arg(CreatorIDPK))),
sm.Where(ReportTexts.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(ReportTexts.Columns.TextLogID.EQ(psql.Arg(TextLogIDPK))),
sm.Columns(ReportTexts.Columns.Only(cols...)),
).One(ctx, exec)
}
// ReportTextExists checks the presence of a single record by primary key
func ReportTextExists(ctx context.Context, exec bob.Executor, CreatorIDPK int32, ReportIDPK int32, TextLogIDPK int32) (bool, error) {
return ReportTexts.Query(
sm.Where(ReportTexts.Columns.CreatorID.EQ(psql.Arg(CreatorIDPK))),
sm.Where(ReportTexts.Columns.ReportID.EQ(psql.Arg(ReportIDPK))),
sm.Where(ReportTexts.Columns.TextLogID.EQ(psql.Arg(TextLogIDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after ReportText is retrieved from the database
func (o *ReportText) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = ReportTexts.AfterSelectHooks.RunHooks(ctx, exec, ReportTextSlice{o})
case bob.QueryTypeInsert:
ctx, err = ReportTexts.AfterInsertHooks.RunHooks(ctx, exec, ReportTextSlice{o})
case bob.QueryTypeUpdate:
ctx, err = ReportTexts.AfterUpdateHooks.RunHooks(ctx, exec, ReportTextSlice{o})
case bob.QueryTypeDelete:
ctx, err = ReportTexts.AfterDeleteHooks.RunHooks(ctx, exec, ReportTextSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the ReportText
func (o *ReportText) primaryKeyVals() bob.Expression {
return psql.ArgGroup(
o.CreatorID,
o.ReportID,
o.TextLogID,
)
}
func (o *ReportText) pkEQ() dialect.Expression {
return psql.Group(psql.Quote("report_text", "creator_id"), psql.Quote("report_text", "report_id"), psql.Quote("report_text", "text_log_id")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
}))
}
// Update uses an executor to update the ReportText
func (o *ReportText) Update(ctx context.Context, exec bob.Executor, s *ReportTextSetter) error {
v, err := ReportTexts.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 ReportText record with an executor
func (o *ReportText) Delete(ctx context.Context, exec bob.Executor) error {
_, err := ReportTexts.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the ReportText using the executor
func (o *ReportText) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := ReportTexts.Query(
sm.Where(ReportTexts.Columns.CreatorID.EQ(psql.Arg(o.CreatorID))),
sm.Where(ReportTexts.Columns.ReportID.EQ(psql.Arg(o.ReportID))),
sm.Where(ReportTexts.Columns.TextLogID.EQ(psql.Arg(o.TextLogID))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after ReportTextSlice is retrieved from the database
func (o ReportTextSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = ReportTexts.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = ReportTexts.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = ReportTexts.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = ReportTexts.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o ReportTextSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Group(psql.Quote("report_text", "creator_id"), psql.Quote("report_text", "report_id"), psql.Quote("report_text", "text_log_id")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
pkPairs := make([]bob.Expression, len(o))
for i, row := range o {
pkPairs[i] = row.primaryKeyVals()
}
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
}))
}
// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o ReportTextSlice) copyMatchingRows(from ...*ReportText) {
for i, old := range o {
for _, new := range from {
if new.CreatorID != old.CreatorID {
continue
}
if new.ReportID != old.ReportID {
continue
}
if new.TextLogID != old.TextLogID {
continue
}
new.R = old.R
o[i] = new
break
}
}
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o ReportTextSlice) 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 ReportTexts.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 *ReportText:
o.copyMatchingRows(retrieved)
case []*ReportText:
o.copyMatchingRows(retrieved...)
case ReportTextSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a ReportText or a slice of ReportText
// then run the AfterUpdateHooks on the slice
_, err = ReportTexts.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o ReportTextSlice) 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 ReportTexts.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 *ReportText:
o.copyMatchingRows(retrieved)
case []*ReportText:
o.copyMatchingRows(retrieved...)
case ReportTextSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a ReportText or a slice of ReportText
// then run the AfterDeleteHooks on the slice
_, err = ReportTexts.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o ReportTextSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ReportTextSetter) error {
if len(o) == 0 {
return nil
}
_, err := ReportTexts.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o ReportTextSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := ReportTexts.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o ReportTextSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := ReportTexts.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// CreatorUser starts a query for related objects on user_
func (o *ReportText) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.CreatorID))),
)...)
}
func (os ReportTextSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkCreatorID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkCreatorID = append(pkCreatorID, o.CreatorID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkCreatorID), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// Report starts a query for related objects on publicreport.report
func (o *ReportText) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
return PublicreportReports.Query(append(mods,
sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))),
)...)
}
func (os ReportTextSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery {
pkReportID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkReportID = append(pkReportID, o.ReportID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")),
))
return PublicreportReports.Query(append(mods,
sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// TextLog starts a query for related objects on comms.text_log
func (o *ReportText) TextLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
return CommsTextLogs.Query(append(mods,
sm.Where(CommsTextLogs.Columns.ID.EQ(psql.Arg(o.TextLogID))),
)...)
}
func (os ReportTextSlice) TextLog(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextLogsQuery {
pkTextLogID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkTextLogID = append(pkTextLogID, o.TextLogID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkTextLogID), "integer[]")),
))
return CommsTextLogs.Query(append(mods,
sm.Where(psql.Group(CommsTextLogs.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
func attachReportTextCreatorUser0(ctx context.Context, exec bob.Executor, count int, reportText0 *ReportText, user1 *User) (*ReportText, error) {
setter := &ReportTextSetter{
CreatorID: omit.From(user1.ID),
}
err := reportText0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachReportTextCreatorUser0: %w", err)
}
return reportText0, nil
}
func (reportText0 *ReportText) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachReportTextCreatorUser0(ctx, exec, 1, reportText0, user1)
if err != nil {
return err
}
reportText0.R.CreatorUser = user1
user1.R.CreatorReportTexts = append(user1.R.CreatorReportTexts, reportText0)
return nil
}
func (reportText0 *ReportText) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachReportTextCreatorUser0(ctx, exec, 1, reportText0, user1)
if err != nil {
return err
}
reportText0.R.CreatorUser = user1
user1.R.CreatorReportTexts = append(user1.R.CreatorReportTexts, reportText0)
return nil
}
func attachReportTextReport0(ctx context.Context, exec bob.Executor, count int, reportText0 *ReportText, publicreportReport1 *PublicreportReport) (*ReportText, error) {
setter := &ReportTextSetter{
ReportID: omit.From(publicreportReport1.ID),
}
err := reportText0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachReportTextReport0: %w", err)
}
return reportText0, nil
}
func (reportText0 *ReportText) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error {
var err error
publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachReportTextReport0(ctx, exec, 1, reportText0, publicreportReport1)
if err != nil {
return err
}
reportText0.R.Report = publicreportReport1
publicreportReport1.R.ReportTexts = append(publicreportReport1.R.ReportTexts, reportText0)
return nil
}
func (reportText0 *ReportText) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error {
var err error
_, err = attachReportTextReport0(ctx, exec, 1, reportText0, publicreportReport1)
if err != nil {
return err
}
reportText0.R.Report = publicreportReport1
publicreportReport1.R.ReportTexts = append(publicreportReport1.R.ReportTexts, reportText0)
return nil
}
func attachReportTextTextLog0(ctx context.Context, exec bob.Executor, count int, reportText0 *ReportText, commsTextLog1 *CommsTextLog) (*ReportText, error) {
setter := &ReportTextSetter{
TextLogID: omit.From(commsTextLog1.ID),
}
err := reportText0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachReportTextTextLog0: %w", err)
}
return reportText0, nil
}
func (reportText0 *ReportText) InsertTextLog(ctx context.Context, exec bob.Executor, related *CommsTextLogSetter) error {
var err error
commsTextLog1, err := CommsTextLogs.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachReportTextTextLog0(ctx, exec, 1, reportText0, commsTextLog1)
if err != nil {
return err
}
reportText0.R.TextLog = commsTextLog1
commsTextLog1.R.ReportTexts = append(commsTextLog1.R.ReportTexts, reportText0)
return nil
}
func (reportText0 *ReportText) AttachTextLog(ctx context.Context, exec bob.Executor, commsTextLog1 *CommsTextLog) error {
var err error
_, err = attachReportTextTextLog0(ctx, exec, 1, reportText0, commsTextLog1)
if err != nil {
return err
}
reportText0.R.TextLog = commsTextLog1
commsTextLog1.R.ReportTexts = append(commsTextLog1.R.ReportTexts, reportText0)
return nil
}
type reportTextWhere[Q psql.Filterable] struct {
CreatorID psql.WhereMod[Q, int32]
ReportID psql.WhereMod[Q, int32]
TextLogID psql.WhereMod[Q, int32]
}
func (reportTextWhere[Q]) AliasedAs(alias string) reportTextWhere[Q] {
return buildReportTextWhere[Q](buildReportTextColumns(alias))
}
func buildReportTextWhere[Q psql.Filterable](cols reportTextColumns) reportTextWhere[Q] {
return reportTextWhere[Q]{
CreatorID: psql.Where[Q, int32](cols.CreatorID),
ReportID: psql.Where[Q, int32](cols.ReportID),
TextLogID: psql.Where[Q, int32](cols.TextLogID),
}
}
func (o *ReportText) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "CreatorUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("reportText cannot load %T as %q", retrieved, name)
}
o.R.CreatorUser = rel
if rel != nil {
rel.R.CreatorReportTexts = ReportTextSlice{o}
}
return nil
case "Report":
rel, ok := retrieved.(*PublicreportReport)
if !ok {
return fmt.Errorf("reportText cannot load %T as %q", retrieved, name)
}
o.R.Report = rel
if rel != nil {
rel.R.ReportTexts = ReportTextSlice{o}
}
return nil
case "TextLog":
rel, ok := retrieved.(*CommsTextLog)
if !ok {
return fmt.Errorf("reportText cannot load %T as %q", retrieved, name)
}
o.R.TextLog = rel
if rel != nil {
rel.R.ReportTexts = ReportTextSlice{o}
}
return nil
default:
return fmt.Errorf("reportText has no relationship %q", name)
}
}
type reportTextPreloader struct {
CreatorUser func(...psql.PreloadOption) psql.Preloader
Report func(...psql.PreloadOption) psql.Preloader
TextLog func(...psql.PreloadOption) psql.Preloader
}
func buildReportTextPreloader() reportTextPreloader {
return reportTextPreloader{
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "CreatorUser",
Sides: []psql.PreloadSide{
{
From: ReportTexts,
To: Users,
FromColumns: []string{"creator_id"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
Report: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{
Name: "Report",
Sides: []psql.PreloadSide{
{
From: ReportTexts,
To: PublicreportReports,
FromColumns: []string{"report_id"},
ToColumns: []string{"id"},
},
},
}, PublicreportReports.Columns.Names(), opts...)
},
TextLog: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsTextLog, CommsTextLogSlice](psql.PreloadRel{
Name: "TextLog",
Sides: []psql.PreloadSide{
{
From: ReportTexts,
To: CommsTextLogs,
FromColumns: []string{"text_log_id"},
ToColumns: []string{"id"},
},
},
}, CommsTextLogs.Columns.Names(), opts...)
},
}
}
type reportTextThenLoader[Q orm.Loadable] struct {
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
TextLog func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildReportTextThenLoader[Q orm.Loadable]() reportTextThenLoader[Q] {
type CreatorUserLoadInterface interface {
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ReportLoadInterface interface {
LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type TextLogLoadInterface interface {
LoadTextLog(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return reportTextThenLoader[Q]{
CreatorUser: thenLoadBuilder[Q](
"CreatorUser",
func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCreatorUser(ctx, exec, mods...)
},
),
Report: thenLoadBuilder[Q](
"Report",
func(ctx context.Context, exec bob.Executor, retrieved ReportLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadReport(ctx, exec, mods...)
},
),
TextLog: thenLoadBuilder[Q](
"TextLog",
func(ctx context.Context, exec bob.Executor, retrieved TextLogLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadTextLog(ctx, exec, mods...)
},
),
}
}
// LoadCreatorUser loads the reportText's CreatorUser into the .R struct
func (o *ReportText) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.CreatorUser = nil
related, err := o.CreatorUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.CreatorReportTexts = ReportTextSlice{o}
o.R.CreatorUser = related
return nil
}
// LoadCreatorUser loads the reportText's CreatorUser into the .R struct
func (os ReportTextSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.CreatorUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !(o.CreatorID == rel.ID) {
continue
}
rel.R.CreatorReportTexts = append(rel.R.CreatorReportTexts, o)
o.R.CreatorUser = rel
break
}
}
return nil
}
// LoadReport loads the reportText's Report into the .R struct
func (o *ReportText) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Report = nil
related, err := o.Report(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ReportTexts = ReportTextSlice{o}
o.R.Report = related
return nil
}
// LoadReport loads the reportText's Report into the .R struct
func (os ReportTextSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
publicreportReports, err := os.Report(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range publicreportReports {
if !(o.ReportID == rel.ID) {
continue
}
rel.R.ReportTexts = append(rel.R.ReportTexts, o)
o.R.Report = rel
break
}
}
return nil
}
// LoadTextLog loads the reportText's TextLog into the .R struct
func (o *ReportText) LoadTextLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.TextLog = nil
related, err := o.TextLog(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ReportTexts = ReportTextSlice{o}
o.R.TextLog = related
return nil
}
// LoadTextLog loads the reportText's TextLog into the .R struct
func (os ReportTextSlice) LoadTextLog(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsTextLogs, err := os.TextLog(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsTextLogs {
if !(o.TextLogID == rel.ID) {
continue
}
rel.R.ReportTexts = append(rel.R.ReportTexts, o)
o.R.TextLog = rel
break
}
}
return nil
}

File diff suppressed because it is too large Load diff

View file

@ -1,112 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
_ "embed"
"io"
"iter"
"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/orm"
"github.com/aarondl/opt/null"
"github.com/google/uuid"
"github.com/stephenafamo/scan"
)
//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:999]
type PublicreportImageWithJSONByNuisanceIDQuery = orm.ModQuery[*dialect.SelectQuery, publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer]
func PublicreportImageWithJSONByNuisanceID(NuisanceID int32) *PublicreportImageWithJSONByNuisanceIDQuery {
var expressionTypArgs publicreportImageWithJSONByNuisanceID
expressionTypArgs.NuisanceID = psql.Arg(NuisanceID)
return &PublicreportImageWithJSONByNuisanceIDQuery{
Query: orm.Query[publicreportImageWithJSONByNuisanceID, PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow, publicreportImageWithJSONByNuisanceIDTransformer]{
ExecQuery: orm.ExecQuery[publicreportImageWithJSONByNuisanceID]{
BaseQuery: bob.BaseQuery[publicreportImageWithJSONByNuisanceID]{
Expression: expressionTypArgs,
Dialect: dialect.Dialect,
QueryType: bob.QueryTypeSelect,
},
},
Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportImageWithJSONByNuisanceIDRow, error)) {
return func(row *scan.Row) (any, error) {
var t PublicreportImageWithJSONByNuisanceIDRow
row.ScheduleScanByIndex(0, &t.ID)
row.ScheduleScanByIndex(1, &t.ContentType)
row.ScheduleScanByIndex(2, &t.Created)
row.ScheduleScanByIndex(3, &t.Location)
row.ScheduleScanByIndex(4, &t.LocationJSON)
row.ScheduleScanByIndex(5, &t.ResolutionX)
row.ScheduleScanByIndex(6, &t.ResolutionY)
row.ScheduleScanByIndex(7, &t.StorageUUID)
row.ScheduleScanByIndex(8, &t.StorageSize)
row.ScheduleScanByIndex(9, &t.UploadedFilename)
return &t, nil
}, func(v any) (PublicreportImageWithJSONByNuisanceIDRow, error) {
return *(v.(*PublicreportImageWithJSONByNuisanceIDRow)), nil
}
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(9, 565))
q.SetTable(expressionTypArgs.subExpr(571, 767))
q.AppendWhere(expressionTypArgs.subExpr(775, 823))
}),
}
}
type PublicreportImageWithJSONByNuisanceIDRow = struct {
ID int32 `db:"id"`
ContentType string `db:"content_type"`
Created time.Time `db:"created"`
Location null.Val[string] `db:"location"`
LocationJSON string `db:"location_json"`
ResolutionX int32 `db:"resolution_x"`
ResolutionY int32 `db:"resolution_y"`
StorageUUID uuid.UUID `db:"storage_uuid"`
StorageSize int64 `db:"storage_size"`
UploadedFilename string `db:"uploaded_filename"`
}
type publicreportImageWithJSONByNuisanceIDTransformer = bob.SliceTransformer[PublicreportImageWithJSONByNuisanceIDRow, []PublicreportImageWithJSONByNuisanceIDRow]
type publicreportImageWithJSONByNuisanceID struct {
NuisanceID bob.Expression
}
func (o publicreportImageWithJSONByNuisanceID) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "nuisanceID",
Start: 821,
Stop: 823,
Expression: o.NuisanceID,
}) {
return
}
}
}
func (o publicreportImageWithJSONByNuisanceID) raw(from, to int) string {
return publicreportImageWithJSONByNuisanceIDSQL[from:to]
}
func (o publicreportImageWithJSONByNuisanceID) subExpr(from, to int) bob.Expression {
return orm.ArgsToExpression(publicreportImageWithJSONByNuisanceIDSQL, from, to, o.args())
}
func (o publicreportImageWithJSONByNuisanceID) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.subExpr(0, len(publicreportImageWithJSONByNuisanceIDSQL)).WriteSQL(ctx, w, d, start)
}

View file

@ -1,18 +0,0 @@
-- Code generated by BobGen psql v0.42.5. DO NOT EDIT.
-- This file is meant to be re-generated in place and/or deleted at any time.
-- PublicreportImageWithJSONByNuisanceID
SELECT
"publicreport.image"."id" AS "id",
"publicreport.image"."content_type" AS "content_type",
"publicreport.image"."created" AS "created",
"publicreport.image"."location" AS "location",
COALESCE(ST_AsGeoJSON("publicreport.image"."location"), '{}') AS "location_json",
"publicreport.image"."resolution_x" AS "resolution_x",
"publicreport.image"."resolution_y" AS "resolution_y",
"publicreport.image"."storage_uuid" AS "storage_uuid",
"publicreport.image"."storage_size" AS "storage_size",
"publicreport.image"."uploaded_filename" AS "uploaded_filename"
FROM "publicreport"."image" AS "publicreport.image"
INNER JOIN "publicreport"."nuisance_image" AS "publicreport.nuisance_image" ON ("publicreport.image"."id" = "publicreport.nuisance_image"."image_id")
WHERE ("publicreport.nuisance_image"."nuisance_id" = $1);

View file

@ -1,15 +0,0 @@
-- PublicreportImageWithJSONByNuisanceID
SELECT
"publicreport.image"."id" AS "id",
"publicreport.image"."content_type" AS "content_type",
"publicreport.image"."created" AS "created",
"publicreport.image"."location" AS "location",
COALESCE(ST_AsGeoJSON("publicreport.image"."location"), '{}') AS "location_json",
"publicreport.image"."resolution_x" AS "resolution_x",
"publicreport.image"."resolution_y" AS "resolution_y",
"publicreport.image"."storage_uuid" AS "storage_uuid",
"publicreport.image"."storage_size" AS "storage_size",
"publicreport.image"."uploaded_filename" AS "uploaded_filename"
FROM "publicreport"."image" AS "publicreport.image"
INNER JOIN "publicreport"."nuisance_image" AS "publicreport.nuisance_image" ON ("publicreport.image"."id" = "publicreport.nuisance_image"."image_id")
WHERE ("publicreport.nuisance_image"."nuisance_id" = $1)

View file

@ -1,112 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
_ "embed"
"io"
"iter"
"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/orm"
"github.com/aarondl/opt/null"
"github.com/google/uuid"
"github.com/stephenafamo/scan"
)
//go:embed publicreport_image_with_json_by_water_id.bob.sql
var formattedQueries_publicreport_image_with_json_by_water_id string
var publicreportImageWithJSONByWaterIDSQL = formattedQueries_publicreport_image_with_json_by_water_id[172:981]
type PublicreportImageWithJSONByWaterIDQuery = orm.ModQuery[*dialect.SelectQuery, publicreportImageWithJSONByWaterID, PublicreportImageWithJSONByWaterIDRow, []PublicreportImageWithJSONByWaterIDRow, publicreportImageWithJSONByWaterIDTransformer]
func PublicreportImageWithJSONByWaterID(WaterID int32) *PublicreportImageWithJSONByWaterIDQuery {
var expressionTypArgs publicreportImageWithJSONByWaterID
expressionTypArgs.WaterID = psql.Arg(WaterID)
return &PublicreportImageWithJSONByWaterIDQuery{
Query: orm.Query[publicreportImageWithJSONByWaterID, PublicreportImageWithJSONByWaterIDRow, []PublicreportImageWithJSONByWaterIDRow, publicreportImageWithJSONByWaterIDTransformer]{
ExecQuery: orm.ExecQuery[publicreportImageWithJSONByWaterID]{
BaseQuery: bob.BaseQuery[publicreportImageWithJSONByWaterID]{
Expression: expressionTypArgs,
Dialect: dialect.Dialect,
QueryType: bob.QueryTypeSelect,
},
},
Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportImageWithJSONByWaterIDRow, error)) {
return func(row *scan.Row) (any, error) {
var t PublicreportImageWithJSONByWaterIDRow
row.ScheduleScanByIndex(0, &t.ID)
row.ScheduleScanByIndex(1, &t.ContentType)
row.ScheduleScanByIndex(2, &t.Created)
row.ScheduleScanByIndex(3, &t.Location)
row.ScheduleScanByIndex(4, &t.LocationJSON)
row.ScheduleScanByIndex(5, &t.ResolutionX)
row.ScheduleScanByIndex(6, &t.ResolutionY)
row.ScheduleScanByIndex(7, &t.StorageUUID)
row.ScheduleScanByIndex(8, &t.StorageSize)
row.ScheduleScanByIndex(9, &t.UploadedFilename)
return &t, nil
}, func(v any) (PublicreportImageWithJSONByWaterIDRow, error) {
return *(v.(*PublicreportImageWithJSONByWaterIDRow)), nil
}
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(9, 565))
q.SetTable(expressionTypArgs.subExpr(571, 758))
q.AppendWhere(expressionTypArgs.subExpr(766, 808))
}),
}
}
type PublicreportImageWithJSONByWaterIDRow = struct {
ID int32 `db:"id"`
ContentType string `db:"content_type"`
Created time.Time `db:"created"`
Location null.Val[string] `db:"location"`
LocationJSON string `db:"location_json"`
ResolutionX int32 `db:"resolution_x"`
ResolutionY int32 `db:"resolution_y"`
StorageUUID uuid.UUID `db:"storage_uuid"`
StorageSize int64 `db:"storage_size"`
UploadedFilename string `db:"uploaded_filename"`
}
type publicreportImageWithJSONByWaterIDTransformer = bob.SliceTransformer[PublicreportImageWithJSONByWaterIDRow, []PublicreportImageWithJSONByWaterIDRow]
type publicreportImageWithJSONByWaterID struct {
WaterID bob.Expression
}
func (o publicreportImageWithJSONByWaterID) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "waterID",
Start: 806,
Stop: 808,
Expression: o.WaterID,
}) {
return
}
}
}
func (o publicreportImageWithJSONByWaterID) raw(from, to int) string {
return publicreportImageWithJSONByWaterIDSQL[from:to]
}
func (o publicreportImageWithJSONByWaterID) subExpr(from, to int) bob.Expression {
return orm.ArgsToExpression(publicreportImageWithJSONByWaterIDSQL, from, to, o.args())
}
func (o publicreportImageWithJSONByWaterID) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.subExpr(0, len(publicreportImageWithJSONByWaterIDSQL)).WriteSQL(ctx, w, d, start)
}

View file

@ -1,18 +0,0 @@
-- Code generated by BobGen psql v0.42.5. DO NOT EDIT.
-- This file is meant to be re-generated in place and/or deleted at any time.
-- PublicreportImageWithJSONByWaterID
SELECT
"publicreport.image"."id" AS "id",
"publicreport.image"."content_type" AS "content_type",
"publicreport.image"."created" AS "created",
"publicreport.image"."location" AS "location",
COALESCE(ST_AsGeoJSON("publicreport.image"."location"), '{}') AS "location_json",
"publicreport.image"."resolution_x" AS "resolution_x",
"publicreport.image"."resolution_y" AS "resolution_y",
"publicreport.image"."storage_uuid" AS "storage_uuid",
"publicreport.image"."storage_size" AS "storage_size",
"publicreport.image"."uploaded_filename" AS "uploaded_filename"
FROM "publicreport"."image" AS "publicreport.image"
INNER JOIN "publicreport"."water_image" AS "publicreport.water_image" ON ("publicreport.image"."id" = "publicreport.water_image"."image_id")
WHERE ("publicreport.water_image"."water_id" = $1);

View file

@ -1,15 +0,0 @@
-- PublicreportImageWithJSONByWaterID
SELECT
"publicreport.image"."id" AS "id",
"publicreport.image"."content_type" AS "content_type",
"publicreport.image"."created" AS "created",
"publicreport.image"."location" AS "location",
COALESCE(ST_AsGeoJSON("publicreport.image"."location"), '{}') AS "location_json",
"publicreport.image"."resolution_x" AS "resolution_x",
"publicreport.image"."resolution_y" AS "resolution_y",
"publicreport.image"."storage_uuid" AS "storage_uuid",
"publicreport.image"."storage_size" AS "storage_size",
"publicreport.image"."uploaded_filename" AS "uploaded_filename"
FROM "publicreport"."image" AS "publicreport.image"
INNER JOIN "publicreport"."water_image" AS "publicreport.water_image" ON ("publicreport.image"."id" = "publicreport.water_image"."image_id")
WHERE ("publicreport.water_image"."water_id" = $1)

View file

@ -1,117 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
_ "embed"
"io"
"iter"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/clause"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/aarondl/opt/null"
"github.com/stephenafamo/scan"
)
//go:embed publicreport_publicid_suggestion.bob.sql
var formattedQueries_publicreport_publicid_suggestion string
var publicreportPublicIDSuggestionSQL = formattedQueries_publicreport_publicid_suggestion[168:428]
type PublicreportPublicIDSuggestionQuery = orm.ModQuery[*dialect.SelectQuery, publicreportPublicIDSuggestion, PublicreportPublicIDSuggestionRow, []PublicreportPublicIDSuggestionRow, publicreportPublicIDSuggestionTransformer]
func PublicreportPublicIDSuggestion(Arg1 string) *PublicreportPublicIDSuggestionQuery {
var expressionTypArgs publicreportPublicIDSuggestion
expressionTypArgs.Arg1 = psql.Arg(Arg1)
return &PublicreportPublicIDSuggestionQuery{
Query: orm.Query[publicreportPublicIDSuggestion, PublicreportPublicIDSuggestionRow, []PublicreportPublicIDSuggestionRow, publicreportPublicIDSuggestionTransformer]{
ExecQuery: orm.ExecQuery[publicreportPublicIDSuggestion]{
BaseQuery: bob.BaseQuery[publicreportPublicIDSuggestion]{
Expression: expressionTypArgs,
Dialect: dialect.Dialect,
QueryType: bob.QueryTypeSelect,
},
},
Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportPublicIDSuggestionRow, error)) {
return func(row *scan.Row) (any, error) {
var t PublicreportPublicIDSuggestionRow
row.ScheduleScanByIndex(0, &t.TableName)
row.ScheduleScanByIndex(1, &t.PublicID)
row.ScheduleScanByIndex(2, &t.Location)
return &t, nil
}, func(v any) (PublicreportPublicIDSuggestionRow, error) {
return *(v.(*PublicreportPublicIDSuggestionRow)), nil
}
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(10, 59))
q.SetTable(expressionTypArgs.subExpr(68, 89))
q.AppendWhere(expressionTypArgs.subExpr(99, 116))
q.AppendCombine(clause.Combine{
Strategy: "UNION",
All: true,
Query: bob.BaseQuery[bob.Expression]{
Expression: expressionTypArgs.subExpr(129, 239),
QueryType: bob.QueryTypeSelect,
Dialect: dialect.Dialect,
},
})
q.CombinedOrder.AppendOrder(expressionTypArgs.subExpr(251, 260))
}),
}
}
type PublicreportPublicIDSuggestionRow = struct {
TableName string `db:"table_name"`
PublicID string `db:"public_id"`
Location null.Val[string] `db:"location"`
}
type publicreportPublicIDSuggestionTransformer = bob.SliceTransformer[PublicreportPublicIDSuggestionRow, []PublicreportPublicIDSuggestionRow]
type publicreportPublicIDSuggestion struct {
Arg1 bob.Expression
}
func (o publicreportPublicIDSuggestion) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "arg1",
Start: 114,
Stop: 116,
Expression: o.Arg1,
}) {
return
}
if !yield(orm.ArgWithPosition{
Name: "arg1",
Start: 237,
Stop: 239,
Expression: o.Arg1,
}) {
return
}
}
}
func (o publicreportPublicIDSuggestion) raw(from, to int) string {
return publicreportPublicIDSuggestionSQL[from:to]
}
func (o publicreportPublicIDSuggestion) subExpr(from, to int) bob.Expression {
return orm.ArgsToExpression(publicreportPublicIDSuggestionSQL, from, to, o.args())
}
func (o publicreportPublicIDSuggestion) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.subExpr(0, len(publicreportPublicIDSuggestionSQL)).WriteSQL(ctx, w, d, start)
}

View file

@ -1,25 +0,0 @@
-- Code generated by BobGen psql v0.42.5. DO NOT EDIT.
-- This file is meant to be re-generated in place and/or deleted at any time.
-- PublicreportPublicIDSuggestion
SELECT
'nuisance' AS table_name,
public_id,
location
FROM
publicreport.nuisance
WHERE
public_id LIKE $1
UNION ALL
SELECT
'water' AS table_name,
public_id,
location
FROM
publicreport.water
WHERE
public_id LIKE $2
ORDER BY
public_id;

View file

@ -1,22 +0,0 @@
-- PublicreportPublicIDSuggestion
SELECT
'nuisance' AS table_name,
public_id,
location
FROM
publicreport.nuisance
WHERE
public_id LIKE $1
UNION ALL
SELECT
'water' AS table_name,
public_id,
location
FROM
publicreport.water
WHERE
public_id LIKE $1
ORDER BY
public_id;

View file

@ -1,105 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
_ "embed"
"io"
"iter"
"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/orm"
"github.com/lib/pq"
"github.com/stephenafamo/scan"
)
//go:embed publicreport_publicid_table.bob.sql
var formattedQueries_publicreport_publicid_table string
var publicreportIDTableSQL = formattedQueries_publicreport_publicid_table[157:536]
type PublicreportIDTableQuery = orm.ModQuery[*dialect.SelectQuery, publicreportIDTable, PublicreportIDTableRow, []PublicreportIDTableRow, publicreportIDTableTransformer]
func PublicreportIDTable(PublicID string) *PublicreportIDTableQuery {
var expressionTypArgs publicreportIDTable
expressionTypArgs.PublicID = psql.Arg(PublicID)
return &PublicreportIDTableQuery{
Query: orm.Query[publicreportIDTable, PublicreportIDTableRow, []PublicreportIDTableRow, publicreportIDTableTransformer]{
ExecQuery: orm.ExecQuery[publicreportIDTable]{
BaseQuery: bob.BaseQuery[publicreportIDTable]{
Expression: expressionTypArgs,
Dialect: dialect.Dialect,
QueryType: bob.QueryTypeSelect,
},
},
Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportIDTableRow, error)) {
return func(row *scan.Row) (any, error) {
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
}
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendCTE(expressionTypArgs.subExpr(5, 223))
q.AppendSelect(expressionTypArgs.subExpr(233, 361))
q.SetTable(expressionTypArgs.subExpr(367, 379))
}),
}
}
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]
type publicreportIDTable struct {
PublicID bob.Expression
}
func (o publicreportIDTable) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "publicID",
Start: 112,
Stop: 114,
Expression: o.PublicID,
}) {
return
}
if !yield(orm.ArgWithPosition{
Name: "publicID",
Start: 219,
Stop: 221,
Expression: o.PublicID,
}) {
return
}
}
}
func (o publicreportIDTable) raw(from, to int) string {
return publicreportIDTableSQL[from:to]
}
func (o publicreportIDTable) subExpr(from, to int) bob.Expression {
return orm.ArgsToExpression(publicreportIDTableSQL, from, to, o.args())
}
func (o publicreportIDTable) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.subExpr(0, len(publicreportIDTableSQL)).WriteSQL(ctx, w, d, start)
}

View file

@ -1,24 +0,0 @@
-- Code generated by BobGen psql v0.42.5. DO NOT EDIT.
-- This file is meant to be re-generated in place and/or deleted at any time.
-- PublicreportIDTable
WITH found_tables AS (
SELECT
'nuisance' as table_name,
id
FROM publicreport.nuisance
WHERE public_id = $1
UNION ALL
SELECT
'water' as table_name,
id
FROM publicreport.water
WHERE public_id = $2
)
SELECT
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,21 +0,0 @@
-- PublicreportIDTable
WITH found_tables AS (
SELECT
'nuisance' as table_name,
id
FROM publicreport.nuisance
WHERE public_id = $1
UNION ALL
SELECT
'water' as table_name,
id
FROM publicreport.water
WHERE public_id = $1
)
SELECT
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;