diff --git a/api/communication.go b/api/communication.go index 60fd46f0..41784688 100644 --- a/api/communication.go +++ b/api/communication.go @@ -31,16 +31,12 @@ type contentListCommunication struct { } func listCommunication(ctx context.Context, r *http.Request, user platform.User, query queryParams) (*contentListCommunication, *nhttp.ErrorWithStatus) { - nreports, err := publicreport.NuisanceReportForOrganization(ctx, user.Organization.ID()) + reports, err := publicreport.ReportsForOrganization(ctx, user.Organization.ID()) if err != nil { return nil, nhttp.NewError("nuisance report query: %w", err) } - wreports, err := publicreport.WaterReportForOrganization(ctx, user.Organization.ID()) - if err != nil { - return nil, nhttp.NewError("water report query: %w", err) - } - comms := make([]communication, len(nreports)+len(wreports)) - for i, report := range nreports { + comms := make([]communication, len(reports)) + for i, report := range reports { comms[i] = communication{ Created: report.Created, History: []historyEntry{ @@ -54,20 +50,6 @@ func listCommunication(ctx context.Context, r *http.Request, user platform.User, Type: "nuisance", } } - for i, report := range wreports { - comms[i+len(nreports)] = communication{ - Created: report.Created, - History: []historyEntry{ - historyEntry{ - Action: "created", - Timestamp: report.Created, - }, - }, - ID: report.PublicID, - PublicReport: report, - Type: "water", - } - } _by_created := func(a, b communication) int { if a.Created == b.Created { return 0 diff --git a/api/publicreport.go b/api/publicreport.go index 9601627b..65f64483 100644 --- a/api/publicreport.go +++ b/api/publicreport.go @@ -54,6 +54,9 @@ func postPublicreportMessage(ctx context.Context, r *http.Request, user platform if err != nil { return nil, nhttp.NewError("failed to create message: %s", err) } + if msg_id == nil { + return nil, nhttp.NewError("nil message id") + } return &createdMessage{ URI: config.MakeURLNidus("/message/%s", strconv.Itoa(int(*msg_id))), }, nil diff --git a/db/dberrors/publicreport.notify_email.bob.go b/db/dberrors/publicreport.notify_email.bob.go new file mode 100644 index 00000000..40786957 --- /dev/null +++ b/db/dberrors/publicreport.notify_email.bob.go @@ -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 +} diff --git a/db/dberrors/publicreport.notify_email_nuisance.bob.go b/db/dberrors/publicreport.notify_email_nuisance_old.bob.go similarity index 68% rename from db/dberrors/publicreport.notify_email_nuisance.bob.go rename to db/dberrors/publicreport.notify_email_nuisance_old.bob.go index 895e7af2..73e9133b 100644 --- a/db/dberrors/publicreport.notify_email_nuisance.bob.go +++ b/db/dberrors/publicreport.notify_email_nuisance_old.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.notify_email_water.bob.go b/db/dberrors/publicreport.notify_email_water_old.bob.go similarity index 68% rename from db/dberrors/publicreport.notify_email_water.bob.go rename to db/dberrors/publicreport.notify_email_water_old.bob.go index 834b821c..8212e075 100644 --- a/db/dberrors/publicreport.notify_email_water.bob.go +++ b/db/dberrors/publicreport.notify_email_water_old.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.notify_phone.bob.go b/db/dberrors/publicreport.notify_phone.bob.go new file mode 100644 index 00000000..5c7a9d9d --- /dev/null +++ b/db/dberrors/publicreport.notify_phone.bob.go @@ -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 +} diff --git a/db/dberrors/publicreport.notify_phone_nuisance.bob.go b/db/dberrors/publicreport.notify_phone_nuisance_old.bob.go similarity index 68% rename from db/dberrors/publicreport.notify_phone_nuisance.bob.go rename to db/dberrors/publicreport.notify_phone_nuisance_old.bob.go index c3f77cb9..a3aa05d2 100644 --- a/db/dberrors/publicreport.notify_phone_nuisance.bob.go +++ b/db/dberrors/publicreport.notify_phone_nuisance_old.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.notify_phone_water.bob.go b/db/dberrors/publicreport.notify_phone_water_old.bob.go similarity index 68% rename from db/dberrors/publicreport.notify_phone_water.bob.go rename to db/dberrors/publicreport.notify_phone_water_old.bob.go index 7bc9c4d3..1deab430 100644 --- a/db/dberrors/publicreport.notify_phone_water.bob.go +++ b/db/dberrors/publicreport.notify_phone_water_old.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.nuisance.bob.go b/db/dberrors/publicreport.nuisance.bob.go index 6c0fd841..88557eef 100644 --- a/db/dberrors/publicreport.nuisance.bob.go +++ b/db/dberrors/publicreport.nuisance.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.nuisance_image.bob.go b/db/dberrors/publicreport.nuisance_image_old.bob.go similarity index 70% rename from db/dberrors/publicreport.nuisance_image.bob.go rename to db/dberrors/publicreport.nuisance_image_old.bob.go index 21d3cb63..faaf0995 100644 --- a/db/dberrors/publicreport.nuisance_image.bob.go +++ b/db/dberrors/publicreport.nuisance_image_old.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.nuisance_old.bob.go b/db/dberrors/publicreport.nuisance_old.bob.go new file mode 100644 index 00000000..cc600d66 --- /dev/null +++ b/db/dberrors/publicreport.nuisance_old.bob.go @@ -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 +} diff --git a/db/dberrors/publicreport.report.bob.go b/db/dberrors/publicreport.report.bob.go new file mode 100644 index 00000000..78922ff8 --- /dev/null +++ b/db/dberrors/publicreport.report.bob.go @@ -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 +} diff --git a/db/dberrors/publicreport.report_image.bob.go b/db/dberrors/publicreport.report_image.bob.go new file mode 100644 index 00000000..8bbf3994 --- /dev/null +++ b/db/dberrors/publicreport.report_image.bob.go @@ -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 +} diff --git a/db/dberrors/publicreport.water.bob.go b/db/dberrors/publicreport.water.bob.go index 69a7e2e8..5d143ffb 100644 --- a/db/dberrors/publicreport.water.bob.go +++ b/db/dberrors/publicreport.water.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.water_image.bob.go b/db/dberrors/publicreport.water_image_old.bob.go similarity index 70% rename from db/dberrors/publicreport.water_image.bob.go rename to db/dberrors/publicreport.water_image_old.bob.go index a374601e..34589150 100644 --- a/db/dberrors/publicreport.water_image.bob.go +++ b/db/dberrors/publicreport.water_image_old.bob.go @@ -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 } diff --git a/db/dberrors/publicreport.water_old.bob.go b/db/dberrors/publicreport.water_old.bob.go new file mode 100644 index 00000000..3b6034eb --- /dev/null +++ b/db/dberrors/publicreport.water_old.bob.go @@ -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 +} diff --git a/db/dberrors/report_text.bob.go b/db/dberrors/report_text.bob.go new file mode 100644 index 00000000..40e22366 --- /dev/null +++ b/db/dberrors/report_text.bob.go @@ -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 +} diff --git a/db/dbinfo/comms.text_job.bob.go b/db/dbinfo/comms.text_job.bob.go index 5cfeb1dc..52c38fe9 100644 --- a/db/dbinfo/comms.text_job.bob.go +++ b/db/dbinfo/comms.text_job.bob.go @@ -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, } } diff --git a/db/dbinfo/publicreport.notify_email.bob.go b/db/dbinfo/publicreport.notify_email.bob.go new file mode 100644 index 00000000..d4f39b27 --- /dev/null +++ b/db/dbinfo/publicreport.notify_email.bob.go @@ -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{} +} diff --git a/db/dbinfo/publicreport.notify_email_nuisance.bob.go b/db/dbinfo/publicreport.notify_email_nuisance_old.bob.go similarity index 55% rename from db/dbinfo/publicreport.notify_email_nuisance.bob.go rename to db/dbinfo/publicreport.notify_email_nuisance_old.bob.go index e30f0719..4d4f06cd 100644 --- a/db/dbinfo/publicreport.notify_email_nuisance.bob.go +++ b/db/dbinfo/publicreport.notify_email_nuisance_old.bob.go @@ -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{} } diff --git a/db/dbinfo/publicreport.notify_email_water.bob.go b/db/dbinfo/publicreport.notify_email_water_old.bob.go similarity index 56% rename from db/dbinfo/publicreport.notify_email_water.bob.go rename to db/dbinfo/publicreport.notify_email_water_old.bob.go index 6e2e4690..d7f97389 100644 --- a/db/dbinfo/publicreport.notify_email_water.bob.go +++ b/db/dbinfo/publicreport.notify_email_water_old.bob.go @@ -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{} } diff --git a/db/dbinfo/publicreport.notify_phone.bob.go b/db/dbinfo/publicreport.notify_phone.bob.go new file mode 100644 index 00000000..32ca744f --- /dev/null +++ b/db/dbinfo/publicreport.notify_phone.bob.go @@ -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{} +} diff --git a/db/dbinfo/publicreport.notify_phone_nuisance.bob.go b/db/dbinfo/publicreport.notify_phone_nuisance_old.bob.go similarity index 55% rename from db/dbinfo/publicreport.notify_phone_nuisance.bob.go rename to db/dbinfo/publicreport.notify_phone_nuisance_old.bob.go index dbc3c594..21d865a9 100644 --- a/db/dbinfo/publicreport.notify_phone_nuisance.bob.go +++ b/db/dbinfo/publicreport.notify_phone_nuisance_old.bob.go @@ -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{} } diff --git a/db/dbinfo/publicreport.notify_phone_water.bob.go b/db/dbinfo/publicreport.notify_phone_water_old.bob.go similarity index 56% rename from db/dbinfo/publicreport.notify_phone_water.bob.go rename to db/dbinfo/publicreport.notify_phone_water_old.bob.go index 8d9655fa..9209ec50 100644 --- a/db/dbinfo/publicreport.notify_phone_water.bob.go +++ b/db/dbinfo/publicreport.notify_phone_water_old.bob.go @@ -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{} } diff --git a/db/dbinfo/publicreport.nuisance.bob.go b/db/dbinfo/publicreport.nuisance.bob.go index 9e991750..19589341 100644 --- a/db/dbinfo/publicreport.nuisance.bob.go +++ b/db/dbinfo/publicreport.nuisance.bob.go @@ -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{} diff --git a/db/dbinfo/publicreport.nuisance_image.bob.go b/db/dbinfo/publicreport.nuisance_image_old.bob.go similarity index 52% rename from db/dbinfo/publicreport.nuisance_image.bob.go rename to db/dbinfo/publicreport.nuisance_image_old.bob.go index c038ed53..9e1be8eb 100644 --- a/db/dbinfo/publicreport.nuisance_image.bob.go +++ b/db/dbinfo/publicreport.nuisance_image_old.bob.go @@ -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{} } diff --git a/db/dbinfo/publicreport.nuisance_old.bob.go b/db/dbinfo/publicreport.nuisance_old.bob.go new file mode 100644 index 00000000..2ade093e --- /dev/null +++ b/db/dbinfo/publicreport.nuisance_old.bob.go @@ -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{} +} diff --git a/db/dbinfo/publicreport.report.bob.go b/db/dbinfo/publicreport.report.bob.go new file mode 100644 index 00000000..6cca69e5 --- /dev/null +++ b/db/dbinfo/publicreport.report.bob.go @@ -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, + } +} diff --git a/db/dbinfo/publicreport.report_image.bob.go b/db/dbinfo/publicreport.report_image.bob.go new file mode 100644 index 00000000..7fbf8796 --- /dev/null +++ b/db/dbinfo/publicreport.report_image.bob.go @@ -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{} +} diff --git a/db/dbinfo/publicreport.water.bob.go b/db/dbinfo/publicreport.water.bob.go index cd707a67..071115c7 100644 --- a/db/dbinfo/publicreport.water.bob.go +++ b/db/dbinfo/publicreport.water.bob.go @@ -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{} diff --git a/db/dbinfo/publicreport.water_image.bob.go b/db/dbinfo/publicreport.water_image_old.bob.go similarity index 54% rename from db/dbinfo/publicreport.water_image.bob.go rename to db/dbinfo/publicreport.water_image_old.bob.go index 33c26e38..ef9f18be 100644 --- a/db/dbinfo/publicreport.water_image.bob.go +++ b/db/dbinfo/publicreport.water_image_old.bob.go @@ -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{} } diff --git a/db/dbinfo/publicreport.water_old.bob.go b/db/dbinfo/publicreport.water_old.bob.go new file mode 100644 index 00000000..ef26bdce --- /dev/null +++ b/db/dbinfo/publicreport.water_old.bob.go @@ -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{} +} diff --git a/db/dbinfo/report_text.bob.go b/db/dbinfo/report_text.bob.go new file mode 100644 index 00000000..3161eb53 --- /dev/null +++ b/db/dbinfo/report_text.bob.go @@ -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{} +} diff --git a/db/enums/enums.bob.go b/db/enums/enums.bob.go index 57c81120..eeb2d051 100644 --- a/db/enums/enums.bob.go +++ b/db/enums/enums.bob.go @@ -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: diff --git a/db/migrations/00110_job.sql b/db/migrations/00110_job.sql index f7fd415a..c1f51cbf 100644 --- a/db/migrations/00110_job.sql +++ b/db/migrations/00110_job.sql @@ -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; diff --git a/db/migrations/00112_unify_publicreport.sql b/db/migrations/00112_unify_publicreport.sql new file mode 100644 index 00000000..44ebf39c --- /dev/null +++ b/db/migrations/00112_unify_publicreport.sql @@ -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'; + diff --git a/db/migrations/00113_report_text.sql b/db/migrations/00113_report_text.sql new file mode 100644 index 00000000..0b50b82c --- /dev/null +++ b/db/migrations/00113_report_text.sql @@ -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; + diff --git a/db/models/address.bob.go b/db/models/address.bob.go index 4d07806f..26cc3cb0 100644 --- a/db/models/address.bob.go +++ b/db/models/address.bob.go @@ -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) } } diff --git a/db/models/bob_loaders.bob.go b/db/models/bob_loaders.bob.go index dd5da76d..b4ab13b0 100644 --- a/db/models/bob_loaders.bob.go +++ b/db/models/bob_loaders.bob.go @@ -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](), } } diff --git a/db/models/bob_where.bob.go b/db/models/bob_where.bob.go index e79d5d22..b3405205 100644 --- a/db/models/bob_where.bob.go +++ b/db/models/bob_where.bob.go @@ -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), diff --git a/db/models/comms.email_contact.bob.go b/db/models/comms.email_contact.bob.go index 8a17203f..80af9b76 100644 --- a/db/models/comms.email_contact.bob.go +++ b/db/models/comms.email_contact.bob.go @@ -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) } } diff --git a/db/models/comms.phone.bob.go b/db/models/comms.phone.bob.go index 9f0aef7b..a4142341 100644 --- a/db/models/comms.phone.bob.go +++ b/db/models/comms.phone.bob.go @@ -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) } } diff --git a/db/models/comms.text_job.bob.go b/db/models/comms.text_job.bob.go index ff59c48e..930272ad 100644 --- a/db/models/comms.text_job.bob.go +++ b/db/models/comms.text_job.bob.go @@ -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 +} diff --git a/db/models/comms.text_log.bob.go b/db/models/comms.text_log.bob.go index 5669f5b8..85076201 100644 --- a/db/models/comms.text_log.bob.go +++ b/db/models/comms.text_log.bob.go @@ -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 +} diff --git a/db/models/organization.bob.go b/db/models/organization.bob.go index f7acc96c..53ecd585 100644 --- a/db/models/organization.bob.go +++ b/db/models/organization.bob.go @@ -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) } } diff --git a/db/models/publicreport.image.bob.go b/db/models/publicreport.image.bob.go index ad2a1022..48bc4b44 100644 --- a/db/models/publicreport.image.bob.go +++ b/db/models/publicreport.image.bob.go @@ -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) } } diff --git a/db/models/publicreport.notify_email.bob.go b/db/models/publicreport.notify_email.bob.go new file mode 100644 index 00000000..4e153215 --- /dev/null +++ b/db/models/publicreport.notify_email.bob.go @@ -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 +} diff --git a/db/models/publicreport.notify_email_nuisance.bob.go b/db/models/publicreport.notify_email_nuisance.bob.go deleted file mode 100644 index 0c3c75ad..00000000 --- a/db/models/publicreport.notify_email_nuisance.bob.go +++ /dev/null @@ -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 -} diff --git a/db/models/publicreport.notify_email_nuisance_old.bob.go b/db/models/publicreport.notify_email_nuisance_old.bob.go new file mode 100644 index 00000000..8dcb6363 --- /dev/null +++ b/db/models/publicreport.notify_email_nuisance_old.bob.go @@ -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 +} diff --git a/db/models/publicreport.notify_email_water.bob.go b/db/models/publicreport.notify_email_water.bob.go deleted file mode 100644 index 5116c82a..00000000 --- a/db/models/publicreport.notify_email_water.bob.go +++ /dev/null @@ -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 -} diff --git a/db/models/publicreport.notify_email_water_old.bob.go b/db/models/publicreport.notify_email_water_old.bob.go new file mode 100644 index 00000000..c4d22785 --- /dev/null +++ b/db/models/publicreport.notify_email_water_old.bob.go @@ -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 +} diff --git a/db/models/publicreport.notify_phone.bob.go b/db/models/publicreport.notify_phone.bob.go new file mode 100644 index 00000000..735d7d4a --- /dev/null +++ b/db/models/publicreport.notify_phone.bob.go @@ -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 +} diff --git a/db/models/publicreport.notify_phone_nuisance.bob.go b/db/models/publicreport.notify_phone_nuisance.bob.go deleted file mode 100644 index a88f06ec..00000000 --- a/db/models/publicreport.notify_phone_nuisance.bob.go +++ /dev/null @@ -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 -} diff --git a/db/models/publicreport.notify_phone_nuisance_old.bob.go b/db/models/publicreport.notify_phone_nuisance_old.bob.go new file mode 100644 index 00000000..e2748d36 --- /dev/null +++ b/db/models/publicreport.notify_phone_nuisance_old.bob.go @@ -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 +} diff --git a/db/models/publicreport.notify_phone_water.bob.go b/db/models/publicreport.notify_phone_water.bob.go deleted file mode 100644 index 812811ba..00000000 --- a/db/models/publicreport.notify_phone_water.bob.go +++ /dev/null @@ -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 -} diff --git a/db/models/publicreport.notify_phone_water_old.bob.go b/db/models/publicreport.notify_phone_water_old.bob.go new file mode 100644 index 00000000..d731b2bd --- /dev/null +++ b/db/models/publicreport.notify_phone_water_old.bob.go @@ -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 +} diff --git a/db/models/publicreport.nuisance.bob.go b/db/models/publicreport.nuisance.bob.go index 9a3daa9e..250dc9e7 100644 --- a/db/models/publicreport.nuisance.bob.go +++ b/db/models/publicreport.nuisance.bob.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "io" - "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/bob/dialect/psql" @@ -19,53 +18,27 @@ import ( "github.com/Gleipnir-Technology/bob/orm" "github.com/Gleipnir-Technology/bob/types/pgtypes" enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" - "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - "github.com/stephenafamo/scan" ) // PublicreportNuisance is an object representing the database table. type PublicreportNuisance struct { - ID int32 `db:"id,pk" ` - AdditionalInfo string `db:"additional_info" ` - Created time.Time `db:"created" ` - Duration enums.PublicreportNuisancedurationtype `db:"duration" ` - SourceContainer bool `db:"source_container" ` - SourceDescription string `db:"source_description" ` - SourceStagnant bool `db:"source_stagnant" ` - PublicID string `db:"public_id" ` - ReporterEmail null.Val[string] `db:"reporter_email" ` - ReporterName null.Val[string] `db:"reporter_name" ` - ReporterPhone null.Val[string] `db:"reporter_phone" ` - AddressRaw string `db:"address_raw" ` - Status enums.PublicreportReportstatustype `db:"status" ` - OrganizationID int32 `db:"organization_id" ` - SourceGutter bool `db:"source_gutter" ` - H3cell null.Val[string] `db:"h3cell" ` - AddressCountry string `db:"address_country" ` - AddressLocality string `db:"address_locality" ` - AddressPostalCode string `db:"address_postal_code" ` - AddressRegion string `db:"address_region" ` - AddressStreet string `db:"address_street" ` - IsLocationBackyard bool `db:"is_location_backyard" ` - IsLocationFrontyard bool `db:"is_location_frontyard" ` - IsLocationGarden bool `db:"is_location_garden" ` - IsLocationOther bool `db:"is_location_other" ` - IsLocationPool bool `db:"is_location_pool" ` - MapZoom float32 `db:"map_zoom" ` - TodEarly bool `db:"tod_early" ` - TodDay bool `db:"tod_day" ` - TodEvening bool `db:"tod_evening" ` - TodNight bool `db:"tod_night" ` - LatlngAccuracyType enums.PublicreportAccuracytype `db:"latlng_accuracy_type" ` - LatlngAccuracyValue float32 `db:"latlng_accuracy_value" ` - ReporterContactConsent null.Val[bool] `db:"reporter_contact_consent" ` - Location null.Val[string] `db:"location" ` - AddressNumber string `db:"address_number" ` - AddressID null.Val[int32] `db:"address_id" ` - Reviewed null.Val[time.Time] `db:"reviewed" ` - ReviewerID null.Val[int32] `db:"reviewer_id" ` + AdditionalInfo string `db:"additional_info" ` + Duration enums.PublicreportNuisancedurationtype `db:"duration" ` + IsLocationBackyard bool `db:"is_location_backyard" ` + IsLocationFrontyard bool `db:"is_location_frontyard" ` + IsLocationGarden bool `db:"is_location_garden" ` + IsLocationOther bool `db:"is_location_other" ` + IsLocationPool bool `db:"is_location_pool" ` + ReportID int32 `db:"report_id,pk" ` + SourceContainer bool `db:"source_container" ` + SourceDescription string `db:"source_description" ` + SourceStagnant bool `db:"source_stagnant" ` + SourceGutter bool `db:"source_gutter" ` + TodEarly bool `db:"tod_early" ` + TodDay bool `db:"tod_day" ` + TodEvening bool `db:"tod_evening" ` + TodNight bool `db:"tod_night" ` R publicreportNuisanceR `db:"-" ` } @@ -82,104 +55,53 @@ type PublicreportNuisancesQuery = *psql.ViewQuery[*PublicreportNuisance, Publicr // publicreportNuisanceR is where relationships are stored. type publicreportNuisanceR struct { - NotifyEmailNuisances PublicreportNotifyEmailNuisanceSlice // publicreport.notify_email_nuisance.notify_email_nuisance_nuisance_id_fkey - NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey - Address *Address // publicreport.nuisance.nuisance_address_id_fkey - Organization *Organization // publicreport.nuisance.nuisance_organization_id_fkey - ReviewerUser *User // publicreport.nuisance.nuisance_reviewer_id_fkey - Images PublicreportImageSlice // publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey + Report *PublicreportReport // publicreport.nuisance.nuisance_report_id_fkey } func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns { return publicreportNuisanceColumns{ ColumnsExpr: expr.NewColumnsExpr( - "id", "additional_info", "created", "duration", "source_container", "source_description", "source_stagnant", "public_id", "reporter_email", "reporter_name", "reporter_phone", "address_raw", "status", "organization_id", "source_gutter", "h3cell", "address_country", "address_locality", "address_postal_code", "address_region", "address_street", "is_location_backyard", "is_location_frontyard", "is_location_garden", "is_location_other", "is_location_pool", "map_zoom", "tod_early", "tod_day", "tod_evening", "tod_night", "latlng_accuracy_type", "latlng_accuracy_value", "reporter_contact_consent", "location", "address_number", "address_id", "reviewed", "reviewer_id", + "additional_info", "duration", "is_location_backyard", "is_location_frontyard", "is_location_garden", "is_location_other", "is_location_pool", "report_id", "source_container", "source_description", "source_stagnant", "source_gutter", "tod_early", "tod_day", "tod_evening", "tod_night", ).WithParent("publicreport.nuisance"), - tableAlias: alias, - ID: psql.Quote(alias, "id"), - AdditionalInfo: psql.Quote(alias, "additional_info"), - Created: psql.Quote(alias, "created"), - Duration: psql.Quote(alias, "duration"), - SourceContainer: psql.Quote(alias, "source_container"), - SourceDescription: psql.Quote(alias, "source_description"), - SourceStagnant: psql.Quote(alias, "source_stagnant"), - PublicID: psql.Quote(alias, "public_id"), - ReporterEmail: psql.Quote(alias, "reporter_email"), - ReporterName: psql.Quote(alias, "reporter_name"), - ReporterPhone: psql.Quote(alias, "reporter_phone"), - AddressRaw: psql.Quote(alias, "address_raw"), - Status: psql.Quote(alias, "status"), - OrganizationID: psql.Quote(alias, "organization_id"), - SourceGutter: psql.Quote(alias, "source_gutter"), - H3cell: psql.Quote(alias, "h3cell"), - AddressCountry: psql.Quote(alias, "address_country"), - AddressLocality: psql.Quote(alias, "address_locality"), - AddressPostalCode: psql.Quote(alias, "address_postal_code"), - AddressRegion: psql.Quote(alias, "address_region"), - AddressStreet: psql.Quote(alias, "address_street"), - IsLocationBackyard: psql.Quote(alias, "is_location_backyard"), - IsLocationFrontyard: psql.Quote(alias, "is_location_frontyard"), - IsLocationGarden: psql.Quote(alias, "is_location_garden"), - IsLocationOther: psql.Quote(alias, "is_location_other"), - IsLocationPool: psql.Quote(alias, "is_location_pool"), - MapZoom: psql.Quote(alias, "map_zoom"), - TodEarly: psql.Quote(alias, "tod_early"), - TodDay: psql.Quote(alias, "tod_day"), - TodEvening: psql.Quote(alias, "tod_evening"), - TodNight: psql.Quote(alias, "tod_night"), - LatlngAccuracyType: psql.Quote(alias, "latlng_accuracy_type"), - LatlngAccuracyValue: psql.Quote(alias, "latlng_accuracy_value"), - ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), - Location: psql.Quote(alias, "location"), - AddressNumber: psql.Quote(alias, "address_number"), - AddressID: psql.Quote(alias, "address_id"), - Reviewed: psql.Quote(alias, "reviewed"), - ReviewerID: psql.Quote(alias, "reviewer_id"), + tableAlias: alias, + AdditionalInfo: psql.Quote(alias, "additional_info"), + Duration: psql.Quote(alias, "duration"), + IsLocationBackyard: psql.Quote(alias, "is_location_backyard"), + IsLocationFrontyard: psql.Quote(alias, "is_location_frontyard"), + IsLocationGarden: psql.Quote(alias, "is_location_garden"), + IsLocationOther: psql.Quote(alias, "is_location_other"), + IsLocationPool: psql.Quote(alias, "is_location_pool"), + ReportID: psql.Quote(alias, "report_id"), + SourceContainer: psql.Quote(alias, "source_container"), + SourceDescription: psql.Quote(alias, "source_description"), + SourceStagnant: psql.Quote(alias, "source_stagnant"), + SourceGutter: psql.Quote(alias, "source_gutter"), + TodEarly: psql.Quote(alias, "tod_early"), + TodDay: psql.Quote(alias, "tod_day"), + TodEvening: psql.Quote(alias, "tod_evening"), + TodNight: psql.Quote(alias, "tod_night"), } } type publicreportNuisanceColumns struct { expr.ColumnsExpr - tableAlias string - ID psql.Expression - AdditionalInfo psql.Expression - Created psql.Expression - Duration psql.Expression - SourceContainer psql.Expression - SourceDescription psql.Expression - SourceStagnant psql.Expression - PublicID psql.Expression - ReporterEmail psql.Expression - ReporterName psql.Expression - ReporterPhone psql.Expression - AddressRaw psql.Expression - Status psql.Expression - OrganizationID psql.Expression - SourceGutter psql.Expression - H3cell psql.Expression - AddressCountry psql.Expression - AddressLocality psql.Expression - AddressPostalCode psql.Expression - AddressRegion psql.Expression - AddressStreet psql.Expression - IsLocationBackyard psql.Expression - IsLocationFrontyard psql.Expression - IsLocationGarden psql.Expression - IsLocationOther psql.Expression - IsLocationPool psql.Expression - MapZoom psql.Expression - TodEarly psql.Expression - TodDay psql.Expression - TodEvening psql.Expression - TodNight psql.Expression - LatlngAccuracyType psql.Expression - LatlngAccuracyValue psql.Expression - ReporterContactConsent psql.Expression - Location psql.Expression - AddressNumber psql.Expression - AddressID psql.Expression - Reviewed psql.Expression - ReviewerID psql.Expression + tableAlias string + AdditionalInfo psql.Expression + Duration psql.Expression + IsLocationBackyard psql.Expression + IsLocationFrontyard psql.Expression + IsLocationGarden psql.Expression + IsLocationOther psql.Expression + IsLocationPool psql.Expression + ReportID psql.Expression + SourceContainer psql.Expression + SourceDescription psql.Expression + SourceStagnant psql.Expression + SourceGutter psql.Expression + TodEarly psql.Expression + TodDay psql.Expression + TodEvening psql.Expression + TodNight psql.Expression } func (c publicreportNuisanceColumns) Alias() string { @@ -194,112 +116,32 @@ func (publicreportNuisanceColumns) AliasedAs(alias string) publicreportNuisanceC // All values are optional, and do not have to be set // Generated columns are not included type PublicreportNuisanceSetter struct { - ID omit.Val[int32] `db:"id,pk" ` - AdditionalInfo omit.Val[string] `db:"additional_info" ` - Created omit.Val[time.Time] `db:"created" ` - Duration omit.Val[enums.PublicreportNuisancedurationtype] `db:"duration" ` - SourceContainer omit.Val[bool] `db:"source_container" ` - SourceDescription omit.Val[string] `db:"source_description" ` - SourceStagnant omit.Val[bool] `db:"source_stagnant" ` - PublicID omit.Val[string] `db:"public_id" ` - ReporterEmail omitnull.Val[string] `db:"reporter_email" ` - ReporterName omitnull.Val[string] `db:"reporter_name" ` - ReporterPhone omitnull.Val[string] `db:"reporter_phone" ` - AddressRaw omit.Val[string] `db:"address_raw" ` - Status omit.Val[enums.PublicreportReportstatustype] `db:"status" ` - OrganizationID omit.Val[int32] `db:"organization_id" ` - SourceGutter omit.Val[bool] `db:"source_gutter" ` - H3cell omitnull.Val[string] `db:"h3cell" ` - AddressCountry omit.Val[string] `db:"address_country" ` - AddressLocality omit.Val[string] `db:"address_locality" ` - AddressPostalCode omit.Val[string] `db:"address_postal_code" ` - AddressRegion omit.Val[string] `db:"address_region" ` - AddressStreet omit.Val[string] `db:"address_street" ` - IsLocationBackyard omit.Val[bool] `db:"is_location_backyard" ` - IsLocationFrontyard omit.Val[bool] `db:"is_location_frontyard" ` - IsLocationGarden omit.Val[bool] `db:"is_location_garden" ` - IsLocationOther omit.Val[bool] `db:"is_location_other" ` - IsLocationPool omit.Val[bool] `db:"is_location_pool" ` - MapZoom omit.Val[float32] `db:"map_zoom" ` - TodEarly omit.Val[bool] `db:"tod_early" ` - TodDay omit.Val[bool] `db:"tod_day" ` - TodEvening omit.Val[bool] `db:"tod_evening" ` - TodNight omit.Val[bool] `db:"tod_night" ` - LatlngAccuracyType omit.Val[enums.PublicreportAccuracytype] `db:"latlng_accuracy_type" ` - LatlngAccuracyValue omit.Val[float32] `db:"latlng_accuracy_value" ` - ReporterContactConsent omitnull.Val[bool] `db:"reporter_contact_consent" ` - Location omitnull.Val[string] `db:"location" ` - AddressNumber omit.Val[string] `db:"address_number" ` - AddressID omitnull.Val[int32] `db:"address_id" ` - Reviewed omitnull.Val[time.Time] `db:"reviewed" ` - ReviewerID omitnull.Val[int32] `db:"reviewer_id" ` + AdditionalInfo omit.Val[string] `db:"additional_info" ` + Duration omit.Val[enums.PublicreportNuisancedurationtype] `db:"duration" ` + IsLocationBackyard omit.Val[bool] `db:"is_location_backyard" ` + IsLocationFrontyard omit.Val[bool] `db:"is_location_frontyard" ` + IsLocationGarden omit.Val[bool] `db:"is_location_garden" ` + IsLocationOther omit.Val[bool] `db:"is_location_other" ` + IsLocationPool omit.Val[bool] `db:"is_location_pool" ` + ReportID omit.Val[int32] `db:"report_id,pk" ` + SourceContainer omit.Val[bool] `db:"source_container" ` + SourceDescription omit.Val[string] `db:"source_description" ` + SourceStagnant omit.Val[bool] `db:"source_stagnant" ` + SourceGutter omit.Val[bool] `db:"source_gutter" ` + TodEarly omit.Val[bool] `db:"tod_early" ` + TodDay omit.Val[bool] `db:"tod_day" ` + TodEvening omit.Val[bool] `db:"tod_evening" ` + TodNight omit.Val[bool] `db:"tod_night" ` } func (s PublicreportNuisanceSetter) SetColumns() []string { - vals := make([]string, 0, 39) - if s.ID.IsValue() { - vals = append(vals, "id") - } + vals := make([]string, 0, 16) if s.AdditionalInfo.IsValue() { vals = append(vals, "additional_info") } - if s.Created.IsValue() { - vals = append(vals, "created") - } if s.Duration.IsValue() { vals = append(vals, "duration") } - if s.SourceContainer.IsValue() { - vals = append(vals, "source_container") - } - if s.SourceDescription.IsValue() { - vals = append(vals, "source_description") - } - if s.SourceStagnant.IsValue() { - vals = append(vals, "source_stagnant") - } - if s.PublicID.IsValue() { - vals = append(vals, "public_id") - } - if !s.ReporterEmail.IsUnset() { - vals = append(vals, "reporter_email") - } - if !s.ReporterName.IsUnset() { - vals = append(vals, "reporter_name") - } - if !s.ReporterPhone.IsUnset() { - vals = append(vals, "reporter_phone") - } - if s.AddressRaw.IsValue() { - vals = append(vals, "address_raw") - } - if s.Status.IsValue() { - vals = append(vals, "status") - } - if s.OrganizationID.IsValue() { - vals = append(vals, "organization_id") - } - if s.SourceGutter.IsValue() { - vals = append(vals, "source_gutter") - } - if !s.H3cell.IsUnset() { - vals = append(vals, "h3cell") - } - if s.AddressCountry.IsValue() { - vals = append(vals, "address_country") - } - if s.AddressLocality.IsValue() { - vals = append(vals, "address_locality") - } - if s.AddressPostalCode.IsValue() { - vals = append(vals, "address_postal_code") - } - if s.AddressRegion.IsValue() { - vals = append(vals, "address_region") - } - if s.AddressStreet.IsValue() { - vals = append(vals, "address_street") - } if s.IsLocationBackyard.IsValue() { vals = append(vals, "is_location_backyard") } @@ -315,8 +157,20 @@ func (s PublicreportNuisanceSetter) SetColumns() []string { if s.IsLocationPool.IsValue() { vals = append(vals, "is_location_pool") } - if s.MapZoom.IsValue() { - vals = append(vals, "map_zoom") + if s.ReportID.IsValue() { + vals = append(vals, "report_id") + } + if s.SourceContainer.IsValue() { + vals = append(vals, "source_container") + } + if s.SourceDescription.IsValue() { + vals = append(vals, "source_description") + } + if s.SourceStagnant.IsValue() { + vals = append(vals, "source_stagnant") + } + if s.SourceGutter.IsValue() { + vals = append(vals, "source_gutter") } if s.TodEarly.IsValue() { vals = append(vals, "tod_early") @@ -330,97 +184,16 @@ func (s PublicreportNuisanceSetter) SetColumns() []string { if s.TodNight.IsValue() { vals = append(vals, "tod_night") } - if s.LatlngAccuracyType.IsValue() { - vals = append(vals, "latlng_accuracy_type") - } - if s.LatlngAccuracyValue.IsValue() { - vals = append(vals, "latlng_accuracy_value") - } - if !s.ReporterContactConsent.IsUnset() { - vals = append(vals, "reporter_contact_consent") - } - if !s.Location.IsUnset() { - vals = append(vals, "location") - } - if s.AddressNumber.IsValue() { - vals = append(vals, "address_number") - } - if !s.AddressID.IsUnset() { - vals = append(vals, "address_id") - } - if !s.Reviewed.IsUnset() { - vals = append(vals, "reviewed") - } - if !s.ReviewerID.IsUnset() { - vals = append(vals, "reviewer_id") - } return vals } func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) { - if s.ID.IsValue() { - t.ID = s.ID.MustGet() - } if s.AdditionalInfo.IsValue() { t.AdditionalInfo = s.AdditionalInfo.MustGet() } - if s.Created.IsValue() { - t.Created = s.Created.MustGet() - } if s.Duration.IsValue() { t.Duration = s.Duration.MustGet() } - if s.SourceContainer.IsValue() { - t.SourceContainer = s.SourceContainer.MustGet() - } - if s.SourceDescription.IsValue() { - t.SourceDescription = s.SourceDescription.MustGet() - } - if s.SourceStagnant.IsValue() { - t.SourceStagnant = s.SourceStagnant.MustGet() - } - if s.PublicID.IsValue() { - t.PublicID = s.PublicID.MustGet() - } - if !s.ReporterEmail.IsUnset() { - t.ReporterEmail = s.ReporterEmail.MustGetNull() - } - if !s.ReporterName.IsUnset() { - t.ReporterName = s.ReporterName.MustGetNull() - } - if !s.ReporterPhone.IsUnset() { - t.ReporterPhone = s.ReporterPhone.MustGetNull() - } - if s.AddressRaw.IsValue() { - t.AddressRaw = s.AddressRaw.MustGet() - } - if s.Status.IsValue() { - t.Status = s.Status.MustGet() - } - if s.OrganizationID.IsValue() { - t.OrganizationID = s.OrganizationID.MustGet() - } - if s.SourceGutter.IsValue() { - t.SourceGutter = s.SourceGutter.MustGet() - } - if !s.H3cell.IsUnset() { - t.H3cell = s.H3cell.MustGetNull() - } - if s.AddressCountry.IsValue() { - t.AddressCountry = s.AddressCountry.MustGet() - } - if s.AddressLocality.IsValue() { - t.AddressLocality = s.AddressLocality.MustGet() - } - if s.AddressPostalCode.IsValue() { - t.AddressPostalCode = s.AddressPostalCode.MustGet() - } - if s.AddressRegion.IsValue() { - t.AddressRegion = s.AddressRegion.MustGet() - } - if s.AddressStreet.IsValue() { - t.AddressStreet = s.AddressStreet.MustGet() - } if s.IsLocationBackyard.IsValue() { t.IsLocationBackyard = s.IsLocationBackyard.MustGet() } @@ -436,8 +209,20 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) { if s.IsLocationPool.IsValue() { t.IsLocationPool = s.IsLocationPool.MustGet() } - if s.MapZoom.IsValue() { - t.MapZoom = s.MapZoom.MustGet() + if s.ReportID.IsValue() { + t.ReportID = s.ReportID.MustGet() + } + if s.SourceContainer.IsValue() { + t.SourceContainer = s.SourceContainer.MustGet() + } + if s.SourceDescription.IsValue() { + t.SourceDescription = s.SourceDescription.MustGet() + } + if s.SourceStagnant.IsValue() { + t.SourceStagnant = s.SourceStagnant.MustGet() + } + if s.SourceGutter.IsValue() { + t.SourceGutter = s.SourceGutter.MustGet() } if s.TodEarly.IsValue() { t.TodEarly = s.TodEarly.MustGet() @@ -451,30 +236,6 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) { if s.TodNight.IsValue() { t.TodNight = s.TodNight.MustGet() } - if s.LatlngAccuracyType.IsValue() { - t.LatlngAccuracyType = s.LatlngAccuracyType.MustGet() - } - if s.LatlngAccuracyValue.IsValue() { - t.LatlngAccuracyValue = s.LatlngAccuracyValue.MustGet() - } - if !s.ReporterContactConsent.IsUnset() { - t.ReporterContactConsent = s.ReporterContactConsent.MustGetNull() - } - if !s.Location.IsUnset() { - t.Location = s.Location.MustGetNull() - } - if s.AddressNumber.IsValue() { - t.AddressNumber = s.AddressNumber.MustGet() - } - if !s.AddressID.IsUnset() { - t.AddressID = s.AddressID.MustGetNull() - } - if !s.Reviewed.IsUnset() { - t.Reviewed = s.Reviewed.MustGetNull() - } - if !s.ReviewerID.IsUnset() { - t.ReviewerID = s.ReviewerID.MustGetNull() - } } func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) { @@ -483,241 +244,103 @@ func (s *PublicreportNuisanceSetter) 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, 39) - if s.ID.IsValue() { - vals[0] = psql.Arg(s.ID.MustGet()) + vals := make([]bob.Expression, 16) + if s.AdditionalInfo.IsValue() { + vals[0] = psql.Arg(s.AdditionalInfo.MustGet()) } else { vals[0] = psql.Raw("DEFAULT") } - if s.AdditionalInfo.IsValue() { - vals[1] = psql.Arg(s.AdditionalInfo.MustGet()) + if s.Duration.IsValue() { + vals[1] = psql.Arg(s.Duration.MustGet()) } else { vals[1] = psql.Raw("DEFAULT") } - if s.Created.IsValue() { - vals[2] = psql.Arg(s.Created.MustGet()) + if s.IsLocationBackyard.IsValue() { + vals[2] = psql.Arg(s.IsLocationBackyard.MustGet()) } else { vals[2] = psql.Raw("DEFAULT") } - if s.Duration.IsValue() { - vals[3] = psql.Arg(s.Duration.MustGet()) + if s.IsLocationFrontyard.IsValue() { + vals[3] = psql.Arg(s.IsLocationFrontyard.MustGet()) } else { vals[3] = psql.Raw("DEFAULT") } - if s.SourceContainer.IsValue() { - vals[4] = psql.Arg(s.SourceContainer.MustGet()) + if s.IsLocationGarden.IsValue() { + vals[4] = psql.Arg(s.IsLocationGarden.MustGet()) } else { vals[4] = psql.Raw("DEFAULT") } - if s.SourceDescription.IsValue() { - vals[5] = psql.Arg(s.SourceDescription.MustGet()) + if s.IsLocationOther.IsValue() { + vals[5] = psql.Arg(s.IsLocationOther.MustGet()) } else { vals[5] = psql.Raw("DEFAULT") } - if s.SourceStagnant.IsValue() { - vals[6] = psql.Arg(s.SourceStagnant.MustGet()) + if s.IsLocationPool.IsValue() { + vals[6] = psql.Arg(s.IsLocationPool.MustGet()) } else { vals[6] = psql.Raw("DEFAULT") } - if s.PublicID.IsValue() { - vals[7] = psql.Arg(s.PublicID.MustGet()) + if s.ReportID.IsValue() { + vals[7] = psql.Arg(s.ReportID.MustGet()) } else { vals[7] = psql.Raw("DEFAULT") } - if !s.ReporterEmail.IsUnset() { - vals[8] = psql.Arg(s.ReporterEmail.MustGetNull()) + if s.SourceContainer.IsValue() { + vals[8] = psql.Arg(s.SourceContainer.MustGet()) } else { vals[8] = psql.Raw("DEFAULT") } - if !s.ReporterName.IsUnset() { - vals[9] = psql.Arg(s.ReporterName.MustGetNull()) + if s.SourceDescription.IsValue() { + vals[9] = psql.Arg(s.SourceDescription.MustGet()) } else { vals[9] = psql.Raw("DEFAULT") } - if !s.ReporterPhone.IsUnset() { - vals[10] = psql.Arg(s.ReporterPhone.MustGetNull()) + if s.SourceStagnant.IsValue() { + vals[10] = psql.Arg(s.SourceStagnant.MustGet()) } else { vals[10] = psql.Raw("DEFAULT") } - if s.AddressRaw.IsValue() { - vals[11] = psql.Arg(s.AddressRaw.MustGet()) + if s.SourceGutter.IsValue() { + vals[11] = psql.Arg(s.SourceGutter.MustGet()) } else { vals[11] = psql.Raw("DEFAULT") } - if s.Status.IsValue() { - vals[12] = psql.Arg(s.Status.MustGet()) + if s.TodEarly.IsValue() { + vals[12] = psql.Arg(s.TodEarly.MustGet()) } else { vals[12] = psql.Raw("DEFAULT") } - if s.OrganizationID.IsValue() { - vals[13] = psql.Arg(s.OrganizationID.MustGet()) + if s.TodDay.IsValue() { + vals[13] = psql.Arg(s.TodDay.MustGet()) } else { vals[13] = psql.Raw("DEFAULT") } - if s.SourceGutter.IsValue() { - vals[14] = psql.Arg(s.SourceGutter.MustGet()) + if s.TodEvening.IsValue() { + vals[14] = psql.Arg(s.TodEvening.MustGet()) } else { vals[14] = psql.Raw("DEFAULT") } - if !s.H3cell.IsUnset() { - vals[15] = psql.Arg(s.H3cell.MustGetNull()) + if s.TodNight.IsValue() { + vals[15] = psql.Arg(s.TodNight.MustGet()) } else { vals[15] = psql.Raw("DEFAULT") } - if s.AddressCountry.IsValue() { - vals[16] = psql.Arg(s.AddressCountry.MustGet()) - } else { - vals[16] = psql.Raw("DEFAULT") - } - - if s.AddressLocality.IsValue() { - vals[17] = psql.Arg(s.AddressLocality.MustGet()) - } else { - vals[17] = psql.Raw("DEFAULT") - } - - if s.AddressPostalCode.IsValue() { - vals[18] = psql.Arg(s.AddressPostalCode.MustGet()) - } else { - vals[18] = psql.Raw("DEFAULT") - } - - if s.AddressRegion.IsValue() { - vals[19] = psql.Arg(s.AddressRegion.MustGet()) - } else { - vals[19] = psql.Raw("DEFAULT") - } - - if s.AddressStreet.IsValue() { - vals[20] = psql.Arg(s.AddressStreet.MustGet()) - } else { - vals[20] = psql.Raw("DEFAULT") - } - - if s.IsLocationBackyard.IsValue() { - vals[21] = psql.Arg(s.IsLocationBackyard.MustGet()) - } else { - vals[21] = psql.Raw("DEFAULT") - } - - if s.IsLocationFrontyard.IsValue() { - vals[22] = psql.Arg(s.IsLocationFrontyard.MustGet()) - } else { - vals[22] = psql.Raw("DEFAULT") - } - - if s.IsLocationGarden.IsValue() { - vals[23] = psql.Arg(s.IsLocationGarden.MustGet()) - } else { - vals[23] = psql.Raw("DEFAULT") - } - - if s.IsLocationOther.IsValue() { - vals[24] = psql.Arg(s.IsLocationOther.MustGet()) - } else { - vals[24] = psql.Raw("DEFAULT") - } - - if s.IsLocationPool.IsValue() { - vals[25] = psql.Arg(s.IsLocationPool.MustGet()) - } else { - vals[25] = psql.Raw("DEFAULT") - } - - if s.MapZoom.IsValue() { - vals[26] = psql.Arg(s.MapZoom.MustGet()) - } else { - vals[26] = psql.Raw("DEFAULT") - } - - if s.TodEarly.IsValue() { - vals[27] = psql.Arg(s.TodEarly.MustGet()) - } else { - vals[27] = psql.Raw("DEFAULT") - } - - if s.TodDay.IsValue() { - vals[28] = psql.Arg(s.TodDay.MustGet()) - } else { - vals[28] = psql.Raw("DEFAULT") - } - - if s.TodEvening.IsValue() { - vals[29] = psql.Arg(s.TodEvening.MustGet()) - } else { - vals[29] = psql.Raw("DEFAULT") - } - - if s.TodNight.IsValue() { - vals[30] = psql.Arg(s.TodNight.MustGet()) - } else { - vals[30] = psql.Raw("DEFAULT") - } - - if s.LatlngAccuracyType.IsValue() { - vals[31] = psql.Arg(s.LatlngAccuracyType.MustGet()) - } else { - vals[31] = psql.Raw("DEFAULT") - } - - if s.LatlngAccuracyValue.IsValue() { - vals[32] = psql.Arg(s.LatlngAccuracyValue.MustGet()) - } else { - vals[32] = psql.Raw("DEFAULT") - } - - if !s.ReporterContactConsent.IsUnset() { - vals[33] = psql.Arg(s.ReporterContactConsent.MustGetNull()) - } else { - vals[33] = psql.Raw("DEFAULT") - } - - if !s.Location.IsUnset() { - vals[34] = psql.Arg(s.Location.MustGetNull()) - } else { - vals[34] = psql.Raw("DEFAULT") - } - - if s.AddressNumber.IsValue() { - vals[35] = psql.Arg(s.AddressNumber.MustGet()) - } else { - vals[35] = psql.Raw("DEFAULT") - } - - if !s.AddressID.IsUnset() { - vals[36] = psql.Arg(s.AddressID.MustGetNull()) - } else { - vals[36] = psql.Raw("DEFAULT") - } - - if !s.Reviewed.IsUnset() { - vals[37] = psql.Arg(s.Reviewed.MustGetNull()) - } else { - vals[37] = psql.Raw("DEFAULT") - } - - if !s.ReviewerID.IsUnset() { - vals[38] = psql.Arg(s.ReviewerID.MustGetNull()) - } else { - vals[38] = psql.Raw("DEFAULT") - } - return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -727,14 +350,7 @@ func (s PublicreportNuisanceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 39) - - if s.ID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "id")...), - psql.Arg(s.ID), - }}) - } + exprs := make([]bob.Expression, 0, 16) if s.AdditionalInfo.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -743,13 +359,6 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } - if s.Created.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "created")...), - psql.Arg(s.Created), - }}) - } - if s.Duration.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "duration")...), @@ -757,125 +366,6 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } - if s.SourceContainer.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "source_container")...), - psql.Arg(s.SourceContainer), - }}) - } - - if s.SourceDescription.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "source_description")...), - psql.Arg(s.SourceDescription), - }}) - } - - if s.SourceStagnant.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "source_stagnant")...), - psql.Arg(s.SourceStagnant), - }}) - } - - if s.PublicID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "public_id")...), - psql.Arg(s.PublicID), - }}) - } - - if !s.ReporterEmail.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_email")...), - psql.Arg(s.ReporterEmail), - }}) - } - - if !s.ReporterName.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_name")...), - psql.Arg(s.ReporterName), - }}) - } - - if !s.ReporterPhone.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_phone")...), - psql.Arg(s.ReporterPhone), - }}) - } - - if s.AddressRaw.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_raw")...), - psql.Arg(s.AddressRaw), - }}) - } - - if s.Status.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "status")...), - psql.Arg(s.Status), - }}) - } - - if s.OrganizationID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "organization_id")...), - psql.Arg(s.OrganizationID), - }}) - } - - if s.SourceGutter.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "source_gutter")...), - psql.Arg(s.SourceGutter), - }}) - } - - if !s.H3cell.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "h3cell")...), - psql.Arg(s.H3cell), - }}) - } - - if s.AddressCountry.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_country")...), - psql.Arg(s.AddressCountry), - }}) - } - - if s.AddressLocality.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_locality")...), - psql.Arg(s.AddressLocality), - }}) - } - - if s.AddressPostalCode.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_postal_code")...), - psql.Arg(s.AddressPostalCode), - }}) - } - - if s.AddressRegion.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_region")...), - psql.Arg(s.AddressRegion), - }}) - } - - if s.AddressStreet.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_street")...), - psql.Arg(s.AddressStreet), - }}) - } - if s.IsLocationBackyard.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "is_location_backyard")...), @@ -911,10 +401,38 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } - if s.MapZoom.IsValue() { + if s.ReportID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "map_zoom")...), - psql.Arg(s.MapZoom), + psql.Quote(append(prefix, "report_id")...), + psql.Arg(s.ReportID), + }}) + } + + if s.SourceContainer.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_container")...), + psql.Arg(s.SourceContainer), + }}) + } + + if s.SourceDescription.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_description")...), + psql.Arg(s.SourceDescription), + }}) + } + + if s.SourceStagnant.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_stagnant")...), + psql.Arg(s.SourceStagnant), + }}) + } + + if s.SourceGutter.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_gutter")...), + psql.Arg(s.SourceGutter), }}) } @@ -946,84 +464,28 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } - if s.LatlngAccuracyType.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "latlng_accuracy_type")...), - psql.Arg(s.LatlngAccuracyType), - }}) - } - - if s.LatlngAccuracyValue.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "latlng_accuracy_value")...), - psql.Arg(s.LatlngAccuracyValue), - }}) - } - - if !s.ReporterContactConsent.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_contact_consent")...), - psql.Arg(s.ReporterContactConsent), - }}) - } - - if !s.Location.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "location")...), - psql.Arg(s.Location), - }}) - } - - if s.AddressNumber.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_number")...), - psql.Arg(s.AddressNumber), - }}) - } - - if !s.AddressID.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_id")...), - psql.Arg(s.AddressID), - }}) - } - - if !s.Reviewed.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reviewed")...), - psql.Arg(s.Reviewed), - }}) - } - - if !s.ReviewerID.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reviewer_id")...), - psql.Arg(s.ReviewerID), - }}) - } - return exprs } // FindPublicreportNuisance retrieves a single record by primary key // If cols is empty Find will return all columns. -func FindPublicreportNuisance(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportNuisance, error) { +func FindPublicreportNuisance(ctx context.Context, exec bob.Executor, ReportIDPK int32, cols ...string) (*PublicreportNuisance, error) { if len(cols) == 0 { return PublicreportNuisances.Query( - sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(PublicreportNuisances.Columns.ReportID.EQ(psql.Arg(ReportIDPK))), ).One(ctx, exec) } return PublicreportNuisances.Query( - sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(PublicreportNuisances.Columns.ReportID.EQ(psql.Arg(ReportIDPK))), sm.Columns(PublicreportNuisances.Columns.Only(cols...)), ).One(ctx, exec) } // PublicreportNuisanceExists checks the presence of a single record by primary key -func PublicreportNuisanceExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { +func PublicreportNuisanceExists(ctx context.Context, exec bob.Executor, ReportIDPK int32) (bool, error) { return PublicreportNuisances.Query( - sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(PublicreportNuisances.Columns.ReportID.EQ(psql.Arg(ReportIDPK))), ).Exists(ctx, exec) } @@ -1047,11 +509,11 @@ func (o *PublicreportNuisance) AfterQueryHook(ctx context.Context, exec bob.Exec // primaryKeyVals returns the primary key values of the PublicreportNuisance func (o *PublicreportNuisance) primaryKeyVals() bob.Expression { - return psql.Arg(o.ID) + return psql.Arg(o.ReportID) } func (o *PublicreportNuisance) pkEQ() dialect.Expression { - return psql.Quote("publicreport.nuisance", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return psql.Quote("publicreport.nuisance", "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) })) } @@ -1078,7 +540,7 @@ func (o *PublicreportNuisance) Delete(ctx context.Context, exec bob.Executor) er // Reload refreshes the PublicreportNuisance using the executor func (o *PublicreportNuisance) Reload(ctx context.Context, exec bob.Executor) error { o2, err := PublicreportNuisances.Query( - sm.Where(PublicreportNuisances.Columns.ID.EQ(psql.Arg(o.ID))), + sm.Where(PublicreportNuisances.Columns.ReportID.EQ(psql.Arg(o.ReportID))), ).One(ctx, exec) if err != nil { return err @@ -1112,7 +574,7 @@ func (o PublicreportNuisanceSlice) pkIN() dialect.Expression { return psql.Raw("NULL") } - return psql.Quote("publicreport.nuisance", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return psql.Quote("publicreport.nuisance", "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() @@ -1127,7 +589,7 @@ func (o PublicreportNuisanceSlice) pkIN() dialect.Expression { func (o PublicreportNuisanceSlice) copyMatchingRows(from ...*PublicreportNuisance) { for i, old := range o { for _, new := range from { - if new.ID != old.ID { + if new.ReportID != old.ReportID { continue } new.R = old.R @@ -1228,540 +690,95 @@ func (o PublicreportNuisanceSlice) ReloadAll(ctx context.Context, exec bob.Execu return nil } -// NotifyEmailNuisances starts a query for related objects on publicreport.notify_email_nuisance -func (o *PublicreportNuisance) NotifyEmailNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisancesQuery { - return PublicreportNotifyEmailNuisances.Query(append(mods, - sm.Where(PublicreportNotifyEmailNuisances.Columns.NuisanceID.EQ(psql.Arg(o.ID))), +// Report starts a query for related objects on publicreport.report +func (o *PublicreportNuisance) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery { + return PublicreportReports.Query(append(mods, + sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))), )...) } -func (os PublicreportNuisanceSlice) NotifyEmailNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisancesQuery { - pkID := make(pgtypes.Array[int32], 0, len(os)) +func (os PublicreportNuisanceSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery { + pkReportID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { continue } - pkID = append(pkID, o.ID) + pkReportID = append(pkReportID, o.ReportID) } PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")), )) - return PublicreportNotifyEmailNuisances.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyEmailNuisances.Columns.NuisanceID).OP("IN", PKArgExpr)), + return PublicreportReports.Query(append(mods, + sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)), )...) } -// NotifyPhoneNuisances starts a query for related objects on publicreport.notify_phone_nuisance -func (o *PublicreportNuisance) NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery { - return PublicreportNotifyPhoneNuisances.Query(append(mods, - sm.Where(PublicreportNotifyPhoneNuisances.Columns.NuisanceID.EQ(psql.Arg(o.ID))), - )...) -} - -func (os PublicreportNuisanceSlice) NotifyPhoneNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisancesQuery { - 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 PublicreportNotifyPhoneNuisances.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyPhoneNuisances.Columns.NuisanceID).OP("IN", PKArgExpr)), - )...) -} - -// Address starts a query for related objects on address -func (o *PublicreportNuisance) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { - return Addresses.Query(append(mods, - sm.Where(Addresses.Columns.ID.EQ(psql.Arg(o.AddressID))), - )...) -} - -func (os PublicreportNuisanceSlice) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { - pkAddressID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkAddressID = append(pkAddressID, o.AddressID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkAddressID), "integer[]")), - )) - - return Addresses.Query(append(mods, - sm.Where(psql.Group(Addresses.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// Organization starts a query for related objects on organization -func (o *PublicreportNuisance) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { - return Organizations.Query(append(mods, - sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), - )...) -} - -func (os PublicreportNuisanceSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { - pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkOrganizationID = append(pkOrganizationID, o.OrganizationID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), - )) - - return Organizations.Query(append(mods, - sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// ReviewerUser starts a query for related objects on user_ -func (o *PublicreportNuisance) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - return Users.Query(append(mods, - sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))), - )...) -} - -func (os PublicreportNuisanceSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkReviewerID = append(pkReviewerID, o.ReviewerID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")), - )) - - return Users.Query(append(mods, - sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// Images starts a query for related objects on publicreport.image -func (o *PublicreportNuisance) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { - return PublicreportImages.Query(append(mods, - sm.InnerJoin(PublicreportNuisanceImages.NameAs()).On( - PublicreportImages.Columns.ID.EQ(PublicreportNuisanceImages.Columns.ImageID)), - sm.Where(PublicreportNuisanceImages.Columns.NuisanceID.EQ(psql.Arg(o.ID))), - )...) -} - -func (os PublicreportNuisanceSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { - 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 PublicreportImages.Query(append(mods, - sm.InnerJoin(PublicreportNuisanceImages.NameAs()).On( - PublicreportImages.Columns.ID.EQ(PublicreportNuisanceImages.Columns.ImageID), - ), - sm.Where(psql.Group(PublicreportNuisanceImages.Columns.NuisanceID).OP("IN", PKArgExpr)), - )...) -} - -func insertPublicreportNuisanceNotifyEmailNuisances0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailNuisances1 []*PublicreportNotifyEmailNuisanceSetter, publicreportNuisance0 *PublicreportNuisance) (PublicreportNotifyEmailNuisanceSlice, error) { - for i := range publicreportNotifyEmailNuisances1 { - publicreportNotifyEmailNuisances1[i].NuisanceID = omit.From(publicreportNuisance0.ID) - } - - ret, err := PublicreportNotifyEmailNuisances.Insert(bob.ToMods(publicreportNotifyEmailNuisances1...)).All(ctx, exec) - if err != nil { - return ret, fmt.Errorf("insertPublicreportNuisanceNotifyEmailNuisances0: %w", err) - } - - return ret, nil -} - -func attachPublicreportNuisanceNotifyEmailNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisances1 PublicreportNotifyEmailNuisanceSlice, publicreportNuisance0 *PublicreportNuisance) (PublicreportNotifyEmailNuisanceSlice, error) { - setter := &PublicreportNotifyEmailNuisanceSetter{ - NuisanceID: omit.From(publicreportNuisance0.ID), - } - - err := publicreportNotifyEmailNuisances1.UpdateAll(ctx, exec, *setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNuisanceNotifyEmailNuisances0: %w", err) - } - - return publicreportNotifyEmailNuisances1, nil -} - -func (publicreportNuisance0 *PublicreportNuisance) InsertNotifyEmailNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - publicreportNotifyEmailNuisances1, err := insertPublicreportNuisanceNotifyEmailNuisances0(ctx, exec, related, publicreportNuisance0) - if err != nil { - return err - } - - publicreportNuisance0.R.NotifyEmailNuisances = append(publicreportNuisance0.R.NotifyEmailNuisances, publicreportNotifyEmailNuisances1...) - - for _, rel := range publicreportNotifyEmailNuisances1 { - rel.R.Nuisance = publicreportNuisance0 - } - return nil -} - -func (publicreportNuisance0 *PublicreportNuisance) AttachNotifyEmailNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisance) error { - if len(related) == 0 { - return nil - } - - var err error - publicreportNotifyEmailNuisances1 := PublicreportNotifyEmailNuisanceSlice(related) - - _, err = attachPublicreportNuisanceNotifyEmailNuisances0(ctx, exec, len(related), publicreportNotifyEmailNuisances1, publicreportNuisance0) - if err != nil { - return err - } - - publicreportNuisance0.R.NotifyEmailNuisances = append(publicreportNuisance0.R.NotifyEmailNuisances, publicreportNotifyEmailNuisances1...) - - for _, rel := range related { - rel.R.Nuisance = publicreportNuisance0 - } - - return nil -} - -func insertPublicreportNuisanceNotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneNuisances1 []*PublicreportNotifyPhoneNuisanceSetter, publicreportNuisance0 *PublicreportNuisance) (PublicreportNotifyPhoneNuisanceSlice, error) { - for i := range publicreportNotifyPhoneNuisances1 { - publicreportNotifyPhoneNuisances1[i].NuisanceID = omit.From(publicreportNuisance0.ID) - } - - ret, err := PublicreportNotifyPhoneNuisances.Insert(bob.ToMods(publicreportNotifyPhoneNuisances1...)).All(ctx, exec) - if err != nil { - return ret, fmt.Errorf("insertPublicreportNuisanceNotifyPhoneNuisances0: %w", err) - } - - return ret, nil -} - -func attachPublicreportNuisanceNotifyPhoneNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisances1 PublicreportNotifyPhoneNuisanceSlice, publicreportNuisance0 *PublicreportNuisance) (PublicreportNotifyPhoneNuisanceSlice, error) { - setter := &PublicreportNotifyPhoneNuisanceSetter{ - NuisanceID: omit.From(publicreportNuisance0.ID), - } - - err := publicreportNotifyPhoneNuisances1.UpdateAll(ctx, exec, *setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNuisanceNotifyPhoneNuisances0: %w", err) - } - - return publicreportNotifyPhoneNuisances1, nil -} - -func (publicreportNuisance0 *PublicreportNuisance) InsertNotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - publicreportNotifyPhoneNuisances1, err := insertPublicreportNuisanceNotifyPhoneNuisances0(ctx, exec, related, publicreportNuisance0) - if err != nil { - return err - } - - publicreportNuisance0.R.NotifyPhoneNuisances = append(publicreportNuisance0.R.NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...) - - for _, rel := range publicreportNotifyPhoneNuisances1 { - rel.R.Nuisance = publicreportNuisance0 - } - return nil -} - -func (publicreportNuisance0 *PublicreportNuisance) AttachNotifyPhoneNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisance) error { - if len(related) == 0 { - return nil - } - - var err error - publicreportNotifyPhoneNuisances1 := PublicreportNotifyPhoneNuisanceSlice(related) - - _, err = attachPublicreportNuisanceNotifyPhoneNuisances0(ctx, exec, len(related), publicreportNotifyPhoneNuisances1, publicreportNuisance0) - if err != nil { - return err - } - - publicreportNuisance0.R.NotifyPhoneNuisances = append(publicreportNuisance0.R.NotifyPhoneNuisances, publicreportNotifyPhoneNuisances1...) - - for _, rel := range related { - rel.R.Nuisance = publicreportNuisance0 - } - - return nil -} - -func attachPublicreportNuisanceAddress0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, address1 *Address) (*PublicreportNuisance, error) { +func attachPublicreportNuisanceReport0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, publicreportReport1 *PublicreportReport) (*PublicreportNuisance, error) { setter := &PublicreportNuisanceSetter{ - AddressID: omitnull.From(address1.ID), + ReportID: omit.From(publicreportReport1.ID), } err := publicreportNuisance0.Update(ctx, exec, setter) if err != nil { - return nil, fmt.Errorf("attachPublicreportNuisanceAddress0: %w", err) + return nil, fmt.Errorf("attachPublicreportNuisanceReport0: %w", err) } return publicreportNuisance0, nil } -func (publicreportNuisance0 *PublicreportNuisance) InsertAddress(ctx context.Context, exec bob.Executor, related *AddressSetter) error { +func (publicreportNuisance0 *PublicreportNuisance) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error { var err error - address1, err := Addresses.Insert(related).One(ctx, exec) + publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec) if err != nil { return fmt.Errorf("inserting related objects: %w", err) } - _, err = attachPublicreportNuisanceAddress0(ctx, exec, 1, publicreportNuisance0, address1) + _, err = attachPublicreportNuisanceReport0(ctx, exec, 1, publicreportNuisance0, publicreportReport1) if err != nil { return err } - publicreportNuisance0.R.Address = address1 + publicreportNuisance0.R.Report = publicreportReport1 - address1.R.Nuisances = append(address1.R.Nuisances, publicreportNuisance0) + publicreportReport1.R.Nuisance = publicreportNuisance0 return nil } -func (publicreportNuisance0 *PublicreportNuisance) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { +func (publicreportNuisance0 *PublicreportNuisance) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error { var err error - _, err = attachPublicreportNuisanceAddress0(ctx, exec, 1, publicreportNuisance0, address1) + _, err = attachPublicreportNuisanceReport0(ctx, exec, 1, publicreportNuisance0, publicreportReport1) if err != nil { return err } - publicreportNuisance0.R.Address = address1 + publicreportNuisance0.R.Report = publicreportReport1 - address1.R.Nuisances = append(address1.R.Nuisances, publicreportNuisance0) - - return nil -} - -func attachPublicreportNuisanceOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, organization1 *Organization) (*PublicreportNuisance, error) { - setter := &PublicreportNuisanceSetter{ - OrganizationID: omit.From(organization1.ID), - } - - err := publicreportNuisance0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNuisanceOrganization0: %w", err) - } - - return publicreportNuisance0, nil -} - -func (publicreportNuisance0 *PublicreportNuisance) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { - var err error - - organization1, err := Organizations.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportNuisanceOrganization0(ctx, exec, 1, publicreportNuisance0, organization1) - if err != nil { - return err - } - - publicreportNuisance0.R.Organization = organization1 - - organization1.R.Nuisances = append(organization1.R.Nuisances, publicreportNuisance0) - - return nil -} - -func (publicreportNuisance0 *PublicreportNuisance) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { - var err error - - _, err = attachPublicreportNuisanceOrganization0(ctx, exec, 1, publicreportNuisance0, organization1) - if err != nil { - return err - } - - publicreportNuisance0.R.Organization = organization1 - - organization1.R.Nuisances = append(organization1.R.Nuisances, publicreportNuisance0) - - return nil -} - -func attachPublicreportNuisanceReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, user1 *User) (*PublicreportNuisance, error) { - setter := &PublicreportNuisanceSetter{ - ReviewerID: omitnull.From(user1.ID), - } - - err := publicreportNuisance0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNuisanceReviewerUser0: %w", err) - } - - return publicreportNuisance0, nil -} - -func (publicreportNuisance0 *PublicreportNuisance) InsertReviewerUser(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 = attachPublicreportNuisanceReviewerUser0(ctx, exec, 1, publicreportNuisance0, user1) - if err != nil { - return err - } - - publicreportNuisance0.R.ReviewerUser = user1 - - user1.R.ReviewerNuisances = append(user1.R.ReviewerNuisances, publicreportNuisance0) - - return nil -} - -func (publicreportNuisance0 *PublicreportNuisance) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error { - var err error - - _, err = attachPublicreportNuisanceReviewerUser0(ctx, exec, 1, publicreportNuisance0, user1) - if err != nil { - return err - } - - publicreportNuisance0.R.ReviewerUser = user1 - - user1.R.ReviewerNuisances = append(user1.R.ReviewerNuisances, publicreportNuisance0) - - return nil -} - -func attachPublicreportNuisanceImages0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, publicreportImages2 PublicreportImageSlice) (PublicreportNuisanceImageSlice, error) { - setters := make([]*PublicreportNuisanceImageSetter, count) - for i := range count { - setters[i] = &PublicreportNuisanceImageSetter{ - NuisanceID: omit.From(publicreportNuisance0.ID), - ImageID: omit.From(publicreportImages2[i].ID), - } - } - - publicreportNuisanceImages1, err := PublicreportNuisanceImages.Insert(bob.ToMods(setters...)).All(ctx, exec) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNuisanceImages0: %w", err) - } - - return publicreportNuisanceImages1, nil -} - -func (publicreportNuisance0 *PublicreportNuisance) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - publicreportImages2 := PublicreportImageSlice(inserted) - - _, err = attachPublicreportNuisanceImages0(ctx, exec, len(related), publicreportNuisance0, publicreportImages2) - if err != nil { - return err - } - - publicreportNuisance0.R.Images = append(publicreportNuisance0.R.Images, publicreportImages2...) - - for _, rel := range publicreportImages2 { - rel.R.Nuisances = append(rel.R.Nuisances, publicreportNuisance0) - } - return nil -} - -func (publicreportNuisance0 *PublicreportNuisance) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { - if len(related) == 0 { - return nil - } - - var err error - publicreportImages2 := PublicreportImageSlice(related) - - _, err = attachPublicreportNuisanceImages0(ctx, exec, len(related), publicreportNuisance0, publicreportImages2) - if err != nil { - return err - } - - publicreportNuisance0.R.Images = append(publicreportNuisance0.R.Images, publicreportImages2...) - - for _, rel := range related { - rel.R.Nuisances = append(rel.R.Nuisances, publicreportNuisance0) - } + publicreportReport1.R.Nuisance = publicreportNuisance0 return nil } type publicreportNuisanceWhere[Q psql.Filterable] struct { - ID psql.WhereMod[Q, int32] - AdditionalInfo psql.WhereMod[Q, string] - Created psql.WhereMod[Q, time.Time] - Duration psql.WhereMod[Q, enums.PublicreportNuisancedurationtype] - SourceContainer psql.WhereMod[Q, bool] - SourceDescription psql.WhereMod[Q, string] - SourceStagnant psql.WhereMod[Q, bool] - PublicID psql.WhereMod[Q, string] - ReporterEmail psql.WhereNullMod[Q, string] - ReporterName psql.WhereNullMod[Q, string] - ReporterPhone psql.WhereNullMod[Q, string] - AddressRaw psql.WhereMod[Q, string] - Status psql.WhereMod[Q, enums.PublicreportReportstatustype] - OrganizationID psql.WhereMod[Q, int32] - SourceGutter psql.WhereMod[Q, bool] - H3cell psql.WhereNullMod[Q, string] - AddressCountry psql.WhereMod[Q, string] - AddressLocality psql.WhereMod[Q, string] - AddressPostalCode psql.WhereMod[Q, string] - AddressRegion psql.WhereMod[Q, string] - AddressStreet psql.WhereMod[Q, string] - IsLocationBackyard psql.WhereMod[Q, bool] - IsLocationFrontyard psql.WhereMod[Q, bool] - IsLocationGarden psql.WhereMod[Q, bool] - IsLocationOther psql.WhereMod[Q, bool] - IsLocationPool psql.WhereMod[Q, bool] - MapZoom psql.WhereMod[Q, float32] - TodEarly psql.WhereMod[Q, bool] - TodDay psql.WhereMod[Q, bool] - TodEvening psql.WhereMod[Q, bool] - TodNight psql.WhereMod[Q, bool] - LatlngAccuracyType psql.WhereMod[Q, enums.PublicreportAccuracytype] - LatlngAccuracyValue psql.WhereMod[Q, float32] - ReporterContactConsent psql.WhereNullMod[Q, bool] - Location psql.WhereNullMod[Q, string] - AddressNumber psql.WhereMod[Q, string] - AddressID psql.WhereNullMod[Q, int32] - Reviewed psql.WhereNullMod[Q, time.Time] - ReviewerID psql.WhereNullMod[Q, int32] + AdditionalInfo psql.WhereMod[Q, string] + Duration psql.WhereMod[Q, enums.PublicreportNuisancedurationtype] + IsLocationBackyard psql.WhereMod[Q, bool] + IsLocationFrontyard psql.WhereMod[Q, bool] + IsLocationGarden psql.WhereMod[Q, bool] + IsLocationOther psql.WhereMod[Q, bool] + IsLocationPool psql.WhereMod[Q, bool] + ReportID psql.WhereMod[Q, int32] + SourceContainer psql.WhereMod[Q, bool] + SourceDescription psql.WhereMod[Q, string] + SourceStagnant psql.WhereMod[Q, bool] + SourceGutter psql.WhereMod[Q, bool] + TodEarly psql.WhereMod[Q, bool] + TodDay psql.WhereMod[Q, bool] + TodEvening psql.WhereMod[Q, bool] + TodNight psql.WhereMod[Q, bool] } func (publicreportNuisanceWhere[Q]) AliasedAs(alias string) publicreportNuisanceWhere[Q] { @@ -1770,45 +787,22 @@ func (publicreportNuisanceWhere[Q]) AliasedAs(alias string) publicreportNuisance func buildPublicreportNuisanceWhere[Q psql.Filterable](cols publicreportNuisanceColumns) publicreportNuisanceWhere[Q] { return publicreportNuisanceWhere[Q]{ - ID: psql.Where[Q, int32](cols.ID), - AdditionalInfo: psql.Where[Q, string](cols.AdditionalInfo), - Created: psql.Where[Q, time.Time](cols.Created), - Duration: psql.Where[Q, enums.PublicreportNuisancedurationtype](cols.Duration), - SourceContainer: psql.Where[Q, bool](cols.SourceContainer), - SourceDescription: psql.Where[Q, string](cols.SourceDescription), - SourceStagnant: psql.Where[Q, bool](cols.SourceStagnant), - PublicID: psql.Where[Q, string](cols.PublicID), - ReporterEmail: psql.WhereNull[Q, string](cols.ReporterEmail), - ReporterName: psql.WhereNull[Q, string](cols.ReporterName), - ReporterPhone: psql.WhereNull[Q, string](cols.ReporterPhone), - AddressRaw: psql.Where[Q, string](cols.AddressRaw), - Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status), - OrganizationID: psql.Where[Q, int32](cols.OrganizationID), - SourceGutter: psql.Where[Q, bool](cols.SourceGutter), - H3cell: psql.WhereNull[Q, string](cols.H3cell), - AddressCountry: psql.Where[Q, string](cols.AddressCountry), - AddressLocality: psql.Where[Q, string](cols.AddressLocality), - AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), - AddressRegion: psql.Where[Q, string](cols.AddressRegion), - AddressStreet: psql.Where[Q, string](cols.AddressStreet), - IsLocationBackyard: psql.Where[Q, bool](cols.IsLocationBackyard), - IsLocationFrontyard: psql.Where[Q, bool](cols.IsLocationFrontyard), - IsLocationGarden: psql.Where[Q, bool](cols.IsLocationGarden), - IsLocationOther: psql.Where[Q, bool](cols.IsLocationOther), - IsLocationPool: psql.Where[Q, bool](cols.IsLocationPool), - MapZoom: psql.Where[Q, float32](cols.MapZoom), - TodEarly: psql.Where[Q, bool](cols.TodEarly), - TodDay: psql.Where[Q, bool](cols.TodDay), - TodEvening: psql.Where[Q, bool](cols.TodEvening), - TodNight: psql.Where[Q, bool](cols.TodNight), - LatlngAccuracyType: psql.Where[Q, enums.PublicreportAccuracytype](cols.LatlngAccuracyType), - LatlngAccuracyValue: psql.Where[Q, float32](cols.LatlngAccuracyValue), - ReporterContactConsent: psql.WhereNull[Q, bool](cols.ReporterContactConsent), - Location: psql.WhereNull[Q, string](cols.Location), - AddressNumber: psql.Where[Q, string](cols.AddressNumber), - AddressID: psql.WhereNull[Q, int32](cols.AddressID), - Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed), - ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID), + AdditionalInfo: psql.Where[Q, string](cols.AdditionalInfo), + Duration: psql.Where[Q, enums.PublicreportNuisancedurationtype](cols.Duration), + IsLocationBackyard: psql.Where[Q, bool](cols.IsLocationBackyard), + IsLocationFrontyard: psql.Where[Q, bool](cols.IsLocationFrontyard), + IsLocationGarden: psql.Where[Q, bool](cols.IsLocationGarden), + IsLocationOther: psql.Where[Q, bool](cols.IsLocationOther), + IsLocationPool: psql.Where[Q, bool](cols.IsLocationPool), + ReportID: psql.Where[Q, int32](cols.ReportID), + SourceContainer: psql.Where[Q, bool](cols.SourceContainer), + SourceDescription: psql.Where[Q, string](cols.SourceDescription), + SourceStagnant: psql.Where[Q, bool](cols.SourceStagnant), + SourceGutter: psql.Where[Q, bool](cols.SourceGutter), + TodEarly: psql.Where[Q, bool](cols.TodEarly), + TodDay: psql.Where[Q, bool](cols.TodDay), + TodEvening: psql.Where[Q, bool](cols.TodEvening), + TodNight: psql.Where[Q, bool](cols.TodNight), } } @@ -1818,82 +812,16 @@ func (o *PublicreportNuisance) Preload(name string, retrieved any) error { } switch name { - case "NotifyEmailNuisances": - rels, ok := retrieved.(PublicreportNotifyEmailNuisanceSlice) + case "Report": + rel, ok := retrieved.(*PublicreportReport) if !ok { return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name) } - o.R.NotifyEmailNuisances = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Nuisance = o - } - } - return nil - case "NotifyPhoneNuisances": - rels, ok := retrieved.(PublicreportNotifyPhoneNuisanceSlice) - if !ok { - return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name) - } - - o.R.NotifyPhoneNuisances = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Nuisance = o - } - } - return nil - case "Address": - rel, ok := retrieved.(*Address) - if !ok { - return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name) - } - - o.R.Address = rel + o.R.Report = rel if rel != nil { - rel.R.Nuisances = PublicreportNuisanceSlice{o} - } - return nil - case "Organization": - rel, ok := retrieved.(*Organization) - if !ok { - return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name) - } - - o.R.Organization = rel - - if rel != nil { - rel.R.Nuisances = PublicreportNuisanceSlice{o} - } - return nil - case "ReviewerUser": - rel, ok := retrieved.(*User) - if !ok { - return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name) - } - - o.R.ReviewerUser = rel - - if rel != nil { - rel.R.ReviewerNuisances = PublicreportNuisanceSlice{o} - } - return nil - case "Images": - rels, ok := retrieved.(PublicreportImageSlice) - if !ok { - return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name) - } - - o.R.Images = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Nuisances = PublicreportNuisanceSlice{o} - } + rel.R.Nuisance = o } return nil default: @@ -1902,153 +830,73 @@ func (o *PublicreportNuisance) Preload(name string, retrieved any) error { } type publicreportNuisancePreloader struct { - Address func(...psql.PreloadOption) psql.Preloader - Organization func(...psql.PreloadOption) psql.Preloader - ReviewerUser func(...psql.PreloadOption) psql.Preloader + Report func(...psql.PreloadOption) psql.Preloader } func buildPublicreportNuisancePreloader() publicreportNuisancePreloader { return publicreportNuisancePreloader{ - Address: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*Address, AddressSlice](psql.PreloadRel{ - Name: "Address", + Report: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{ + Name: "Report", Sides: []psql.PreloadSide{ { From: PublicreportNuisances, - To: Addresses, - FromColumns: []string{"address_id"}, + To: PublicreportReports, + FromColumns: []string{"report_id"}, ToColumns: []string{"id"}, }, }, - }, Addresses.Columns.Names(), opts...) - }, - Organization: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ - Name: "Organization", - Sides: []psql.PreloadSide{ - { - From: PublicreportNuisances, - To: Organizations, - FromColumns: []string{"organization_id"}, - ToColumns: []string{"id"}, - }, - }, - }, Organizations.Columns.Names(), opts...) - }, - ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*User, UserSlice](psql.PreloadRel{ - Name: "ReviewerUser", - Sides: []psql.PreloadSide{ - { - From: PublicreportNuisances, - To: Users, - FromColumns: []string{"reviewer_id"}, - ToColumns: []string{"id"}, - }, - }, - }, Users.Columns.Names(), opts...) + }, PublicreportReports.Columns.Names(), opts...) }, } } type publicreportNuisanceThenLoader[Q orm.Loadable] struct { - NotifyEmailNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildPublicreportNuisanceThenLoader[Q orm.Loadable]() publicreportNuisanceThenLoader[Q] { - type NotifyEmailNuisancesLoadInterface interface { - LoadNotifyEmailNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type NotifyPhoneNuisancesLoadInterface interface { - LoadNotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type AddressLoadInterface interface { - LoadAddress(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type OrganizationLoadInterface interface { - LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type ReviewerUserLoadInterface interface { - LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type ImagesLoadInterface interface { - LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type ReportLoadInterface interface { + LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } return publicreportNuisanceThenLoader[Q]{ - NotifyEmailNuisances: thenLoadBuilder[Q]( - "NotifyEmailNuisances", - func(ctx context.Context, exec bob.Executor, retrieved NotifyEmailNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadNotifyEmailNuisances(ctx, exec, mods...) - }, - ), - NotifyPhoneNuisances: thenLoadBuilder[Q]( - "NotifyPhoneNuisances", - func(ctx context.Context, exec bob.Executor, retrieved NotifyPhoneNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadNotifyPhoneNuisances(ctx, exec, mods...) - }, - ), - Address: thenLoadBuilder[Q]( - "Address", - func(ctx context.Context, exec bob.Executor, retrieved AddressLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadAddress(ctx, exec, mods...) - }, - ), - Organization: thenLoadBuilder[Q]( - "Organization", - func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadOrganization(ctx, exec, mods...) - }, - ), - ReviewerUser: thenLoadBuilder[Q]( - "ReviewerUser", - func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadReviewerUser(ctx, exec, mods...) - }, - ), - Images: thenLoadBuilder[Q]( - "Images", - func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadImages(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...) }, ), } } -// LoadNotifyEmailNuisances loads the publicreportNuisance's NotifyEmailNuisances into the .R struct -func (o *PublicreportNuisance) LoadNotifyEmailNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReport loads the publicreportNuisance's Report into the .R struct +func (o *PublicreportNuisance) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } // Reset the relationship - o.R.NotifyEmailNuisances = nil + o.R.Report = nil - related, err := o.NotifyEmailNuisances(mods...).All(ctx, exec) + related, err := o.Report(mods...).One(ctx, exec) if err != nil { return err } - for _, rel := range related { - rel.R.Nuisance = o - } + related.R.Nuisance = o - o.R.NotifyEmailNuisances = related + o.R.Report = related return nil } -// LoadNotifyEmailNuisances loads the publicreportNuisance's NotifyEmailNuisances into the .R struct -func (os PublicreportNuisanceSlice) LoadNotifyEmailNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReport loads the publicreportNuisance's Report into the .R struct +func (os PublicreportNuisanceSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } - publicreportNotifyEmailNuisances, err := os.NotifyEmailNuisances(mods...).All(ctx, exec) + publicreportReports, err := os.Report(mods...).All(ctx, exec) if err != nil { return err } @@ -2058,329 +906,18 @@ func (os PublicreportNuisanceSlice) LoadNotifyEmailNuisances(ctx context.Context continue } - o.R.NotifyEmailNuisances = nil - } + for _, rel := range publicreportReports { - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportNotifyEmailNuisances { - - if !(o.ID == rel.NuisanceID) { + if !(o.ReportID == rel.ID) { continue } rel.R.Nuisance = o - o.R.NotifyEmailNuisances = append(o.R.NotifyEmailNuisances, rel) - } - } - - return nil -} - -// LoadNotifyPhoneNuisances loads the publicreportNuisance's NotifyPhoneNuisances into the .R struct -func (o *PublicreportNuisance) LoadNotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.NotifyPhoneNuisances = nil - - related, err := o.NotifyPhoneNuisances(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, rel := range related { - rel.R.Nuisance = o - } - - o.R.NotifyPhoneNuisances = related - return nil -} - -// LoadNotifyPhoneNuisances loads the publicreportNuisance's NotifyPhoneNuisances into the .R struct -func (os PublicreportNuisanceSlice) LoadNotifyPhoneNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - publicreportNotifyPhoneNuisances, err := os.NotifyPhoneNuisances(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - o.R.NotifyPhoneNuisances = nil - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportNotifyPhoneNuisances { - - if !(o.ID == rel.NuisanceID) { - continue - } - - rel.R.Nuisance = o - - o.R.NotifyPhoneNuisances = append(o.R.NotifyPhoneNuisances, rel) - } - } - - return nil -} - -// LoadAddress loads the publicreportNuisance's Address into the .R struct -func (o *PublicreportNuisance) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Address = nil - - related, err := o.Address(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.Nuisances = PublicreportNuisanceSlice{o} - - o.R.Address = related - return nil -} - -// LoadAddress loads the publicreportNuisance's Address into the .R struct -func (os PublicreportNuisanceSlice) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - addresses, err := os.Address(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range addresses { - if !o.AddressID.IsValue() { - continue - } - - if !(o.AddressID.IsValue() && o.AddressID.MustGet() == rel.ID) { - continue - } - - rel.R.Nuisances = append(rel.R.Nuisances, o) - - o.R.Address = rel + o.R.Report = rel break } } return nil } - -// LoadOrganization loads the publicreportNuisance's Organization into the .R struct -func (o *PublicreportNuisance) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Organization = nil - - related, err := o.Organization(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.Nuisances = PublicreportNuisanceSlice{o} - - o.R.Organization = related - return nil -} - -// LoadOrganization loads the publicreportNuisance's Organization into the .R struct -func (os PublicreportNuisanceSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - organizations, err := os.Organization(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range organizations { - - if !(o.OrganizationID == rel.ID) { - continue - } - - rel.R.Nuisances = append(rel.R.Nuisances, o) - - o.R.Organization = rel - break - } - } - - return nil -} - -// LoadReviewerUser loads the publicreportNuisance's ReviewerUser into the .R struct -func (o *PublicreportNuisance) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.ReviewerUser = nil - - related, err := o.ReviewerUser(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.ReviewerNuisances = PublicreportNuisanceSlice{o} - - o.R.ReviewerUser = related - return nil -} - -// LoadReviewerUser loads the publicreportNuisance's ReviewerUser into the .R struct -func (os PublicreportNuisanceSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - users, err := os.ReviewerUser(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range users { - if !o.ReviewerID.IsValue() { - continue - } - - if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) { - continue - } - - rel.R.ReviewerNuisances = append(rel.R.ReviewerNuisances, o) - - o.R.ReviewerUser = rel - break - } - } - - return nil -} - -// LoadImages loads the publicreportNuisance's Images into the .R struct -func (o *PublicreportNuisance) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Images = nil - - related, err := o.Images(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, rel := range related { - rel.R.Nuisances = PublicreportNuisanceSlice{o} - } - - o.R.Images = related - return nil -} - -// LoadImages loads the publicreportNuisance's Images into the .R struct -func (os PublicreportNuisanceSlice) LoadImages(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(PublicreportImages.Columns)) - } - - q := os.Images(append( - mods, - sm.Columns(PublicreportNuisanceImages.Columns.NuisanceID.As("related_publicreport.nuisance.ID")), - )...) - - IDSlice := []int32{} - - mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), 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.nuisance.ID", &IDSlice[len(IDSlice)-1]) - - return nil, nil - }, - func(any, any) error { - return nil - } - }) - - publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper) - if err != nil { - return err - } - - for _, o := range os { - o.R.Images = nil - } - - for _, o := range os { - for i, rel := range publicreportImages { - if !(o.ID == IDSlice[i]) { - continue - } - - rel.R.Nuisances = append(rel.R.Nuisances, o) - - o.R.Images = append(o.R.Images, rel) - } - } - - return nil -} diff --git a/db/models/publicreport.nuisance_image.bob.go b/db/models/publicreport.nuisance_image.bob.go deleted file mode 100644 index 414782e8..00000000 --- a/db/models/publicreport.nuisance_image.bob.go +++ /dev/null @@ -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 -} diff --git a/db/models/publicreport.nuisance_image_old.bob.go b/db/models/publicreport.nuisance_image_old.bob.go new file mode 100644 index 00000000..f3a874da --- /dev/null +++ b/db/models/publicreport.nuisance_image_old.bob.go @@ -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 +} diff --git a/db/models/publicreport.nuisance_old.bob.go b/db/models/publicreport.nuisance_old.bob.go new file mode 100644 index 00000000..ab831f65 --- /dev/null +++ b/db/models/publicreport.nuisance_old.bob.go @@ -0,0 +1,2386 @@ +// 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" + enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/scan" +) + +// PublicreportNuisanceOld is an object representing the database table. +type PublicreportNuisanceOld struct { + ID int32 `db:"id,pk" ` + AdditionalInfo string `db:"additional_info" ` + Created time.Time `db:"created" ` + Duration enums.PublicreportNuisancedurationtype `db:"duration" ` + SourceContainer bool `db:"source_container" ` + SourceDescription string `db:"source_description" ` + SourceStagnant bool `db:"source_stagnant" ` + PublicID string `db:"public_id" ` + ReporterEmail null.Val[string] `db:"reporter_email" ` + ReporterName null.Val[string] `db:"reporter_name" ` + ReporterPhone null.Val[string] `db:"reporter_phone" ` + AddressRaw string `db:"address_raw" ` + Status enums.PublicreportReportstatustype `db:"status" ` + OrganizationID int32 `db:"organization_id" ` + SourceGutter bool `db:"source_gutter" ` + H3cell null.Val[string] `db:"h3cell" ` + AddressCountry string `db:"address_country" ` + AddressLocality string `db:"address_locality" ` + AddressPostalCode string `db:"address_postal_code" ` + AddressRegion string `db:"address_region" ` + AddressStreet string `db:"address_street" ` + IsLocationBackyard bool `db:"is_location_backyard" ` + IsLocationFrontyard bool `db:"is_location_frontyard" ` + IsLocationGarden bool `db:"is_location_garden" ` + IsLocationOther bool `db:"is_location_other" ` + IsLocationPool bool `db:"is_location_pool" ` + MapZoom float32 `db:"map_zoom" ` + TodEarly bool `db:"tod_early" ` + TodDay bool `db:"tod_day" ` + TodEvening bool `db:"tod_evening" ` + TodNight bool `db:"tod_night" ` + LatlngAccuracyType enums.PublicreportAccuracytype `db:"latlng_accuracy_type" ` + LatlngAccuracyValue float32 `db:"latlng_accuracy_value" ` + ReporterContactConsent null.Val[bool] `db:"reporter_contact_consent" ` + Location null.Val[string] `db:"location" ` + AddressNumber string `db:"address_number" ` + AddressID null.Val[int32] `db:"address_id" ` + Reviewed null.Val[time.Time] `db:"reviewed" ` + ReviewerID null.Val[int32] `db:"reviewer_id" ` + + R publicreportNuisanceOldR `db:"-" ` +} + +// PublicreportNuisanceOldSlice is an alias for a slice of pointers to PublicreportNuisanceOld. +// This should almost always be used instead of []*PublicreportNuisanceOld. +type PublicreportNuisanceOldSlice []*PublicreportNuisanceOld + +// PublicreportNuisanceOlds contains methods to work with the nuisance_old table +var PublicreportNuisanceOlds = psql.NewTablex[*PublicreportNuisanceOld, PublicreportNuisanceOldSlice, *PublicreportNuisanceOldSetter]("publicreport", "nuisance_old", buildPublicreportNuisanceOldColumns("publicreport.nuisance_old")) + +// PublicreportNuisanceOldsQuery is a query on the nuisance_old table +type PublicreportNuisanceOldsQuery = *psql.ViewQuery[*PublicreportNuisanceOld, PublicreportNuisanceOldSlice] + +// publicreportNuisanceOldR is where relationships are stored. +type publicreportNuisanceOldR struct { + NuisanceNotifyEmailNuisanceOlds PublicreportNotifyEmailNuisanceOldSlice // publicreport.notify_email_nuisance_old.notify_email_nuisance_nuisance_id_fkey + NuisanceNotifyPhoneNuisanceOlds PublicreportNotifyPhoneNuisanceOldSlice // publicreport.notify_phone_nuisance_old.notify_phone_nuisance_nuisance_id_fkey + Images PublicreportImageSlice // publicreport.nuisance_image_old.nuisance_image_image_id_fkeypublicreport.nuisance_image_old.nuisance_image_nuisance_id_fkey + Address *Address // publicreport.nuisance_old.nuisance_address_id_fkey + Organization *Organization // publicreport.nuisance_old.nuisance_organization_id_fkey + ReviewerUser *User // publicreport.nuisance_old.nuisance_reviewer_id_fkey +} + +func buildPublicreportNuisanceOldColumns(alias string) publicreportNuisanceOldColumns { + return publicreportNuisanceOldColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "additional_info", "created", "duration", "source_container", "source_description", "source_stagnant", "public_id", "reporter_email", "reporter_name", "reporter_phone", "address_raw", "status", "organization_id", "source_gutter", "h3cell", "address_country", "address_locality", "address_postal_code", "address_region", "address_street", "is_location_backyard", "is_location_frontyard", "is_location_garden", "is_location_other", "is_location_pool", "map_zoom", "tod_early", "tod_day", "tod_evening", "tod_night", "latlng_accuracy_type", "latlng_accuracy_value", "reporter_contact_consent", "location", "address_number", "address_id", "reviewed", "reviewer_id", + ).WithParent("publicreport.nuisance_old"), + tableAlias: alias, + ID: psql.Quote(alias, "id"), + AdditionalInfo: psql.Quote(alias, "additional_info"), + Created: psql.Quote(alias, "created"), + Duration: psql.Quote(alias, "duration"), + SourceContainer: psql.Quote(alias, "source_container"), + SourceDescription: psql.Quote(alias, "source_description"), + SourceStagnant: psql.Quote(alias, "source_stagnant"), + PublicID: psql.Quote(alias, "public_id"), + ReporterEmail: psql.Quote(alias, "reporter_email"), + ReporterName: psql.Quote(alias, "reporter_name"), + ReporterPhone: psql.Quote(alias, "reporter_phone"), + AddressRaw: psql.Quote(alias, "address_raw"), + Status: psql.Quote(alias, "status"), + OrganizationID: psql.Quote(alias, "organization_id"), + SourceGutter: psql.Quote(alias, "source_gutter"), + H3cell: psql.Quote(alias, "h3cell"), + AddressCountry: psql.Quote(alias, "address_country"), + AddressLocality: psql.Quote(alias, "address_locality"), + AddressPostalCode: psql.Quote(alias, "address_postal_code"), + AddressRegion: psql.Quote(alias, "address_region"), + AddressStreet: psql.Quote(alias, "address_street"), + IsLocationBackyard: psql.Quote(alias, "is_location_backyard"), + IsLocationFrontyard: psql.Quote(alias, "is_location_frontyard"), + IsLocationGarden: psql.Quote(alias, "is_location_garden"), + IsLocationOther: psql.Quote(alias, "is_location_other"), + IsLocationPool: psql.Quote(alias, "is_location_pool"), + MapZoom: psql.Quote(alias, "map_zoom"), + TodEarly: psql.Quote(alias, "tod_early"), + TodDay: psql.Quote(alias, "tod_day"), + TodEvening: psql.Quote(alias, "tod_evening"), + TodNight: psql.Quote(alias, "tod_night"), + LatlngAccuracyType: psql.Quote(alias, "latlng_accuracy_type"), + LatlngAccuracyValue: psql.Quote(alias, "latlng_accuracy_value"), + ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), + Location: psql.Quote(alias, "location"), + AddressNumber: psql.Quote(alias, "address_number"), + AddressID: psql.Quote(alias, "address_id"), + Reviewed: psql.Quote(alias, "reviewed"), + ReviewerID: psql.Quote(alias, "reviewer_id"), + } +} + +type publicreportNuisanceOldColumns struct { + expr.ColumnsExpr + tableAlias string + ID psql.Expression + AdditionalInfo psql.Expression + Created psql.Expression + Duration psql.Expression + SourceContainer psql.Expression + SourceDescription psql.Expression + SourceStagnant psql.Expression + PublicID psql.Expression + ReporterEmail psql.Expression + ReporterName psql.Expression + ReporterPhone psql.Expression + AddressRaw psql.Expression + Status psql.Expression + OrganizationID psql.Expression + SourceGutter psql.Expression + H3cell psql.Expression + AddressCountry psql.Expression + AddressLocality psql.Expression + AddressPostalCode psql.Expression + AddressRegion psql.Expression + AddressStreet psql.Expression + IsLocationBackyard psql.Expression + IsLocationFrontyard psql.Expression + IsLocationGarden psql.Expression + IsLocationOther psql.Expression + IsLocationPool psql.Expression + MapZoom psql.Expression + TodEarly psql.Expression + TodDay psql.Expression + TodEvening psql.Expression + TodNight psql.Expression + LatlngAccuracyType psql.Expression + LatlngAccuracyValue psql.Expression + ReporterContactConsent psql.Expression + Location psql.Expression + AddressNumber psql.Expression + AddressID psql.Expression + Reviewed psql.Expression + ReviewerID psql.Expression +} + +func (c publicreportNuisanceOldColumns) Alias() string { + return c.tableAlias +} + +func (publicreportNuisanceOldColumns) AliasedAs(alias string) publicreportNuisanceOldColumns { + return buildPublicreportNuisanceOldColumns(alias) +} + +// PublicreportNuisanceOldSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type PublicreportNuisanceOldSetter struct { + ID omit.Val[int32] `db:"id,pk" ` + AdditionalInfo omit.Val[string] `db:"additional_info" ` + Created omit.Val[time.Time] `db:"created" ` + Duration omit.Val[enums.PublicreportNuisancedurationtype] `db:"duration" ` + SourceContainer omit.Val[bool] `db:"source_container" ` + SourceDescription omit.Val[string] `db:"source_description" ` + SourceStagnant omit.Val[bool] `db:"source_stagnant" ` + PublicID omit.Val[string] `db:"public_id" ` + ReporterEmail omitnull.Val[string] `db:"reporter_email" ` + ReporterName omitnull.Val[string] `db:"reporter_name" ` + ReporterPhone omitnull.Val[string] `db:"reporter_phone" ` + AddressRaw omit.Val[string] `db:"address_raw" ` + Status omit.Val[enums.PublicreportReportstatustype] `db:"status" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + SourceGutter omit.Val[bool] `db:"source_gutter" ` + H3cell omitnull.Val[string] `db:"h3cell" ` + AddressCountry omit.Val[string] `db:"address_country" ` + AddressLocality omit.Val[string] `db:"address_locality" ` + AddressPostalCode omit.Val[string] `db:"address_postal_code" ` + AddressRegion omit.Val[string] `db:"address_region" ` + AddressStreet omit.Val[string] `db:"address_street" ` + IsLocationBackyard omit.Val[bool] `db:"is_location_backyard" ` + IsLocationFrontyard omit.Val[bool] `db:"is_location_frontyard" ` + IsLocationGarden omit.Val[bool] `db:"is_location_garden" ` + IsLocationOther omit.Val[bool] `db:"is_location_other" ` + IsLocationPool omit.Val[bool] `db:"is_location_pool" ` + MapZoom omit.Val[float32] `db:"map_zoom" ` + TodEarly omit.Val[bool] `db:"tod_early" ` + TodDay omit.Val[bool] `db:"tod_day" ` + TodEvening omit.Val[bool] `db:"tod_evening" ` + TodNight omit.Val[bool] `db:"tod_night" ` + LatlngAccuracyType omit.Val[enums.PublicreportAccuracytype] `db:"latlng_accuracy_type" ` + LatlngAccuracyValue omit.Val[float32] `db:"latlng_accuracy_value" ` + ReporterContactConsent omitnull.Val[bool] `db:"reporter_contact_consent" ` + Location omitnull.Val[string] `db:"location" ` + AddressNumber omit.Val[string] `db:"address_number" ` + AddressID omitnull.Val[int32] `db:"address_id" ` + Reviewed omitnull.Val[time.Time] `db:"reviewed" ` + ReviewerID omitnull.Val[int32] `db:"reviewer_id" ` +} + +func (s PublicreportNuisanceOldSetter) SetColumns() []string { + vals := make([]string, 0, 39) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.AdditionalInfo.IsValue() { + vals = append(vals, "additional_info") + } + if s.Created.IsValue() { + vals = append(vals, "created") + } + if s.Duration.IsValue() { + vals = append(vals, "duration") + } + if s.SourceContainer.IsValue() { + vals = append(vals, "source_container") + } + if s.SourceDescription.IsValue() { + vals = append(vals, "source_description") + } + if s.SourceStagnant.IsValue() { + vals = append(vals, "source_stagnant") + } + if s.PublicID.IsValue() { + vals = append(vals, "public_id") + } + if !s.ReporterEmail.IsUnset() { + vals = append(vals, "reporter_email") + } + if !s.ReporterName.IsUnset() { + vals = append(vals, "reporter_name") + } + if !s.ReporterPhone.IsUnset() { + vals = append(vals, "reporter_phone") + } + if s.AddressRaw.IsValue() { + vals = append(vals, "address_raw") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + if s.OrganizationID.IsValue() { + vals = append(vals, "organization_id") + } + if s.SourceGutter.IsValue() { + vals = append(vals, "source_gutter") + } + if !s.H3cell.IsUnset() { + vals = append(vals, "h3cell") + } + if s.AddressCountry.IsValue() { + vals = append(vals, "address_country") + } + if s.AddressLocality.IsValue() { + vals = append(vals, "address_locality") + } + if s.AddressPostalCode.IsValue() { + vals = append(vals, "address_postal_code") + } + if s.AddressRegion.IsValue() { + vals = append(vals, "address_region") + } + if s.AddressStreet.IsValue() { + vals = append(vals, "address_street") + } + if s.IsLocationBackyard.IsValue() { + vals = append(vals, "is_location_backyard") + } + if s.IsLocationFrontyard.IsValue() { + vals = append(vals, "is_location_frontyard") + } + if s.IsLocationGarden.IsValue() { + vals = append(vals, "is_location_garden") + } + if s.IsLocationOther.IsValue() { + vals = append(vals, "is_location_other") + } + if s.IsLocationPool.IsValue() { + vals = append(vals, "is_location_pool") + } + if s.MapZoom.IsValue() { + vals = append(vals, "map_zoom") + } + if s.TodEarly.IsValue() { + vals = append(vals, "tod_early") + } + if s.TodDay.IsValue() { + vals = append(vals, "tod_day") + } + if s.TodEvening.IsValue() { + vals = append(vals, "tod_evening") + } + if s.TodNight.IsValue() { + vals = append(vals, "tod_night") + } + if s.LatlngAccuracyType.IsValue() { + vals = append(vals, "latlng_accuracy_type") + } + if s.LatlngAccuracyValue.IsValue() { + vals = append(vals, "latlng_accuracy_value") + } + if !s.ReporterContactConsent.IsUnset() { + vals = append(vals, "reporter_contact_consent") + } + if !s.Location.IsUnset() { + vals = append(vals, "location") + } + if s.AddressNumber.IsValue() { + vals = append(vals, "address_number") + } + if !s.AddressID.IsUnset() { + vals = append(vals, "address_id") + } + if !s.Reviewed.IsUnset() { + vals = append(vals, "reviewed") + } + if !s.ReviewerID.IsUnset() { + vals = append(vals, "reviewer_id") + } + return vals +} + +func (s PublicreportNuisanceOldSetter) Overwrite(t *PublicreportNuisanceOld) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.AdditionalInfo.IsValue() { + t.AdditionalInfo = s.AdditionalInfo.MustGet() + } + if s.Created.IsValue() { + t.Created = s.Created.MustGet() + } + if s.Duration.IsValue() { + t.Duration = s.Duration.MustGet() + } + if s.SourceContainer.IsValue() { + t.SourceContainer = s.SourceContainer.MustGet() + } + if s.SourceDescription.IsValue() { + t.SourceDescription = s.SourceDescription.MustGet() + } + if s.SourceStagnant.IsValue() { + t.SourceStagnant = s.SourceStagnant.MustGet() + } + if s.PublicID.IsValue() { + t.PublicID = s.PublicID.MustGet() + } + if !s.ReporterEmail.IsUnset() { + t.ReporterEmail = s.ReporterEmail.MustGetNull() + } + if !s.ReporterName.IsUnset() { + t.ReporterName = s.ReporterName.MustGetNull() + } + if !s.ReporterPhone.IsUnset() { + t.ReporterPhone = s.ReporterPhone.MustGetNull() + } + if s.AddressRaw.IsValue() { + t.AddressRaw = s.AddressRaw.MustGet() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } + if s.OrganizationID.IsValue() { + t.OrganizationID = s.OrganizationID.MustGet() + } + if s.SourceGutter.IsValue() { + t.SourceGutter = s.SourceGutter.MustGet() + } + if !s.H3cell.IsUnset() { + t.H3cell = s.H3cell.MustGetNull() + } + if s.AddressCountry.IsValue() { + t.AddressCountry = s.AddressCountry.MustGet() + } + if s.AddressLocality.IsValue() { + t.AddressLocality = s.AddressLocality.MustGet() + } + if s.AddressPostalCode.IsValue() { + t.AddressPostalCode = s.AddressPostalCode.MustGet() + } + if s.AddressRegion.IsValue() { + t.AddressRegion = s.AddressRegion.MustGet() + } + if s.AddressStreet.IsValue() { + t.AddressStreet = s.AddressStreet.MustGet() + } + if s.IsLocationBackyard.IsValue() { + t.IsLocationBackyard = s.IsLocationBackyard.MustGet() + } + if s.IsLocationFrontyard.IsValue() { + t.IsLocationFrontyard = s.IsLocationFrontyard.MustGet() + } + if s.IsLocationGarden.IsValue() { + t.IsLocationGarden = s.IsLocationGarden.MustGet() + } + if s.IsLocationOther.IsValue() { + t.IsLocationOther = s.IsLocationOther.MustGet() + } + if s.IsLocationPool.IsValue() { + t.IsLocationPool = s.IsLocationPool.MustGet() + } + if s.MapZoom.IsValue() { + t.MapZoom = s.MapZoom.MustGet() + } + if s.TodEarly.IsValue() { + t.TodEarly = s.TodEarly.MustGet() + } + if s.TodDay.IsValue() { + t.TodDay = s.TodDay.MustGet() + } + if s.TodEvening.IsValue() { + t.TodEvening = s.TodEvening.MustGet() + } + if s.TodNight.IsValue() { + t.TodNight = s.TodNight.MustGet() + } + if s.LatlngAccuracyType.IsValue() { + t.LatlngAccuracyType = s.LatlngAccuracyType.MustGet() + } + if s.LatlngAccuracyValue.IsValue() { + t.LatlngAccuracyValue = s.LatlngAccuracyValue.MustGet() + } + if !s.ReporterContactConsent.IsUnset() { + t.ReporterContactConsent = s.ReporterContactConsent.MustGetNull() + } + if !s.Location.IsUnset() { + t.Location = s.Location.MustGetNull() + } + if s.AddressNumber.IsValue() { + t.AddressNumber = s.AddressNumber.MustGet() + } + if !s.AddressID.IsUnset() { + t.AddressID = s.AddressID.MustGetNull() + } + if !s.Reviewed.IsUnset() { + t.Reviewed = s.Reviewed.MustGetNull() + } + if !s.ReviewerID.IsUnset() { + t.ReviewerID = s.ReviewerID.MustGetNull() + } +} + +func (s *PublicreportNuisanceOldSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return PublicreportNuisanceOlds.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, 39) + if s.ID.IsValue() { + vals[0] = psql.Arg(s.ID.MustGet()) + } else { + vals[0] = psql.Raw("DEFAULT") + } + + if s.AdditionalInfo.IsValue() { + vals[1] = psql.Arg(s.AdditionalInfo.MustGet()) + } else { + vals[1] = psql.Raw("DEFAULT") + } + + if s.Created.IsValue() { + vals[2] = psql.Arg(s.Created.MustGet()) + } else { + vals[2] = psql.Raw("DEFAULT") + } + + if s.Duration.IsValue() { + vals[3] = psql.Arg(s.Duration.MustGet()) + } else { + vals[3] = psql.Raw("DEFAULT") + } + + if s.SourceContainer.IsValue() { + vals[4] = psql.Arg(s.SourceContainer.MustGet()) + } else { + vals[4] = psql.Raw("DEFAULT") + } + + if s.SourceDescription.IsValue() { + vals[5] = psql.Arg(s.SourceDescription.MustGet()) + } else { + vals[5] = psql.Raw("DEFAULT") + } + + if s.SourceStagnant.IsValue() { + vals[6] = psql.Arg(s.SourceStagnant.MustGet()) + } else { + vals[6] = psql.Raw("DEFAULT") + } + + if s.PublicID.IsValue() { + vals[7] = psql.Arg(s.PublicID.MustGet()) + } else { + vals[7] = psql.Raw("DEFAULT") + } + + if !s.ReporterEmail.IsUnset() { + vals[8] = psql.Arg(s.ReporterEmail.MustGetNull()) + } else { + vals[8] = psql.Raw("DEFAULT") + } + + if !s.ReporterName.IsUnset() { + vals[9] = psql.Arg(s.ReporterName.MustGetNull()) + } else { + vals[9] = psql.Raw("DEFAULT") + } + + if !s.ReporterPhone.IsUnset() { + vals[10] = psql.Arg(s.ReporterPhone.MustGetNull()) + } else { + vals[10] = psql.Raw("DEFAULT") + } + + if s.AddressRaw.IsValue() { + vals[11] = psql.Arg(s.AddressRaw.MustGet()) + } else { + vals[11] = psql.Raw("DEFAULT") + } + + if s.Status.IsValue() { + vals[12] = psql.Arg(s.Status.MustGet()) + } else { + vals[12] = psql.Raw("DEFAULT") + } + + if s.OrganizationID.IsValue() { + vals[13] = psql.Arg(s.OrganizationID.MustGet()) + } else { + vals[13] = psql.Raw("DEFAULT") + } + + if s.SourceGutter.IsValue() { + vals[14] = psql.Arg(s.SourceGutter.MustGet()) + } else { + vals[14] = psql.Raw("DEFAULT") + } + + if !s.H3cell.IsUnset() { + vals[15] = psql.Arg(s.H3cell.MustGetNull()) + } else { + vals[15] = psql.Raw("DEFAULT") + } + + if s.AddressCountry.IsValue() { + vals[16] = psql.Arg(s.AddressCountry.MustGet()) + } else { + vals[16] = psql.Raw("DEFAULT") + } + + if s.AddressLocality.IsValue() { + vals[17] = psql.Arg(s.AddressLocality.MustGet()) + } else { + vals[17] = psql.Raw("DEFAULT") + } + + if s.AddressPostalCode.IsValue() { + vals[18] = psql.Arg(s.AddressPostalCode.MustGet()) + } else { + vals[18] = psql.Raw("DEFAULT") + } + + if s.AddressRegion.IsValue() { + vals[19] = psql.Arg(s.AddressRegion.MustGet()) + } else { + vals[19] = psql.Raw("DEFAULT") + } + + if s.AddressStreet.IsValue() { + vals[20] = psql.Arg(s.AddressStreet.MustGet()) + } else { + vals[20] = psql.Raw("DEFAULT") + } + + if s.IsLocationBackyard.IsValue() { + vals[21] = psql.Arg(s.IsLocationBackyard.MustGet()) + } else { + vals[21] = psql.Raw("DEFAULT") + } + + if s.IsLocationFrontyard.IsValue() { + vals[22] = psql.Arg(s.IsLocationFrontyard.MustGet()) + } else { + vals[22] = psql.Raw("DEFAULT") + } + + if s.IsLocationGarden.IsValue() { + vals[23] = psql.Arg(s.IsLocationGarden.MustGet()) + } else { + vals[23] = psql.Raw("DEFAULT") + } + + if s.IsLocationOther.IsValue() { + vals[24] = psql.Arg(s.IsLocationOther.MustGet()) + } else { + vals[24] = psql.Raw("DEFAULT") + } + + if s.IsLocationPool.IsValue() { + vals[25] = psql.Arg(s.IsLocationPool.MustGet()) + } else { + vals[25] = psql.Raw("DEFAULT") + } + + if s.MapZoom.IsValue() { + vals[26] = psql.Arg(s.MapZoom.MustGet()) + } else { + vals[26] = psql.Raw("DEFAULT") + } + + if s.TodEarly.IsValue() { + vals[27] = psql.Arg(s.TodEarly.MustGet()) + } else { + vals[27] = psql.Raw("DEFAULT") + } + + if s.TodDay.IsValue() { + vals[28] = psql.Arg(s.TodDay.MustGet()) + } else { + vals[28] = psql.Raw("DEFAULT") + } + + if s.TodEvening.IsValue() { + vals[29] = psql.Arg(s.TodEvening.MustGet()) + } else { + vals[29] = psql.Raw("DEFAULT") + } + + if s.TodNight.IsValue() { + vals[30] = psql.Arg(s.TodNight.MustGet()) + } else { + vals[30] = psql.Raw("DEFAULT") + } + + if s.LatlngAccuracyType.IsValue() { + vals[31] = psql.Arg(s.LatlngAccuracyType.MustGet()) + } else { + vals[31] = psql.Raw("DEFAULT") + } + + if s.LatlngAccuracyValue.IsValue() { + vals[32] = psql.Arg(s.LatlngAccuracyValue.MustGet()) + } else { + vals[32] = psql.Raw("DEFAULT") + } + + if !s.ReporterContactConsent.IsUnset() { + vals[33] = psql.Arg(s.ReporterContactConsent.MustGetNull()) + } else { + vals[33] = psql.Raw("DEFAULT") + } + + if !s.Location.IsUnset() { + vals[34] = psql.Arg(s.Location.MustGetNull()) + } else { + vals[34] = psql.Raw("DEFAULT") + } + + if s.AddressNumber.IsValue() { + vals[35] = psql.Arg(s.AddressNumber.MustGet()) + } else { + vals[35] = psql.Raw("DEFAULT") + } + + if !s.AddressID.IsUnset() { + vals[36] = psql.Arg(s.AddressID.MustGetNull()) + } else { + vals[36] = psql.Raw("DEFAULT") + } + + if !s.Reviewed.IsUnset() { + vals[37] = psql.Arg(s.Reviewed.MustGetNull()) + } else { + vals[37] = psql.Raw("DEFAULT") + } + + if !s.ReviewerID.IsUnset() { + vals[38] = psql.Arg(s.ReviewerID.MustGetNull()) + } else { + vals[38] = psql.Raw("DEFAULT") + } + + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") + })) +} + +func (s PublicreportNuisanceOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions()...) +} + +func (s PublicreportNuisanceOldSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 39) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "id")...), + psql.Arg(s.ID), + }}) + } + + if s.AdditionalInfo.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "additional_info")...), + psql.Arg(s.AdditionalInfo), + }}) + } + + if s.Created.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + + if s.Duration.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "duration")...), + psql.Arg(s.Duration), + }}) + } + + if s.SourceContainer.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_container")...), + psql.Arg(s.SourceContainer), + }}) + } + + if s.SourceDescription.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_description")...), + psql.Arg(s.SourceDescription), + }}) + } + + if s.SourceStagnant.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_stagnant")...), + psql.Arg(s.SourceStagnant), + }}) + } + + if s.PublicID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "public_id")...), + psql.Arg(s.PublicID), + }}) + } + + if !s.ReporterEmail.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_email")...), + psql.Arg(s.ReporterEmail), + }}) + } + + if !s.ReporterName.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_name")...), + psql.Arg(s.ReporterName), + }}) + } + + if !s.ReporterPhone.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_phone")...), + psql.Arg(s.ReporterPhone), + }}) + } + + if s.AddressRaw.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_raw")...), + psql.Arg(s.AddressRaw), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "status")...), + psql.Arg(s.Status), + }}) + } + + if s.OrganizationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "organization_id")...), + psql.Arg(s.OrganizationID), + }}) + } + + if s.SourceGutter.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "source_gutter")...), + psql.Arg(s.SourceGutter), + }}) + } + + if !s.H3cell.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "h3cell")...), + psql.Arg(s.H3cell), + }}) + } + + if s.AddressCountry.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_country")...), + psql.Arg(s.AddressCountry), + }}) + } + + if s.AddressLocality.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_locality")...), + psql.Arg(s.AddressLocality), + }}) + } + + if s.AddressPostalCode.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_postal_code")...), + psql.Arg(s.AddressPostalCode), + }}) + } + + if s.AddressRegion.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_region")...), + psql.Arg(s.AddressRegion), + }}) + } + + if s.AddressStreet.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_street")...), + psql.Arg(s.AddressStreet), + }}) + } + + if s.IsLocationBackyard.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_location_backyard")...), + psql.Arg(s.IsLocationBackyard), + }}) + } + + if s.IsLocationFrontyard.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_location_frontyard")...), + psql.Arg(s.IsLocationFrontyard), + }}) + } + + if s.IsLocationGarden.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_location_garden")...), + psql.Arg(s.IsLocationGarden), + }}) + } + + if s.IsLocationOther.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_location_other")...), + psql.Arg(s.IsLocationOther), + }}) + } + + if s.IsLocationPool.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_location_pool")...), + psql.Arg(s.IsLocationPool), + }}) + } + + if s.MapZoom.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "map_zoom")...), + psql.Arg(s.MapZoom), + }}) + } + + if s.TodEarly.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "tod_early")...), + psql.Arg(s.TodEarly), + }}) + } + + if s.TodDay.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "tod_day")...), + psql.Arg(s.TodDay), + }}) + } + + if s.TodEvening.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "tod_evening")...), + psql.Arg(s.TodEvening), + }}) + } + + if s.TodNight.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "tod_night")...), + psql.Arg(s.TodNight), + }}) + } + + if s.LatlngAccuracyType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "latlng_accuracy_type")...), + psql.Arg(s.LatlngAccuracyType), + }}) + } + + if s.LatlngAccuracyValue.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "latlng_accuracy_value")...), + psql.Arg(s.LatlngAccuracyValue), + }}) + } + + if !s.ReporterContactConsent.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_contact_consent")...), + psql.Arg(s.ReporterContactConsent), + }}) + } + + if !s.Location.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "location")...), + psql.Arg(s.Location), + }}) + } + + if s.AddressNumber.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_number")...), + psql.Arg(s.AddressNumber), + }}) + } + + if !s.AddressID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_id")...), + psql.Arg(s.AddressID), + }}) + } + + if !s.Reviewed.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reviewed")...), + psql.Arg(s.Reviewed), + }}) + } + + if !s.ReviewerID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reviewer_id")...), + psql.Arg(s.ReviewerID), + }}) + } + + return exprs +} + +// FindPublicreportNuisanceOld retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindPublicreportNuisanceOld(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportNuisanceOld, error) { + if len(cols) == 0 { + return PublicreportNuisanceOlds.Query( + sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(IDPK))), + ).One(ctx, exec) + } + + return PublicreportNuisanceOlds.Query( + sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Columns(PublicreportNuisanceOlds.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// PublicreportNuisanceOldExists checks the presence of a single record by primary key +func PublicreportNuisanceOldExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return PublicreportNuisanceOlds.Query( + sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after PublicreportNuisanceOld is retrieved from the database +func (o *PublicreportNuisanceOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = PublicreportNuisanceOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNuisanceOldSlice{o}) + case bob.QueryTypeInsert: + ctx, err = PublicreportNuisanceOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNuisanceOldSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = PublicreportNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNuisanceOldSlice{o}) + case bob.QueryTypeDelete: + ctx, err = PublicreportNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNuisanceOldSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the PublicreportNuisanceOld +func (o *PublicreportNuisanceOld) primaryKeyVals() bob.Expression { + return psql.Arg(o.ID) +} + +func (o *PublicreportNuisanceOld) pkEQ() dialect.Expression { + return psql.Quote("publicreport.nuisance_old", "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 PublicreportNuisanceOld +func (o *PublicreportNuisanceOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportNuisanceOldSetter) error { + v, err := PublicreportNuisanceOlds.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 PublicreportNuisanceOld record with an executor +func (o *PublicreportNuisanceOld) Delete(ctx context.Context, exec bob.Executor) error { + _, err := PublicreportNuisanceOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the PublicreportNuisanceOld using the executor +func (o *PublicreportNuisanceOld) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := PublicreportNuisanceOlds.Query( + sm.Where(PublicreportNuisanceOlds.Columns.ID.EQ(psql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after PublicreportNuisanceOldSlice is retrieved from the database +func (o PublicreportNuisanceOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = PublicreportNuisanceOlds.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = PublicreportNuisanceOlds.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = PublicreportNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = PublicreportNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o PublicreportNuisanceOldSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return psql.Raw("NULL") + } + + return psql.Quote("publicreport.nuisance_old", "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 PublicreportNuisanceOldSlice) copyMatchingRows(from ...*PublicreportNuisanceOld) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o PublicreportNuisanceOldSlice) 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 PublicreportNuisanceOlds.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 *PublicreportNuisanceOld: + o.copyMatchingRows(retrieved) + case []*PublicreportNuisanceOld: + o.copyMatchingRows(retrieved...) + case PublicreportNuisanceOldSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a PublicreportNuisanceOld or a slice of PublicreportNuisanceOld + // then run the AfterUpdateHooks on the slice + _, err = PublicreportNuisanceOlds.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o PublicreportNuisanceOldSlice) 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 PublicreportNuisanceOlds.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 *PublicreportNuisanceOld: + o.copyMatchingRows(retrieved) + case []*PublicreportNuisanceOld: + o.copyMatchingRows(retrieved...) + case PublicreportNuisanceOldSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a PublicreportNuisanceOld or a slice of PublicreportNuisanceOld + // then run the AfterDeleteHooks on the slice + _, err = PublicreportNuisanceOlds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o PublicreportNuisanceOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNuisanceOldSetter) error { + if len(o) == 0 { + return nil + } + + _, err := PublicreportNuisanceOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) + return err +} + +func (o PublicreportNuisanceOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := PublicreportNuisanceOlds.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o PublicreportNuisanceOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := PublicreportNuisanceOlds.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// NuisanceNotifyEmailNuisanceOlds starts a query for related objects on publicreport.notify_email_nuisance_old +func (o *PublicreportNuisanceOld) NuisanceNotifyEmailNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisanceOldsQuery { + return PublicreportNotifyEmailNuisanceOlds.Query(append(mods, + sm.Where(PublicreportNotifyEmailNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportNuisanceOldSlice) NuisanceNotifyEmailNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailNuisanceOldsQuery { + 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 PublicreportNotifyEmailNuisanceOlds.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyEmailNuisanceOlds.Columns.NuisanceID).OP("IN", PKArgExpr)), + )...) +} + +// NuisanceNotifyPhoneNuisanceOlds starts a query for related objects on publicreport.notify_phone_nuisance_old +func (o *PublicreportNuisanceOld) NuisanceNotifyPhoneNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisanceOldsQuery { + return PublicreportNotifyPhoneNuisanceOlds.Query(append(mods, + sm.Where(PublicreportNotifyPhoneNuisanceOlds.Columns.NuisanceID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportNuisanceOldSlice) NuisanceNotifyPhoneNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneNuisanceOldsQuery { + 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 PublicreportNotifyPhoneNuisanceOlds.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyPhoneNuisanceOlds.Columns.NuisanceID).OP("IN", PKArgExpr)), + )...) +} + +// Images starts a query for related objects on publicreport.image +func (o *PublicreportNuisanceOld) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { + return PublicreportImages.Query(append(mods, + sm.InnerJoin(PublicreportNuisanceImageOlds.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportNuisanceImageOlds.Columns.ImageID)), + sm.Where(PublicreportNuisanceImageOlds.Columns.NuisanceID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportNuisanceOldSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { + 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 PublicreportImages.Query(append(mods, + sm.InnerJoin(PublicreportNuisanceImageOlds.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportNuisanceImageOlds.Columns.ImageID), + ), + sm.Where(psql.Group(PublicreportNuisanceImageOlds.Columns.NuisanceID).OP("IN", PKArgExpr)), + )...) +} + +// Address starts a query for related objects on address +func (o *PublicreportNuisanceOld) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { + return Addresses.Query(append(mods, + sm.Where(Addresses.Columns.ID.EQ(psql.Arg(o.AddressID))), + )...) +} + +func (os PublicreportNuisanceOldSlice) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { + pkAddressID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkAddressID = append(pkAddressID, o.AddressID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkAddressID), "integer[]")), + )) + + return Addresses.Query(append(mods, + sm.Where(psql.Group(Addresses.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// Organization starts a query for related objects on organization +func (o *PublicreportNuisanceOld) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + return Organizations.Query(append(mods, + sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), + )...) +} + +func (os PublicreportNuisanceOldSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkOrganizationID = append(pkOrganizationID, o.OrganizationID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), + )) + + return Organizations.Query(append(mods, + sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ReviewerUser starts a query for related objects on user_ +func (o *PublicreportNuisanceOld) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + return Users.Query(append(mods, + sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))), + )...) +} + +func (os PublicreportNuisanceOldSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkReviewerID = append(pkReviewerID, o.ReviewerID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")), + )) + + return Users.Query(append(mods, + sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func insertPublicreportNuisanceOldNuisanceNotifyEmailNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailNuisanceOlds1 []*PublicreportNotifyEmailNuisanceOldSetter, publicreportNuisanceOld0 *PublicreportNuisanceOld) (PublicreportNotifyEmailNuisanceOldSlice, error) { + for i := range publicreportNotifyEmailNuisanceOlds1 { + publicreportNotifyEmailNuisanceOlds1[i].NuisanceID = omit.From(publicreportNuisanceOld0.ID) + } + + ret, err := PublicreportNotifyEmailNuisanceOlds.Insert(bob.ToMods(publicreportNotifyEmailNuisanceOlds1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportNuisanceOldNuisanceNotifyEmailNuisanceOlds0: %w", err) + } + + return ret, nil +} + +func attachPublicreportNuisanceOldNuisanceNotifyEmailNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailNuisanceOlds1 PublicreportNotifyEmailNuisanceOldSlice, publicreportNuisanceOld0 *PublicreportNuisanceOld) (PublicreportNotifyEmailNuisanceOldSlice, error) { + setter := &PublicreportNotifyEmailNuisanceOldSetter{ + NuisanceID: omit.From(publicreportNuisanceOld0.ID), + } + + err := publicreportNotifyEmailNuisanceOlds1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceOldNuisanceNotifyEmailNuisanceOlds0: %w", err) + } + + return publicreportNotifyEmailNuisanceOlds1, nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) InsertNuisanceNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceOldSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNotifyEmailNuisanceOlds1, err := insertPublicreportNuisanceOldNuisanceNotifyEmailNuisanceOlds0(ctx, exec, related, publicreportNuisanceOld0) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.NuisanceNotifyEmailNuisanceOlds = append(publicreportNuisanceOld0.R.NuisanceNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOlds1...) + + for _, rel := range publicreportNotifyEmailNuisanceOlds1 { + rel.R.NuisanceNuisanceOld = publicreportNuisanceOld0 + } + return nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) AttachNuisanceNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailNuisanceOld) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNotifyEmailNuisanceOlds1 := PublicreportNotifyEmailNuisanceOldSlice(related) + + _, err = attachPublicreportNuisanceOldNuisanceNotifyEmailNuisanceOlds0(ctx, exec, len(related), publicreportNotifyEmailNuisanceOlds1, publicreportNuisanceOld0) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.NuisanceNotifyEmailNuisanceOlds = append(publicreportNuisanceOld0.R.NuisanceNotifyEmailNuisanceOlds, publicreportNotifyEmailNuisanceOlds1...) + + for _, rel := range related { + rel.R.NuisanceNuisanceOld = publicreportNuisanceOld0 + } + + return nil +} + +func insertPublicreportNuisanceOldNuisanceNotifyPhoneNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneNuisanceOlds1 []*PublicreportNotifyPhoneNuisanceOldSetter, publicreportNuisanceOld0 *PublicreportNuisanceOld) (PublicreportNotifyPhoneNuisanceOldSlice, error) { + for i := range publicreportNotifyPhoneNuisanceOlds1 { + publicreportNotifyPhoneNuisanceOlds1[i].NuisanceID = omit.From(publicreportNuisanceOld0.ID) + } + + ret, err := PublicreportNotifyPhoneNuisanceOlds.Insert(bob.ToMods(publicreportNotifyPhoneNuisanceOlds1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportNuisanceOldNuisanceNotifyPhoneNuisanceOlds0: %w", err) + } + + return ret, nil +} + +func attachPublicreportNuisanceOldNuisanceNotifyPhoneNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneNuisanceOlds1 PublicreportNotifyPhoneNuisanceOldSlice, publicreportNuisanceOld0 *PublicreportNuisanceOld) (PublicreportNotifyPhoneNuisanceOldSlice, error) { + setter := &PublicreportNotifyPhoneNuisanceOldSetter{ + NuisanceID: omit.From(publicreportNuisanceOld0.ID), + } + + err := publicreportNotifyPhoneNuisanceOlds1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceOldNuisanceNotifyPhoneNuisanceOlds0: %w", err) + } + + return publicreportNotifyPhoneNuisanceOlds1, nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) InsertNuisanceNotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceOldSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNotifyPhoneNuisanceOlds1, err := insertPublicreportNuisanceOldNuisanceNotifyPhoneNuisanceOlds0(ctx, exec, related, publicreportNuisanceOld0) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.NuisanceNotifyPhoneNuisanceOlds = append(publicreportNuisanceOld0.R.NuisanceNotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOlds1...) + + for _, rel := range publicreportNotifyPhoneNuisanceOlds1 { + rel.R.NuisanceNuisanceOld = publicreportNuisanceOld0 + } + return nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) AttachNuisanceNotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneNuisanceOld) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNotifyPhoneNuisanceOlds1 := PublicreportNotifyPhoneNuisanceOldSlice(related) + + _, err = attachPublicreportNuisanceOldNuisanceNotifyPhoneNuisanceOlds0(ctx, exec, len(related), publicreportNotifyPhoneNuisanceOlds1, publicreportNuisanceOld0) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.NuisanceNotifyPhoneNuisanceOlds = append(publicreportNuisanceOld0.R.NuisanceNotifyPhoneNuisanceOlds, publicreportNotifyPhoneNuisanceOlds1...) + + for _, rel := range related { + rel.R.NuisanceNuisanceOld = publicreportNuisanceOld0 + } + + return nil +} + +func attachPublicreportNuisanceOldImages0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOld0 *PublicreportNuisanceOld, publicreportImages2 PublicreportImageSlice) (PublicreportNuisanceImageOldSlice, error) { + setters := make([]*PublicreportNuisanceImageOldSetter, count) + for i := range count { + setters[i] = &PublicreportNuisanceImageOldSetter{ + NuisanceID: omit.From(publicreportNuisanceOld0.ID), + ImageID: omit.From(publicreportImages2[i].ID), + } + } + + publicreportNuisanceImageOlds1, err := PublicreportNuisanceImageOlds.Insert(bob.ToMods(setters...)).All(ctx, exec) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceOldImages0: %w", err) + } + + return publicreportNuisanceImageOlds1, nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + publicreportImages2 := PublicreportImageSlice(inserted) + + _, err = attachPublicreportNuisanceOldImages0(ctx, exec, len(related), publicreportNuisanceOld0, publicreportImages2) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.Images = append(publicreportNuisanceOld0.R.Images, publicreportImages2...) + + for _, rel := range publicreportImages2 { + rel.R.NuisanceOlds = append(rel.R.NuisanceOlds, publicreportNuisanceOld0) + } + return nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportImages2 := PublicreportImageSlice(related) + + _, err = attachPublicreportNuisanceOldImages0(ctx, exec, len(related), publicreportNuisanceOld0, publicreportImages2) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.Images = append(publicreportNuisanceOld0.R.Images, publicreportImages2...) + + for _, rel := range related { + rel.R.NuisanceOlds = append(rel.R.NuisanceOlds, publicreportNuisanceOld0) + } + + return nil +} + +func attachPublicreportNuisanceOldAddress0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOld0 *PublicreportNuisanceOld, address1 *Address) (*PublicreportNuisanceOld, error) { + setter := &PublicreportNuisanceOldSetter{ + AddressID: omitnull.From(address1.ID), + } + + err := publicreportNuisanceOld0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceOldAddress0: %w", err) + } + + return publicreportNuisanceOld0, nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) InsertAddress(ctx context.Context, exec bob.Executor, related *AddressSetter) error { + var err error + + address1, err := Addresses.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachPublicreportNuisanceOldAddress0(ctx, exec, 1, publicreportNuisanceOld0, address1) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.Address = address1 + + address1.R.NuisanceOlds = append(address1.R.NuisanceOlds, publicreportNuisanceOld0) + + return nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { + var err error + + _, err = attachPublicreportNuisanceOldAddress0(ctx, exec, 1, publicreportNuisanceOld0, address1) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.Address = address1 + + address1.R.NuisanceOlds = append(address1.R.NuisanceOlds, publicreportNuisanceOld0) + + return nil +} + +func attachPublicreportNuisanceOldOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOld0 *PublicreportNuisanceOld, organization1 *Organization) (*PublicreportNuisanceOld, error) { + setter := &PublicreportNuisanceOldSetter{ + OrganizationID: omit.From(organization1.ID), + } + + err := publicreportNuisanceOld0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceOldOrganization0: %w", err) + } + + return publicreportNuisanceOld0, nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { + var err error + + organization1, err := Organizations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachPublicreportNuisanceOldOrganization0(ctx, exec, 1, publicreportNuisanceOld0, organization1) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.Organization = organization1 + + organization1.R.NuisanceOlds = append(organization1.R.NuisanceOlds, publicreportNuisanceOld0) + + return nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { + var err error + + _, err = attachPublicreportNuisanceOldOrganization0(ctx, exec, 1, publicreportNuisanceOld0, organization1) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.Organization = organization1 + + organization1.R.NuisanceOlds = append(organization1.R.NuisanceOlds, publicreportNuisanceOld0) + + return nil +} + +func attachPublicreportNuisanceOldReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOld0 *PublicreportNuisanceOld, user1 *User) (*PublicreportNuisanceOld, error) { + setter := &PublicreportNuisanceOldSetter{ + ReviewerID: omitnull.From(user1.ID), + } + + err := publicreportNuisanceOld0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceOldReviewerUser0: %w", err) + } + + return publicreportNuisanceOld0, nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) InsertReviewerUser(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 = attachPublicreportNuisanceOldReviewerUser0(ctx, exec, 1, publicreportNuisanceOld0, user1) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.ReviewerUser = user1 + + user1.R.ReviewerNuisanceOlds = append(user1.R.ReviewerNuisanceOlds, publicreportNuisanceOld0) + + return nil +} + +func (publicreportNuisanceOld0 *PublicreportNuisanceOld) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error { + var err error + + _, err = attachPublicreportNuisanceOldReviewerUser0(ctx, exec, 1, publicreportNuisanceOld0, user1) + if err != nil { + return err + } + + publicreportNuisanceOld0.R.ReviewerUser = user1 + + user1.R.ReviewerNuisanceOlds = append(user1.R.ReviewerNuisanceOlds, publicreportNuisanceOld0) + + return nil +} + +type publicreportNuisanceOldWhere[Q psql.Filterable] struct { + ID psql.WhereMod[Q, int32] + AdditionalInfo psql.WhereMod[Q, string] + Created psql.WhereMod[Q, time.Time] + Duration psql.WhereMod[Q, enums.PublicreportNuisancedurationtype] + SourceContainer psql.WhereMod[Q, bool] + SourceDescription psql.WhereMod[Q, string] + SourceStagnant psql.WhereMod[Q, bool] + PublicID psql.WhereMod[Q, string] + ReporterEmail psql.WhereNullMod[Q, string] + ReporterName psql.WhereNullMod[Q, string] + ReporterPhone psql.WhereNullMod[Q, string] + AddressRaw psql.WhereMod[Q, string] + Status psql.WhereMod[Q, enums.PublicreportReportstatustype] + OrganizationID psql.WhereMod[Q, int32] + SourceGutter psql.WhereMod[Q, bool] + H3cell psql.WhereNullMod[Q, string] + AddressCountry psql.WhereMod[Q, string] + AddressLocality psql.WhereMod[Q, string] + AddressPostalCode psql.WhereMod[Q, string] + AddressRegion psql.WhereMod[Q, string] + AddressStreet psql.WhereMod[Q, string] + IsLocationBackyard psql.WhereMod[Q, bool] + IsLocationFrontyard psql.WhereMod[Q, bool] + IsLocationGarden psql.WhereMod[Q, bool] + IsLocationOther psql.WhereMod[Q, bool] + IsLocationPool psql.WhereMod[Q, bool] + MapZoom psql.WhereMod[Q, float32] + TodEarly psql.WhereMod[Q, bool] + TodDay psql.WhereMod[Q, bool] + TodEvening psql.WhereMod[Q, bool] + TodNight psql.WhereMod[Q, bool] + LatlngAccuracyType psql.WhereMod[Q, enums.PublicreportAccuracytype] + LatlngAccuracyValue psql.WhereMod[Q, float32] + ReporterContactConsent psql.WhereNullMod[Q, bool] + Location psql.WhereNullMod[Q, string] + AddressNumber psql.WhereMod[Q, string] + AddressID psql.WhereNullMod[Q, int32] + Reviewed psql.WhereNullMod[Q, time.Time] + ReviewerID psql.WhereNullMod[Q, int32] +} + +func (publicreportNuisanceOldWhere[Q]) AliasedAs(alias string) publicreportNuisanceOldWhere[Q] { + return buildPublicreportNuisanceOldWhere[Q](buildPublicreportNuisanceOldColumns(alias)) +} + +func buildPublicreportNuisanceOldWhere[Q psql.Filterable](cols publicreportNuisanceOldColumns) publicreportNuisanceOldWhere[Q] { + return publicreportNuisanceOldWhere[Q]{ + ID: psql.Where[Q, int32](cols.ID), + AdditionalInfo: psql.Where[Q, string](cols.AdditionalInfo), + Created: psql.Where[Q, time.Time](cols.Created), + Duration: psql.Where[Q, enums.PublicreportNuisancedurationtype](cols.Duration), + SourceContainer: psql.Where[Q, bool](cols.SourceContainer), + SourceDescription: psql.Where[Q, string](cols.SourceDescription), + SourceStagnant: psql.Where[Q, bool](cols.SourceStagnant), + PublicID: psql.Where[Q, string](cols.PublicID), + ReporterEmail: psql.WhereNull[Q, string](cols.ReporterEmail), + ReporterName: psql.WhereNull[Q, string](cols.ReporterName), + ReporterPhone: psql.WhereNull[Q, string](cols.ReporterPhone), + AddressRaw: psql.Where[Q, string](cols.AddressRaw), + Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status), + OrganizationID: psql.Where[Q, int32](cols.OrganizationID), + SourceGutter: psql.Where[Q, bool](cols.SourceGutter), + H3cell: psql.WhereNull[Q, string](cols.H3cell), + AddressCountry: psql.Where[Q, string](cols.AddressCountry), + AddressLocality: psql.Where[Q, string](cols.AddressLocality), + AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), + AddressRegion: psql.Where[Q, string](cols.AddressRegion), + AddressStreet: psql.Where[Q, string](cols.AddressStreet), + IsLocationBackyard: psql.Where[Q, bool](cols.IsLocationBackyard), + IsLocationFrontyard: psql.Where[Q, bool](cols.IsLocationFrontyard), + IsLocationGarden: psql.Where[Q, bool](cols.IsLocationGarden), + IsLocationOther: psql.Where[Q, bool](cols.IsLocationOther), + IsLocationPool: psql.Where[Q, bool](cols.IsLocationPool), + MapZoom: psql.Where[Q, float32](cols.MapZoom), + TodEarly: psql.Where[Q, bool](cols.TodEarly), + TodDay: psql.Where[Q, bool](cols.TodDay), + TodEvening: psql.Where[Q, bool](cols.TodEvening), + TodNight: psql.Where[Q, bool](cols.TodNight), + LatlngAccuracyType: psql.Where[Q, enums.PublicreportAccuracytype](cols.LatlngAccuracyType), + LatlngAccuracyValue: psql.Where[Q, float32](cols.LatlngAccuracyValue), + ReporterContactConsent: psql.WhereNull[Q, bool](cols.ReporterContactConsent), + Location: psql.WhereNull[Q, string](cols.Location), + AddressNumber: psql.Where[Q, string](cols.AddressNumber), + AddressID: psql.WhereNull[Q, int32](cols.AddressID), + Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed), + ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID), + } +} + +func (o *PublicreportNuisanceOld) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "NuisanceNotifyEmailNuisanceOlds": + rels, ok := retrieved.(PublicreportNotifyEmailNuisanceOldSlice) + if !ok { + return fmt.Errorf("publicreportNuisanceOld cannot load %T as %q", retrieved, name) + } + + o.R.NuisanceNotifyEmailNuisanceOlds = rels + + for _, rel := range rels { + if rel != nil { + rel.R.NuisanceNuisanceOld = o + } + } + return nil + case "NuisanceNotifyPhoneNuisanceOlds": + rels, ok := retrieved.(PublicreportNotifyPhoneNuisanceOldSlice) + if !ok { + return fmt.Errorf("publicreportNuisanceOld cannot load %T as %q", retrieved, name) + } + + o.R.NuisanceNotifyPhoneNuisanceOlds = rels + + for _, rel := range rels { + if rel != nil { + rel.R.NuisanceNuisanceOld = o + } + } + return nil + case "Images": + rels, ok := retrieved.(PublicreportImageSlice) + if !ok { + return fmt.Errorf("publicreportNuisanceOld cannot load %T as %q", retrieved, name) + } + + o.R.Images = rels + + for _, rel := range rels { + if rel != nil { + rel.R.NuisanceOlds = PublicreportNuisanceOldSlice{o} + } + } + return nil + case "Address": + rel, ok := retrieved.(*Address) + if !ok { + return fmt.Errorf("publicreportNuisanceOld cannot load %T as %q", retrieved, name) + } + + o.R.Address = rel + + if rel != nil { + rel.R.NuisanceOlds = PublicreportNuisanceOldSlice{o} + } + return nil + case "Organization": + rel, ok := retrieved.(*Organization) + if !ok { + return fmt.Errorf("publicreportNuisanceOld cannot load %T as %q", retrieved, name) + } + + o.R.Organization = rel + + if rel != nil { + rel.R.NuisanceOlds = PublicreportNuisanceOldSlice{o} + } + return nil + case "ReviewerUser": + rel, ok := retrieved.(*User) + if !ok { + return fmt.Errorf("publicreportNuisanceOld cannot load %T as %q", retrieved, name) + } + + o.R.ReviewerUser = rel + + if rel != nil { + rel.R.ReviewerNuisanceOlds = PublicreportNuisanceOldSlice{o} + } + return nil + default: + return fmt.Errorf("publicreportNuisanceOld has no relationship %q", name) + } +} + +type publicreportNuisanceOldPreloader struct { + Address func(...psql.PreloadOption) psql.Preloader + Organization func(...psql.PreloadOption) psql.Preloader + ReviewerUser func(...psql.PreloadOption) psql.Preloader +} + +func buildPublicreportNuisanceOldPreloader() publicreportNuisanceOldPreloader { + return publicreportNuisanceOldPreloader{ + Address: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Address, AddressSlice](psql.PreloadRel{ + Name: "Address", + Sides: []psql.PreloadSide{ + { + From: PublicreportNuisanceOlds, + To: Addresses, + FromColumns: []string{"address_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Addresses.Columns.Names(), opts...) + }, + Organization: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ + Name: "Organization", + Sides: []psql.PreloadSide{ + { + From: PublicreportNuisanceOlds, + To: Organizations, + FromColumns: []string{"organization_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Organizations.Columns.Names(), opts...) + }, + ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*User, UserSlice](psql.PreloadRel{ + Name: "ReviewerUser", + Sides: []psql.PreloadSide{ + { + From: PublicreportNuisanceOlds, + To: Users, + FromColumns: []string{"reviewer_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Users.Columns.Names(), opts...) + }, + } +} + +type publicreportNuisanceOldThenLoader[Q orm.Loadable] struct { + NuisanceNotifyEmailNuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + NuisanceNotifyPhoneNuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildPublicreportNuisanceOldThenLoader[Q orm.Loadable]() publicreportNuisanceOldThenLoader[Q] { + type NuisanceNotifyEmailNuisanceOldsLoadInterface interface { + LoadNuisanceNotifyEmailNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type NuisanceNotifyPhoneNuisanceOldsLoadInterface interface { + LoadNuisanceNotifyPhoneNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ImagesLoadInterface interface { + LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type AddressLoadInterface interface { + LoadAddress(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OrganizationLoadInterface interface { + LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReviewerUserLoadInterface interface { + LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return publicreportNuisanceOldThenLoader[Q]{ + NuisanceNotifyEmailNuisanceOlds: thenLoadBuilder[Q]( + "NuisanceNotifyEmailNuisanceOlds", + func(ctx context.Context, exec bob.Executor, retrieved NuisanceNotifyEmailNuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadNuisanceNotifyEmailNuisanceOlds(ctx, exec, mods...) + }, + ), + NuisanceNotifyPhoneNuisanceOlds: thenLoadBuilder[Q]( + "NuisanceNotifyPhoneNuisanceOlds", + func(ctx context.Context, exec bob.Executor, retrieved NuisanceNotifyPhoneNuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadNuisanceNotifyPhoneNuisanceOlds(ctx, exec, mods...) + }, + ), + Images: thenLoadBuilder[Q]( + "Images", + func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadImages(ctx, exec, mods...) + }, + ), + Address: thenLoadBuilder[Q]( + "Address", + func(ctx context.Context, exec bob.Executor, retrieved AddressLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAddress(ctx, exec, mods...) + }, + ), + Organization: thenLoadBuilder[Q]( + "Organization", + func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOrganization(ctx, exec, mods...) + }, + ), + ReviewerUser: thenLoadBuilder[Q]( + "ReviewerUser", + func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReviewerUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadNuisanceNotifyEmailNuisanceOlds loads the publicreportNuisanceOld's NuisanceNotifyEmailNuisanceOlds into the .R struct +func (o *PublicreportNuisanceOld) LoadNuisanceNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.NuisanceNotifyEmailNuisanceOlds = nil + + related, err := o.NuisanceNotifyEmailNuisanceOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.NuisanceNuisanceOld = o + } + + o.R.NuisanceNotifyEmailNuisanceOlds = related + return nil +} + +// LoadNuisanceNotifyEmailNuisanceOlds loads the publicreportNuisanceOld's NuisanceNotifyEmailNuisanceOlds into the .R struct +func (os PublicreportNuisanceOldSlice) LoadNuisanceNotifyEmailNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportNotifyEmailNuisanceOlds, err := os.NuisanceNotifyEmailNuisanceOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.NuisanceNotifyEmailNuisanceOlds = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNotifyEmailNuisanceOlds { + + if !(o.ID == rel.NuisanceID) { + continue + } + + rel.R.NuisanceNuisanceOld = o + + o.R.NuisanceNotifyEmailNuisanceOlds = append(o.R.NuisanceNotifyEmailNuisanceOlds, rel) + } + } + + return nil +} + +// LoadNuisanceNotifyPhoneNuisanceOlds loads the publicreportNuisanceOld's NuisanceNotifyPhoneNuisanceOlds into the .R struct +func (o *PublicreportNuisanceOld) LoadNuisanceNotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.NuisanceNotifyPhoneNuisanceOlds = nil + + related, err := o.NuisanceNotifyPhoneNuisanceOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.NuisanceNuisanceOld = o + } + + o.R.NuisanceNotifyPhoneNuisanceOlds = related + return nil +} + +// LoadNuisanceNotifyPhoneNuisanceOlds loads the publicreportNuisanceOld's NuisanceNotifyPhoneNuisanceOlds into the .R struct +func (os PublicreportNuisanceOldSlice) LoadNuisanceNotifyPhoneNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportNotifyPhoneNuisanceOlds, err := os.NuisanceNotifyPhoneNuisanceOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.NuisanceNotifyPhoneNuisanceOlds = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNotifyPhoneNuisanceOlds { + + if !(o.ID == rel.NuisanceID) { + continue + } + + rel.R.NuisanceNuisanceOld = o + + o.R.NuisanceNotifyPhoneNuisanceOlds = append(o.R.NuisanceNotifyPhoneNuisanceOlds, rel) + } + } + + return nil +} + +// LoadImages loads the publicreportNuisanceOld's Images into the .R struct +func (o *PublicreportNuisanceOld) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Images = nil + + related, err := o.Images(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.NuisanceOlds = PublicreportNuisanceOldSlice{o} + } + + o.R.Images = related + return nil +} + +// LoadImages loads the publicreportNuisanceOld's Images into the .R struct +func (os PublicreportNuisanceOldSlice) LoadImages(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(PublicreportImages.Columns)) + } + + q := os.Images(append( + mods, + sm.Columns(PublicreportNuisanceImageOlds.Columns.NuisanceID.As("related_publicreport.nuisance_old.ID")), + )...) + + IDSlice := []int32{} + + mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), 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.nuisance_old.ID", &IDSlice[len(IDSlice)-1]) + + return nil, nil + }, + func(any, any) error { + return nil + } + }) + + publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper) + if err != nil { + return err + } + + for _, o := range os { + o.R.Images = nil + } + + for _, o := range os { + for i, rel := range publicreportImages { + if !(o.ID == IDSlice[i]) { + continue + } + + rel.R.NuisanceOlds = append(rel.R.NuisanceOlds, o) + + o.R.Images = append(o.R.Images, rel) + } + } + + return nil +} + +// LoadAddress loads the publicreportNuisanceOld's Address into the .R struct +func (o *PublicreportNuisanceOld) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Address = nil + + related, err := o.Address(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.NuisanceOlds = PublicreportNuisanceOldSlice{o} + + o.R.Address = related + return nil +} + +// LoadAddress loads the publicreportNuisanceOld's Address into the .R struct +func (os PublicreportNuisanceOldSlice) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + addresses, err := os.Address(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range addresses { + if !o.AddressID.IsValue() { + continue + } + + if !(o.AddressID.IsValue() && o.AddressID.MustGet() == rel.ID) { + continue + } + + rel.R.NuisanceOlds = append(rel.R.NuisanceOlds, o) + + o.R.Address = rel + break + } + } + + return nil +} + +// LoadOrganization loads the publicreportNuisanceOld's Organization into the .R struct +func (o *PublicreportNuisanceOld) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Organization = nil + + related, err := o.Organization(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.NuisanceOlds = PublicreportNuisanceOldSlice{o} + + o.R.Organization = related + return nil +} + +// LoadOrganization loads the publicreportNuisanceOld's Organization into the .R struct +func (os PublicreportNuisanceOldSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + organizations, err := os.Organization(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range organizations { + + if !(o.OrganizationID == rel.ID) { + continue + } + + rel.R.NuisanceOlds = append(rel.R.NuisanceOlds, o) + + o.R.Organization = rel + break + } + } + + return nil +} + +// LoadReviewerUser loads the publicreportNuisanceOld's ReviewerUser into the .R struct +func (o *PublicreportNuisanceOld) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReviewerUser = nil + + related, err := o.ReviewerUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ReviewerNuisanceOlds = PublicreportNuisanceOldSlice{o} + + o.R.ReviewerUser = related + return nil +} + +// LoadReviewerUser loads the publicreportNuisanceOld's ReviewerUser into the .R struct +func (os PublicreportNuisanceOldSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + users, err := os.ReviewerUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range users { + if !o.ReviewerID.IsValue() { + continue + } + + if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) { + continue + } + + rel.R.ReviewerNuisanceOlds = append(rel.R.ReviewerNuisanceOlds, o) + + o.R.ReviewerUser = rel + break + } + } + + return nil +} diff --git a/db/models/publicreport.report.bob.go b/db/models/publicreport.report.bob.go new file mode 100644 index 00000000..c7392260 --- /dev/null +++ b/db/models/publicreport.report.bob.go @@ -0,0 +1,2729 @@ +// 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" + enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/scan" +) + +// PublicreportReport is an object representing the database table. +type PublicreportReport struct { + AddressRaw string `db:"address_raw" ` + AddressNumber string `db:"address_number" ` + AddressStreet string `db:"address_street" ` + AddressLocality string `db:"address_locality" ` + AddressRegion string `db:"address_region" ` + AddressPostalCode string `db:"address_postal_code" ` + AddressCountry string `db:"address_country" ` + AddressID null.Val[int32] `db:"address_id" ` + Created time.Time `db:"created" ` + Location null.Val[string] `db:"location" ` + H3cell null.Val[string] `db:"h3cell" ` + ID int32 `db:"id,pk" ` + LatlngAccuracyType enums.PublicreportAccuracytype `db:"latlng_accuracy_type" ` + LatlngAccuracyValue float32 `db:"latlng_accuracy_value" ` + MapZoom float32 `db:"map_zoom" ` + OrganizationID int32 `db:"organization_id" ` + PublicID string `db:"public_id" ` + ReporterName string `db:"reporter_name" ` + ReporterEmail string `db:"reporter_email" ` + ReporterPhone string `db:"reporter_phone" ` + ReporterContactConsent null.Val[bool] `db:"reporter_contact_consent" ` + ReportType string `db:"report_type" ` + Reviewed null.Val[time.Time] `db:"reviewed" ` + ReviewerID null.Val[int32] `db:"reviewer_id" ` + Status enums.PublicreportReportstatustype `db:"status" ` + + R publicreportReportR `db:"-" ` +} + +// PublicreportReportSlice is an alias for a slice of pointers to PublicreportReport. +// This should almost always be used instead of []*PublicreportReport. +type PublicreportReportSlice []*PublicreportReport + +// PublicreportReports contains methods to work with the report table +var PublicreportReports = psql.NewTablex[*PublicreportReport, PublicreportReportSlice, *PublicreportReportSetter]("publicreport", "report", buildPublicreportReportColumns("publicreport.report")) + +// PublicreportReportsQuery is a query on the report table +type PublicreportReportsQuery = *psql.ViewQuery[*PublicreportReport, PublicreportReportSlice] + +// publicreportReportR is where relationships are stored. +type publicreportReportR struct { + TextJobs CommsTextJobSlice // comms.text_job.text_job_report_id_fkey + NotifyEmails PublicreportNotifyEmailSlice // publicreport.notify_email.notify_email_report_id_fkey + NotifyPhones PublicreportNotifyPhoneSlice // publicreport.notify_phone.notify_phone_report_id_fkey + Nuisance *PublicreportNuisance // publicreport.nuisance.nuisance_report_id_fkey + Address *Address // publicreport.report.report_address_id_fkey + Organization *Organization // publicreport.report.report_organization_id_fkey + ReviewerUser *User // publicreport.report.report_reviewer_id_fkey + Images PublicreportImageSlice // publicreport.report_image.report_image_image_id_fkeypublicreport.report_image.report_image_report_id_fkey + Water *PublicreportWater // publicreport.water.water_report_id_fkey + ReportTexts ReportTextSlice // report_text.report_text_report_id_fkey +} + +func buildPublicreportReportColumns(alias string) publicreportReportColumns { + return publicreportReportColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "address_raw", "address_number", "address_street", "address_locality", "address_region", "address_postal_code", "address_country", "address_id", "created", "location", "h3cell", "id", "latlng_accuracy_type", "latlng_accuracy_value", "map_zoom", "organization_id", "public_id", "reporter_name", "reporter_email", "reporter_phone", "reporter_contact_consent", "report_type", "reviewed", "reviewer_id", "status", + ).WithParent("publicreport.report"), + tableAlias: alias, + AddressRaw: psql.Quote(alias, "address_raw"), + AddressNumber: psql.Quote(alias, "address_number"), + AddressStreet: psql.Quote(alias, "address_street"), + AddressLocality: psql.Quote(alias, "address_locality"), + AddressRegion: psql.Quote(alias, "address_region"), + AddressPostalCode: psql.Quote(alias, "address_postal_code"), + AddressCountry: psql.Quote(alias, "address_country"), + AddressID: psql.Quote(alias, "address_id"), + Created: psql.Quote(alias, "created"), + Location: psql.Quote(alias, "location"), + H3cell: psql.Quote(alias, "h3cell"), + ID: psql.Quote(alias, "id"), + LatlngAccuracyType: psql.Quote(alias, "latlng_accuracy_type"), + LatlngAccuracyValue: psql.Quote(alias, "latlng_accuracy_value"), + MapZoom: psql.Quote(alias, "map_zoom"), + OrganizationID: psql.Quote(alias, "organization_id"), + PublicID: psql.Quote(alias, "public_id"), + ReporterName: psql.Quote(alias, "reporter_name"), + ReporterEmail: psql.Quote(alias, "reporter_email"), + ReporterPhone: psql.Quote(alias, "reporter_phone"), + ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), + ReportType: psql.Quote(alias, "report_type"), + Reviewed: psql.Quote(alias, "reviewed"), + ReviewerID: psql.Quote(alias, "reviewer_id"), + Status: psql.Quote(alias, "status"), + } +} + +type publicreportReportColumns struct { + expr.ColumnsExpr + tableAlias string + AddressRaw psql.Expression + AddressNumber psql.Expression + AddressStreet psql.Expression + AddressLocality psql.Expression + AddressRegion psql.Expression + AddressPostalCode psql.Expression + AddressCountry psql.Expression + AddressID psql.Expression + Created psql.Expression + Location psql.Expression + H3cell psql.Expression + ID psql.Expression + LatlngAccuracyType psql.Expression + LatlngAccuracyValue psql.Expression + MapZoom psql.Expression + OrganizationID psql.Expression + PublicID psql.Expression + ReporterName psql.Expression + ReporterEmail psql.Expression + ReporterPhone psql.Expression + ReporterContactConsent psql.Expression + ReportType psql.Expression + Reviewed psql.Expression + ReviewerID psql.Expression + Status psql.Expression +} + +func (c publicreportReportColumns) Alias() string { + return c.tableAlias +} + +func (publicreportReportColumns) AliasedAs(alias string) publicreportReportColumns { + return buildPublicreportReportColumns(alias) +} + +// PublicreportReportSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type PublicreportReportSetter struct { + AddressRaw omit.Val[string] `db:"address_raw" ` + AddressNumber omit.Val[string] `db:"address_number" ` + AddressStreet omit.Val[string] `db:"address_street" ` + AddressLocality omit.Val[string] `db:"address_locality" ` + AddressRegion omit.Val[string] `db:"address_region" ` + AddressPostalCode omit.Val[string] `db:"address_postal_code" ` + AddressCountry omit.Val[string] `db:"address_country" ` + AddressID omitnull.Val[int32] `db:"address_id" ` + Created omit.Val[time.Time] `db:"created" ` + Location omitnull.Val[string] `db:"location" ` + H3cell omitnull.Val[string] `db:"h3cell" ` + ID omit.Val[int32] `db:"id,pk" ` + LatlngAccuracyType omit.Val[enums.PublicreportAccuracytype] `db:"latlng_accuracy_type" ` + LatlngAccuracyValue omit.Val[float32] `db:"latlng_accuracy_value" ` + MapZoom omit.Val[float32] `db:"map_zoom" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + PublicID omit.Val[string] `db:"public_id" ` + ReporterName omit.Val[string] `db:"reporter_name" ` + ReporterEmail omit.Val[string] `db:"reporter_email" ` + ReporterPhone omit.Val[string] `db:"reporter_phone" ` + ReporterContactConsent omitnull.Val[bool] `db:"reporter_contact_consent" ` + ReportType omit.Val[string] `db:"report_type" ` + Reviewed omitnull.Val[time.Time] `db:"reviewed" ` + ReviewerID omitnull.Val[int32] `db:"reviewer_id" ` + Status omit.Val[enums.PublicreportReportstatustype] `db:"status" ` +} + +func (s PublicreportReportSetter) SetColumns() []string { + vals := make([]string, 0, 25) + if s.AddressRaw.IsValue() { + vals = append(vals, "address_raw") + } + if s.AddressNumber.IsValue() { + vals = append(vals, "address_number") + } + if s.AddressStreet.IsValue() { + vals = append(vals, "address_street") + } + if s.AddressLocality.IsValue() { + vals = append(vals, "address_locality") + } + if s.AddressRegion.IsValue() { + vals = append(vals, "address_region") + } + if s.AddressPostalCode.IsValue() { + vals = append(vals, "address_postal_code") + } + if s.AddressCountry.IsValue() { + vals = append(vals, "address_country") + } + if !s.AddressID.IsUnset() { + vals = append(vals, "address_id") + } + if s.Created.IsValue() { + vals = append(vals, "created") + } + if !s.Location.IsUnset() { + vals = append(vals, "location") + } + if !s.H3cell.IsUnset() { + vals = append(vals, "h3cell") + } + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.LatlngAccuracyType.IsValue() { + vals = append(vals, "latlng_accuracy_type") + } + if s.LatlngAccuracyValue.IsValue() { + vals = append(vals, "latlng_accuracy_value") + } + if s.MapZoom.IsValue() { + vals = append(vals, "map_zoom") + } + if s.OrganizationID.IsValue() { + vals = append(vals, "organization_id") + } + if s.PublicID.IsValue() { + vals = append(vals, "public_id") + } + if s.ReporterName.IsValue() { + vals = append(vals, "reporter_name") + } + if s.ReporterEmail.IsValue() { + vals = append(vals, "reporter_email") + } + if s.ReporterPhone.IsValue() { + vals = append(vals, "reporter_phone") + } + if !s.ReporterContactConsent.IsUnset() { + vals = append(vals, "reporter_contact_consent") + } + if s.ReportType.IsValue() { + vals = append(vals, "report_type") + } + if !s.Reviewed.IsUnset() { + vals = append(vals, "reviewed") + } + if !s.ReviewerID.IsUnset() { + vals = append(vals, "reviewer_id") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + return vals +} + +func (s PublicreportReportSetter) Overwrite(t *PublicreportReport) { + if s.AddressRaw.IsValue() { + t.AddressRaw = s.AddressRaw.MustGet() + } + if s.AddressNumber.IsValue() { + t.AddressNumber = s.AddressNumber.MustGet() + } + if s.AddressStreet.IsValue() { + t.AddressStreet = s.AddressStreet.MustGet() + } + if s.AddressLocality.IsValue() { + t.AddressLocality = s.AddressLocality.MustGet() + } + if s.AddressRegion.IsValue() { + t.AddressRegion = s.AddressRegion.MustGet() + } + if s.AddressPostalCode.IsValue() { + t.AddressPostalCode = s.AddressPostalCode.MustGet() + } + if s.AddressCountry.IsValue() { + t.AddressCountry = s.AddressCountry.MustGet() + } + if !s.AddressID.IsUnset() { + t.AddressID = s.AddressID.MustGetNull() + } + if s.Created.IsValue() { + t.Created = s.Created.MustGet() + } + if !s.Location.IsUnset() { + t.Location = s.Location.MustGetNull() + } + if !s.H3cell.IsUnset() { + t.H3cell = s.H3cell.MustGetNull() + } + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.LatlngAccuracyType.IsValue() { + t.LatlngAccuracyType = s.LatlngAccuracyType.MustGet() + } + if s.LatlngAccuracyValue.IsValue() { + t.LatlngAccuracyValue = s.LatlngAccuracyValue.MustGet() + } + if s.MapZoom.IsValue() { + t.MapZoom = s.MapZoom.MustGet() + } + if s.OrganizationID.IsValue() { + t.OrganizationID = s.OrganizationID.MustGet() + } + if s.PublicID.IsValue() { + t.PublicID = s.PublicID.MustGet() + } + if s.ReporterName.IsValue() { + t.ReporterName = s.ReporterName.MustGet() + } + if s.ReporterEmail.IsValue() { + t.ReporterEmail = s.ReporterEmail.MustGet() + } + if s.ReporterPhone.IsValue() { + t.ReporterPhone = s.ReporterPhone.MustGet() + } + if !s.ReporterContactConsent.IsUnset() { + t.ReporterContactConsent = s.ReporterContactConsent.MustGetNull() + } + if s.ReportType.IsValue() { + t.ReportType = s.ReportType.MustGet() + } + if !s.Reviewed.IsUnset() { + t.Reviewed = s.Reviewed.MustGetNull() + } + if !s.ReviewerID.IsUnset() { + t.ReviewerID = s.ReviewerID.MustGetNull() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } +} + +func (s *PublicreportReportSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return PublicreportReports.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, 25) + if s.AddressRaw.IsValue() { + vals[0] = psql.Arg(s.AddressRaw.MustGet()) + } else { + vals[0] = psql.Raw("DEFAULT") + } + + if s.AddressNumber.IsValue() { + vals[1] = psql.Arg(s.AddressNumber.MustGet()) + } else { + vals[1] = psql.Raw("DEFAULT") + } + + if s.AddressStreet.IsValue() { + vals[2] = psql.Arg(s.AddressStreet.MustGet()) + } else { + vals[2] = psql.Raw("DEFAULT") + } + + if s.AddressLocality.IsValue() { + vals[3] = psql.Arg(s.AddressLocality.MustGet()) + } else { + vals[3] = psql.Raw("DEFAULT") + } + + if s.AddressRegion.IsValue() { + vals[4] = psql.Arg(s.AddressRegion.MustGet()) + } else { + vals[4] = psql.Raw("DEFAULT") + } + + if s.AddressPostalCode.IsValue() { + vals[5] = psql.Arg(s.AddressPostalCode.MustGet()) + } else { + vals[5] = psql.Raw("DEFAULT") + } + + if s.AddressCountry.IsValue() { + vals[6] = psql.Arg(s.AddressCountry.MustGet()) + } else { + vals[6] = psql.Raw("DEFAULT") + } + + if !s.AddressID.IsUnset() { + vals[7] = psql.Arg(s.AddressID.MustGetNull()) + } else { + vals[7] = psql.Raw("DEFAULT") + } + + if s.Created.IsValue() { + vals[8] = psql.Arg(s.Created.MustGet()) + } else { + vals[8] = psql.Raw("DEFAULT") + } + + if !s.Location.IsUnset() { + vals[9] = psql.Arg(s.Location.MustGetNull()) + } else { + vals[9] = psql.Raw("DEFAULT") + } + + if !s.H3cell.IsUnset() { + vals[10] = psql.Arg(s.H3cell.MustGetNull()) + } else { + vals[10] = psql.Raw("DEFAULT") + } + + if s.ID.IsValue() { + vals[11] = psql.Arg(s.ID.MustGet()) + } else { + vals[11] = psql.Raw("DEFAULT") + } + + if s.LatlngAccuracyType.IsValue() { + vals[12] = psql.Arg(s.LatlngAccuracyType.MustGet()) + } else { + vals[12] = psql.Raw("DEFAULT") + } + + if s.LatlngAccuracyValue.IsValue() { + vals[13] = psql.Arg(s.LatlngAccuracyValue.MustGet()) + } else { + vals[13] = psql.Raw("DEFAULT") + } + + if s.MapZoom.IsValue() { + vals[14] = psql.Arg(s.MapZoom.MustGet()) + } else { + vals[14] = psql.Raw("DEFAULT") + } + + if s.OrganizationID.IsValue() { + vals[15] = psql.Arg(s.OrganizationID.MustGet()) + } else { + vals[15] = psql.Raw("DEFAULT") + } + + if s.PublicID.IsValue() { + vals[16] = psql.Arg(s.PublicID.MustGet()) + } else { + vals[16] = psql.Raw("DEFAULT") + } + + if s.ReporterName.IsValue() { + vals[17] = psql.Arg(s.ReporterName.MustGet()) + } else { + vals[17] = psql.Raw("DEFAULT") + } + + if s.ReporterEmail.IsValue() { + vals[18] = psql.Arg(s.ReporterEmail.MustGet()) + } else { + vals[18] = psql.Raw("DEFAULT") + } + + if s.ReporterPhone.IsValue() { + vals[19] = psql.Arg(s.ReporterPhone.MustGet()) + } else { + vals[19] = psql.Raw("DEFAULT") + } + + if !s.ReporterContactConsent.IsUnset() { + vals[20] = psql.Arg(s.ReporterContactConsent.MustGetNull()) + } else { + vals[20] = psql.Raw("DEFAULT") + } + + if s.ReportType.IsValue() { + vals[21] = psql.Arg(s.ReportType.MustGet()) + } else { + vals[21] = psql.Raw("DEFAULT") + } + + if !s.Reviewed.IsUnset() { + vals[22] = psql.Arg(s.Reviewed.MustGetNull()) + } else { + vals[22] = psql.Raw("DEFAULT") + } + + if !s.ReviewerID.IsUnset() { + vals[23] = psql.Arg(s.ReviewerID.MustGetNull()) + } else { + vals[23] = psql.Raw("DEFAULT") + } + + if s.Status.IsValue() { + vals[24] = psql.Arg(s.Status.MustGet()) + } else { + vals[24] = psql.Raw("DEFAULT") + } + + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") + })) +} + +func (s PublicreportReportSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions()...) +} + +func (s PublicreportReportSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 25) + + if s.AddressRaw.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_raw")...), + psql.Arg(s.AddressRaw), + }}) + } + + if s.AddressNumber.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_number")...), + psql.Arg(s.AddressNumber), + }}) + } + + if s.AddressStreet.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_street")...), + psql.Arg(s.AddressStreet), + }}) + } + + if s.AddressLocality.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_locality")...), + psql.Arg(s.AddressLocality), + }}) + } + + if s.AddressRegion.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_region")...), + psql.Arg(s.AddressRegion), + }}) + } + + if s.AddressPostalCode.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_postal_code")...), + psql.Arg(s.AddressPostalCode), + }}) + } + + if s.AddressCountry.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_country")...), + psql.Arg(s.AddressCountry), + }}) + } + + if !s.AddressID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_id")...), + psql.Arg(s.AddressID), + }}) + } + + if s.Created.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + + if !s.Location.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "location")...), + psql.Arg(s.Location), + }}) + } + + if !s.H3cell.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "h3cell")...), + psql.Arg(s.H3cell), + }}) + } + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "id")...), + psql.Arg(s.ID), + }}) + } + + if s.LatlngAccuracyType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "latlng_accuracy_type")...), + psql.Arg(s.LatlngAccuracyType), + }}) + } + + if s.LatlngAccuracyValue.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "latlng_accuracy_value")...), + psql.Arg(s.LatlngAccuracyValue), + }}) + } + + if s.MapZoom.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "map_zoom")...), + psql.Arg(s.MapZoom), + }}) + } + + if s.OrganizationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "organization_id")...), + psql.Arg(s.OrganizationID), + }}) + } + + if s.PublicID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "public_id")...), + psql.Arg(s.PublicID), + }}) + } + + if s.ReporterName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_name")...), + psql.Arg(s.ReporterName), + }}) + } + + if s.ReporterEmail.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_email")...), + psql.Arg(s.ReporterEmail), + }}) + } + + if s.ReporterPhone.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_phone")...), + psql.Arg(s.ReporterPhone), + }}) + } + + if !s.ReporterContactConsent.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_contact_consent")...), + psql.Arg(s.ReporterContactConsent), + }}) + } + + if s.ReportType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "report_type")...), + psql.Arg(s.ReportType), + }}) + } + + if !s.Reviewed.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reviewed")...), + psql.Arg(s.Reviewed), + }}) + } + + if !s.ReviewerID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reviewer_id")...), + psql.Arg(s.ReviewerID), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "status")...), + psql.Arg(s.Status), + }}) + } + + return exprs +} + +// FindPublicreportReport retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindPublicreportReport(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportReport, error) { + if len(cols) == 0 { + return PublicreportReports.Query( + sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(IDPK))), + ).One(ctx, exec) + } + + return PublicreportReports.Query( + sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Columns(PublicreportReports.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// PublicreportReportExists checks the presence of a single record by primary key +func PublicreportReportExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return PublicreportReports.Query( + sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after PublicreportReport is retrieved from the database +func (o *PublicreportReport) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = PublicreportReports.AfterSelectHooks.RunHooks(ctx, exec, PublicreportReportSlice{o}) + case bob.QueryTypeInsert: + ctx, err = PublicreportReports.AfterInsertHooks.RunHooks(ctx, exec, PublicreportReportSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = PublicreportReports.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportReportSlice{o}) + case bob.QueryTypeDelete: + ctx, err = PublicreportReports.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportReportSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the PublicreportReport +func (o *PublicreportReport) primaryKeyVals() bob.Expression { + return psql.Arg(o.ID) +} + +func (o *PublicreportReport) pkEQ() dialect.Expression { + return psql.Quote("publicreport.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 PublicreportReport +func (o *PublicreportReport) Update(ctx context.Context, exec bob.Executor, s *PublicreportReportSetter) error { + v, err := PublicreportReports.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 PublicreportReport record with an executor +func (o *PublicreportReport) Delete(ctx context.Context, exec bob.Executor) error { + _, err := PublicreportReports.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the PublicreportReport using the executor +func (o *PublicreportReport) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := PublicreportReports.Query( + sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after PublicreportReportSlice is retrieved from the database +func (o PublicreportReportSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = PublicreportReports.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = PublicreportReports.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = PublicreportReports.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = PublicreportReports.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o PublicreportReportSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return psql.Raw("NULL") + } + + return psql.Quote("publicreport.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 PublicreportReportSlice) copyMatchingRows(from ...*PublicreportReport) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o PublicreportReportSlice) 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 PublicreportReports.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 *PublicreportReport: + o.copyMatchingRows(retrieved) + case []*PublicreportReport: + o.copyMatchingRows(retrieved...) + case PublicreportReportSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a PublicreportReport or a slice of PublicreportReport + // then run the AfterUpdateHooks on the slice + _, err = PublicreportReports.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o PublicreportReportSlice) 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 PublicreportReports.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 *PublicreportReport: + o.copyMatchingRows(retrieved) + case []*PublicreportReport: + o.copyMatchingRows(retrieved...) + case PublicreportReportSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a PublicreportReport or a slice of PublicreportReport + // then run the AfterDeleteHooks on the slice + _, err = PublicreportReports.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o PublicreportReportSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportReportSetter) error { + if len(o) == 0 { + return nil + } + + _, err := PublicreportReports.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) + return err +} + +func (o PublicreportReportSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := PublicreportReports.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o PublicreportReportSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := PublicreportReports.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// TextJobs starts a query for related objects on comms.text_job +func (o *PublicreportReport) TextJobs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextJobsQuery { + return CommsTextJobs.Query(append(mods, + sm.Where(CommsTextJobs.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) TextJobs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextJobsQuery { + 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 CommsTextJobs.Query(append(mods, + sm.Where(psql.Group(CommsTextJobs.Columns.ReportID).OP("IN", PKArgExpr)), + )...) +} + +// NotifyEmails starts a query for related objects on publicreport.notify_email +func (o *PublicreportReport) NotifyEmails(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailsQuery { + return PublicreportNotifyEmails.Query(append(mods, + sm.Where(PublicreportNotifyEmails.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) NotifyEmails(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailsQuery { + 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 PublicreportNotifyEmails.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyEmails.Columns.ReportID).OP("IN", PKArgExpr)), + )...) +} + +// NotifyPhones starts a query for related objects on publicreport.notify_phone +func (o *PublicreportReport) NotifyPhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonesQuery { + return PublicreportNotifyPhones.Query(append(mods, + sm.Where(PublicreportNotifyPhones.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) NotifyPhones(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonesQuery { + 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 PublicreportNotifyPhones.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyPhones.Columns.ReportID).OP("IN", PKArgExpr)), + )...) +} + +// Nuisance starts a query for related objects on publicreport.nuisance +func (o *PublicreportReport) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery { + return PublicreportNuisances.Query(append(mods, + sm.Where(PublicreportNuisances.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) Nuisance(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery { + 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 PublicreportNuisances.Query(append(mods, + sm.Where(psql.Group(PublicreportNuisances.Columns.ReportID).OP("IN", PKArgExpr)), + )...) +} + +// Address starts a query for related objects on address +func (o *PublicreportReport) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { + return Addresses.Query(append(mods, + sm.Where(Addresses.Columns.ID.EQ(psql.Arg(o.AddressID))), + )...) +} + +func (os PublicreportReportSlice) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { + pkAddressID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkAddressID = append(pkAddressID, o.AddressID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkAddressID), "integer[]")), + )) + + return Addresses.Query(append(mods, + sm.Where(psql.Group(Addresses.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// Organization starts a query for related objects on organization +func (o *PublicreportReport) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + return Organizations.Query(append(mods, + sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), + )...) +} + +func (os PublicreportReportSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkOrganizationID = append(pkOrganizationID, o.OrganizationID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), + )) + + return Organizations.Query(append(mods, + sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ReviewerUser starts a query for related objects on user_ +func (o *PublicreportReport) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + return Users.Query(append(mods, + sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))), + )...) +} + +func (os PublicreportReportSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkReviewerID = append(pkReviewerID, o.ReviewerID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")), + )) + + return Users.Query(append(mods, + sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// Images starts a query for related objects on publicreport.image +func (o *PublicreportReport) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { + return PublicreportImages.Query(append(mods, + sm.InnerJoin(PublicreportReportImages.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportReportImages.Columns.ImageID)), + sm.Where(PublicreportReportImages.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { + 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 PublicreportImages.Query(append(mods, + sm.InnerJoin(PublicreportReportImages.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportReportImages.Columns.ImageID), + ), + sm.Where(psql.Group(PublicreportReportImages.Columns.ReportID).OP("IN", PKArgExpr)), + )...) +} + +// Water starts a query for related objects on publicreport.water +func (o *PublicreportReport) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery { + return PublicreportWaters.Query(append(mods, + sm.Where(PublicreportWaters.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) Water(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery { + 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 PublicreportWaters.Query(append(mods, + sm.Where(psql.Group(PublicreportWaters.Columns.ReportID).OP("IN", PKArgExpr)), + )...) +} + +// ReportTexts starts a query for related objects on report_text +func (o *PublicreportReport) ReportTexts(mods ...bob.Mod[*dialect.SelectQuery]) ReportTextsQuery { + return ReportTexts.Query(append(mods, + sm.Where(ReportTexts.Columns.ReportID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportReportSlice) 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.ReportID).OP("IN", PKArgExpr)), + )...) +} + +func insertPublicreportReportTextJobs0(ctx context.Context, exec bob.Executor, commsTextJobs1 []*CommsTextJobSetter, publicreportReport0 *PublicreportReport) (CommsTextJobSlice, error) { + for i := range commsTextJobs1 { + commsTextJobs1[i].ReportID = omitnull.From(publicreportReport0.ID) + } + + ret, err := CommsTextJobs.Insert(bob.ToMods(commsTextJobs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportTextJobs0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportTextJobs0(ctx context.Context, exec bob.Executor, count int, commsTextJobs1 CommsTextJobSlice, publicreportReport0 *PublicreportReport) (CommsTextJobSlice, error) { + setter := &CommsTextJobSetter{ + ReportID: omitnull.From(publicreportReport0.ID), + } + + err := commsTextJobs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportTextJobs0: %w", err) + } + + return commsTextJobs1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertTextJobs(ctx context.Context, exec bob.Executor, related ...*CommsTextJobSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + commsTextJobs1, err := insertPublicreportReportTextJobs0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.TextJobs = append(publicreportReport0.R.TextJobs, commsTextJobs1...) + + for _, rel := range commsTextJobs1 { + rel.R.Report = publicreportReport0 + } + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachTextJobs(ctx context.Context, exec bob.Executor, related ...*CommsTextJob) error { + if len(related) == 0 { + return nil + } + + var err error + commsTextJobs1 := CommsTextJobSlice(related) + + _, err = attachPublicreportReportTextJobs0(ctx, exec, len(related), commsTextJobs1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.TextJobs = append(publicreportReport0.R.TextJobs, commsTextJobs1...) + + for _, rel := range related { + rel.R.Report = publicreportReport0 + } + + return nil +} + +func insertPublicreportReportNotifyEmails0(ctx context.Context, exec bob.Executor, publicreportNotifyEmails1 []*PublicreportNotifyEmailSetter, publicreportReport0 *PublicreportReport) (PublicreportNotifyEmailSlice, error) { + for i := range publicreportNotifyEmails1 { + publicreportNotifyEmails1[i].ReportID = omit.From(publicreportReport0.ID) + } + + ret, err := PublicreportNotifyEmails.Insert(bob.ToMods(publicreportNotifyEmails1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportNotifyEmails0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportNotifyEmails0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmails1 PublicreportNotifyEmailSlice, publicreportReport0 *PublicreportReport) (PublicreportNotifyEmailSlice, error) { + setter := &PublicreportNotifyEmailSetter{ + ReportID: omit.From(publicreportReport0.ID), + } + + err := publicreportNotifyEmails1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportNotifyEmails0: %w", err) + } + + return publicreportNotifyEmails1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertNotifyEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNotifyEmails1, err := insertPublicreportReportNotifyEmails0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.NotifyEmails = append(publicreportReport0.R.NotifyEmails, publicreportNotifyEmails1...) + + for _, rel := range publicreportNotifyEmails1 { + rel.R.Report = publicreportReport0 + } + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachNotifyEmails(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmail) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNotifyEmails1 := PublicreportNotifyEmailSlice(related) + + _, err = attachPublicreportReportNotifyEmails0(ctx, exec, len(related), publicreportNotifyEmails1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.NotifyEmails = append(publicreportReport0.R.NotifyEmails, publicreportNotifyEmails1...) + + for _, rel := range related { + rel.R.Report = publicreportReport0 + } + + return nil +} + +func insertPublicreportReportNotifyPhones0(ctx context.Context, exec bob.Executor, publicreportNotifyPhones1 []*PublicreportNotifyPhoneSetter, publicreportReport0 *PublicreportReport) (PublicreportNotifyPhoneSlice, error) { + for i := range publicreportNotifyPhones1 { + publicreportNotifyPhones1[i].ReportID = omit.From(publicreportReport0.ID) + } + + ret, err := PublicreportNotifyPhones.Insert(bob.ToMods(publicreportNotifyPhones1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportNotifyPhones0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportNotifyPhones0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhones1 PublicreportNotifyPhoneSlice, publicreportReport0 *PublicreportReport) (PublicreportNotifyPhoneSlice, error) { + setter := &PublicreportNotifyPhoneSetter{ + ReportID: omit.From(publicreportReport0.ID), + } + + err := publicreportNotifyPhones1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportNotifyPhones0: %w", err) + } + + return publicreportNotifyPhones1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertNotifyPhones(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNotifyPhones1, err := insertPublicreportReportNotifyPhones0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.NotifyPhones = append(publicreportReport0.R.NotifyPhones, publicreportNotifyPhones1...) + + for _, rel := range publicreportNotifyPhones1 { + rel.R.Report = publicreportReport0 + } + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachNotifyPhones(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhone) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNotifyPhones1 := PublicreportNotifyPhoneSlice(related) + + _, err = attachPublicreportReportNotifyPhones0(ctx, exec, len(related), publicreportNotifyPhones1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.NotifyPhones = append(publicreportReport0.R.NotifyPhones, publicreportNotifyPhones1...) + + for _, rel := range related { + rel.R.Report = publicreportReport0 + } + + return nil +} + +func insertPublicreportReportNuisance0(ctx context.Context, exec bob.Executor, publicreportNuisance1 *PublicreportNuisanceSetter, publicreportReport0 *PublicreportReport) (*PublicreportNuisance, error) { + publicreportNuisance1.ReportID = omit.From(publicreportReport0.ID) + + ret, err := PublicreportNuisances.Insert(publicreportNuisance1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportNuisance0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportNuisance0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance1 *PublicreportNuisance, publicreportReport0 *PublicreportReport) (*PublicreportNuisance, error) { + setter := &PublicreportNuisanceSetter{ + ReportID: omit.From(publicreportReport0.ID), + } + + err := publicreportNuisance1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportNuisance0: %w", err) + } + + return publicreportNuisance1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertNuisance(ctx context.Context, exec bob.Executor, related *PublicreportNuisanceSetter) error { + var err error + + publicreportNuisance1, err := insertPublicreportReportNuisance0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.Nuisance = publicreportNuisance1 + + publicreportNuisance1.R.Report = publicreportReport0 + + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachNuisance(ctx context.Context, exec bob.Executor, publicreportNuisance1 *PublicreportNuisance) error { + var err error + + _, err = attachPublicreportReportNuisance0(ctx, exec, 1, publicreportNuisance1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.Nuisance = publicreportNuisance1 + + publicreportNuisance1.R.Report = publicreportReport0 + + return nil +} + +func attachPublicreportReportAddress0(ctx context.Context, exec bob.Executor, count int, publicreportReport0 *PublicreportReport, address1 *Address) (*PublicreportReport, error) { + setter := &PublicreportReportSetter{ + AddressID: omitnull.From(address1.ID), + } + + err := publicreportReport0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportAddress0: %w", err) + } + + return publicreportReport0, nil +} + +func (publicreportReport0 *PublicreportReport) InsertAddress(ctx context.Context, exec bob.Executor, related *AddressSetter) error { + var err error + + address1, err := Addresses.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachPublicreportReportAddress0(ctx, exec, 1, publicreportReport0, address1) + if err != nil { + return err + } + + publicreportReport0.R.Address = address1 + + address1.R.Reports = append(address1.R.Reports, publicreportReport0) + + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { + var err error + + _, err = attachPublicreportReportAddress0(ctx, exec, 1, publicreportReport0, address1) + if err != nil { + return err + } + + publicreportReport0.R.Address = address1 + + address1.R.Reports = append(address1.R.Reports, publicreportReport0) + + return nil +} + +func attachPublicreportReportOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportReport0 *PublicreportReport, organization1 *Organization) (*PublicreportReport, error) { + setter := &PublicreportReportSetter{ + OrganizationID: omit.From(organization1.ID), + } + + err := publicreportReport0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportOrganization0: %w", err) + } + + return publicreportReport0, nil +} + +func (publicreportReport0 *PublicreportReport) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { + var err error + + organization1, err := Organizations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachPublicreportReportOrganization0(ctx, exec, 1, publicreportReport0, organization1) + if err != nil { + return err + } + + publicreportReport0.R.Organization = organization1 + + organization1.R.Reports = append(organization1.R.Reports, publicreportReport0) + + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { + var err error + + _, err = attachPublicreportReportOrganization0(ctx, exec, 1, publicreportReport0, organization1) + if err != nil { + return err + } + + publicreportReport0.R.Organization = organization1 + + organization1.R.Reports = append(organization1.R.Reports, publicreportReport0) + + return nil +} + +func attachPublicreportReportReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportReport0 *PublicreportReport, user1 *User) (*PublicreportReport, error) { + setter := &PublicreportReportSetter{ + ReviewerID: omitnull.From(user1.ID), + } + + err := publicreportReport0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportReviewerUser0: %w", err) + } + + return publicreportReport0, nil +} + +func (publicreportReport0 *PublicreportReport) InsertReviewerUser(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 = attachPublicreportReportReviewerUser0(ctx, exec, 1, publicreportReport0, user1) + if err != nil { + return err + } + + publicreportReport0.R.ReviewerUser = user1 + + user1.R.ReviewerReports = append(user1.R.ReviewerReports, publicreportReport0) + + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error { + var err error + + _, err = attachPublicreportReportReviewerUser0(ctx, exec, 1, publicreportReport0, user1) + if err != nil { + return err + } + + publicreportReport0.R.ReviewerUser = user1 + + user1.R.ReviewerReports = append(user1.R.ReviewerReports, publicreportReport0) + + return nil +} + +func attachPublicreportReportImages0(ctx context.Context, exec bob.Executor, count int, publicreportReport0 *PublicreportReport, publicreportImages2 PublicreportImageSlice) (PublicreportReportImageSlice, error) { + setters := make([]*PublicreportReportImageSetter, count) + for i := range count { + setters[i] = &PublicreportReportImageSetter{ + ReportID: omit.From(publicreportReport0.ID), + ImageID: omit.From(publicreportImages2[i].ID), + } + } + + publicreportReportImages1, err := PublicreportReportImages.Insert(bob.ToMods(setters...)).All(ctx, exec) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportImages0: %w", err) + } + + return publicreportReportImages1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + publicreportImages2 := PublicreportImageSlice(inserted) + + _, err = attachPublicreportReportImages0(ctx, exec, len(related), publicreportReport0, publicreportImages2) + if err != nil { + return err + } + + publicreportReport0.R.Images = append(publicreportReport0.R.Images, publicreportImages2...) + + for _, rel := range publicreportImages2 { + rel.R.Reports = append(rel.R.Reports, publicreportReport0) + } + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportImages2 := PublicreportImageSlice(related) + + _, err = attachPublicreportReportImages0(ctx, exec, len(related), publicreportReport0, publicreportImages2) + if err != nil { + return err + } + + publicreportReport0.R.Images = append(publicreportReport0.R.Images, publicreportImages2...) + + for _, rel := range related { + rel.R.Reports = append(rel.R.Reports, publicreportReport0) + } + + return nil +} + +func insertPublicreportReportWater0(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWaterSetter, publicreportReport0 *PublicreportReport) (*PublicreportWater, error) { + publicreportWater1.ReportID = omit.From(publicreportReport0.ID) + + ret, err := PublicreportWaters.Insert(publicreportWater1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportWater0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportWater0(ctx context.Context, exec bob.Executor, count int, publicreportWater1 *PublicreportWater, publicreportReport0 *PublicreportReport) (*PublicreportWater, error) { + setter := &PublicreportWaterSetter{ + ReportID: omit.From(publicreportReport0.ID), + } + + err := publicreportWater1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportWater0: %w", err) + } + + return publicreportWater1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertWater(ctx context.Context, exec bob.Executor, related *PublicreportWaterSetter) error { + var err error + + publicreportWater1, err := insertPublicreportReportWater0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.Water = publicreportWater1 + + publicreportWater1.R.Report = publicreportReport0 + + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachWater(ctx context.Context, exec bob.Executor, publicreportWater1 *PublicreportWater) error { + var err error + + _, err = attachPublicreportReportWater0(ctx, exec, 1, publicreportWater1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.Water = publicreportWater1 + + publicreportWater1.R.Report = publicreportReport0 + + return nil +} + +func insertPublicreportReportReportTexts0(ctx context.Context, exec bob.Executor, reportTexts1 []*ReportTextSetter, publicreportReport0 *PublicreportReport) (ReportTextSlice, error) { + for i := range reportTexts1 { + reportTexts1[i].ReportID = omit.From(publicreportReport0.ID) + } + + ret, err := ReportTexts.Insert(bob.ToMods(reportTexts1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportReportReportTexts0: %w", err) + } + + return ret, nil +} + +func attachPublicreportReportReportTexts0(ctx context.Context, exec bob.Executor, count int, reportTexts1 ReportTextSlice, publicreportReport0 *PublicreportReport) (ReportTextSlice, error) { + setter := &ReportTextSetter{ + ReportID: omit.From(publicreportReport0.ID), + } + + err := reportTexts1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportReportReportTexts0: %w", err) + } + + return reportTexts1, nil +} + +func (publicreportReport0 *PublicreportReport) InsertReportTexts(ctx context.Context, exec bob.Executor, related ...*ReportTextSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + reportTexts1, err := insertPublicreportReportReportTexts0(ctx, exec, related, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.ReportTexts = append(publicreportReport0.R.ReportTexts, reportTexts1...) + + for _, rel := range reportTexts1 { + rel.R.Report = publicreportReport0 + } + return nil +} + +func (publicreportReport0 *PublicreportReport) AttachReportTexts(ctx context.Context, exec bob.Executor, related ...*ReportText) error { + if len(related) == 0 { + return nil + } + + var err error + reportTexts1 := ReportTextSlice(related) + + _, err = attachPublicreportReportReportTexts0(ctx, exec, len(related), reportTexts1, publicreportReport0) + if err != nil { + return err + } + + publicreportReport0.R.ReportTexts = append(publicreportReport0.R.ReportTexts, reportTexts1...) + + for _, rel := range related { + rel.R.Report = publicreportReport0 + } + + return nil +} + +type publicreportReportWhere[Q psql.Filterable] struct { + AddressRaw psql.WhereMod[Q, string] + AddressNumber psql.WhereMod[Q, string] + AddressStreet psql.WhereMod[Q, string] + AddressLocality psql.WhereMod[Q, string] + AddressRegion psql.WhereMod[Q, string] + AddressPostalCode psql.WhereMod[Q, string] + AddressCountry psql.WhereMod[Q, string] + AddressID psql.WhereNullMod[Q, int32] + Created psql.WhereMod[Q, time.Time] + Location psql.WhereNullMod[Q, string] + H3cell psql.WhereNullMod[Q, string] + ID psql.WhereMod[Q, int32] + LatlngAccuracyType psql.WhereMod[Q, enums.PublicreportAccuracytype] + LatlngAccuracyValue psql.WhereMod[Q, float32] + MapZoom psql.WhereMod[Q, float32] + OrganizationID psql.WhereMod[Q, int32] + PublicID psql.WhereMod[Q, string] + ReporterName psql.WhereMod[Q, string] + ReporterEmail psql.WhereMod[Q, string] + ReporterPhone psql.WhereMod[Q, string] + ReporterContactConsent psql.WhereNullMod[Q, bool] + ReportType psql.WhereMod[Q, string] + Reviewed psql.WhereNullMod[Q, time.Time] + ReviewerID psql.WhereNullMod[Q, int32] + Status psql.WhereMod[Q, enums.PublicreportReportstatustype] +} + +func (publicreportReportWhere[Q]) AliasedAs(alias string) publicreportReportWhere[Q] { + return buildPublicreportReportWhere[Q](buildPublicreportReportColumns(alias)) +} + +func buildPublicreportReportWhere[Q psql.Filterable](cols publicreportReportColumns) publicreportReportWhere[Q] { + return publicreportReportWhere[Q]{ + AddressRaw: psql.Where[Q, string](cols.AddressRaw), + AddressNumber: psql.Where[Q, string](cols.AddressNumber), + AddressStreet: psql.Where[Q, string](cols.AddressStreet), + AddressLocality: psql.Where[Q, string](cols.AddressLocality), + AddressRegion: psql.Where[Q, string](cols.AddressRegion), + AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), + AddressCountry: psql.Where[Q, string](cols.AddressCountry), + AddressID: psql.WhereNull[Q, int32](cols.AddressID), + Created: psql.Where[Q, time.Time](cols.Created), + Location: psql.WhereNull[Q, string](cols.Location), + H3cell: psql.WhereNull[Q, string](cols.H3cell), + ID: psql.Where[Q, int32](cols.ID), + LatlngAccuracyType: psql.Where[Q, enums.PublicreportAccuracytype](cols.LatlngAccuracyType), + LatlngAccuracyValue: psql.Where[Q, float32](cols.LatlngAccuracyValue), + MapZoom: psql.Where[Q, float32](cols.MapZoom), + OrganizationID: psql.Where[Q, int32](cols.OrganizationID), + PublicID: psql.Where[Q, string](cols.PublicID), + ReporterName: psql.Where[Q, string](cols.ReporterName), + ReporterEmail: psql.Where[Q, string](cols.ReporterEmail), + ReporterPhone: psql.Where[Q, string](cols.ReporterPhone), + ReporterContactConsent: psql.WhereNull[Q, bool](cols.ReporterContactConsent), + ReportType: psql.Where[Q, string](cols.ReportType), + Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed), + ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID), + Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status), + } +} + +func (o *PublicreportReport) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "TextJobs": + rels, ok := retrieved.(CommsTextJobSlice) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.TextJobs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.Report = o + } + } + return nil + case "NotifyEmails": + rels, ok := retrieved.(PublicreportNotifyEmailSlice) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.NotifyEmails = rels + + for _, rel := range rels { + if rel != nil { + rel.R.Report = o + } + } + return nil + case "NotifyPhones": + rels, ok := retrieved.(PublicreportNotifyPhoneSlice) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.NotifyPhones = rels + + for _, rel := range rels { + if rel != nil { + rel.R.Report = o + } + } + return nil + case "Nuisance": + rel, ok := retrieved.(*PublicreportNuisance) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.Nuisance = rel + + if rel != nil { + rel.R.Report = o + } + return nil + case "Address": + rel, ok := retrieved.(*Address) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.Address = rel + + if rel != nil { + rel.R.Reports = PublicreportReportSlice{o} + } + return nil + case "Organization": + rel, ok := retrieved.(*Organization) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.Organization = rel + + if rel != nil { + rel.R.Reports = PublicreportReportSlice{o} + } + return nil + case "ReviewerUser": + rel, ok := retrieved.(*User) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.ReviewerUser = rel + + if rel != nil { + rel.R.ReviewerReports = PublicreportReportSlice{o} + } + return nil + case "Images": + rels, ok := retrieved.(PublicreportImageSlice) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.Images = rels + + for _, rel := range rels { + if rel != nil { + rel.R.Reports = PublicreportReportSlice{o} + } + } + return nil + case "Water": + rel, ok := retrieved.(*PublicreportWater) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.Water = rel + + if rel != nil { + rel.R.Report = o + } + return nil + case "ReportTexts": + rels, ok := retrieved.(ReportTextSlice) + if !ok { + return fmt.Errorf("publicreportReport cannot load %T as %q", retrieved, name) + } + + o.R.ReportTexts = rels + + for _, rel := range rels { + if rel != nil { + rel.R.Report = o + } + } + return nil + default: + return fmt.Errorf("publicreportReport has no relationship %q", name) + } +} + +type publicreportReportPreloader struct { + Nuisance func(...psql.PreloadOption) psql.Preloader + Address func(...psql.PreloadOption) psql.Preloader + Organization func(...psql.PreloadOption) psql.Preloader + ReviewerUser func(...psql.PreloadOption) psql.Preloader + Water func(...psql.PreloadOption) psql.Preloader +} + +func buildPublicreportReportPreloader() publicreportReportPreloader { + return publicreportReportPreloader{ + Nuisance: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*PublicreportNuisance, PublicreportNuisanceSlice](psql.PreloadRel{ + Name: "Nuisance", + Sides: []psql.PreloadSide{ + { + From: PublicreportReports, + To: PublicreportNuisances, + FromColumns: []string{"id"}, + ToColumns: []string{"report_id"}, + }, + }, + }, PublicreportNuisances.Columns.Names(), opts...) + }, + Address: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Address, AddressSlice](psql.PreloadRel{ + Name: "Address", + Sides: []psql.PreloadSide{ + { + From: PublicreportReports, + To: Addresses, + FromColumns: []string{"address_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Addresses.Columns.Names(), opts...) + }, + Organization: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ + Name: "Organization", + Sides: []psql.PreloadSide{ + { + From: PublicreportReports, + To: Organizations, + FromColumns: []string{"organization_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Organizations.Columns.Names(), opts...) + }, + ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*User, UserSlice](psql.PreloadRel{ + Name: "ReviewerUser", + Sides: []psql.PreloadSide{ + { + From: PublicreportReports, + To: Users, + FromColumns: []string{"reviewer_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Users.Columns.Names(), opts...) + }, + Water: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*PublicreportWater, PublicreportWaterSlice](psql.PreloadRel{ + Name: "Water", + Sides: []psql.PreloadSide{ + { + From: PublicreportReports, + To: PublicreportWaters, + FromColumns: []string{"id"}, + ToColumns: []string{"report_id"}, + }, + }, + }, PublicreportWaters.Columns.Names(), opts...) + }, + } +} + +type publicreportReportThenLoader[Q orm.Loadable] struct { + TextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + NotifyEmails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + NotifyPhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Nuisance func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Water func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildPublicreportReportThenLoader[Q orm.Loadable]() publicreportReportThenLoader[Q] { + type TextJobsLoadInterface interface { + LoadTextJobs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type NotifyEmailsLoadInterface interface { + LoadNotifyEmails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type NotifyPhonesLoadInterface interface { + LoadNotifyPhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type NuisanceLoadInterface interface { + LoadNuisance(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type AddressLoadInterface interface { + LoadAddress(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OrganizationLoadInterface interface { + LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReviewerUserLoadInterface interface { + LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ImagesLoadInterface interface { + LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type WaterLoadInterface interface { + LoadWater(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReportTextsLoadInterface interface { + LoadReportTexts(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return publicreportReportThenLoader[Q]{ + TextJobs: thenLoadBuilder[Q]( + "TextJobs", + func(ctx context.Context, exec bob.Executor, retrieved TextJobsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadTextJobs(ctx, exec, mods...) + }, + ), + NotifyEmails: thenLoadBuilder[Q]( + "NotifyEmails", + func(ctx context.Context, exec bob.Executor, retrieved NotifyEmailsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadNotifyEmails(ctx, exec, mods...) + }, + ), + NotifyPhones: thenLoadBuilder[Q]( + "NotifyPhones", + func(ctx context.Context, exec bob.Executor, retrieved NotifyPhonesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadNotifyPhones(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...) + }, + ), + Address: thenLoadBuilder[Q]( + "Address", + func(ctx context.Context, exec bob.Executor, retrieved AddressLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAddress(ctx, exec, mods...) + }, + ), + Organization: thenLoadBuilder[Q]( + "Organization", + func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOrganization(ctx, exec, mods...) + }, + ), + ReviewerUser: thenLoadBuilder[Q]( + "ReviewerUser", + func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReviewerUser(ctx, exec, mods...) + }, + ), + Images: thenLoadBuilder[Q]( + "Images", + func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadImages(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...) + }, + ), + 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...) + }, + ), + } +} + +// LoadTextJobs loads the publicreportReport's TextJobs into the .R struct +func (o *PublicreportReport) LoadTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.TextJobs = nil + + related, err := o.TextJobs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Report = o + } + + o.R.TextJobs = related + return nil +} + +// LoadTextJobs loads the publicreportReport's TextJobs into the .R struct +func (os PublicreportReportSlice) LoadTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + commsTextJobs, err := os.TextJobs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.TextJobs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range commsTextJobs { + + if !rel.ReportID.IsValue() { + continue + } + if !(rel.ReportID.IsValue() && o.ID == rel.ReportID.MustGet()) { + continue + } + + rel.R.Report = o + + o.R.TextJobs = append(o.R.TextJobs, rel) + } + } + + return nil +} + +// LoadNotifyEmails loads the publicreportReport's NotifyEmails into the .R struct +func (o *PublicreportReport) LoadNotifyEmails(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.NotifyEmails = nil + + related, err := o.NotifyEmails(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Report = o + } + + o.R.NotifyEmails = related + return nil +} + +// LoadNotifyEmails loads the publicreportReport's NotifyEmails into the .R struct +func (os PublicreportReportSlice) LoadNotifyEmails(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportNotifyEmails, err := os.NotifyEmails(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.NotifyEmails = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNotifyEmails { + + if !(o.ID == rel.ReportID) { + continue + } + + rel.R.Report = o + + o.R.NotifyEmails = append(o.R.NotifyEmails, rel) + } + } + + return nil +} + +// LoadNotifyPhones loads the publicreportReport's NotifyPhones into the .R struct +func (o *PublicreportReport) LoadNotifyPhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.NotifyPhones = nil + + related, err := o.NotifyPhones(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Report = o + } + + o.R.NotifyPhones = related + return nil +} + +// LoadNotifyPhones loads the publicreportReport's NotifyPhones into the .R struct +func (os PublicreportReportSlice) LoadNotifyPhones(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportNotifyPhones, err := os.NotifyPhones(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.NotifyPhones = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNotifyPhones { + + if !(o.ID == rel.ReportID) { + continue + } + + rel.R.Report = o + + o.R.NotifyPhones = append(o.R.NotifyPhones, rel) + } + } + + return nil +} + +// LoadNuisance loads the publicreportReport's Nuisance into the .R struct +func (o *PublicreportReport) 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.Report = o + + o.R.Nuisance = related + return nil +} + +// LoadNuisance loads the publicreportReport's Nuisance into the .R struct +func (os PublicreportReportSlice) 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.ID == rel.ReportID) { + continue + } + + rel.R.Report = o + + o.R.Nuisance = rel + break + } + } + + return nil +} + +// LoadAddress loads the publicreportReport's Address into the .R struct +func (o *PublicreportReport) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Address = nil + + related, err := o.Address(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.Reports = PublicreportReportSlice{o} + + o.R.Address = related + return nil +} + +// LoadAddress loads the publicreportReport's Address into the .R struct +func (os PublicreportReportSlice) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + addresses, err := os.Address(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range addresses { + if !o.AddressID.IsValue() { + continue + } + + if !(o.AddressID.IsValue() && o.AddressID.MustGet() == rel.ID) { + continue + } + + rel.R.Reports = append(rel.R.Reports, o) + + o.R.Address = rel + break + } + } + + return nil +} + +// LoadOrganization loads the publicreportReport's Organization into the .R struct +func (o *PublicreportReport) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Organization = nil + + related, err := o.Organization(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.Reports = PublicreportReportSlice{o} + + o.R.Organization = related + return nil +} + +// LoadOrganization loads the publicreportReport's Organization into the .R struct +func (os PublicreportReportSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + organizations, err := os.Organization(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range organizations { + + if !(o.OrganizationID == rel.ID) { + continue + } + + rel.R.Reports = append(rel.R.Reports, o) + + o.R.Organization = rel + break + } + } + + return nil +} + +// LoadReviewerUser loads the publicreportReport's ReviewerUser into the .R struct +func (o *PublicreportReport) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReviewerUser = nil + + related, err := o.ReviewerUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ReviewerReports = PublicreportReportSlice{o} + + o.R.ReviewerUser = related + return nil +} + +// LoadReviewerUser loads the publicreportReport's ReviewerUser into the .R struct +func (os PublicreportReportSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + users, err := os.ReviewerUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range users { + if !o.ReviewerID.IsValue() { + continue + } + + if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) { + continue + } + + rel.R.ReviewerReports = append(rel.R.ReviewerReports, o) + + o.R.ReviewerUser = rel + break + } + } + + return nil +} + +// LoadImages loads the publicreportReport's Images into the .R struct +func (o *PublicreportReport) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Images = nil + + related, err := o.Images(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Reports = PublicreportReportSlice{o} + } + + o.R.Images = related + return nil +} + +// LoadImages loads the publicreportReport's Images into the .R struct +func (os PublicreportReportSlice) LoadImages(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(PublicreportImages.Columns)) + } + + q := os.Images(append( + mods, + sm.Columns(PublicreportReportImages.Columns.ReportID.As("related_publicreport.report.ID")), + )...) + + IDSlice := []int32{} + + mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), 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.report.ID", &IDSlice[len(IDSlice)-1]) + + return nil, nil + }, + func(any, any) error { + return nil + } + }) + + publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper) + if err != nil { + return err + } + + for _, o := range os { + o.R.Images = nil + } + + for _, o := range os { + for i, rel := range publicreportImages { + if !(o.ID == IDSlice[i]) { + continue + } + + rel.R.Reports = append(rel.R.Reports, o) + + o.R.Images = append(o.R.Images, rel) + } + } + + return nil +} + +// LoadWater loads the publicreportReport's Water into the .R struct +func (o *PublicreportReport) 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.Report = o + + o.R.Water = related + return nil +} + +// LoadWater loads the publicreportReport's Water into the .R struct +func (os PublicreportReportSlice) 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.ID == rel.ReportID) { + continue + } + + rel.R.Report = o + + o.R.Water = rel + break + } + } + + return nil +} + +// LoadReportTexts loads the publicreportReport's ReportTexts into the .R struct +func (o *PublicreportReport) 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.Report = o + } + + o.R.ReportTexts = related + return nil +} + +// LoadReportTexts loads the publicreportReport's ReportTexts into the .R struct +func (os PublicreportReportSlice) 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.ReportID) { + continue + } + + rel.R.Report = o + + o.R.ReportTexts = append(o.R.ReportTexts, rel) + } + } + + return nil +} diff --git a/db/models/publicreport.report_image.bob.go b/db/models/publicreport.report_image.bob.go new file mode 100644 index 00000000..dacb440d --- /dev/null +++ b/db/models/publicreport.report_image.bob.go @@ -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 +} diff --git a/db/models/publicreport.water.bob.go b/db/models/publicreport.water.bob.go index cbe0933d..b0b90e54 100644 --- a/db/models/publicreport.water.bob.go +++ b/db/models/publicreport.water.bob.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "io" - "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/bob/dialect/psql" @@ -18,53 +17,28 @@ import ( "github.com/Gleipnir-Technology/bob/expr" "github.com/Gleipnir-Technology/bob/orm" "github.com/Gleipnir-Technology/bob/types/pgtypes" - enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" - "github.com/aarondl/opt/null" "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - "github.com/stephenafamo/scan" ) // PublicreportWater is an object representing the database table. type PublicreportWater struct { - ID int32 `db:"id,pk" ` - AccessComments string `db:"access_comments" ` - AccessGate bool `db:"access_gate" ` - AccessFence bool `db:"access_fence" ` - AccessLocked bool `db:"access_locked" ` - AccessDog bool `db:"access_dog" ` - AccessOther bool `db:"access_other" ` - AddressRaw string `db:"address_raw" ` - AddressCountry string `db:"address_country" ` - AddressPostalCode string `db:"address_postal_code" ` - AddressLocality string `db:"address_locality" ` - AddressStreet string `db:"address_street" ` - AddressRegion string `db:"address_region" ` - Comments string `db:"comments" ` - Created time.Time `db:"created" ` - H3cell null.Val[string] `db:"h3cell" ` - HasAdult bool `db:"has_adult" ` - HasLarvae bool `db:"has_larvae" ` - HasPupae bool `db:"has_pupae" ` - MapZoom float32 `db:"map_zoom" ` - OwnerEmail string `db:"owner_email" ` - OwnerName string `db:"owner_name" ` - OwnerPhone string `db:"owner_phone" ` - PublicID string `db:"public_id" ` - ReporterEmail string `db:"reporter_email" ` - ReporterName string `db:"reporter_name" ` - ReporterPhone string `db:"reporter_phone" ` - Status enums.PublicreportReportstatustype `db:"status" ` - OrganizationID int32 `db:"organization_id" ` - HasBackyardPermission bool `db:"has_backyard_permission" ` - IsReporterConfidential bool `db:"is_reporter_confidential" ` - IsReporterOwner bool `db:"is_reporter_owner" ` - ReporterContactConsent null.Val[bool] `db:"reporter_contact_consent" ` - Location null.Val[string] `db:"location" ` - AddressNumber string `db:"address_number" ` - AddressID null.Val[int32] `db:"address_id" ` - Reviewed null.Val[time.Time] `db:"reviewed" ` - ReviewerID null.Val[int32] `db:"reviewer_id" ` + AccessComments string `db:"access_comments" ` + AccessGate bool `db:"access_gate" ` + AccessFence bool `db:"access_fence" ` + AccessLocked bool `db:"access_locked" ` + AccessDog bool `db:"access_dog" ` + AccessOther bool `db:"access_other" ` + Comments string `db:"comments" ` + IsReporterConfidential bool `db:"is_reporter_confidential" ` + IsReporterOwner bool `db:"is_reporter_owner" ` + HasAdult bool `db:"has_adult" ` + HasBackyardPermission bool `db:"has_backyard_permission" ` + HasLarvae bool `db:"has_larvae" ` + HasPupae bool `db:"has_pupae" ` + OwnerEmail string `db:"owner_email" ` + OwnerName string `db:"owner_name" ` + OwnerPhone string `db:"owner_phone" ` + ReportID int32 `db:"report_id,pk" ` R publicreportWaterR `db:"-" ` } @@ -81,102 +55,55 @@ type PublicreportWatersQuery = *psql.ViewQuery[*PublicreportWater, PublicreportW // publicreportWaterR is where relationships are stored. type publicreportWaterR struct { - NotifyEmailWaters PublicreportNotifyEmailWaterSlice // publicreport.notify_email_water.notify_email_pool_pool_id_fkey - NotifyPhoneWaters PublicreportNotifyPhoneWaterSlice // publicreport.notify_phone_water.notify_phone_pool_pool_id_fkey - Address *Address // publicreport.water.pool_address_id_fkey - Organization *Organization // publicreport.water.pool_organization_id_fkey - ReviewerUser *User // publicreport.water.water_reviewer_id_fkey - Images PublicreportImageSlice // publicreport.water_image.pool_image_image_id_fkeypublicreport.water_image.pool_image_pool_id_fkey + Report *PublicreportReport // publicreport.water.water_report_id_fkey } func buildPublicreportWaterColumns(alias string) publicreportWaterColumns { return publicreportWaterColumns{ ColumnsExpr: expr.NewColumnsExpr( - "id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address_raw", "address_country", "address_postal_code", "address_locality", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "status", "organization_id", "has_backyard_permission", "is_reporter_confidential", "is_reporter_owner", "reporter_contact_consent", "location", "address_number", "address_id", "reviewed", "reviewer_id", + "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "comments", "is_reporter_confidential", "is_reporter_owner", "has_adult", "has_backyard_permission", "has_larvae", "has_pupae", "owner_email", "owner_name", "owner_phone", "report_id", ).WithParent("publicreport.water"), tableAlias: alias, - ID: psql.Quote(alias, "id"), AccessComments: psql.Quote(alias, "access_comments"), AccessGate: psql.Quote(alias, "access_gate"), AccessFence: psql.Quote(alias, "access_fence"), AccessLocked: psql.Quote(alias, "access_locked"), AccessDog: psql.Quote(alias, "access_dog"), AccessOther: psql.Quote(alias, "access_other"), - AddressRaw: psql.Quote(alias, "address_raw"), - AddressCountry: psql.Quote(alias, "address_country"), - AddressPostalCode: psql.Quote(alias, "address_postal_code"), - AddressLocality: psql.Quote(alias, "address_locality"), - AddressStreet: psql.Quote(alias, "address_street"), - AddressRegion: psql.Quote(alias, "address_region"), Comments: psql.Quote(alias, "comments"), - Created: psql.Quote(alias, "created"), - H3cell: psql.Quote(alias, "h3cell"), + IsReporterConfidential: psql.Quote(alias, "is_reporter_confidential"), + IsReporterOwner: psql.Quote(alias, "is_reporter_owner"), HasAdult: psql.Quote(alias, "has_adult"), + HasBackyardPermission: psql.Quote(alias, "has_backyard_permission"), HasLarvae: psql.Quote(alias, "has_larvae"), HasPupae: psql.Quote(alias, "has_pupae"), - MapZoom: psql.Quote(alias, "map_zoom"), OwnerEmail: psql.Quote(alias, "owner_email"), OwnerName: psql.Quote(alias, "owner_name"), OwnerPhone: psql.Quote(alias, "owner_phone"), - PublicID: psql.Quote(alias, "public_id"), - ReporterEmail: psql.Quote(alias, "reporter_email"), - ReporterName: psql.Quote(alias, "reporter_name"), - ReporterPhone: psql.Quote(alias, "reporter_phone"), - Status: psql.Quote(alias, "status"), - OrganizationID: psql.Quote(alias, "organization_id"), - HasBackyardPermission: psql.Quote(alias, "has_backyard_permission"), - IsReporterConfidential: psql.Quote(alias, "is_reporter_confidential"), - IsReporterOwner: psql.Quote(alias, "is_reporter_owner"), - ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), - Location: psql.Quote(alias, "location"), - AddressNumber: psql.Quote(alias, "address_number"), - AddressID: psql.Quote(alias, "address_id"), - Reviewed: psql.Quote(alias, "reviewed"), - ReviewerID: psql.Quote(alias, "reviewer_id"), + ReportID: psql.Quote(alias, "report_id"), } } type publicreportWaterColumns struct { expr.ColumnsExpr tableAlias string - ID psql.Expression AccessComments psql.Expression AccessGate psql.Expression AccessFence psql.Expression AccessLocked psql.Expression AccessDog psql.Expression AccessOther psql.Expression - AddressRaw psql.Expression - AddressCountry psql.Expression - AddressPostalCode psql.Expression - AddressLocality psql.Expression - AddressStreet psql.Expression - AddressRegion psql.Expression Comments psql.Expression - Created psql.Expression - H3cell psql.Expression + IsReporterConfidential psql.Expression + IsReporterOwner psql.Expression HasAdult psql.Expression + HasBackyardPermission psql.Expression HasLarvae psql.Expression HasPupae psql.Expression - MapZoom psql.Expression OwnerEmail psql.Expression OwnerName psql.Expression OwnerPhone psql.Expression - PublicID psql.Expression - ReporterEmail psql.Expression - ReporterName psql.Expression - ReporterPhone psql.Expression - Status psql.Expression - OrganizationID psql.Expression - HasBackyardPermission psql.Expression - IsReporterConfidential psql.Expression - IsReporterOwner psql.Expression - ReporterContactConsent psql.Expression - Location psql.Expression - AddressNumber psql.Expression - AddressID psql.Expression - Reviewed psql.Expression - ReviewerID psql.Expression + ReportID psql.Expression } func (c publicreportWaterColumns) Alias() string { @@ -191,51 +118,27 @@ func (publicreportWaterColumns) AliasedAs(alias string) publicreportWaterColumns // All values are optional, and do not have to be set // Generated columns are not included type PublicreportWaterSetter struct { - ID omit.Val[int32] `db:"id,pk" ` - AccessComments omit.Val[string] `db:"access_comments" ` - AccessGate omit.Val[bool] `db:"access_gate" ` - AccessFence omit.Val[bool] `db:"access_fence" ` - AccessLocked omit.Val[bool] `db:"access_locked" ` - AccessDog omit.Val[bool] `db:"access_dog" ` - AccessOther omit.Val[bool] `db:"access_other" ` - AddressRaw omit.Val[string] `db:"address_raw" ` - AddressCountry omit.Val[string] `db:"address_country" ` - AddressPostalCode omit.Val[string] `db:"address_postal_code" ` - AddressLocality omit.Val[string] `db:"address_locality" ` - AddressStreet omit.Val[string] `db:"address_street" ` - AddressRegion omit.Val[string] `db:"address_region" ` - Comments omit.Val[string] `db:"comments" ` - Created omit.Val[time.Time] `db:"created" ` - H3cell omitnull.Val[string] `db:"h3cell" ` - HasAdult omit.Val[bool] `db:"has_adult" ` - HasLarvae omit.Val[bool] `db:"has_larvae" ` - HasPupae omit.Val[bool] `db:"has_pupae" ` - MapZoom omit.Val[float32] `db:"map_zoom" ` - OwnerEmail omit.Val[string] `db:"owner_email" ` - OwnerName omit.Val[string] `db:"owner_name" ` - OwnerPhone omit.Val[string] `db:"owner_phone" ` - PublicID omit.Val[string] `db:"public_id" ` - ReporterEmail omit.Val[string] `db:"reporter_email" ` - ReporterName omit.Val[string] `db:"reporter_name" ` - ReporterPhone omit.Val[string] `db:"reporter_phone" ` - Status omit.Val[enums.PublicreportReportstatustype] `db:"status" ` - OrganizationID omit.Val[int32] `db:"organization_id" ` - HasBackyardPermission omit.Val[bool] `db:"has_backyard_permission" ` - IsReporterConfidential omit.Val[bool] `db:"is_reporter_confidential" ` - IsReporterOwner omit.Val[bool] `db:"is_reporter_owner" ` - ReporterContactConsent omitnull.Val[bool] `db:"reporter_contact_consent" ` - Location omitnull.Val[string] `db:"location" ` - AddressNumber omit.Val[string] `db:"address_number" ` - AddressID omitnull.Val[int32] `db:"address_id" ` - Reviewed omitnull.Val[time.Time] `db:"reviewed" ` - ReviewerID omitnull.Val[int32] `db:"reviewer_id" ` + AccessComments omit.Val[string] `db:"access_comments" ` + AccessGate omit.Val[bool] `db:"access_gate" ` + AccessFence omit.Val[bool] `db:"access_fence" ` + AccessLocked omit.Val[bool] `db:"access_locked" ` + AccessDog omit.Val[bool] `db:"access_dog" ` + AccessOther omit.Val[bool] `db:"access_other" ` + Comments omit.Val[string] `db:"comments" ` + IsReporterConfidential omit.Val[bool] `db:"is_reporter_confidential" ` + IsReporterOwner omit.Val[bool] `db:"is_reporter_owner" ` + HasAdult omit.Val[bool] `db:"has_adult" ` + HasBackyardPermission omit.Val[bool] `db:"has_backyard_permission" ` + HasLarvae omit.Val[bool] `db:"has_larvae" ` + HasPupae omit.Val[bool] `db:"has_pupae" ` + OwnerEmail omit.Val[string] `db:"owner_email" ` + OwnerName omit.Val[string] `db:"owner_name" ` + OwnerPhone omit.Val[string] `db:"owner_phone" ` + ReportID omit.Val[int32] `db:"report_id,pk" ` } func (s PublicreportWaterSetter) SetColumns() []string { - vals := make([]string, 0, 38) - if s.ID.IsValue() { - vals = append(vals, "id") - } + vals := make([]string, 0, 17) if s.AccessComments.IsValue() { vals = append(vals, "access_comments") } @@ -254,45 +157,27 @@ func (s PublicreportWaterSetter) SetColumns() []string { if s.AccessOther.IsValue() { vals = append(vals, "access_other") } - if s.AddressRaw.IsValue() { - vals = append(vals, "address_raw") - } - if s.AddressCountry.IsValue() { - vals = append(vals, "address_country") - } - if s.AddressPostalCode.IsValue() { - vals = append(vals, "address_postal_code") - } - if s.AddressLocality.IsValue() { - vals = append(vals, "address_locality") - } - if s.AddressStreet.IsValue() { - vals = append(vals, "address_street") - } - if s.AddressRegion.IsValue() { - vals = append(vals, "address_region") - } if s.Comments.IsValue() { vals = append(vals, "comments") } - if s.Created.IsValue() { - vals = append(vals, "created") + if s.IsReporterConfidential.IsValue() { + vals = append(vals, "is_reporter_confidential") } - if !s.H3cell.IsUnset() { - vals = append(vals, "h3cell") + if s.IsReporterOwner.IsValue() { + vals = append(vals, "is_reporter_owner") } if s.HasAdult.IsValue() { vals = append(vals, "has_adult") } + if s.HasBackyardPermission.IsValue() { + vals = append(vals, "has_backyard_permission") + } if s.HasLarvae.IsValue() { vals = append(vals, "has_larvae") } if s.HasPupae.IsValue() { vals = append(vals, "has_pupae") } - if s.MapZoom.IsValue() { - vals = append(vals, "map_zoom") - } if s.OwnerEmail.IsValue() { vals = append(vals, "owner_email") } @@ -302,58 +187,13 @@ func (s PublicreportWaterSetter) SetColumns() []string { if s.OwnerPhone.IsValue() { vals = append(vals, "owner_phone") } - if s.PublicID.IsValue() { - vals = append(vals, "public_id") - } - if s.ReporterEmail.IsValue() { - vals = append(vals, "reporter_email") - } - if s.ReporterName.IsValue() { - vals = append(vals, "reporter_name") - } - if s.ReporterPhone.IsValue() { - vals = append(vals, "reporter_phone") - } - if s.Status.IsValue() { - vals = append(vals, "status") - } - if s.OrganizationID.IsValue() { - vals = append(vals, "organization_id") - } - if s.HasBackyardPermission.IsValue() { - vals = append(vals, "has_backyard_permission") - } - if s.IsReporterConfidential.IsValue() { - vals = append(vals, "is_reporter_confidential") - } - if s.IsReporterOwner.IsValue() { - vals = append(vals, "is_reporter_owner") - } - if !s.ReporterContactConsent.IsUnset() { - vals = append(vals, "reporter_contact_consent") - } - if !s.Location.IsUnset() { - vals = append(vals, "location") - } - if s.AddressNumber.IsValue() { - vals = append(vals, "address_number") - } - if !s.AddressID.IsUnset() { - vals = append(vals, "address_id") - } - if !s.Reviewed.IsUnset() { - vals = append(vals, "reviewed") - } - if !s.ReviewerID.IsUnset() { - vals = append(vals, "reviewer_id") + if s.ReportID.IsValue() { + vals = append(vals, "report_id") } return vals } func (s PublicreportWaterSetter) Overwrite(t *PublicreportWater) { - if s.ID.IsValue() { - t.ID = s.ID.MustGet() - } if s.AccessComments.IsValue() { t.AccessComments = s.AccessComments.MustGet() } @@ -372,45 +212,27 @@ func (s PublicreportWaterSetter) Overwrite(t *PublicreportWater) { if s.AccessOther.IsValue() { t.AccessOther = s.AccessOther.MustGet() } - if s.AddressRaw.IsValue() { - t.AddressRaw = s.AddressRaw.MustGet() - } - if s.AddressCountry.IsValue() { - t.AddressCountry = s.AddressCountry.MustGet() - } - if s.AddressPostalCode.IsValue() { - t.AddressPostalCode = s.AddressPostalCode.MustGet() - } - if s.AddressLocality.IsValue() { - t.AddressLocality = s.AddressLocality.MustGet() - } - if s.AddressStreet.IsValue() { - t.AddressStreet = s.AddressStreet.MustGet() - } - if s.AddressRegion.IsValue() { - t.AddressRegion = s.AddressRegion.MustGet() - } if s.Comments.IsValue() { t.Comments = s.Comments.MustGet() } - if s.Created.IsValue() { - t.Created = s.Created.MustGet() + if s.IsReporterConfidential.IsValue() { + t.IsReporterConfidential = s.IsReporterConfidential.MustGet() } - if !s.H3cell.IsUnset() { - t.H3cell = s.H3cell.MustGetNull() + if s.IsReporterOwner.IsValue() { + t.IsReporterOwner = s.IsReporterOwner.MustGet() } if s.HasAdult.IsValue() { t.HasAdult = s.HasAdult.MustGet() } + if s.HasBackyardPermission.IsValue() { + t.HasBackyardPermission = s.HasBackyardPermission.MustGet() + } if s.HasLarvae.IsValue() { t.HasLarvae = s.HasLarvae.MustGet() } if s.HasPupae.IsValue() { t.HasPupae = s.HasPupae.MustGet() } - if s.MapZoom.IsValue() { - t.MapZoom = s.MapZoom.MustGet() - } if s.OwnerEmail.IsValue() { t.OwnerEmail = s.OwnerEmail.MustGet() } @@ -420,50 +242,8 @@ func (s PublicreportWaterSetter) Overwrite(t *PublicreportWater) { if s.OwnerPhone.IsValue() { t.OwnerPhone = s.OwnerPhone.MustGet() } - if s.PublicID.IsValue() { - t.PublicID = s.PublicID.MustGet() - } - if s.ReporterEmail.IsValue() { - t.ReporterEmail = s.ReporterEmail.MustGet() - } - if s.ReporterName.IsValue() { - t.ReporterName = s.ReporterName.MustGet() - } - if s.ReporterPhone.IsValue() { - t.ReporterPhone = s.ReporterPhone.MustGet() - } - if s.Status.IsValue() { - t.Status = s.Status.MustGet() - } - if s.OrganizationID.IsValue() { - t.OrganizationID = s.OrganizationID.MustGet() - } - if s.HasBackyardPermission.IsValue() { - t.HasBackyardPermission = s.HasBackyardPermission.MustGet() - } - if s.IsReporterConfidential.IsValue() { - t.IsReporterConfidential = s.IsReporterConfidential.MustGet() - } - if s.IsReporterOwner.IsValue() { - t.IsReporterOwner = s.IsReporterOwner.MustGet() - } - if !s.ReporterContactConsent.IsUnset() { - t.ReporterContactConsent = s.ReporterContactConsent.MustGetNull() - } - if !s.Location.IsUnset() { - t.Location = s.Location.MustGetNull() - } - if s.AddressNumber.IsValue() { - t.AddressNumber = s.AddressNumber.MustGet() - } - if !s.AddressID.IsUnset() { - t.AddressID = s.AddressID.MustGetNull() - } - if !s.Reviewed.IsUnset() { - t.Reviewed = s.Reviewed.MustGetNull() - } - if !s.ReviewerID.IsUnset() { - t.ReviewerID = s.ReviewerID.MustGetNull() + if s.ReportID.IsValue() { + t.ReportID = s.ReportID.MustGet() } } @@ -473,235 +253,109 @@ func (s *PublicreportWaterSetter) 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, 38) - if s.ID.IsValue() { - vals[0] = psql.Arg(s.ID.MustGet()) + vals := make([]bob.Expression, 17) + if s.AccessComments.IsValue() { + vals[0] = psql.Arg(s.AccessComments.MustGet()) } else { vals[0] = psql.Raw("DEFAULT") } - if s.AccessComments.IsValue() { - vals[1] = psql.Arg(s.AccessComments.MustGet()) + if s.AccessGate.IsValue() { + vals[1] = psql.Arg(s.AccessGate.MustGet()) } else { vals[1] = psql.Raw("DEFAULT") } - if s.AccessGate.IsValue() { - vals[2] = psql.Arg(s.AccessGate.MustGet()) + if s.AccessFence.IsValue() { + vals[2] = psql.Arg(s.AccessFence.MustGet()) } else { vals[2] = psql.Raw("DEFAULT") } - if s.AccessFence.IsValue() { - vals[3] = psql.Arg(s.AccessFence.MustGet()) + if s.AccessLocked.IsValue() { + vals[3] = psql.Arg(s.AccessLocked.MustGet()) } else { vals[3] = psql.Raw("DEFAULT") } - if s.AccessLocked.IsValue() { - vals[4] = psql.Arg(s.AccessLocked.MustGet()) + if s.AccessDog.IsValue() { + vals[4] = psql.Arg(s.AccessDog.MustGet()) } else { vals[4] = psql.Raw("DEFAULT") } - if s.AccessDog.IsValue() { - vals[5] = psql.Arg(s.AccessDog.MustGet()) + if s.AccessOther.IsValue() { + vals[5] = psql.Arg(s.AccessOther.MustGet()) } else { vals[5] = psql.Raw("DEFAULT") } - if s.AccessOther.IsValue() { - vals[6] = psql.Arg(s.AccessOther.MustGet()) + if s.Comments.IsValue() { + vals[6] = psql.Arg(s.Comments.MustGet()) } else { vals[6] = psql.Raw("DEFAULT") } - if s.AddressRaw.IsValue() { - vals[7] = psql.Arg(s.AddressRaw.MustGet()) + if s.IsReporterConfidential.IsValue() { + vals[7] = psql.Arg(s.IsReporterConfidential.MustGet()) } else { vals[7] = psql.Raw("DEFAULT") } - if s.AddressCountry.IsValue() { - vals[8] = psql.Arg(s.AddressCountry.MustGet()) + if s.IsReporterOwner.IsValue() { + vals[8] = psql.Arg(s.IsReporterOwner.MustGet()) } else { vals[8] = psql.Raw("DEFAULT") } - if s.AddressPostalCode.IsValue() { - vals[9] = psql.Arg(s.AddressPostalCode.MustGet()) + if s.HasAdult.IsValue() { + vals[9] = psql.Arg(s.HasAdult.MustGet()) } else { vals[9] = psql.Raw("DEFAULT") } - if s.AddressLocality.IsValue() { - vals[10] = psql.Arg(s.AddressLocality.MustGet()) + if s.HasBackyardPermission.IsValue() { + vals[10] = psql.Arg(s.HasBackyardPermission.MustGet()) } else { vals[10] = psql.Raw("DEFAULT") } - if s.AddressStreet.IsValue() { - vals[11] = psql.Arg(s.AddressStreet.MustGet()) + if s.HasLarvae.IsValue() { + vals[11] = psql.Arg(s.HasLarvae.MustGet()) } else { vals[11] = psql.Raw("DEFAULT") } - if s.AddressRegion.IsValue() { - vals[12] = psql.Arg(s.AddressRegion.MustGet()) + if s.HasPupae.IsValue() { + vals[12] = psql.Arg(s.HasPupae.MustGet()) } else { vals[12] = psql.Raw("DEFAULT") } - if s.Comments.IsValue() { - vals[13] = psql.Arg(s.Comments.MustGet()) + if s.OwnerEmail.IsValue() { + vals[13] = psql.Arg(s.OwnerEmail.MustGet()) } else { vals[13] = psql.Raw("DEFAULT") } - if s.Created.IsValue() { - vals[14] = psql.Arg(s.Created.MustGet()) + if s.OwnerName.IsValue() { + vals[14] = psql.Arg(s.OwnerName.MustGet()) } else { vals[14] = psql.Raw("DEFAULT") } - if !s.H3cell.IsUnset() { - vals[15] = psql.Arg(s.H3cell.MustGetNull()) + if s.OwnerPhone.IsValue() { + vals[15] = psql.Arg(s.OwnerPhone.MustGet()) } else { vals[15] = psql.Raw("DEFAULT") } - if s.HasAdult.IsValue() { - vals[16] = psql.Arg(s.HasAdult.MustGet()) + if s.ReportID.IsValue() { + vals[16] = psql.Arg(s.ReportID.MustGet()) } else { vals[16] = psql.Raw("DEFAULT") } - if s.HasLarvae.IsValue() { - vals[17] = psql.Arg(s.HasLarvae.MustGet()) - } else { - vals[17] = psql.Raw("DEFAULT") - } - - if s.HasPupae.IsValue() { - vals[18] = psql.Arg(s.HasPupae.MustGet()) - } else { - vals[18] = psql.Raw("DEFAULT") - } - - if s.MapZoom.IsValue() { - vals[19] = psql.Arg(s.MapZoom.MustGet()) - } else { - vals[19] = psql.Raw("DEFAULT") - } - - if s.OwnerEmail.IsValue() { - vals[20] = psql.Arg(s.OwnerEmail.MustGet()) - } else { - vals[20] = psql.Raw("DEFAULT") - } - - if s.OwnerName.IsValue() { - vals[21] = psql.Arg(s.OwnerName.MustGet()) - } else { - vals[21] = psql.Raw("DEFAULT") - } - - if s.OwnerPhone.IsValue() { - vals[22] = psql.Arg(s.OwnerPhone.MustGet()) - } else { - vals[22] = psql.Raw("DEFAULT") - } - - if s.PublicID.IsValue() { - vals[23] = psql.Arg(s.PublicID.MustGet()) - } else { - vals[23] = psql.Raw("DEFAULT") - } - - if s.ReporterEmail.IsValue() { - vals[24] = psql.Arg(s.ReporterEmail.MustGet()) - } else { - vals[24] = psql.Raw("DEFAULT") - } - - if s.ReporterName.IsValue() { - vals[25] = psql.Arg(s.ReporterName.MustGet()) - } else { - vals[25] = psql.Raw("DEFAULT") - } - - if s.ReporterPhone.IsValue() { - vals[26] = psql.Arg(s.ReporterPhone.MustGet()) - } else { - vals[26] = psql.Raw("DEFAULT") - } - - if s.Status.IsValue() { - vals[27] = psql.Arg(s.Status.MustGet()) - } else { - vals[27] = psql.Raw("DEFAULT") - } - - if s.OrganizationID.IsValue() { - vals[28] = psql.Arg(s.OrganizationID.MustGet()) - } else { - vals[28] = psql.Raw("DEFAULT") - } - - if s.HasBackyardPermission.IsValue() { - vals[29] = psql.Arg(s.HasBackyardPermission.MustGet()) - } else { - vals[29] = psql.Raw("DEFAULT") - } - - if s.IsReporterConfidential.IsValue() { - vals[30] = psql.Arg(s.IsReporterConfidential.MustGet()) - } else { - vals[30] = psql.Raw("DEFAULT") - } - - if s.IsReporterOwner.IsValue() { - vals[31] = psql.Arg(s.IsReporterOwner.MustGet()) - } else { - vals[31] = psql.Raw("DEFAULT") - } - - if !s.ReporterContactConsent.IsUnset() { - vals[32] = psql.Arg(s.ReporterContactConsent.MustGetNull()) - } else { - vals[32] = psql.Raw("DEFAULT") - } - - if !s.Location.IsUnset() { - vals[33] = psql.Arg(s.Location.MustGetNull()) - } else { - vals[33] = psql.Raw("DEFAULT") - } - - if s.AddressNumber.IsValue() { - vals[34] = psql.Arg(s.AddressNumber.MustGet()) - } else { - vals[34] = psql.Raw("DEFAULT") - } - - if !s.AddressID.IsUnset() { - vals[35] = psql.Arg(s.AddressID.MustGetNull()) - } else { - vals[35] = psql.Raw("DEFAULT") - } - - if !s.Reviewed.IsUnset() { - vals[36] = psql.Arg(s.Reviewed.MustGetNull()) - } else { - vals[36] = psql.Raw("DEFAULT") - } - - if !s.ReviewerID.IsUnset() { - vals[37] = psql.Arg(s.ReviewerID.MustGetNull()) - } else { - vals[37] = psql.Raw("DEFAULT") - } - return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -711,14 +365,7 @@ func (s PublicreportWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 38) - - if s.ID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "id")...), - psql.Arg(s.ID), - }}) - } + exprs := make([]bob.Expression, 0, 17) if s.AccessComments.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -762,48 +409,6 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression }}) } - if s.AddressRaw.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_raw")...), - psql.Arg(s.AddressRaw), - }}) - } - - if s.AddressCountry.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_country")...), - psql.Arg(s.AddressCountry), - }}) - } - - if s.AddressPostalCode.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_postal_code")...), - psql.Arg(s.AddressPostalCode), - }}) - } - - if s.AddressLocality.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_locality")...), - psql.Arg(s.AddressLocality), - }}) - } - - if s.AddressStreet.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_street")...), - psql.Arg(s.AddressStreet), - }}) - } - - if s.AddressRegion.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_region")...), - psql.Arg(s.AddressRegion), - }}) - } - if s.Comments.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "comments")...), @@ -811,17 +416,17 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression }}) } - if s.Created.IsValue() { + if s.IsReporterConfidential.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "created")...), - psql.Arg(s.Created), + psql.Quote(append(prefix, "is_reporter_confidential")...), + psql.Arg(s.IsReporterConfidential), }}) } - if !s.H3cell.IsUnset() { + if s.IsReporterOwner.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "h3cell")...), - psql.Arg(s.H3cell), + psql.Quote(append(prefix, "is_reporter_owner")...), + psql.Arg(s.IsReporterOwner), }}) } @@ -832,6 +437,13 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression }}) } + if s.HasBackyardPermission.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "has_backyard_permission")...), + psql.Arg(s.HasBackyardPermission), + }}) + } + if s.HasLarvae.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "has_larvae")...), @@ -846,13 +458,6 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression }}) } - if s.MapZoom.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "map_zoom")...), - psql.Arg(s.MapZoom), - }}) - } - if s.OwnerEmail.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ psql.Quote(append(prefix, "owner_email")...), @@ -874,108 +479,10 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression }}) } - if s.PublicID.IsValue() { + if s.ReportID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "public_id")...), - psql.Arg(s.PublicID), - }}) - } - - if s.ReporterEmail.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_email")...), - psql.Arg(s.ReporterEmail), - }}) - } - - if s.ReporterName.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_name")...), - psql.Arg(s.ReporterName), - }}) - } - - if s.ReporterPhone.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_phone")...), - psql.Arg(s.ReporterPhone), - }}) - } - - if s.Status.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "status")...), - psql.Arg(s.Status), - }}) - } - - if s.OrganizationID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "organization_id")...), - psql.Arg(s.OrganizationID), - }}) - } - - if s.HasBackyardPermission.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "has_backyard_permission")...), - psql.Arg(s.HasBackyardPermission), - }}) - } - - if s.IsReporterConfidential.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "is_reporter_confidential")...), - psql.Arg(s.IsReporterConfidential), - }}) - } - - if s.IsReporterOwner.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "is_reporter_owner")...), - psql.Arg(s.IsReporterOwner), - }}) - } - - if !s.ReporterContactConsent.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reporter_contact_consent")...), - psql.Arg(s.ReporterContactConsent), - }}) - } - - if !s.Location.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "location")...), - psql.Arg(s.Location), - }}) - } - - if s.AddressNumber.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_number")...), - psql.Arg(s.AddressNumber), - }}) - } - - if !s.AddressID.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_id")...), - psql.Arg(s.AddressID), - }}) - } - - if !s.Reviewed.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reviewed")...), - psql.Arg(s.Reviewed), - }}) - } - - if !s.ReviewerID.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "reviewer_id")...), - psql.Arg(s.ReviewerID), + psql.Quote(append(prefix, "report_id")...), + psql.Arg(s.ReportID), }}) } @@ -984,23 +491,23 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression // FindPublicreportWater retrieves a single record by primary key // If cols is empty Find will return all columns. -func FindPublicreportWater(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportWater, error) { +func FindPublicreportWater(ctx context.Context, exec bob.Executor, ReportIDPK int32, cols ...string) (*PublicreportWater, error) { if len(cols) == 0 { return PublicreportWaters.Query( - sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(PublicreportWaters.Columns.ReportID.EQ(psql.Arg(ReportIDPK))), ).One(ctx, exec) } return PublicreportWaters.Query( - sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(PublicreportWaters.Columns.ReportID.EQ(psql.Arg(ReportIDPK))), sm.Columns(PublicreportWaters.Columns.Only(cols...)), ).One(ctx, exec) } // PublicreportWaterExists checks the presence of a single record by primary key -func PublicreportWaterExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { +func PublicreportWaterExists(ctx context.Context, exec bob.Executor, ReportIDPK int32) (bool, error) { return PublicreportWaters.Query( - sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(PublicreportWaters.Columns.ReportID.EQ(psql.Arg(ReportIDPK))), ).Exists(ctx, exec) } @@ -1024,11 +531,11 @@ func (o *PublicreportWater) AfterQueryHook(ctx context.Context, exec bob.Executo // primaryKeyVals returns the primary key values of the PublicreportWater func (o *PublicreportWater) primaryKeyVals() bob.Expression { - return psql.Arg(o.ID) + return psql.Arg(o.ReportID) } func (o *PublicreportWater) pkEQ() dialect.Expression { - return psql.Quote("publicreport.water", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return psql.Quote("publicreport.water", "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) })) } @@ -1055,7 +562,7 @@ func (o *PublicreportWater) Delete(ctx context.Context, exec bob.Executor) error // Reload refreshes the PublicreportWater using the executor func (o *PublicreportWater) Reload(ctx context.Context, exec bob.Executor) error { o2, err := PublicreportWaters.Query( - sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(o.ID))), + sm.Where(PublicreportWaters.Columns.ReportID.EQ(psql.Arg(o.ReportID))), ).One(ctx, exec) if err != nil { return err @@ -1089,7 +596,7 @@ func (o PublicreportWaterSlice) pkIN() dialect.Expression { return psql.Raw("NULL") } - return psql.Quote("publicreport.water", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return psql.Quote("publicreport.water", "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() @@ -1104,7 +611,7 @@ func (o PublicreportWaterSlice) pkIN() dialect.Expression { func (o PublicreportWaterSlice) copyMatchingRows(from ...*PublicreportWater) { for i, old := range o { for _, new := range from { - if new.ID != old.ID { + if new.ReportID != old.ReportID { continue } new.R = old.R @@ -1205,539 +712,96 @@ func (o PublicreportWaterSlice) ReloadAll(ctx context.Context, exec bob.Executor return nil } -// NotifyEmailWaters starts a query for related objects on publicreport.notify_email_water -func (o *PublicreportWater) NotifyEmailWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWatersQuery { - return PublicreportNotifyEmailWaters.Query(append(mods, - sm.Where(PublicreportNotifyEmailWaters.Columns.WaterID.EQ(psql.Arg(o.ID))), +// Report starts a query for related objects on publicreport.report +func (o *PublicreportWater) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery { + return PublicreportReports.Query(append(mods, + sm.Where(PublicreportReports.Columns.ID.EQ(psql.Arg(o.ReportID))), )...) } -func (os PublicreportWaterSlice) NotifyEmailWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWatersQuery { - pkID := make(pgtypes.Array[int32], 0, len(os)) +func (os PublicreportWaterSlice) Report(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery { + pkReportID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { continue } - pkID = append(pkID, o.ID) + pkReportID = append(pkReportID, o.ReportID) } PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + psql.F("unnest", psql.Cast(psql.Arg(pkReportID), "integer[]")), )) - return PublicreportNotifyEmailWaters.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyEmailWaters.Columns.WaterID).OP("IN", PKArgExpr)), + return PublicreportReports.Query(append(mods, + sm.Where(psql.Group(PublicreportReports.Columns.ID).OP("IN", PKArgExpr)), )...) } -// NotifyPhoneWaters starts a query for related objects on publicreport.notify_phone_water -func (o *PublicreportWater) NotifyPhoneWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWatersQuery { - return PublicreportNotifyPhoneWaters.Query(append(mods, - sm.Where(PublicreportNotifyPhoneWaters.Columns.WaterID.EQ(psql.Arg(o.ID))), - )...) -} - -func (os PublicreportWaterSlice) NotifyPhoneWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWatersQuery { - 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 PublicreportNotifyPhoneWaters.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyPhoneWaters.Columns.WaterID).OP("IN", PKArgExpr)), - )...) -} - -// Address starts a query for related objects on address -func (o *PublicreportWater) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { - return Addresses.Query(append(mods, - sm.Where(Addresses.Columns.ID.EQ(psql.Arg(o.AddressID))), - )...) -} - -func (os PublicreportWaterSlice) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { - pkAddressID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkAddressID = append(pkAddressID, o.AddressID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkAddressID), "integer[]")), - )) - - return Addresses.Query(append(mods, - sm.Where(psql.Group(Addresses.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// Organization starts a query for related objects on organization -func (o *PublicreportWater) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { - return Organizations.Query(append(mods, - sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), - )...) -} - -func (os PublicreportWaterSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { - pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkOrganizationID = append(pkOrganizationID, o.OrganizationID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), - )) - - return Organizations.Query(append(mods, - sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// ReviewerUser starts a query for related objects on user_ -func (o *PublicreportWater) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - return Users.Query(append(mods, - sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))), - )...) -} - -func (os PublicreportWaterSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkReviewerID = append(pkReviewerID, o.ReviewerID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")), - )) - - return Users.Query(append(mods, - sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// Images starts a query for related objects on publicreport.image -func (o *PublicreportWater) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { - return PublicreportImages.Query(append(mods, - sm.InnerJoin(PublicreportWaterImages.NameAs()).On( - PublicreportImages.Columns.ID.EQ(PublicreportWaterImages.Columns.ImageID)), - sm.Where(PublicreportWaterImages.Columns.WaterID.EQ(psql.Arg(o.ID))), - )...) -} - -func (os PublicreportWaterSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { - 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 PublicreportImages.Query(append(mods, - sm.InnerJoin(PublicreportWaterImages.NameAs()).On( - PublicreportImages.Columns.ID.EQ(PublicreportWaterImages.Columns.ImageID), - ), - sm.Where(psql.Group(PublicreportWaterImages.Columns.WaterID).OP("IN", PKArgExpr)), - )...) -} - -func insertPublicreportWaterNotifyEmailWaters0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailWaters1 []*PublicreportNotifyEmailWaterSetter, publicreportWater0 *PublicreportWater) (PublicreportNotifyEmailWaterSlice, error) { - for i := range publicreportNotifyEmailWaters1 { - publicreportNotifyEmailWaters1[i].WaterID = omit.From(publicreportWater0.ID) - } - - ret, err := PublicreportNotifyEmailWaters.Insert(bob.ToMods(publicreportNotifyEmailWaters1...)).All(ctx, exec) - if err != nil { - return ret, fmt.Errorf("insertPublicreportWaterNotifyEmailWaters0: %w", err) - } - - return ret, nil -} - -func attachPublicreportWaterNotifyEmailWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaters1 PublicreportNotifyEmailWaterSlice, publicreportWater0 *PublicreportWater) (PublicreportNotifyEmailWaterSlice, error) { - setter := &PublicreportNotifyEmailWaterSetter{ - WaterID: omit.From(publicreportWater0.ID), - } - - err := publicreportNotifyEmailWaters1.UpdateAll(ctx, exec, *setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportWaterNotifyEmailWaters0: %w", err) - } - - return publicreportNotifyEmailWaters1, nil -} - -func (publicreportWater0 *PublicreportWater) InsertNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - publicreportNotifyEmailWaters1, err := insertPublicreportWaterNotifyEmailWaters0(ctx, exec, related, publicreportWater0) - if err != nil { - return err - } - - publicreportWater0.R.NotifyEmailWaters = append(publicreportWater0.R.NotifyEmailWaters, publicreportNotifyEmailWaters1...) - - for _, rel := range publicreportNotifyEmailWaters1 { - rel.R.Water = publicreportWater0 - } - return nil -} - -func (publicreportWater0 *PublicreportWater) AttachNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWater) error { - if len(related) == 0 { - return nil - } - - var err error - publicreportNotifyEmailWaters1 := PublicreportNotifyEmailWaterSlice(related) - - _, err = attachPublicreportWaterNotifyEmailWaters0(ctx, exec, len(related), publicreportNotifyEmailWaters1, publicreportWater0) - if err != nil { - return err - } - - publicreportWater0.R.NotifyEmailWaters = append(publicreportWater0.R.NotifyEmailWaters, publicreportNotifyEmailWaters1...) - - for _, rel := range related { - rel.R.Water = publicreportWater0 - } - - return nil -} - -func insertPublicreportWaterNotifyPhoneWaters0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneWaters1 []*PublicreportNotifyPhoneWaterSetter, publicreportWater0 *PublicreportWater) (PublicreportNotifyPhoneWaterSlice, error) { - for i := range publicreportNotifyPhoneWaters1 { - publicreportNotifyPhoneWaters1[i].WaterID = omit.From(publicreportWater0.ID) - } - - ret, err := PublicreportNotifyPhoneWaters.Insert(bob.ToMods(publicreportNotifyPhoneWaters1...)).All(ctx, exec) - if err != nil { - return ret, fmt.Errorf("insertPublicreportWaterNotifyPhoneWaters0: %w", err) - } - - return ret, nil -} - -func attachPublicreportWaterNotifyPhoneWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaters1 PublicreportNotifyPhoneWaterSlice, publicreportWater0 *PublicreportWater) (PublicreportNotifyPhoneWaterSlice, error) { - setter := &PublicreportNotifyPhoneWaterSetter{ - WaterID: omit.From(publicreportWater0.ID), - } - - err := publicreportNotifyPhoneWaters1.UpdateAll(ctx, exec, *setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportWaterNotifyPhoneWaters0: %w", err) - } - - return publicreportNotifyPhoneWaters1, nil -} - -func (publicreportWater0 *PublicreportWater) InsertNotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - publicreportNotifyPhoneWaters1, err := insertPublicreportWaterNotifyPhoneWaters0(ctx, exec, related, publicreportWater0) - if err != nil { - return err - } - - publicreportWater0.R.NotifyPhoneWaters = append(publicreportWater0.R.NotifyPhoneWaters, publicreportNotifyPhoneWaters1...) - - for _, rel := range publicreportNotifyPhoneWaters1 { - rel.R.Water = publicreportWater0 - } - return nil -} - -func (publicreportWater0 *PublicreportWater) AttachNotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWater) error { - if len(related) == 0 { - return nil - } - - var err error - publicreportNotifyPhoneWaters1 := PublicreportNotifyPhoneWaterSlice(related) - - _, err = attachPublicreportWaterNotifyPhoneWaters0(ctx, exec, len(related), publicreportNotifyPhoneWaters1, publicreportWater0) - if err != nil { - return err - } - - publicreportWater0.R.NotifyPhoneWaters = append(publicreportWater0.R.NotifyPhoneWaters, publicreportNotifyPhoneWaters1...) - - for _, rel := range related { - rel.R.Water = publicreportWater0 - } - - return nil -} - -func attachPublicreportWaterAddress0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, address1 *Address) (*PublicreportWater, error) { +func attachPublicreportWaterReport0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, publicreportReport1 *PublicreportReport) (*PublicreportWater, error) { setter := &PublicreportWaterSetter{ - AddressID: omitnull.From(address1.ID), + ReportID: omit.From(publicreportReport1.ID), } err := publicreportWater0.Update(ctx, exec, setter) if err != nil { - return nil, fmt.Errorf("attachPublicreportWaterAddress0: %w", err) + return nil, fmt.Errorf("attachPublicreportWaterReport0: %w", err) } return publicreportWater0, nil } -func (publicreportWater0 *PublicreportWater) InsertAddress(ctx context.Context, exec bob.Executor, related *AddressSetter) error { +func (publicreportWater0 *PublicreportWater) InsertReport(ctx context.Context, exec bob.Executor, related *PublicreportReportSetter) error { var err error - address1, err := Addresses.Insert(related).One(ctx, exec) + publicreportReport1, err := PublicreportReports.Insert(related).One(ctx, exec) if err != nil { return fmt.Errorf("inserting related objects: %w", err) } - _, err = attachPublicreportWaterAddress0(ctx, exec, 1, publicreportWater0, address1) + _, err = attachPublicreportWaterReport0(ctx, exec, 1, publicreportWater0, publicreportReport1) if err != nil { return err } - publicreportWater0.R.Address = address1 + publicreportWater0.R.Report = publicreportReport1 - address1.R.Waters = append(address1.R.Waters, publicreportWater0) + publicreportReport1.R.Water = publicreportWater0 return nil } -func (publicreportWater0 *PublicreportWater) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { +func (publicreportWater0 *PublicreportWater) AttachReport(ctx context.Context, exec bob.Executor, publicreportReport1 *PublicreportReport) error { var err error - _, err = attachPublicreportWaterAddress0(ctx, exec, 1, publicreportWater0, address1) + _, err = attachPublicreportWaterReport0(ctx, exec, 1, publicreportWater0, publicreportReport1) if err != nil { return err } - publicreportWater0.R.Address = address1 + publicreportWater0.R.Report = publicreportReport1 - address1.R.Waters = append(address1.R.Waters, publicreportWater0) - - return nil -} - -func attachPublicreportWaterOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, organization1 *Organization) (*PublicreportWater, error) { - setter := &PublicreportWaterSetter{ - OrganizationID: omit.From(organization1.ID), - } - - err := publicreportWater0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportWaterOrganization0: %w", err) - } - - return publicreportWater0, nil -} - -func (publicreportWater0 *PublicreportWater) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { - var err error - - organization1, err := Organizations.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportWaterOrganization0(ctx, exec, 1, publicreportWater0, organization1) - if err != nil { - return err - } - - publicreportWater0.R.Organization = organization1 - - organization1.R.Waters = append(organization1.R.Waters, publicreportWater0) - - return nil -} - -func (publicreportWater0 *PublicreportWater) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { - var err error - - _, err = attachPublicreportWaterOrganization0(ctx, exec, 1, publicreportWater0, organization1) - if err != nil { - return err - } - - publicreportWater0.R.Organization = organization1 - - organization1.R.Waters = append(organization1.R.Waters, publicreportWater0) - - return nil -} - -func attachPublicreportWaterReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, user1 *User) (*PublicreportWater, error) { - setter := &PublicreportWaterSetter{ - ReviewerID: omitnull.From(user1.ID), - } - - err := publicreportWater0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportWaterReviewerUser0: %w", err) - } - - return publicreportWater0, nil -} - -func (publicreportWater0 *PublicreportWater) InsertReviewerUser(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 = attachPublicreportWaterReviewerUser0(ctx, exec, 1, publicreportWater0, user1) - if err != nil { - return err - } - - publicreportWater0.R.ReviewerUser = user1 - - user1.R.ReviewerWaters = append(user1.R.ReviewerWaters, publicreportWater0) - - return nil -} - -func (publicreportWater0 *PublicreportWater) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error { - var err error - - _, err = attachPublicreportWaterReviewerUser0(ctx, exec, 1, publicreportWater0, user1) - if err != nil { - return err - } - - publicreportWater0.R.ReviewerUser = user1 - - user1.R.ReviewerWaters = append(user1.R.ReviewerWaters, publicreportWater0) - - return nil -} - -func attachPublicreportWaterImages0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, publicreportImages2 PublicreportImageSlice) (PublicreportWaterImageSlice, error) { - setters := make([]*PublicreportWaterImageSetter, count) - for i := range count { - setters[i] = &PublicreportWaterImageSetter{ - WaterID: omit.From(publicreportWater0.ID), - ImageID: omit.From(publicreportImages2[i].ID), - } - } - - publicreportWaterImages1, err := PublicreportWaterImages.Insert(bob.ToMods(setters...)).All(ctx, exec) - if err != nil { - return nil, fmt.Errorf("attachPublicreportWaterImages0: %w", err) - } - - return publicreportWaterImages1, nil -} - -func (publicreportWater0 *PublicreportWater) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - publicreportImages2 := PublicreportImageSlice(inserted) - - _, err = attachPublicreportWaterImages0(ctx, exec, len(related), publicreportWater0, publicreportImages2) - if err != nil { - return err - } - - publicreportWater0.R.Images = append(publicreportWater0.R.Images, publicreportImages2...) - - for _, rel := range publicreportImages2 { - rel.R.Waters = append(rel.R.Waters, publicreportWater0) - } - return nil -} - -func (publicreportWater0 *PublicreportWater) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { - if len(related) == 0 { - return nil - } - - var err error - publicreportImages2 := PublicreportImageSlice(related) - - _, err = attachPublicreportWaterImages0(ctx, exec, len(related), publicreportWater0, publicreportImages2) - if err != nil { - return err - } - - publicreportWater0.R.Images = append(publicreportWater0.R.Images, publicreportImages2...) - - for _, rel := range related { - rel.R.Waters = append(rel.R.Waters, publicreportWater0) - } + publicreportReport1.R.Water = publicreportWater0 return nil } type publicreportWaterWhere[Q psql.Filterable] struct { - ID psql.WhereMod[Q, int32] AccessComments psql.WhereMod[Q, string] AccessGate psql.WhereMod[Q, bool] AccessFence psql.WhereMod[Q, bool] AccessLocked psql.WhereMod[Q, bool] AccessDog psql.WhereMod[Q, bool] AccessOther psql.WhereMod[Q, bool] - AddressRaw psql.WhereMod[Q, string] - AddressCountry psql.WhereMod[Q, string] - AddressPostalCode psql.WhereMod[Q, string] - AddressLocality psql.WhereMod[Q, string] - AddressStreet psql.WhereMod[Q, string] - AddressRegion psql.WhereMod[Q, string] Comments psql.WhereMod[Q, string] - Created psql.WhereMod[Q, time.Time] - H3cell psql.WhereNullMod[Q, string] + IsReporterConfidential psql.WhereMod[Q, bool] + IsReporterOwner psql.WhereMod[Q, bool] HasAdult psql.WhereMod[Q, bool] + HasBackyardPermission psql.WhereMod[Q, bool] HasLarvae psql.WhereMod[Q, bool] HasPupae psql.WhereMod[Q, bool] - MapZoom psql.WhereMod[Q, float32] OwnerEmail psql.WhereMod[Q, string] OwnerName psql.WhereMod[Q, string] OwnerPhone psql.WhereMod[Q, string] - PublicID psql.WhereMod[Q, string] - ReporterEmail psql.WhereMod[Q, string] - ReporterName psql.WhereMod[Q, string] - ReporterPhone psql.WhereMod[Q, string] - Status psql.WhereMod[Q, enums.PublicreportReportstatustype] - OrganizationID psql.WhereMod[Q, int32] - HasBackyardPermission psql.WhereMod[Q, bool] - IsReporterConfidential psql.WhereMod[Q, bool] - IsReporterOwner psql.WhereMod[Q, bool] - ReporterContactConsent psql.WhereNullMod[Q, bool] - Location psql.WhereNullMod[Q, string] - AddressNumber psql.WhereMod[Q, string] - AddressID psql.WhereNullMod[Q, int32] - Reviewed psql.WhereNullMod[Q, time.Time] - ReviewerID psql.WhereNullMod[Q, int32] + ReportID psql.WhereMod[Q, int32] } func (publicreportWaterWhere[Q]) AliasedAs(alias string) publicreportWaterWhere[Q] { @@ -1746,44 +810,23 @@ func (publicreportWaterWhere[Q]) AliasedAs(alias string) publicreportWaterWhere[ func buildPublicreportWaterWhere[Q psql.Filterable](cols publicreportWaterColumns) publicreportWaterWhere[Q] { return publicreportWaterWhere[Q]{ - ID: psql.Where[Q, int32](cols.ID), AccessComments: psql.Where[Q, string](cols.AccessComments), AccessGate: psql.Where[Q, bool](cols.AccessGate), AccessFence: psql.Where[Q, bool](cols.AccessFence), AccessLocked: psql.Where[Q, bool](cols.AccessLocked), AccessDog: psql.Where[Q, bool](cols.AccessDog), AccessOther: psql.Where[Q, bool](cols.AccessOther), - AddressRaw: psql.Where[Q, string](cols.AddressRaw), - AddressCountry: psql.Where[Q, string](cols.AddressCountry), - AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), - AddressLocality: psql.Where[Q, string](cols.AddressLocality), - AddressStreet: psql.Where[Q, string](cols.AddressStreet), - AddressRegion: psql.Where[Q, string](cols.AddressRegion), Comments: psql.Where[Q, string](cols.Comments), - Created: psql.Where[Q, time.Time](cols.Created), - H3cell: psql.WhereNull[Q, string](cols.H3cell), + IsReporterConfidential: psql.Where[Q, bool](cols.IsReporterConfidential), + IsReporterOwner: psql.Where[Q, bool](cols.IsReporterOwner), HasAdult: psql.Where[Q, bool](cols.HasAdult), + HasBackyardPermission: psql.Where[Q, bool](cols.HasBackyardPermission), HasLarvae: psql.Where[Q, bool](cols.HasLarvae), HasPupae: psql.Where[Q, bool](cols.HasPupae), - MapZoom: psql.Where[Q, float32](cols.MapZoom), OwnerEmail: psql.Where[Q, string](cols.OwnerEmail), OwnerName: psql.Where[Q, string](cols.OwnerName), OwnerPhone: psql.Where[Q, string](cols.OwnerPhone), - PublicID: psql.Where[Q, string](cols.PublicID), - ReporterEmail: psql.Where[Q, string](cols.ReporterEmail), - ReporterName: psql.Where[Q, string](cols.ReporterName), - ReporterPhone: psql.Where[Q, string](cols.ReporterPhone), - Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status), - OrganizationID: psql.Where[Q, int32](cols.OrganizationID), - HasBackyardPermission: psql.Where[Q, bool](cols.HasBackyardPermission), - IsReporterConfidential: psql.Where[Q, bool](cols.IsReporterConfidential), - IsReporterOwner: psql.Where[Q, bool](cols.IsReporterOwner), - ReporterContactConsent: psql.WhereNull[Q, bool](cols.ReporterContactConsent), - Location: psql.WhereNull[Q, string](cols.Location), - AddressNumber: psql.Where[Q, string](cols.AddressNumber), - AddressID: psql.WhereNull[Q, int32](cols.AddressID), - Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed), - ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID), + ReportID: psql.Where[Q, int32](cols.ReportID), } } @@ -1793,82 +836,16 @@ func (o *PublicreportWater) Preload(name string, retrieved any) error { } switch name { - case "NotifyEmailWaters": - rels, ok := retrieved.(PublicreportNotifyEmailWaterSlice) + case "Report": + rel, ok := retrieved.(*PublicreportReport) if !ok { return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) } - o.R.NotifyEmailWaters = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Water = o - } - } - return nil - case "NotifyPhoneWaters": - rels, ok := retrieved.(PublicreportNotifyPhoneWaterSlice) - if !ok { - return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) - } - - o.R.NotifyPhoneWaters = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Water = o - } - } - return nil - case "Address": - rel, ok := retrieved.(*Address) - if !ok { - return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) - } - - o.R.Address = rel + o.R.Report = rel if rel != nil { - rel.R.Waters = PublicreportWaterSlice{o} - } - return nil - case "Organization": - rel, ok := retrieved.(*Organization) - if !ok { - return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) - } - - o.R.Organization = rel - - if rel != nil { - rel.R.Waters = PublicreportWaterSlice{o} - } - return nil - case "ReviewerUser": - rel, ok := retrieved.(*User) - if !ok { - return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) - } - - o.R.ReviewerUser = rel - - if rel != nil { - rel.R.ReviewerWaters = PublicreportWaterSlice{o} - } - return nil - case "Images": - rels, ok := retrieved.(PublicreportImageSlice) - if !ok { - return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) - } - - o.R.Images = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Waters = PublicreportWaterSlice{o} - } + rel.R.Water = o } return nil default: @@ -1877,153 +854,73 @@ func (o *PublicreportWater) Preload(name string, retrieved any) error { } type publicreportWaterPreloader struct { - Address func(...psql.PreloadOption) psql.Preloader - Organization func(...psql.PreloadOption) psql.Preloader - ReviewerUser func(...psql.PreloadOption) psql.Preloader + Report func(...psql.PreloadOption) psql.Preloader } func buildPublicreportWaterPreloader() publicreportWaterPreloader { return publicreportWaterPreloader{ - Address: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*Address, AddressSlice](psql.PreloadRel{ - Name: "Address", + Report: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*PublicreportReport, PublicreportReportSlice](psql.PreloadRel{ + Name: "Report", Sides: []psql.PreloadSide{ { From: PublicreportWaters, - To: Addresses, - FromColumns: []string{"address_id"}, + To: PublicreportReports, + FromColumns: []string{"report_id"}, ToColumns: []string{"id"}, }, }, - }, Addresses.Columns.Names(), opts...) - }, - Organization: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ - Name: "Organization", - Sides: []psql.PreloadSide{ - { - From: PublicreportWaters, - To: Organizations, - FromColumns: []string{"organization_id"}, - ToColumns: []string{"id"}, - }, - }, - }, Organizations.Columns.Names(), opts...) - }, - ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*User, UserSlice](psql.PreloadRel{ - Name: "ReviewerUser", - Sides: []psql.PreloadSide{ - { - From: PublicreportWaters, - To: Users, - FromColumns: []string{"reviewer_id"}, - ToColumns: []string{"id"}, - }, - }, - }, Users.Columns.Names(), opts...) + }, PublicreportReports.Columns.Names(), opts...) }, } } type publicreportWaterThenLoader[Q orm.Loadable] struct { - NotifyEmailWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - NotifyPhoneWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Report func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildPublicreportWaterThenLoader[Q orm.Loadable]() publicreportWaterThenLoader[Q] { - type NotifyEmailWatersLoadInterface interface { - LoadNotifyEmailWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type NotifyPhoneWatersLoadInterface interface { - LoadNotifyPhoneWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type AddressLoadInterface interface { - LoadAddress(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type OrganizationLoadInterface interface { - LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type ReviewerUserLoadInterface interface { - LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type ImagesLoadInterface interface { - LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type ReportLoadInterface interface { + LoadReport(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } return publicreportWaterThenLoader[Q]{ - NotifyEmailWaters: thenLoadBuilder[Q]( - "NotifyEmailWaters", - func(ctx context.Context, exec bob.Executor, retrieved NotifyEmailWatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadNotifyEmailWaters(ctx, exec, mods...) - }, - ), - NotifyPhoneWaters: thenLoadBuilder[Q]( - "NotifyPhoneWaters", - func(ctx context.Context, exec bob.Executor, retrieved NotifyPhoneWatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadNotifyPhoneWaters(ctx, exec, mods...) - }, - ), - Address: thenLoadBuilder[Q]( - "Address", - func(ctx context.Context, exec bob.Executor, retrieved AddressLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadAddress(ctx, exec, mods...) - }, - ), - Organization: thenLoadBuilder[Q]( - "Organization", - func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadOrganization(ctx, exec, mods...) - }, - ), - ReviewerUser: thenLoadBuilder[Q]( - "ReviewerUser", - func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadReviewerUser(ctx, exec, mods...) - }, - ), - Images: thenLoadBuilder[Q]( - "Images", - func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadImages(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...) }, ), } } -// LoadNotifyEmailWaters loads the publicreportWater's NotifyEmailWaters into the .R struct -func (o *PublicreportWater) LoadNotifyEmailWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReport loads the publicreportWater's Report into the .R struct +func (o *PublicreportWater) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } // Reset the relationship - o.R.NotifyEmailWaters = nil + o.R.Report = nil - related, err := o.NotifyEmailWaters(mods...).All(ctx, exec) + related, err := o.Report(mods...).One(ctx, exec) if err != nil { return err } - for _, rel := range related { - rel.R.Water = o - } + related.R.Water = o - o.R.NotifyEmailWaters = related + o.R.Report = related return nil } -// LoadNotifyEmailWaters loads the publicreportWater's NotifyEmailWaters into the .R struct -func (os PublicreportWaterSlice) LoadNotifyEmailWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReport loads the publicreportWater's Report into the .R struct +func (os PublicreportWaterSlice) LoadReport(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } - publicreportNotifyEmailWaters, err := os.NotifyEmailWaters(mods...).All(ctx, exec) + publicreportReports, err := os.Report(mods...).All(ctx, exec) if err != nil { return err } @@ -2033,329 +930,18 @@ func (os PublicreportWaterSlice) LoadNotifyEmailWaters(ctx context.Context, exec continue } - o.R.NotifyEmailWaters = nil - } + for _, rel := range publicreportReports { - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportNotifyEmailWaters { - - if !(o.ID == rel.WaterID) { + if !(o.ReportID == rel.ID) { continue } rel.R.Water = o - o.R.NotifyEmailWaters = append(o.R.NotifyEmailWaters, rel) - } - } - - return nil -} - -// LoadNotifyPhoneWaters loads the publicreportWater's NotifyPhoneWaters into the .R struct -func (o *PublicreportWater) LoadNotifyPhoneWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.NotifyPhoneWaters = nil - - related, err := o.NotifyPhoneWaters(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, rel := range related { - rel.R.Water = o - } - - o.R.NotifyPhoneWaters = related - return nil -} - -// LoadNotifyPhoneWaters loads the publicreportWater's NotifyPhoneWaters into the .R struct -func (os PublicreportWaterSlice) LoadNotifyPhoneWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - publicreportNotifyPhoneWaters, err := os.NotifyPhoneWaters(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - o.R.NotifyPhoneWaters = nil - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportNotifyPhoneWaters { - - if !(o.ID == rel.WaterID) { - continue - } - - rel.R.Water = o - - o.R.NotifyPhoneWaters = append(o.R.NotifyPhoneWaters, rel) - } - } - - return nil -} - -// LoadAddress loads the publicreportWater's Address into the .R struct -func (o *PublicreportWater) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Address = nil - - related, err := o.Address(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.Waters = PublicreportWaterSlice{o} - - o.R.Address = related - return nil -} - -// LoadAddress loads the publicreportWater's Address into the .R struct -func (os PublicreportWaterSlice) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - addresses, err := os.Address(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range addresses { - if !o.AddressID.IsValue() { - continue - } - - if !(o.AddressID.IsValue() && o.AddressID.MustGet() == rel.ID) { - continue - } - - rel.R.Waters = append(rel.R.Waters, o) - - o.R.Address = rel + o.R.Report = rel break } } return nil } - -// LoadOrganization loads the publicreportWater's Organization into the .R struct -func (o *PublicreportWater) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Organization = nil - - related, err := o.Organization(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.Waters = PublicreportWaterSlice{o} - - o.R.Organization = related - return nil -} - -// LoadOrganization loads the publicreportWater's Organization into the .R struct -func (os PublicreportWaterSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - organizations, err := os.Organization(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range organizations { - - if !(o.OrganizationID == rel.ID) { - continue - } - - rel.R.Waters = append(rel.R.Waters, o) - - o.R.Organization = rel - break - } - } - - return nil -} - -// LoadReviewerUser loads the publicreportWater's ReviewerUser into the .R struct -func (o *PublicreportWater) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.ReviewerUser = nil - - related, err := o.ReviewerUser(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.ReviewerWaters = PublicreportWaterSlice{o} - - o.R.ReviewerUser = related - return nil -} - -// LoadReviewerUser loads the publicreportWater's ReviewerUser into the .R struct -func (os PublicreportWaterSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - users, err := os.ReviewerUser(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range users { - if !o.ReviewerID.IsValue() { - continue - } - - if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) { - continue - } - - rel.R.ReviewerWaters = append(rel.R.ReviewerWaters, o) - - o.R.ReviewerUser = rel - break - } - } - - return nil -} - -// LoadImages loads the publicreportWater's Images into the .R struct -func (o *PublicreportWater) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Images = nil - - related, err := o.Images(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, rel := range related { - rel.R.Waters = PublicreportWaterSlice{o} - } - - o.R.Images = related - return nil -} - -// LoadImages loads the publicreportWater's Images into the .R struct -func (os PublicreportWaterSlice) LoadImages(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(PublicreportImages.Columns)) - } - - q := os.Images(append( - mods, - sm.Columns(PublicreportWaterImages.Columns.WaterID.As("related_publicreport.water.ID")), - )...) - - IDSlice := []int32{} - - mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), 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.water.ID", &IDSlice[len(IDSlice)-1]) - - return nil, nil - }, - func(any, any) error { - return nil - } - }) - - publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper) - if err != nil { - return err - } - - for _, o := range os { - o.R.Images = nil - } - - for _, o := range os { - for i, rel := range publicreportImages { - if !(o.ID == IDSlice[i]) { - continue - } - - rel.R.Waters = append(rel.R.Waters, o) - - o.R.Images = append(o.R.Images, rel) - } - } - - return nil -} diff --git a/db/models/publicreport.water_image.bob.go b/db/models/publicreport.water_image.bob.go deleted file mode 100644 index 924f7c68..00000000 --- a/db/models/publicreport.water_image.bob.go +++ /dev/null @@ -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 -} diff --git a/db/models/publicreport.water_image_old.bob.go b/db/models/publicreport.water_image_old.bob.go new file mode 100644 index 00000000..b99ffcd6 --- /dev/null +++ b/db/models/publicreport.water_image_old.bob.go @@ -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 +} diff --git a/db/models/publicreport.water_old.bob.go b/db/models/publicreport.water_old.bob.go new file mode 100644 index 00000000..02f6626d --- /dev/null +++ b/db/models/publicreport.water_old.bob.go @@ -0,0 +1,2361 @@ +// 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" + enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/scan" +) + +// PublicreportWaterOld is an object representing the database table. +type PublicreportWaterOld struct { + ID int32 `db:"id,pk" ` + AccessComments string `db:"access_comments" ` + AccessGate bool `db:"access_gate" ` + AccessFence bool `db:"access_fence" ` + AccessLocked bool `db:"access_locked" ` + AccessDog bool `db:"access_dog" ` + AccessOther bool `db:"access_other" ` + AddressRaw string `db:"address_raw" ` + AddressCountry string `db:"address_country" ` + AddressPostalCode string `db:"address_postal_code" ` + AddressLocality string `db:"address_locality" ` + AddressStreet string `db:"address_street" ` + AddressRegion string `db:"address_region" ` + Comments string `db:"comments" ` + Created time.Time `db:"created" ` + H3cell null.Val[string] `db:"h3cell" ` + HasAdult bool `db:"has_adult" ` + HasLarvae bool `db:"has_larvae" ` + HasPupae bool `db:"has_pupae" ` + MapZoom float32 `db:"map_zoom" ` + OwnerEmail string `db:"owner_email" ` + OwnerName string `db:"owner_name" ` + OwnerPhone string `db:"owner_phone" ` + PublicID string `db:"public_id" ` + ReporterEmail string `db:"reporter_email" ` + ReporterName string `db:"reporter_name" ` + ReporterPhone string `db:"reporter_phone" ` + Status enums.PublicreportReportstatustype `db:"status" ` + OrganizationID int32 `db:"organization_id" ` + HasBackyardPermission bool `db:"has_backyard_permission" ` + IsReporterConfidential bool `db:"is_reporter_confidential" ` + IsReporterOwner bool `db:"is_reporter_owner" ` + ReporterContactConsent null.Val[bool] `db:"reporter_contact_consent" ` + Location null.Val[string] `db:"location" ` + AddressNumber string `db:"address_number" ` + AddressID null.Val[int32] `db:"address_id" ` + Reviewed null.Val[time.Time] `db:"reviewed" ` + ReviewerID null.Val[int32] `db:"reviewer_id" ` + + R publicreportWaterOldR `db:"-" ` +} + +// PublicreportWaterOldSlice is an alias for a slice of pointers to PublicreportWaterOld. +// This should almost always be used instead of []*PublicreportWaterOld. +type PublicreportWaterOldSlice []*PublicreportWaterOld + +// PublicreportWaterOlds contains methods to work with the water_old table +var PublicreportWaterOlds = psql.NewTablex[*PublicreportWaterOld, PublicreportWaterOldSlice, *PublicreportWaterOldSetter]("publicreport", "water_old", buildPublicreportWaterOldColumns("publicreport.water_old")) + +// PublicreportWaterOldsQuery is a query on the water_old table +type PublicreportWaterOldsQuery = *psql.ViewQuery[*PublicreportWaterOld, PublicreportWaterOldSlice] + +// publicreportWaterOldR is where relationships are stored. +type publicreportWaterOldR struct { + WaterNotifyEmailWaterOlds PublicreportNotifyEmailWaterOldSlice // publicreport.notify_email_water_old.notify_email_pool_pool_id_fkey + WaterNotifyPhoneWaterOlds PublicreportNotifyPhoneWaterOldSlice // publicreport.notify_phone_water_old.notify_phone_pool_pool_id_fkey + Images PublicreportImageSlice // publicreport.water_image_old.pool_image_image_id_fkeypublicreport.water_image_old.pool_image_pool_id_fkey + Address *Address // publicreport.water_old.pool_address_id_fkey + Organization *Organization // publicreport.water_old.pool_organization_id_fkey + ReviewerUser *User // publicreport.water_old.water_reviewer_id_fkey +} + +func buildPublicreportWaterOldColumns(alias string) publicreportWaterOldColumns { + return publicreportWaterOldColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address_raw", "address_country", "address_postal_code", "address_locality", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "status", "organization_id", "has_backyard_permission", "is_reporter_confidential", "is_reporter_owner", "reporter_contact_consent", "location", "address_number", "address_id", "reviewed", "reviewer_id", + ).WithParent("publicreport.water_old"), + tableAlias: alias, + ID: psql.Quote(alias, "id"), + AccessComments: psql.Quote(alias, "access_comments"), + AccessGate: psql.Quote(alias, "access_gate"), + AccessFence: psql.Quote(alias, "access_fence"), + AccessLocked: psql.Quote(alias, "access_locked"), + AccessDog: psql.Quote(alias, "access_dog"), + AccessOther: psql.Quote(alias, "access_other"), + AddressRaw: psql.Quote(alias, "address_raw"), + AddressCountry: psql.Quote(alias, "address_country"), + AddressPostalCode: psql.Quote(alias, "address_postal_code"), + AddressLocality: psql.Quote(alias, "address_locality"), + AddressStreet: psql.Quote(alias, "address_street"), + AddressRegion: psql.Quote(alias, "address_region"), + Comments: psql.Quote(alias, "comments"), + Created: psql.Quote(alias, "created"), + H3cell: psql.Quote(alias, "h3cell"), + HasAdult: psql.Quote(alias, "has_adult"), + HasLarvae: psql.Quote(alias, "has_larvae"), + HasPupae: psql.Quote(alias, "has_pupae"), + MapZoom: psql.Quote(alias, "map_zoom"), + OwnerEmail: psql.Quote(alias, "owner_email"), + OwnerName: psql.Quote(alias, "owner_name"), + OwnerPhone: psql.Quote(alias, "owner_phone"), + PublicID: psql.Quote(alias, "public_id"), + ReporterEmail: psql.Quote(alias, "reporter_email"), + ReporterName: psql.Quote(alias, "reporter_name"), + ReporterPhone: psql.Quote(alias, "reporter_phone"), + Status: psql.Quote(alias, "status"), + OrganizationID: psql.Quote(alias, "organization_id"), + HasBackyardPermission: psql.Quote(alias, "has_backyard_permission"), + IsReporterConfidential: psql.Quote(alias, "is_reporter_confidential"), + IsReporterOwner: psql.Quote(alias, "is_reporter_owner"), + ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), + Location: psql.Quote(alias, "location"), + AddressNumber: psql.Quote(alias, "address_number"), + AddressID: psql.Quote(alias, "address_id"), + Reviewed: psql.Quote(alias, "reviewed"), + ReviewerID: psql.Quote(alias, "reviewer_id"), + } +} + +type publicreportWaterOldColumns struct { + expr.ColumnsExpr + tableAlias string + ID psql.Expression + AccessComments psql.Expression + AccessGate psql.Expression + AccessFence psql.Expression + AccessLocked psql.Expression + AccessDog psql.Expression + AccessOther psql.Expression + AddressRaw psql.Expression + AddressCountry psql.Expression + AddressPostalCode psql.Expression + AddressLocality psql.Expression + AddressStreet psql.Expression + AddressRegion psql.Expression + Comments psql.Expression + Created psql.Expression + H3cell psql.Expression + HasAdult psql.Expression + HasLarvae psql.Expression + HasPupae psql.Expression + MapZoom psql.Expression + OwnerEmail psql.Expression + OwnerName psql.Expression + OwnerPhone psql.Expression + PublicID psql.Expression + ReporterEmail psql.Expression + ReporterName psql.Expression + ReporterPhone psql.Expression + Status psql.Expression + OrganizationID psql.Expression + HasBackyardPermission psql.Expression + IsReporterConfidential psql.Expression + IsReporterOwner psql.Expression + ReporterContactConsent psql.Expression + Location psql.Expression + AddressNumber psql.Expression + AddressID psql.Expression + Reviewed psql.Expression + ReviewerID psql.Expression +} + +func (c publicreportWaterOldColumns) Alias() string { + return c.tableAlias +} + +func (publicreportWaterOldColumns) AliasedAs(alias string) publicreportWaterOldColumns { + return buildPublicreportWaterOldColumns(alias) +} + +// PublicreportWaterOldSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type PublicreportWaterOldSetter struct { + ID omit.Val[int32] `db:"id,pk" ` + AccessComments omit.Val[string] `db:"access_comments" ` + AccessGate omit.Val[bool] `db:"access_gate" ` + AccessFence omit.Val[bool] `db:"access_fence" ` + AccessLocked omit.Val[bool] `db:"access_locked" ` + AccessDog omit.Val[bool] `db:"access_dog" ` + AccessOther omit.Val[bool] `db:"access_other" ` + AddressRaw omit.Val[string] `db:"address_raw" ` + AddressCountry omit.Val[string] `db:"address_country" ` + AddressPostalCode omit.Val[string] `db:"address_postal_code" ` + AddressLocality omit.Val[string] `db:"address_locality" ` + AddressStreet omit.Val[string] `db:"address_street" ` + AddressRegion omit.Val[string] `db:"address_region" ` + Comments omit.Val[string] `db:"comments" ` + Created omit.Val[time.Time] `db:"created" ` + H3cell omitnull.Val[string] `db:"h3cell" ` + HasAdult omit.Val[bool] `db:"has_adult" ` + HasLarvae omit.Val[bool] `db:"has_larvae" ` + HasPupae omit.Val[bool] `db:"has_pupae" ` + MapZoom omit.Val[float32] `db:"map_zoom" ` + OwnerEmail omit.Val[string] `db:"owner_email" ` + OwnerName omit.Val[string] `db:"owner_name" ` + OwnerPhone omit.Val[string] `db:"owner_phone" ` + PublicID omit.Val[string] `db:"public_id" ` + ReporterEmail omit.Val[string] `db:"reporter_email" ` + ReporterName omit.Val[string] `db:"reporter_name" ` + ReporterPhone omit.Val[string] `db:"reporter_phone" ` + Status omit.Val[enums.PublicreportReportstatustype] `db:"status" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + HasBackyardPermission omit.Val[bool] `db:"has_backyard_permission" ` + IsReporterConfidential omit.Val[bool] `db:"is_reporter_confidential" ` + IsReporterOwner omit.Val[bool] `db:"is_reporter_owner" ` + ReporterContactConsent omitnull.Val[bool] `db:"reporter_contact_consent" ` + Location omitnull.Val[string] `db:"location" ` + AddressNumber omit.Val[string] `db:"address_number" ` + AddressID omitnull.Val[int32] `db:"address_id" ` + Reviewed omitnull.Val[time.Time] `db:"reviewed" ` + ReviewerID omitnull.Val[int32] `db:"reviewer_id" ` +} + +func (s PublicreportWaterOldSetter) SetColumns() []string { + vals := make([]string, 0, 38) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.AccessComments.IsValue() { + vals = append(vals, "access_comments") + } + if s.AccessGate.IsValue() { + vals = append(vals, "access_gate") + } + if s.AccessFence.IsValue() { + vals = append(vals, "access_fence") + } + if s.AccessLocked.IsValue() { + vals = append(vals, "access_locked") + } + if s.AccessDog.IsValue() { + vals = append(vals, "access_dog") + } + if s.AccessOther.IsValue() { + vals = append(vals, "access_other") + } + if s.AddressRaw.IsValue() { + vals = append(vals, "address_raw") + } + if s.AddressCountry.IsValue() { + vals = append(vals, "address_country") + } + if s.AddressPostalCode.IsValue() { + vals = append(vals, "address_postal_code") + } + if s.AddressLocality.IsValue() { + vals = append(vals, "address_locality") + } + if s.AddressStreet.IsValue() { + vals = append(vals, "address_street") + } + if s.AddressRegion.IsValue() { + vals = append(vals, "address_region") + } + if s.Comments.IsValue() { + vals = append(vals, "comments") + } + if s.Created.IsValue() { + vals = append(vals, "created") + } + if !s.H3cell.IsUnset() { + vals = append(vals, "h3cell") + } + if s.HasAdult.IsValue() { + vals = append(vals, "has_adult") + } + if s.HasLarvae.IsValue() { + vals = append(vals, "has_larvae") + } + if s.HasPupae.IsValue() { + vals = append(vals, "has_pupae") + } + if s.MapZoom.IsValue() { + vals = append(vals, "map_zoom") + } + if s.OwnerEmail.IsValue() { + vals = append(vals, "owner_email") + } + if s.OwnerName.IsValue() { + vals = append(vals, "owner_name") + } + if s.OwnerPhone.IsValue() { + vals = append(vals, "owner_phone") + } + if s.PublicID.IsValue() { + vals = append(vals, "public_id") + } + if s.ReporterEmail.IsValue() { + vals = append(vals, "reporter_email") + } + if s.ReporterName.IsValue() { + vals = append(vals, "reporter_name") + } + if s.ReporterPhone.IsValue() { + vals = append(vals, "reporter_phone") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + if s.OrganizationID.IsValue() { + vals = append(vals, "organization_id") + } + if s.HasBackyardPermission.IsValue() { + vals = append(vals, "has_backyard_permission") + } + if s.IsReporterConfidential.IsValue() { + vals = append(vals, "is_reporter_confidential") + } + if s.IsReporterOwner.IsValue() { + vals = append(vals, "is_reporter_owner") + } + if !s.ReporterContactConsent.IsUnset() { + vals = append(vals, "reporter_contact_consent") + } + if !s.Location.IsUnset() { + vals = append(vals, "location") + } + if s.AddressNumber.IsValue() { + vals = append(vals, "address_number") + } + if !s.AddressID.IsUnset() { + vals = append(vals, "address_id") + } + if !s.Reviewed.IsUnset() { + vals = append(vals, "reviewed") + } + if !s.ReviewerID.IsUnset() { + vals = append(vals, "reviewer_id") + } + return vals +} + +func (s PublicreportWaterOldSetter) Overwrite(t *PublicreportWaterOld) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.AccessComments.IsValue() { + t.AccessComments = s.AccessComments.MustGet() + } + if s.AccessGate.IsValue() { + t.AccessGate = s.AccessGate.MustGet() + } + if s.AccessFence.IsValue() { + t.AccessFence = s.AccessFence.MustGet() + } + if s.AccessLocked.IsValue() { + t.AccessLocked = s.AccessLocked.MustGet() + } + if s.AccessDog.IsValue() { + t.AccessDog = s.AccessDog.MustGet() + } + if s.AccessOther.IsValue() { + t.AccessOther = s.AccessOther.MustGet() + } + if s.AddressRaw.IsValue() { + t.AddressRaw = s.AddressRaw.MustGet() + } + if s.AddressCountry.IsValue() { + t.AddressCountry = s.AddressCountry.MustGet() + } + if s.AddressPostalCode.IsValue() { + t.AddressPostalCode = s.AddressPostalCode.MustGet() + } + if s.AddressLocality.IsValue() { + t.AddressLocality = s.AddressLocality.MustGet() + } + if s.AddressStreet.IsValue() { + t.AddressStreet = s.AddressStreet.MustGet() + } + if s.AddressRegion.IsValue() { + t.AddressRegion = s.AddressRegion.MustGet() + } + if s.Comments.IsValue() { + t.Comments = s.Comments.MustGet() + } + if s.Created.IsValue() { + t.Created = s.Created.MustGet() + } + if !s.H3cell.IsUnset() { + t.H3cell = s.H3cell.MustGetNull() + } + if s.HasAdult.IsValue() { + t.HasAdult = s.HasAdult.MustGet() + } + if s.HasLarvae.IsValue() { + t.HasLarvae = s.HasLarvae.MustGet() + } + if s.HasPupae.IsValue() { + t.HasPupae = s.HasPupae.MustGet() + } + if s.MapZoom.IsValue() { + t.MapZoom = s.MapZoom.MustGet() + } + if s.OwnerEmail.IsValue() { + t.OwnerEmail = s.OwnerEmail.MustGet() + } + if s.OwnerName.IsValue() { + t.OwnerName = s.OwnerName.MustGet() + } + if s.OwnerPhone.IsValue() { + t.OwnerPhone = s.OwnerPhone.MustGet() + } + if s.PublicID.IsValue() { + t.PublicID = s.PublicID.MustGet() + } + if s.ReporterEmail.IsValue() { + t.ReporterEmail = s.ReporterEmail.MustGet() + } + if s.ReporterName.IsValue() { + t.ReporterName = s.ReporterName.MustGet() + } + if s.ReporterPhone.IsValue() { + t.ReporterPhone = s.ReporterPhone.MustGet() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } + if s.OrganizationID.IsValue() { + t.OrganizationID = s.OrganizationID.MustGet() + } + if s.HasBackyardPermission.IsValue() { + t.HasBackyardPermission = s.HasBackyardPermission.MustGet() + } + if s.IsReporterConfidential.IsValue() { + t.IsReporterConfidential = s.IsReporterConfidential.MustGet() + } + if s.IsReporterOwner.IsValue() { + t.IsReporterOwner = s.IsReporterOwner.MustGet() + } + if !s.ReporterContactConsent.IsUnset() { + t.ReporterContactConsent = s.ReporterContactConsent.MustGetNull() + } + if !s.Location.IsUnset() { + t.Location = s.Location.MustGetNull() + } + if s.AddressNumber.IsValue() { + t.AddressNumber = s.AddressNumber.MustGet() + } + if !s.AddressID.IsUnset() { + t.AddressID = s.AddressID.MustGetNull() + } + if !s.Reviewed.IsUnset() { + t.Reviewed = s.Reviewed.MustGetNull() + } + if !s.ReviewerID.IsUnset() { + t.ReviewerID = s.ReviewerID.MustGetNull() + } +} + +func (s *PublicreportWaterOldSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return PublicreportWaterOlds.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, 38) + if s.ID.IsValue() { + vals[0] = psql.Arg(s.ID.MustGet()) + } else { + vals[0] = psql.Raw("DEFAULT") + } + + if s.AccessComments.IsValue() { + vals[1] = psql.Arg(s.AccessComments.MustGet()) + } else { + vals[1] = psql.Raw("DEFAULT") + } + + if s.AccessGate.IsValue() { + vals[2] = psql.Arg(s.AccessGate.MustGet()) + } else { + vals[2] = psql.Raw("DEFAULT") + } + + if s.AccessFence.IsValue() { + vals[3] = psql.Arg(s.AccessFence.MustGet()) + } else { + vals[3] = psql.Raw("DEFAULT") + } + + if s.AccessLocked.IsValue() { + vals[4] = psql.Arg(s.AccessLocked.MustGet()) + } else { + vals[4] = psql.Raw("DEFAULT") + } + + if s.AccessDog.IsValue() { + vals[5] = psql.Arg(s.AccessDog.MustGet()) + } else { + vals[5] = psql.Raw("DEFAULT") + } + + if s.AccessOther.IsValue() { + vals[6] = psql.Arg(s.AccessOther.MustGet()) + } else { + vals[6] = psql.Raw("DEFAULT") + } + + if s.AddressRaw.IsValue() { + vals[7] = psql.Arg(s.AddressRaw.MustGet()) + } else { + vals[7] = psql.Raw("DEFAULT") + } + + if s.AddressCountry.IsValue() { + vals[8] = psql.Arg(s.AddressCountry.MustGet()) + } else { + vals[8] = psql.Raw("DEFAULT") + } + + if s.AddressPostalCode.IsValue() { + vals[9] = psql.Arg(s.AddressPostalCode.MustGet()) + } else { + vals[9] = psql.Raw("DEFAULT") + } + + if s.AddressLocality.IsValue() { + vals[10] = psql.Arg(s.AddressLocality.MustGet()) + } else { + vals[10] = psql.Raw("DEFAULT") + } + + if s.AddressStreet.IsValue() { + vals[11] = psql.Arg(s.AddressStreet.MustGet()) + } else { + vals[11] = psql.Raw("DEFAULT") + } + + if s.AddressRegion.IsValue() { + vals[12] = psql.Arg(s.AddressRegion.MustGet()) + } else { + vals[12] = psql.Raw("DEFAULT") + } + + if s.Comments.IsValue() { + vals[13] = psql.Arg(s.Comments.MustGet()) + } else { + vals[13] = psql.Raw("DEFAULT") + } + + if s.Created.IsValue() { + vals[14] = psql.Arg(s.Created.MustGet()) + } else { + vals[14] = psql.Raw("DEFAULT") + } + + if !s.H3cell.IsUnset() { + vals[15] = psql.Arg(s.H3cell.MustGetNull()) + } else { + vals[15] = psql.Raw("DEFAULT") + } + + if s.HasAdult.IsValue() { + vals[16] = psql.Arg(s.HasAdult.MustGet()) + } else { + vals[16] = psql.Raw("DEFAULT") + } + + if s.HasLarvae.IsValue() { + vals[17] = psql.Arg(s.HasLarvae.MustGet()) + } else { + vals[17] = psql.Raw("DEFAULT") + } + + if s.HasPupae.IsValue() { + vals[18] = psql.Arg(s.HasPupae.MustGet()) + } else { + vals[18] = psql.Raw("DEFAULT") + } + + if s.MapZoom.IsValue() { + vals[19] = psql.Arg(s.MapZoom.MustGet()) + } else { + vals[19] = psql.Raw("DEFAULT") + } + + if s.OwnerEmail.IsValue() { + vals[20] = psql.Arg(s.OwnerEmail.MustGet()) + } else { + vals[20] = psql.Raw("DEFAULT") + } + + if s.OwnerName.IsValue() { + vals[21] = psql.Arg(s.OwnerName.MustGet()) + } else { + vals[21] = psql.Raw("DEFAULT") + } + + if s.OwnerPhone.IsValue() { + vals[22] = psql.Arg(s.OwnerPhone.MustGet()) + } else { + vals[22] = psql.Raw("DEFAULT") + } + + if s.PublicID.IsValue() { + vals[23] = psql.Arg(s.PublicID.MustGet()) + } else { + vals[23] = psql.Raw("DEFAULT") + } + + if s.ReporterEmail.IsValue() { + vals[24] = psql.Arg(s.ReporterEmail.MustGet()) + } else { + vals[24] = psql.Raw("DEFAULT") + } + + if s.ReporterName.IsValue() { + vals[25] = psql.Arg(s.ReporterName.MustGet()) + } else { + vals[25] = psql.Raw("DEFAULT") + } + + if s.ReporterPhone.IsValue() { + vals[26] = psql.Arg(s.ReporterPhone.MustGet()) + } else { + vals[26] = psql.Raw("DEFAULT") + } + + if s.Status.IsValue() { + vals[27] = psql.Arg(s.Status.MustGet()) + } else { + vals[27] = psql.Raw("DEFAULT") + } + + if s.OrganizationID.IsValue() { + vals[28] = psql.Arg(s.OrganizationID.MustGet()) + } else { + vals[28] = psql.Raw("DEFAULT") + } + + if s.HasBackyardPermission.IsValue() { + vals[29] = psql.Arg(s.HasBackyardPermission.MustGet()) + } else { + vals[29] = psql.Raw("DEFAULT") + } + + if s.IsReporterConfidential.IsValue() { + vals[30] = psql.Arg(s.IsReporterConfidential.MustGet()) + } else { + vals[30] = psql.Raw("DEFAULT") + } + + if s.IsReporterOwner.IsValue() { + vals[31] = psql.Arg(s.IsReporterOwner.MustGet()) + } else { + vals[31] = psql.Raw("DEFAULT") + } + + if !s.ReporterContactConsent.IsUnset() { + vals[32] = psql.Arg(s.ReporterContactConsent.MustGetNull()) + } else { + vals[32] = psql.Raw("DEFAULT") + } + + if !s.Location.IsUnset() { + vals[33] = psql.Arg(s.Location.MustGetNull()) + } else { + vals[33] = psql.Raw("DEFAULT") + } + + if s.AddressNumber.IsValue() { + vals[34] = psql.Arg(s.AddressNumber.MustGet()) + } else { + vals[34] = psql.Raw("DEFAULT") + } + + if !s.AddressID.IsUnset() { + vals[35] = psql.Arg(s.AddressID.MustGetNull()) + } else { + vals[35] = psql.Raw("DEFAULT") + } + + if !s.Reviewed.IsUnset() { + vals[36] = psql.Arg(s.Reviewed.MustGetNull()) + } else { + vals[36] = psql.Raw("DEFAULT") + } + + if !s.ReviewerID.IsUnset() { + vals[37] = psql.Arg(s.ReviewerID.MustGetNull()) + } else { + vals[37] = psql.Raw("DEFAULT") + } + + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") + })) +} + +func (s PublicreportWaterOldSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions()...) +} + +func (s PublicreportWaterOldSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 38) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "id")...), + psql.Arg(s.ID), + }}) + } + + if s.AccessComments.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "access_comments")...), + psql.Arg(s.AccessComments), + }}) + } + + if s.AccessGate.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "access_gate")...), + psql.Arg(s.AccessGate), + }}) + } + + if s.AccessFence.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "access_fence")...), + psql.Arg(s.AccessFence), + }}) + } + + if s.AccessLocked.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "access_locked")...), + psql.Arg(s.AccessLocked), + }}) + } + + if s.AccessDog.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "access_dog")...), + psql.Arg(s.AccessDog), + }}) + } + + if s.AccessOther.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "access_other")...), + psql.Arg(s.AccessOther), + }}) + } + + if s.AddressRaw.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_raw")...), + psql.Arg(s.AddressRaw), + }}) + } + + if s.AddressCountry.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_country")...), + psql.Arg(s.AddressCountry), + }}) + } + + if s.AddressPostalCode.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_postal_code")...), + psql.Arg(s.AddressPostalCode), + }}) + } + + if s.AddressLocality.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_locality")...), + psql.Arg(s.AddressLocality), + }}) + } + + if s.AddressStreet.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_street")...), + psql.Arg(s.AddressStreet), + }}) + } + + if s.AddressRegion.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_region")...), + psql.Arg(s.AddressRegion), + }}) + } + + if s.Comments.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "comments")...), + psql.Arg(s.Comments), + }}) + } + + if s.Created.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + + if !s.H3cell.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "h3cell")...), + psql.Arg(s.H3cell), + }}) + } + + if s.HasAdult.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "has_adult")...), + psql.Arg(s.HasAdult), + }}) + } + + if s.HasLarvae.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "has_larvae")...), + psql.Arg(s.HasLarvae), + }}) + } + + if s.HasPupae.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "has_pupae")...), + psql.Arg(s.HasPupae), + }}) + } + + if s.MapZoom.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "map_zoom")...), + psql.Arg(s.MapZoom), + }}) + } + + if s.OwnerEmail.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "owner_email")...), + psql.Arg(s.OwnerEmail), + }}) + } + + if s.OwnerName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "owner_name")...), + psql.Arg(s.OwnerName), + }}) + } + + if s.OwnerPhone.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "owner_phone")...), + psql.Arg(s.OwnerPhone), + }}) + } + + if s.PublicID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "public_id")...), + psql.Arg(s.PublicID), + }}) + } + + if s.ReporterEmail.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_email")...), + psql.Arg(s.ReporterEmail), + }}) + } + + if s.ReporterName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_name")...), + psql.Arg(s.ReporterName), + }}) + } + + if s.ReporterPhone.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_phone")...), + psql.Arg(s.ReporterPhone), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "status")...), + psql.Arg(s.Status), + }}) + } + + if s.OrganizationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "organization_id")...), + psql.Arg(s.OrganizationID), + }}) + } + + if s.HasBackyardPermission.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "has_backyard_permission")...), + psql.Arg(s.HasBackyardPermission), + }}) + } + + if s.IsReporterConfidential.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_reporter_confidential")...), + psql.Arg(s.IsReporterConfidential), + }}) + } + + if s.IsReporterOwner.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_reporter_owner")...), + psql.Arg(s.IsReporterOwner), + }}) + } + + if !s.ReporterContactConsent.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reporter_contact_consent")...), + psql.Arg(s.ReporterContactConsent), + }}) + } + + if !s.Location.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "location")...), + psql.Arg(s.Location), + }}) + } + + if s.AddressNumber.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_number")...), + psql.Arg(s.AddressNumber), + }}) + } + + if !s.AddressID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_id")...), + psql.Arg(s.AddressID), + }}) + } + + if !s.Reviewed.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reviewed")...), + psql.Arg(s.Reviewed), + }}) + } + + if !s.ReviewerID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "reviewer_id")...), + psql.Arg(s.ReviewerID), + }}) + } + + return exprs +} + +// FindPublicreportWaterOld retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindPublicreportWaterOld(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportWaterOld, error) { + if len(cols) == 0 { + return PublicreportWaterOlds.Query( + sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(IDPK))), + ).One(ctx, exec) + } + + return PublicreportWaterOlds.Query( + sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Columns(PublicreportWaterOlds.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// PublicreportWaterOldExists checks the presence of a single record by primary key +func PublicreportWaterOldExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return PublicreportWaterOlds.Query( + sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after PublicreportWaterOld is retrieved from the database +func (o *PublicreportWaterOld) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = PublicreportWaterOlds.AfterSelectHooks.RunHooks(ctx, exec, PublicreportWaterOldSlice{o}) + case bob.QueryTypeInsert: + ctx, err = PublicreportWaterOlds.AfterInsertHooks.RunHooks(ctx, exec, PublicreportWaterOldSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = PublicreportWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportWaterOldSlice{o}) + case bob.QueryTypeDelete: + ctx, err = PublicreportWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportWaterOldSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the PublicreportWaterOld +func (o *PublicreportWaterOld) primaryKeyVals() bob.Expression { + return psql.Arg(o.ID) +} + +func (o *PublicreportWaterOld) pkEQ() dialect.Expression { + return psql.Quote("publicreport.water_old", "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 PublicreportWaterOld +func (o *PublicreportWaterOld) Update(ctx context.Context, exec bob.Executor, s *PublicreportWaterOldSetter) error { + v, err := PublicreportWaterOlds.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 PublicreportWaterOld record with an executor +func (o *PublicreportWaterOld) Delete(ctx context.Context, exec bob.Executor) error { + _, err := PublicreportWaterOlds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the PublicreportWaterOld using the executor +func (o *PublicreportWaterOld) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := PublicreportWaterOlds.Query( + sm.Where(PublicreportWaterOlds.Columns.ID.EQ(psql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after PublicreportWaterOldSlice is retrieved from the database +func (o PublicreportWaterOldSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = PublicreportWaterOlds.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = PublicreportWaterOlds.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = PublicreportWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = PublicreportWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o PublicreportWaterOldSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return psql.Raw("NULL") + } + + return psql.Quote("publicreport.water_old", "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 PublicreportWaterOldSlice) copyMatchingRows(from ...*PublicreportWaterOld) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o PublicreportWaterOldSlice) 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 PublicreportWaterOlds.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 *PublicreportWaterOld: + o.copyMatchingRows(retrieved) + case []*PublicreportWaterOld: + o.copyMatchingRows(retrieved...) + case PublicreportWaterOldSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a PublicreportWaterOld or a slice of PublicreportWaterOld + // then run the AfterUpdateHooks on the slice + _, err = PublicreportWaterOlds.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o PublicreportWaterOldSlice) 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 PublicreportWaterOlds.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 *PublicreportWaterOld: + o.copyMatchingRows(retrieved) + case []*PublicreportWaterOld: + o.copyMatchingRows(retrieved...) + case PublicreportWaterOldSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a PublicreportWaterOld or a slice of PublicreportWaterOld + // then run the AfterDeleteHooks on the slice + _, err = PublicreportWaterOlds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o PublicreportWaterOldSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportWaterOldSetter) error { + if len(o) == 0 { + return nil + } + + _, err := PublicreportWaterOlds.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) + return err +} + +func (o PublicreportWaterOldSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := PublicreportWaterOlds.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o PublicreportWaterOldSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := PublicreportWaterOlds.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// WaterNotifyEmailWaterOlds starts a query for related objects on publicreport.notify_email_water_old +func (o *PublicreportWaterOld) WaterNotifyEmailWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWaterOldsQuery { + return PublicreportNotifyEmailWaterOlds.Query(append(mods, + sm.Where(PublicreportNotifyEmailWaterOlds.Columns.WaterID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportWaterOldSlice) WaterNotifyEmailWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWaterOldsQuery { + 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 PublicreportNotifyEmailWaterOlds.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyEmailWaterOlds.Columns.WaterID).OP("IN", PKArgExpr)), + )...) +} + +// WaterNotifyPhoneWaterOlds starts a query for related objects on publicreport.notify_phone_water_old +func (o *PublicreportWaterOld) WaterNotifyPhoneWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWaterOldsQuery { + return PublicreportNotifyPhoneWaterOlds.Query(append(mods, + sm.Where(PublicreportNotifyPhoneWaterOlds.Columns.WaterID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportWaterOldSlice) WaterNotifyPhoneWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWaterOldsQuery { + 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 PublicreportNotifyPhoneWaterOlds.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyPhoneWaterOlds.Columns.WaterID).OP("IN", PKArgExpr)), + )...) +} + +// Images starts a query for related objects on publicreport.image +func (o *PublicreportWaterOld) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { + return PublicreportImages.Query(append(mods, + sm.InnerJoin(PublicreportWaterImageOlds.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportWaterImageOlds.Columns.ImageID)), + sm.Where(PublicreportWaterImageOlds.Columns.WaterID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os PublicreportWaterOldSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { + 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 PublicreportImages.Query(append(mods, + sm.InnerJoin(PublicreportWaterImageOlds.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportWaterImageOlds.Columns.ImageID), + ), + sm.Where(psql.Group(PublicreportWaterImageOlds.Columns.WaterID).OP("IN", PKArgExpr)), + )...) +} + +// Address starts a query for related objects on address +func (o *PublicreportWaterOld) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { + return Addresses.Query(append(mods, + sm.Where(Addresses.Columns.ID.EQ(psql.Arg(o.AddressID))), + )...) +} + +func (os PublicreportWaterOldSlice) Address(mods ...bob.Mod[*dialect.SelectQuery]) AddressesQuery { + pkAddressID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkAddressID = append(pkAddressID, o.AddressID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkAddressID), "integer[]")), + )) + + return Addresses.Query(append(mods, + sm.Where(psql.Group(Addresses.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// Organization starts a query for related objects on organization +func (o *PublicreportWaterOld) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + return Organizations.Query(append(mods, + sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), + )...) +} + +func (os PublicreportWaterOldSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkOrganizationID = append(pkOrganizationID, o.OrganizationID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), + )) + + return Organizations.Query(append(mods, + sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ReviewerUser starts a query for related objects on user_ +func (o *PublicreportWaterOld) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + return Users.Query(append(mods, + sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))), + )...) +} + +func (os PublicreportWaterOldSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkReviewerID = append(pkReviewerID, o.ReviewerID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")), + )) + + return Users.Query(append(mods, + sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func insertPublicreportWaterOldWaterNotifyEmailWaterOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailWaterOlds1 []*PublicreportNotifyEmailWaterOldSetter, publicreportWaterOld0 *PublicreportWaterOld) (PublicreportNotifyEmailWaterOldSlice, error) { + for i := range publicreportNotifyEmailWaterOlds1 { + publicreportNotifyEmailWaterOlds1[i].WaterID = omit.From(publicreportWaterOld0.ID) + } + + ret, err := PublicreportNotifyEmailWaterOlds.Insert(bob.ToMods(publicreportNotifyEmailWaterOlds1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportWaterOldWaterNotifyEmailWaterOlds0: %w", err) + } + + return ret, nil +} + +func attachPublicreportWaterOldWaterNotifyEmailWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaterOlds1 PublicreportNotifyEmailWaterOldSlice, publicreportWaterOld0 *PublicreportWaterOld) (PublicreportNotifyEmailWaterOldSlice, error) { + setter := &PublicreportNotifyEmailWaterOldSetter{ + WaterID: omit.From(publicreportWaterOld0.ID), + } + + err := publicreportNotifyEmailWaterOlds1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterOldWaterNotifyEmailWaterOlds0: %w", err) + } + + return publicreportNotifyEmailWaterOlds1, nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) InsertWaterNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterOldSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNotifyEmailWaterOlds1, err := insertPublicreportWaterOldWaterNotifyEmailWaterOlds0(ctx, exec, related, publicreportWaterOld0) + if err != nil { + return err + } + + publicreportWaterOld0.R.WaterNotifyEmailWaterOlds = append(publicreportWaterOld0.R.WaterNotifyEmailWaterOlds, publicreportNotifyEmailWaterOlds1...) + + for _, rel := range publicreportNotifyEmailWaterOlds1 { + rel.R.WaterWaterOld = publicreportWaterOld0 + } + return nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) AttachWaterNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterOld) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNotifyEmailWaterOlds1 := PublicreportNotifyEmailWaterOldSlice(related) + + _, err = attachPublicreportWaterOldWaterNotifyEmailWaterOlds0(ctx, exec, len(related), publicreportNotifyEmailWaterOlds1, publicreportWaterOld0) + if err != nil { + return err + } + + publicreportWaterOld0.R.WaterNotifyEmailWaterOlds = append(publicreportWaterOld0.R.WaterNotifyEmailWaterOlds, publicreportNotifyEmailWaterOlds1...) + + for _, rel := range related { + rel.R.WaterWaterOld = publicreportWaterOld0 + } + + return nil +} + +func insertPublicreportWaterOldWaterNotifyPhoneWaterOlds0(ctx context.Context, exec bob.Executor, publicreportNotifyPhoneWaterOlds1 []*PublicreportNotifyPhoneWaterOldSetter, publicreportWaterOld0 *PublicreportWaterOld) (PublicreportNotifyPhoneWaterOldSlice, error) { + for i := range publicreportNotifyPhoneWaterOlds1 { + publicreportNotifyPhoneWaterOlds1[i].WaterID = omit.From(publicreportWaterOld0.ID) + } + + ret, err := PublicreportNotifyPhoneWaterOlds.Insert(bob.ToMods(publicreportNotifyPhoneWaterOlds1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertPublicreportWaterOldWaterNotifyPhoneWaterOlds0: %w", err) + } + + return ret, nil +} + +func attachPublicreportWaterOldWaterNotifyPhoneWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaterOlds1 PublicreportNotifyPhoneWaterOldSlice, publicreportWaterOld0 *PublicreportWaterOld) (PublicreportNotifyPhoneWaterOldSlice, error) { + setter := &PublicreportNotifyPhoneWaterOldSetter{ + WaterID: omit.From(publicreportWaterOld0.ID), + } + + err := publicreportNotifyPhoneWaterOlds1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterOldWaterNotifyPhoneWaterOlds0: %w", err) + } + + return publicreportNotifyPhoneWaterOlds1, nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) InsertWaterNotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterOldSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNotifyPhoneWaterOlds1, err := insertPublicreportWaterOldWaterNotifyPhoneWaterOlds0(ctx, exec, related, publicreportWaterOld0) + if err != nil { + return err + } + + publicreportWaterOld0.R.WaterNotifyPhoneWaterOlds = append(publicreportWaterOld0.R.WaterNotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOlds1...) + + for _, rel := range publicreportNotifyPhoneWaterOlds1 { + rel.R.WaterWaterOld = publicreportWaterOld0 + } + return nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) AttachWaterNotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterOld) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNotifyPhoneWaterOlds1 := PublicreportNotifyPhoneWaterOldSlice(related) + + _, err = attachPublicreportWaterOldWaterNotifyPhoneWaterOlds0(ctx, exec, len(related), publicreportNotifyPhoneWaterOlds1, publicreportWaterOld0) + if err != nil { + return err + } + + publicreportWaterOld0.R.WaterNotifyPhoneWaterOlds = append(publicreportWaterOld0.R.WaterNotifyPhoneWaterOlds, publicreportNotifyPhoneWaterOlds1...) + + for _, rel := range related { + rel.R.WaterWaterOld = publicreportWaterOld0 + } + + return nil +} + +func attachPublicreportWaterOldImages0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOld0 *PublicreportWaterOld, publicreportImages2 PublicreportImageSlice) (PublicreportWaterImageOldSlice, error) { + setters := make([]*PublicreportWaterImageOldSetter, count) + for i := range count { + setters[i] = &PublicreportWaterImageOldSetter{ + WaterID: omit.From(publicreportWaterOld0.ID), + ImageID: omit.From(publicreportImages2[i].ID), + } + } + + publicreportWaterImageOlds1, err := PublicreportWaterImageOlds.Insert(bob.ToMods(setters...)).All(ctx, exec) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterOldImages0: %w", err) + } + + return publicreportWaterImageOlds1, nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + inserted, err := PublicreportImages.Insert(bob.ToMods(related...)).All(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + publicreportImages2 := PublicreportImageSlice(inserted) + + _, err = attachPublicreportWaterOldImages0(ctx, exec, len(related), publicreportWaterOld0, publicreportImages2) + if err != nil { + return err + } + + publicreportWaterOld0.R.Images = append(publicreportWaterOld0.R.Images, publicreportImages2...) + + for _, rel := range publicreportImages2 { + rel.R.WaterOlds = append(rel.R.WaterOlds, publicreportWaterOld0) + } + return nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportImages2 := PublicreportImageSlice(related) + + _, err = attachPublicreportWaterOldImages0(ctx, exec, len(related), publicreportWaterOld0, publicreportImages2) + if err != nil { + return err + } + + publicreportWaterOld0.R.Images = append(publicreportWaterOld0.R.Images, publicreportImages2...) + + for _, rel := range related { + rel.R.WaterOlds = append(rel.R.WaterOlds, publicreportWaterOld0) + } + + return nil +} + +func attachPublicreportWaterOldAddress0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOld0 *PublicreportWaterOld, address1 *Address) (*PublicreportWaterOld, error) { + setter := &PublicreportWaterOldSetter{ + AddressID: omitnull.From(address1.ID), + } + + err := publicreportWaterOld0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterOldAddress0: %w", err) + } + + return publicreportWaterOld0, nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) InsertAddress(ctx context.Context, exec bob.Executor, related *AddressSetter) error { + var err error + + address1, err := Addresses.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachPublicreportWaterOldAddress0(ctx, exec, 1, publicreportWaterOld0, address1) + if err != nil { + return err + } + + publicreportWaterOld0.R.Address = address1 + + address1.R.WaterOlds = append(address1.R.WaterOlds, publicreportWaterOld0) + + return nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { + var err error + + _, err = attachPublicreportWaterOldAddress0(ctx, exec, 1, publicreportWaterOld0, address1) + if err != nil { + return err + } + + publicreportWaterOld0.R.Address = address1 + + address1.R.WaterOlds = append(address1.R.WaterOlds, publicreportWaterOld0) + + return nil +} + +func attachPublicreportWaterOldOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOld0 *PublicreportWaterOld, organization1 *Organization) (*PublicreportWaterOld, error) { + setter := &PublicreportWaterOldSetter{ + OrganizationID: omit.From(organization1.ID), + } + + err := publicreportWaterOld0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterOldOrganization0: %w", err) + } + + return publicreportWaterOld0, nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { + var err error + + organization1, err := Organizations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachPublicreportWaterOldOrganization0(ctx, exec, 1, publicreportWaterOld0, organization1) + if err != nil { + return err + } + + publicreportWaterOld0.R.Organization = organization1 + + organization1.R.WaterOlds = append(organization1.R.WaterOlds, publicreportWaterOld0) + + return nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { + var err error + + _, err = attachPublicreportWaterOldOrganization0(ctx, exec, 1, publicreportWaterOld0, organization1) + if err != nil { + return err + } + + publicreportWaterOld0.R.Organization = organization1 + + organization1.R.WaterOlds = append(organization1.R.WaterOlds, publicreportWaterOld0) + + return nil +} + +func attachPublicreportWaterOldReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOld0 *PublicreportWaterOld, user1 *User) (*PublicreportWaterOld, error) { + setter := &PublicreportWaterOldSetter{ + ReviewerID: omitnull.From(user1.ID), + } + + err := publicreportWaterOld0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterOldReviewerUser0: %w", err) + } + + return publicreportWaterOld0, nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) InsertReviewerUser(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 = attachPublicreportWaterOldReviewerUser0(ctx, exec, 1, publicreportWaterOld0, user1) + if err != nil { + return err + } + + publicreportWaterOld0.R.ReviewerUser = user1 + + user1.R.ReviewerWaterOlds = append(user1.R.ReviewerWaterOlds, publicreportWaterOld0) + + return nil +} + +func (publicreportWaterOld0 *PublicreportWaterOld) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error { + var err error + + _, err = attachPublicreportWaterOldReviewerUser0(ctx, exec, 1, publicreportWaterOld0, user1) + if err != nil { + return err + } + + publicreportWaterOld0.R.ReviewerUser = user1 + + user1.R.ReviewerWaterOlds = append(user1.R.ReviewerWaterOlds, publicreportWaterOld0) + + return nil +} + +type publicreportWaterOldWhere[Q psql.Filterable] struct { + ID psql.WhereMod[Q, int32] + AccessComments psql.WhereMod[Q, string] + AccessGate psql.WhereMod[Q, bool] + AccessFence psql.WhereMod[Q, bool] + AccessLocked psql.WhereMod[Q, bool] + AccessDog psql.WhereMod[Q, bool] + AccessOther psql.WhereMod[Q, bool] + AddressRaw psql.WhereMod[Q, string] + AddressCountry psql.WhereMod[Q, string] + AddressPostalCode psql.WhereMod[Q, string] + AddressLocality psql.WhereMod[Q, string] + AddressStreet psql.WhereMod[Q, string] + AddressRegion psql.WhereMod[Q, string] + Comments psql.WhereMod[Q, string] + Created psql.WhereMod[Q, time.Time] + H3cell psql.WhereNullMod[Q, string] + HasAdult psql.WhereMod[Q, bool] + HasLarvae psql.WhereMod[Q, bool] + HasPupae psql.WhereMod[Q, bool] + MapZoom psql.WhereMod[Q, float32] + OwnerEmail psql.WhereMod[Q, string] + OwnerName psql.WhereMod[Q, string] + OwnerPhone psql.WhereMod[Q, string] + PublicID psql.WhereMod[Q, string] + ReporterEmail psql.WhereMod[Q, string] + ReporterName psql.WhereMod[Q, string] + ReporterPhone psql.WhereMod[Q, string] + Status psql.WhereMod[Q, enums.PublicreportReportstatustype] + OrganizationID psql.WhereMod[Q, int32] + HasBackyardPermission psql.WhereMod[Q, bool] + IsReporterConfidential psql.WhereMod[Q, bool] + IsReporterOwner psql.WhereMod[Q, bool] + ReporterContactConsent psql.WhereNullMod[Q, bool] + Location psql.WhereNullMod[Q, string] + AddressNumber psql.WhereMod[Q, string] + AddressID psql.WhereNullMod[Q, int32] + Reviewed psql.WhereNullMod[Q, time.Time] + ReviewerID psql.WhereNullMod[Q, int32] +} + +func (publicreportWaterOldWhere[Q]) AliasedAs(alias string) publicreportWaterOldWhere[Q] { + return buildPublicreportWaterOldWhere[Q](buildPublicreportWaterOldColumns(alias)) +} + +func buildPublicreportWaterOldWhere[Q psql.Filterable](cols publicreportWaterOldColumns) publicreportWaterOldWhere[Q] { + return publicreportWaterOldWhere[Q]{ + ID: psql.Where[Q, int32](cols.ID), + AccessComments: psql.Where[Q, string](cols.AccessComments), + AccessGate: psql.Where[Q, bool](cols.AccessGate), + AccessFence: psql.Where[Q, bool](cols.AccessFence), + AccessLocked: psql.Where[Q, bool](cols.AccessLocked), + AccessDog: psql.Where[Q, bool](cols.AccessDog), + AccessOther: psql.Where[Q, bool](cols.AccessOther), + AddressRaw: psql.Where[Q, string](cols.AddressRaw), + AddressCountry: psql.Where[Q, string](cols.AddressCountry), + AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), + AddressLocality: psql.Where[Q, string](cols.AddressLocality), + AddressStreet: psql.Where[Q, string](cols.AddressStreet), + AddressRegion: psql.Where[Q, string](cols.AddressRegion), + Comments: psql.Where[Q, string](cols.Comments), + Created: psql.Where[Q, time.Time](cols.Created), + H3cell: psql.WhereNull[Q, string](cols.H3cell), + HasAdult: psql.Where[Q, bool](cols.HasAdult), + HasLarvae: psql.Where[Q, bool](cols.HasLarvae), + HasPupae: psql.Where[Q, bool](cols.HasPupae), + MapZoom: psql.Where[Q, float32](cols.MapZoom), + OwnerEmail: psql.Where[Q, string](cols.OwnerEmail), + OwnerName: psql.Where[Q, string](cols.OwnerName), + OwnerPhone: psql.Where[Q, string](cols.OwnerPhone), + PublicID: psql.Where[Q, string](cols.PublicID), + ReporterEmail: psql.Where[Q, string](cols.ReporterEmail), + ReporterName: psql.Where[Q, string](cols.ReporterName), + ReporterPhone: psql.Where[Q, string](cols.ReporterPhone), + Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status), + OrganizationID: psql.Where[Q, int32](cols.OrganizationID), + HasBackyardPermission: psql.Where[Q, bool](cols.HasBackyardPermission), + IsReporterConfidential: psql.Where[Q, bool](cols.IsReporterConfidential), + IsReporterOwner: psql.Where[Q, bool](cols.IsReporterOwner), + ReporterContactConsent: psql.WhereNull[Q, bool](cols.ReporterContactConsent), + Location: psql.WhereNull[Q, string](cols.Location), + AddressNumber: psql.Where[Q, string](cols.AddressNumber), + AddressID: psql.WhereNull[Q, int32](cols.AddressID), + Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed), + ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID), + } +} + +func (o *PublicreportWaterOld) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "WaterNotifyEmailWaterOlds": + rels, ok := retrieved.(PublicreportNotifyEmailWaterOldSlice) + if !ok { + return fmt.Errorf("publicreportWaterOld cannot load %T as %q", retrieved, name) + } + + o.R.WaterNotifyEmailWaterOlds = rels + + for _, rel := range rels { + if rel != nil { + rel.R.WaterWaterOld = o + } + } + return nil + case "WaterNotifyPhoneWaterOlds": + rels, ok := retrieved.(PublicreportNotifyPhoneWaterOldSlice) + if !ok { + return fmt.Errorf("publicreportWaterOld cannot load %T as %q", retrieved, name) + } + + o.R.WaterNotifyPhoneWaterOlds = rels + + for _, rel := range rels { + if rel != nil { + rel.R.WaterWaterOld = o + } + } + return nil + case "Images": + rels, ok := retrieved.(PublicreportImageSlice) + if !ok { + return fmt.Errorf("publicreportWaterOld cannot load %T as %q", retrieved, name) + } + + o.R.Images = rels + + for _, rel := range rels { + if rel != nil { + rel.R.WaterOlds = PublicreportWaterOldSlice{o} + } + } + return nil + case "Address": + rel, ok := retrieved.(*Address) + if !ok { + return fmt.Errorf("publicreportWaterOld cannot load %T as %q", retrieved, name) + } + + o.R.Address = rel + + if rel != nil { + rel.R.WaterOlds = PublicreportWaterOldSlice{o} + } + return nil + case "Organization": + rel, ok := retrieved.(*Organization) + if !ok { + return fmt.Errorf("publicreportWaterOld cannot load %T as %q", retrieved, name) + } + + o.R.Organization = rel + + if rel != nil { + rel.R.WaterOlds = PublicreportWaterOldSlice{o} + } + return nil + case "ReviewerUser": + rel, ok := retrieved.(*User) + if !ok { + return fmt.Errorf("publicreportWaterOld cannot load %T as %q", retrieved, name) + } + + o.R.ReviewerUser = rel + + if rel != nil { + rel.R.ReviewerWaterOlds = PublicreportWaterOldSlice{o} + } + return nil + default: + return fmt.Errorf("publicreportWaterOld has no relationship %q", name) + } +} + +type publicreportWaterOldPreloader struct { + Address func(...psql.PreloadOption) psql.Preloader + Organization func(...psql.PreloadOption) psql.Preloader + ReviewerUser func(...psql.PreloadOption) psql.Preloader +} + +func buildPublicreportWaterOldPreloader() publicreportWaterOldPreloader { + return publicreportWaterOldPreloader{ + Address: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Address, AddressSlice](psql.PreloadRel{ + Name: "Address", + Sides: []psql.PreloadSide{ + { + From: PublicreportWaterOlds, + To: Addresses, + FromColumns: []string{"address_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Addresses.Columns.Names(), opts...) + }, + Organization: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ + Name: "Organization", + Sides: []psql.PreloadSide{ + { + From: PublicreportWaterOlds, + To: Organizations, + FromColumns: []string{"organization_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Organizations.Columns.Names(), opts...) + }, + ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*User, UserSlice](psql.PreloadRel{ + Name: "ReviewerUser", + Sides: []psql.PreloadSide{ + { + From: PublicreportWaterOlds, + To: Users, + FromColumns: []string{"reviewer_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Users.Columns.Names(), opts...) + }, + } +} + +type publicreportWaterOldThenLoader[Q orm.Loadable] struct { + WaterNotifyEmailWaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + WaterNotifyPhoneWaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildPublicreportWaterOldThenLoader[Q orm.Loadable]() publicreportWaterOldThenLoader[Q] { + type WaterNotifyEmailWaterOldsLoadInterface interface { + LoadWaterNotifyEmailWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type WaterNotifyPhoneWaterOldsLoadInterface interface { + LoadWaterNotifyPhoneWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ImagesLoadInterface interface { + LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type AddressLoadInterface interface { + LoadAddress(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OrganizationLoadInterface interface { + LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReviewerUserLoadInterface interface { + LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return publicreportWaterOldThenLoader[Q]{ + WaterNotifyEmailWaterOlds: thenLoadBuilder[Q]( + "WaterNotifyEmailWaterOlds", + func(ctx context.Context, exec bob.Executor, retrieved WaterNotifyEmailWaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadWaterNotifyEmailWaterOlds(ctx, exec, mods...) + }, + ), + WaterNotifyPhoneWaterOlds: thenLoadBuilder[Q]( + "WaterNotifyPhoneWaterOlds", + func(ctx context.Context, exec bob.Executor, retrieved WaterNotifyPhoneWaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadWaterNotifyPhoneWaterOlds(ctx, exec, mods...) + }, + ), + Images: thenLoadBuilder[Q]( + "Images", + func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadImages(ctx, exec, mods...) + }, + ), + Address: thenLoadBuilder[Q]( + "Address", + func(ctx context.Context, exec bob.Executor, retrieved AddressLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAddress(ctx, exec, mods...) + }, + ), + Organization: thenLoadBuilder[Q]( + "Organization", + func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOrganization(ctx, exec, mods...) + }, + ), + ReviewerUser: thenLoadBuilder[Q]( + "ReviewerUser", + func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReviewerUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadWaterNotifyEmailWaterOlds loads the publicreportWaterOld's WaterNotifyEmailWaterOlds into the .R struct +func (o *PublicreportWaterOld) LoadWaterNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.WaterNotifyEmailWaterOlds = nil + + related, err := o.WaterNotifyEmailWaterOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.WaterWaterOld = o + } + + o.R.WaterNotifyEmailWaterOlds = related + return nil +} + +// LoadWaterNotifyEmailWaterOlds loads the publicreportWaterOld's WaterNotifyEmailWaterOlds into the .R struct +func (os PublicreportWaterOldSlice) LoadWaterNotifyEmailWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportNotifyEmailWaterOlds, err := os.WaterNotifyEmailWaterOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.WaterNotifyEmailWaterOlds = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNotifyEmailWaterOlds { + + if !(o.ID == rel.WaterID) { + continue + } + + rel.R.WaterWaterOld = o + + o.R.WaterNotifyEmailWaterOlds = append(o.R.WaterNotifyEmailWaterOlds, rel) + } + } + + return nil +} + +// LoadWaterNotifyPhoneWaterOlds loads the publicreportWaterOld's WaterNotifyPhoneWaterOlds into the .R struct +func (o *PublicreportWaterOld) LoadWaterNotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.WaterNotifyPhoneWaterOlds = nil + + related, err := o.WaterNotifyPhoneWaterOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.WaterWaterOld = o + } + + o.R.WaterNotifyPhoneWaterOlds = related + return nil +} + +// LoadWaterNotifyPhoneWaterOlds loads the publicreportWaterOld's WaterNotifyPhoneWaterOlds into the .R struct +func (os PublicreportWaterOldSlice) LoadWaterNotifyPhoneWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportNotifyPhoneWaterOlds, err := os.WaterNotifyPhoneWaterOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.WaterNotifyPhoneWaterOlds = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNotifyPhoneWaterOlds { + + if !(o.ID == rel.WaterID) { + continue + } + + rel.R.WaterWaterOld = o + + o.R.WaterNotifyPhoneWaterOlds = append(o.R.WaterNotifyPhoneWaterOlds, rel) + } + } + + return nil +} + +// LoadImages loads the publicreportWaterOld's Images into the .R struct +func (o *PublicreportWaterOld) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Images = nil + + related, err := o.Images(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.WaterOlds = PublicreportWaterOldSlice{o} + } + + o.R.Images = related + return nil +} + +// LoadImages loads the publicreportWaterOld's Images into the .R struct +func (os PublicreportWaterOldSlice) LoadImages(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(PublicreportImages.Columns)) + } + + q := os.Images(append( + mods, + sm.Columns(PublicreportWaterImageOlds.Columns.WaterID.As("related_publicreport.water_old.ID")), + )...) + + IDSlice := []int32{} + + mapper := scan.Mod(scan.StructMapper[*PublicreportImage](), 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.water_old.ID", &IDSlice[len(IDSlice)-1]) + + return nil, nil + }, + func(any, any) error { + return nil + } + }) + + publicreportImages, err := bob.Allx[bob.SliceTransformer[*PublicreportImage, PublicreportImageSlice]](ctx, exec, q, mapper) + if err != nil { + return err + } + + for _, o := range os { + o.R.Images = nil + } + + for _, o := range os { + for i, rel := range publicreportImages { + if !(o.ID == IDSlice[i]) { + continue + } + + rel.R.WaterOlds = append(rel.R.WaterOlds, o) + + o.R.Images = append(o.R.Images, rel) + } + } + + return nil +} + +// LoadAddress loads the publicreportWaterOld's Address into the .R struct +func (o *PublicreportWaterOld) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Address = nil + + related, err := o.Address(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.WaterOlds = PublicreportWaterOldSlice{o} + + o.R.Address = related + return nil +} + +// LoadAddress loads the publicreportWaterOld's Address into the .R struct +func (os PublicreportWaterOldSlice) LoadAddress(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + addresses, err := os.Address(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range addresses { + if !o.AddressID.IsValue() { + continue + } + + if !(o.AddressID.IsValue() && o.AddressID.MustGet() == rel.ID) { + continue + } + + rel.R.WaterOlds = append(rel.R.WaterOlds, o) + + o.R.Address = rel + break + } + } + + return nil +} + +// LoadOrganization loads the publicreportWaterOld's Organization into the .R struct +func (o *PublicreportWaterOld) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Organization = nil + + related, err := o.Organization(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.WaterOlds = PublicreportWaterOldSlice{o} + + o.R.Organization = related + return nil +} + +// LoadOrganization loads the publicreportWaterOld's Organization into the .R struct +func (os PublicreportWaterOldSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + organizations, err := os.Organization(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range organizations { + + if !(o.OrganizationID == rel.ID) { + continue + } + + rel.R.WaterOlds = append(rel.R.WaterOlds, o) + + o.R.Organization = rel + break + } + } + + return nil +} + +// LoadReviewerUser loads the publicreportWaterOld's ReviewerUser into the .R struct +func (o *PublicreportWaterOld) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReviewerUser = nil + + related, err := o.ReviewerUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ReviewerWaterOlds = PublicreportWaterOldSlice{o} + + o.R.ReviewerUser = related + return nil +} + +// LoadReviewerUser loads the publicreportWaterOld's ReviewerUser into the .R struct +func (os PublicreportWaterOldSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + users, err := os.ReviewerUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range users { + if !o.ReviewerID.IsValue() { + continue + } + + if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) { + continue + } + + rel.R.ReviewerWaterOlds = append(rel.R.ReviewerWaterOlds, o) + + o.R.ReviewerUser = rel + break + } + } + + return nil +} diff --git a/db/models/report_text.bob.go b/db/models/report_text.bob.go new file mode 100644 index 00000000..47d07b04 --- /dev/null +++ b/db/models/report_text.bob.go @@ -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 +} diff --git a/db/models/user_.bob.go b/db/models/user_.bob.go index 9cd579b6..eab6eda3 100644 --- a/db/models/user_.bob.go +++ b/db/models/user_.bob.go @@ -57,6 +57,7 @@ type UsersQuery = *psql.ViewQuery[*User, UserSlice] type userR struct { UserOauthTokens ArcgisOauthTokenSlice // arcgis.oauth_token.oauth_token_user_id_fkey PublicUserUser ArcgisUserSlice // arcgis.user_.user__public_user_id_fkey + CreatorTextJobs CommsTextJobSlice // comms.text_job.text_job_creator_id_fkey CreatorComplianceReportRequests ComplianceReportRequestSlice // compliance_report_request.compliance_report_request_creator_fkey CreatorFeatures FeatureSlice // feature.feature_creator_id_fkey CommitterFiles FileuploadFileSlice // fileupload.file.file_committer_fkey @@ -68,8 +69,10 @@ type userR struct { CreatorNoteImages NoteImageSlice // note_image.note_image_creator_id_fkey DeletorNoteImages NoteImageSlice // note_image.note_image_deletor_id_fkey UserNotifications NotificationSlice // notification.notification_user_id_fkey - ReviewerNuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_reviewer_id_fkey - ReviewerWaters PublicreportWaterSlice // publicreport.water.water_reviewer_id_fkey + ReviewerNuisanceOlds PublicreportNuisanceOldSlice // publicreport.nuisance_old.nuisance_reviewer_id_fkey + ReviewerReports PublicreportReportSlice // publicreport.report.report_reviewer_id_fkey + ReviewerWaterOlds PublicreportWaterOldSlice // publicreport.water_old.water_reviewer_id_fkey + CreatorReportTexts ReportTextSlice // report_text.report_text_creator_id_fkey CreatorResidents ResidentSlice // resident.resident_creator_fkey CreatorReviewTasks ReviewTaskSlice // review_task.review_task_creator_id_fkey ReviewerReviewTasks ReviewTaskSlice // review_task.review_task_reviewer_id_fkey @@ -693,6 +696,30 @@ func (os UserSlice) PublicUserUser(mods ...bob.Mod[*dialect.SelectQuery]) Arcgis )...) } +// CreatorTextJobs starts a query for related objects on comms.text_job +func (o *User) CreatorTextJobs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextJobsQuery { + return CommsTextJobs.Query(append(mods, + sm.Where(CommsTextJobs.Columns.CreatorID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) CreatorTextJobs(mods ...bob.Mod[*dialect.SelectQuery]) CommsTextJobsQuery { + 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 CommsTextJobs.Query(append(mods, + sm.Where(psql.Group(CommsTextJobs.Columns.CreatorID).OP("IN", PKArgExpr)), + )...) +} + // CreatorComplianceReportRequests starts a query for related objects on compliance_report_request func (o *User) CreatorComplianceReportRequests(mods ...bob.Mod[*dialect.SelectQuery]) ComplianceReportRequestsQuery { return ComplianceReportRequests.Query(append(mods, @@ -957,14 +984,14 @@ func (os UserSlice) UserNotifications(mods ...bob.Mod[*dialect.SelectQuery]) Not )...) } -// ReviewerNuisances starts a query for related objects on publicreport.nuisance -func (o *User) ReviewerNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery { - return PublicreportNuisances.Query(append(mods, - sm.Where(PublicreportNuisances.Columns.ReviewerID.EQ(psql.Arg(o.ID))), +// ReviewerNuisanceOlds starts a query for related objects on publicreport.nuisance_old +func (o *User) ReviewerNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery { + return PublicreportNuisanceOlds.Query(append(mods, + sm.Where(PublicreportNuisanceOlds.Columns.ReviewerID.EQ(psql.Arg(o.ID))), )...) } -func (os UserSlice) ReviewerNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery { +func (os UserSlice) ReviewerNuisanceOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisanceOldsQuery { pkID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { @@ -976,19 +1003,19 @@ func (os UserSlice) ReviewerNuisances(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.ReviewerID).OP("IN", PKArgExpr)), + return PublicreportNuisanceOlds.Query(append(mods, + sm.Where(psql.Group(PublicreportNuisanceOlds.Columns.ReviewerID).OP("IN", PKArgExpr)), )...) } -// ReviewerWaters starts a query for related objects on publicreport.water -func (o *User) ReviewerWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery { - return PublicreportWaters.Query(append(mods, - sm.Where(PublicreportWaters.Columns.ReviewerID.EQ(psql.Arg(o.ID))), +// ReviewerReports starts a query for related objects on publicreport.report +func (o *User) ReviewerReports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery { + return PublicreportReports.Query(append(mods, + sm.Where(PublicreportReports.Columns.ReviewerID.EQ(psql.Arg(o.ID))), )...) } -func (os UserSlice) ReviewerWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery { +func (os UserSlice) ReviewerReports(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportReportsQuery { pkID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { @@ -1000,8 +1027,56 @@ func (os UserSlice) ReviewerWaters(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.ReviewerID).OP("IN", PKArgExpr)), + return PublicreportReports.Query(append(mods, + sm.Where(psql.Group(PublicreportReports.Columns.ReviewerID).OP("IN", PKArgExpr)), + )...) +} + +// ReviewerWaterOlds starts a query for related objects on publicreport.water_old +func (o *User) ReviewerWaterOlds(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWaterOldsQuery { + return PublicreportWaterOlds.Query(append(mods, + sm.Where(PublicreportWaterOlds.Columns.ReviewerID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) ReviewerWaterOlds(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.ReviewerID).OP("IN", PKArgExpr)), + )...) +} + +// CreatorReportTexts starts a query for related objects on report_text +func (o *User) CreatorReportTexts(mods ...bob.Mod[*dialect.SelectQuery]) ReportTextsQuery { + return ReportTexts.Query(append(mods, + sm.Where(ReportTexts.Columns.CreatorID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) CreatorReportTexts(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.CreatorID).OP("IN", PKArgExpr)), )...) } @@ -1309,6 +1384,74 @@ func (user0 *User) AttachPublicUserUser(ctx context.Context, exec bob.Executor, return nil } +func insertUserCreatorTextJobs0(ctx context.Context, exec bob.Executor, commsTextJobs1 []*CommsTextJobSetter, user0 *User) (CommsTextJobSlice, error) { + for i := range commsTextJobs1 { + commsTextJobs1[i].CreatorID = omitnull.From(user0.ID) + } + + ret, err := CommsTextJobs.Insert(bob.ToMods(commsTextJobs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserCreatorTextJobs0: %w", err) + } + + return ret, nil +} + +func attachUserCreatorTextJobs0(ctx context.Context, exec bob.Executor, count int, commsTextJobs1 CommsTextJobSlice, user0 *User) (CommsTextJobSlice, error) { + setter := &CommsTextJobSetter{ + CreatorID: omitnull.From(user0.ID), + } + + err := commsTextJobs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserCreatorTextJobs0: %w", err) + } + + return commsTextJobs1, nil +} + +func (user0 *User) InsertCreatorTextJobs(ctx context.Context, exec bob.Executor, related ...*CommsTextJobSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + commsTextJobs1, err := insertUserCreatorTextJobs0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.CreatorTextJobs = append(user0.R.CreatorTextJobs, commsTextJobs1...) + + for _, rel := range commsTextJobs1 { + rel.R.CreatorUser = user0 + } + return nil +} + +func (user0 *User) AttachCreatorTextJobs(ctx context.Context, exec bob.Executor, related ...*CommsTextJob) error { + if len(related) == 0 { + return nil + } + + var err error + commsTextJobs1 := CommsTextJobSlice(related) + + _, err = attachUserCreatorTextJobs0(ctx, exec, len(related), commsTextJobs1, user0) + if err != nil { + return err + } + + user0.R.CreatorTextJobs = append(user0.R.CreatorTextJobs, commsTextJobs1...) + + for _, rel := range related { + rel.R.CreatorUser = user0 + } + + return nil +} + func insertUserCreatorComplianceReportRequests0(ctx context.Context, exec bob.Executor, complianceReportRequests1 []*ComplianceReportRequestSetter, user0 *User) (ComplianceReportRequestSlice, error) { for i := range complianceReportRequests1 { complianceReportRequests1[i].Creator = omit.From(user0.ID) @@ -2057,66 +2200,66 @@ func (user0 *User) AttachUserNotifications(ctx context.Context, exec bob.Executo return nil } -func insertUserReviewerNuisances0(ctx context.Context, exec bob.Executor, publicreportNuisances1 []*PublicreportNuisanceSetter, user0 *User) (PublicreportNuisanceSlice, error) { - for i := range publicreportNuisances1 { - publicreportNuisances1[i].ReviewerID = omitnull.From(user0.ID) +func insertUserReviewerNuisanceOlds0(ctx context.Context, exec bob.Executor, publicreportNuisanceOlds1 []*PublicreportNuisanceOldSetter, user0 *User) (PublicreportNuisanceOldSlice, error) { + for i := range publicreportNuisanceOlds1 { + publicreportNuisanceOlds1[i].ReviewerID = omitnull.From(user0.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("insertUserReviewerNuisances0: %w", err) + return ret, fmt.Errorf("insertUserReviewerNuisanceOlds0: %w", err) } return ret, nil } -func attachUserReviewerNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNuisances1 PublicreportNuisanceSlice, user0 *User) (PublicreportNuisanceSlice, error) { - setter := &PublicreportNuisanceSetter{ +func attachUserReviewerNuisanceOlds0(ctx context.Context, exec bob.Executor, count int, publicreportNuisanceOlds1 PublicreportNuisanceOldSlice, user0 *User) (PublicreportNuisanceOldSlice, error) { + setter := &PublicreportNuisanceOldSetter{ ReviewerID: omitnull.From(user0.ID), } - err := publicreportNuisances1.UpdateAll(ctx, exec, *setter) + err := publicreportNuisanceOlds1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachUserReviewerNuisances0: %w", err) + return nil, fmt.Errorf("attachUserReviewerNuisanceOlds0: %w", err) } - return publicreportNuisances1, nil + return publicreportNuisanceOlds1, nil } -func (user0 *User) InsertReviewerNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error { +func (user0 *User) InsertReviewerNuisanceOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceOldSetter) error { if len(related) == 0 { return nil } var err error - publicreportNuisances1, err := insertUserReviewerNuisances0(ctx, exec, related, user0) + publicreportNuisanceOlds1, err := insertUserReviewerNuisanceOlds0(ctx, exec, related, user0) if err != nil { return err } - user0.R.ReviewerNuisances = append(user0.R.ReviewerNuisances, publicreportNuisances1...) + user0.R.ReviewerNuisanceOlds = append(user0.R.ReviewerNuisanceOlds, publicreportNuisanceOlds1...) - for _, rel := range publicreportNuisances1 { + for _, rel := range publicreportNuisanceOlds1 { rel.R.ReviewerUser = user0 } return nil } -func (user0 *User) AttachReviewerNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error { +func (user0 *User) AttachReviewerNuisanceOlds(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 = attachUserReviewerNuisances0(ctx, exec, len(related), publicreportNuisances1, user0) + _, err = attachUserReviewerNuisanceOlds0(ctx, exec, len(related), publicreportNuisanceOlds1, user0) if err != nil { return err } - user0.R.ReviewerNuisances = append(user0.R.ReviewerNuisances, publicreportNuisances1...) + user0.R.ReviewerNuisanceOlds = append(user0.R.ReviewerNuisanceOlds, publicreportNuisanceOlds1...) for _, rel := range related { rel.R.ReviewerUser = user0 @@ -2125,66 +2268,66 @@ func (user0 *User) AttachReviewerNuisances(ctx context.Context, exec bob.Executo return nil } -func insertUserReviewerWaters0(ctx context.Context, exec bob.Executor, publicreportWaters1 []*PublicreportWaterSetter, user0 *User) (PublicreportWaterSlice, error) { - for i := range publicreportWaters1 { - publicreportWaters1[i].ReviewerID = omitnull.From(user0.ID) +func insertUserReviewerReports0(ctx context.Context, exec bob.Executor, publicreportReports1 []*PublicreportReportSetter, user0 *User) (PublicreportReportSlice, error) { + for i := range publicreportReports1 { + publicreportReports1[i].ReviewerID = omitnull.From(user0.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("insertUserReviewerWaters0: %w", err) + return ret, fmt.Errorf("insertUserReviewerReports0: %w", err) } return ret, nil } -func attachUserReviewerWaters0(ctx context.Context, exec bob.Executor, count int, publicreportWaters1 PublicreportWaterSlice, user0 *User) (PublicreportWaterSlice, error) { - setter := &PublicreportWaterSetter{ +func attachUserReviewerReports0(ctx context.Context, exec bob.Executor, count int, publicreportReports1 PublicreportReportSlice, user0 *User) (PublicreportReportSlice, error) { + setter := &PublicreportReportSetter{ ReviewerID: omitnull.From(user0.ID), } - err := publicreportWaters1.UpdateAll(ctx, exec, *setter) + err := publicreportReports1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachUserReviewerWaters0: %w", err) + return nil, fmt.Errorf("attachUserReviewerReports0: %w", err) } - return publicreportWaters1, nil + return publicreportReports1, nil } -func (user0 *User) InsertReviewerWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error { +func (user0 *User) InsertReviewerReports(ctx context.Context, exec bob.Executor, related ...*PublicreportReportSetter) error { if len(related) == 0 { return nil } var err error - publicreportWaters1, err := insertUserReviewerWaters0(ctx, exec, related, user0) + publicreportReports1, err := insertUserReviewerReports0(ctx, exec, related, user0) if err != nil { return err } - user0.R.ReviewerWaters = append(user0.R.ReviewerWaters, publicreportWaters1...) + user0.R.ReviewerReports = append(user0.R.ReviewerReports, publicreportReports1...) - for _, rel := range publicreportWaters1 { + for _, rel := range publicreportReports1 { rel.R.ReviewerUser = user0 } return nil } -func (user0 *User) AttachReviewerWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error { +func (user0 *User) AttachReviewerReports(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 = attachUserReviewerWaters0(ctx, exec, len(related), publicreportWaters1, user0) + _, err = attachUserReviewerReports0(ctx, exec, len(related), publicreportReports1, user0) if err != nil { return err } - user0.R.ReviewerWaters = append(user0.R.ReviewerWaters, publicreportWaters1...) + user0.R.ReviewerReports = append(user0.R.ReviewerReports, publicreportReports1...) for _, rel := range related { rel.R.ReviewerUser = user0 @@ -2193,6 +2336,142 @@ func (user0 *User) AttachReviewerWaters(ctx context.Context, exec bob.Executor, return nil } +func insertUserReviewerWaterOlds0(ctx context.Context, exec bob.Executor, publicreportWaterOlds1 []*PublicreportWaterOldSetter, user0 *User) (PublicreportWaterOldSlice, error) { + for i := range publicreportWaterOlds1 { + publicreportWaterOlds1[i].ReviewerID = omitnull.From(user0.ID) + } + + ret, err := PublicreportWaterOlds.Insert(bob.ToMods(publicreportWaterOlds1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserReviewerWaterOlds0: %w", err) + } + + return ret, nil +} + +func attachUserReviewerWaterOlds0(ctx context.Context, exec bob.Executor, count int, publicreportWaterOlds1 PublicreportWaterOldSlice, user0 *User) (PublicreportWaterOldSlice, error) { + setter := &PublicreportWaterOldSetter{ + ReviewerID: omitnull.From(user0.ID), + } + + err := publicreportWaterOlds1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserReviewerWaterOlds0: %w", err) + } + + return publicreportWaterOlds1, nil +} + +func (user0 *User) InsertReviewerWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOldSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportWaterOlds1, err := insertUserReviewerWaterOlds0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.ReviewerWaterOlds = append(user0.R.ReviewerWaterOlds, publicreportWaterOlds1...) + + for _, rel := range publicreportWaterOlds1 { + rel.R.ReviewerUser = user0 + } + return nil +} + +func (user0 *User) AttachReviewerWaterOlds(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterOld) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportWaterOlds1 := PublicreportWaterOldSlice(related) + + _, err = attachUserReviewerWaterOlds0(ctx, exec, len(related), publicreportWaterOlds1, user0) + if err != nil { + return err + } + + user0.R.ReviewerWaterOlds = append(user0.R.ReviewerWaterOlds, publicreportWaterOlds1...) + + for _, rel := range related { + rel.R.ReviewerUser = user0 + } + + return nil +} + +func insertUserCreatorReportTexts0(ctx context.Context, exec bob.Executor, reportTexts1 []*ReportTextSetter, user0 *User) (ReportTextSlice, error) { + for i := range reportTexts1 { + reportTexts1[i].CreatorID = omit.From(user0.ID) + } + + ret, err := ReportTexts.Insert(bob.ToMods(reportTexts1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserCreatorReportTexts0: %w", err) + } + + return ret, nil +} + +func attachUserCreatorReportTexts0(ctx context.Context, exec bob.Executor, count int, reportTexts1 ReportTextSlice, user0 *User) (ReportTextSlice, error) { + setter := &ReportTextSetter{ + CreatorID: omit.From(user0.ID), + } + + err := reportTexts1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserCreatorReportTexts0: %w", err) + } + + return reportTexts1, nil +} + +func (user0 *User) InsertCreatorReportTexts(ctx context.Context, exec bob.Executor, related ...*ReportTextSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + reportTexts1, err := insertUserCreatorReportTexts0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.CreatorReportTexts = append(user0.R.CreatorReportTexts, reportTexts1...) + + for _, rel := range reportTexts1 { + rel.R.CreatorUser = user0 + } + return nil +} + +func (user0 *User) AttachCreatorReportTexts(ctx context.Context, exec bob.Executor, related ...*ReportText) error { + if len(related) == 0 { + return nil + } + + var err error + reportTexts1 := ReportTextSlice(related) + + _, err = attachUserCreatorReportTexts0(ctx, exec, len(related), reportTexts1, user0) + if err != nil { + return err + } + + user0.R.CreatorReportTexts = append(user0.R.CreatorReportTexts, reportTexts1...) + + for _, rel := range related { + rel.R.CreatorUser = user0 + } + + return nil +} + func insertUserCreatorResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, user0 *User) (ResidentSlice, error) { for i := range residents1 { residents1[i].Creator = omit.From(user0.ID) @@ -2721,6 +3000,20 @@ func (o *User) Preload(name string, retrieved any) error { } } return nil + case "CreatorTextJobs": + rels, ok := retrieved.(CommsTextJobSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.CreatorTextJobs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.CreatorUser = o + } + } + return nil case "CreatorComplianceReportRequests": rels, ok := retrieved.(ComplianceReportRequestSlice) if !ok { @@ -2875,13 +3168,13 @@ func (o *User) Preload(name string, retrieved any) error { } } return nil - case "ReviewerNuisances": - rels, ok := retrieved.(PublicreportNuisanceSlice) + case "ReviewerNuisanceOlds": + rels, ok := retrieved.(PublicreportNuisanceOldSlice) if !ok { return fmt.Errorf("user cannot load %T as %q", retrieved, name) } - o.R.ReviewerNuisances = rels + o.R.ReviewerNuisanceOlds = rels for _, rel := range rels { if rel != nil { @@ -2889,13 +3182,13 @@ func (o *User) Preload(name string, retrieved any) error { } } return nil - case "ReviewerWaters": - rels, ok := retrieved.(PublicreportWaterSlice) + case "ReviewerReports": + rels, ok := retrieved.(PublicreportReportSlice) if !ok { return fmt.Errorf("user cannot load %T as %q", retrieved, name) } - o.R.ReviewerWaters = rels + o.R.ReviewerReports = rels for _, rel := range rels { if rel != nil { @@ -2903,6 +3196,34 @@ func (o *User) Preload(name string, retrieved any) error { } } return nil + case "ReviewerWaterOlds": + rels, ok := retrieved.(PublicreportWaterOldSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.ReviewerWaterOlds = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ReviewerUser = o + } + } + return nil + case "CreatorReportTexts": + rels, ok := retrieved.(ReportTextSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.CreatorReportTexts = rels + + for _, rel := range rels { + if rel != nil { + rel.R.CreatorUser = o + } + } + return nil case "CreatorResidents": rels, ok := retrieved.(ResidentSlice) if !ok { @@ -3029,6 +3350,7 @@ func buildUserPreloader() userPreloader { type userThenLoader[Q orm.Loadable] struct { UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CreatorTextJobs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorComplianceReportRequests func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorFeatures func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CommitterFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] @@ -3040,8 +3362,10 @@ type userThenLoader[Q orm.Loadable] struct { CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReviewerNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - ReviewerWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerNuisanceOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerReports func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReviewerWaterOlds func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CreatorReportTexts func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorReviewTasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] ReviewerReviewTasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] @@ -3058,6 +3382,9 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { type PublicUserUserLoadInterface interface { LoadPublicUserUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type CreatorTextJobsLoadInterface interface { + LoadCreatorTextJobs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type CreatorComplianceReportRequestsLoadInterface interface { LoadCreatorComplianceReportRequests(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -3091,11 +3418,17 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { type UserNotificationsLoadInterface interface { LoadUserNotifications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type ReviewerNuisancesLoadInterface interface { - LoadReviewerNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type ReviewerNuisanceOldsLoadInterface interface { + LoadReviewerNuisanceOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type ReviewerWatersLoadInterface interface { - LoadReviewerWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type ReviewerReportsLoadInterface interface { + LoadReviewerReports(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReviewerWaterOldsLoadInterface interface { + LoadReviewerWaterOlds(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type CreatorReportTextsLoadInterface interface { + LoadCreatorReportTexts(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } type CreatorResidentsLoadInterface interface { LoadCreatorResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error @@ -3132,6 +3465,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { return retrieved.LoadPublicUserUser(ctx, exec, mods...) }, ), + CreatorTextJobs: thenLoadBuilder[Q]( + "CreatorTextJobs", + func(ctx context.Context, exec bob.Executor, retrieved CreatorTextJobsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCreatorTextJobs(ctx, exec, mods...) + }, + ), CreatorComplianceReportRequests: thenLoadBuilder[Q]( "CreatorComplianceReportRequests", func(ctx context.Context, exec bob.Executor, retrieved CreatorComplianceReportRequestsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -3198,16 +3537,28 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { return retrieved.LoadUserNotifications(ctx, exec, mods...) }, ), - ReviewerNuisances: thenLoadBuilder[Q]( - "ReviewerNuisances", - func(ctx context.Context, exec bob.Executor, retrieved ReviewerNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadReviewerNuisances(ctx, exec, mods...) + ReviewerNuisanceOlds: thenLoadBuilder[Q]( + "ReviewerNuisanceOlds", + func(ctx context.Context, exec bob.Executor, retrieved ReviewerNuisanceOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReviewerNuisanceOlds(ctx, exec, mods...) }, ), - ReviewerWaters: thenLoadBuilder[Q]( - "ReviewerWaters", - func(ctx context.Context, exec bob.Executor, retrieved ReviewerWatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadReviewerWaters(ctx, exec, mods...) + ReviewerReports: thenLoadBuilder[Q]( + "ReviewerReports", + func(ctx context.Context, exec bob.Executor, retrieved ReviewerReportsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReviewerReports(ctx, exec, mods...) + }, + ), + ReviewerWaterOlds: thenLoadBuilder[Q]( + "ReviewerWaterOlds", + func(ctx context.Context, exec bob.Executor, retrieved ReviewerWaterOldsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReviewerWaterOlds(ctx, exec, mods...) + }, + ), + CreatorReportTexts: thenLoadBuilder[Q]( + "CreatorReportTexts", + func(ctx context.Context, exec bob.Executor, retrieved CreatorReportTextsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCreatorReportTexts(ctx, exec, mods...) }, ), CreatorResidents: thenLoadBuilder[Q]( @@ -3377,6 +3728,70 @@ func (os UserSlice) LoadPublicUserUser(ctx context.Context, exec bob.Executor, m return nil } +// LoadCreatorTextJobs loads the user's CreatorTextJobs into the .R struct +func (o *User) LoadCreatorTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CreatorTextJobs = nil + + related, err := o.CreatorTextJobs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.CreatorUser = o + } + + o.R.CreatorTextJobs = related + return nil +} + +// LoadCreatorTextJobs loads the user's CreatorTextJobs into the .R struct +func (os UserSlice) LoadCreatorTextJobs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + commsTextJobs, err := os.CreatorTextJobs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.CreatorTextJobs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range commsTextJobs { + + if !rel.CreatorID.IsValue() { + continue + } + if !(rel.CreatorID.IsValue() && o.ID == rel.CreatorID.MustGet()) { + continue + } + + rel.R.CreatorUser = o + + o.R.CreatorTextJobs = append(o.R.CreatorTextJobs, rel) + } + } + + return nil +} + // LoadCreatorComplianceReportRequests loads the user's CreatorComplianceReportRequests into the .R struct func (o *User) LoadCreatorComplianceReportRequests(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -4057,16 +4472,16 @@ func (os UserSlice) LoadUserNotifications(ctx context.Context, exec bob.Executor return nil } -// LoadReviewerNuisances loads the user's ReviewerNuisances into the .R struct -func (o *User) LoadReviewerNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReviewerNuisanceOlds loads the user's ReviewerNuisanceOlds into the .R struct +func (o *User) LoadReviewerNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } // Reset the relationship - o.R.ReviewerNuisances = nil + o.R.ReviewerNuisanceOlds = nil - related, err := o.ReviewerNuisances(mods...).All(ctx, exec) + related, err := o.ReviewerNuisanceOlds(mods...).All(ctx, exec) if err != nil { return err } @@ -4075,17 +4490,17 @@ func (o *User) LoadReviewerNuisances(ctx context.Context, exec bob.Executor, mod rel.R.ReviewerUser = o } - o.R.ReviewerNuisances = related + o.R.ReviewerNuisanceOlds = related return nil } -// LoadReviewerNuisances loads the user's ReviewerNuisances into the .R struct -func (os UserSlice) LoadReviewerNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReviewerNuisanceOlds loads the user's ReviewerNuisanceOlds into the .R struct +func (os UserSlice) LoadReviewerNuisanceOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } - publicreportNuisances, err := os.ReviewerNuisances(mods...).All(ctx, exec) + publicreportNuisanceOlds, err := os.ReviewerNuisanceOlds(mods...).All(ctx, exec) if err != nil { return err } @@ -4095,7 +4510,7 @@ func (os UserSlice) LoadReviewerNuisances(ctx context.Context, exec bob.Executor continue } - o.R.ReviewerNuisances = nil + o.R.ReviewerNuisanceOlds = nil } for _, o := range os { @@ -4103,7 +4518,7 @@ func (os UserSlice) LoadReviewerNuisances(ctx context.Context, exec bob.Executor continue } - for _, rel := range publicreportNuisances { + for _, rel := range publicreportNuisanceOlds { if !rel.ReviewerID.IsValue() { continue @@ -4114,23 +4529,23 @@ func (os UserSlice) LoadReviewerNuisances(ctx context.Context, exec bob.Executor rel.R.ReviewerUser = o - o.R.ReviewerNuisances = append(o.R.ReviewerNuisances, rel) + o.R.ReviewerNuisanceOlds = append(o.R.ReviewerNuisanceOlds, rel) } } return nil } -// LoadReviewerWaters loads the user's ReviewerWaters into the .R struct -func (o *User) LoadReviewerWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReviewerReports loads the user's ReviewerReports into the .R struct +func (o *User) LoadReviewerReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { return nil } // Reset the relationship - o.R.ReviewerWaters = nil + o.R.ReviewerReports = nil - related, err := o.ReviewerWaters(mods...).All(ctx, exec) + related, err := o.ReviewerReports(mods...).All(ctx, exec) if err != nil { return err } @@ -4139,17 +4554,17 @@ func (o *User) LoadReviewerWaters(ctx context.Context, exec bob.Executor, mods . rel.R.ReviewerUser = o } - o.R.ReviewerWaters = related + o.R.ReviewerReports = related return nil } -// LoadReviewerWaters loads the user's ReviewerWaters into the .R struct -func (os UserSlice) LoadReviewerWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// LoadReviewerReports loads the user's ReviewerReports into the .R struct +func (os UserSlice) LoadReviewerReports(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if len(os) == 0 { return nil } - publicreportWaters, err := os.ReviewerWaters(mods...).All(ctx, exec) + publicreportReports, err := os.ReviewerReports(mods...).All(ctx, exec) if err != nil { return err } @@ -4159,7 +4574,7 @@ func (os UserSlice) LoadReviewerWaters(ctx context.Context, exec bob.Executor, m continue } - o.R.ReviewerWaters = nil + o.R.ReviewerReports = nil } for _, o := range os { @@ -4167,7 +4582,7 @@ func (os UserSlice) LoadReviewerWaters(ctx context.Context, exec bob.Executor, m continue } - for _, rel := range publicreportWaters { + for _, rel := range publicreportReports { if !rel.ReviewerID.IsValue() { continue @@ -4178,7 +4593,132 @@ func (os UserSlice) LoadReviewerWaters(ctx context.Context, exec bob.Executor, m rel.R.ReviewerUser = o - o.R.ReviewerWaters = append(o.R.ReviewerWaters, rel) + o.R.ReviewerReports = append(o.R.ReviewerReports, rel) + } + } + + return nil +} + +// LoadReviewerWaterOlds loads the user's ReviewerWaterOlds into the .R struct +func (o *User) LoadReviewerWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReviewerWaterOlds = nil + + related, err := o.ReviewerWaterOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ReviewerUser = o + } + + o.R.ReviewerWaterOlds = related + return nil +} + +// LoadReviewerWaterOlds loads the user's ReviewerWaterOlds into the .R struct +func (os UserSlice) LoadReviewerWaterOlds(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + publicreportWaterOlds, err := os.ReviewerWaterOlds(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ReviewerWaterOlds = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportWaterOlds { + + if !rel.ReviewerID.IsValue() { + continue + } + if !(rel.ReviewerID.IsValue() && o.ID == rel.ReviewerID.MustGet()) { + continue + } + + rel.R.ReviewerUser = o + + o.R.ReviewerWaterOlds = append(o.R.ReviewerWaterOlds, rel) + } + } + + return nil +} + +// LoadCreatorReportTexts loads the user's CreatorReportTexts into the .R struct +func (o *User) LoadCreatorReportTexts(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CreatorReportTexts = nil + + related, err := o.CreatorReportTexts(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.CreatorUser = o + } + + o.R.CreatorReportTexts = related + return nil +} + +// LoadCreatorReportTexts loads the user's CreatorReportTexts into the .R struct +func (os UserSlice) LoadCreatorReportTexts(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + reportTexts, err := os.CreatorReportTexts(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.CreatorReportTexts = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range reportTexts { + + if !(o.ID == rel.CreatorID) { + continue + } + + rel.R.CreatorUser = o + + o.R.CreatorReportTexts = append(o.R.CreatorReportTexts, rel) } } diff --git a/db/sql/publicreport_image_with_json_by_nuisance_id.bob.go b/db/sql/publicreport_image_with_json_by_nuisance_id.bob.go deleted file mode 100644 index 8d212514..00000000 --- a/db/sql/publicreport_image_with_json_by_nuisance_id.bob.go +++ /dev/null @@ -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) -} diff --git a/db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql b/db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql deleted file mode 100644 index bc70146f..00000000 --- a/db/sql/publicreport_image_with_json_by_nuisance_id.bob.sql +++ /dev/null @@ -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); diff --git a/db/sql/publicreport_image_with_json_by_nuisance_id.sql b/db/sql/publicreport_image_with_json_by_nuisance_id.sql deleted file mode 100644 index 4230d56c..00000000 --- a/db/sql/publicreport_image_with_json_by_nuisance_id.sql +++ /dev/null @@ -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) diff --git a/db/sql/publicreport_image_with_json_by_water_id.bob.go b/db/sql/publicreport_image_with_json_by_water_id.bob.go deleted file mode 100644 index 30b16a93..00000000 --- a/db/sql/publicreport_image_with_json_by_water_id.bob.go +++ /dev/null @@ -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) -} diff --git a/db/sql/publicreport_image_with_json_by_water_id.bob.sql b/db/sql/publicreport_image_with_json_by_water_id.bob.sql deleted file mode 100644 index 5b3be486..00000000 --- a/db/sql/publicreport_image_with_json_by_water_id.bob.sql +++ /dev/null @@ -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); diff --git a/db/sql/publicreport_image_with_json_by_water_id.sql b/db/sql/publicreport_image_with_json_by_water_id.sql deleted file mode 100644 index 1ec6949e..00000000 --- a/db/sql/publicreport_image_with_json_by_water_id.sql +++ /dev/null @@ -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) diff --git a/db/sql/publicreport_publicid_suggestion.bob.go b/db/sql/publicreport_publicid_suggestion.bob.go deleted file mode 100644 index 4bf153c2..00000000 --- a/db/sql/publicreport_publicid_suggestion.bob.go +++ /dev/null @@ -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) -} diff --git a/db/sql/publicreport_publicid_suggestion.bob.sql b/db/sql/publicreport_publicid_suggestion.bob.sql deleted file mode 100644 index 2311ddd1..00000000 --- a/db/sql/publicreport_publicid_suggestion.bob.sql +++ /dev/null @@ -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; diff --git a/db/sql/publicreport_publicid_suggestion.sql b/db/sql/publicreport_publicid_suggestion.sql deleted file mode 100644 index 9fbfb9a0..00000000 --- a/db/sql/publicreport_publicid_suggestion.sql +++ /dev/null @@ -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; diff --git a/db/sql/publicreport_publicid_table.bob.go b/db/sql/publicreport_publicid_table.bob.go deleted file mode 100644 index a8b23cbc..00000000 --- a/db/sql/publicreport_publicid_table.bob.go +++ /dev/null @@ -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) -} diff --git a/db/sql/publicreport_publicid_table.bob.sql b/db/sql/publicreport_publicid_table.bob.sql deleted file mode 100644 index 2c9c643f..00000000 --- a/db/sql/publicreport_publicid_table.bob.sql +++ /dev/null @@ -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; diff --git a/db/sql/publicreport_publicid_table.sql b/db/sql/publicreport_publicid_table.sql deleted file mode 100644 index bd61f040..00000000 --- a/db/sql/publicreport_publicid_table.sql +++ /dev/null @@ -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; diff --git a/platform/background/background.go b/platform/background/background.go index 90a69d7c..cd34bc72 100644 --- a/platform/background/background.go +++ b/platform/background/background.go @@ -3,6 +3,7 @@ package background import ( "context" "fmt" + "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/nidus-sync/db/enums" @@ -26,11 +27,15 @@ func NewEmailSend(ctx context.Context, txn bob.Executor, email_id int32) error { func NewLabelStudioAudioCreate(ctx context.Context, txn bob.Executor, note_audio_id int32) error { return newJob(ctx, txn, enums.JobtypeLabelStudioAudioCreate, note_audio_id) } -func NewTextSend(ctx context.Context, txn bob.Executor, text_id int32) error { - return newJob(ctx, txn, enums.JobtypeTextSend, text_id) +func NewTextRespond(ctx context.Context, txn bob.Executor, text_id int32) error { + return newJob(ctx, txn, enums.JobtypeTextRespond, text_id) +} +func NewTextSend(ctx context.Context, txn bob.Executor, job_id int32) error { + return newJob(ctx, txn, enums.JobtypeTextSend, job_id) } func newJob(ctx context.Context, txn bob.Executor, t enums.Jobtype, id int32) error { _, err := models.Jobs.Insert(&models.JobSetter{ + Created: omit.From(time.Now()), // ID Type: omit.From(t), RowID: omit.From(id), diff --git a/platform/communication.go b/platform/communication.go index 5303f2bb..c277923e 100644 --- a/platform/communication.go +++ b/platform/communication.go @@ -9,16 +9,9 @@ import ( ) func NotificationCount(ctx context.Context, org *models.Organization, user *models.User) (result uint, err error) { - count_nreports, err := publicreport.NuisanceReportForOrganizationCount(ctx, org.ID) + count_reports, err := publicreport.ReportsForOrganizationCount(ctx, org.ID) if err != nil { - return 0, fmt.Errorf("nuisance report query: %w", err) + return 0, fmt.Errorf("report query: %w", err) } - result += count_nreports - - count_wreports, err := publicreport.WaterReportForOrganizationCount(ctx, org.ID) - if err != nil { - return 0, fmt.Errorf("water report query: %w", err) - } - result += count_wreports - return result, nil + return uint(count_reports), nil } diff --git a/platform/csv/flyover.go b/platform/csv/flyover.go index 1f63a48e..5290aeec 100644 --- a/platform/csv/flyover.go +++ b/platform/csv/flyover.go @@ -225,8 +225,8 @@ func insertFlyover(ctx context.Context, txn bob.Tx, file *models.FileuploadFile, um.SetCol("geom").To(geom_query), um.SetCol("is_in_district").To(psql.F("ST_Contains", "org.service_area_geometry", geom_query)), um.From("fileupload.csv").As("csv"), - um.InnerJoin("fileupload.file").As("file").OnEQ(psql.Raw("csv.file_id"), psql.Raw("file.id")), - um.InnerJoin("organization").As("org").OnEQ(psql.Raw("file.organization_id"), psql.Raw("org.id")), + um.InnerJoin("fileupload.file").As("file").OnEQ(psql.Quote("csv", "file_id"), psql.Quote("file", "id")), + um.InnerJoin("organization").As("org").OnEQ(psql.Quote("file", "organization_id"), psql.Quote("org", "id")), um.Where(psql.Quote("pool", "id").EQ(psql.Arg(flyover.ID))), ).Exec(ctx, txn) if err != nil { diff --git a/platform/event/event.go b/platform/event/event.go index e703deb3..6467db13 100644 --- a/platform/event/event.go +++ b/platform/event/event.go @@ -73,6 +73,7 @@ type ResourceType int const ( TypeUnknown = iota TypeRMONuisance + TypeRMOReport TypeRMOWater ) diff --git a/platform/label_studio.go b/platform/label_studio.go index 43e841b9..190559dd 100644 --- a/platform/label_studio.go +++ b/platform/label_studio.go @@ -21,24 +21,27 @@ var labelStudioProject *labelstudio.Project var minioClient *minio.Client func initializeLabelStudio() error { - // Initialize the minio client - //minioBucket := os.Getenv("S3_BUCKET") - - var err error - labelStudioClient, err = createLabelStudioClient() - if err != nil { - return fmt.Errorf("Failed to create label studio client: %w", err) - } - // Get the project we are going to upload to - labelStudioProject, err = findLabelStudioProject(labelStudioClient, "Nidus Speech-to-Text Transcriptions") - if err != nil { - return fmt.Errorf("Failed to find the label studio project: %w", err) - } - minioClient, err = createMinioClient() - if err != nil { - return fmt.Errorf("Failed to create minio client: %w", err) - } return nil + /* + // Initialize the minio client + //minioBucket := os.Getenv("S3_BUCKET") + + var err error + labelStudioClient, err = createLabelStudioClient() + if err != nil { + return fmt.Errorf("Failed to create label studio client: %w", err) + } + // Get the project we are going to upload to + labelStudioProject, err = findLabelStudioProject(labelStudioClient, "Nidus Speech-to-Text Transcriptions") + if err != nil { + return fmt.Errorf("Failed to find the label studio project: %w", err) + } + minioClient, err = createMinioClient() + if err != nil { + return fmt.Errorf("Failed to create minio client: %w", err) + } + return nil + */ } func createMinioClient() (*minio.Client, error) { baseUrl := os.Getenv("S3_BASE_URL") diff --git a/platform/notification.go b/platform/notification.go index 33d77bf1..8f56a71a 100644 --- a/platform/notification.go +++ b/platform/notification.go @@ -111,21 +111,15 @@ func NotificationCountsForUser(ctx context.Context, u User) (*UserNotificationCo if err != nil { return nil, fmt.Errorf("Failed to get home notification count: %w", err) } - count_nuisance, err := u.Organization.model.Nuisances( - models.SelectWhere.PublicreportNuisances.Reviewed.IsNull(), + count_reports, err := u.Organization.model.Reports( + models.SelectWhere.PublicreportReports.Reviewed.IsNull(), ).Count(ctx, db.PGInstance.BobDB) if err != nil { return nil, fmt.Errorf("Failed to get nuisance notification count: %w", err) } - count_water, err := u.Organization.model.Waters( - models.SelectWhere.PublicreportWaters.Reviewed.IsNull(), - ).Count(ctx, db.PGInstance.BobDB) - if err != nil { - return nil, fmt.Errorf("Failed to get water notification count: %w", err) - } - log.Debug().Int64("nuisance", count_nuisance).Int64("water", count_water).Int64("home", count_home).Int("user", u.ID).Msg("calculated notification counts") + log.Debug().Int64("reports", count_reports).Int64("home", count_home).Int("user", u.ID).Msg("calculated notification counts") return &UserNotificationCounts{ - Communications: uint(count_nuisance + count_water), + Communications: uint(count_reports), Home: uint(count_home), }, nil } diff --git a/platform/nuisance.go b/platform/nuisance.go index cf63e09f..0d3b65ce 100644 --- a/platform/nuisance.go +++ b/platform/nuisance.go @@ -1,104 +1 @@ package platform - -import ( - "context" - "fmt" - - "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/um" - "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/Gleipnir-Technology/nidus-sync/platform/event" - "github.com/Gleipnir-Technology/nidus-sync/platform/geocode" - "github.com/Gleipnir-Technology/nidus-sync/platform/report" - "github.com/Gleipnir-Technology/nidus-sync/platform/types" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - "github.com/rs/zerolog/log" -) - -func NuisanceCreate(ctx context.Context, setter models.PublicreportNuisanceSetter, latlng LatLng, address Address, images []ImageUpload) (public_id string, err error) { - txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) - if err != nil { - return "", fmt.Errorf("create txn: %w", err) - } - defer txn.Rollback(ctx) - - public_id, err = report.GenerateReportID() - if err != nil { - return "", fmt.Errorf("create public ID: %w", err) - } - setter.PublicID = omit.From(public_id) - - // If we've got an locality value it was set by geocoding so we should save it - var a *models.Address - if address.Locality != "" && latlng.Latitude != nil && latlng.Longitude != nil { - a, err = geocode.EnsureAddress(ctx, txn, address, types.Location{ - Latitude: *latlng.Latitude, - Longitude: *latlng.Longitude, - }) - if err != nil { - return "", fmt.Errorf("Failed to ensure address: %w", err) - } - } - - saved_images, err := saveImageUploads(ctx, txn, images) - if err != nil { - return "", fmt.Errorf("Failed to save image uploads: %w", err) - } - var organization_id *int32 - organization_id, err = MatchDistrict(ctx, latlng.Longitude, latlng.Latitude, images) - if err != nil { - log.Warn().Err(err).Msg("Failed to match district") - } - - if a != nil { - setter.AddressID = omitnull.From(a.ID) - } - if organization_id != nil { - setter.OrganizationID = omit.FromPtr(organization_id) - } - nuisance, err := models.PublicreportNuisances.Insert(&setter).One(ctx, txn) - if err != nil { - return "", fmt.Errorf("Failed to create database record: %w", err) - } - if latlng.Latitude != nil && latlng.Longitude != nil { - h3cell, _ := latlng.H3Cell() - geom_query, _ := latlng.GeometryQuery() - _, err = psql.Update( - um.Table("publicreport.nuisance"), - um.SetCol("h3cell").ToArg(h3cell), - um.SetCol("location").To(geom_query), - um.Where(psql.Quote("id").EQ(psql.Arg(nuisance.ID))), - ).Exec(ctx, txn) - if err != nil { - return "", fmt.Errorf("Failed to insert publicreport.nuisance geospatial", err) - } - } - log.Info().Str("public_id", public_id).Int32("id", nuisance.ID).Msg("Created nuisance report") - if len(saved_images) > 0 { - setters := make([]*models.PublicreportNuisanceImageSetter, 0) - for _, image := range saved_images { - setters = append(setters, &models.PublicreportNuisanceImageSetter{ - ImageID: omit.From(int32(image.ID)), - NuisanceID: omit.From(int32(nuisance.ID)), - }) - } - _, err = models.PublicreportNuisanceImages.Insert(bob.ToMods(setters...)).Exec(ctx, txn) - if err != nil { - return "", fmt.Errorf("Failed to save reference to images: %w", err) - } - log.Info().Int("len", len(images)).Msg("saved uploaded images") - } - txn.Commit(ctx) - - if organization_id != nil { - event.Created( - event.TypeRMONuisance, - *organization_id, - nuisance.PublicID, - ) - } - return nuisance.PublicID, nil -} diff --git a/platform/publicreport.go b/platform/publicreport.go index f0a89490..d16055f1 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -6,9 +6,9 @@ import ( "fmt" "time" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" //"github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/um" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" @@ -20,71 +20,68 @@ import ( ) func PublicreportInvalid(ctx context.Context, user User, report_id string) error { - tablename, _, err := reportFromID(ctx, user, report_id) + report, err := reportFromID(ctx, user, report_id) if err != nil { return fmt.Errorf("query report existence: %w", err) } - _, err = psql.Update( - um.Table("publicreport."+tablename), - um.SetCol("reviewed").ToArg(time.Now()), - um.SetCol("reviewer_id").ToArg(user.ID), - um.SetCol("status").ToArg(enums.PublicreportReportstatustypeInvalidated), - um.Where(psql.Quote("public_id").EQ(psql.Arg(report_id))), - ).Exec(ctx, db.PGInstance.BobDB) - if err != nil { - return fmt.Errorf("update report %s.%s: %w", tablename, report_id, err) - } + err = report.Update(ctx, db.PGInstance.BobDB, &models.PublicreportReportSetter{ + Reviewed: omitnull.From(time.Now()), + ReviewerID: omitnull.From(int32(user.ID)), + Status: omit.From(enums.PublicreportReportstatustypeInvalidated), + }) - log.Info().Str("report-id", report_id).Str("tablename", tablename).Msg("Marked as invalid") - resource := resourceTypeFromTablename(tablename) - event.Updated(resource, user.Organization.ID(), report_id) + log.Info().Int32("id", report.ID).Msg("Report marked as invalid") + event.Updated(event.TypeRMOReport, user.Organization.ID(), report_id) return nil } func PublicReportMessageCreate(ctx context.Context, user User, report_id, message string) (message_id *int32, err error) { - _, report, err := reportFromID(ctx, user, report_id) + txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) + if err != nil { + return nil, fmt.Errorf("create txn: %w", err) + } + defer txn.Rollback(ctx) + + report, err := reportFromID(ctx, user, report_id) if err != nil { return nil, fmt.Errorf("query report existence: %w", err) } - if report.ReporterPhone.GetOr("") != "" { - msg_id, err := text.ReportMessage(ctx, int32(user.ID), report_id, report.ReporterPhone.MustGet(), message) + if report.ReporterPhone != "" { + log.Debug().Str("report_id", report_id).Msg("contacting via phone") + p, err := text.ParsePhoneNumber(report.ReporterPhone) + if err != nil { + return nil, fmt.Errorf("parse phone: %w", err) + } + msg_id, err := text.ReportMessage(ctx, txn, int32(user.ID), int32(report.ID), *p, message) if err != nil { return nil, fmt.Errorf("send text: %w", err) } + txn.Commit(ctx) + log.Debug().Int32("msg_id", *msg_id).Msg("Created text.ReportMessage") return msg_id, nil - } else if report.ReporterEmail.GetOr("") != "" { - msg_id, err := email.ReportMessage(ctx, int32(user.ID), report_id, report.ReporterEmail.MustGet(), message) + } else if report.ReporterEmail != "" { + msg_id, err := email.ReportMessage(ctx, int32(user.ID), report_id, report.ReporterEmail, message) if err != nil { return nil, fmt.Errorf("send email: %w", err) } + txn.Commit(ctx) return msg_id, nil } else { + log.Debug().Str("report_id", report_id).Msg("contacting via email") return nil, errors.New("no contact methods available") } } func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id string, tablename string) { - resource := resourceTypeFromTablename(tablename) - event.Updated(resource, org_id, report_id) + event.Updated(event.TypeRMOReport, org_id, report_id) } -func resourceTypeFromTablename(tablename string) event.ResourceType { - switch tablename { - case "nuisance": - return event.TypeRMONuisance - case "water": - return event.TypeRMOWater - default: - return event.TypeUnknown - } -} -func reportFromID(ctx context.Context, user User, report_id string) (string, *models.PublicreportReportLocation, error) { - report, err := models.PublicreportReportLocations.Query( - models.SelectWhere.PublicreportReportLocations.PublicID.EQ(report_id), - models.SelectWhere.PublicreportReportLocations.OrganizationID.EQ(user.Organization.ID()), +func reportFromID(ctx context.Context, user User, report_id string) (*models.PublicreportReport, error) { + report, err := models.PublicreportReports.Query( + models.SelectWhere.PublicreportReports.PublicID.EQ(report_id), + models.SelectWhere.PublicreportReports.OrganizationID.EQ(user.Organization.ID()), ).One(ctx, db.PGInstance.BobDB) if err != nil { - return "", nil, err + return nil, err } - tablename := report.TableName.MustGet() - return tablename, report, nil + return report, nil } diff --git a/platform/publicreport/image.go b/platform/publicreport/image.go index 5a4737cb..3dc78b03 100644 --- a/platform/publicreport/image.go +++ b/platform/publicreport/image.go @@ -28,85 +28,37 @@ LEFT JOIN publicreport.image_exif e ON i.id = e.image_id WHERE i.id IN (1, 2, 3, 4) GROUP BY i.id; */ -// Get all the images that belong to the list of nuisance report IDs -func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids []int32) (results map[int32][]types.Image, err error) { +// Get all the images that belong to the list of report IDs +func loadImagesForReport(ctx context.Context, org_id int32, report_ids []int32) (results map[int32][]types.Image, err error) { rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( "i.storage_uuid AS uuid", "COALESCE(ST_X(i.location), 0) AS \"location.longitude\"", "COALESCE(ST_Y(i.location), 0) AS \"location.latitude\"", - "ST_Distance(i.location::geography, n.location::geography) AS \"distance_from_reporter_meters\"", + "ST_Distance(i.location::geography, r.location::geography) AS \"distance_from_reporter_meters\"", "COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Make'), '') AS exif_make", "COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Model'), '') AS exif_model", "COALESCE(MAX(e.value) FILTER (WHERE e.name = 'DateTime'), '') AS exif_datetime", - "ni.nuisance_id AS report_id", + "r.id AS report_id", ), sm.From("publicreport.image").As("i"), sm.LeftJoin("publicreport.image_exif").As("e").OnEQ( psql.Quote("i", "id"), psql.Quote("e", "image_id"), ), - sm.InnerJoin("publicreport.nuisance_image").As("ni").OnEQ( - psql.Quote("ni", "image_id"), + sm.InnerJoin("publicreport.report_image").As("ri").OnEQ( + psql.Quote("ri", "image_id"), psql.Quote("i", "id"), ), - sm.InnerJoin("publicreport.nuisance").As("n").OnEQ( - psql.Quote("ni", "nuisance_id"), - psql.Quote("n", "id"), + sm.InnerJoin("publicreport.report").As("r").OnEQ( + psql.Quote("ri", "report_id"), + psql.Quote("r", "id"), ), - sm.Where(psql.Quote("ni", "nuisance_id").EQ(psql.Any(report_ids))), + sm.Where(psql.Quote("ri", "report_id").EQ(psql.Any(report_ids))), sm.GroupBy( //psql.Quote("i", "id"), //psql.Quote("ni", "nuisance_id"), - psql.Raw("i.id, ni.nuisance_id, n.location"), - ), - ), scan.StructMapper[types.Image]()) - if err != nil { - return nil, fmt.Errorf("get images: %w", err) - } - results = make(map[int32][]types.Image, len(report_ids)) - for _, row := range rows { - r, ok := results[row.ReportID] - if !ok { - r = make([]types.Image, 0) - } - r = append(r, row) - results[row.ReportID] = r - } - return results, nil -} - -// Get all the images that belong to the list of water report IDs -func loadImagesForReportWater(ctx context.Context, org_id int32, report_ids []int32) (results map[int32][]types.Image, err error) { - rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( - sm.Columns( - "i.storage_uuid AS uuid", - "COALESCE(ST_X(i.location), 0) AS \"location.longitude\"", - "COALESCE(ST_Y(i.location), 0) AS \"location.latitude\"", - "ST_Distance(i.location::geography, w.location::geography) AS \"distance_from_reporter_meters\"", - "COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Make'), '') AS exif_make", - "COALESCE(MAX(e.value) FILTER (WHERE e.name = 'Model'), '') AS exif_model", - "COALESCE(MAX(e.value) FILTER (WHERE e.name = 'DateTime'), '') AS exif_datetime", - "wi.water_id AS report_id", - ), - sm.From("publicreport.image").As("i"), - sm.LeftJoin("publicreport.image_exif").As("e").OnEQ( - psql.Quote("i", "id"), - psql.Quote("e", "image_id"), - ), - sm.InnerJoin("publicreport.water_image").As("wi").OnEQ( - psql.Quote("wi", "image_id"), - psql.Quote("i", "id"), - ), - sm.InnerJoin("publicreport.water").As("w").OnEQ( - psql.Quote("wi", "water_id"), - psql.Quote("w", "id"), - ), - sm.Where(psql.Quote("wi", "water_id").EQ(psql.Any(report_ids))), - sm.GroupBy( - //psql.Quote("i", "id"), - //psql.Quote("ni", "nuisance_id"), - psql.Raw("i.id, wi.water_id, w.location"), + psql.Raw("i.id, ri.report_id, r.id, r.location"), ), ), scan.StructMapper[types.Image]()) if err != nil { diff --git a/platform/publicreport/nuisance.go b/platform/publicreport/nuisance.go index c1249ace..6ef7d498 100644 --- a/platform/publicreport/nuisance.go +++ b/platform/publicreport/nuisance.go @@ -3,71 +3,47 @@ package publicreport import ( "context" "fmt" - "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/bob/dialect/psql" "github.com/Gleipnir-Technology/bob/dialect/psql/sm" //"github.com/Gleipnir-Technology/nidus-sync/config" "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/platform/types" - //"github.com/Gleipnir-Technology/nidus-sync/db/models" //"github.com/google/uuid" //"github.com/rs/zerolog/log" "github.com/stephenafamo/scan" ) type Nuisance struct { - AdditionalInfo string `db:"additional_info" json:"additional_info"` - Address types.Address `db:"address" json:"address"` - AddressRaw string `db:"address_raw" json:"address_raw"` - Created time.Time `db:"created" json:"created"` - Duration string `db:"duration" json:"duration"` - ID int32 `db:"id" json:"-"` - Images []types.Image `db:"-" json:"images"` - IsLocationBackyard bool `db:"is_location_backyard" json:"is_location_backyard"` - IsLocationFrontyard bool `db:"is_location_frontyard" json:"is_location_frontyard"` - IsLocationGarden bool `db:"is_location_garden" json:"is_location_garden"` - IsLocationOther bool `db:"is_location_other" json:"is_location_other"` - IsLocationPool bool `db:"is_location_pool" json:"is_location_pool"` - Location types.Location `db:"location" json:"location"` - PublicID string `db:"public_id" json:"public_id"` - Reporter types.Contact `db:"reporter" json:"reporter"` - SourceContainer bool `db:"source_container" json:"source_container"` - SourceDescription string `db:"source_description" json:"source_description"` - SourceGutter bool `db:"source_gutter" json:"source_gutter"` - SourceStagnant bool `db:"source_stagnant" json:"source_stagnant"` - TODDay bool `db:"tod_day" json:"time_of_day_day"` - TODEarly bool `db:"tod_early" json:"time_of_day_early"` - TODEvening bool `db:"tod_evening" json:"time_of_day_evening"` - TODNight bool `db:"tod_night" json:"time_of_day_night"` + AdditionalInfo string `db:"additional_info" json:"additional_info"` + Duration string `db:"duration" json:"duration"` + IsLocationBackyard bool `db:"is_location_backyard" json:"is_location_backyard"` + IsLocationFrontyard bool `db:"is_location_frontyard" json:"is_location_frontyard"` + IsLocationGarden bool `db:"is_location_garden" json:"is_location_garden"` + IsLocationOther bool `db:"is_location_other" json:"is_location_other"` + IsLocationPool bool `db:"is_location_pool" json:"is_location_pool"` + ReportID int32 `db:"report_id" json:"-"` + SourceContainer bool `db:"source_container" json:"source_container"` + SourceDescription string `db:"source_description" json:"source_description"` + SourceGutter bool `db:"source_gutter" json:"source_gutter"` + SourceStagnant bool `db:"source_stagnant" json:"source_stagnant"` + TODDay bool `db:"tod_day" json:"time_of_day_day"` + TODEarly bool `db:"tod_early" json:"time_of_day_early"` + TODEvening bool `db:"tod_evening" json:"time_of_day_evening"` + TODNight bool `db:"tod_night" json:"time_of_day_night"` } -func NuisanceReportForOrganization(ctx context.Context, org_id int32) ([]Nuisance, error) { - reports, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( +func nuisancesByReportID(ctx context.Context, report_ids []int32) (map[int32]*Nuisance, error) { + rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( "additional_info", - "address_raw AS address_raw", - "address_country AS \"address.country\"", - "address_locality AS \"address.locality\"", - "address_number AS \"address.number\"", - "address_postal_code AS \"address.postal_code\"", - "address_region AS \"address.region\"", - "address_street AS \"address.street\"", - "created", "duration", - "id", "is_location_backyard", "is_location_frontyard", "is_location_garden", "is_location_other", "is_location_pool", - "ST_Y(location::geometry::geometry(point, 4326)) AS \"location.latitude\"", - "ST_X(location::geometry::geometry(point, 4326)) AS \"location.longitude\"", - "public_id", - "reporter_email AS \"reporter.email\"", - "reporter_name AS \"reporter.name\"", - "reporter_phone AS \"reporter.phone\"", + "report_id", "source_container", "source_description", "source_gutter", @@ -78,43 +54,32 @@ func NuisanceReportForOrganization(ctx context.Context, org_id int32) ([]Nuisanc "tod_night", ), sm.From("publicreport.nuisance"), - sm.Where(psql.Quote("publicreport", "nuisance", "organization_id").EQ(psql.Arg(org_id))), - sm.Where(psql.Quote("publicreport", "nuisance", "reviewed").IsNull()), + sm.Where(psql.Quote("report_id").EQ( + psql.Any(report_ids), + )), ), scan.StructMapper[Nuisance]()) if err != nil { - return nil, fmt.Errorf("get reports: %w", err) + return nil, fmt.Errorf("query nuisance: %w", err) } - report_ids := make([]int32, len(reports)) - for i, report := range reports { - report_ids[i] = report.ID - } - images_by_id, err := loadImagesForReportNuisance(ctx, org_id, report_ids) - if err != nil { - return nil, fmt.Errorf("images for report: %w", err) - } - for i := range reports { - images, ok := images_by_id[reports[i].ID] - if ok { - reports[i].Images = images - } else { - reports[i].Images = []types.Image{} + results := make(map[int32]*Nuisance, len(rows)) + for _, row := range rows { + results[row.ReportID] = &Nuisance{ + AdditionalInfo: row.AdditionalInfo, + Duration: row.Duration, + IsLocationBackyard: row.IsLocationBackyard, + IsLocationFrontyard: row.IsLocationFrontyard, + IsLocationGarden: row.IsLocationGarden, + IsLocationOther: row.IsLocationOther, + IsLocationPool: row.IsLocationPool, + SourceContainer: row.SourceContainer, + SourceDescription: row.SourceDescription, + SourceGutter: row.SourceGutter, + SourceStagnant: row.SourceStagnant, + TODDay: row.TODDay, + TODEarly: row.TODEarly, + TODEvening: row.TODEvening, + TODNight: row.TODNight, } } - return reports, nil -} -func NuisanceReportForOrganizationCount(ctx context.Context, org_id int32) (uint, error) { - type _Row struct { - Count uint `db:"count"` - } - row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.Columns( - "COUNT(*) AS count", - ), - sm.From("publicreport.nuisance"), - sm.Where(psql.Quote("publicreport", "nuisance", "organization_id").EQ(psql.Arg(org_id))), - ), scan.StructMapper[_Row]()) - if err != nil { - return 0, fmt.Errorf("query count: %w", err) - } - return row.Count, nil + return results, nil } diff --git a/platform/publicreport/report.go b/platform/publicreport/report.go new file mode 100644 index 00000000..93e6913b --- /dev/null +++ b/platform/publicreport/report.go @@ -0,0 +1,106 @@ +package publicreport + +import ( + "context" + "fmt" + "time" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/sm" + //"github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/Gleipnir-Technology/nidus-sync/db" + //"github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + //"github.com/google/uuid" + //"github.com/rs/zerolog/log" + "github.com/stephenafamo/scan" +) + +type Report struct { + Address types.Address `db:"address" json:"address"` + AddressRaw string `db:"address_raw" json:"address_raw"` + Created time.Time `db:"created" json:"created"` + ID int32 `db:"id" json:"-"` + Images []types.Image `db:"images" json:"images"` + Location types.Location `db:"location" json:"location"` + Nuisance *Nuisance `db:"nuisance" json:"nuisance"` + PublicID string `db:"public_id" json:"public_id"` + Reporter types.Contact `db:"reporter" json:"reporter"` + Status string `db:"status" json:"status"` + Water *Water `db:"water" json:"water"` +} + +func ReportsForOrganization(ctx context.Context, org_id int32) ([]Report, error) { + rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( + sm.Columns( + "address_country AS \"address.country\"", + "address_locality AS \"address.locality\"", + "address_number AS \"address.number\"", + "address_postal_code AS \"address.postal_code\"", + "address_raw AS address_raw", + "address_region AS \"address.region\"", + "address_street AS \"address.street\"", + "created", + "id", + "ST_Y(location::geometry::geometry(point, 4326)) AS \"location.latitude\"", + "ST_X(location::geometry::geometry(point, 4326)) AS \"location.longitude\"", + "public_id", + "reporter_email AS \"reporter.email\"", + "reporter_name AS \"reporter.name\"", + "reporter_phone AS \"reporter.phone\"", + "status", + ), + sm.From("publicreport.report"), + sm.Where(psql.Quote("publicreport", "report", "organization_id").EQ(psql.Arg(org_id))), + sm.Where(psql.Quote("publicreport", "report", "reviewed").IsNull()), + ), scan.StructMapper[Report]()) + + if err != nil { + return nil, fmt.Errorf("get reports: %w", err) + } + report_ids := make([]int32, len(rows)) + for i, row := range rows { + report_ids[i] = row.ID + } + images_by_id, err := loadImagesForReport(ctx, org_id, report_ids) + if err != nil { + return nil, fmt.Errorf("images for report: %w", err) + } + nuisances_by_report_id, err := nuisancesByReportID(ctx, report_ids) + if err != nil { + return nil, fmt.Errorf("nuisances: %w", err) + } + waters_by_report_id, err := watersByReportID(ctx, report_ids) + if err != nil { + return nil, fmt.Errorf("waters: %w", err) + } + + for _, row := range rows { + images, ok := images_by_id[row.ID] + if ok { + row.Images = images + } else { + row.Images = []types.Image{} + } + row.Nuisance = nuisances_by_report_id[row.ID] + row.Water = waters_by_report_id[row.ID] + } + return rows, nil +} +func ReportsForOrganizationCount(ctx context.Context, org_id int32) (uint, error) { + type _Row struct { + Count uint `db:"count"` + } + row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( + sm.Columns( + "COUNT(*) AS count", + ), + sm.From("publicreport.report"), + sm.Where(psql.Quote("publicreport", "report", "organization_id").EQ(psql.Arg(org_id))), + ), scan.StructMapper[_Row]()) + if err != nil { + return 0, fmt.Errorf("query count: %w", err) + } + return row.Count, nil +} diff --git a/platform/publicreport/water.go b/platform/publicreport/water.go index 56340efd..b9e3240a 100644 --- a/platform/publicreport/water.go +++ b/platform/publicreport/water.go @@ -3,7 +3,6 @@ package publicreport import ( "context" "fmt" - "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/bob/dialect/psql" @@ -18,34 +17,25 @@ import ( ) type Water struct { - AccessComments string `db:"access_comments" json:"access_comments"` - AccessGate bool `db:"access_gate" json:"access_gate"` - AccessFence bool `db:"access_fence" json:"access_fence"` - AccessLocked bool `db:"access_locked" json:"access_locked"` - AccessDog bool `db:"access_dog" json:"access_dog"` - AccessOther bool `db:"access_other" json:"access_other"` - Address types.Address `db:"address" json:"address"` - AddressRaw string `db:"address_raw" json:"address_raw"` - Comments string `db:"comments" json:"comments"` - Created time.Time `db:"created" json:"created"` - HasAdult bool `db:"has_adult" json:"has_adult"` - HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"` - HasLarvae bool `db:"has_larvae" json:"has_larvae"` - HasPupae bool `db:"has_pupae" json:"has_pupae"` - ID int32 `db:"id" json:"-"` - Images []types.Image `db:"-" json:"images"` - IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"` - IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"` - Location types.Location `db:"location" json:"location"` - Owner types.Contact `db:"owner" json:"owner"` - PublicID string `db:"public_id" json:"public_id"` - Reporter types.Contact `db:"reporter" json:"reporter"` - ReporterContactConsent *bool `db:"reporter_contact_consent" json:"reporter_contact_consent"` - Status string `db:"status" json:"status"` + AccessComments string `db:"access_comments" json:"access_comments"` + AccessGate bool `db:"access_gate" json:"access_gate"` + AccessFence bool `db:"access_fence" json:"access_fence"` + AccessLocked bool `db:"access_locked" json:"access_locked"` + AccessDog bool `db:"access_dog" json:"access_dog"` + AccessOther bool `db:"access_other" json:"access_other"` + Comments string `db:"comments" json:"comments"` + HasAdult bool `db:"has_adult" json:"has_adult"` + HasBackyardPermission bool `db:"has_backyard_permission" json:"has_backyard_permission"` + HasLarvae bool `db:"has_larvae" json:"has_larvae"` + HasPupae bool `db:"has_pupae" json:"has_pupae"` + IsReporterConfidential bool `db:"is_reporter_confidential" json:"is_reporter_confidential"` + IsReporterOwner bool `db:"is_reporter_owner" json:"is_reporter_owner"` + Owner types.Contact `db:"owner" json:"owner"` + ReportID int32 `db:"report_id" json:"-"` } -func WaterReportForOrganization(ctx context.Context, org_id int32) ([]Water, error) { - reports, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( +func watersByReportID(ctx context.Context, report_ids []int32) (map[int32]*Water, error) { + rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( "access_comments", "access_gate", @@ -53,72 +43,45 @@ func WaterReportForOrganization(ctx context.Context, org_id int32) ([]Water, err "access_locked", "access_dog", "access_other", - "access_gate AS address_raw", - "address_country AS \"address.country\"", - "address_locality AS \"address.locality\"", - "address_number AS \"address.number\"", - "address_postal_code AS \"address.postal_code\"", - "address_region AS \"address.region\"", - "address_street AS \"address.street\"", "comments", - "created", "has_adult", "has_backyard_permission", "has_larvae", "has_pupae", - "id", "is_reporter_confidential", "is_reporter_owner", - "ST_Y(location::geometry::geometry(point, 4326)) AS \"location.latitude\"", - "ST_X(location::geometry::geometry(point, 4326)) AS \"location.longitude\"", "owner_email AS \"owner.email\"", "owner_name AS \"owner.name\"", "owner_phone AS \"owner.phone\"", - "public_id", - "reporter_email AS \"reporter.email\"", - "reporter_name AS \"reporter.name\"", - "reporter_phone AS \"reporter.phone\"", - "reporter_contact_consent", - "status", + "report_id", ), sm.From("publicreport.water"), - sm.Where(psql.Quote("publicreport", "water", "organization_id").EQ(psql.Arg(org_id))), - sm.Where(psql.Quote("publicreport", "water", "reviewed").IsNull()), + sm.Where(psql.Quote("report_id").EQ( + psql.Any(report_ids), + )), ), scan.StructMapper[Water]()) if err != nil { - return nil, fmt.Errorf("get reports: %w", err) + return nil, fmt.Errorf("query water: %w", err) } - report_ids := make([]int32, len(reports)) - for i, report := range reports { - report_ids[i] = report.ID - } - images_by_id, err := loadImagesForReportWater(ctx, org_id, report_ids) - if err != nil { - return nil, fmt.Errorf("images for report: %w", err) - } - for i := range reports { - images, ok := images_by_id[reports[i].ID] - if ok { - reports[i].Images = images - } else { - reports[i].Images = []types.Image{} + results := make(map[int32]*Water, len(rows)) + for _, row := range rows { + results[row.ReportID] = &Water{ + AccessComments: row.AccessComments, + AccessGate: row.AccessGate, + AccessFence: row.AccessFence, + AccessLocked: row.AccessLocked, + AccessDog: row.AccessDog, + AccessOther: row.AccessOther, + Comments: row.Comments, + HasAdult: row.HasAdult, + HasBackyardPermission: row.HasBackyardPermission, + HasLarvae: row.HasLarvae, + HasPupae: row.HasPupae, + IsReporterConfidential: row.IsReporterConfidential, + IsReporterOwner: row.IsReporterOwner, + Owner: row.Owner, + ReportID: row.ReportID, } } - return reports, nil -} -func WaterReportForOrganizationCount(ctx context.Context, org_id int32) (uint, error) { - type _Row struct { - Count uint `db:"count"` - } - row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.Columns( - "COUNT(*) AS count", - ), - sm.From("publicreport.water"), - sm.Where(psql.Quote("publicreport", "water", "organization_id").EQ(psql.Arg(org_id))), - ), scan.StructMapper[_Row]()) - if err != nil { - return 0, fmt.Errorf("query count: %w", err) - } - return row.Count, nil + return results, nil } diff --git a/platform/report.go b/platform/report.go new file mode 100644 index 00000000..7d011ff2 --- /dev/null +++ b/platform/report.go @@ -0,0 +1,134 @@ +package platform + +import ( + "context" + "fmt" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/um" + "github.com/Gleipnir-Technology/nidus-sync/db" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/platform/event" + "github.com/Gleipnir-Technology/nidus-sync/platform/geocode" + "github.com/Gleipnir-Technology/nidus-sync/platform/report" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/rs/zerolog/log" +) + +func ReportNuisanceCreate(ctx context.Context, setter_report models.PublicreportReportSetter, setter_nuisance models.PublicreportNuisanceSetter, latlng LatLng, address Address, images []ImageUpload) (*models.PublicreportReport, error) { + return reportCreate(ctx, setter_report, latlng, address, images, func(ctx context.Context, txn bob.Executor, report_id int32) error { + setter_nuisance.ReportID = omit.From(report_id) + _, err := models.PublicreportNuisances.Insert(&setter_nuisance).One(ctx, txn) + if err != nil { + return fmt.Errorf("Failed to create nuisance database record: %w", err) + } + return nil + }) +} + +func ReportWaterCreate(ctx context.Context, setter_report models.PublicreportReportSetter, setter_water models.PublicreportWaterSetter, latlng LatLng, address Address, images []ImageUpload) (*models.PublicreportReport, error) { + return reportCreate(ctx, setter_report, latlng, address, images, func(ctx context.Context, txn bob.Executor, report_id int32) error { + setter_water.ReportID = omit.From(report_id) + _, err := models.PublicreportWaters.Insert(&setter_water).One(ctx, txn) + if err != nil { + return fmt.Errorf("Failed to create water database record: %w", err) + } + return nil + }) +} + +type funcSetReportDetail = func(context.Context, bob.Executor, int32) error + +func reportCreate(ctx context.Context, setter_report models.PublicreportReportSetter, latlng LatLng, address Address, images []ImageUpload, detail_setter funcSetReportDetail) (result *models.PublicreportReport, err error) { + txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) + if err != nil { + return nil, fmt.Errorf("create txn: %w", err) + } + defer txn.Rollback(ctx) + + public_id, err := report.GenerateReportID() + if err != nil { + return nil, fmt.Errorf("create public ID: %w", err) + } + setter_report.PublicID = omit.From(public_id) + + // If we've got an locality value it was set by geocoding so we should save it + var a *models.Address + if address.Locality != "" && latlng.Latitude != nil && latlng.Longitude != nil { + a, err = geocode.EnsureAddress(ctx, txn, address, types.Location{ + Latitude: *latlng.Latitude, + Longitude: *latlng.Longitude, + }) + if err != nil { + return nil, fmt.Errorf("Failed to ensure address: %w", err) + } + } + + saved_images, err := saveImageUploads(ctx, txn, images) + if err != nil { + return nil, fmt.Errorf("Failed to save image uploads: %w", err) + } + var organization_id *int32 + organization_id, err = MatchDistrict(ctx, latlng.Longitude, latlng.Latitude, images) + if err != nil { + log.Warn().Err(err).Msg("Failed to match district") + } + + if a != nil { + setter_report.AddressID = omitnull.From(a.ID) + } + if organization_id != nil { + setter_report.OrganizationID = omit.FromPtr(organization_id) + } + result, err = models.PublicreportReports.Insert(&setter_report).One(ctx, txn) + if err != nil { + return nil, fmt.Errorf("Failed to create report database record: %w", err) + } + if latlng.Latitude != nil && latlng.Longitude != nil { + h3cell, _ := latlng.H3Cell() + geom_query, _ := latlng.GeometryQuery() + _, err = psql.Update( + um.Table("publicreport.report"), + um.SetCol("h3cell").ToArg(h3cell), + um.SetCol("location").To(geom_query), + um.Where(psql.Quote("id").EQ(psql.Arg(result.ID))), + ).Exec(ctx, txn) + if err != nil { + return nil, fmt.Errorf("Failed to insert publicreport.report geospatial", err) + } + } + log.Info().Str("public_id", public_id).Int32("id", result.ID).Msg("Created base report") + + if len(saved_images) > 0 { + setters := make([]*models.PublicreportReportImageSetter, 0) + for _, image := range saved_images { + setters = append(setters, &models.PublicreportReportImageSetter{ + ImageID: omit.From(int32(image.ID)), + ReportID: omit.From(int32(result.ID)), + }) + } + _, err = models.PublicreportReportImages.Insert(bob.ToMods(setters...)).Exec(ctx, txn) + if err != nil { + return nil, fmt.Errorf("Failed to save reference to images: %w", err) + } + log.Info().Int("len", len(images)).Msg("saved uploaded images") + } + + err = detail_setter(ctx, txn, result.ID) + if err != nil { + return nil, fmt.Errorf("detail setter: %w", err) + } + txn.Commit(ctx) + + if organization_id != nil { + event.Created( + event.TypeRMONuisance, + *organization_id, + result.PublicID, + ) + } + return result, nil +} diff --git a/platform/report/notification.go b/platform/report/notification.go index c3f0a127..a558cd5d 100644 --- a/platform/report/notification.go +++ b/platform/report/notification.go @@ -5,35 +5,28 @@ import ( "crypto/rand" "fmt" "math/big" - "strconv" "strings" "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/Gleipnir-Technology/nidus-sync/db/sql" "github.com/Gleipnir-Technology/nidus-sync/platform/email" "github.com/Gleipnir-Technology/nidus-sync/platform/text" "github.com/Gleipnir-Technology/nidus-sync/platform/types" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" "github.com/rs/zerolog/log" - //"github.com/stephenafamo/scan" ) func DistrictForReport(ctx context.Context, report_id string) (*models.Organization, error) { - some_report, err := findSomeReport(ctx, report_id) + report, err := reportByPublicID(ctx, db.PGInstance.BobDB, report_id) if err != nil { return nil, fmt.Errorf("Failed to find report %s: %w", report_id, err) } - org_id := some_report.districtID(ctx) - if org_id == nil { - return nil, nil - } - result, e := models.FindOrganization(ctx, db.PGInstance.BobDB, *org_id) + result, e := models.FindOrganization(ctx, db.PGInstance.BobDB, report.OrganizationID) if e != nil { - return nil, fmt.Errorf("Failed to load organization %d: %w", org_id, e) + return nil, fmt.Errorf("Failed to load organization %d: %w", report.OrganizationID, e) } return result, nil } @@ -64,15 +57,15 @@ func GenerateReportID() (string, error) { } func RegisterNotificationEmail(ctx context.Context, txn bob.Executor, report_id string, destination string) *ErrorWithCode { - some_report, err := findSomeReport(ctx, report_id) - if err != nil { - return err + report, e := reportByPublicID(ctx, db.PGInstance.BobDB, report_id) + if e != nil { + return newInternalError(e, "Failed to find report") } - e := email.EnsureInDB(ctx, destination) + e = email.EnsureInDB(ctx, destination) if e != nil { return newInternalError(e, "Failed to ensure phone is in DB") } - err = some_report.addNotificationEmail(ctx, txn, destination) + err := addNotificationEmail(ctx, txn, report, destination) if err != nil { return err } @@ -81,19 +74,19 @@ func RegisterNotificationEmail(ctx context.Context, txn bob.Executor, report_id } func RegisterNotificationPhone(ctx context.Context, txn bob.Executor, report_id string, phone types.E164) *ErrorWithCode { - some_report, err := findSomeReport(ctx, report_id) - if err != nil { - return err + report, e := reportByPublicID(ctx, db.PGInstance.BobDB, report_id) + if e != nil { + return newInternalError(e, "Failed to find report") } - e := text.EnsureInDB(ctx, db.PGInstance.BobDB, phone) + e = text.EnsureInDB(ctx, db.PGInstance.BobDB, phone) if e != nil { return newInternalError(e, "Failed to ensure phone is in DB") } - err = some_report.addNotificationPhone(ctx, txn, phone) + err := addNotificationPhone(ctx, txn, report, phone) if err != nil { return err } - text.ReportSubscriptionConfirmationText(ctx, phone, report_id) + text.ReportSubscriptionConfirmationText(ctx, db.PGInstance.BobDB, phone, report.PublicID) return nil } @@ -136,64 +129,95 @@ func RegisterSubscriptionPhone(ctx context.Context, txn bob.Executor, phone type } func SaveReporter(ctx context.Context, txn bob.Executor, report_id string, name string, email string, phone *types.E164, has_consent bool) *ErrorWithCode { - some_report, err := findSomeReport(ctx, report_id) - if err != nil { - return err + report, e := reportByPublicID(ctx, db.PGInstance.BobDB, report_id) + if e != nil { + return newInternalError(e, "Failed to find report") } if name != "" { - err = some_report.updateReporterName(ctx, txn, name) + err := updateReporterName(ctx, txn, report, name) if err != nil { return err } } if phone != nil { - err = some_report.updateReporterPhone(ctx, txn, *phone) + err := updateReporterPhone(ctx, txn, report, *phone) if err != nil { return err } } if email != "" { - err = some_report.updateReporterEmail(ctx, txn, email) + err := updateReporterEmail(ctx, txn, report, email) if err != nil { return err } } - err = some_report.updateReporterConsent(ctx, txn, has_consent) + err := updateReporterConsent(ctx, txn, report, has_consent) if err != nil { return err } return nil } -func findSomeReport(ctx context.Context, report_id string) (result SomeReport, err *ErrorWithCode) { - rows, e := sql.PublicreportIDTable(report_id).All(ctx, db.PGInstance.BobDB) - if e != nil { - log.Error().Err(e).Str("report_id", report_id).Msg("failed to query report ID table") - return result, newErrorWithCode("internal-error", "Failed to query report ID table: %w", e) - } - switch len(rows) { - case 0: - return result, newErrorWithCode("invalid-report-id", "No reports match the provided ID") - case 1: - break - default: - log.Error().Err(e).Str("report_id", report_id).Msg("More than one report with the provided ID, which shouldn't happen") - return result, newErrorWithCode("internal-error", "More than one report with the provided ID, which shouldn't happen") - } - row := rows[0] - report_id_str := row.ReportIds[0] - t, e := strconv.ParseInt(report_id_str, 10, 32) - if e != nil { - log.Error().Err(e).Str("report_id_str", report_id_str).Msg("Unable to parse integer reponse from database") - return result, newErrorWithCode("internal-error", "Unable to parse integer response from database") - } - - switch row.FoundInTables[0] { - case "nuisance": - return newNuisance(ctx, report_id, int32(t)) - case "water": - return newWater(ctx, report_id, int32(t)) - default: - log.Error().Err(e).Str("table_name", row.FoundInTables[0]).Msg("Unrecognized table") - return Nuisance{}, newErrorWithCode("internal-error", fmt.Sprintf("Unrecognized table '%s'", row.FoundInTables[0])) - } +func reportByPublicID(ctx context.Context, txn bob.Executor, public_id string) (*models.PublicreportReport, error) { + return models.PublicreportReports.Query( + models.SelectWhere.PublicreportReports.PublicID.EQ(public_id), + ).One(ctx, txn) +} +func addNotificationEmail(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, email string) *ErrorWithCode { + setter := models.PublicreportNotifyEmailSetter{ + Created: omit.From(time.Now()), + Deleted: omitnull.FromPtr[time.Time](nil), + EmailAddress: omit.From(email), + ReportID: omit.From(report.ID), + } + _, err := models.PublicreportNotifyEmails.Insert(&setter).Exec(ctx, txn) + if err != nil { + return newInternalError(err, "Failed to save new notification email row") + } + return nil +} +func addNotificationPhone(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, phone types.E164) *ErrorWithCode { + var err error + setter := models.PublicreportNotifyPhoneSetter{ + Created: omit.From(time.Now()), + Deleted: omitnull.FromPtr[time.Time](nil), + PhoneE164: omit.From(phone.PhoneString()), + ReportID: omit.From(report.ID), + } + _, err = models.PublicreportNotifyPhones.Insert(&setter).Exec(ctx, txn) + if err != nil { + return newInternalError(err, "Failed to save new notification phone row") + } + return nil +} +func updateReporterConsent(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, has_consent bool) *ErrorWithCode { + return updateReportCol(ctx, txn, report, &models.PublicreportReportSetter{ + ReporterContactConsent: omitnull.From(has_consent), + }) +} +func updateReporterEmail(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, email string) *ErrorWithCode { + return updateReportCol(ctx, txn, report, &models.PublicreportReportSetter{ + ReporterEmail: omit.From(email), + }) +} +func updateReporterName(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, name string) *ErrorWithCode { + return updateReportCol(ctx, txn, report, &models.PublicreportReportSetter{ + ReporterName: omit.From(name), + }) +} +func updateReportCol(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, setter *models.PublicreportReportSetter) *ErrorWithCode { + err := report.Update(ctx, txn, setter) + if err != nil { + log.Error().Err(err).Str("public_id", report.PublicID).Int32("report_id", report.ID).Msg("Failed to update report") + return newInternalError(err, "Failed to update nuisance report in the database") + } + return nil +} +func updateReporterPhone(ctx context.Context, txn bob.Executor, report *models.PublicreportReport, phone types.E164) *ErrorWithCode { + err := report.Update(ctx, txn, &models.PublicreportReportSetter{ + ReporterPhone: omit.From(phone.PhoneString()), + }) + if err != nil { + return newInternalError(err, "Failed to update report: %w", err) + } + return nil } diff --git a/platform/report/report_nuisance.go b/platform/report/report_nuisance.go deleted file mode 100644 index e26f589c..00000000 --- a/platform/report/report_nuisance.go +++ /dev/null @@ -1,133 +0,0 @@ -package report - -import ( - "context" - //"crypto/rand" - //"fmt" - //"math/big" - //"strconv" - //"strings" - "time" - - "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/sm" - "github.com/Gleipnir-Technology/bob/dialect/psql/um" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - //"github.com/Gleipnir-Technology/nidus-sync/background" - "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/db/models" - //"github.com/Gleipnir-Technology/nidus-sync/db/sql" - "github.com/Gleipnir-Technology/nidus-sync/platform/types" - "github.com/rs/zerolog/log" - "github.com/stephenafamo/scan" -) - -type Nuisance struct { - id int32 - publicReportID string - row *models.PublicreportNuisance -} - -func (sr Nuisance) PublicReportID() string { - return sr.publicReportID -} -func (sr Nuisance) addNotificationEmail(ctx context.Context, txn bob.Executor, email string) *ErrorWithCode { - setter := models.PublicreportNotifyEmailNuisanceSetter{ - Created: omit.From(time.Now()), - Deleted: omitnull.FromPtr[time.Time](nil), - NuisanceID: omit.From(sr.id), - EmailAddress: omit.From(email), - } - _, err := models.PublicreportNotifyEmailNuisances.Insert(&setter).Exec(ctx, txn) - if err != nil { - return newInternalError(err, "Failed to save new notification email row") - } - return nil -} -func (sr Nuisance) addNotificationPhone(ctx context.Context, txn bob.Executor, phone types.E164) *ErrorWithCode { - var err error - setter := models.PublicreportNotifyPhoneNuisanceSetter{ - Created: omit.From(time.Now()), - Deleted: omitnull.FromPtr[time.Time](nil), - NuisanceID: omit.From(sr.id), - PhoneE164: omit.From(phone.PhoneString()), - } - _, err = models.PublicreportNotifyPhoneNuisances.Insert(&setter).Exec(ctx, txn) - if err != nil { - return newInternalError(err, "Failed to save new notification phone row") - } - return nil -} -func (sr Nuisance) districtID(ctx context.Context) *int32 { - type _Row struct { - OrganizationID *int32 - } - row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.From("publicreport.nuisance"), - sm.Columns("organization_id"), - sm.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))), - ), scan.StructMapper[_Row]()) - if err != nil { - log.Warn().Err(err).Msg("Failed to query for organization_id") - return nil - } - return row.OrganizationID -} -func (sr Nuisance) reportID() int32 { - return sr.id -} -func (sr Nuisance) updateReporterConsent(ctx context.Context, txn bob.Executor, has_consent bool) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportNuisanceSetter{ - ReporterContactConsent: omitnull.From(has_consent), - }) -} -func (sr Nuisance) updateReportCol(ctx context.Context, txn bob.Executor, setter *models.PublicreportNuisanceSetter) *ErrorWithCode { - err := sr.row.Update(ctx, txn, setter) - if err != nil { - log.Error().Err(err).Str("public_id", sr.publicReportID).Int32("report_id", sr.id).Msg("Failed to update report") - return newInternalError(err, "Failed to update nuisance report in the database") - } - return nil -} -func (sr Nuisance) updateReporterEmail(ctx context.Context, txn bob.Executor, email string) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportNuisanceSetter{ - ReporterEmail: omitnull.From(email), - }) -} -func (sr Nuisance) updateReporterName(ctx context.Context, txn bob.Executor, name string) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportNuisanceSetter{ - ReporterName: omitnull.From(name), - }) -} -func (sr Nuisance) updateReporterPhone(ctx context.Context, txn bob.Executor, phone types.E164) *ErrorWithCode { - result, err := psql.Update( - um.Table("publicreport.nuisance"), - um.SetCol("reporter_phone").ToArg(phone.PhoneString()), - um.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))), - ).Exec(ctx, txn) - if err != nil { - return newInternalError(err, "Failed to update report: %w", err) - } - rowcount, err := result.RowsAffected() - if err != nil { - return newInternalError(err, "Failed to get rows affected: %w", err) - } - if rowcount != 1 { - log.Warn().Str("public_report_id", sr.publicReportID).Msg("updated more than one row, which is a programmer error") - } - return nil -} - -func newNuisance(ctx context.Context, public_id string, report_id int32) (Nuisance, *ErrorWithCode) { - row, err := models.FindPublicreportNuisance(ctx, db.PGInstance.BobDB, report_id) - if err != nil { - return Nuisance{}, newInternalError(err, "Failed to find nuisance report %d: %w", public_id, err) - } - return Nuisance{ - id: report_id, - publicReportID: public_id, - row: row, - }, nil -} diff --git a/platform/report/report_water.go b/platform/report/report_water.go deleted file mode 100644 index 2f2f1550..00000000 --- a/platform/report/report_water.go +++ /dev/null @@ -1,119 +0,0 @@ -package report - -import ( - "context" - //"crypto/rand" - //"fmt" - //"math/big" - //"strconv" - //"strings" - "time" - - "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/sm" - "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/Gleipnir-Technology/nidus-sync/platform/types" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - "github.com/rs/zerolog/log" - "github.com/stephenafamo/scan" -) - -type Water struct { - id int32 - publicReportID string - row *models.PublicreportWater -} - -func (sr Water) PublicReportID() string { - return sr.publicReportID -} -func (sr Water) addNotificationEmail(ctx context.Context, txn bob.Executor, email string) *ErrorWithCode { - setter := models.PublicreportNotifyEmailWaterSetter{ - Created: omit.From(time.Now()), - Deleted: omitnull.FromPtr[time.Time](nil), - EmailAddress: omit.From(email), - WaterID: omit.From(sr.id), - } - _, err := models.PublicreportNotifyEmailWaters.Insert(&setter).Exec(ctx, txn) - if err != nil { - log.Error().Err(err).Msg("Failed to save new notification email row") - return newInternalError(err, "Failed to save new notification email row") - } - return nil -} -func (sr Water) addNotificationPhone(ctx context.Context, txn bob.Executor, phone types.E164) *ErrorWithCode { - setter := models.PublicreportNotifyPhoneWaterSetter{ - Created: omit.From(time.Now()), - Deleted: omitnull.FromPtr[time.Time](nil), - PhoneE164: omit.From(phone.PhoneString()), - WaterID: omit.From(sr.id), - } - _, err := models.PublicreportNotifyPhoneWaters.Insert(&setter).Exec(ctx, txn) - if err != nil { - log.Error().Err(err).Msg("Failed to save new notification phone row") - return newInternalError(err, "Failed to save new notification phone row") - } - return nil -} -func (sr Water) districtID(ctx context.Context) *int32 { - type _Row struct { - OrganizationID *int32 - } - - row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.From("publicreport.water"), - sm.Columns("organization_id"), - sm.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))), - ), scan.StructMapper[_Row]()) - if err != nil { - log.Warn().Err(err).Msg("Failed to query for organization_id") - return nil - } - return row.OrganizationID -} -func (sr Water) reportID() int32 { - return sr.id -} -func (sr Water) updateReporterConsent(ctx context.Context, txn bob.Executor, has_consent bool) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ - ReporterContactConsent: omitnull.From(has_consent), - }) -} -func (sr Water) updateReporterEmail(ctx context.Context, txn bob.Executor, email string) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ - ReporterEmail: omit.From(email), - }) -} -func (sr Water) updateReporterName(ctx context.Context, txn bob.Executor, name string) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ - ReporterName: omit.From(name), - }) -} -func (sr Water) updateReportCol(ctx context.Context, txn bob.Executor, setter *models.PublicreportWaterSetter) *ErrorWithCode { - err := sr.row.Update(ctx, txn, setter) - if err != nil { - log.Error().Err(err).Str("public_id", sr.publicReportID).Int32("report_id", sr.id).Msg("Failed to update report") - return newInternalError(err, "Failed to update water report in the database") - } - return nil -} -func (sr Water) updateReporterPhone(ctx context.Context, txn bob.Executor, phone types.E164) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ - ReporterPhone: omit.From(phone.PhoneString()), - }) -} -func newWater(ctx context.Context, public_id string, report_id int32) (Water, *ErrorWithCode) { - row, err := models.FindPublicreportWater(ctx, db.PGInstance.BobDB, report_id) - if err != nil { - log.Error().Err(err).Msg("Failed to find water report") - return Water{}, newInternalError(err, "Failed to find water report %d: %w", public_id, err) - } - return Water{ - id: report_id, - publicReportID: public_id, - row: row, - }, nil -} diff --git a/platform/start.go b/platform/start.go index 7dbdf158..41e35b85 100644 --- a/platform/start.go +++ b/platform/start.go @@ -60,6 +60,11 @@ func StartAll(ctx context.Context) error { defer waitGroup.Done() refreshFieldseekerData(ctx, newOAuthTokenChannel) }() + waitGroup.Add(1) + go func() { + defer waitGroup.Done() + listenForJobs(ctx) + }() err = addWaitingJobs(ctx) if err != nil { @@ -109,8 +114,10 @@ func handleJob(ctx context.Context, txn bob.Executor, job *models.Job) error { return handleJobLabelStudioAudioCreate(ctx, txn, job.RowID) case enums.JobtypeEmailSend: return email.Job(ctx, txn, job.RowID) + case enums.JobtypeTextRespond: + return text.JobRespond(ctx, txn, job.RowID) case enums.JobtypeTextSend: - return text.Job(ctx, txn, job.RowID) + return text.JobSend(ctx, txn, job.RowID) default: return fmt.Errorf("No handler for job type %s", string(job.Type)) } @@ -151,6 +158,7 @@ func listenAndDoOneJob(ctx context.Context) error { } for { + log.Debug().Msg("wait for notification") notification, err := conn.Conn().WaitForNotification(ctx) if err != nil { //if !pgconn.Timeout(err) { @@ -161,12 +169,14 @@ func listenAndDoOneJob(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to parse int from payload '%s': %w", notification.Payload, err) } + log.Debug().Int("job_id", job_id).Msg("got notification for job") c := bobpgx.NewConn(conn.Conn()) job, err := models.FindJob(ctx, c, int32(job_id)) if err != nil { return fmt.Errorf("Failed to find job %d: %w", job_id, err) } + sublog := log.With().Int32("job", job.ID).Int32("row_id", job.RowID).Str("type", string(job.Type)).Logger() //tx, err := c.BeginTx(ctx, pgx.TxOptions{}) tx, err := conn.BeginTx(ctx, pgx.TxOptions{}) @@ -176,7 +186,6 @@ func listenAndDoOneJob(ctx context.Context) error { ctx, cancel := context.WithCancel(ctx) txn := bobpgx.NewTx(tx, cancel) - sublog := log.With().Int32("job", job.ID).Int32("row_id", job.RowID).Logger() err = handleJob(ctx, txn, job) if err != nil { sublog.Error().Err(err).Msg("failed to handle job") @@ -190,5 +199,6 @@ func listenAndDoOneJob(ctx context.Context) error { return fmt.Errorf("delete job: %w", err) } txn.Commit(ctx) + sublog.Debug().Msg("job complete") } } diff --git a/platform/text/job.go b/platform/text/job.go index ddb65b48..494641e6 100644 --- a/platform/text/job.go +++ b/platform/text/job.go @@ -5,21 +5,35 @@ import ( "fmt" "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/nidus-sync/config" - "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/platform/types" + "github.com/rs/zerolog/log" ) -func Job(ctx context.Context, txn bob.Executor, text_id int32) error { - return sendTextComplete(ctx, txn, text_id) +func JobRespond(ctx context.Context, txn bob.Executor, log_id int32) error { + return respondText(ctx, txn, log_id) } - -func ReportSubscriptionConfirmationText(ctx context.Context, destination types.E164, report_id string) error { - content := fmt.Sprintf("Thanks for submitting mosquito report %s. Text for any questions. We'll send you updates as we get them.", report_id) - origin := enums.CommsTextoriginWebsiteAction - err := sendTextBegin(ctx, *types.NewE164(&config.PhoneNumberReport), destination, content, origin, true, true) +func JobSend(ctx context.Context, txn bob.Executor, job_id int32) error { + job, err := models.FindCommsTextJob(ctx, txn, job_id) if err != nil { - return fmt.Errorf("Failed to send initial confirmation: %w", err) + return fmt.Errorf("find text: %w", err) } - return err + log.Debug().Int32("job.id", job.ID).Msg("completing text job") + return sendTextComplete(ctx, txn, job) +} +func handleWaitingTextJobs(ctx context.Context, txn bob.Executor, dst types.E164) error { + jobs, err := models.CommsTextJobs.Query( + models.SelectWhere.CommsTextJobs.Destination.EQ(dst.PhoneString()), + models.SelectWhere.CommsTextJobs.Completed.IsNull(), + ).All(ctx, txn) + if err != nil { + return fmt.Errorf("query jobs: %w", err) + } + for _, job := range jobs { + err = sendTextComplete(ctx, txn, job) + if err != nil { + return fmt.Errorf("send text complete: %w", err) + } + } + return nil } diff --git a/platform/text/llm.go b/platform/text/llm.go index efd664fa..6acf58ec 100644 --- a/platform/text/llm.go +++ b/platform/text/llm.go @@ -1,9 +1,90 @@ package text import ( + "context" + + "fmt" "github.com/rs/zerolog/log" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/um" + "github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/Gleipnir-Technology/nidus-sync/db" + //"github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/db/sql" + "github.com/Gleipnir-Technology/nidus-sync/llm" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + //"github.com/rs/zerolog/log" ) func SendTextFromLLM(content string) { log.Info().Str("content", content).Msg("Pretend I sent a message") } +func generateNextMessage(ctx context.Context, history []llm.Message, customer_phone types.E164) (llm.Message, error) { + _handle_report_status := func() (string, error) { + return "Report: ABCD-1234-5678, District: Delta MVCD, Status: scheduled, Appointment: Wednesday 3:30pm", nil + } + _handle_contact_district := func(reason string) { + log.Warn().Str("reason", reason).Msg("Contacting district") + } + _handle_contact_supervisor := func(reason string) { + log.Warn().Str("reason", reason).Msg("Contacting supervisor") + } + return llm.GenerateNextMessage(ctx, history, _handle_report_status, _handle_contact_district, _handle_contact_supervisor) +} +func handleResetConversation(ctx context.Context, txn bob.Executor, src types.E164) error { + err := wipeLLMMemory(ctx, src) + sublog := log.With().Str("src", src.PhoneString()).Logger() + if err != nil { + return fmt.Errorf("wipe memory: %w") + } + content := "LLM memory wiped" + err = sendTextCommandResponse(ctx, txn, src, content) + if err != nil { + return fmt.Errorf("Failed to indicated memory wiped: %w", err) + } + sublog.Info().Err(err).Msg("Wiped LLM memory") + return nil +} + +func loadPreviousMessagesForLLM(ctx context.Context, src types.E164) ([]llm.Message, error) { + messages, err := sql.TextsBySenders(config.PhoneNumberReportStr, src.PhoneString()).All(ctx, db.PGInstance.BobDB) + results := make([]llm.Message, 0) + if err != nil { + return results, fmt.Errorf("Failed to get message history for %s and %s: %w", config.PhoneNumberReportStr, src, err) + } + for _, m := range messages { + if m.IsVisibleToLLM { + is_from_customer := (m.Source == src.PhoneString()) + results = append(results, llm.Message{ + IsFromCustomer: is_from_customer, + Content: m.Content, + }) + } + } + return results, nil +} +func wipeLLMMemory(ctx context.Context, src types.E164) error { + destination := config.PhoneNumberReportStr + rows, err := sql.TextsBySenders(destination, src.PhoneString()).All(ctx, db.PGInstance.BobDB) + if err != nil { + return fmt.Errorf("Failed to query for texts: %w", err) + } + ids := make([]int32, 0) + for _, r := range rows { + ids = append(ids, r.ID) + } + _, err = models.CommsTextLogs.Update( + um.Where( + models.CommsTextLogs.Columns.ID.EQ(psql.Any(ids)), + ), + um.SetCol("is_visible_to_llm").ToArg(false), + ).Exec(ctx, db.PGInstance.BobDB) + if err != nil { + return fmt.Errorf("Failed to update texts: %w", err) + } + + return nil +} diff --git a/platform/text/phone_number.go b/platform/text/phone_number.go new file mode 100644 index 00000000..c75a92f0 --- /dev/null +++ b/platform/text/phone_number.go @@ -0,0 +1,50 @@ +package text + +import ( + "context" + "fmt" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/im" + "github.com/Gleipnir-Technology/nidus-sync/db" + "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + "github.com/aarondl/opt/omit" + "github.com/rs/zerolog/log" +) + +func EnsureInDB(ctx context.Context, txn bob.Executor, dst types.E164) (err error) { + return ensureInDB(ctx, txn, dst.PhoneString()) +} +func ensureInDB(ctx context.Context, txn bob.Executor, destination string) (err error) { + _, err = psql.Insert( + im.Into("comms.phone", "e164", "is_subscribed", "status"), + im.Values( + psql.Arg(destination), + psql.Arg(false), + psql.Arg("unconfirmed"), + ), + im.OnConflict("e164").DoNothing(), + ).Exec(ctx, txn) + return err +} +func phoneStatus(ctx context.Context, src types.E164) (enums.CommsPhonestatustype, error) { + phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, src.PhoneString()) + if err != nil { + return enums.CommsPhonestatustypeUnconfirmed, fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src.PhoneString(), err) + } + return phone.Status, nil +} +func setPhoneStatus(ctx context.Context, txn bob.Executor, src types.E164, status enums.CommsPhonestatustype) error { + phone, err := models.FindCommsPhone(ctx, txn, src.PhoneString()) + if err != nil { + return fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src, err) + } + phone.Update(ctx, txn, &models.CommsPhoneSetter{ + Status: omit.From(status), + }) + log.Info().Str("src", src.PhoneString()).Str("status", string(status)).Msg("Set number subscribed") + return nil +} diff --git a/platform/text/report-subscription.go b/platform/text/report-subscription.go deleted file mode 100644 index 579a08fc..00000000 --- a/platform/text/report-subscription.go +++ /dev/null @@ -1,42 +0,0 @@ -package text - -import ( - "context" - "fmt" - - "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/db/enums" - "github.com/Gleipnir-Technology/nidus-sync/platform/types" - //"github.com/rs/zerolog/log" -) - -func sendReportSubscription(ctx context.Context, source, destination types.E164, content string) error { - err := EnsureInDB(ctx, db.PGInstance.BobDB, destination) - if err != nil { - return fmt.Errorf("Failed to ensure text message destination is in the DB: %w", err) - } - status, err := phoneStatus(ctx, destination) - if err != nil { - return fmt.Errorf("Failed to check if subscribed: %w", err) - } - switch status { - case enums.CommsPhonestatustypeUnconfirmed: - err = delayMessage(ctx, enums.CommsTextjobsourceRmo, destination, content, enums.CommsTextjobtypeReportConfirmation) - if err != nil { - return fmt.Errorf("Failed to delay report subscription message: %w", err) - } - err := ensureInitialText(ctx, source, destination) - if err != nil { - return fmt.Errorf("Failed to ensure initial text has been sent: %w", err) - } - return nil - case enums.CommsPhonestatustypeOkToSend: - err = sendTextBegin(ctx, source, destination, content, enums.CommsTextoriginWebsiteAction, false, true) - if err != nil { - return fmt.Errorf("Failed to send report subscription confirmation: %w", err) - } - case enums.CommsPhonestatustypeStopped: - resendInitialText(ctx, source, destination) - } - return nil -} diff --git a/platform/text/report.go b/platform/text/report.go index 9aa046f5..5bc9dd95 100644 --- a/platform/text/report.go +++ b/platform/text/report.go @@ -2,9 +2,39 @@ package text import ( "context" - //"github.com/Gleipnir-Technology/nidus-sync/platform/types" + "fmt" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + //"github.com/rs/zerolog/log" ) -func ReportMessage(ctx context.Context, user_id int32, report_id, destination, message string) (*int32, error) { +// Send a message from a district to a public reporter within the context of the public report +func ReportMessage(ctx context.Context, txn bob.Executor, user_id int32, report_id int32, destination types.E164, content string) (*int32, error) { + job_id, err := sendTextBegin(ctx, txn, &user_id, &report_id, destination, content, enums.CommsTextjobtypeReportMessage) + if err != nil { + return nil, fmt.Errorf("Failed to send initial confirmation: %w", err) + } + return job_id, nil +} + +// Send a message from the system to a public reporter indicating they are subscribed to updates on the report +func ReportSubscriptionConfirmationText(ctx context.Context, txn bob.Executor, destination types.E164, report_id string) error { + content := fmt.Sprintf("Thanks for submitting mosquito report %s. Text for any questions. We'll send you updates as we get them.", report_id) + _, err := sendTextBegin(ctx, txn, nil, nil, destination, content, enums.CommsTextjobtypeReportConfirmation) + if err != nil { + return fmt.Errorf("Failed to send initial confirmation: %w", err) + } + return err +} +func reportForTextRecipient(ctx context.Context, txn bob.Executor, destination types.E164) (*models.PublicreportReport, error) { + /*return models.ReportText + psql.Query( + return Addresses.Query( + sm.Where(Addresses.Columns.ID.EQ(psql.Arg(IDPK))), + ).Exists(ctx, exec) + */ return nil, nil } diff --git a/platform/text/send.go b/platform/text/send.go new file mode 100644 index 00000000..03ade096 --- /dev/null +++ b/platform/text/send.go @@ -0,0 +1,191 @@ +package text + +import ( + "context" + "fmt" + "time" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/nidus-sync/comms/text" + "github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + //"github.com/Gleipnir-Technology/nidus-sync/db" + "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/platform/background" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" + "github.com/rs/zerolog/log" +) + +func ensureInitialText(ctx context.Context, txn bob.Executor, dst types.E164) error { + rows, err := models.CommsTextLogs.Query( + models.SelectWhere.CommsTextLogs.Destination.EQ(dst.PhoneString()), + models.SelectWhere.CommsTextLogs.IsWelcome.EQ(true), + ).All(ctx, txn) + if err != nil { + return fmt.Errorf("Failed to query text logs: %w", err) + } + if len(rows) > 0 { + return nil + } + return sendInitialText(ctx, txn, dst) +} +func insertTextLog(ctx context.Context, txn bob.Executor, destination types.E164, source types.E164, origin enums.CommsTextorigin, content string, is_welcome bool, is_visible_to_llm bool) (l *models.CommsTextLog, err error) { + l, err = models.CommsTextLogs.Insert(&models.CommsTextLogSetter{ + //ID: + Content: omit.From(content), + Created: omit.From(time.Now()), + Destination: omit.From(destination.PhoneString()), + IsVisibleToLLM: omit.From(is_visible_to_llm), + IsWelcome: omit.From(is_welcome), + Origin: omit.From(origin), + Source: omit.From(source.PhoneString()), + TwilioSid: omitnull.FromPtr[string](nil), + TwilioStatus: omit.From(""), + }).One(ctx, txn) + + return l, err +} +func resendInitialText(ctx context.Context, txn bob.Executor, dst types.E164) error { + phone, err := models.FindCommsPhone(ctx, txn, dst.PhoneString()) + if err != nil { + return fmt.Errorf("Failed to find phone %s: %w", dst, err) + } + err = phone.Update(ctx, txn, &models.CommsPhoneSetter{ + Status: omit.From(enums.CommsPhonestatustypeUnconfirmed), + }) + if err != nil { + return fmt.Errorf("Failed to clear subscription on phone %s: %w", dst, err) + } + return nil +} +func sendInitialText(ctx context.Context, txn bob.Executor, dst types.E164) error { + content := "Welcome to Report Mosquitoes Online. We received your request and want to confirm text updates. Reply YES to continue. Reply STOP at any time to unsubscribe" + _, err := sendTextDirect(ctx, txn, enums.CommsTextoriginWebsiteAction, dst.PhoneString(), content, false, true) + if err != nil { + return fmt.Errorf("send text: %w", err) + } + return nil +} + +// Begin the process of sending the text message, but only get as far as adding it to +// the database, then let the backend finish sending. +func sendTextBegin(ctx context.Context, txn bob.Executor, user_id *int32, report_id *int32, destination types.E164, content string, type_ enums.CommsTextjobtype) (*int32, error) { + err := EnsureInDB(ctx, txn, destination) + if err != nil { + return nil, fmt.Errorf("Failed to ensure text message destination is in the DB: %w", err) + } + job, err := models.CommsTextJobs.Insert(&models.CommsTextJobSetter{ + Content: omit.From(content), + CreatorID: omitnull.FromPtr(user_id), + Created: omit.From(time.Now()), + Destination: omit.From(destination.PhoneString()), + //ID: + ReportID: omitnull.FromPtr(report_id), + Source: omit.From(enums.CommsTextjobsourceRmo), + Type: omit.From(type_), + }).One(ctx, txn) + if err != nil { + return nil, fmt.Errorf("Failed to add delayed text job: %w", err) + } + err = background.NewTextSend(ctx, txn, job.ID) + if err != nil { + return nil, fmt.Errorf("new background job: %w", err) + } + return &job.ID, nil +} +func sendTextCommandResponse(ctx context.Context, txn bob.Executor, dst types.E164, content string) error { + _, err := sendTextDirect(ctx, txn, enums.CommsTextoriginCommandResponse, dst.PhoneString(), content, false, false) + return err +} +func sendTextComplete(ctx context.Context, txn bob.Executor, job *models.CommsTextJob) error { + dst, err := ParsePhoneNumber(job.Destination) + if err != nil { + return fmt.Errorf("parse phone: %w", err) + } + var origin enums.CommsTextorigin + switch job.Type { + case enums.CommsTextjobtypeReportConfirmation: + origin = enums.CommsTextoriginWebsiteAction + case enums.CommsTextjobtypeReportMessage: + origin = enums.CommsTextoriginDistrict + default: + return fmt.Errorf("incomplete switch: %s", string(job.Type)) + } + status, err := phoneStatus(ctx, *dst) + if err != nil { + return fmt.Errorf("Failed to check if subscribed: %w", err) + } + log.Debug().Str("phone status", string(status)).Str("destination", job.Destination).Send() + switch status { + case enums.CommsPhonestatustypeUnconfirmed: + err := ensureInitialText(ctx, txn, *dst) + if err != nil { + return fmt.Errorf("Failed to ensure initial text has been sent: %w", err) + } + return nil + case enums.CommsPhonestatustypeOkToSend: + _, err = sendTextDirect(ctx, txn, origin, dst.PhoneString(), job.Content, true, false) + if err != nil { + return fmt.Errorf("Failed to send report subscription confirmation: %w", err) + } + return nil + case enums.CommsPhonestatustypeStopped: + resendInitialText(ctx, txn, *dst) + } + text_log, err := sendTextDirect(ctx, txn, origin, job.Destination, job.Content, true, false) + if err != nil { + return fmt.Errorf("send text direct: %w", err) + } + err = job.Update(ctx, txn, &models.CommsTextJobSetter{ + Completed: omitnull.From(time.Now()), + }) + if err != nil { + return fmt.Errorf("update job: %w", err) + } + if job.ReportID.IsValue() { + _, err := models.ReportTexts.Insert(&models.ReportTextSetter{ + CreatorID: omit.From(job.CreatorID.MustGet()), + ReportID: omit.From(job.ReportID.MustGet()), + TextLogID: omit.From(text_log.ID), + }).One(ctx, txn) + if err != nil { + return fmt.Errorf("insert report_text: %w", err) + } + } + return nil +} + +// Send a text message and save the appropriate database records. +// Send immediately using the current goroutine +func sendTextDirect(ctx context.Context, txn bob.Executor, origin enums.CommsTextorigin, destination, content string, is_visible_to_llm, is_welcome bool) (*models.CommsTextLog, error) { + text_log, err := models.CommsTextLogs.Insert(&models.CommsTextLogSetter{ + //ID: + Content: omit.From(content), + Created: omit.From(time.Now()), + Destination: omit.From(destination), + IsVisibleToLLM: omit.From(is_visible_to_llm), + IsWelcome: omit.From(is_welcome), + Origin: omit.From(origin), + Source: omit.From(config.PhoneNumberReportStr), + TwilioSid: omitnull.FromPtr[string](nil), + TwilioStatus: omit.From(""), + }).One(ctx, txn) + if err != nil { + return nil, fmt.Errorf("insert text log: %w", err) + } + pid, err := text.SendText(ctx, config.VoipMSNumber, destination, content) + if err != nil { + return nil, fmt.Errorf("send text: %w", err) + } + err = text_log.Update(ctx, txn, &models.CommsTextLogSetter{ + TwilioSid: omitnull.From(pid), + TwilioStatus: omit.From("created"), + }) + if err != nil { + return nil, fmt.Errorf("update %w", err) + } + + return text_log, nil +} diff --git a/platform/text/text.go b/platform/text/text.go index d8396a7a..931925b7 100644 --- a/platform/text/text.go +++ b/platform/text/text.go @@ -7,17 +7,12 @@ import ( "time" "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/im" - "github.com/Gleipnir-Technology/bob/dialect/psql/um" - "github.com/Gleipnir-Technology/nidus-sync/comms/text" "github.com/Gleipnir-Technology/nidus-sync/config" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/Gleipnir-Technology/nidus-sync/db/sql" - "github.com/Gleipnir-Technology/nidus-sync/llm" "github.com/Gleipnir-Technology/nidus-sync/platform/background" + "github.com/Gleipnir-Technology/nidus-sync/platform/event" "github.com/Gleipnir-Technology/nidus-sync/platform/types" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" @@ -25,19 +20,7 @@ import ( "github.com/rs/zerolog/log" ) -func EnsureInDB(ctx context.Context, ex bob.Executor, destination types.E164) (err error) { - _, err = psql.Insert( - im.Into("comms.phone", "e164", "is_subscribed", "status"), - im.Values( - psql.Arg(destination.PhoneString()), - psql.Arg(false), - psql.Arg("unconfirmed"), - ), - im.OnConflict("e164").DoNothing(), - ).Exec(ctx, ex) - return err -} -func HandleTextMessage(ctx context.Context, source string, destination string, body string) error { +func HandleTextMessage(ctx context.Context, source string, destination string, content string) error { src, err := ParsePhoneNumber(source) if err != nil { return fmt.Errorf("parse source '%s': %w", source, err) @@ -46,29 +29,80 @@ func HandleTextMessage(ctx context.Context, source string, destination string, b if err != nil { return fmt.Errorf("parse destination '%s': %w", destination, err) } - _, err = insertTextLog(ctx, *dst, *src, enums.CommsTextoriginCustomer, body, false, true) + txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) if err != nil { - return fmt.Errorf("insert text log: %w", err) + return fmt.Errorf("start txn: %w", err) } + defer txn.Rollback(ctx) + status, err := phoneStatus(ctx, *src) if err != nil { return fmt.Errorf("Failed to get phone status") } - body_l := strings.TrimSpace(strings.ToLower(body)) - // We don't know if they're subscribed or not. + is_visible_to_llm := true + if status == enums.CommsPhonestatustypeUnconfirmed { + is_visible_to_llm = false + } + l, err := models.CommsTextLogs.Insert(&models.CommsTextLogSetter{ + //ID: + Content: omit.From(content), + Created: omit.From(time.Now()), + Destination: omit.From(dst.PhoneString()), + IsVisibleToLLM: omit.From(is_visible_to_llm), + IsWelcome: omit.From(false), + Origin: omit.From(enums.CommsTextoriginCustomer), + Source: omit.From(src.PhoneString()), + TwilioSid: omitnull.FromPtr[string](nil), + TwilioStatus: omit.From(""), + }).One(ctx, txn) + if err != nil { + return fmt.Errorf("insert text log: %w", err) + } + log.Debug().Int32("id", l.ID).Msg("insert comms text log") + err = background.NewTextRespond(ctx, txn, l.ID) + if err != nil { + return fmt.Errorf("text respond: %w", err) + } + txn.Commit(ctx) + return err +} + +func respondText(ctx context.Context, txn bob.Executor, log_id int32) error { + l, err := models.FindCommsTextLog(ctx, txn, log_id) + if err != nil { + return fmt.Errorf("find comms: %w", err) + } + src, err := ParsePhoneNumber(l.Source) + if err != nil { + return fmt.Errorf("parse source: %w", err) + } + + status, err := phoneStatus(ctx, *src) + if err != nil { + return fmt.Errorf("Failed to get phone status") + } + + body_l := strings.TrimSpace(strings.ToLower(l.Content)) + // If the user isn't confirmed for sending regular texts ensure they get a reprompt if status == enums.CommsPhonestatustypeUnconfirmed { switch body_l { case "yes": - setPhoneStatus(ctx, *src, enums.CommsPhonestatustypeOkToSend) - content := "Thanks, we've confirmed your phone number. You can text STOP at any time if you change your mind" - err := sendTextBegin(ctx, *dst, *src, content, enums.CommsTextoriginCommandResponse, false, false) + err = setPhoneStatus(ctx, txn, *src, enums.CommsPhonestatustypeOkToSend) if err != nil { - log.Error().Err(err).Msg("Failed to send confirmation response") + return fmt.Errorf("set phone status: %w", err) } - handleWaitingTextJobs(ctx, *src) + content := "Thanks, we've confirmed your phone number. You can text STOP at any time if you change your mind" + err = sendTextCommandResponse(ctx, txn, *src, content) + if err != nil { + return fmt.Errorf("send response: %w", err) + } + handleWaitingTextJobs(ctx, txn, *src) + // We don't handle 'stop' here because we allow them to say 'stop' at any time, regardless of + // phone status. + //case "stop": default: content := "I have to start with either 'YES' or 'STOP' first, Which do you want?" - err = sendTextBegin(ctx, *dst, *src, content, enums.CommsTextoriginReiteration, false, false) + err = sendTextCommandResponse(ctx, txn, *src, content) if err != nil { log.Error().Err(err).Msg("Failed to resend initial prompt.") } @@ -78,32 +112,48 @@ func HandleTextMessage(ctx context.Context, source string, destination string, b switch body_l { case "stop": content := "You have successfully been unsubscribed. You will not receive any more messages from this number. Reply START to resubscribe." - err = sendTextBegin(ctx, *dst, *src, content, enums.CommsTextoriginCommandResponse, false, false) + err = sendTextCommandResponse(ctx, txn, *src, content) if err != nil { log.Error().Err(err).Msg("Failed to send unsubscribe acknowledgement.") } - setPhoneStatus(ctx, *src, enums.CommsPhonestatustypeStopped) + setPhoneStatus(ctx, txn, *src, enums.CommsPhonestatustypeStopped) return nil case "reset conversation": - handleResetConversation(ctx, *src, *dst) + err = handleResetConversation(ctx, txn, *src) + if err != nil { + log.Error().Err(err).Msg("Failed to wipe memory") + content := "Failed to wipe memory" + sendTextCommandResponse(ctx, txn, *src, content) + return fmt.Errorf("reset conversation: %w", err) + } return nil - default: } - previous_messages, err := loadPreviousMessagesForLLM(ctx, *dst, *src) + // If we've got an open public report from this phone number then we'll let the district respond + report, err := reportForTextRecipient(ctx, txn, *src) + if err != nil { + return fmt.Errorf("has open report: %w", err) + } + if report != nil { + event.Updated(event.TypeRMOReport, report.OrganizationID, report.PublicID) + } + // Otherwise let the LLM handle the response + return respondTextLLM(ctx, txn, *src) +} + +func respondTextLLM(ctx context.Context, txn bob.Executor, src types.E164) error { + previous_messages, err := loadPreviousMessagesForLLM(ctx, src) if err != nil { return fmt.Errorf("Failed to get previous messages: %w", err) } log.Info().Int("len", len(previous_messages)).Msg("passing") - sublog := log.With().Str("dst", destination).Str("src", source).Logger() - next_message, err := generateNextMessage(ctx, previous_messages, *src) + next_message, err := generateNextMessage(ctx, previous_messages, src) if err != nil { return fmt.Errorf("Failed to generate next message: %w", err) } - err = sendTextBegin(ctx, *dst, *src, next_message.Content, enums.CommsTextoriginLLM, false, true) + _, err = sendTextDirect(ctx, txn, enums.CommsTextoriginLLM, src.PhoneString(), next_message.Content, true, false) if err != nil { return fmt.Errorf("Failed to send response text: %w", err) } - sublog.Info().Str("content", next_message.Content).Str("body", body).Str("reply", next_message.Content).Msg("Handled text message") return nil } @@ -157,249 +207,3 @@ func UpdateMessageStatus(twilio_sid string, status string) { return } } -func delayMessage(ctx context.Context, source enums.CommsTextjobsource, destination types.E164, content string, type_ enums.CommsTextjobtype) error { - job, err := models.CommsTextJobs.Insert(&models.CommsTextJobSetter{ - Content: omit.From(content), - Created: omit.From(time.Now()), - Destination: omit.From(destination.PhoneString()), - //ID: - Source: omit.From(source), - Type: omit.From(type_), - }).One(ctx, db.PGInstance.BobDB) - if err != nil { - return fmt.Errorf("Failed to add delayed text job: %w", err) - } - log.Info().Int32("id", job.ID).Msg("Created delayed text job") - return nil -} - -func resendInitialText(ctx context.Context, src, dst types.E164) error { - phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, dst.PhoneString()) - if err != nil { - return fmt.Errorf("Failed to find phone %s: %w", dst, err) - } - err = phone.Update(ctx, db.PGInstance.BobDB, &models.CommsPhoneSetter{ - Status: omit.From(enums.CommsPhonestatustypeUnconfirmed), - }) - if err != nil { - return fmt.Errorf("Failed to clear subscription on phone %s: %w", dst, err) - } - return nil -} - -func sendInitialText(ctx context.Context, src, dst types.E164) error { - content := "Welcome to Report Mosquitoes Online. We received your request and want to confirm text updates. Reply YES to continue. Reply STOP at any time to unsubscribe" - origin := enums.CommsTextoriginWebsiteAction - err := sendTextBegin(ctx, src, dst, content, origin, true, true) - if err != nil { - return fmt.Errorf("Failed to send initial confirmation: %w", err) - } - return nil -} - -func ensureInitialText(ctx context.Context, src, dst types.E164) error { - // - rows, err := models.CommsTextLogs.Query( - models.SelectWhere.CommsTextLogs.Destination.EQ(dst.PhoneString()), - models.SelectWhere.CommsTextLogs.IsWelcome.EQ(true), - ).All(ctx, db.PGInstance.BobDB) - if err != nil { - return fmt.Errorf("Failed to query text logs: %w", err) - } - if len(rows) > 0 { - return nil - } - return sendInitialText(ctx, src, dst) -} - -func generateNextMessage(ctx context.Context, history []llm.Message, customer_phone types.E164) (llm.Message, error) { - _handle_report_status := func() (string, error) { - return "Report: ABCD-1234-5678, District: Delta MVCD, Status: scheduled, Appointment: Wednesday 3:30pm", nil - } - _handle_contact_district := func(reason string) { - log.Warn().Str("reason", reason).Msg("Contacting district") - } - _handle_contact_supervisor := func(reason string) { - log.Warn().Str("reason", reason).Msg("Contacting supervisor") - } - return llm.GenerateNextMessage(ctx, history, _handle_report_status, _handle_contact_district, _handle_contact_supervisor) -} - -func handleWaitingTextJobs(ctx context.Context, src types.E164) { - jobs, err := models.CommsTextJobs.Query( - models.SelectWhere.CommsTextJobs.Destination.EQ(src.PhoneString()), - models.SelectWhere.CommsTextJobs.Completed.IsNull(), - ).All(ctx, db.PGInstance.BobDB) - if err != nil { - log.Error().Err(err).Msg("Failed to query for jobs") - return - } - for _, job := range jobs { - var source string - switch job.Source { - case enums.CommsTextjobsourceRmo: - source = config.PhoneNumberReportStr - //case enums.CommsTextJobsourcenidus: - //src := config.PhoneNumebrNidusStr - default: - log.Error().Str("source", job.Source.String()).Msg("Can't support background text job.") - continue - } - p, err := phonenumbers.Parse(job.Destination, "US") - if err != nil { - log.Error().Err(err).Str("dest", job.Destination).Int32("id", job.ID).Msg("Invalid destination in job") - continue - } - dst := types.NewE164(p) - p, err = phonenumbers.Parse(source, "US") - if err != nil { - log.Error().Err(err).Str("source", source).Int32("id", job.ID).Msg("Invalid source in job") - continue - } - src := types.NewE164(p) - err = sendTextBegin(ctx, *src, *dst, job.Content, enums.CommsTextoriginWebsiteAction, false, true) - if err != nil { - log.Error().Err(err).Int32("id", job.ID).Msg("Failed to send delayed text job.") - continue - } - err = job.Update(ctx, db.PGInstance.BobDB, &models.CommsTextJobSetter{ - Completed: omitnull.From(time.Now()), - }) - if err != nil { - log.Error().Err(err).Int32("id", job.ID).Msg("Failed to update delayed text job.") - continue - } - } -} - -func handleResetConversation(ctx context.Context, src types.E164, dst types.E164) { - err := wipeLLMMemory(ctx, src, dst) - sublog := log.With().Str("src", src.PhoneString()).Str("dst", dst.PhoneString()).Logger() - if err != nil { - sublog.Error().Err(err).Msg("Failed to wipe memory") - content := "Failed to wip memory" - err = sendTextBegin(ctx, dst, src, content, enums.CommsTextoriginCommandResponse, false, false) - if err != nil { - sublog.Error().Err(err).Msg("Failed to indicated memory wipe failure.") - } - return - } - content := "LLM memory wiped" - err = sendTextBegin(ctx, dst, src, content, enums.CommsTextoriginCommandResponse, false, false) - if err != nil { - sublog.Error().Err(err).Msg("Failed to indicated memory wiped.") - return - } - sublog.Info().Err(err).Msg("Wiped LLM memory") -} - -func insertTextLog(ctx context.Context, destination types.E164, source types.E164, origin enums.CommsTextorigin, content string, is_welcome bool, is_visible_to_llm bool) (l *models.CommsTextLog, err error) { - l, err = models.CommsTextLogs.Insert(&models.CommsTextLogSetter{ - //ID: - Content: omit.From(content), - Created: omit.From(time.Now()), - Destination: omit.From(destination.PhoneString()), - IsVisibleToLLM: omit.From(is_visible_to_llm), - IsWelcome: omit.From(is_welcome), - Origin: omit.From(origin), - Source: omit.From(source.PhoneString()), - TwilioSid: omitnull.FromPtr[string](nil), - TwilioStatus: omit.From(""), - }).One(ctx, db.PGInstance.BobDB) - if err != nil { - log.Debug().Int32("id", l.ID).Bool("is_visible_to_llm", is_visible_to_llm).Str("message", content).Msg("inserted text log") - } - - return l, err -} - -func phoneStatus(ctx context.Context, src types.E164) (enums.CommsPhonestatustype, error) { - phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, src.PhoneString()) - if err != nil { - return enums.CommsPhonestatustypeUnconfirmed, fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src.PhoneString(), err) - } - return phone.Status, nil -} - -func loadPreviousMessagesForLLM(ctx context.Context, dst, src types.E164) ([]llm.Message, error) { - messages, err := sql.TextsBySenders(dst.PhoneString(), src.PhoneString()).All(ctx, db.PGInstance.BobDB) - results := make([]llm.Message, 0) - if err != nil { - return results, fmt.Errorf("Failed to get message history for %s and %s: %w", dst, src, err) - } - for _, m := range messages { - if m.IsVisibleToLLM { - is_from_customer := (m.Source == src.PhoneString()) - results = append(results, llm.Message{ - IsFromCustomer: is_from_customer, - Content: m.Content, - }) - } - } - return results, nil -} - -func sendTextBegin(ctx context.Context, source types.E164, destination types.E164, message string, origin enums.CommsTextorigin, is_welcome bool, is_visible_to_llm bool) error { - err := EnsureInDB(ctx, db.PGInstance.BobDB, destination) - if err != nil { - return fmt.Errorf("Failed to ensure text message destination is in the DB: %w", err) - } - l, err := insertTextLog(ctx, destination, source, origin, message, is_welcome, is_visible_to_llm) - if err != nil { - return fmt.Errorf("Failed to insert text message in the DB: %w", err) - } - return background.NewTextSend(ctx, db.PGInstance.BobDB, l.ID) -} -func sendTextComplete(ctx context.Context, txn bob.Executor, text_id int32) error { - text_log, err := models.FindCommsTextLog(ctx, txn, text_id) - if err != nil { - return fmt.Errorf("find text: %w", err) - } - sid, err := text.SendText(ctx, text_log.Source, text_log.Destination, text_log.Content) - if err != nil { - return fmt.Errorf("Failed to send text message: %w", err) - } - err = text_log.Update(ctx, db.PGInstance.BobDB, &models.CommsTextLogSetter{ - TwilioSid: omitnull.From(sid), - TwilioStatus: omit.From("created"), - }) - if err != nil { - return fmt.Errorf("Failed to update text Twilio status: %w", err) - } - - return nil -} - -func setPhoneStatus(ctx context.Context, src types.E164, status enums.CommsPhonestatustype) error { - phone, err := models.FindCommsPhone(ctx, db.PGInstance.BobDB, src.PhoneString()) - if err != nil { - return fmt.Errorf("Failed to determine if '%s' is subscribed: %w", src, err) - } - phone.Update(ctx, db.PGInstance.BobDB, &models.CommsPhoneSetter{ - Status: omit.From(status), - }) - log.Info().Str("src", src.PhoneString()).Str("status", string(status)).Msg("Set number subscribed") - return nil -} - -func wipeLLMMemory(ctx context.Context, src types.E164, dst types.E164) error { - rows, err := sql.TextsBySenders(dst.PhoneString(), src.PhoneString()).All(ctx, db.PGInstance.BobDB) - if err != nil { - return fmt.Errorf("Failed to query for texts: %w", err) - } - ids := make([]int32, 0) - for _, r := range rows { - ids = append(ids, r.ID) - } - _, err = models.CommsTextLogs.Update( - um.Where( - models.CommsTextLogs.Columns.ID.EQ(psql.Any(ids)), - ), - um.SetCol("is_visible_to_llm").ToArg(false), - ).Exec(ctx, db.PGInstance.BobDB) - if err != nil { - return fmt.Errorf("Failed to update texts: %w", err) - } - - return nil -} diff --git a/platform/water.go b/platform/water.go index f55221b0..0d3b65ce 100644 --- a/platform/water.go +++ b/platform/water.go @@ -1,104 +1 @@ package platform - -import ( - "context" - "fmt" - - "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/um" - "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/Gleipnir-Technology/nidus-sync/platform/event" - "github.com/Gleipnir-Technology/nidus-sync/platform/geocode" - "github.com/Gleipnir-Technology/nidus-sync/platform/report" - "github.com/Gleipnir-Technology/nidus-sync/platform/types" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - "github.com/rs/zerolog/log" -) - -func WaterCreate(ctx context.Context, setter models.PublicreportWaterSetter, latlng LatLng, address Address, images []ImageUpload) (public_id string, err error) { - txn, err := db.PGInstance.BobDB.BeginTx(ctx, nil) - if err != nil { - return "", fmt.Errorf("Failed to create transaction: %w", err) - } - defer txn.Rollback(ctx) - public_id, err = report.GenerateReportID() - if err != nil { - return "", fmt.Errorf("Failed to create water report public ID", err) - } - setter.PublicID = omit.From(public_id) - - // If we've got an locality value it was set by geocoding so we should save it - var a *models.Address - if address.Locality != "" && latlng.Latitude != nil && latlng.Longitude != nil { - a, err = geocode.EnsureAddress(ctx, txn, address, types.Location{ - Latitude: *latlng.Latitude, - Longitude: *latlng.Longitude, - }) - if err != nil { - return "", fmt.Errorf("Failed to ensure address: %w", err) - } - } - - saved_images, err := saveImageUploads(ctx, txn, images) - if err != nil { - return "", fmt.Errorf("Failed to save image uploads", err) - } - - var organization_id *int32 - organization_id, err = MatchDistrict(ctx, latlng.Longitude, latlng.Latitude, images) - if err != nil { - log.Warn().Err(err).Msg("Failed to match district") - } - if a != nil { - setter.AddressID = omitnull.From(a.ID) - } - if organization_id != nil { - setter.OrganizationID = omit.FromPtr(organization_id) - } - - water, err := models.PublicreportWaters.Insert(&setter).One(ctx, txn) - if err != nil { - return "", fmt.Errorf("Failed to create database record", err) - } - - if latlng.Latitude != nil && latlng.Longitude != nil { - h3cell, _ := latlng.H3Cell() - geom_query, _ := latlng.GeometryQuery() - _, err = psql.Update( - um.Table("publicreport.water"), - um.SetCol("h3cell").ToArg(h3cell), - um.SetCol("location").To(geom_query), - um.Where(psql.Quote("id").EQ(psql.Arg(water.ID))), - ).Exec(ctx, txn) - if err != nil { - return "", fmt.Errorf("Failed to update publicreport.water geospatial", err) - } - } - log.Info().Int32("id", water.ID).Str("public_id", water.PublicID).Msg("Created water report") - setters := make([]*models.PublicreportWaterImageSetter, 0) - for _, image := range saved_images { - setters = append(setters, &models.PublicreportWaterImageSetter{ - ImageID: omit.From(int32(image.ID)), - WaterID: omit.From(int32(water.ID)), - }) - } - if len(setters) > 0 { - _, err = models.PublicreportWaterImages.Insert(bob.ToMods(setters...)).Exec(ctx, txn) - if err != nil { - return "", fmt.Errorf("Failed to save upload relationships", err) - } - } - txn.Commit(ctx) - - if organization_id != nil { - event.Created( - event.TypeRMOWater, - *organization_id, - water.PublicID, - ) - } - return water.PublicID, nil -} diff --git a/rmo/nuisance.go b/rmo/nuisance.go index ddd6b4fd..603da8c7 100644 --- a/rmo/nuisance.go +++ b/rmo/nuisance.go @@ -142,8 +142,7 @@ func postNuisance(w http.ResponseWriter, r *http.Request) { Street: address_street, Unit: "", } - setter := models.PublicreportNuisanceSetter{ - AdditionalInfo: omit.From(additional_info), + setter_report := models.PublicreportReportSetter{ //AddressID: omitnull.From(latlng.Cell.String()), AddressRaw: omit.From(address.Raw), AddressCountry: omit.From(address.Country), @@ -153,13 +152,7 @@ func postNuisance(w http.ResponseWriter, r *http.Request) { AddressRegion: omit.From(address.Region), AddressStreet: omit.From(address.Street), Created: omit.From(time.Now()), - Duration: omit.From(duration), //H3cell: omitnull.From(latlng.Cell.String()), - IsLocationBackyard: omit.From(is_location_backyard), - IsLocationFrontyard: omit.From(is_location_frontyard), - IsLocationGarden: omit.From(is_location_garden), - IsLocationOther: omit.From(is_location_other), - IsLocationPool: omit.From(is_location_pool), LatlngAccuracyType: omit.From(latlng.AccuracyType), LatlngAccuracyValue: omit.From(float32(latlng.AccuracyValue)), //Location: omitnull.From(fmt.Sprintf("ST_GeometryFromText(Point(%s %s))", longitude, latitude)), @@ -167,19 +160,29 @@ func postNuisance(w http.ResponseWriter, r *http.Request) { MapZoom: omit.From(latlng.MapZoom), //OrganizationID: omitnull.FromPtr(organization_id), //PublicID: omit.From(public_id), - ReporterEmail: omitnull.FromPtr[string](nil), - ReporterName: omitnull.FromPtr[string](nil), - ReporterPhone: omitnull.FromPtr[string](nil), + ReporterEmail: omit.From(""), + ReporterName: omit.From(""), + ReporterPhone: omit.From(""), + Status: omit.From(enums.PublicreportReportstatustypeReported), + } + setter_nuisance := models.PublicreportNuisanceSetter{ + AdditionalInfo: omit.From(additional_info), + Duration: omit.From(duration), + IsLocationBackyard: omit.From(is_location_backyard), + IsLocationFrontyard: omit.From(is_location_frontyard), + IsLocationGarden: omit.From(is_location_garden), + IsLocationOther: omit.From(is_location_other), + IsLocationPool: omit.From(is_location_pool), + //ReportID omit.Val[int32] SourceContainer: omit.From(source_container), SourceDescription: omit.From(source_description), SourceGutter: omit.From(source_gutters), SourceStagnant: omit.From(source_stagnant), - Status: omit.From(enums.PublicreportReportstatustypeReported), - TodEarly: omit.From(tod_early), TodDay: omit.From(tod_day), + TodEarly: omit.From(tod_early), TodEvening: omit.From(tod_evening), TodNight: omit.From(tod_night), } - public_id, err := platform.NuisanceCreate(ctx, setter, latlng, address, uploads) + public_id, err := platform.ReportNuisanceCreate(ctx, setter_report, setter_nuisance, latlng, address, uploads) http.Redirect(w, r, fmt.Sprintf("/submit-complete?report=%s", public_id), http.StatusFound) } diff --git a/rmo/report.go b/rmo/report.go index 1dc7c474..670be3f2 100644 --- a/rmo/report.go +++ b/rmo/report.go @@ -8,17 +8,20 @@ import ( "strings" //"github.com/Gleipnir-Technology/nidus-sync/config" + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/sm" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/enums" - "github.com/Gleipnir-Technology/nidus-sync/db/sql" "github.com/Gleipnir-Technology/nidus-sync/platform" + "github.com/stephenafamo/scan" //"github.com/go-chi/chi/v5" //"github.com/rs/zerolog/log" ) type ReportSuggestion struct { - ID string `json:"id"` - Type string `json:"type"` + ID string `json:"id"` + //Type string `json:"type"` //Location string } type ReportSuggestionResponse struct { @@ -33,11 +36,25 @@ func getReportSuggestion(w http.ResponseWriter, r *http.Request) { } p := partialSearchParam(partial_report_id) ctx := r.Context() - rows, err := sql.PublicreportPublicIDSuggestion(p).All(ctx, db.PGInstance.BobDB) - if err != nil { - respondError(w, "Failed to query DB: %w", err, http.StatusInternalServerError) - return + /* + rows, err := sql.PublicreportPublicIDSuggestion(p).All(ctx, db.PGInstance.BobDB) + if err != nil { + respondError(w, "Failed to query DB: %w", err, http.StatusInternalServerError) + return + } + */ + type _Row struct { + Location string `db:"location"` + PublicID string `db:"public_id"` } + rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( + sm.Columns("public_id", "location"), + sm.From("publicreport.report"), + sm.Where( + psql.Quote("public_id").Like(psql.Arg(p)), + ), + ), scan.StructMapper[_Row]()) + var result ReportSuggestionResponse for _, row := range rows { /* @@ -54,8 +71,8 @@ func getReportSuggestion(w http.ResponseWriter, r *http.Request) { log.Debug().Str("location", value_str).Msg("Looking at row") */ result.Reports = append(result.Reports, ReportSuggestion{ - Type: row.TableName, - ID: row.PublicID, + //Type: row.TableName, + ID: row.PublicID, //Location: "", }) } diff --git a/rmo/status.go b/rmo/status.go index 2eed8835..629964f7 100644 --- a/rmo/status.go +++ b/rmo/status.go @@ -13,17 +13,14 @@ import ( "github.com/Gleipnir-Technology/bob/dialect/psql/sm" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/Gleipnir-Technology/nidus-sync/db/sql" "github.com/Gleipnir-Technology/nidus-sync/html" "github.com/go-chi/chi/v5" + "github.com/google/uuid" //"github.com/rs/zerolog/log" "github.com/stephenafamo/scan" - /* - "github.com/Gleipnir-Technology/nidus-sync/db" - "github.com/Gleipnir-Technology/nidus-sync/h3utils" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - */) + "golang.org/x/text/cases" + "golang.org/x/text/language" +) type ContentStatus struct { District *ContentDistrict @@ -95,30 +92,94 @@ func getStatus(w http.ResponseWriter, r *http.Request) { content.Error = "Sorry, we can't find that report" html.RenderOrError(w, "rmo/status.html", content) } -func contentFromNuisance(ctx context.Context, report_id string) (result ContentStatusByID, err error) { - nuisance, err := models.PublicreportNuisances.Query( - models.SelectWhere.PublicreportNuisances.PublicID.EQ(report_id), - ).One(ctx, db.PGInstance.BobDB) +func contentFromReport(ctx context.Context, report *models.PublicreportReport) (result ContentStatusByID, err error) { + org, err := models.FindOrganization(ctx, db.PGInstance.BobDB, report.OrganizationID) if err != nil { - return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err) + return result, fmt.Errorf("Failed to get district information: %w", err) } - images, err := sql.PublicreportImageWithJSONByNuisanceID(nuisance.ID).All(ctx, db.PGInstance.BobDB) - if err != nil { - return result, fmt.Errorf("Failed to get images %s: %w", report_id, err) + type _Row struct { + ID int32 `db:"id"` + ContentType string `db:"content_type"` + Created time.Time `db:"created"` + Location 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 int32 `db:"storage_size"` + UploadedFilename string `db:"uploaded_filename"` } - - org_id := nuisance.OrganizationID - org, err := models.FindOrganization(ctx, db.PGInstance.BobDB, org_id) + images, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( + sm.Columns( + "id", + "content_type", + "created", + "location", + "COALESCE(ST_AsGeoJSON(location), '{}') AS location_json", + "resolution_x", + "resolution_y", + "storage_uuid", + "storage_size", + "uploaded_filename", + ), + sm.From("publicreport.image"), + sm.InnerJoin("publicreport.report_image").OnEQ( + psql.Quote("publicreport", "image", "id"), + psql.Quote("publicreport", "report_image", "image_id"), + ), + sm.Where( + psql.Quote("publicreport", "report_image", "report_id").EQ(psql.Arg(report.ID)), + ), + ), scan.StructMapper[_Row]()) if err != nil { - return result, fmt.Errorf("Failed to get district %d information: %w", org_id, err) + return result, fmt.Errorf("Failed to get images: %w", err) } result.District = newContentDistrict(org) - result.Report.ID = report_id - result.Report.Address = nuisance.AddressRaw - result.Report.Created = nuisance.Created + result.Report.ID = report.PublicID + result.Report.Address = report.AddressRaw + result.Report.Created = report.Created result.Report.ImageCount = len(images) - result.Report.Status = strings.Title(nuisance.Status.String()) + result.Report.Status = cases.Title(language.AmericanEnglish).String(report.Status.String()) + result.Timeline = []TimelineEntry{ + TimelineEntry{ + At: report.Created, + Detail: "Initial report was submitted", + Title: "Created", + }, + } + + type LocationGeoJSON struct { + Location string + } + location, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( + sm.Columns( + psql.F("ST_AsGeoJSON", "location"), + ), + sm.From("publicreport.report"), + sm.Where(psql.Quote("id").EQ(psql.Arg(report.ID))), + ), scan.SingleColumnMapper[string]) + if err != nil { + return result, fmt.Errorf("Failed to query location of report %d: %w", report.ID, err) + } + result.Report.Location = location + nuisance, err := models.PublicreportNuisances.Query( + models.SelectWhere.PublicreportNuisances.ReportID.EQ(report.ID), + ).One(ctx, db.PGInstance.BobDB) + if err == nil { + result.Report.Type = "Mosquito Nuisance" + addContentFromNuisance(&result, nuisance) + } + water, err := models.PublicreportWaters.Query( + models.SelectWhere.PublicreportWaters.ReportID.EQ(report.ID), + ).One(ctx, db.PGInstance.BobDB) + if err == nil { + result.Report.Type = "Standing Water" + addContentFromWater(&result, water) + } + return result, nil +} +func addContentFromNuisance(result *ContentStatusByID, nuisance *models.PublicreportNuisance) { result.Report.Type = "Mosquito Nuisance" result.Report.Details = []DetailEntry{ DetailEntry{ @@ -174,56 +235,8 @@ func contentFromNuisance(ctx context.Context, report_id string) (result ContentS Value: strconv.FormatBool(nuisance.SourceGutter), }, } - result.Timeline = []TimelineEntry{ - TimelineEntry{ - At: nuisance.Created, - Detail: "Initial report was submitted", - Title: "Created", - }, - } - - type LocationGeoJSON struct { - Location string - } - location, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.Columns( - psql.F("ST_AsGeoJSON", "location"), - ), - sm.From("publicreport.nuisance"), - sm.Where(psql.Quote("public_id").EQ(psql.Arg(report_id))), - ), scan.SingleColumnMapper[string]) - if err != nil { - return result, fmt.Errorf("Failed to query nuisance %s: %w", report_id, err) - } - result.Report.Location = location - - return result, err } -func contentFromWater(ctx context.Context, report_id string) (result ContentStatusByID, err error) { - water, err := models.PublicreportWaters.Query( - models.SelectWhere.PublicreportWaters.PublicID.EQ(report_id), - ).One(ctx, db.PGInstance.BobDB) - if err != nil { - return result, fmt.Errorf("Failed to query water %s: %w", report_id, err) - } - - images, err := sql.PublicreportImageWithJSONByWaterID(water.ID).All(ctx, db.PGInstance.BobDB) - if err != nil { - return result, fmt.Errorf("Failed to get images %s: %w", report_id, err) - } - - org_id := water.OrganizationID - org, err := models.FindOrganization(ctx, db.PGInstance.BobDB, org_id) - if err != nil { - return result, fmt.Errorf("Failed to get district %d information: %w", org_id, err) - } - result.District = newContentDistrict(org) - result.Report.ID = report_id - result.Report.Address = water.AddressRaw - result.Report.Created = water.Created - result.Report.ImageCount = len(images) - result.Report.Status = strings.Title(water.Status.String()) - result.Report.Type = "Mosquito Nuisance" +func addContentFromWater(result *ContentStatusByID, water *models.PublicreportWater) { result.Report.Details = []DetailEntry{ DetailEntry{ Name: "Has a gate that affects access?", @@ -254,48 +267,20 @@ func contentFromWater(ctx context.Context, report_id string) (result ContentStat Value: strconv.FormatBool(water.HasAdult), }, } - result.Timeline = []TimelineEntry{ - TimelineEntry{ - At: water.Created, - Detail: "Initial report was submitted", - Title: "Created", - }, - } - location, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select( - sm.Columns( - psql.F("ST_AsGeoJSON", "location"), - ), - sm.From("publicreport.water"), - sm.Where(psql.Quote("public_id").EQ(psql.Arg(report_id))), - ), scan.SingleColumnMapper[string]) - if err != nil { - return result, fmt.Errorf("Failed to query water %s: %w", report_id, err) - } - result.Report.Location = location - - return result, err } func getStatusByID(w http.ResponseWriter, r *http.Request) { report_id := chi.URLParam(r, "report_id") ctx := r.Context() - location, err := models.PublicreportReportLocations.Query( - models.SelectWhere.PublicreportReportLocations.PublicID.EQ(report_id), + report, err := models.PublicreportReports.Query( + models.SelectWhere.PublicreportReports.PublicID.EQ(report_id), ).One(ctx, db.PGInstance.BobDB) if err != nil { respondError(w, "Failed to find report", err, http.StatusBadRequest) return } - var content ContentStatusByID - switch location.TableName.MustGet() { - case "nuisance": - content, err = contentFromNuisance(ctx, report_id) - case "water": - content, err = contentFromWater(ctx, report_id) - default: - err = fmt.Errorf("table name %s not in switch", location.TableName.MustGet()) - } + content, err := contentFromReport(ctx, report) if err != nil { respondError(w, "Failed to generate report content", err, http.StatusInternalServerError) return diff --git a/rmo/water.go b/rmo/water.go index fd2b6ae5..7ce156ab 100644 --- a/rmo/water.go +++ b/rmo/water.go @@ -97,13 +97,7 @@ func postWater(w http.ResponseWriter, r *http.Request) { Street: address_street, Unit: "", } - setter := models.PublicreportWaterSetter{ - AccessComments: omit.From(access_comments), - AccessDog: omit.From(access_dog), - AccessFence: omit.From(access_fence), - AccessGate: omit.From(access_gate), - AccessLocked: omit.From(access_locked), - AccessOther: omit.From(access_other), + setter_report := models.PublicreportReportSetter{ AddressRaw: omit.From(address_raw), AddressCountry: omit.From(address_country), AddressLocality: omit.From(address_locality), @@ -111,28 +105,37 @@ func postWater(w http.ResponseWriter, r *http.Request) { AddressPostalCode: omit.From(address_postal_code), AddressStreet: omit.From(address_street), AddressRegion: omit.From(address_region), - Comments: omit.From(comments), Created: omit.From(time.Now()), //H3cell: omitnull.From(geospatial.Cell.String()), - HasAdult: omit.From(has_adult), - HasBackyardPermission: omit.From(has_backyard_permission), - HasLarvae: omit.From(has_larvae), - HasPupae: omit.From(has_pupae), - IsReporterConfidential: omit.From(is_reporter_confidential), - IsReporterOwner: omit.From(is_reporter_owner), //Location: add later MapZoom: omit.From(latlng.MapZoom), //OrganizationID: omitnull.FromPtr(organization_id), - OwnerEmail: omit.From(owner_email), - OwnerName: omit.From(owner_name), - OwnerPhone: omit.From(owner_phone), //PublicID: omit.From(public_id), ReporterEmail: omit.From(""), ReporterName: omit.From(""), ReporterPhone: omit.From(""), Status: omit.From(enums.PublicreportReportstatustypeReported), } - public_id, err := platform.WaterCreate(ctx, setter, latlng, address, uploads) + setter_water := models.PublicreportWaterSetter{ + AccessComments: omit.From(access_comments), + AccessDog: omit.From(access_dog), + AccessFence: omit.From(access_fence), + AccessGate: omit.From(access_gate), + AccessLocked: omit.From(access_locked), + AccessOther: omit.From(access_other), + Comments: omit.From(comments), + HasAdult: omit.From(has_adult), + HasBackyardPermission: omit.From(has_backyard_permission), + HasLarvae: omit.From(has_larvae), + HasPupae: omit.From(has_pupae), + IsReporterConfidential: omit.From(is_reporter_confidential), + IsReporterOwner: omit.From(is_reporter_owner), + OwnerEmail: omit.From(owner_email), + OwnerName: omit.From(owner_name), + OwnerPhone: omit.From(owner_phone), + //ReportID omit.Val[int32] + } + public_id, err := platform.ReportWaterCreate(ctx, setter_report, setter_water, latlng, address, uploads) if err != nil { respondError(w, "Failed to save new report", err, http.StatusInternalServerError) return