diff --git a/config/config.go b/config/config.go index 31e4c7a3..fef6cd40 100644 --- a/config/config.go +++ b/config/config.go @@ -26,7 +26,6 @@ var ( ForwardEmailNidusAddress string ForwardEmailNidusPassword string ForwardEmailNidusUsername string - MapboxToken string PGDSN string PhoneNumberReport phonenumbers.PhoneNumber PhoneNumberReportStr string @@ -136,10 +135,6 @@ func Parse() (err error) { if ForwardEmailNidusPassword == "" { return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_NIDUS_PASSWORD") } - MapboxToken = os.Getenv("MAPBOX_TOKEN") - if MapboxToken == "" { - return fmt.Errorf("You must specify a non-empty MAPBOX_TOKEN") - } PGDSN = os.Getenv("POSTGRES_DSN") if PGDSN == "" { return fmt.Errorf("You must specify a non-empty POSTGRES_DSN") diff --git a/db/dberrors/publicreport.notify_email_pool.bob.go b/db/dberrors/publicreport.notify_email_water.bob.go similarity index 61% rename from db/dberrors/publicreport.notify_email_pool.bob.go rename to db/dberrors/publicreport.notify_email_water.bob.go index c721505e..834b821c 100644 --- a/db/dberrors/publicreport.notify_email_pool.bob.go +++ b/db/dberrors/publicreport.notify_email_water.bob.go @@ -3,15 +3,15 @@ package dberrors -var PublicreportNotifyEmailPoolErrors = &publicreportNotifyEmailPoolErrors{ +var PublicreportNotifyEmailWaterErrors = &publicreportNotifyEmailWaterErrors{ ErrUniqueNotifyEmailPoolPkey: &UniqueConstraintError{ schema: "publicreport", - table: "notify_email_pool", - columns: []string{"pool_id", "email_address"}, + table: "notify_email_water", + columns: []string{"water_id", "email_address"}, s: "notify_email_pool_pkey", }, } -type publicreportNotifyEmailPoolErrors struct { +type publicreportNotifyEmailWaterErrors struct { ErrUniqueNotifyEmailPoolPkey *UniqueConstraintError } diff --git a/db/dberrors/publicreport.notify_phone_pool.bob.go b/db/dberrors/publicreport.notify_phone_water.bob.go similarity index 61% rename from db/dberrors/publicreport.notify_phone_pool.bob.go rename to db/dberrors/publicreport.notify_phone_water.bob.go index 3b0a0287..7bc9c4d3 100644 --- a/db/dberrors/publicreport.notify_phone_pool.bob.go +++ b/db/dberrors/publicreport.notify_phone_water.bob.go @@ -3,15 +3,15 @@ package dberrors -var PublicreportNotifyPhonePoolErrors = &publicreportNotifyPhonePoolErrors{ +var PublicreportNotifyPhoneWaterErrors = &publicreportNotifyPhoneWaterErrors{ ErrUniqueNotifyPhonePoolPkey: &UniqueConstraintError{ schema: "publicreport", - table: "notify_phone_pool", - columns: []string{"pool_id", "phone_e164"}, + table: "notify_phone_water", + columns: []string{"water_id", "phone_e164"}, s: "notify_phone_pool_pkey", }, } -type publicreportNotifyPhonePoolErrors struct { +type publicreportNotifyPhoneWaterErrors struct { ErrUniqueNotifyPhonePoolPkey *UniqueConstraintError } diff --git a/db/dberrors/publicreport.pool.bob.go b/db/dberrors/publicreport.water.bob.go similarity index 79% rename from db/dberrors/publicreport.pool.bob.go rename to db/dberrors/publicreport.water.bob.go index c774c014..69a7e2e8 100644 --- a/db/dberrors/publicreport.pool.bob.go +++ b/db/dberrors/publicreport.water.bob.go @@ -3,23 +3,23 @@ package dberrors -var PublicreportPoolErrors = &publicreportPoolErrors{ +var PublicreportWaterErrors = &publicreportWaterErrors{ ErrUniquePoolPkey: &UniqueConstraintError{ schema: "publicreport", - table: "pool", + table: "water", columns: []string{"id"}, s: "pool_pkey", }, ErrUniquePoolPublicIdKey: &UniqueConstraintError{ schema: "publicreport", - table: "pool", + table: "water", columns: []string{"public_id"}, s: "pool_public_id_key", }, } -type publicreportPoolErrors struct { +type publicreportWaterErrors struct { ErrUniquePoolPkey *UniqueConstraintError ErrUniquePoolPublicIdKey *UniqueConstraintError diff --git a/db/dberrors/publicreport.pool_image.bob.go b/db/dberrors/publicreport.water_image.bob.go similarity index 63% rename from db/dberrors/publicreport.pool_image.bob.go rename to db/dberrors/publicreport.water_image.bob.go index 8f5c66e2..a374601e 100644 --- a/db/dberrors/publicreport.pool_image.bob.go +++ b/db/dberrors/publicreport.water_image.bob.go @@ -3,15 +3,15 @@ package dberrors -var PublicreportPoolImageErrors = &publicreportPoolImageErrors{ +var PublicreportWaterImageErrors = &publicreportWaterImageErrors{ ErrUniquePoolImagePkey: &UniqueConstraintError{ schema: "publicreport", - table: "pool_image", - columns: []string{"image_id", "pool_id"}, + table: "water_image", + columns: []string{"image_id", "water_id"}, s: "pool_image_pkey", }, } -type publicreportPoolImageErrors struct { +type publicreportWaterImageErrors struct { ErrUniquePoolImagePkey *UniqueConstraintError } diff --git a/db/dbinfo/publicreport.notify_email_pool.bob.go b/db/dbinfo/publicreport.notify_email_water.bob.go similarity index 52% rename from db/dbinfo/publicreport.notify_email_pool.bob.go rename to db/dbinfo/publicreport.notify_email_water.bob.go index cc31323b..6e2e4690 100644 --- a/db/dbinfo/publicreport.notify_email_pool.bob.go +++ b/db/dbinfo/publicreport.notify_email_water.bob.go @@ -5,16 +5,16 @@ package dbinfo import "github.com/aarondl/opt/null" -var PublicreportNotifyEmailPools = Table[ - publicreportNotifyEmailPoolColumns, - publicreportNotifyEmailPoolIndexes, - publicreportNotifyEmailPoolForeignKeys, - publicreportNotifyEmailPoolUniques, - publicreportNotifyEmailPoolChecks, +var PublicreportNotifyEmailWaters = Table[ + publicreportNotifyEmailWaterColumns, + publicreportNotifyEmailWaterIndexes, + publicreportNotifyEmailWaterForeignKeys, + publicreportNotifyEmailWaterUniques, + publicreportNotifyEmailWaterChecks, ]{ Schema: "publicreport", - Name: "notify_email_pool", - Columns: publicreportNotifyEmailPoolColumns{ + Name: "notify_email_water", + Columns: publicreportNotifyEmailWaterColumns{ Created: column{ Name: "created", DBType: "timestamp without time zone", @@ -33,8 +33,8 @@ var PublicreportNotifyEmailPools = Table[ Generated: false, AutoIncr: false, }, - PoolID: column{ - Name: "pool_id", + WaterID: column{ + Name: "water_id", DBType: "integer", Default: "", Comment: "", @@ -52,13 +52,13 @@ var PublicreportNotifyEmailPools = Table[ AutoIncr: false, }, }, - Indexes: publicreportNotifyEmailPoolIndexes{ + Indexes: publicreportNotifyEmailWaterIndexes{ NotifyEmailPoolPkey: index{ Type: "btree", Name: "notify_email_pool_pkey", Columns: []indexColumn{ { - Name: "pool_id", + Name: "water_id", Desc: null.FromCond(false, true), IsExpression: false, }, @@ -78,26 +78,26 @@ var PublicreportNotifyEmailPools = Table[ }, PrimaryKey: &constraint{ Name: "notify_email_pool_pkey", - Columns: []string{"pool_id", "email_address"}, + Columns: []string{"water_id", "email_address"}, Comment: "", }, - ForeignKeys: publicreportNotifyEmailPoolForeignKeys{ - PublicreportNotifyEmailPoolNotifyEmailPoolEmailAddressFkey: foreignKey{ + ForeignKeys: publicreportNotifyEmailWaterForeignKeys{ + PublicreportNotifyEmailWaterNotifyEmailPoolEmailAddressFkey: foreignKey{ constraint: constraint{ - Name: "publicreport.notify_email_pool.notify_email_pool_email_address_fkey", + Name: "publicreport.notify_email_water.notify_email_pool_email_address_fkey", Columns: []string{"email_address"}, Comment: "", }, ForeignTable: "comms.email_contact", ForeignColumns: []string{"address"}, }, - PublicreportNotifyEmailPoolNotifyEmailPoolPoolIDFkey: foreignKey{ + PublicreportNotifyEmailWaterNotifyEmailPoolPoolIDFkey: foreignKey{ constraint: constraint{ - Name: "publicreport.notify_email_pool.notify_email_pool_pool_id_fkey", - Columns: []string{"pool_id"}, + Name: "publicreport.notify_email_water.notify_email_pool_pool_id_fkey", + Columns: []string{"water_id"}, Comment: "", }, - ForeignTable: "publicreport.pool", + ForeignTable: "publicreport.water", ForeignColumns: []string{"id"}, }, }, @@ -105,48 +105,48 @@ var PublicreportNotifyEmailPools = Table[ Comment: "", } -type publicreportNotifyEmailPoolColumns struct { +type publicreportNotifyEmailWaterColumns struct { Created column Deleted column - PoolID column + WaterID column EmailAddress column } -func (c publicreportNotifyEmailPoolColumns) AsSlice() []column { +func (c publicreportNotifyEmailWaterColumns) AsSlice() []column { return []column{ - c.Created, c.Deleted, c.PoolID, c.EmailAddress, + c.Created, c.Deleted, c.WaterID, c.EmailAddress, } } -type publicreportNotifyEmailPoolIndexes struct { +type publicreportNotifyEmailWaterIndexes struct { NotifyEmailPoolPkey index } -func (i publicreportNotifyEmailPoolIndexes) AsSlice() []index { +func (i publicreportNotifyEmailWaterIndexes) AsSlice() []index { return []index{ i.NotifyEmailPoolPkey, } } -type publicreportNotifyEmailPoolForeignKeys struct { - PublicreportNotifyEmailPoolNotifyEmailPoolEmailAddressFkey foreignKey - PublicreportNotifyEmailPoolNotifyEmailPoolPoolIDFkey foreignKey +type publicreportNotifyEmailWaterForeignKeys struct { + PublicreportNotifyEmailWaterNotifyEmailPoolEmailAddressFkey foreignKey + PublicreportNotifyEmailWaterNotifyEmailPoolPoolIDFkey foreignKey } -func (f publicreportNotifyEmailPoolForeignKeys) AsSlice() []foreignKey { +func (f publicreportNotifyEmailWaterForeignKeys) AsSlice() []foreignKey { return []foreignKey{ - f.PublicreportNotifyEmailPoolNotifyEmailPoolEmailAddressFkey, f.PublicreportNotifyEmailPoolNotifyEmailPoolPoolIDFkey, + f.PublicreportNotifyEmailWaterNotifyEmailPoolEmailAddressFkey, f.PublicreportNotifyEmailWaterNotifyEmailPoolPoolIDFkey, } } -type publicreportNotifyEmailPoolUniques struct{} +type publicreportNotifyEmailWaterUniques struct{} -func (u publicreportNotifyEmailPoolUniques) AsSlice() []constraint { +func (u publicreportNotifyEmailWaterUniques) AsSlice() []constraint { return []constraint{} } -type publicreportNotifyEmailPoolChecks struct{} +type publicreportNotifyEmailWaterChecks struct{} -func (c publicreportNotifyEmailPoolChecks) AsSlice() []check { +func (c publicreportNotifyEmailWaterChecks) AsSlice() []check { return []check{} } diff --git a/db/dbinfo/publicreport.notify_phone_pool.bob.go b/db/dbinfo/publicreport.notify_phone_water.bob.go similarity index 52% rename from db/dbinfo/publicreport.notify_phone_pool.bob.go rename to db/dbinfo/publicreport.notify_phone_water.bob.go index 2cb9b545..8d9655fa 100644 --- a/db/dbinfo/publicreport.notify_phone_pool.bob.go +++ b/db/dbinfo/publicreport.notify_phone_water.bob.go @@ -5,16 +5,16 @@ package dbinfo import "github.com/aarondl/opt/null" -var PublicreportNotifyPhonePools = Table[ - publicreportNotifyPhonePoolColumns, - publicreportNotifyPhonePoolIndexes, - publicreportNotifyPhonePoolForeignKeys, - publicreportNotifyPhonePoolUniques, - publicreportNotifyPhonePoolChecks, +var PublicreportNotifyPhoneWaters = Table[ + publicreportNotifyPhoneWaterColumns, + publicreportNotifyPhoneWaterIndexes, + publicreportNotifyPhoneWaterForeignKeys, + publicreportNotifyPhoneWaterUniques, + publicreportNotifyPhoneWaterChecks, ]{ Schema: "publicreport", - Name: "notify_phone_pool", - Columns: publicreportNotifyPhonePoolColumns{ + Name: "notify_phone_water", + Columns: publicreportNotifyPhoneWaterColumns{ Created: column{ Name: "created", DBType: "timestamp without time zone", @@ -42,8 +42,8 @@ var PublicreportNotifyPhonePools = Table[ Generated: false, AutoIncr: false, }, - PoolID: column{ - Name: "pool_id", + WaterID: column{ + Name: "water_id", DBType: "integer", Default: "", Comment: "", @@ -52,13 +52,13 @@ var PublicreportNotifyPhonePools = Table[ AutoIncr: false, }, }, - Indexes: publicreportNotifyPhonePoolIndexes{ + Indexes: publicreportNotifyPhoneWaterIndexes{ NotifyPhonePoolPkey: index{ Type: "btree", Name: "notify_phone_pool_pkey", Columns: []indexColumn{ { - Name: "pool_id", + Name: "water_id", Desc: null.FromCond(false, true), IsExpression: false, }, @@ -78,26 +78,26 @@ var PublicreportNotifyPhonePools = Table[ }, PrimaryKey: &constraint{ Name: "notify_phone_pool_pkey", - Columns: []string{"pool_id", "phone_e164"}, + Columns: []string{"water_id", "phone_e164"}, Comment: "", }, - ForeignKeys: publicreportNotifyPhonePoolForeignKeys{ - PublicreportNotifyPhonePoolNotifyPhonePoolPhoneE164Fkey: foreignKey{ + ForeignKeys: publicreportNotifyPhoneWaterForeignKeys{ + PublicreportNotifyPhoneWaterNotifyPhonePoolPhoneE164Fkey: foreignKey{ constraint: constraint{ - Name: "publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey", + Name: "publicreport.notify_phone_water.notify_phone_pool_phone_e164_fkey", Columns: []string{"phone_e164"}, Comment: "", }, ForeignTable: "comms.phone", ForeignColumns: []string{"e164"}, }, - PublicreportNotifyPhonePoolNotifyPhonePoolPoolIDFkey: foreignKey{ + PublicreportNotifyPhoneWaterNotifyPhonePoolPoolIDFkey: foreignKey{ constraint: constraint{ - Name: "publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey", - Columns: []string{"pool_id"}, + Name: "publicreport.notify_phone_water.notify_phone_pool_pool_id_fkey", + Columns: []string{"water_id"}, Comment: "", }, - ForeignTable: "publicreport.pool", + ForeignTable: "publicreport.water", ForeignColumns: []string{"id"}, }, }, @@ -105,48 +105,48 @@ var PublicreportNotifyPhonePools = Table[ Comment: "", } -type publicreportNotifyPhonePoolColumns struct { +type publicreportNotifyPhoneWaterColumns struct { Created column Deleted column PhoneE164 column - PoolID column + WaterID column } -func (c publicreportNotifyPhonePoolColumns) AsSlice() []column { +func (c publicreportNotifyPhoneWaterColumns) AsSlice() []column { return []column{ - c.Created, c.Deleted, c.PhoneE164, c.PoolID, + c.Created, c.Deleted, c.PhoneE164, c.WaterID, } } -type publicreportNotifyPhonePoolIndexes struct { +type publicreportNotifyPhoneWaterIndexes struct { NotifyPhonePoolPkey index } -func (i publicreportNotifyPhonePoolIndexes) AsSlice() []index { +func (i publicreportNotifyPhoneWaterIndexes) AsSlice() []index { return []index{ i.NotifyPhonePoolPkey, } } -type publicreportNotifyPhonePoolForeignKeys struct { - PublicreportNotifyPhonePoolNotifyPhonePoolPhoneE164Fkey foreignKey - PublicreportNotifyPhonePoolNotifyPhonePoolPoolIDFkey foreignKey +type publicreportNotifyPhoneWaterForeignKeys struct { + PublicreportNotifyPhoneWaterNotifyPhonePoolPhoneE164Fkey foreignKey + PublicreportNotifyPhoneWaterNotifyPhonePoolPoolIDFkey foreignKey } -func (f publicreportNotifyPhonePoolForeignKeys) AsSlice() []foreignKey { +func (f publicreportNotifyPhoneWaterForeignKeys) AsSlice() []foreignKey { return []foreignKey{ - f.PublicreportNotifyPhonePoolNotifyPhonePoolPhoneE164Fkey, f.PublicreportNotifyPhonePoolNotifyPhonePoolPoolIDFkey, + f.PublicreportNotifyPhoneWaterNotifyPhonePoolPhoneE164Fkey, f.PublicreportNotifyPhoneWaterNotifyPhonePoolPoolIDFkey, } } -type publicreportNotifyPhonePoolUniques struct{} +type publicreportNotifyPhoneWaterUniques struct{} -func (u publicreportNotifyPhonePoolUniques) AsSlice() []constraint { +func (u publicreportNotifyPhoneWaterUniques) AsSlice() []constraint { return []constraint{} } -type publicreportNotifyPhonePoolChecks struct{} +type publicreportNotifyPhoneWaterChecks struct{} -func (c publicreportNotifyPhonePoolChecks) AsSlice() []check { +func (c publicreportNotifyPhoneWaterChecks) AsSlice() []check { return []check{} } diff --git a/db/dbinfo/publicreport.nuisance.bob.go b/db/dbinfo/publicreport.nuisance.bob.go index f20375a8..fa89ab27 100644 --- a/db/dbinfo/publicreport.nuisance.bob.go +++ b/db/dbinfo/publicreport.nuisance.bob.go @@ -114,8 +114,8 @@ var PublicreportNuisances = Table[ Generated: false, AutoIncr: false, }, - Address: column{ - Name: "address", + AddressRaw: column{ + Name: "address_raw", DBType: "text", Default: "", Comment: "", @@ -168,8 +168,8 @@ var PublicreportNuisances = Table[ Generated: false, AutoIncr: false, }, - AddressPlace: column{ - Name: "address_place", + AddressLocality: column{ + Name: "address_locality", DBType: "text", Default: "", Comment: "", @@ -177,8 +177,8 @@ var PublicreportNuisances = Table[ Generated: false, AutoIncr: false, }, - AddressPostcode: column{ - Name: "address_postcode", + AddressPostalCode: column{ + Name: "address_postal_code", DBType: "text", Default: "", Comment: "", @@ -339,6 +339,15 @@ var PublicreportNuisances = Table[ Generated: false, AutoIncr: false, }, + AddressID: column{ + Name: "address_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, }, Indexes: publicreportNuisanceIndexes{ NuisancePkey: index{ @@ -382,6 +391,15 @@ var PublicreportNuisances = Table[ Comment: "", }, ForeignKeys: publicreportNuisanceForeignKeys{ + PublicreportNuisanceNuisanceAddressIDFkey: foreignKey{ + constraint: constraint{ + Name: "publicreport.nuisance.nuisance_address_id_fkey", + Columns: []string{"address_id"}, + Comment: "", + }, + ForeignTable: "address", + ForeignColumns: []string{"id"}, + }, PublicreportNuisanceNuisanceOrganizationIDFkey: foreignKey{ constraint: constraint{ Name: "publicreport.nuisance.nuisance_organization_id_fkey", @@ -415,14 +433,14 @@ type publicreportNuisanceColumns struct { ReporterEmail column ReporterName column ReporterPhone column - Address column + AddressRaw column Status column OrganizationID column SourceGutter column H3cell column AddressCountry column - AddressPlace column - AddressPostcode column + AddressLocality column + AddressPostalCode column AddressRegion column AddressStreet column IsLocationBackyard column @@ -440,11 +458,12 @@ type publicreportNuisanceColumns struct { ReporterContactConsent column Location column AddressNumber column + AddressID column } func (c publicreportNuisanceColumns) AsSlice() []column { return []column{ - c.ID, c.AdditionalInfo, c.Created, c.Duration, c.SourceContainer, c.SourceDescription, c.SourceStagnant, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Address, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressPlace, c.AddressPostcode, c.AddressRegion, c.AddressStreet, c.IsLocationBackyard, c.IsLocationFrontyard, c.IsLocationGarden, c.IsLocationOther, c.IsLocationPool, c.MapZoom, c.TodEarly, c.TodDay, c.TodEvening, c.TodNight, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.ReporterContactConsent, c.Location, c.AddressNumber, + 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, } } @@ -460,12 +479,13 @@ func (i publicreportNuisanceIndexes) AsSlice() []index { } type publicreportNuisanceForeignKeys struct { + PublicreportNuisanceNuisanceAddressIDFkey foreignKey PublicreportNuisanceNuisanceOrganizationIDFkey foreignKey } func (f publicreportNuisanceForeignKeys) AsSlice() []foreignKey { return []foreignKey{ - f.PublicreportNuisanceNuisanceOrganizationIDFkey, + f.PublicreportNuisanceNuisanceAddressIDFkey, f.PublicreportNuisanceNuisanceOrganizationIDFkey, } } diff --git a/db/dbinfo/publicreport.pool_image.bob.go b/db/dbinfo/publicreport.pool_image.bob.go deleted file mode 100644 index 3d39ed61..00000000 --- a/db/dbinfo/publicreport.pool_image.bob.go +++ /dev/null @@ -1,132 +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 dbinfo - -import "github.com/aarondl/opt/null" - -var PublicreportPoolImages = Table[ - publicreportPoolImageColumns, - publicreportPoolImageIndexes, - publicreportPoolImageForeignKeys, - publicreportPoolImageUniques, - publicreportPoolImageChecks, -]{ - Schema: "publicreport", - Name: "pool_image", - Columns: publicreportPoolImageColumns{ - ImageID: column{ - Name: "image_id", - DBType: "integer", - Default: "", - Comment: "", - Nullable: false, - Generated: false, - AutoIncr: false, - }, - PoolID: column{ - Name: "pool_id", - DBType: "integer", - Default: "", - Comment: "", - Nullable: false, - Generated: false, - AutoIncr: false, - }, - }, - Indexes: publicreportPoolImageIndexes{ - PoolImagePkey: index{ - Type: "btree", - Name: "pool_image_pkey", - Columns: []indexColumn{ - { - Name: "image_id", - Desc: null.FromCond(false, true), - IsExpression: false, - }, - { - Name: "pool_id", - Desc: null.FromCond(false, true), - IsExpression: false, - }, - }, - Unique: true, - Comment: "", - NullsFirst: []bool{false, false}, - NullsDistinct: false, - Where: "", - Include: []string{}, - }, - }, - PrimaryKey: &constraint{ - Name: "pool_image_pkey", - Columns: []string{"image_id", "pool_id"}, - Comment: "", - }, - ForeignKeys: publicreportPoolImageForeignKeys{ - PublicreportPoolImagePoolImageImageIDFkey: foreignKey{ - constraint: constraint{ - Name: "publicreport.pool_image.pool_image_image_id_fkey", - Columns: []string{"image_id"}, - Comment: "", - }, - ForeignTable: "publicreport.image", - ForeignColumns: []string{"id"}, - }, - PublicreportPoolImagePoolImagePoolIDFkey: foreignKey{ - constraint: constraint{ - Name: "publicreport.pool_image.pool_image_pool_id_fkey", - Columns: []string{"pool_id"}, - Comment: "", - }, - ForeignTable: "publicreport.pool", - ForeignColumns: []string{"id"}, - }, - }, - - Comment: "", -} - -type publicreportPoolImageColumns struct { - ImageID column - PoolID column -} - -func (c publicreportPoolImageColumns) AsSlice() []column { - return []column{ - c.ImageID, c.PoolID, - } -} - -type publicreportPoolImageIndexes struct { - PoolImagePkey index -} - -func (i publicreportPoolImageIndexes) AsSlice() []index { - return []index{ - i.PoolImagePkey, - } -} - -type publicreportPoolImageForeignKeys struct { - PublicreportPoolImagePoolImageImageIDFkey foreignKey - PublicreportPoolImagePoolImagePoolIDFkey foreignKey -} - -func (f publicreportPoolImageForeignKeys) AsSlice() []foreignKey { - return []foreignKey{ - f.PublicreportPoolImagePoolImageImageIDFkey, f.PublicreportPoolImagePoolImagePoolIDFkey, - } -} - -type publicreportPoolImageUniques struct{} - -func (u publicreportPoolImageUniques) AsSlice() []constraint { - return []constraint{} -} - -type publicreportPoolImageChecks struct{} - -func (c publicreportPoolImageChecks) AsSlice() []check { - return []check{} -} diff --git a/db/dbinfo/publicreport.pool.bob.go b/db/dbinfo/publicreport.water.bob.go similarity index 79% rename from db/dbinfo/publicreport.pool.bob.go rename to db/dbinfo/publicreport.water.bob.go index 1d5d501b..22f72d3f 100644 --- a/db/dbinfo/publicreport.pool.bob.go +++ b/db/dbinfo/publicreport.water.bob.go @@ -5,16 +5,16 @@ package dbinfo import "github.com/aarondl/opt/null" -var PublicreportPools = Table[ - publicreportPoolColumns, - publicreportPoolIndexes, - publicreportPoolForeignKeys, - publicreportPoolUniques, - publicreportPoolChecks, +var PublicreportWaters = Table[ + publicreportWaterColumns, + publicreportWaterIndexes, + publicreportWaterForeignKeys, + publicreportWaterUniques, + publicreportWaterChecks, ]{ Schema: "publicreport", - Name: "pool", - Columns: publicreportPoolColumns{ + Name: "water", + Columns: publicreportWaterColumns{ ID: column{ Name: "id", DBType: "integer", @@ -78,8 +78,8 @@ var PublicreportPools = Table[ Generated: false, AutoIncr: false, }, - Address: column{ - Name: "address", + AddressRaw: column{ + Name: "address_raw", DBType: "text", Default: "", Comment: "", @@ -96,8 +96,8 @@ var PublicreportPools = Table[ Generated: false, AutoIncr: false, }, - AddressPostCode: column{ - Name: "address_post_code", + AddressPostalCode: column{ + Name: "address_postal_code", DBType: "text", Default: "", Comment: "", @@ -105,8 +105,8 @@ var PublicreportPools = Table[ Generated: false, AutoIncr: false, }, - AddressPlace: column{ - Name: "address_place", + AddressLocality: column{ + Name: "address_locality", DBType: "text", Default: "", Comment: "", @@ -330,8 +330,17 @@ var PublicreportPools = Table[ Generated: false, AutoIncr: false, }, + AddressID: column{ + Name: "address_id", + DBType: "integer", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, }, - Indexes: publicreportPoolIndexes{ + Indexes: publicreportWaterIndexes{ PoolPkey: index{ Type: "btree", Name: "pool_pkey", @@ -372,10 +381,19 @@ var PublicreportPools = Table[ Columns: []string{"id"}, Comment: "", }, - ForeignKeys: publicreportPoolForeignKeys{ - PublicreportPoolPoolOrganizationIDFkey: foreignKey{ + ForeignKeys: publicreportWaterForeignKeys{ + PublicreportWaterPoolAddressIDFkey: foreignKey{ constraint: constraint{ - Name: "publicreport.pool.pool_organization_id_fkey", + Name: "publicreport.water.pool_address_id_fkey", + Columns: []string{"address_id"}, + Comment: "", + }, + ForeignTable: "address", + ForeignColumns: []string{"id"}, + }, + PublicreportWaterPoolOrganizationIDFkey: foreignKey{ + constraint: constraint{ + Name: "publicreport.water.pool_organization_id_fkey", Columns: []string{"organization_id"}, Comment: "", }, @@ -383,7 +401,7 @@ var PublicreportPools = Table[ ForeignColumns: []string{"id"}, }, }, - Uniques: publicreportPoolUniques{ + Uniques: publicreportWaterUniques{ PoolPublicIDKey: constraint{ Name: "pool_public_id_key", Columns: []string{"public_id"}, @@ -394,7 +412,7 @@ var PublicreportPools = Table[ Comment: "", } -type publicreportPoolColumns struct { +type publicreportWaterColumns struct { ID column AccessComments column AccessGate column @@ -402,10 +420,10 @@ type publicreportPoolColumns struct { AccessLocked column AccessDog column AccessOther column - Address column + AddressRaw column AddressCountry column - AddressPostCode column - AddressPlace column + AddressPostalCode column + AddressLocality column AddressStreet column AddressRegion column Comments column @@ -430,47 +448,49 @@ type publicreportPoolColumns struct { ReporterContactConsent column Location column AddressNumber column + AddressID column } -func (c publicreportPoolColumns) AsSlice() []column { +func (c publicreportWaterColumns) AsSlice() []column { return []column{ - c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.Address, c.AddressCountry, c.AddressPostCode, c.AddressPlace, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, c.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.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, } } -type publicreportPoolIndexes struct { +type publicreportWaterIndexes struct { PoolPkey index PoolPublicIDKey index } -func (i publicreportPoolIndexes) AsSlice() []index { +func (i publicreportWaterIndexes) AsSlice() []index { return []index{ i.PoolPkey, i.PoolPublicIDKey, } } -type publicreportPoolForeignKeys struct { - PublicreportPoolPoolOrganizationIDFkey foreignKey +type publicreportWaterForeignKeys struct { + PublicreportWaterPoolAddressIDFkey foreignKey + PublicreportWaterPoolOrganizationIDFkey foreignKey } -func (f publicreportPoolForeignKeys) AsSlice() []foreignKey { +func (f publicreportWaterForeignKeys) AsSlice() []foreignKey { return []foreignKey{ - f.PublicreportPoolPoolOrganizationIDFkey, + f.PublicreportWaterPoolAddressIDFkey, f.PublicreportWaterPoolOrganizationIDFkey, } } -type publicreportPoolUniques struct { +type publicreportWaterUniques struct { PoolPublicIDKey constraint } -func (u publicreportPoolUniques) AsSlice() []constraint { +func (u publicreportWaterUniques) AsSlice() []constraint { return []constraint{ u.PoolPublicIDKey, } } -type publicreportPoolChecks struct{} +type publicreportWaterChecks struct{} -func (c publicreportPoolChecks) AsSlice() []check { +func (c publicreportWaterChecks) AsSlice() []check { return []check{} } diff --git a/db/dbinfo/publicreport.water_image.bob.go b/db/dbinfo/publicreport.water_image.bob.go new file mode 100644 index 00000000..33c26e38 --- /dev/null +++ b/db/dbinfo/publicreport.water_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 PublicreportWaterImages = Table[ + publicreportWaterImageColumns, + publicreportWaterImageIndexes, + publicreportWaterImageForeignKeys, + publicreportWaterImageUniques, + publicreportWaterImageChecks, +]{ + Schema: "publicreport", + Name: "water_image", + Columns: publicreportWaterImageColumns{ + ImageID: column{ + Name: "image_id", + DBType: "integer", + Default: "", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, + WaterID: column{ + Name: "water_id", + DBType: "integer", + Default: "", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, + }, + Indexes: publicreportWaterImageIndexes{ + PoolImagePkey: index{ + Type: "btree", + Name: "pool_image_pkey", + Columns: []indexColumn{ + { + Name: "image_id", + Desc: null.FromCond(false, true), + IsExpression: false, + }, + { + Name: "water_id", + Desc: null.FromCond(false, true), + IsExpression: false, + }, + }, + Unique: true, + Comment: "", + NullsFirst: []bool{false, false}, + NullsDistinct: false, + Where: "", + Include: []string{}, + }, + }, + PrimaryKey: &constraint{ + Name: "pool_image_pkey", + Columns: []string{"image_id", "water_id"}, + Comment: "", + }, + ForeignKeys: publicreportWaterImageForeignKeys{ + PublicreportWaterImagePoolImageImageIDFkey: foreignKey{ + constraint: constraint{ + Name: "publicreport.water_image.pool_image_image_id_fkey", + Columns: []string{"image_id"}, + Comment: "", + }, + ForeignTable: "publicreport.image", + ForeignColumns: []string{"id"}, + }, + PublicreportWaterImagePoolImagePoolIDFkey: foreignKey{ + constraint: constraint{ + Name: "publicreport.water_image.pool_image_pool_id_fkey", + Columns: []string{"water_id"}, + Comment: "", + }, + ForeignTable: "publicreport.water", + ForeignColumns: []string{"id"}, + }, + }, + + Comment: "", +} + +type publicreportWaterImageColumns struct { + ImageID column + WaterID column +} + +func (c publicreportWaterImageColumns) AsSlice() []column { + return []column{ + c.ImageID, c.WaterID, + } +} + +type publicreportWaterImageIndexes struct { + PoolImagePkey index +} + +func (i publicreportWaterImageIndexes) AsSlice() []index { + return []index{ + i.PoolImagePkey, + } +} + +type publicreportWaterImageForeignKeys struct { + PublicreportWaterImagePoolImageImageIDFkey foreignKey + PublicreportWaterImagePoolImagePoolIDFkey foreignKey +} + +func (f publicreportWaterImageForeignKeys) AsSlice() []foreignKey { + return []foreignKey{ + f.PublicreportWaterImagePoolImageImageIDFkey, f.PublicreportWaterImagePoolImagePoolIDFkey, + } +} + +type publicreportWaterImageUniques struct{} + +func (u publicreportWaterImageUniques) AsSlice() []constraint { + return []constraint{} +} + +type publicreportWaterImageChecks struct{} + +func (c publicreportWaterImageChecks) AsSlice() []check { + return []check{} +} diff --git a/db/migrations/00096_publicreport_address_locality.sql b/db/migrations/00096_publicreport_address_locality.sql new file mode 100644 index 00000000..3a0a8a83 --- /dev/null +++ b/db/migrations/00096_publicreport_address_locality.sql @@ -0,0 +1,46 @@ +-- +goose Up +ALTER TABLE publicreport.nuisance RENAME COLUMN address TO address_raw; +ALTER TABLE publicreport.nuisance RENAME COLUMN address_place TO address_locality; +ALTER TABLE publicreport.nuisance RENAME COLUMN address_postcode TO address_postal_code; + +ALTER TABLE publicreport.nuisance ADD COLUMN address_id INTEGER REFERENCES address(id); + +ALTER TABLE publicreport.pool RENAME COLUMN address TO address_raw; +ALTER TABLE publicreport.pool RENAME COLUMN address_place TO address_locality; +ALTER TABLE publicreport.pool RENAME COLUMN address_post_code TO address_postal_code; + +ALTER TABLE publicreport.pool ADD COLUMN address_id INTEGER REFERENCES address(id); + +ALTER TABLE publicreport.pool RENAME TO water; + +ALTER TABLE publicreport.pool_image RENAME COLUMN pool_id TO water_id; +ALTER TABLE publicreport.pool_image RENAME TO water_image; + +ALTER TABLE publicreport.notify_email_pool RENAME COLUMN pool_id TO water_id; +ALTER TABLE publicreport.notify_email_pool RENAME TO notify_email_water; + +ALTER TABLE publicreport.notify_phone_pool RENAME COLUMN pool_id TO water_id; +ALTER TABLE publicreport.notify_phone_pool RENAME TO notify_phone_water; +-- +goose Down +ALTER TABLE publicreport.notify_phone_water RENAME TO notify_phone_pool; +ALTER TABLE publicreport.notify_phone_pool RENAME COLUMN water_id TO pool_id; + +ALTER TABLE publicreport.notify_email_water RENAME TO notify_email_pool; +ALTER TABLE publicreport.notify_email_pool RENAME COLUMN water_id TO pool_id; + +ALTER TABLE publicreport.water_image RENAME COLUMN water_id TO pool_id; +ALTER TABLE publicreport.water_image RENAME TO pool_image; + +ALTER TABLE publicreport.water RENAME TO pool; + +ALTER TABLE publicreport.pool DROP COLUMN address_id; + +ALTER TABLE publicreport.pool RENAME COLUMN address_postal_code TO address_post_code; +ALTER TABLE publicreport.pool RENAME COLUMN address_locality TO address_place; +ALTER TABLE publicreport.pool RENAME COLUMN address_raw TO address; + +ALTER TABLE publicreport.nuisance DROP COLUMN address_id; + +ALTER TABLE publicreport.nuisance RENAME COLUMN address_postal_code TO address_postcode; +ALTER TABLE publicreport.nuisance RENAME COLUMN address_locality TO address_place; +ALTER TABLE publicreport.nuisance RENAME COLUMN address_raw TO address; diff --git a/db/models/address.bob.go b/db/models/address.bob.go index 3fddd361..4d07806f 100644 --- a/db/models/address.bob.go +++ b/db/models/address.bob.go @@ -20,6 +20,7 @@ import ( "github.com/Gleipnir-Technology/bob/types/pgtypes" enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" ) // Address is an object representing the database table. @@ -51,9 +52,11 @@ type AddressesQuery = *psql.ViewQuery[*Address, AddressSlice] // addressR is where relationships are stored. type addressR struct { - Mailers CommsMailerSlice // comms.mailer.mailer_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 + 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 } func buildAddressColumns(alias string) addressColumns { @@ -602,6 +605,54 @@ 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))), + )...) +} + +func (os AddressSlice) Nuisances(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.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))), + )...) +} + +func (os AddressSlice) Waters(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.AddressID).OP("IN", PKArgExpr)), + )...) +} + // Residents starts a query for related objects on resident func (o *Address) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery { return Residents.Query(append(mods, @@ -718,6 +769,142 @@ 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) + } + + ret, err := PublicreportNuisances.Insert(bob.ToMods(publicreportNuisances1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAddressNuisances0: %w", err) + } + + return ret, nil +} + +func attachAddressNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNuisances1 PublicreportNuisanceSlice, address0 *Address) (PublicreportNuisanceSlice, error) { + setter := &PublicreportNuisanceSetter{ + AddressID: omitnull.From(address0.ID), + } + + err := publicreportNuisances1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAddressNuisances0: %w", err) + } + + return publicreportNuisances1, nil +} + +func (address0 *Address) InsertNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportNuisances1, err := insertAddressNuisances0(ctx, exec, related, address0) + if err != nil { + return err + } + + address0.R.Nuisances = append(address0.R.Nuisances, publicreportNuisances1...) + + for _, rel := range publicreportNuisances1 { + rel.R.Address = address0 + } + return nil +} + +func (address0 *Address) AttachNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportNuisances1 := PublicreportNuisanceSlice(related) + + _, err = attachAddressNuisances0(ctx, exec, len(related), publicreportNuisances1, address0) + if err != nil { + return err + } + + address0.R.Nuisances = append(address0.R.Nuisances, publicreportNuisances1...) + + for _, rel := range related { + rel.R.Address = address0 + } + + 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) + } + + ret, err := PublicreportWaters.Insert(bob.ToMods(publicreportWaters1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAddressWaters0: %w", err) + } + + return ret, nil +} + +func attachAddressWaters0(ctx context.Context, exec bob.Executor, count int, publicreportWaters1 PublicreportWaterSlice, address0 *Address) (PublicreportWaterSlice, error) { + setter := &PublicreportWaterSetter{ + AddressID: omitnull.From(address0.ID), + } + + err := publicreportWaters1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAddressWaters0: %w", err) + } + + return publicreportWaters1, nil +} + +func (address0 *Address) InsertWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + publicreportWaters1, err := insertAddressWaters0(ctx, exec, related, address0) + if err != nil { + return err + } + + address0.R.Waters = append(address0.R.Waters, publicreportWaters1...) + + for _, rel := range publicreportWaters1 { + rel.R.Address = address0 + } + return nil +} + +func (address0 *Address) AttachWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error { + if len(related) == 0 { + return nil + } + + var err error + publicreportWaters1 := PublicreportWaterSlice(related) + + _, err = attachAddressWaters0(ctx, exec, len(related), publicreportWaters1, address0) + if err != nil { + return err + } + + address0.R.Waters = append(address0.R.Waters, publicreportWaters1...) + + for _, rel := range related { + rel.R.Address = address0 + } + + return nil +} + func insertAddressResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, address0 *Address) (ResidentSlice, error) { for i := range residents1 { residents1[i].AddressID = omit.From(address0.ID) @@ -888,6 +1075,34 @@ func (o *Address) Preload(name string, retrieved any) error { o.R.Mailers = rels + for _, rel := range rels { + if rel != nil { + rel.R.Address = o + } + } + return nil + case "Nuisances": + rels, ok := retrieved.(PublicreportNuisanceSlice) + if !ok { + return fmt.Errorf("address cannot load %T as %q", retrieved, name) + } + + o.R.Nuisances = rels + + for _, rel := range rels { + if rel != nil { + rel.R.Address = o + } + } + return nil + case "Waters": + rels, ok := retrieved.(PublicreportWaterSlice) + if !ok { + return fmt.Errorf("address cannot load %T as %q", retrieved, name) + } + + o.R.Waters = rels + for _, rel := range rels { if rel != nil { rel.R.Address = o @@ -949,6 +1164,8 @@ 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] } @@ -957,6 +1174,12 @@ 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 WatersLoadInterface interface { + LoadWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type ResidentsLoadInterface interface { LoadResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -971,6 +1194,18 @@ 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...) + }, + ), + 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...) + }, + ), Residents: thenLoadBuilder[Q]( "Residents", func(ctx context.Context, exec bob.Executor, retrieved ResidentsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -1047,6 +1282,134 @@ 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 { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Nuisances = nil + + related, err := o.Nuisances(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Address = o + } + + o.R.Nuisances = 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 { + if len(os) == 0 { + return nil + } + + publicreportNuisances, err := os.Nuisances(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.Nuisances = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportNuisances { + + if !rel.AddressID.IsValue() { + continue + } + if !(rel.AddressID.IsValue() && o.ID == rel.AddressID.MustGet()) { + continue + } + + rel.R.Address = o + + o.R.Nuisances = append(o.R.Nuisances, 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 { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Waters = nil + + related, err := o.Waters(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Address = o + } + + o.R.Waters = 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 { + if len(os) == 0 { + return nil + } + + publicreportWaters, err := os.Waters(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.Waters = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range publicreportWaters { + + if !rel.AddressID.IsValue() { + continue + } + if !(rel.AddressID.IsValue() && o.ID == rel.AddressID.MustGet()) { + continue + } + + rel.R.Address = o + + o.R.Waters = append(o.R.Waters, rel) + } + } + + return nil +} + // LoadResidents loads the address's Residents into the .R struct func (o *Address) LoadResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { diff --git a/db/models/bob_loaders.bob.go b/db/models/bob_loaders.bob.go index 76663efd..dd5da76d 100644 --- a/db/models/bob_loaders.bob.go +++ b/db/models/bob_loaders.bob.go @@ -88,15 +88,15 @@ type preloaders struct { PublicreportImage publicreportImagePreloader PublicreportImageExif publicreportImageExifPreloader PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisancePreloader - PublicreportNotifyEmailPool publicreportNotifyEmailPoolPreloader + PublicreportNotifyEmailWater publicreportNotifyEmailWaterPreloader PublicreportNotifyPhoneNuisance publicreportNotifyPhoneNuisancePreloader - PublicreportNotifyPhonePool publicreportNotifyPhonePoolPreloader + PublicreportNotifyPhoneWater publicreportNotifyPhoneWaterPreloader PublicreportNuisance publicreportNuisancePreloader PublicreportNuisanceImage publicreportNuisanceImagePreloader - PublicreportPool publicreportPoolPreloader - PublicreportPoolImage publicreportPoolImagePreloader PublicreportSubscribeEmail publicreportSubscribeEmailPreloader PublicreportSubscribePhone publicreportSubscribePhonePreloader + PublicreportWater publicreportWaterPreloader + PublicreportWaterImage publicreportWaterImagePreloader Resident residentPreloader ReviewTask reviewTaskPreloader ReviewTaskPool reviewTaskPoolPreloader @@ -179,15 +179,15 @@ func getPreloaders() preloaders { PublicreportImage: buildPublicreportImagePreloader(), PublicreportImageExif: buildPublicreportImageExifPreloader(), PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisancePreloader(), - PublicreportNotifyEmailPool: buildPublicreportNotifyEmailPoolPreloader(), + PublicreportNotifyEmailWater: buildPublicreportNotifyEmailWaterPreloader(), PublicreportNotifyPhoneNuisance: buildPublicreportNotifyPhoneNuisancePreloader(), - PublicreportNotifyPhonePool: buildPublicreportNotifyPhonePoolPreloader(), + PublicreportNotifyPhoneWater: buildPublicreportNotifyPhoneWaterPreloader(), PublicreportNuisance: buildPublicreportNuisancePreloader(), PublicreportNuisanceImage: buildPublicreportNuisanceImagePreloader(), - PublicreportPool: buildPublicreportPoolPreloader(), - PublicreportPoolImage: buildPublicreportPoolImagePreloader(), PublicreportSubscribeEmail: buildPublicreportSubscribeEmailPreloader(), PublicreportSubscribePhone: buildPublicreportSubscribePhonePreloader(), + PublicreportWater: buildPublicreportWaterPreloader(), + PublicreportWaterImage: buildPublicreportWaterImagePreloader(), Resident: buildResidentPreloader(), ReviewTask: buildReviewTaskPreloader(), ReviewTaskPool: buildReviewTaskPoolPreloader(), @@ -276,15 +276,15 @@ type thenLoaders[Q orm.Loadable] struct { PublicreportImage publicreportImageThenLoader[Q] PublicreportImageExif publicreportImageExifThenLoader[Q] PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisanceThenLoader[Q] - PublicreportNotifyEmailPool publicreportNotifyEmailPoolThenLoader[Q] + PublicreportNotifyEmailWater publicreportNotifyEmailWaterThenLoader[Q] PublicreportNotifyPhoneNuisance publicreportNotifyPhoneNuisanceThenLoader[Q] - PublicreportNotifyPhonePool publicreportNotifyPhonePoolThenLoader[Q] + PublicreportNotifyPhoneWater publicreportNotifyPhoneWaterThenLoader[Q] PublicreportNuisance publicreportNuisanceThenLoader[Q] PublicreportNuisanceImage publicreportNuisanceImageThenLoader[Q] - PublicreportPool publicreportPoolThenLoader[Q] - PublicreportPoolImage publicreportPoolImageThenLoader[Q] PublicreportSubscribeEmail publicreportSubscribeEmailThenLoader[Q] PublicreportSubscribePhone publicreportSubscribePhoneThenLoader[Q] + PublicreportWater publicreportWaterThenLoader[Q] + PublicreportWaterImage publicreportWaterImageThenLoader[Q] Resident residentThenLoader[Q] ReviewTask reviewTaskThenLoader[Q] ReviewTaskPool reviewTaskPoolThenLoader[Q] @@ -367,15 +367,15 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { PublicreportImage: buildPublicreportImageThenLoader[Q](), PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](), PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisanceThenLoader[Q](), - PublicreportNotifyEmailPool: buildPublicreportNotifyEmailPoolThenLoader[Q](), + PublicreportNotifyEmailWater: buildPublicreportNotifyEmailWaterThenLoader[Q](), PublicreportNotifyPhoneNuisance: buildPublicreportNotifyPhoneNuisanceThenLoader[Q](), - PublicreportNotifyPhonePool: buildPublicreportNotifyPhonePoolThenLoader[Q](), + PublicreportNotifyPhoneWater: buildPublicreportNotifyPhoneWaterThenLoader[Q](), PublicreportNuisance: buildPublicreportNuisanceThenLoader[Q](), PublicreportNuisanceImage: buildPublicreportNuisanceImageThenLoader[Q](), - PublicreportPool: buildPublicreportPoolThenLoader[Q](), - PublicreportPoolImage: buildPublicreportPoolImageThenLoader[Q](), PublicreportSubscribeEmail: buildPublicreportSubscribeEmailThenLoader[Q](), PublicreportSubscribePhone: buildPublicreportSubscribePhoneThenLoader[Q](), + PublicreportWater: buildPublicreportWaterThenLoader[Q](), + PublicreportWaterImage: buildPublicreportWaterImageThenLoader[Q](), Resident: buildResidentThenLoader[Q](), ReviewTask: buildReviewTaskThenLoader[Q](), ReviewTaskPool: buildReviewTaskPoolThenLoader[Q](), diff --git a/db/models/bob_where.bob.go b/db/models/bob_where.bob.go index 7b8ea230..c9bc9789 100644 --- a/db/models/bob_where.bob.go +++ b/db/models/bob_where.bob.go @@ -91,16 +91,16 @@ func Where[Q psql.Filterable]() struct { PublicreportImages publicreportImageWhere[Q] PublicreportImageExifs publicreportImageExifWhere[Q] PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q] - PublicreportNotifyEmailPools publicreportNotifyEmailPoolWhere[Q] + PublicreportNotifyEmailWaters publicreportNotifyEmailWaterWhere[Q] PublicreportNotifyPhoneNuisances publicreportNotifyPhoneNuisanceWhere[Q] - PublicreportNotifyPhonePools publicreportNotifyPhonePoolWhere[Q] + PublicreportNotifyPhoneWaters publicreportNotifyPhoneWaterWhere[Q] PublicreportNuisances publicreportNuisanceWhere[Q] PublicreportNuisanceImages publicreportNuisanceImageWhere[Q] - PublicreportPools publicreportPoolWhere[Q] - PublicreportPoolImages publicreportPoolImageWhere[Q] PublicreportReportLocations publicreportReportLocationWhere[Q] PublicreportSubscribeEmails publicreportSubscribeEmailWhere[Q] PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q] + PublicreportWaters publicreportWaterWhere[Q] + PublicreportWaterImages publicreportWaterImageWhere[Q] RasterColumns rasterColumnWhere[Q] RasterOverviews rasterOverviewWhere[Q] Residents residentWhere[Q] @@ -188,16 +188,16 @@ func Where[Q psql.Filterable]() struct { PublicreportImages publicreportImageWhere[Q] PublicreportImageExifs publicreportImageExifWhere[Q] PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q] - PublicreportNotifyEmailPools publicreportNotifyEmailPoolWhere[Q] + PublicreportNotifyEmailWaters publicreportNotifyEmailWaterWhere[Q] PublicreportNotifyPhoneNuisances publicreportNotifyPhoneNuisanceWhere[Q] - PublicreportNotifyPhonePools publicreportNotifyPhonePoolWhere[Q] + PublicreportNotifyPhoneWaters publicreportNotifyPhoneWaterWhere[Q] PublicreportNuisances publicreportNuisanceWhere[Q] PublicreportNuisanceImages publicreportNuisanceImageWhere[Q] - PublicreportPools publicreportPoolWhere[Q] - PublicreportPoolImages publicreportPoolImageWhere[Q] PublicreportReportLocations publicreportReportLocationWhere[Q] PublicreportSubscribeEmails publicreportSubscribeEmailWhere[Q] PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q] + PublicreportWaters publicreportWaterWhere[Q] + PublicreportWaterImages publicreportWaterImageWhere[Q] RasterColumns rasterColumnWhere[Q] RasterOverviews rasterOverviewWhere[Q] Residents residentWhere[Q] @@ -284,16 +284,16 @@ func Where[Q psql.Filterable]() struct { PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns), PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns), PublicreportNotifyEmailNuisances: buildPublicreportNotifyEmailNuisanceWhere[Q](PublicreportNotifyEmailNuisances.Columns), - PublicreportNotifyEmailPools: buildPublicreportNotifyEmailPoolWhere[Q](PublicreportNotifyEmailPools.Columns), + PublicreportNotifyEmailWaters: buildPublicreportNotifyEmailWaterWhere[Q](PublicreportNotifyEmailWaters.Columns), PublicreportNotifyPhoneNuisances: buildPublicreportNotifyPhoneNuisanceWhere[Q](PublicreportNotifyPhoneNuisances.Columns), - PublicreportNotifyPhonePools: buildPublicreportNotifyPhonePoolWhere[Q](PublicreportNotifyPhonePools.Columns), + PublicreportNotifyPhoneWaters: buildPublicreportNotifyPhoneWaterWhere[Q](PublicreportNotifyPhoneWaters.Columns), PublicreportNuisances: buildPublicreportNuisanceWhere[Q](PublicreportNuisances.Columns), PublicreportNuisanceImages: buildPublicreportNuisanceImageWhere[Q](PublicreportNuisanceImages.Columns), - PublicreportPools: buildPublicreportPoolWhere[Q](PublicreportPools.Columns), - PublicreportPoolImages: buildPublicreportPoolImageWhere[Q](PublicreportPoolImages.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), RasterColumns: buildRasterColumnWhere[Q](RasterColumns.Columns), RasterOverviews: buildRasterOverviewWhere[Q](RasterOverviews.Columns), Residents: buildResidentWhere[Q](Residents.Columns), diff --git a/db/models/comms.email_contact.bob.go b/db/models/comms.email_contact.bob.go index 44c76462..8a17203f 100644 --- a/db/models/comms.email_contact.bob.go +++ b/db/models/comms.email_contact.bob.go @@ -46,7 +46,7 @@ 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 - EmailAddressNotifyEmailPools PublicreportNotifyEmailPoolSlice // publicreport.notify_email_pool.notify_email_pool_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 } @@ -495,14 +495,14 @@ func (os CommsEmailContactSlice) EmailAddressNotifyEmailNuisances(mods ...bob.Mo )...) } -// EmailAddressNotifyEmailPools starts a query for related objects on publicreport.notify_email_pool -func (o *CommsEmailContact) EmailAddressNotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery { - return PublicreportNotifyEmailPools.Query(append(mods, - sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(o.Address))), +// 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))), )...) } -func (os CommsEmailContactSlice) EmailAddressNotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery { +func (os CommsEmailContactSlice) EmailAddressNotifyEmailWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWatersQuery { pkAddress := make(pgtypes.Array[string], 0, len(os)) for _, o := range os { if o == nil { @@ -514,8 +514,8 @@ func (os CommsEmailContactSlice) EmailAddressNotifyEmailPools(mods ...bob.Mod[*d psql.F("unnest", psql.Cast(psql.Arg(pkAddress), "text[]")), )) - return PublicreportNotifyEmailPools.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyEmailPools.Columns.EmailAddress).OP("IN", PKArgExpr)), + return PublicreportNotifyEmailWaters.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyEmailWaters.Columns.EmailAddress).OP("IN", PKArgExpr)), )...) } @@ -744,66 +744,66 @@ func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailNuisan return nil } -func insertCommsEmailContactEmailAddressNotifyEmailPools0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailPools1 []*PublicreportNotifyEmailPoolSetter, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailPoolSlice, error) { - for i := range publicreportNotifyEmailPools1 { - publicreportNotifyEmailPools1[i].EmailAddress = omit.From(commsEmailContact0.Address) +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) } - ret, err := PublicreportNotifyEmailPools.Insert(bob.ToMods(publicreportNotifyEmailPools1...)).All(ctx, exec) + ret, err := PublicreportNotifyEmailWaters.Insert(bob.ToMods(publicreportNotifyEmailWaters1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailPools0: %w", err) + return ret, fmt.Errorf("insertCommsEmailContactEmailAddressNotifyEmailWaters0: %w", err) } return ret, nil } -func attachCommsEmailContactEmailAddressNotifyEmailPools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPools1 PublicreportNotifyEmailPoolSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailPoolSlice, error) { - setter := &PublicreportNotifyEmailPoolSetter{ +func attachCommsEmailContactEmailAddressNotifyEmailWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaters1 PublicreportNotifyEmailWaterSlice, commsEmailContact0 *CommsEmailContact) (PublicreportNotifyEmailWaterSlice, error) { + setter := &PublicreportNotifyEmailWaterSetter{ EmailAddress: omit.From(commsEmailContact0.Address), } - err := publicreportNotifyEmailPools1.UpdateAll(ctx, exec, *setter) + err := publicreportNotifyEmailWaters1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailPools0: %w", err) + return nil, fmt.Errorf("attachCommsEmailContactEmailAddressNotifyEmailWaters0: %w", err) } - return publicreportNotifyEmailPools1, nil + return publicreportNotifyEmailWaters1, nil } -func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPoolSetter) error { +func (commsEmailContact0 *CommsEmailContact) InsertEmailAddressNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterSetter) error { if len(related) == 0 { return nil } var err error - publicreportNotifyEmailPools1, err := insertCommsEmailContactEmailAddressNotifyEmailPools0(ctx, exec, related, commsEmailContact0) + publicreportNotifyEmailWaters1, err := insertCommsEmailContactEmailAddressNotifyEmailWaters0(ctx, exec, related, commsEmailContact0) if err != nil { return err } - commsEmailContact0.R.EmailAddressNotifyEmailPools = append(commsEmailContact0.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPools1...) + commsEmailContact0.R.EmailAddressNotifyEmailWaters = append(commsEmailContact0.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWaters1...) - for _, rel := range publicreportNotifyEmailPools1 { + for _, rel := range publicreportNotifyEmailWaters1 { rel.R.EmailAddressEmailContact = commsEmailContact0 } return nil } -func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPool) error { +func (commsEmailContact0 *CommsEmailContact) AttachEmailAddressNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWater) error { if len(related) == 0 { return nil } var err error - publicreportNotifyEmailPools1 := PublicreportNotifyEmailPoolSlice(related) + publicreportNotifyEmailWaters1 := PublicreportNotifyEmailWaterSlice(related) - _, err = attachCommsEmailContactEmailAddressNotifyEmailPools0(ctx, exec, len(related), publicreportNotifyEmailPools1, commsEmailContact0) + _, err = attachCommsEmailContactEmailAddressNotifyEmailWaters0(ctx, exec, len(related), publicreportNotifyEmailWaters1, commsEmailContact0) if err != nil { return err } - commsEmailContact0.R.EmailAddressNotifyEmailPools = append(commsEmailContact0.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPools1...) + commsEmailContact0.R.EmailAddressNotifyEmailWaters = append(commsEmailContact0.R.EmailAddressNotifyEmailWaters, publicreportNotifyEmailWaters1...) for _, rel := range related { rel.R.EmailAddressEmailContact = commsEmailContact0 @@ -948,13 +948,13 @@ func (o *CommsEmailContact) Preload(name string, retrieved any) error { } } return nil - case "EmailAddressNotifyEmailPools": - rels, ok := retrieved.(PublicreportNotifyEmailPoolSlice) + case "EmailAddressNotifyEmailWaters": + rels, ok := retrieved.(PublicreportNotifyEmailWaterSlice) if !ok { return fmt.Errorf("commsEmailContact cannot load %T as %q", retrieved, name) } - o.R.EmailAddressNotifyEmailPools = rels + o.R.EmailAddressNotifyEmailWaters = rels for _, rel := range rels { if rel != nil { @@ -991,7 +991,7 @@ 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] - EmailAddressNotifyEmailPools 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] } @@ -1005,8 +1005,8 @@ func buildCommsEmailContactThenLoader[Q orm.Loadable]() commsEmailContactThenLoa type EmailAddressNotifyEmailNuisancesLoadInterface interface { LoadEmailAddressNotifyEmailNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type EmailAddressNotifyEmailPoolsLoadInterface interface { - LoadEmailAddressNotifyEmailPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type EmailAddressNotifyEmailWatersLoadInterface interface { + LoadEmailAddressNotifyEmailWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } type EmailAddressSubscribeEmailsLoadInterface interface { LoadEmailAddressSubscribeEmails(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error @@ -1031,10 +1031,10 @@ func buildCommsEmailContactThenLoader[Q orm.Loadable]() commsEmailContactThenLoa return retrieved.LoadEmailAddressNotifyEmailNuisances(ctx, exec, mods...) }, ), - EmailAddressNotifyEmailPools: thenLoadBuilder[Q]( - "EmailAddressNotifyEmailPools", - func(ctx context.Context, exec bob.Executor, retrieved EmailAddressNotifyEmailPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadEmailAddressNotifyEmailPools(ctx, exec, mods...) + 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...) }, ), EmailAddressSubscribeEmails: thenLoadBuilder[Q]( @@ -1249,16 +1249,16 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailNuisances(ctx contex return nil } -// LoadEmailAddressNotifyEmailPools loads the commsEmailContact's EmailAddressNotifyEmailPools into the .R struct -func (o *CommsEmailContact) LoadEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if o == nil { return nil } // Reset the relationship - o.R.EmailAddressNotifyEmailPools = nil + o.R.EmailAddressNotifyEmailWaters = nil - related, err := o.EmailAddressNotifyEmailPools(mods...).All(ctx, exec) + related, err := o.EmailAddressNotifyEmailWaters(mods...).All(ctx, exec) if err != nil { return err } @@ -1267,17 +1267,17 @@ func (o *CommsEmailContact) LoadEmailAddressNotifyEmailPools(ctx context.Context rel.R.EmailAddressEmailContact = o } - o.R.EmailAddressNotifyEmailPools = related + o.R.EmailAddressNotifyEmailWaters = related return nil } -// LoadEmailAddressNotifyEmailPools loads the commsEmailContact's EmailAddressNotifyEmailPools into the .R struct -func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if len(os) == 0 { return nil } - publicreportNotifyEmailPools, err := os.EmailAddressNotifyEmailPools(mods...).All(ctx, exec) + publicreportNotifyEmailWaters, err := os.EmailAddressNotifyEmailWaters(mods...).All(ctx, exec) if err != nil { return err } @@ -1287,7 +1287,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailPools(ctx context.Co continue } - o.R.EmailAddressNotifyEmailPools = nil + o.R.EmailAddressNotifyEmailWaters = nil } for _, o := range os { @@ -1295,7 +1295,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailPools(ctx context.Co continue } - for _, rel := range publicreportNotifyEmailPools { + for _, rel := range publicreportNotifyEmailWaters { if !(o.Address == rel.EmailAddress) { continue @@ -1303,7 +1303,7 @@ func (os CommsEmailContactSlice) LoadEmailAddressNotifyEmailPools(ctx context.Co rel.R.EmailAddressEmailContact = o - o.R.EmailAddressNotifyEmailPools = append(o.R.EmailAddressNotifyEmailPools, rel) + o.R.EmailAddressNotifyEmailWaters = append(o.R.EmailAddressNotifyEmailWaters, rel) } } diff --git a/db/models/comms.phone.bob.go b/db/models/comms.phone.bob.go index 073f4f9c..9f0aef7b 100644 --- a/db/models/comms.phone.bob.go +++ b/db/models/comms.phone.bob.go @@ -51,7 +51,7 @@ type commsPhoneR struct { 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 - PhoneE164NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_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 } @@ -575,14 +575,14 @@ func (os CommsPhoneSlice) PhoneE164NotifyPhoneNuisances(mods ...bob.Mod[*dialect )...) } -// PhoneE164NotifyPhonePools starts a query for related objects on publicreport.notify_phone_pool -func (o *CommsPhone) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery { - return PublicreportNotifyPhonePools.Query(append(mods, - sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(o.E164))), +// 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))), )...) } -func (os CommsPhoneSlice) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery { +func (os CommsPhoneSlice) PhoneE164NotifyPhoneWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhoneWatersQuery { pkE164 := make(pgtypes.Array[string], 0, len(os)) for _, o := range os { if o == nil { @@ -594,8 +594,8 @@ func (os CommsPhoneSlice) PhoneE164NotifyPhonePools(mods ...bob.Mod[*dialect.Sel psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")), )) - return PublicreportNotifyPhonePools.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyPhonePools.Columns.PhoneE164).OP("IN", PKArgExpr)), + return PublicreportNotifyPhoneWaters.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyPhoneWaters.Columns.PhoneE164).OP("IN", PKArgExpr)), )...) } @@ -1120,66 +1120,66 @@ func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneNuisances(ctx context.C return nil } -func insertCommsPhonePhoneE164NotifyPhonePools0(ctx context.Context, exec bob.Executor, publicreportNotifyPhonePools1 []*PublicreportNotifyPhonePoolSetter, commsPhone0 *CommsPhone) (PublicreportNotifyPhonePoolSlice, error) { - for i := range publicreportNotifyPhonePools1 { - publicreportNotifyPhonePools1[i].PhoneE164 = omit.From(commsPhone0.E164) +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) } - ret, err := PublicreportNotifyPhonePools.Insert(bob.ToMods(publicreportNotifyPhonePools1...)).All(ctx, exec) + ret, err := PublicreportNotifyPhoneWaters.Insert(bob.ToMods(publicreportNotifyPhoneWaters1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhonePools0: %w", err) + return ret, fmt.Errorf("insertCommsPhonePhoneE164NotifyPhoneWaters0: %w", err) } return ret, nil } -func attachCommsPhonePhoneE164NotifyPhonePools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePools1 PublicreportNotifyPhonePoolSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhonePoolSlice, error) { - setter := &PublicreportNotifyPhonePoolSetter{ +func attachCommsPhonePhoneE164NotifyPhoneWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaters1 PublicreportNotifyPhoneWaterSlice, commsPhone0 *CommsPhone) (PublicreportNotifyPhoneWaterSlice, error) { + setter := &PublicreportNotifyPhoneWaterSetter{ PhoneE164: omit.From(commsPhone0.E164), } - err := publicreportNotifyPhonePools1.UpdateAll(ctx, exec, *setter) + err := publicreportNotifyPhoneWaters1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhonePools0: %w", err) + return nil, fmt.Errorf("attachCommsPhonePhoneE164NotifyPhoneWaters0: %w", err) } - return publicreportNotifyPhonePools1, nil + return publicreportNotifyPhoneWaters1, nil } -func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePoolSetter) error { +func (commsPhone0 *CommsPhone) InsertPhoneE164NotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterSetter) error { if len(related) == 0 { return nil } var err error - publicreportNotifyPhonePools1, err := insertCommsPhonePhoneE164NotifyPhonePools0(ctx, exec, related, commsPhone0) + publicreportNotifyPhoneWaters1, err := insertCommsPhonePhoneE164NotifyPhoneWaters0(ctx, exec, related, commsPhone0) if err != nil { return err } - commsPhone0.R.PhoneE164NotifyPhonePools = append(commsPhone0.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePools1...) + commsPhone0.R.PhoneE164NotifyPhoneWaters = append(commsPhone0.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWaters1...) - for _, rel := range publicreportNotifyPhonePools1 { + for _, rel := range publicreportNotifyPhoneWaters1 { rel.R.PhoneE164Phone = commsPhone0 } return nil } -func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePool) error { +func (commsPhone0 *CommsPhone) AttachPhoneE164NotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWater) error { if len(related) == 0 { return nil } var err error - publicreportNotifyPhonePools1 := PublicreportNotifyPhonePoolSlice(related) + publicreportNotifyPhoneWaters1 := PublicreportNotifyPhoneWaterSlice(related) - _, err = attachCommsPhonePhoneE164NotifyPhonePools0(ctx, exec, len(related), publicreportNotifyPhonePools1, commsPhone0) + _, err = attachCommsPhonePhoneE164NotifyPhoneWaters0(ctx, exec, len(related), publicreportNotifyPhoneWaters1, commsPhone0) if err != nil { return err } - commsPhone0.R.PhoneE164NotifyPhonePools = append(commsPhone0.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePools1...) + commsPhone0.R.PhoneE164NotifyPhoneWaters = append(commsPhone0.R.PhoneE164NotifyPhoneWaters, publicreportNotifyPhoneWaters1...) for _, rel := range related { rel.R.PhoneE164Phone = commsPhone0 @@ -1446,13 +1446,13 @@ func (o *CommsPhone) Preload(name string, retrieved any) error { } } return nil - case "PhoneE164NotifyPhonePools": - rels, ok := retrieved.(PublicreportNotifyPhonePoolSlice) + case "PhoneE164NotifyPhoneWaters": + rels, ok := retrieved.(PublicreportNotifyPhoneWaterSlice) if !ok { return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name) } - o.R.PhoneE164NotifyPhonePools = rels + o.R.PhoneE164NotifyPhoneWaters = rels for _, rel := range rels { if rel != nil { @@ -1507,7 +1507,7 @@ type commsPhoneThenLoader[Q orm.Loadable] struct { 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] - PhoneE164NotifyPhonePools 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] } @@ -1534,8 +1534,8 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] { type PhoneE164NotifyPhoneNuisancesLoadInterface interface { LoadPhoneE164NotifyPhoneNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type PhoneE164NotifyPhonePoolsLoadInterface interface { - LoadPhoneE164NotifyPhonePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type PhoneE164NotifyPhoneWatersLoadInterface interface { + LoadPhoneE164NotifyPhoneWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } type PhoneE164SubscribePhonesLoadInterface interface { LoadPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error @@ -1587,10 +1587,10 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] { return retrieved.LoadPhoneE164NotifyPhoneNuisances(ctx, exec, mods...) }, ), - PhoneE164NotifyPhonePools: thenLoadBuilder[Q]( - "PhoneE164NotifyPhonePools", - func(ctx context.Context, exec bob.Executor, retrieved PhoneE164NotifyPhonePoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPhoneE164NotifyPhonePools(ctx, exec, mods...) + 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...) }, ), PhoneE164SubscribePhones: thenLoadBuilder[Q]( @@ -2061,16 +2061,16 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhoneNuisances(ctx context.Context, return nil } -// LoadPhoneE164NotifyPhonePools loads the commsPhone's PhoneE164NotifyPhonePools into the .R struct -func (o *CommsPhone) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if o == nil { return nil } // Reset the relationship - o.R.PhoneE164NotifyPhonePools = nil + o.R.PhoneE164NotifyPhoneWaters = nil - related, err := o.PhoneE164NotifyPhonePools(mods...).All(ctx, exec) + related, err := o.PhoneE164NotifyPhoneWaters(mods...).All(ctx, exec) if err != nil { return err } @@ -2079,17 +2079,17 @@ func (o *CommsPhone) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob rel.R.PhoneE164Phone = o } - o.R.PhoneE164NotifyPhonePools = related + o.R.PhoneE164NotifyPhoneWaters = related return nil } -// LoadPhoneE164NotifyPhonePools loads the commsPhone's PhoneE164NotifyPhonePools into the .R struct -func (os CommsPhoneSlice) LoadPhoneE164NotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if len(os) == 0 { return nil } - publicreportNotifyPhonePools, err := os.PhoneE164NotifyPhonePools(mods...).All(ctx, exec) + publicreportNotifyPhoneWaters, err := os.PhoneE164NotifyPhoneWaters(mods...).All(ctx, exec) if err != nil { return err } @@ -2099,7 +2099,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhonePools(ctx context.Context, exe continue } - o.R.PhoneE164NotifyPhonePools = nil + o.R.PhoneE164NotifyPhoneWaters = nil } for _, o := range os { @@ -2107,7 +2107,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhonePools(ctx context.Context, exe continue } - for _, rel := range publicreportNotifyPhonePools { + for _, rel := range publicreportNotifyPhoneWaters { if !(o.E164 == rel.PhoneE164) { continue @@ -2115,7 +2115,7 @@ func (os CommsPhoneSlice) LoadPhoneE164NotifyPhonePools(ctx context.Context, exe rel.R.PhoneE164Phone = o - o.R.PhoneE164NotifyPhonePools = append(o.R.PhoneE164NotifyPhonePools, rel) + o.R.PhoneE164NotifyPhoneWaters = append(o.R.PhoneE164NotifyPhoneWaters, rel) } } diff --git a/db/models/organization.bob.go b/db/models/organization.bob.go index ab499262..2526d152 100644 --- a/db/models/organization.bob.go +++ b/db/models/organization.bob.go @@ -119,7 +119,7 @@ type organizationR struct { 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 - PublicreportPool PublicreportPoolSlice // publicreport.pool.pool_organization_id_fkey + Waters PublicreportWaterSlice // publicreport.water.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 @@ -1973,14 +1973,14 @@ func (os OrganizationSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) Pub )...) } -// PublicreportPool starts a query for related objects on publicreport.pool -func (o *Organization) PublicreportPool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - return PublicreportPools.Query(append(mods, - sm.Where(PublicreportPools.Columns.OrganizationID.EQ(psql.Arg(o.ID))), +// 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))), )...) } -func (os OrganizationSlice) PublicreportPool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { +func (os OrganizationSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery { pkID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { @@ -1992,8 +1992,8 @@ func (os OrganizationSlice) PublicreportPool(mods ...bob.Mod[*dialect.SelectQuer psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), )) - return PublicreportPools.Query(append(mods, - sm.Where(psql.Group(PublicreportPools.Columns.OrganizationID).OP("IN", PKArgExpr)), + return PublicreportWaters.Query(append(mods, + sm.Where(psql.Group(PublicreportWaters.Columns.OrganizationID).OP("IN", PKArgExpr)), )...) } @@ -4927,66 +4927,66 @@ func (organization0 *Organization) AttachNuisances(ctx context.Context, exec bob return nil } -func insertOrganizationPublicreportPool0(ctx context.Context, exec bob.Executor, publicreportPools1 []*PublicreportPoolSetter, organization0 *Organization) (PublicreportPoolSlice, error) { - for i := range publicreportPools1 { - publicreportPools1[i].OrganizationID = omitnull.From(organization0.ID) +func insertOrganizationWaters0(ctx context.Context, exec bob.Executor, publicreportWaters1 []*PublicreportWaterSetter, organization0 *Organization) (PublicreportWaterSlice, error) { + for i := range publicreportWaters1 { + publicreportWaters1[i].OrganizationID = omitnull.From(organization0.ID) } - ret, err := PublicreportPools.Insert(bob.ToMods(publicreportPools1...)).All(ctx, exec) + ret, err := PublicreportWaters.Insert(bob.ToMods(publicreportWaters1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertOrganizationPublicreportPool0: %w", err) + return ret, fmt.Errorf("insertOrganizationWaters0: %w", err) } return ret, nil } -func attachOrganizationPublicreportPool0(ctx context.Context, exec bob.Executor, count int, publicreportPools1 PublicreportPoolSlice, organization0 *Organization) (PublicreportPoolSlice, error) { - setter := &PublicreportPoolSetter{ +func attachOrganizationWaters0(ctx context.Context, exec bob.Executor, count int, publicreportWaters1 PublicreportWaterSlice, organization0 *Organization) (PublicreportWaterSlice, error) { + setter := &PublicreportWaterSetter{ OrganizationID: omitnull.From(organization0.ID), } - err := publicreportPools1.UpdateAll(ctx, exec, *setter) + err := publicreportWaters1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachOrganizationPublicreportPool0: %w", err) + return nil, fmt.Errorf("attachOrganizationWaters0: %w", err) } - return publicreportPools1, nil + return publicreportWaters1, nil } -func (organization0 *Organization) InsertPublicreportPool(ctx context.Context, exec bob.Executor, related ...*PublicreportPoolSetter) error { +func (organization0 *Organization) InsertWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error { if len(related) == 0 { return nil } var err error - publicreportPools1, err := insertOrganizationPublicreportPool0(ctx, exec, related, organization0) + publicreportWaters1, err := insertOrganizationWaters0(ctx, exec, related, organization0) if err != nil { return err } - organization0.R.PublicreportPool = append(organization0.R.PublicreportPool, publicreportPools1...) + organization0.R.Waters = append(organization0.R.Waters, publicreportWaters1...) - for _, rel := range publicreportPools1 { + for _, rel := range publicreportWaters1 { rel.R.Organization = organization0 } return nil } -func (organization0 *Organization) AttachPublicreportPool(ctx context.Context, exec bob.Executor, related ...*PublicreportPool) error { +func (organization0 *Organization) AttachWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error { if len(related) == 0 { return nil } var err error - publicreportPools1 := PublicreportPoolSlice(related) + publicreportWaters1 := PublicreportWaterSlice(related) - _, err = attachOrganizationPublicreportPool0(ctx, exec, len(related), publicreportPools1, organization0) + _, err = attachOrganizationWaters0(ctx, exec, len(related), publicreportWaters1, organization0) if err != nil { return err } - organization0.R.PublicreportPool = append(organization0.R.PublicreportPool, publicreportPools1...) + organization0.R.Waters = append(organization0.R.Waters, publicreportWaters1...) for _, rel := range related { rel.R.Organization = organization0 @@ -5879,13 +5879,13 @@ func (o *Organization) Preload(name string, retrieved any) error { } } return nil - case "PublicreportPool": - rels, ok := retrieved.(PublicreportPoolSlice) + case "Waters": + rels, ok := retrieved.(PublicreportWaterSlice) if !ok { return fmt.Errorf("organization cannot load %T as %q", retrieved, name) } - o.R.PublicreportPool = rels + o.R.Waters = rels for _, rel := range rels { if rel != nil { @@ -6034,7 +6034,7 @@ type organizationThenLoader[Q orm.Loadable] struct { 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] - PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Waters 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] @@ -6170,8 +6170,8 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] { type NuisancesLoadInterface interface { LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type PublicreportPoolLoadInterface interface { - LoadPublicreportPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type WatersLoadInterface interface { + LoadWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } type ReviewTasksLoadInterface interface { LoadReviewTasks(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error @@ -6442,10 +6442,10 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] { return retrieved.LoadNuisances(ctx, exec, mods...) }, ), - PublicreportPool: thenLoadBuilder[Q]( - "PublicreportPool", - func(ctx context.Context, exec bob.Executor, retrieved PublicreportPoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPublicreportPool(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...) }, ), ReviewTasks: thenLoadBuilder[Q]( @@ -9117,16 +9117,16 @@ func (os OrganizationSlice) LoadNuisances(ctx context.Context, exec bob.Executor return nil } -// LoadPublicreportPool loads the organization's PublicreportPool into the .R struct -func (o *Organization) LoadPublicreportPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if o == nil { return nil } // Reset the relationship - o.R.PublicreportPool = nil + o.R.Waters = nil - related, err := o.PublicreportPool(mods...).All(ctx, exec) + related, err := o.Waters(mods...).All(ctx, exec) if err != nil { return err } @@ -9135,17 +9135,17 @@ func (o *Organization) LoadPublicreportPool(ctx context.Context, exec bob.Execut rel.R.Organization = o } - o.R.PublicreportPool = related + o.R.Waters = related return nil } -// LoadPublicreportPool loads the organization's PublicreportPool into the .R struct -func (os OrganizationSlice) LoadPublicreportPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if len(os) == 0 { return nil } - publicreportPools, err := os.PublicreportPool(mods...).All(ctx, exec) + publicreportWaters, err := os.Waters(mods...).All(ctx, exec) if err != nil { return err } @@ -9155,7 +9155,7 @@ func (os OrganizationSlice) LoadPublicreportPool(ctx context.Context, exec bob.E continue } - o.R.PublicreportPool = nil + o.R.Waters = nil } for _, o := range os { @@ -9163,7 +9163,7 @@ func (os OrganizationSlice) LoadPublicreportPool(ctx context.Context, exec bob.E continue } - for _, rel := range publicreportPools { + for _, rel := range publicreportWaters { if !rel.OrganizationID.IsValue() { continue @@ -9174,7 +9174,7 @@ func (os OrganizationSlice) LoadPublicreportPool(ctx context.Context, exec bob.E rel.R.Organization = o - o.R.PublicreportPool = append(o.R.PublicreportPool, rel) + o.R.Waters = append(o.R.Waters, rel) } } diff --git a/db/models/publicreport.image.bob.go b/db/models/publicreport.image.bob.go index 0aab0010..ad2a1022 100644 --- a/db/models/publicreport.image.bob.go +++ b/db/models/publicreport.image.bob.go @@ -54,7 +54,7 @@ type PublicreportImagesQuery = *psql.ViewQuery[*PublicreportImage, PublicreportI 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 - Pools PublicreportPoolSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey + Waters PublicreportWaterSlice // publicreport.water_image.pool_image_image_id_fkeypublicreport.water_image.pool_image_pool_id_fkey } func buildPublicreportImageColumns(alias string) publicreportImageColumns { @@ -588,16 +588,16 @@ func (os PublicreportImageSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery] )...) } -// Pools starts a query for related objects on publicreport.pool -func (o *PublicreportImage) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - return PublicreportPools.Query(append(mods, - sm.InnerJoin(PublicreportPoolImages.NameAs()).On( - PublicreportPools.Columns.ID.EQ(PublicreportPoolImages.Columns.PoolID)), - sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(o.ID))), +// 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))), )...) } -func (os PublicreportImageSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { +func (os PublicreportImageSlice) Waters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery { pkID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { @@ -609,11 +609,11 @@ func (os PublicreportImageSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) Pu psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), )) - return PublicreportPools.Query(append(mods, - sm.InnerJoin(PublicreportPoolImages.NameAs()).On( - PublicreportPools.Columns.ID.EQ(PublicreportPoolImages.Columns.PoolID), + return PublicreportWaters.Query(append(mods, + sm.InnerJoin(PublicreportWaterImages.NameAs()).On( + PublicreportWaters.Columns.ID.EQ(PublicreportWaterImages.Columns.WaterID), ), - sm.Where(psql.Group(PublicreportPoolImages.Columns.ImageID).OP("IN", PKArgExpr)), + sm.Where(psql.Group(PublicreportWaterImages.Columns.ImageID).OP("IN", PKArgExpr)), )...) } @@ -750,63 +750,63 @@ func (publicreportImage0 *PublicreportImage) AttachNuisances(ctx context.Context return nil } -func attachPublicreportImagePools0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportPools2 PublicreportPoolSlice) (PublicreportPoolImageSlice, error) { - setters := make([]*PublicreportPoolImageSetter, count) +func attachPublicreportImageWaters0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportWaters2 PublicreportWaterSlice) (PublicreportWaterImageSlice, error) { + setters := make([]*PublicreportWaterImageSetter, count) for i := range count { - setters[i] = &PublicreportPoolImageSetter{ + setters[i] = &PublicreportWaterImageSetter{ ImageID: omit.From(publicreportImage0.ID), - PoolID: omit.From(publicreportPools2[i].ID), + WaterID: omit.From(publicreportWaters2[i].ID), } } - publicreportPoolImages1, err := PublicreportPoolImages.Insert(bob.ToMods(setters...)).All(ctx, exec) + publicreportWaterImages1, err := PublicreportWaterImages.Insert(bob.ToMods(setters...)).All(ctx, exec) if err != nil { - return nil, fmt.Errorf("attachPublicreportImagePools0: %w", err) + return nil, fmt.Errorf("attachPublicreportImageWaters0: %w", err) } - return publicreportPoolImages1, nil + return publicreportWaterImages1, nil } -func (publicreportImage0 *PublicreportImage) InsertPools(ctx context.Context, exec bob.Executor, related ...*PublicreportPoolSetter) error { +func (publicreportImage0 *PublicreportImage) InsertWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error { if len(related) == 0 { return nil } var err error - inserted, err := PublicreportPools.Insert(bob.ToMods(related...)).All(ctx, exec) + inserted, err := PublicreportWaters.Insert(bob.ToMods(related...)).All(ctx, exec) if err != nil { return fmt.Errorf("inserting related objects: %w", err) } - publicreportPools2 := PublicreportPoolSlice(inserted) + publicreportWaters2 := PublicreportWaterSlice(inserted) - _, err = attachPublicreportImagePools0(ctx, exec, len(related), publicreportImage0, publicreportPools2) + _, err = attachPublicreportImageWaters0(ctx, exec, len(related), publicreportImage0, publicreportWaters2) if err != nil { return err } - publicreportImage0.R.Pools = append(publicreportImage0.R.Pools, publicreportPools2...) + publicreportImage0.R.Waters = append(publicreportImage0.R.Waters, publicreportWaters2...) - for _, rel := range publicreportPools2 { + for _, rel := range publicreportWaters2 { rel.R.Images = append(rel.R.Images, publicreportImage0) } return nil } -func (publicreportImage0 *PublicreportImage) AttachPools(ctx context.Context, exec bob.Executor, related ...*PublicreportPool) error { +func (publicreportImage0 *PublicreportImage) AttachWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error { if len(related) == 0 { return nil } var err error - publicreportPools2 := PublicreportPoolSlice(related) + publicreportWaters2 := PublicreportWaterSlice(related) - _, err = attachPublicreportImagePools0(ctx, exec, len(related), publicreportImage0, publicreportPools2) + _, err = attachPublicreportImageWaters0(ctx, exec, len(related), publicreportImage0, publicreportWaters2) if err != nil { return err } - publicreportImage0.R.Pools = append(publicreportImage0.R.Pools, publicreportPools2...) + publicreportImage0.R.Waters = append(publicreportImage0.R.Waters, publicreportWaters2...) for _, rel := range related { rel.R.Images = append(rel.R.Images, publicreportImage0) @@ -879,13 +879,13 @@ func (o *PublicreportImage) Preload(name string, retrieved any) error { } } return nil - case "Pools": - rels, ok := retrieved.(PublicreportPoolSlice) + case "Waters": + rels, ok := retrieved.(PublicreportWaterSlice) if !ok { return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name) } - o.R.Pools = rels + o.R.Waters = rels for _, rel := range rels { if rel != nil { @@ -907,7 +907,7 @@ 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] - Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Waters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildPublicreportImageThenLoader[Q orm.Loadable]() publicreportImageThenLoader[Q] { @@ -917,8 +917,8 @@ func buildPublicreportImageThenLoader[Q orm.Loadable]() publicreportImageThenLoa type NuisancesLoadInterface interface { LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type PoolsLoadInterface interface { - LoadPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + type WatersLoadInterface interface { + LoadWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } return publicreportImageThenLoader[Q]{ @@ -934,10 +934,10 @@ func buildPublicreportImageThenLoader[Q orm.Loadable]() publicreportImageThenLoa return retrieved.LoadNuisances(ctx, exec, mods...) }, ), - Pools: thenLoadBuilder[Q]( - "Pools", - func(ctx context.Context, exec bob.Executor, retrieved PoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPools(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...) }, ), } @@ -1085,16 +1085,16 @@ func (os PublicreportImageSlice) LoadNuisances(ctx context.Context, exec bob.Exe return nil } -// LoadPools loads the publicreportImage's Pools into the .R struct -func (o *PublicreportImage) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if o == nil { return nil } // Reset the relationship - o.R.Pools = nil + o.R.Waters = nil - related, err := o.Pools(mods...).All(ctx, exec) + related, err := o.Waters(mods...).All(ctx, exec) if err != nil { return err } @@ -1103,12 +1103,12 @@ func (o *PublicreportImage) LoadPools(ctx context.Context, exec bob.Executor, mo rel.R.Images = PublicreportImageSlice{o} } - o.R.Pools = related + o.R.Waters = related return nil } -// LoadPools loads the publicreportImage's Pools into the .R struct -func (os PublicreportImageSlice) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if len(os) == 0 { return nil } @@ -1120,17 +1120,17 @@ func (os PublicreportImageSlice) LoadPools(ctx context.Context, exec bob.Executo } if len(sq.SelectList.Columns) == 0 { - mods = append(mods, sm.Columns(PublicreportPools.Columns)) + mods = append(mods, sm.Columns(PublicreportWaters.Columns)) } - q := os.Pools(append( + q := os.Waters(append( mods, - sm.Columns(PublicreportPoolImages.Columns.ImageID.As("related_publicreport.image.ID")), + sm.Columns(PublicreportWaterImages.Columns.ImageID.As("related_publicreport.image.ID")), )...) IDSlice := []int32{} - mapper := scan.Mod(scan.StructMapper[*PublicreportPool](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) { + mapper := scan.Mod(scan.StructMapper[*PublicreportWater](), 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 +1142,24 @@ func (os PublicreportImageSlice) LoadPools(ctx context.Context, exec bob.Executo } }) - publicreportPools, err := bob.Allx[bob.SliceTransformer[*PublicreportPool, PublicreportPoolSlice]](ctx, exec, q, mapper) + publicreportWaters, err := bob.Allx[bob.SliceTransformer[*PublicreportWater, PublicreportWaterSlice]](ctx, exec, q, mapper) if err != nil { return err } for _, o := range os { - o.R.Pools = nil + o.R.Waters = nil } for _, o := range os { - for i, rel := range publicreportPools { + for i, rel := range publicreportWaters { if !(o.ID == IDSlice[i]) { continue } rel.R.Images = append(rel.R.Images, o) - o.R.Pools = append(o.R.Pools, rel) + o.R.Waters = append(o.R.Waters, rel) } } diff --git a/db/models/publicreport.notify_email_pool.bob.go b/db/models/publicreport.notify_email_pool.bob.go deleted file mode 100644 index 34eaba58..00000000 --- a/db/models/publicreport.notify_email_pool.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" -) - -// PublicreportNotifyEmailPool is an object representing the database table. -type PublicreportNotifyEmailPool struct { - Created time.Time `db:"created" ` - Deleted null.Val[time.Time] `db:"deleted" ` - PoolID int32 `db:"pool_id,pk" ` - EmailAddress string `db:"email_address,pk" ` - - R publicreportNotifyEmailPoolR `db:"-" ` -} - -// PublicreportNotifyEmailPoolSlice is an alias for a slice of pointers to PublicreportNotifyEmailPool. -// This should almost always be used instead of []*PublicreportNotifyEmailPool. -type PublicreportNotifyEmailPoolSlice []*PublicreportNotifyEmailPool - -// PublicreportNotifyEmailPools contains methods to work with the notify_email_pool table -var PublicreportNotifyEmailPools = psql.NewTablex[*PublicreportNotifyEmailPool, PublicreportNotifyEmailPoolSlice, *PublicreportNotifyEmailPoolSetter]("publicreport", "notify_email_pool", buildPublicreportNotifyEmailPoolColumns("publicreport.notify_email_pool")) - -// PublicreportNotifyEmailPoolsQuery is a query on the notify_email_pool table -type PublicreportNotifyEmailPoolsQuery = *psql.ViewQuery[*PublicreportNotifyEmailPool, PublicreportNotifyEmailPoolSlice] - -// publicreportNotifyEmailPoolR is where relationships are stored. -type publicreportNotifyEmailPoolR struct { - EmailAddressEmailContact *CommsEmailContact // publicreport.notify_email_pool.notify_email_pool_email_address_fkey - Pool *PublicreportPool // publicreport.notify_email_pool.notify_email_pool_pool_id_fkey -} - -func buildPublicreportNotifyEmailPoolColumns(alias string) publicreportNotifyEmailPoolColumns { - return publicreportNotifyEmailPoolColumns{ - ColumnsExpr: expr.NewColumnsExpr( - "created", "deleted", "pool_id", "email_address", - ).WithParent("publicreport.notify_email_pool"), - tableAlias: alias, - Created: psql.Quote(alias, "created"), - Deleted: psql.Quote(alias, "deleted"), - PoolID: psql.Quote(alias, "pool_id"), - EmailAddress: psql.Quote(alias, "email_address"), - } -} - -type publicreportNotifyEmailPoolColumns struct { - expr.ColumnsExpr - tableAlias string - Created psql.Expression - Deleted psql.Expression - PoolID psql.Expression - EmailAddress psql.Expression -} - -func (c publicreportNotifyEmailPoolColumns) Alias() string { - return c.tableAlias -} - -func (publicreportNotifyEmailPoolColumns) AliasedAs(alias string) publicreportNotifyEmailPoolColumns { - return buildPublicreportNotifyEmailPoolColumns(alias) -} - -// PublicreportNotifyEmailPoolSetter is used for insert/upsert/update operations -// All values are optional, and do not have to be set -// Generated columns are not included -type PublicreportNotifyEmailPoolSetter struct { - Created omit.Val[time.Time] `db:"created" ` - Deleted omitnull.Val[time.Time] `db:"deleted" ` - PoolID omit.Val[int32] `db:"pool_id,pk" ` - EmailAddress omit.Val[string] `db:"email_address,pk" ` -} - -func (s PublicreportNotifyEmailPoolSetter) SetColumns() []string { - vals := make([]string, 0, 4) - if s.Created.IsValue() { - vals = append(vals, "created") - } - if !s.Deleted.IsUnset() { - vals = append(vals, "deleted") - } - if s.PoolID.IsValue() { - vals = append(vals, "pool_id") - } - if s.EmailAddress.IsValue() { - vals = append(vals, "email_address") - } - return vals -} - -func (s PublicreportNotifyEmailPoolSetter) Overwrite(t *PublicreportNotifyEmailPool) { - if s.Created.IsValue() { - t.Created = s.Created.MustGet() - } - if !s.Deleted.IsUnset() { - t.Deleted = s.Deleted.MustGetNull() - } - if s.PoolID.IsValue() { - t.PoolID = s.PoolID.MustGet() - } - if s.EmailAddress.IsValue() { - t.EmailAddress = s.EmailAddress.MustGet() - } -} - -func (s *PublicreportNotifyEmailPoolSetter) Apply(q *dialect.InsertQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportNotifyEmailPools.BeforeInsertHooks.RunHooks(ctx, exec, s) - }) - - q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 4) - if s.Created.IsValue() { - vals[0] = psql.Arg(s.Created.MustGet()) - } else { - vals[0] = psql.Raw("DEFAULT") - } - - if !s.Deleted.IsUnset() { - vals[1] = psql.Arg(s.Deleted.MustGetNull()) - } else { - vals[1] = psql.Raw("DEFAULT") - } - - if s.PoolID.IsValue() { - vals[2] = psql.Arg(s.PoolID.MustGet()) - } else { - vals[2] = psql.Raw("DEFAULT") - } - - if s.EmailAddress.IsValue() { - vals[3] = psql.Arg(s.EmailAddress.MustGet()) - } else { - vals[3] = psql.Raw("DEFAULT") - } - - return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") - })) -} - -func (s PublicreportNotifyEmailPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return um.Set(s.Expressions()...) -} - -func (s PublicreportNotifyEmailPoolSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 4) - - if s.Created.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "created")...), - psql.Arg(s.Created), - }}) - } - - if !s.Deleted.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "deleted")...), - psql.Arg(s.Deleted), - }}) - } - - if s.PoolID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "pool_id")...), - psql.Arg(s.PoolID), - }}) - } - - if s.EmailAddress.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "email_address")...), - psql.Arg(s.EmailAddress), - }}) - } - - return exprs -} - -// FindPublicreportNotifyEmailPool retrieves a single record by primary key -// If cols is empty Find will return all columns. -func FindPublicreportNotifyEmailPool(ctx context.Context, exec bob.Executor, PoolIDPK int32, EmailAddressPK string, cols ...string) (*PublicreportNotifyEmailPool, error) { - if len(cols) == 0 { - return PublicreportNotifyEmailPools.Query( - sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))), - ).One(ctx, exec) - } - - return PublicreportNotifyEmailPools.Query( - sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))), - sm.Columns(PublicreportNotifyEmailPools.Columns.Only(cols...)), - ).One(ctx, exec) -} - -// PublicreportNotifyEmailPoolExists checks the presence of a single record by primary key -func PublicreportNotifyEmailPoolExists(ctx context.Context, exec bob.Executor, PoolIDPK int32, EmailAddressPK string) (bool, error) { - return PublicreportNotifyEmailPools.Query( - sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(EmailAddressPK))), - ).Exists(ctx, exec) -} - -// AfterQueryHook is called after PublicreportNotifyEmailPool is retrieved from the database -func (o *PublicreportNotifyEmailPool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = PublicreportNotifyEmailPools.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o}) - case bob.QueryTypeInsert: - ctx, err = PublicreportNotifyEmailPools.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o}) - case bob.QueryTypeUpdate: - ctx, err = PublicreportNotifyEmailPools.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o}) - case bob.QueryTypeDelete: - ctx, err = PublicreportNotifyEmailPools.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyEmailPoolSlice{o}) - } - - return err -} - -// primaryKeyVals returns the primary key values of the PublicreportNotifyEmailPool -func (o *PublicreportNotifyEmailPool) primaryKeyVals() bob.Expression { - return psql.ArgGroup( - o.PoolID, - o.EmailAddress, - ) -} - -func (o *PublicreportNotifyEmailPool) pkEQ() dialect.Expression { - return psql.Group(psql.Quote("publicreport.notify_email_pool", "pool_id"), psql.Quote("publicreport.notify_email_pool", "email_address")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - return o.primaryKeyVals().WriteSQL(ctx, w, d, start) - })) -} - -// Update uses an executor to update the PublicreportNotifyEmailPool -func (o *PublicreportNotifyEmailPool) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyEmailPoolSetter) error { - v, err := PublicreportNotifyEmailPools.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) - if err != nil { - return err - } - - o.R = v.R - *o = *v - - return nil -} - -// Delete deletes a single PublicreportNotifyEmailPool record with an executor -func (o *PublicreportNotifyEmailPool) Delete(ctx context.Context, exec bob.Executor) error { - _, err := PublicreportNotifyEmailPools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) - return err -} - -// Reload refreshes the PublicreportNotifyEmailPool using the executor -func (o *PublicreportNotifyEmailPool) Reload(ctx context.Context, exec bob.Executor) error { - o2, err := PublicreportNotifyEmailPools.Query( - sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(o.PoolID))), - sm.Where(PublicreportNotifyEmailPools.Columns.EmailAddress.EQ(psql.Arg(o.EmailAddress))), - ).One(ctx, exec) - if err != nil { - return err - } - o2.R = o.R - *o = *o2 - - return nil -} - -// AfterQueryHook is called after PublicreportNotifyEmailPoolSlice is retrieved from the database -func (o PublicreportNotifyEmailPoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = PublicreportNotifyEmailPools.AfterSelectHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeInsert: - ctx, err = PublicreportNotifyEmailPools.AfterInsertHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeUpdate: - ctx, err = PublicreportNotifyEmailPools.AfterUpdateHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeDelete: - ctx, err = PublicreportNotifyEmailPools.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err -} - -func (o PublicreportNotifyEmailPoolSlice) pkIN() dialect.Expression { - if len(o) == 0 { - return psql.Raw("NULL") - } - - return psql.Group(psql.Quote("publicreport.notify_email_pool", "pool_id"), psql.Quote("publicreport.notify_email_pool", "email_address")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - pkPairs := make([]bob.Expression, len(o)) - for i, row := range o { - pkPairs[i] = row.primaryKeyVals() - } - return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") - })) -} - -// copyMatchingRows finds models in the given slice that have the same primary key -// then it first copies the existing relationships from the old model to the new model -// and then replaces the old model in the slice with the new model -func (o PublicreportNotifyEmailPoolSlice) copyMatchingRows(from ...*PublicreportNotifyEmailPool) { - for i, old := range o { - for _, new := range from { - if new.PoolID != old.PoolID { - continue - } - if new.EmailAddress != old.EmailAddress { - continue - } - new.R = old.R - o[i] = new - break - } - } -} - -// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" -func (o PublicreportNotifyEmailPoolSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportNotifyEmailPools.BeforeUpdateHooks.RunHooks(ctx, exec, o) - }) - - q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { - var err error - switch retrieved := retrieved.(type) { - case *PublicreportNotifyEmailPool: - o.copyMatchingRows(retrieved) - case []*PublicreportNotifyEmailPool: - o.copyMatchingRows(retrieved...) - case PublicreportNotifyEmailPoolSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a PublicreportNotifyEmailPool or a slice of PublicreportNotifyEmailPool - // then run the AfterUpdateHooks on the slice - _, err = PublicreportNotifyEmailPools.AfterUpdateHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" -func (o PublicreportNotifyEmailPoolSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { - return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportNotifyEmailPools.BeforeDeleteHooks.RunHooks(ctx, exec, o) - }) - - q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { - var err error - switch retrieved := retrieved.(type) { - case *PublicreportNotifyEmailPool: - o.copyMatchingRows(retrieved) - case []*PublicreportNotifyEmailPool: - o.copyMatchingRows(retrieved...) - case PublicreportNotifyEmailPoolSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a PublicreportNotifyEmailPool or a slice of PublicreportNotifyEmailPool - // then run the AfterDeleteHooks on the slice - _, err = PublicreportNotifyEmailPools.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -func (o PublicreportNotifyEmailPoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyEmailPoolSetter) error { - if len(o) == 0 { - return nil - } - - _, err := PublicreportNotifyEmailPools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) - return err -} - -func (o PublicreportNotifyEmailPoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - _, err := PublicreportNotifyEmailPools.Delete(o.DeleteMod()).Exec(ctx, exec) - return err -} - -func (o PublicreportNotifyEmailPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - o2, err := PublicreportNotifyEmailPools.Query(sm.Where(o.pkIN())).All(ctx, exec) - if err != nil { - return err - } - - o.copyMatchingRows(o2...) - - return nil -} - -// EmailAddressEmailContact starts a query for related objects on comms.email_contact -func (o *PublicreportNotifyEmailPool) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery { - return CommsEmailContacts.Query(append(mods, - sm.Where(CommsEmailContacts.Columns.Address.EQ(psql.Arg(o.EmailAddress))), - )...) -} - -func (os PublicreportNotifyEmailPoolSlice) EmailAddressEmailContact(mods ...bob.Mod[*dialect.SelectQuery]) CommsEmailContactsQuery { - pkEmailAddress := make(pgtypes.Array[string], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkEmailAddress = append(pkEmailAddress, o.EmailAddress) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkEmailAddress), "text[]")), - )) - - return CommsEmailContacts.Query(append(mods, - sm.Where(psql.Group(CommsEmailContacts.Columns.Address).OP("IN", PKArgExpr)), - )...) -} - -// Pool starts a query for related objects on publicreport.pool -func (o *PublicreportNotifyEmailPool) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - return PublicreportPools.Query(append(mods, - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))), - )...) -} - -func (os PublicreportNotifyEmailPoolSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - pkPoolID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkPoolID = append(pkPoolID, o.PoolID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")), - )) - - return PublicreportPools.Query(append(mods, - sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -func attachPublicreportNotifyEmailPoolEmailAddressEmailContact0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool, commsEmailContact1 *CommsEmailContact) (*PublicreportNotifyEmailPool, error) { - setter := &PublicreportNotifyEmailPoolSetter{ - EmailAddress: omit.From(commsEmailContact1.Address), - } - - err := publicreportNotifyEmailPool0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNotifyEmailPoolEmailAddressEmailContact0: %w", err) - } - - return publicreportNotifyEmailPool0, nil -} - -func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) InsertEmailAddressEmailContact(ctx context.Context, exec bob.Executor, related *CommsEmailContactSetter) error { - var err error - - commsEmailContact1, err := CommsEmailContacts.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportNotifyEmailPoolEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailPool0, commsEmailContact1) - if err != nil { - return err - } - - publicreportNotifyEmailPool0.R.EmailAddressEmailContact = commsEmailContact1 - - commsEmailContact1.R.EmailAddressNotifyEmailPools = append(commsEmailContact1.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPool0) - - return nil -} - -func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) AttachEmailAddressEmailContact(ctx context.Context, exec bob.Executor, commsEmailContact1 *CommsEmailContact) error { - var err error - - _, err = attachPublicreportNotifyEmailPoolEmailAddressEmailContact0(ctx, exec, 1, publicreportNotifyEmailPool0, commsEmailContact1) - if err != nil { - return err - } - - publicreportNotifyEmailPool0.R.EmailAddressEmailContact = commsEmailContact1 - - commsEmailContact1.R.EmailAddressNotifyEmailPools = append(commsEmailContact1.R.EmailAddressNotifyEmailPools, publicreportNotifyEmailPool0) - - return nil -} - -func attachPublicreportNotifyEmailPoolPool0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool, publicreportPool1 *PublicreportPool) (*PublicreportNotifyEmailPool, error) { - setter := &PublicreportNotifyEmailPoolSetter{ - PoolID: omit.From(publicreportPool1.ID), - } - - err := publicreportNotifyEmailPool0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNotifyEmailPoolPool0: %w", err) - } - - return publicreportNotifyEmailPool0, nil -} - -func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error { - var err error - - publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportNotifyEmailPoolPool0(ctx, exec, 1, publicreportNotifyEmailPool0, publicreportPool1) - if err != nil { - return err - } - - publicreportNotifyEmailPool0.R.Pool = publicreportPool1 - - publicreportPool1.R.NotifyEmailPools = append(publicreportPool1.R.NotifyEmailPools, publicreportNotifyEmailPool0) - - return nil -} - -func (publicreportNotifyEmailPool0 *PublicreportNotifyEmailPool) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error { - var err error - - _, err = attachPublicreportNotifyEmailPoolPool0(ctx, exec, 1, publicreportNotifyEmailPool0, publicreportPool1) - if err != nil { - return err - } - - publicreportNotifyEmailPool0.R.Pool = publicreportPool1 - - publicreportPool1.R.NotifyEmailPools = append(publicreportPool1.R.NotifyEmailPools, publicreportNotifyEmailPool0) - - return nil -} - -type publicreportNotifyEmailPoolWhere[Q psql.Filterable] struct { - Created psql.WhereMod[Q, time.Time] - Deleted psql.WhereNullMod[Q, time.Time] - PoolID psql.WhereMod[Q, int32] - EmailAddress psql.WhereMod[Q, string] -} - -func (publicreportNotifyEmailPoolWhere[Q]) AliasedAs(alias string) publicreportNotifyEmailPoolWhere[Q] { - return buildPublicreportNotifyEmailPoolWhere[Q](buildPublicreportNotifyEmailPoolColumns(alias)) -} - -func buildPublicreportNotifyEmailPoolWhere[Q psql.Filterable](cols publicreportNotifyEmailPoolColumns) publicreportNotifyEmailPoolWhere[Q] { - return publicreportNotifyEmailPoolWhere[Q]{ - Created: psql.Where[Q, time.Time](cols.Created), - Deleted: psql.WhereNull[Q, time.Time](cols.Deleted), - PoolID: psql.Where[Q, int32](cols.PoolID), - EmailAddress: psql.Where[Q, string](cols.EmailAddress), - } -} - -func (o *PublicreportNotifyEmailPool) Preload(name string, retrieved any) error { - if o == nil { - return nil - } - - switch name { - case "EmailAddressEmailContact": - rel, ok := retrieved.(*CommsEmailContact) - if !ok { - return fmt.Errorf("publicreportNotifyEmailPool cannot load %T as %q", retrieved, name) - } - - o.R.EmailAddressEmailContact = rel - - if rel != nil { - rel.R.EmailAddressNotifyEmailPools = PublicreportNotifyEmailPoolSlice{o} - } - return nil - case "Pool": - rel, ok := retrieved.(*PublicreportPool) - if !ok { - return fmt.Errorf("publicreportNotifyEmailPool cannot load %T as %q", retrieved, name) - } - - o.R.Pool = rel - - if rel != nil { - rel.R.NotifyEmailPools = PublicreportNotifyEmailPoolSlice{o} - } - return nil - default: - return fmt.Errorf("publicreportNotifyEmailPool has no relationship %q", name) - } -} - -type publicreportNotifyEmailPoolPreloader struct { - EmailAddressEmailContact func(...psql.PreloadOption) psql.Preloader - Pool func(...psql.PreloadOption) psql.Preloader -} - -func buildPublicreportNotifyEmailPoolPreloader() publicreportNotifyEmailPoolPreloader { - return publicreportNotifyEmailPoolPreloader{ - EmailAddressEmailContact: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*CommsEmailContact, CommsEmailContactSlice](psql.PreloadRel{ - Name: "EmailAddressEmailContact", - Sides: []psql.PreloadSide{ - { - From: PublicreportNotifyEmailPools, - To: CommsEmailContacts, - FromColumns: []string{"email_address"}, - ToColumns: []string{"address"}, - }, - }, - }, CommsEmailContacts.Columns.Names(), opts...) - }, - Pool: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{ - Name: "Pool", - Sides: []psql.PreloadSide{ - { - From: PublicreportNotifyEmailPools, - To: PublicreportPools, - FromColumns: []string{"pool_id"}, - ToColumns: []string{"id"}, - }, - }, - }, PublicreportPools.Columns.Names(), opts...) - }, - } -} - -type publicreportNotifyEmailPoolThenLoader[Q orm.Loadable] struct { - EmailAddressEmailContact func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] -} - -func buildPublicreportNotifyEmailPoolThenLoader[Q orm.Loadable]() publicreportNotifyEmailPoolThenLoader[Q] { - type EmailAddressEmailContactLoadInterface interface { - LoadEmailAddressEmailContact(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type PoolLoadInterface interface { - LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - - return publicreportNotifyEmailPoolThenLoader[Q]{ - EmailAddressEmailContact: thenLoadBuilder[Q]( - "EmailAddressEmailContact", - func(ctx context.Context, exec bob.Executor, retrieved EmailAddressEmailContactLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadEmailAddressEmailContact(ctx, exec, mods...) - }, - ), - Pool: thenLoadBuilder[Q]( - "Pool", - func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPool(ctx, exec, mods...) - }, - ), - } -} - -// LoadEmailAddressEmailContact loads the publicreportNotifyEmailPool's EmailAddressEmailContact into the .R struct -func (o *PublicreportNotifyEmailPool) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.EmailAddressEmailContact = nil - - related, err := o.EmailAddressEmailContact(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.EmailAddressNotifyEmailPools = PublicreportNotifyEmailPoolSlice{o} - - o.R.EmailAddressEmailContact = related - return nil -} - -// LoadEmailAddressEmailContact loads the publicreportNotifyEmailPool's EmailAddressEmailContact into the .R struct -func (os PublicreportNotifyEmailPoolSlice) LoadEmailAddressEmailContact(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - commsEmailContacts, err := os.EmailAddressEmailContact(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range commsEmailContacts { - - if !(o.EmailAddress == rel.Address) { - continue - } - - rel.R.EmailAddressNotifyEmailPools = append(rel.R.EmailAddressNotifyEmailPools, o) - - o.R.EmailAddressEmailContact = rel - break - } - } - - return nil -} - -// LoadPool loads the publicreportNotifyEmailPool's Pool into the .R struct -func (o *PublicreportNotifyEmailPool) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Pool = nil - - related, err := o.Pool(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.NotifyEmailPools = PublicreportNotifyEmailPoolSlice{o} - - o.R.Pool = related - return nil -} - -// LoadPool loads the publicreportNotifyEmailPool's Pool into the .R struct -func (os PublicreportNotifyEmailPoolSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - publicreportPools, err := os.Pool(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportPools { - - if !(o.PoolID == rel.ID) { - continue - } - - rel.R.NotifyEmailPools = append(rel.R.NotifyEmailPools, o) - - o.R.Pool = rel - break - } - } - - return nil -} diff --git a/db/models/publicreport.notify_email_water.bob.go b/db/models/publicreport.notify_email_water.bob.go new file mode 100644 index 00000000..5116c82a --- /dev/null +++ b/db/models/publicreport.notify_email_water.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" +) + +// 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_phone_pool.bob.go b/db/models/publicreport.notify_phone_pool.bob.go deleted file mode 100644 index eba92b9a..00000000 --- a/db/models/publicreport.notify_phone_pool.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" -) - -// PublicreportNotifyPhonePool is an object representing the database table. -type PublicreportNotifyPhonePool struct { - Created time.Time `db:"created" ` - Deleted null.Val[time.Time] `db:"deleted" ` - PhoneE164 string `db:"phone_e164,pk" ` - PoolID int32 `db:"pool_id,pk" ` - - R publicreportNotifyPhonePoolR `db:"-" ` -} - -// PublicreportNotifyPhonePoolSlice is an alias for a slice of pointers to PublicreportNotifyPhonePool. -// This should almost always be used instead of []*PublicreportNotifyPhonePool. -type PublicreportNotifyPhonePoolSlice []*PublicreportNotifyPhonePool - -// PublicreportNotifyPhonePools contains methods to work with the notify_phone_pool table -var PublicreportNotifyPhonePools = psql.NewTablex[*PublicreportNotifyPhonePool, PublicreportNotifyPhonePoolSlice, *PublicreportNotifyPhonePoolSetter]("publicreport", "notify_phone_pool", buildPublicreportNotifyPhonePoolColumns("publicreport.notify_phone_pool")) - -// PublicreportNotifyPhonePoolsQuery is a query on the notify_phone_pool table -type PublicreportNotifyPhonePoolsQuery = *psql.ViewQuery[*PublicreportNotifyPhonePool, PublicreportNotifyPhonePoolSlice] - -// publicreportNotifyPhonePoolR is where relationships are stored. -type publicreportNotifyPhonePoolR struct { - PhoneE164Phone *CommsPhone // publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey - Pool *PublicreportPool // publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey -} - -func buildPublicreportNotifyPhonePoolColumns(alias string) publicreportNotifyPhonePoolColumns { - return publicreportNotifyPhonePoolColumns{ - ColumnsExpr: expr.NewColumnsExpr( - "created", "deleted", "phone_e164", "pool_id", - ).WithParent("publicreport.notify_phone_pool"), - tableAlias: alias, - Created: psql.Quote(alias, "created"), - Deleted: psql.Quote(alias, "deleted"), - PhoneE164: psql.Quote(alias, "phone_e164"), - PoolID: psql.Quote(alias, "pool_id"), - } -} - -type publicreportNotifyPhonePoolColumns struct { - expr.ColumnsExpr - tableAlias string - Created psql.Expression - Deleted psql.Expression - PhoneE164 psql.Expression - PoolID psql.Expression -} - -func (c publicreportNotifyPhonePoolColumns) Alias() string { - return c.tableAlias -} - -func (publicreportNotifyPhonePoolColumns) AliasedAs(alias string) publicreportNotifyPhonePoolColumns { - return buildPublicreportNotifyPhonePoolColumns(alias) -} - -// PublicreportNotifyPhonePoolSetter is used for insert/upsert/update operations -// All values are optional, and do not have to be set -// Generated columns are not included -type PublicreportNotifyPhonePoolSetter struct { - Created omit.Val[time.Time] `db:"created" ` - Deleted omitnull.Val[time.Time] `db:"deleted" ` - PhoneE164 omit.Val[string] `db:"phone_e164,pk" ` - PoolID omit.Val[int32] `db:"pool_id,pk" ` -} - -func (s PublicreportNotifyPhonePoolSetter) SetColumns() []string { - vals := make([]string, 0, 4) - if s.Created.IsValue() { - vals = append(vals, "created") - } - if !s.Deleted.IsUnset() { - vals = append(vals, "deleted") - } - if s.PhoneE164.IsValue() { - vals = append(vals, "phone_e164") - } - if s.PoolID.IsValue() { - vals = append(vals, "pool_id") - } - return vals -} - -func (s PublicreportNotifyPhonePoolSetter) Overwrite(t *PublicreportNotifyPhonePool) { - if s.Created.IsValue() { - t.Created = s.Created.MustGet() - } - if !s.Deleted.IsUnset() { - t.Deleted = s.Deleted.MustGetNull() - } - if s.PhoneE164.IsValue() { - t.PhoneE164 = s.PhoneE164.MustGet() - } - if s.PoolID.IsValue() { - t.PoolID = s.PoolID.MustGet() - } -} - -func (s *PublicreportNotifyPhonePoolSetter) Apply(q *dialect.InsertQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportNotifyPhonePools.BeforeInsertHooks.RunHooks(ctx, exec, s) - }) - - q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 4) - if s.Created.IsValue() { - vals[0] = psql.Arg(s.Created.MustGet()) - } else { - vals[0] = psql.Raw("DEFAULT") - } - - if !s.Deleted.IsUnset() { - vals[1] = psql.Arg(s.Deleted.MustGetNull()) - } else { - vals[1] = psql.Raw("DEFAULT") - } - - if s.PhoneE164.IsValue() { - vals[2] = psql.Arg(s.PhoneE164.MustGet()) - } else { - vals[2] = psql.Raw("DEFAULT") - } - - if s.PoolID.IsValue() { - vals[3] = psql.Arg(s.PoolID.MustGet()) - } else { - vals[3] = psql.Raw("DEFAULT") - } - - return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") - })) -} - -func (s PublicreportNotifyPhonePoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return um.Set(s.Expressions()...) -} - -func (s PublicreportNotifyPhonePoolSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 4) - - if s.Created.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "created")...), - psql.Arg(s.Created), - }}) - } - - if !s.Deleted.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "deleted")...), - psql.Arg(s.Deleted), - }}) - } - - if s.PhoneE164.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "phone_e164")...), - psql.Arg(s.PhoneE164), - }}) - } - - if s.PoolID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "pool_id")...), - psql.Arg(s.PoolID), - }}) - } - - return exprs -} - -// FindPublicreportNotifyPhonePool retrieves a single record by primary key -// If cols is empty Find will return all columns. -func FindPublicreportNotifyPhonePool(ctx context.Context, exec bob.Executor, PoolIDPK int32, PhoneE164PK string, cols ...string) (*PublicreportNotifyPhonePool, error) { - if len(cols) == 0 { - return PublicreportNotifyPhonePools.Query( - sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))), - ).One(ctx, exec) - } - - return PublicreportNotifyPhonePools.Query( - sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))), - sm.Columns(PublicreportNotifyPhonePools.Columns.Only(cols...)), - ).One(ctx, exec) -} - -// PublicreportNotifyPhonePoolExists checks the presence of a single record by primary key -func PublicreportNotifyPhonePoolExists(ctx context.Context, exec bob.Executor, PoolIDPK int32, PhoneE164PK string) (bool, error) { - return PublicreportNotifyPhonePools.Query( - sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(PhoneE164PK))), - ).Exists(ctx, exec) -} - -// AfterQueryHook is called after PublicreportNotifyPhonePool is retrieved from the database -func (o *PublicreportNotifyPhonePool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = PublicreportNotifyPhonePools.AfterSelectHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o}) - case bob.QueryTypeInsert: - ctx, err = PublicreportNotifyPhonePools.AfterInsertHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o}) - case bob.QueryTypeUpdate: - ctx, err = PublicreportNotifyPhonePools.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o}) - case bob.QueryTypeDelete: - ctx, err = PublicreportNotifyPhonePools.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportNotifyPhonePoolSlice{o}) - } - - return err -} - -// primaryKeyVals returns the primary key values of the PublicreportNotifyPhonePool -func (o *PublicreportNotifyPhonePool) primaryKeyVals() bob.Expression { - return psql.ArgGroup( - o.PoolID, - o.PhoneE164, - ) -} - -func (o *PublicreportNotifyPhonePool) pkEQ() dialect.Expression { - return psql.Group(psql.Quote("publicreport.notify_phone_pool", "pool_id"), psql.Quote("publicreport.notify_phone_pool", "phone_e164")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - return o.primaryKeyVals().WriteSQL(ctx, w, d, start) - })) -} - -// Update uses an executor to update the PublicreportNotifyPhonePool -func (o *PublicreportNotifyPhonePool) Update(ctx context.Context, exec bob.Executor, s *PublicreportNotifyPhonePoolSetter) error { - v, err := PublicreportNotifyPhonePools.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) - if err != nil { - return err - } - - o.R = v.R - *o = *v - - return nil -} - -// Delete deletes a single PublicreportNotifyPhonePool record with an executor -func (o *PublicreportNotifyPhonePool) Delete(ctx context.Context, exec bob.Executor) error { - _, err := PublicreportNotifyPhonePools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) - return err -} - -// Reload refreshes the PublicreportNotifyPhonePool using the executor -func (o *PublicreportNotifyPhonePool) Reload(ctx context.Context, exec bob.Executor) error { - o2, err := PublicreportNotifyPhonePools.Query( - sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(o.PoolID))), - sm.Where(PublicreportNotifyPhonePools.Columns.PhoneE164.EQ(psql.Arg(o.PhoneE164))), - ).One(ctx, exec) - if err != nil { - return err - } - o2.R = o.R - *o = *o2 - - return nil -} - -// AfterQueryHook is called after PublicreportNotifyPhonePoolSlice is retrieved from the database -func (o PublicreportNotifyPhonePoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = PublicreportNotifyPhonePools.AfterSelectHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeInsert: - ctx, err = PublicreportNotifyPhonePools.AfterInsertHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeUpdate: - ctx, err = PublicreportNotifyPhonePools.AfterUpdateHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeDelete: - ctx, err = PublicreportNotifyPhonePools.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err -} - -func (o PublicreportNotifyPhonePoolSlice) pkIN() dialect.Expression { - if len(o) == 0 { - return psql.Raw("NULL") - } - - return psql.Group(psql.Quote("publicreport.notify_phone_pool", "pool_id"), psql.Quote("publicreport.notify_phone_pool", "phone_e164")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - pkPairs := make([]bob.Expression, len(o)) - for i, row := range o { - pkPairs[i] = row.primaryKeyVals() - } - return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") - })) -} - -// copyMatchingRows finds models in the given slice that have the same primary key -// then it first copies the existing relationships from the old model to the new model -// and then replaces the old model in the slice with the new model -func (o PublicreportNotifyPhonePoolSlice) copyMatchingRows(from ...*PublicreportNotifyPhonePool) { - for i, old := range o { - for _, new := range from { - if new.PoolID != old.PoolID { - continue - } - if new.PhoneE164 != old.PhoneE164 { - continue - } - new.R = old.R - o[i] = new - break - } - } -} - -// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" -func (o PublicreportNotifyPhonePoolSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportNotifyPhonePools.BeforeUpdateHooks.RunHooks(ctx, exec, o) - }) - - q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { - var err error - switch retrieved := retrieved.(type) { - case *PublicreportNotifyPhonePool: - o.copyMatchingRows(retrieved) - case []*PublicreportNotifyPhonePool: - o.copyMatchingRows(retrieved...) - case PublicreportNotifyPhonePoolSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a PublicreportNotifyPhonePool or a slice of PublicreportNotifyPhonePool - // then run the AfterUpdateHooks on the slice - _, err = PublicreportNotifyPhonePools.AfterUpdateHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" -func (o PublicreportNotifyPhonePoolSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { - return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportNotifyPhonePools.BeforeDeleteHooks.RunHooks(ctx, exec, o) - }) - - q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { - var err error - switch retrieved := retrieved.(type) { - case *PublicreportNotifyPhonePool: - o.copyMatchingRows(retrieved) - case []*PublicreportNotifyPhonePool: - o.copyMatchingRows(retrieved...) - case PublicreportNotifyPhonePoolSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a PublicreportNotifyPhonePool or a slice of PublicreportNotifyPhonePool - // then run the AfterDeleteHooks on the slice - _, err = PublicreportNotifyPhonePools.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -func (o PublicreportNotifyPhonePoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportNotifyPhonePoolSetter) error { - if len(o) == 0 { - return nil - } - - _, err := PublicreportNotifyPhonePools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) - return err -} - -func (o PublicreportNotifyPhonePoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - _, err := PublicreportNotifyPhonePools.Delete(o.DeleteMod()).Exec(ctx, exec) - return err -} - -func (o PublicreportNotifyPhonePoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - o2, err := PublicreportNotifyPhonePools.Query(sm.Where(o.pkIN())).All(ctx, exec) - if err != nil { - return err - } - - o.copyMatchingRows(o2...) - - return nil -} - -// PhoneE164Phone starts a query for related objects on comms.phone -func (o *PublicreportNotifyPhonePool) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { - return CommsPhones.Query(append(mods, - sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PhoneE164))), - )...) -} - -func (os PublicreportNotifyPhonePoolSlice) PhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery { - pkPhoneE164 := make(pgtypes.Array[string], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkPhoneE164 = append(pkPhoneE164, o.PhoneE164) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkPhoneE164), "text[]")), - )) - - return CommsPhones.Query(append(mods, - sm.Where(psql.Group(CommsPhones.Columns.E164).OP("IN", PKArgExpr)), - )...) -} - -// Pool starts a query for related objects on publicreport.pool -func (o *PublicreportNotifyPhonePool) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - return PublicreportPools.Query(append(mods, - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))), - )...) -} - -func (os PublicreportNotifyPhonePoolSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - pkPoolID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkPoolID = append(pkPoolID, o.PoolID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")), - )) - - return PublicreportPools.Query(append(mods, - sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -func attachPublicreportNotifyPhonePoolPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool, commsPhone1 *CommsPhone) (*PublicreportNotifyPhonePool, error) { - setter := &PublicreportNotifyPhonePoolSetter{ - PhoneE164: omit.From(commsPhone1.E164), - } - - err := publicreportNotifyPhonePool0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNotifyPhonePoolPhoneE164Phone0: %w", err) - } - - return publicreportNotifyPhonePool0, nil -} - -func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) InsertPhoneE164Phone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error { - var err error - - commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportNotifyPhonePoolPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhonePool0, commsPhone1) - if err != nil { - return err - } - - publicreportNotifyPhonePool0.R.PhoneE164Phone = commsPhone1 - - commsPhone1.R.PhoneE164NotifyPhonePools = append(commsPhone1.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePool0) - - return nil -} - -func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) AttachPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error { - var err error - - _, err = attachPublicreportNotifyPhonePoolPhoneE164Phone0(ctx, exec, 1, publicreportNotifyPhonePool0, commsPhone1) - if err != nil { - return err - } - - publicreportNotifyPhonePool0.R.PhoneE164Phone = commsPhone1 - - commsPhone1.R.PhoneE164NotifyPhonePools = append(commsPhone1.R.PhoneE164NotifyPhonePools, publicreportNotifyPhonePool0) - - return nil -} - -func attachPublicreportNotifyPhonePoolPool0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool, publicreportPool1 *PublicreportPool) (*PublicreportNotifyPhonePool, error) { - setter := &PublicreportNotifyPhonePoolSetter{ - PoolID: omit.From(publicreportPool1.ID), - } - - err := publicreportNotifyPhonePool0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportNotifyPhonePoolPool0: %w", err) - } - - return publicreportNotifyPhonePool0, nil -} - -func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error { - var err error - - publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportNotifyPhonePoolPool0(ctx, exec, 1, publicreportNotifyPhonePool0, publicreportPool1) - if err != nil { - return err - } - - publicreportNotifyPhonePool0.R.Pool = publicreportPool1 - - publicreportPool1.R.NotifyPhonePools = append(publicreportPool1.R.NotifyPhonePools, publicreportNotifyPhonePool0) - - return nil -} - -func (publicreportNotifyPhonePool0 *PublicreportNotifyPhonePool) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error { - var err error - - _, err = attachPublicreportNotifyPhonePoolPool0(ctx, exec, 1, publicreportNotifyPhonePool0, publicreportPool1) - if err != nil { - return err - } - - publicreportNotifyPhonePool0.R.Pool = publicreportPool1 - - publicreportPool1.R.NotifyPhonePools = append(publicreportPool1.R.NotifyPhonePools, publicreportNotifyPhonePool0) - - return nil -} - -type publicreportNotifyPhonePoolWhere[Q psql.Filterable] struct { - Created psql.WhereMod[Q, time.Time] - Deleted psql.WhereNullMod[Q, time.Time] - PhoneE164 psql.WhereMod[Q, string] - PoolID psql.WhereMod[Q, int32] -} - -func (publicreportNotifyPhonePoolWhere[Q]) AliasedAs(alias string) publicreportNotifyPhonePoolWhere[Q] { - return buildPublicreportNotifyPhonePoolWhere[Q](buildPublicreportNotifyPhonePoolColumns(alias)) -} - -func buildPublicreportNotifyPhonePoolWhere[Q psql.Filterable](cols publicreportNotifyPhonePoolColumns) publicreportNotifyPhonePoolWhere[Q] { - return publicreportNotifyPhonePoolWhere[Q]{ - Created: psql.Where[Q, time.Time](cols.Created), - Deleted: psql.WhereNull[Q, time.Time](cols.Deleted), - PhoneE164: psql.Where[Q, string](cols.PhoneE164), - PoolID: psql.Where[Q, int32](cols.PoolID), - } -} - -func (o *PublicreportNotifyPhonePool) Preload(name string, retrieved any) error { - if o == nil { - return nil - } - - switch name { - case "PhoneE164Phone": - rel, ok := retrieved.(*CommsPhone) - if !ok { - return fmt.Errorf("publicreportNotifyPhonePool cannot load %T as %q", retrieved, name) - } - - o.R.PhoneE164Phone = rel - - if rel != nil { - rel.R.PhoneE164NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o} - } - return nil - case "Pool": - rel, ok := retrieved.(*PublicreportPool) - if !ok { - return fmt.Errorf("publicreportNotifyPhonePool cannot load %T as %q", retrieved, name) - } - - o.R.Pool = rel - - if rel != nil { - rel.R.NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o} - } - return nil - default: - return fmt.Errorf("publicreportNotifyPhonePool has no relationship %q", name) - } -} - -type publicreportNotifyPhonePoolPreloader struct { - PhoneE164Phone func(...psql.PreloadOption) psql.Preloader - Pool func(...psql.PreloadOption) psql.Preloader -} - -func buildPublicreportNotifyPhonePoolPreloader() publicreportNotifyPhonePoolPreloader { - return publicreportNotifyPhonePoolPreloader{ - PhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{ - Name: "PhoneE164Phone", - Sides: []psql.PreloadSide{ - { - From: PublicreportNotifyPhonePools, - To: CommsPhones, - FromColumns: []string{"phone_e164"}, - ToColumns: []string{"e164"}, - }, - }, - }, CommsPhones.Columns.Names(), opts...) - }, - Pool: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{ - Name: "Pool", - Sides: []psql.PreloadSide{ - { - From: PublicreportNotifyPhonePools, - To: PublicreportPools, - FromColumns: []string{"pool_id"}, - ToColumns: []string{"id"}, - }, - }, - }, PublicreportPools.Columns.Names(), opts...) - }, - } -} - -type publicreportNotifyPhonePoolThenLoader[Q orm.Loadable] struct { - PhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] -} - -func buildPublicreportNotifyPhonePoolThenLoader[Q orm.Loadable]() publicreportNotifyPhonePoolThenLoader[Q] { - type PhoneE164PhoneLoadInterface interface { - LoadPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type PoolLoadInterface interface { - LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - - return publicreportNotifyPhonePoolThenLoader[Q]{ - PhoneE164Phone: thenLoadBuilder[Q]( - "PhoneE164Phone", - func(ctx context.Context, exec bob.Executor, retrieved PhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPhoneE164Phone(ctx, exec, mods...) - }, - ), - Pool: thenLoadBuilder[Q]( - "Pool", - func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPool(ctx, exec, mods...) - }, - ), - } -} - -// LoadPhoneE164Phone loads the publicreportNotifyPhonePool's PhoneE164Phone into the .R struct -func (o *PublicreportNotifyPhonePool) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.PhoneE164Phone = nil - - related, err := o.PhoneE164Phone(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.PhoneE164NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o} - - o.R.PhoneE164Phone = related - return nil -} - -// LoadPhoneE164Phone loads the publicreportNotifyPhonePool's PhoneE164Phone into the .R struct -func (os PublicreportNotifyPhonePoolSlice) LoadPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - commsPhones, err := os.PhoneE164Phone(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range commsPhones { - - if !(o.PhoneE164 == rel.E164) { - continue - } - - rel.R.PhoneE164NotifyPhonePools = append(rel.R.PhoneE164NotifyPhonePools, o) - - o.R.PhoneE164Phone = rel - break - } - } - - return nil -} - -// LoadPool loads the publicreportNotifyPhonePool's Pool into the .R struct -func (o *PublicreportNotifyPhonePool) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Pool = nil - - related, err := o.Pool(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.NotifyPhonePools = PublicreportNotifyPhonePoolSlice{o} - - o.R.Pool = related - return nil -} - -// LoadPool loads the publicreportNotifyPhonePool's Pool into the .R struct -func (os PublicreportNotifyPhonePoolSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - publicreportPools, err := os.Pool(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportPools { - - if !(o.PoolID == rel.ID) { - continue - } - - rel.R.NotifyPhonePools = append(rel.R.NotifyPhonePools, o) - - o.R.Pool = rel - break - } - } - - return nil -} diff --git a/db/models/publicreport.notify_phone_water.bob.go b/db/models/publicreport.notify_phone_water.bob.go new file mode 100644 index 00000000..812811ba --- /dev/null +++ b/db/models/publicreport.notify_phone_water.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" +) + +// 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.nuisance.bob.go b/db/models/publicreport.nuisance.bob.go index f390440e..c57c2734 100644 --- a/db/models/publicreport.nuisance.bob.go +++ b/db/models/publicreport.nuisance.bob.go @@ -38,14 +38,14 @@ type PublicreportNuisance struct { ReporterEmail null.Val[string] `db:"reporter_email" ` ReporterName null.Val[string] `db:"reporter_name" ` ReporterPhone null.Val[string] `db:"reporter_phone" ` - Address string `db:"address" ` + AddressRaw string `db:"address_raw" ` Status enums.PublicreportReportstatustype `db:"status" ` OrganizationID null.Val[int32] `db:"organization_id" ` SourceGutter bool `db:"source_gutter" ` H3cell null.Val[string] `db:"h3cell" ` AddressCountry string `db:"address_country" ` - AddressPlace string `db:"address_place" ` - AddressPostcode string `db:"address_postcode" ` + 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" ` @@ -63,6 +63,7 @@ type PublicreportNuisance struct { 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" ` R publicreportNuisanceR `db:"-" ` } @@ -81,6 +82,7 @@ type PublicreportNuisancesQuery = *psql.ViewQuery[*PublicreportNuisance, Publicr 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 Images PublicreportImageSlice // publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey } @@ -88,7 +90,7 @@ type publicreportNuisanceR struct { 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", "status", "organization_id", "source_gutter", "h3cell", "address_country", "address_place", "address_postcode", "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", + "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", ).WithParent("publicreport.nuisance"), tableAlias: alias, ID: psql.Quote(alias, "id"), @@ -102,14 +104,14 @@ func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns ReporterEmail: psql.Quote(alias, "reporter_email"), ReporterName: psql.Quote(alias, "reporter_name"), ReporterPhone: psql.Quote(alias, "reporter_phone"), - Address: psql.Quote(alias, "address"), + 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"), - AddressPlace: psql.Quote(alias, "address_place"), - AddressPostcode: psql.Quote(alias, "address_postcode"), + 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"), @@ -127,6 +129,7 @@ func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), Location: psql.Quote(alias, "location"), AddressNumber: psql.Quote(alias, "address_number"), + AddressID: psql.Quote(alias, "address_id"), } } @@ -144,14 +147,14 @@ type publicreportNuisanceColumns struct { ReporterEmail psql.Expression ReporterName psql.Expression ReporterPhone psql.Expression - Address psql.Expression + AddressRaw psql.Expression Status psql.Expression OrganizationID psql.Expression SourceGutter psql.Expression H3cell psql.Expression AddressCountry psql.Expression - AddressPlace psql.Expression - AddressPostcode psql.Expression + AddressLocality psql.Expression + AddressPostalCode psql.Expression AddressRegion psql.Expression AddressStreet psql.Expression IsLocationBackyard psql.Expression @@ -169,6 +172,7 @@ type publicreportNuisanceColumns struct { ReporterContactConsent psql.Expression Location psql.Expression AddressNumber psql.Expression + AddressID psql.Expression } func (c publicreportNuisanceColumns) Alias() string { @@ -194,14 +198,14 @@ type PublicreportNuisanceSetter struct { ReporterEmail omitnull.Val[string] `db:"reporter_email" ` ReporterName omitnull.Val[string] `db:"reporter_name" ` ReporterPhone omitnull.Val[string] `db:"reporter_phone" ` - Address omit.Val[string] `db:"address" ` + AddressRaw omit.Val[string] `db:"address_raw" ` Status omit.Val[enums.PublicreportReportstatustype] `db:"status" ` OrganizationID omitnull.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" ` - AddressPlace omit.Val[string] `db:"address_place" ` - AddressPostcode omit.Val[string] `db:"address_postcode" ` + 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" ` @@ -219,10 +223,11 @@ type PublicreportNuisanceSetter struct { 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" ` } func (s PublicreportNuisanceSetter) SetColumns() []string { - vals := make([]string, 0, 36) + vals := make([]string, 0, 37) if s.ID.IsValue() { vals = append(vals, "id") } @@ -256,8 +261,8 @@ func (s PublicreportNuisanceSetter) SetColumns() []string { if !s.ReporterPhone.IsUnset() { vals = append(vals, "reporter_phone") } - if s.Address.IsValue() { - vals = append(vals, "address") + if s.AddressRaw.IsValue() { + vals = append(vals, "address_raw") } if s.Status.IsValue() { vals = append(vals, "status") @@ -274,11 +279,11 @@ func (s PublicreportNuisanceSetter) SetColumns() []string { if s.AddressCountry.IsValue() { vals = append(vals, "address_country") } - if s.AddressPlace.IsValue() { - vals = append(vals, "address_place") + if s.AddressLocality.IsValue() { + vals = append(vals, "address_locality") } - if s.AddressPostcode.IsValue() { - vals = append(vals, "address_postcode") + if s.AddressPostalCode.IsValue() { + vals = append(vals, "address_postal_code") } if s.AddressRegion.IsValue() { vals = append(vals, "address_region") @@ -331,6 +336,9 @@ func (s PublicreportNuisanceSetter) SetColumns() []string { if s.AddressNumber.IsValue() { vals = append(vals, "address_number") } + if !s.AddressID.IsUnset() { + vals = append(vals, "address_id") + } return vals } @@ -368,8 +376,8 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) { if !s.ReporterPhone.IsUnset() { t.ReporterPhone = s.ReporterPhone.MustGetNull() } - if s.Address.IsValue() { - t.Address = s.Address.MustGet() + if s.AddressRaw.IsValue() { + t.AddressRaw = s.AddressRaw.MustGet() } if s.Status.IsValue() { t.Status = s.Status.MustGet() @@ -386,11 +394,11 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) { if s.AddressCountry.IsValue() { t.AddressCountry = s.AddressCountry.MustGet() } - if s.AddressPlace.IsValue() { - t.AddressPlace = s.AddressPlace.MustGet() + if s.AddressLocality.IsValue() { + t.AddressLocality = s.AddressLocality.MustGet() } - if s.AddressPostcode.IsValue() { - t.AddressPostcode = s.AddressPostcode.MustGet() + if s.AddressPostalCode.IsValue() { + t.AddressPostalCode = s.AddressPostalCode.MustGet() } if s.AddressRegion.IsValue() { t.AddressRegion = s.AddressRegion.MustGet() @@ -443,6 +451,9 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) { if s.AddressNumber.IsValue() { t.AddressNumber = s.AddressNumber.MustGet() } + if !s.AddressID.IsUnset() { + t.AddressID = s.AddressID.MustGetNull() + } } func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) { @@ -451,7 +462,7 @@ 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, 36) + vals := make([]bob.Expression, 37) if s.ID.IsValue() { vals[0] = psql.Arg(s.ID.MustGet()) } else { @@ -518,8 +529,8 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) { vals[10] = psql.Raw("DEFAULT") } - if s.Address.IsValue() { - vals[11] = psql.Arg(s.Address.MustGet()) + if s.AddressRaw.IsValue() { + vals[11] = psql.Arg(s.AddressRaw.MustGet()) } else { vals[11] = psql.Raw("DEFAULT") } @@ -554,14 +565,14 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) { vals[16] = psql.Raw("DEFAULT") } - if s.AddressPlace.IsValue() { - vals[17] = psql.Arg(s.AddressPlace.MustGet()) + if s.AddressLocality.IsValue() { + vals[17] = psql.Arg(s.AddressLocality.MustGet()) } else { vals[17] = psql.Raw("DEFAULT") } - if s.AddressPostcode.IsValue() { - vals[18] = psql.Arg(s.AddressPostcode.MustGet()) + if s.AddressPostalCode.IsValue() { + vals[18] = psql.Arg(s.AddressPostalCode.MustGet()) } else { vals[18] = psql.Raw("DEFAULT") } @@ -668,6 +679,12 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) { vals[35] = psql.Raw("DEFAULT") } + if !s.AddressID.IsUnset() { + vals[36] = psql.Arg(s.AddressID.MustGetNull()) + } else { + vals[36] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -677,7 +694,7 @@ func (s PublicreportNuisanceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 36) + exprs := make([]bob.Expression, 0, 37) if s.ID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -756,10 +773,10 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } - if s.Address.IsValue() { + if s.AddressRaw.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address")...), - psql.Arg(s.Address), + psql.Quote(append(prefix, "address_raw")...), + psql.Arg(s.AddressRaw), }}) } @@ -798,17 +815,17 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } - if s.AddressPlace.IsValue() { + if s.AddressLocality.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_place")...), - psql.Arg(s.AddressPlace), + psql.Quote(append(prefix, "address_locality")...), + psql.Arg(s.AddressLocality), }}) } - if s.AddressPostcode.IsValue() { + if s.AddressPostalCode.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_postcode")...), - psql.Arg(s.AddressPostcode), + psql.Quote(append(prefix, "address_postal_code")...), + psql.Arg(s.AddressPostalCode), }}) } @@ -931,6 +948,13 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi }}) } + if !s.AddressID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_id")...), + psql.Arg(s.AddressID), + }}) + } + return exprs } @@ -1205,6 +1229,30 @@ func (os PublicreportNuisanceSlice) NotifyPhoneNuisances(mods ...bob.Mod[*dialec )...) } +// 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, @@ -1394,6 +1442,54 @@ func (publicreportNuisance0 *PublicreportNuisance) AttachNotifyPhoneNuisances(ct return nil } +func attachPublicreportNuisanceAddress0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, address1 *Address) (*PublicreportNuisance, error) { + setter := &PublicreportNuisanceSetter{ + AddressID: omitnull.From(address1.ID), + } + + err := publicreportNuisance0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportNuisanceAddress0: %w", err) + } + + return publicreportNuisance0, nil +} + +func (publicreportNuisance0 *PublicreportNuisance) 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 = attachPublicreportNuisanceAddress0(ctx, exec, 1, publicreportNuisance0, address1) + if err != nil { + return err + } + + publicreportNuisance0.R.Address = address1 + + address1.R.Nuisances = append(address1.R.Nuisances, publicreportNuisance0) + + return nil +} + +func (publicreportNuisance0 *PublicreportNuisance) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { + var err error + + _, err = attachPublicreportNuisanceAddress0(ctx, exec, 1, publicreportNuisance0, address1) + if err != nil { + return err + } + + publicreportNuisance0.R.Address = address1 + + 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: omitnull.From(organization1.ID), @@ -1519,14 +1615,14 @@ type publicreportNuisanceWhere[Q psql.Filterable] struct { ReporterEmail psql.WhereNullMod[Q, string] ReporterName psql.WhereNullMod[Q, string] ReporterPhone psql.WhereNullMod[Q, string] - Address psql.WhereMod[Q, string] + AddressRaw psql.WhereMod[Q, string] Status psql.WhereMod[Q, enums.PublicreportReportstatustype] OrganizationID psql.WhereNullMod[Q, int32] SourceGutter psql.WhereMod[Q, bool] H3cell psql.WhereNullMod[Q, string] AddressCountry psql.WhereMod[Q, string] - AddressPlace psql.WhereMod[Q, string] - AddressPostcode 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] @@ -1544,6 +1640,7 @@ type publicreportNuisanceWhere[Q psql.Filterable] struct { ReporterContactConsent psql.WhereNullMod[Q, bool] Location psql.WhereNullMod[Q, string] AddressNumber psql.WhereMod[Q, string] + AddressID psql.WhereNullMod[Q, int32] } func (publicreportNuisanceWhere[Q]) AliasedAs(alias string) publicreportNuisanceWhere[Q] { @@ -1563,14 +1660,14 @@ func buildPublicreportNuisanceWhere[Q psql.Filterable](cols publicreportNuisance ReporterEmail: psql.WhereNull[Q, string](cols.ReporterEmail), ReporterName: psql.WhereNull[Q, string](cols.ReporterName), ReporterPhone: psql.WhereNull[Q, string](cols.ReporterPhone), - Address: psql.Where[Q, string](cols.Address), + AddressRaw: psql.Where[Q, string](cols.AddressRaw), Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status), OrganizationID: psql.WhereNull[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), - AddressPlace: psql.Where[Q, string](cols.AddressPlace), - AddressPostcode: psql.Where[Q, string](cols.AddressPostcode), + 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), @@ -1588,6 +1685,7 @@ func buildPublicreportNuisanceWhere[Q psql.Filterable](cols publicreportNuisance 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), } } @@ -1625,6 +1723,18 @@ func (o *PublicreportNuisance) Preload(name string, retrieved any) error { } } 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 + + if rel != nil { + rel.R.Nuisances = PublicreportNuisanceSlice{o} + } + return nil case "Organization": rel, ok := retrieved.(*Organization) if !ok { @@ -1657,11 +1767,25 @@ func (o *PublicreportNuisance) Preload(name string, retrieved any) error { } type publicreportNuisancePreloader struct { + Address func(...psql.PreloadOption) psql.Preloader Organization 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", + Sides: []psql.PreloadSide{ + { + From: PublicreportNuisances, + 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", @@ -1681,6 +1805,7 @@ func buildPublicreportNuisancePreloader() publicreportNuisancePreloader { 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] Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } @@ -1692,6 +1817,9 @@ func buildPublicreportNuisanceThenLoader[Q orm.Loadable]() publicreportNuisanceT 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 } @@ -1712,6 +1840,12 @@ func buildPublicreportNuisanceThenLoader[Q orm.Loadable]() publicreportNuisanceT 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 { @@ -1849,6 +1983,61 @@ func (os PublicreportNuisanceSlice) LoadNotifyPhoneNuisances(ctx context.Context 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 + 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 { diff --git a/db/models/publicreport.pool_image.bob.go b/db/models/publicreport.pool_image.bob.go deleted file mode 100644 index 8e1c3eab..00000000 --- a/db/models/publicreport.pool_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" -) - -// PublicreportPoolImage is an object representing the database table. -type PublicreportPoolImage struct { - ImageID int32 `db:"image_id,pk" ` - PoolID int32 `db:"pool_id,pk" ` - - R publicreportPoolImageR `db:"-" ` -} - -// PublicreportPoolImageSlice is an alias for a slice of pointers to PublicreportPoolImage. -// This should almost always be used instead of []*PublicreportPoolImage. -type PublicreportPoolImageSlice []*PublicreportPoolImage - -// PublicreportPoolImages contains methods to work with the pool_image table -var PublicreportPoolImages = psql.NewTablex[*PublicreportPoolImage, PublicreportPoolImageSlice, *PublicreportPoolImageSetter]("publicreport", "pool_image", buildPublicreportPoolImageColumns("publicreport.pool_image")) - -// PublicreportPoolImagesQuery is a query on the pool_image table -type PublicreportPoolImagesQuery = *psql.ViewQuery[*PublicreportPoolImage, PublicreportPoolImageSlice] - -// publicreportPoolImageR is where relationships are stored. -type publicreportPoolImageR struct { - Image *PublicreportImage // publicreport.pool_image.pool_image_image_id_fkey - Pool *PublicreportPool // publicreport.pool_image.pool_image_pool_id_fkey -} - -func buildPublicreportPoolImageColumns(alias string) publicreportPoolImageColumns { - return publicreportPoolImageColumns{ - ColumnsExpr: expr.NewColumnsExpr( - "image_id", "pool_id", - ).WithParent("publicreport.pool_image"), - tableAlias: alias, - ImageID: psql.Quote(alias, "image_id"), - PoolID: psql.Quote(alias, "pool_id"), - } -} - -type publicreportPoolImageColumns struct { - expr.ColumnsExpr - tableAlias string - ImageID psql.Expression - PoolID psql.Expression -} - -func (c publicreportPoolImageColumns) Alias() string { - return c.tableAlias -} - -func (publicreportPoolImageColumns) AliasedAs(alias string) publicreportPoolImageColumns { - return buildPublicreportPoolImageColumns(alias) -} - -// PublicreportPoolImageSetter is used for insert/upsert/update operations -// All values are optional, and do not have to be set -// Generated columns are not included -type PublicreportPoolImageSetter struct { - ImageID omit.Val[int32] `db:"image_id,pk" ` - PoolID omit.Val[int32] `db:"pool_id,pk" ` -} - -func (s PublicreportPoolImageSetter) SetColumns() []string { - vals := make([]string, 0, 2) - if s.ImageID.IsValue() { - vals = append(vals, "image_id") - } - if s.PoolID.IsValue() { - vals = append(vals, "pool_id") - } - return vals -} - -func (s PublicreportPoolImageSetter) Overwrite(t *PublicreportPoolImage) { - if s.ImageID.IsValue() { - t.ImageID = s.ImageID.MustGet() - } - if s.PoolID.IsValue() { - t.PoolID = s.PoolID.MustGet() - } -} - -func (s *PublicreportPoolImageSetter) Apply(q *dialect.InsertQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportPoolImages.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.PoolID.IsValue() { - vals[1] = psql.Arg(s.PoolID.MustGet()) - } else { - vals[1] = psql.Raw("DEFAULT") - } - - return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") - })) -} - -func (s PublicreportPoolImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return um.Set(s.Expressions()...) -} - -func (s PublicreportPoolImageSetter) 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.PoolID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "pool_id")...), - psql.Arg(s.PoolID), - }}) - } - - return exprs -} - -// FindPublicreportPoolImage retrieves a single record by primary key -// If cols is empty Find will return all columns. -func FindPublicreportPoolImage(ctx context.Context, exec bob.Executor, ImageIDPK int32, PoolIDPK int32, cols ...string) (*PublicreportPoolImage, error) { - if len(cols) == 0 { - return PublicreportPoolImages.Query( - sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))), - sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - ).One(ctx, exec) - } - - return PublicreportPoolImages.Query( - sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))), - sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - sm.Columns(PublicreportPoolImages.Columns.Only(cols...)), - ).One(ctx, exec) -} - -// PublicreportPoolImageExists checks the presence of a single record by primary key -func PublicreportPoolImageExists(ctx context.Context, exec bob.Executor, ImageIDPK int32, PoolIDPK int32) (bool, error) { - return PublicreportPoolImages.Query( - sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(ImageIDPK))), - sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(PoolIDPK))), - ).Exists(ctx, exec) -} - -// AfterQueryHook is called after PublicreportPoolImage is retrieved from the database -func (o *PublicreportPoolImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = PublicreportPoolImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o}) - case bob.QueryTypeInsert: - ctx, err = PublicreportPoolImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o}) - case bob.QueryTypeUpdate: - ctx, err = PublicreportPoolImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o}) - case bob.QueryTypeDelete: - ctx, err = PublicreportPoolImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportPoolImageSlice{o}) - } - - return err -} - -// primaryKeyVals returns the primary key values of the PublicreportPoolImage -func (o *PublicreportPoolImage) primaryKeyVals() bob.Expression { - return psql.ArgGroup( - o.ImageID, - o.PoolID, - ) -} - -func (o *PublicreportPoolImage) pkEQ() dialect.Expression { - return psql.Group(psql.Quote("publicreport.pool_image", "image_id"), psql.Quote("publicreport.pool_image", "pool_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 PublicreportPoolImage -func (o *PublicreportPoolImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportPoolImageSetter) error { - v, err := PublicreportPoolImages.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 PublicreportPoolImage record with an executor -func (o *PublicreportPoolImage) Delete(ctx context.Context, exec bob.Executor) error { - _, err := PublicreportPoolImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) - return err -} - -// Reload refreshes the PublicreportPoolImage using the executor -func (o *PublicreportPoolImage) Reload(ctx context.Context, exec bob.Executor) error { - o2, err := PublicreportPoolImages.Query( - sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(o.ImageID))), - sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(o.PoolID))), - ).One(ctx, exec) - if err != nil { - return err - } - o2.R = o.R - *o = *o2 - - return nil -} - -// AfterQueryHook is called after PublicreportPoolImageSlice is retrieved from the database -func (o PublicreportPoolImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = PublicreportPoolImages.AfterSelectHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeInsert: - ctx, err = PublicreportPoolImages.AfterInsertHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeUpdate: - ctx, err = PublicreportPoolImages.AfterUpdateHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeDelete: - ctx, err = PublicreportPoolImages.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err -} - -func (o PublicreportPoolImageSlice) pkIN() dialect.Expression { - if len(o) == 0 { - return psql.Raw("NULL") - } - - return psql.Group(psql.Quote("publicreport.pool_image", "image_id"), psql.Quote("publicreport.pool_image", "pool_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 PublicreportPoolImageSlice) copyMatchingRows(from ...*PublicreportPoolImage) { - for i, old := range o { - for _, new := range from { - if new.ImageID != old.ImageID { - continue - } - if new.PoolID != old.PoolID { - continue - } - new.R = old.R - o[i] = new - break - } - } -} - -// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" -func (o PublicreportPoolImageSlice) 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 PublicreportPoolImages.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 *PublicreportPoolImage: - o.copyMatchingRows(retrieved) - case []*PublicreportPoolImage: - o.copyMatchingRows(retrieved...) - case PublicreportPoolImageSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a PublicreportPoolImage or a slice of PublicreportPoolImage - // then run the AfterUpdateHooks on the slice - _, err = PublicreportPoolImages.AfterUpdateHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" -func (o PublicreportPoolImageSlice) 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 PublicreportPoolImages.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 *PublicreportPoolImage: - o.copyMatchingRows(retrieved) - case []*PublicreportPoolImage: - o.copyMatchingRows(retrieved...) - case PublicreportPoolImageSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a PublicreportPoolImage or a slice of PublicreportPoolImage - // then run the AfterDeleteHooks on the slice - _, err = PublicreportPoolImages.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -func (o PublicreportPoolImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportPoolImageSetter) error { - if len(o) == 0 { - return nil - } - - _, err := PublicreportPoolImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) - return err -} - -func (o PublicreportPoolImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - _, err := PublicreportPoolImages.Delete(o.DeleteMod()).Exec(ctx, exec) - return err -} - -func (o PublicreportPoolImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - o2, err := PublicreportPoolImages.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 *PublicreportPoolImage) Image(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { - return PublicreportImages.Query(append(mods, - sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(o.ImageID))), - )...) -} - -func (os PublicreportPoolImageSlice) 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)), - )...) -} - -// Pool starts a query for related objects on publicreport.pool -func (o *PublicreportPoolImage) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - return PublicreportPools.Query(append(mods, - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))), - )...) -} - -func (os PublicreportPoolImageSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery { - pkPoolID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkPoolID = append(pkPoolID, o.PoolID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")), - )) - - return PublicreportPools.Query(append(mods, - sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -func attachPublicreportPoolImageImage0(ctx context.Context, exec bob.Executor, count int, publicreportPoolImage0 *PublicreportPoolImage, publicreportImage1 *PublicreportImage) (*PublicreportPoolImage, error) { - setter := &PublicreportPoolImageSetter{ - ImageID: omit.From(publicreportImage1.ID), - } - - err := publicreportPoolImage0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportPoolImageImage0: %w", err) - } - - return publicreportPoolImage0, nil -} - -func (publicreportPoolImage0 *PublicreportPoolImage) 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 = attachPublicreportPoolImageImage0(ctx, exec, 1, publicreportPoolImage0, publicreportImage1) - if err != nil { - return err - } - - publicreportPoolImage0.R.Image = publicreportImage1 - - return nil -} - -func (publicreportPoolImage0 *PublicreportPoolImage) AttachImage(ctx context.Context, exec bob.Executor, publicreportImage1 *PublicreportImage) error { - var err error - - _, err = attachPublicreportPoolImageImage0(ctx, exec, 1, publicreportPoolImage0, publicreportImage1) - if err != nil { - return err - } - - publicreportPoolImage0.R.Image = publicreportImage1 - - return nil -} - -func attachPublicreportPoolImagePool0(ctx context.Context, exec bob.Executor, count int, publicreportPoolImage0 *PublicreportPoolImage, publicreportPool1 *PublicreportPool) (*PublicreportPoolImage, error) { - setter := &PublicreportPoolImageSetter{ - PoolID: omit.From(publicreportPool1.ID), - } - - err := publicreportPoolImage0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPublicreportPoolImagePool0: %w", err) - } - - return publicreportPoolImage0, nil -} - -func (publicreportPoolImage0 *PublicreportPoolImage) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error { - var err error - - publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPublicreportPoolImagePool0(ctx, exec, 1, publicreportPoolImage0, publicreportPool1) - if err != nil { - return err - } - - publicreportPoolImage0.R.Pool = publicreportPool1 - - return nil -} - -func (publicreportPoolImage0 *PublicreportPoolImage) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error { - var err error - - _, err = attachPublicreportPoolImagePool0(ctx, exec, 1, publicreportPoolImage0, publicreportPool1) - if err != nil { - return err - } - - publicreportPoolImage0.R.Pool = publicreportPool1 - - return nil -} - -type publicreportPoolImageWhere[Q psql.Filterable] struct { - ImageID psql.WhereMod[Q, int32] - PoolID psql.WhereMod[Q, int32] -} - -func (publicreportPoolImageWhere[Q]) AliasedAs(alias string) publicreportPoolImageWhere[Q] { - return buildPublicreportPoolImageWhere[Q](buildPublicreportPoolImageColumns(alias)) -} - -func buildPublicreportPoolImageWhere[Q psql.Filterable](cols publicreportPoolImageColumns) publicreportPoolImageWhere[Q] { - return publicreportPoolImageWhere[Q]{ - ImageID: psql.Where[Q, int32](cols.ImageID), - PoolID: psql.Where[Q, int32](cols.PoolID), - } -} - -func (o *PublicreportPoolImage) Preload(name string, retrieved any) error { - if o == nil { - return nil - } - - switch name { - case "Image": - rel, ok := retrieved.(*PublicreportImage) - if !ok { - return fmt.Errorf("publicreportPoolImage cannot load %T as %q", retrieved, name) - } - - o.R.Image = rel - - return nil - case "Pool": - rel, ok := retrieved.(*PublicreportPool) - if !ok { - return fmt.Errorf("publicreportPoolImage cannot load %T as %q", retrieved, name) - } - - o.R.Pool = rel - - return nil - default: - return fmt.Errorf("publicreportPoolImage has no relationship %q", name) - } -} - -type publicreportPoolImagePreloader struct { - Image func(...psql.PreloadOption) psql.Preloader - Pool func(...psql.PreloadOption) psql.Preloader -} - -func buildPublicreportPoolImagePreloader() publicreportPoolImagePreloader { - return publicreportPoolImagePreloader{ - Image: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*PublicreportImage, PublicreportImageSlice](psql.PreloadRel{ - Name: "Image", - Sides: []psql.PreloadSide{ - { - From: PublicreportPoolImages, - To: PublicreportImages, - FromColumns: []string{"image_id"}, - ToColumns: []string{"id"}, - }, - }, - }, PublicreportImages.Columns.Names(), opts...) - }, - Pool: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{ - Name: "Pool", - Sides: []psql.PreloadSide{ - { - From: PublicreportPoolImages, - To: PublicreportPools, - FromColumns: []string{"pool_id"}, - ToColumns: []string{"id"}, - }, - }, - }, PublicreportPools.Columns.Names(), opts...) - }, - } -} - -type publicreportPoolImageThenLoader[Q orm.Loadable] struct { - Image func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] -} - -func buildPublicreportPoolImageThenLoader[Q orm.Loadable]() publicreportPoolImageThenLoader[Q] { - type ImageLoadInterface interface { - LoadImage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type PoolLoadInterface interface { - LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - - return publicreportPoolImageThenLoader[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...) - }, - ), - Pool: thenLoadBuilder[Q]( - "Pool", - func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPool(ctx, exec, mods...) - }, - ), - } -} - -// LoadImage loads the publicreportPoolImage's Image into the .R struct -func (o *PublicreportPoolImage) 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 publicreportPoolImage's Image into the .R struct -func (os PublicreportPoolImageSlice) 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 -} - -// LoadPool loads the publicreportPoolImage's Pool into the .R struct -func (o *PublicreportPoolImage) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Pool = nil - - related, err := o.Pool(mods...).One(ctx, exec) - if err != nil { - return err - } - - o.R.Pool = related - return nil -} - -// LoadPool loads the publicreportPoolImage's Pool into the .R struct -func (os PublicreportPoolImageSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - publicreportPools, err := os.Pool(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range publicreportPools { - - if !(o.PoolID == rel.ID) { - continue - } - - o.R.Pool = rel - break - } - } - - return nil -} diff --git a/db/models/publicreport.pool.bob.go b/db/models/publicreport.water.bob.go similarity index 58% rename from db/models/publicreport.pool.bob.go rename to db/models/publicreport.water.bob.go index 8e999665..defa613b 100644 --- a/db/models/publicreport.pool.bob.go +++ b/db/models/publicreport.water.bob.go @@ -25,8 +25,8 @@ import ( "github.com/stephenafamo/scan" ) -// PublicreportPool is an object representing the database table. -type PublicreportPool struct { +// 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" ` @@ -34,10 +34,10 @@ type PublicreportPool struct { AccessLocked bool `db:"access_locked" ` AccessDog bool `db:"access_dog" ` AccessOther bool `db:"access_other" ` - Address string `db:"address" ` + AddressRaw string `db:"address_raw" ` AddressCountry string `db:"address_country" ` - AddressPostCode string `db:"address_post_code" ` - AddressPlace string `db:"address_place" ` + 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" ` @@ -62,33 +62,35 @@ type PublicreportPool struct { 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" ` - R publicreportPoolR `db:"-" ` + R publicreportWaterR `db:"-" ` } -// PublicreportPoolSlice is an alias for a slice of pointers to PublicreportPool. -// This should almost always be used instead of []*PublicreportPool. -type PublicreportPoolSlice []*PublicreportPool +// PublicreportWaterSlice is an alias for a slice of pointers to PublicreportWater. +// This should almost always be used instead of []*PublicreportWater. +type PublicreportWaterSlice []*PublicreportWater -// PublicreportPools contains methods to work with the pool table -var PublicreportPools = psql.NewTablex[*PublicreportPool, PublicreportPoolSlice, *PublicreportPoolSetter]("publicreport", "pool", buildPublicreportPoolColumns("publicreport.pool")) +// PublicreportWaters contains methods to work with the water table +var PublicreportWaters = psql.NewTablex[*PublicreportWater, PublicreportWaterSlice, *PublicreportWaterSetter]("publicreport", "water", buildPublicreportWaterColumns("publicreport.water")) -// PublicreportPoolsQuery is a query on the pool table -type PublicreportPoolsQuery = *psql.ViewQuery[*PublicreportPool, PublicreportPoolSlice] +// PublicreportWatersQuery is a query on the water table +type PublicreportWatersQuery = *psql.ViewQuery[*PublicreportWater, PublicreportWaterSlice] -// publicreportPoolR is where relationships are stored. -type publicreportPoolR struct { - NotifyEmailPools PublicreportNotifyEmailPoolSlice // publicreport.notify_email_pool.notify_email_pool_pool_id_fkey - NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_pool_id_fkey - Organization *Organization // publicreport.pool.pool_organization_id_fkey - Images PublicreportImageSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey +// 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 + Images PublicreportImageSlice // publicreport.water_image.pool_image_image_id_fkeypublicreport.water_image.pool_image_pool_id_fkey } -func buildPublicreportPoolColumns(alias string) publicreportPoolColumns { - return publicreportPoolColumns{ +func buildPublicreportWaterColumns(alias string) publicreportWaterColumns { + return publicreportWaterColumns{ ColumnsExpr: expr.NewColumnsExpr( - "id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address", "address_country", "address_post_code", "address_place", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "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", - ).WithParent("publicreport.pool"), + "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", + ).WithParent("publicreport.water"), tableAlias: alias, ID: psql.Quote(alias, "id"), AccessComments: psql.Quote(alias, "access_comments"), @@ -97,10 +99,10 @@ func buildPublicreportPoolColumns(alias string) publicreportPoolColumns { AccessLocked: psql.Quote(alias, "access_locked"), AccessDog: psql.Quote(alias, "access_dog"), AccessOther: psql.Quote(alias, "access_other"), - Address: psql.Quote(alias, "address"), + AddressRaw: psql.Quote(alias, "address_raw"), AddressCountry: psql.Quote(alias, "address_country"), - AddressPostCode: psql.Quote(alias, "address_post_code"), - AddressPlace: psql.Quote(alias, "address_place"), + 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"), @@ -125,10 +127,11 @@ func buildPublicreportPoolColumns(alias string) publicreportPoolColumns { ReporterContactConsent: psql.Quote(alias, "reporter_contact_consent"), Location: psql.Quote(alias, "location"), AddressNumber: psql.Quote(alias, "address_number"), + AddressID: psql.Quote(alias, "address_id"), } } -type publicreportPoolColumns struct { +type publicreportWaterColumns struct { expr.ColumnsExpr tableAlias string ID psql.Expression @@ -138,10 +141,10 @@ type publicreportPoolColumns struct { AccessLocked psql.Expression AccessDog psql.Expression AccessOther psql.Expression - Address psql.Expression + AddressRaw psql.Expression AddressCountry psql.Expression - AddressPostCode psql.Expression - AddressPlace psql.Expression + AddressPostalCode psql.Expression + AddressLocality psql.Expression AddressStreet psql.Expression AddressRegion psql.Expression Comments psql.Expression @@ -166,20 +169,21 @@ type publicreportPoolColumns struct { ReporterContactConsent psql.Expression Location psql.Expression AddressNumber psql.Expression + AddressID psql.Expression } -func (c publicreportPoolColumns) Alias() string { +func (c publicreportWaterColumns) Alias() string { return c.tableAlias } -func (publicreportPoolColumns) AliasedAs(alias string) publicreportPoolColumns { - return buildPublicreportPoolColumns(alias) +func (publicreportWaterColumns) AliasedAs(alias string) publicreportWaterColumns { + return buildPublicreportWaterColumns(alias) } -// PublicreportPoolSetter is used for insert/upsert/update operations +// PublicreportWaterSetter is used for insert/upsert/update operations // All values are optional, and do not have to be set // Generated columns are not included -type PublicreportPoolSetter struct { +type PublicreportWaterSetter struct { ID omit.Val[int32] `db:"id,pk" ` AccessComments omit.Val[string] `db:"access_comments" ` AccessGate omit.Val[bool] `db:"access_gate" ` @@ -187,10 +191,10 @@ type PublicreportPoolSetter struct { AccessLocked omit.Val[bool] `db:"access_locked" ` AccessDog omit.Val[bool] `db:"access_dog" ` AccessOther omit.Val[bool] `db:"access_other" ` - Address omit.Val[string] `db:"address" ` + AddressRaw omit.Val[string] `db:"address_raw" ` AddressCountry omit.Val[string] `db:"address_country" ` - AddressPostCode omit.Val[string] `db:"address_post_code" ` - AddressPlace omit.Val[string] `db:"address_place" ` + 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" ` @@ -215,10 +219,11 @@ type PublicreportPoolSetter struct { 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" ` } -func (s PublicreportPoolSetter) SetColumns() []string { - vals := make([]string, 0, 35) +func (s PublicreportWaterSetter) SetColumns() []string { + vals := make([]string, 0, 36) if s.ID.IsValue() { vals = append(vals, "id") } @@ -240,17 +245,17 @@ func (s PublicreportPoolSetter) SetColumns() []string { if s.AccessOther.IsValue() { vals = append(vals, "access_other") } - if s.Address.IsValue() { - vals = append(vals, "address") + if s.AddressRaw.IsValue() { + vals = append(vals, "address_raw") } if s.AddressCountry.IsValue() { vals = append(vals, "address_country") } - if s.AddressPostCode.IsValue() { - vals = append(vals, "address_post_code") + if s.AddressPostalCode.IsValue() { + vals = append(vals, "address_postal_code") } - if s.AddressPlace.IsValue() { - vals = append(vals, "address_place") + if s.AddressLocality.IsValue() { + vals = append(vals, "address_locality") } if s.AddressStreet.IsValue() { vals = append(vals, "address_street") @@ -324,10 +329,13 @@ func (s PublicreportPoolSetter) SetColumns() []string { if s.AddressNumber.IsValue() { vals = append(vals, "address_number") } + if !s.AddressID.IsUnset() { + vals = append(vals, "address_id") + } return vals } -func (s PublicreportPoolSetter) Overwrite(t *PublicreportPool) { +func (s PublicreportWaterSetter) Overwrite(t *PublicreportWater) { if s.ID.IsValue() { t.ID = s.ID.MustGet() } @@ -349,17 +357,17 @@ func (s PublicreportPoolSetter) Overwrite(t *PublicreportPool) { if s.AccessOther.IsValue() { t.AccessOther = s.AccessOther.MustGet() } - if s.Address.IsValue() { - t.Address = s.Address.MustGet() + if s.AddressRaw.IsValue() { + t.AddressRaw = s.AddressRaw.MustGet() } if s.AddressCountry.IsValue() { t.AddressCountry = s.AddressCountry.MustGet() } - if s.AddressPostCode.IsValue() { - t.AddressPostCode = s.AddressPostCode.MustGet() + if s.AddressPostalCode.IsValue() { + t.AddressPostalCode = s.AddressPostalCode.MustGet() } - if s.AddressPlace.IsValue() { - t.AddressPlace = s.AddressPlace.MustGet() + if s.AddressLocality.IsValue() { + t.AddressLocality = s.AddressLocality.MustGet() } if s.AddressStreet.IsValue() { t.AddressStreet = s.AddressStreet.MustGet() @@ -433,15 +441,18 @@ func (s PublicreportPoolSetter) Overwrite(t *PublicreportPool) { if s.AddressNumber.IsValue() { t.AddressNumber = s.AddressNumber.MustGet() } + if !s.AddressID.IsUnset() { + t.AddressID = s.AddressID.MustGetNull() + } } -func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) { +func (s *PublicreportWaterSetter) Apply(q *dialect.InsertQuery) { q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return PublicreportPools.BeforeInsertHooks.RunHooks(ctx, exec, s) + return PublicreportWaters.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, 35) + vals := make([]bob.Expression, 36) if s.ID.IsValue() { vals[0] = psql.Arg(s.ID.MustGet()) } else { @@ -484,8 +495,8 @@ func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) { vals[6] = psql.Raw("DEFAULT") } - if s.Address.IsValue() { - vals[7] = psql.Arg(s.Address.MustGet()) + if s.AddressRaw.IsValue() { + vals[7] = psql.Arg(s.AddressRaw.MustGet()) } else { vals[7] = psql.Raw("DEFAULT") } @@ -496,14 +507,14 @@ func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) { vals[8] = psql.Raw("DEFAULT") } - if s.AddressPostCode.IsValue() { - vals[9] = psql.Arg(s.AddressPostCode.MustGet()) + if s.AddressPostalCode.IsValue() { + vals[9] = psql.Arg(s.AddressPostalCode.MustGet()) } else { vals[9] = psql.Raw("DEFAULT") } - if s.AddressPlace.IsValue() { - vals[10] = psql.Arg(s.AddressPlace.MustGet()) + if s.AddressLocality.IsValue() { + vals[10] = psql.Arg(s.AddressLocality.MustGet()) } else { vals[10] = psql.Raw("DEFAULT") } @@ -652,16 +663,22 @@ func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) { vals[34] = psql.Raw("DEFAULT") } + if !s.AddressID.IsUnset() { + vals[35] = psql.Arg(s.AddressID.MustGetNull()) + } else { + vals[35] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } -func (s PublicreportPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { +func (s PublicreportWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { return um.Set(s.Expressions()...) } -func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 35) +func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 36) if s.ID.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -712,10 +729,10 @@ func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression { }}) } - if s.Address.IsValue() { + if s.AddressRaw.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address")...), - psql.Arg(s.Address), + psql.Quote(append(prefix, "address_raw")...), + psql.Arg(s.AddressRaw), }}) } @@ -726,17 +743,17 @@ func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression { }}) } - if s.AddressPostCode.IsValue() { + if s.AddressPostalCode.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_post_code")...), - psql.Arg(s.AddressPostCode), + psql.Quote(append(prefix, "address_postal_code")...), + psql.Arg(s.AddressPostalCode), }}) } - if s.AddressPlace.IsValue() { + if s.AddressLocality.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_place")...), - psql.Arg(s.AddressPlace), + psql.Quote(append(prefix, "address_locality")...), + psql.Arg(s.AddressLocality), }}) } @@ -908,63 +925,70 @@ func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression { }}) } + if !s.AddressID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_id")...), + psql.Arg(s.AddressID), + }}) + } + return exprs } -// FindPublicreportPool retrieves a single record by primary key +// FindPublicreportWater retrieves a single record by primary key // If cols is empty Find will return all columns. -func FindPublicreportPool(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportPool, error) { +func FindPublicreportWater(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportWater, error) { if len(cols) == 0 { - return PublicreportPools.Query( - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(IDPK))), + return PublicreportWaters.Query( + sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(IDPK))), ).One(ctx, exec) } - return PublicreportPools.Query( - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(IDPK))), - sm.Columns(PublicreportPools.Columns.Only(cols...)), + return PublicreportWaters.Query( + sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Columns(PublicreportWaters.Columns.Only(cols...)), ).One(ctx, exec) } -// PublicreportPoolExists checks the presence of a single record by primary key -func PublicreportPoolExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { - return PublicreportPools.Query( - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(IDPK))), +// PublicreportWaterExists checks the presence of a single record by primary key +func PublicreportWaterExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return PublicreportWaters.Query( + sm.Where(PublicreportWaters.Columns.ID.EQ(psql.Arg(IDPK))), ).Exists(ctx, exec) } -// AfterQueryHook is called after PublicreportPool is retrieved from the database -func (o *PublicreportPool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { +// AfterQueryHook is called after PublicreportWater is retrieved from the database +func (o *PublicreportWater) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { var err error switch queryType { case bob.QueryTypeSelect: - ctx, err = PublicreportPools.AfterSelectHooks.RunHooks(ctx, exec, PublicreportPoolSlice{o}) + ctx, err = PublicreportWaters.AfterSelectHooks.RunHooks(ctx, exec, PublicreportWaterSlice{o}) case bob.QueryTypeInsert: - ctx, err = PublicreportPools.AfterInsertHooks.RunHooks(ctx, exec, PublicreportPoolSlice{o}) + ctx, err = PublicreportWaters.AfterInsertHooks.RunHooks(ctx, exec, PublicreportWaterSlice{o}) case bob.QueryTypeUpdate: - ctx, err = PublicreportPools.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportPoolSlice{o}) + ctx, err = PublicreportWaters.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportWaterSlice{o}) case bob.QueryTypeDelete: - ctx, err = PublicreportPools.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportPoolSlice{o}) + ctx, err = PublicreportWaters.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportWaterSlice{o}) } return err } -// primaryKeyVals returns the primary key values of the PublicreportPool -func (o *PublicreportPool) primaryKeyVals() bob.Expression { +// primaryKeyVals returns the primary key values of the PublicreportWater +func (o *PublicreportWater) primaryKeyVals() bob.Expression { return psql.Arg(o.ID) } -func (o *PublicreportPool) pkEQ() dialect.Expression { - return psql.Quote("publicreport.pool", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { +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 o.primaryKeyVals().WriteSQL(ctx, w, d, start) })) } -// Update uses an executor to update the PublicreportPool -func (o *PublicreportPool) Update(ctx context.Context, exec bob.Executor, s *PublicreportPoolSetter) error { - v, err := PublicreportPools.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) +// Update uses an executor to update the PublicreportWater +func (o *PublicreportWater) Update(ctx context.Context, exec bob.Executor, s *PublicreportWaterSetter) error { + v, err := PublicreportWaters.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) if err != nil { return err } @@ -975,16 +999,16 @@ func (o *PublicreportPool) Update(ctx context.Context, exec bob.Executor, s *Pub return nil } -// Delete deletes a single PublicreportPool record with an executor -func (o *PublicreportPool) Delete(ctx context.Context, exec bob.Executor) error { - _, err := PublicreportPools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) +// Delete deletes a single PublicreportWater record with an executor +func (o *PublicreportWater) Delete(ctx context.Context, exec bob.Executor) error { + _, err := PublicreportWaters.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) return err } -// Reload refreshes the PublicreportPool using the executor -func (o *PublicreportPool) Reload(ctx context.Context, exec bob.Executor) error { - o2, err := PublicreportPools.Query( - sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.ID))), +// 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))), ).One(ctx, exec) if err != nil { return err @@ -995,30 +1019,30 @@ func (o *PublicreportPool) Reload(ctx context.Context, exec bob.Executor) error return nil } -// AfterQueryHook is called after PublicreportPoolSlice is retrieved from the database -func (o PublicreportPoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { +// AfterQueryHook is called after PublicreportWaterSlice is retrieved from the database +func (o PublicreportWaterSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { var err error switch queryType { case bob.QueryTypeSelect: - ctx, err = PublicreportPools.AfterSelectHooks.RunHooks(ctx, exec, o) + ctx, err = PublicreportWaters.AfterSelectHooks.RunHooks(ctx, exec, o) case bob.QueryTypeInsert: - ctx, err = PublicreportPools.AfterInsertHooks.RunHooks(ctx, exec, o) + ctx, err = PublicreportWaters.AfterInsertHooks.RunHooks(ctx, exec, o) case bob.QueryTypeUpdate: - ctx, err = PublicreportPools.AfterUpdateHooks.RunHooks(ctx, exec, o) + ctx, err = PublicreportWaters.AfterUpdateHooks.RunHooks(ctx, exec, o) case bob.QueryTypeDelete: - ctx, err = PublicreportPools.AfterDeleteHooks.RunHooks(ctx, exec, o) + ctx, err = PublicreportWaters.AfterDeleteHooks.RunHooks(ctx, exec, o) } return err } -func (o PublicreportPoolSlice) pkIN() dialect.Expression { +func (o PublicreportWaterSlice) pkIN() dialect.Expression { if len(o) == 0 { return psql.Raw("NULL") } - return psql.Quote("publicreport.pool", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return psql.Quote("publicreport.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() @@ -1030,7 +1054,7 @@ func (o PublicreportPoolSlice) pkIN() dialect.Expression { // 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 PublicreportPoolSlice) copyMatchingRows(from ...*PublicreportPool) { +func (o PublicreportWaterSlice) copyMatchingRows(from ...*PublicreportWater) { for i, old := range o { for _, new := range from { if new.ID != old.ID { @@ -1044,25 +1068,25 @@ func (o PublicreportPoolSlice) copyMatchingRows(from ...*PublicreportPool) { } // UpdateMod modifies an update query with "WHERE primary_key IN (o...)" -func (o PublicreportPoolSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { +func (o PublicreportWaterSlice) 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 PublicreportPools.BeforeUpdateHooks.RunHooks(ctx, exec, o) + return PublicreportWaters.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 *PublicreportPool: + case *PublicreportWater: o.copyMatchingRows(retrieved) - case []*PublicreportPool: + case []*PublicreportWater: o.copyMatchingRows(retrieved...) - case PublicreportPoolSlice: + case PublicreportWaterSlice: o.copyMatchingRows(retrieved...) default: - // If the retrieved value is not a PublicreportPool or a slice of PublicreportPool + // If the retrieved value is not a PublicreportWater or a slice of PublicreportWater // then run the AfterUpdateHooks on the slice - _, err = PublicreportPools.AfterUpdateHooks.RunHooks(ctx, exec, o) + _, err = PublicreportWaters.AfterUpdateHooks.RunHooks(ctx, exec, o) } return err @@ -1073,25 +1097,25 @@ func (o PublicreportPoolSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { } // DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" -func (o PublicreportPoolSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { +func (o PublicreportWaterSlice) 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 PublicreportPools.BeforeDeleteHooks.RunHooks(ctx, exec, o) + return PublicreportWaters.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 *PublicreportPool: + case *PublicreportWater: o.copyMatchingRows(retrieved) - case []*PublicreportPool: + case []*PublicreportWater: o.copyMatchingRows(retrieved...) - case PublicreportPoolSlice: + case PublicreportWaterSlice: o.copyMatchingRows(retrieved...) default: - // If the retrieved value is not a PublicreportPool or a slice of PublicreportPool + // If the retrieved value is not a PublicreportWater or a slice of PublicreportWater // then run the AfterDeleteHooks on the slice - _, err = PublicreportPools.AfterDeleteHooks.RunHooks(ctx, exec, o) + _, err = PublicreportWaters.AfterDeleteHooks.RunHooks(ctx, exec, o) } return err @@ -1101,30 +1125,30 @@ func (o PublicreportPoolSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { }) } -func (o PublicreportPoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportPoolSetter) error { +func (o PublicreportWaterSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportWaterSetter) error { if len(o) == 0 { return nil } - _, err := PublicreportPools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) + _, err := PublicreportWaters.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) return err } -func (o PublicreportPoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { +func (o PublicreportWaterSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { if len(o) == 0 { return nil } - _, err := PublicreportPools.Delete(o.DeleteMod()).Exec(ctx, exec) + _, err := PublicreportWaters.Delete(o.DeleteMod()).Exec(ctx, exec) return err } -func (o PublicreportPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { +func (o PublicreportWaterSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { if len(o) == 0 { return nil } - o2, err := PublicreportPools.Query(sm.Where(o.pkIN())).All(ctx, exec) + o2, err := PublicreportWaters.Query(sm.Where(o.pkIN())).All(ctx, exec) if err != nil { return err } @@ -1134,14 +1158,14 @@ func (o PublicreportPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) return nil } -// NotifyEmailPools starts a query for related objects on publicreport.notify_email_pool -func (o *PublicreportPool) NotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery { - return PublicreportNotifyEmailPools.Query(append(mods, - sm.Where(PublicreportNotifyEmailPools.Columns.PoolID.EQ(psql.Arg(o.ID))), +// 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))), )...) } -func (os PublicreportPoolSlice) NotifyEmailPools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailPoolsQuery { +func (os PublicreportWaterSlice) NotifyEmailWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyEmailWatersQuery { pkID := make(pgtypes.Array[int32], 0, len(os)) for _, o := range os { if o == nil { @@ -1153,19 +1177,19 @@ func (os PublicreportPoolSlice) NotifyEmailPools(mods ...bob.Mod[*dialect.Select psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), )) - return PublicreportNotifyEmailPools.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyEmailPools.Columns.PoolID).OP("IN", PKArgExpr)), + return PublicreportNotifyEmailWaters.Query(append(mods, + sm.Where(psql.Group(PublicreportNotifyEmailWaters.Columns.WaterID).OP("IN", PKArgExpr)), )...) } -// NotifyPhonePools starts a query for related objects on publicreport.notify_phone_pool -func (o *PublicreportPool) NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery { - return PublicreportNotifyPhonePools.Query(append(mods, - sm.Where(PublicreportNotifyPhonePools.Columns.PoolID.EQ(psql.Arg(o.ID))), +// 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 PublicreportPoolSlice) NotifyPhonePools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNotifyPhonePoolsQuery { +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 { @@ -1177,19 +1201,43 @@ func (os PublicreportPoolSlice) NotifyPhonePools(mods ...bob.Mod[*dialect.Select psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), )) - return PublicreportNotifyPhonePools.Query(append(mods, - sm.Where(psql.Group(PublicreportNotifyPhonePools.Columns.PoolID).OP("IN", PKArgExpr)), + 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 *PublicreportPool) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { +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 PublicreportPoolSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { +func (os PublicreportWaterSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { pkOrganizationID := make(pgtypes.Array[null.Val[int32]], 0, len(os)) for _, o := range os { if o == nil { @@ -1207,15 +1255,15 @@ func (os PublicreportPoolSlice) Organization(mods ...bob.Mod[*dialect.SelectQuer } // Images starts a query for related objects on publicreport.image -func (o *PublicreportPool) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { +func (o *PublicreportWater) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { return PublicreportImages.Query(append(mods, - sm.InnerJoin(PublicreportPoolImages.NameAs()).On( - PublicreportImages.Columns.ID.EQ(PublicreportPoolImages.Columns.ImageID)), - sm.Where(PublicreportPoolImages.Columns.PoolID.EQ(psql.Arg(o.ID))), + sm.InnerJoin(PublicreportWaterImages.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportWaterImages.Columns.ImageID)), + sm.Where(PublicreportWaterImages.Columns.WaterID.EQ(psql.Arg(o.ID))), )...) } -func (os PublicreportPoolSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery { +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 { @@ -1228,163 +1276,211 @@ func (os PublicreportPoolSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) Pu )) return PublicreportImages.Query(append(mods, - sm.InnerJoin(PublicreportPoolImages.NameAs()).On( - PublicreportImages.Columns.ID.EQ(PublicreportPoolImages.Columns.ImageID), + sm.InnerJoin(PublicreportWaterImages.NameAs()).On( + PublicreportImages.Columns.ID.EQ(PublicreportWaterImages.Columns.ImageID), ), - sm.Where(psql.Group(PublicreportPoolImages.Columns.PoolID).OP("IN", PKArgExpr)), + sm.Where(psql.Group(PublicreportWaterImages.Columns.WaterID).OP("IN", PKArgExpr)), )...) } -func insertPublicreportPoolNotifyEmailPools0(ctx context.Context, exec bob.Executor, publicreportNotifyEmailPools1 []*PublicreportNotifyEmailPoolSetter, publicreportPool0 *PublicreportPool) (PublicreportNotifyEmailPoolSlice, error) { - for i := range publicreportNotifyEmailPools1 { - publicreportNotifyEmailPools1[i].PoolID = omit.From(publicreportPool0.ID) +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 := PublicreportNotifyEmailPools.Insert(bob.ToMods(publicreportNotifyEmailPools1...)).All(ctx, exec) + ret, err := PublicreportNotifyEmailWaters.Insert(bob.ToMods(publicreportNotifyEmailWaters1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertPublicreportPoolNotifyEmailPools0: %w", err) + return ret, fmt.Errorf("insertPublicreportWaterNotifyEmailWaters0: %w", err) } return ret, nil } -func attachPublicreportPoolNotifyEmailPools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailPools1 PublicreportNotifyEmailPoolSlice, publicreportPool0 *PublicreportPool) (PublicreportNotifyEmailPoolSlice, error) { - setter := &PublicreportNotifyEmailPoolSetter{ - PoolID: omit.From(publicreportPool0.ID), +func attachPublicreportWaterNotifyEmailWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyEmailWaters1 PublicreportNotifyEmailWaterSlice, publicreportWater0 *PublicreportWater) (PublicreportNotifyEmailWaterSlice, error) { + setter := &PublicreportNotifyEmailWaterSetter{ + WaterID: omit.From(publicreportWater0.ID), } - err := publicreportNotifyEmailPools1.UpdateAll(ctx, exec, *setter) + err := publicreportNotifyEmailWaters1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachPublicreportPoolNotifyEmailPools0: %w", err) + return nil, fmt.Errorf("attachPublicreportWaterNotifyEmailWaters0: %w", err) } - return publicreportNotifyEmailPools1, nil + return publicreportNotifyEmailWaters1, nil } -func (publicreportPool0 *PublicreportPool) InsertNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPoolSetter) error { +func (publicreportWater0 *PublicreportWater) InsertNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWaterSetter) error { if len(related) == 0 { return nil } var err error - publicreportNotifyEmailPools1, err := insertPublicreportPoolNotifyEmailPools0(ctx, exec, related, publicreportPool0) + publicreportNotifyEmailWaters1, err := insertPublicreportWaterNotifyEmailWaters0(ctx, exec, related, publicreportWater0) if err != nil { return err } - publicreportPool0.R.NotifyEmailPools = append(publicreportPool0.R.NotifyEmailPools, publicreportNotifyEmailPools1...) + publicreportWater0.R.NotifyEmailWaters = append(publicreportWater0.R.NotifyEmailWaters, publicreportNotifyEmailWaters1...) - for _, rel := range publicreportNotifyEmailPools1 { - rel.R.Pool = publicreportPool0 + for _, rel := range publicreportNotifyEmailWaters1 { + rel.R.Water = publicreportWater0 } return nil } -func (publicreportPool0 *PublicreportPool) AttachNotifyEmailPools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailPool) error { +func (publicreportWater0 *PublicreportWater) AttachNotifyEmailWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyEmailWater) error { if len(related) == 0 { return nil } var err error - publicreportNotifyEmailPools1 := PublicreportNotifyEmailPoolSlice(related) + publicreportNotifyEmailWaters1 := PublicreportNotifyEmailWaterSlice(related) - _, err = attachPublicreportPoolNotifyEmailPools0(ctx, exec, len(related), publicreportNotifyEmailPools1, publicreportPool0) + _, err = attachPublicreportWaterNotifyEmailWaters0(ctx, exec, len(related), publicreportNotifyEmailWaters1, publicreportWater0) if err != nil { return err } - publicreportPool0.R.NotifyEmailPools = append(publicreportPool0.R.NotifyEmailPools, publicreportNotifyEmailPools1...) + publicreportWater0.R.NotifyEmailWaters = append(publicreportWater0.R.NotifyEmailWaters, publicreportNotifyEmailWaters1...) for _, rel := range related { - rel.R.Pool = publicreportPool0 + rel.R.Water = publicreportWater0 } return nil } -func insertPublicreportPoolNotifyPhonePools0(ctx context.Context, exec bob.Executor, publicreportNotifyPhonePools1 []*PublicreportNotifyPhonePoolSetter, publicreportPool0 *PublicreportPool) (PublicreportNotifyPhonePoolSlice, error) { - for i := range publicreportNotifyPhonePools1 { - publicreportNotifyPhonePools1[i].PoolID = omit.From(publicreportPool0.ID) +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 := PublicreportNotifyPhonePools.Insert(bob.ToMods(publicreportNotifyPhonePools1...)).All(ctx, exec) + ret, err := PublicreportNotifyPhoneWaters.Insert(bob.ToMods(publicreportNotifyPhoneWaters1...)).All(ctx, exec) if err != nil { - return ret, fmt.Errorf("insertPublicreportPoolNotifyPhonePools0: %w", err) + return ret, fmt.Errorf("insertPublicreportWaterNotifyPhoneWaters0: %w", err) } return ret, nil } -func attachPublicreportPoolNotifyPhonePools0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhonePools1 PublicreportNotifyPhonePoolSlice, publicreportPool0 *PublicreportPool) (PublicreportNotifyPhonePoolSlice, error) { - setter := &PublicreportNotifyPhonePoolSetter{ - PoolID: omit.From(publicreportPool0.ID), +func attachPublicreportWaterNotifyPhoneWaters0(ctx context.Context, exec bob.Executor, count int, publicreportNotifyPhoneWaters1 PublicreportNotifyPhoneWaterSlice, publicreportWater0 *PublicreportWater) (PublicreportNotifyPhoneWaterSlice, error) { + setter := &PublicreportNotifyPhoneWaterSetter{ + WaterID: omit.From(publicreportWater0.ID), } - err := publicreportNotifyPhonePools1.UpdateAll(ctx, exec, *setter) + err := publicreportNotifyPhoneWaters1.UpdateAll(ctx, exec, *setter) if err != nil { - return nil, fmt.Errorf("attachPublicreportPoolNotifyPhonePools0: %w", err) + return nil, fmt.Errorf("attachPublicreportWaterNotifyPhoneWaters0: %w", err) } - return publicreportNotifyPhonePools1, nil + return publicreportNotifyPhoneWaters1, nil } -func (publicreportPool0 *PublicreportPool) InsertNotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePoolSetter) error { +func (publicreportWater0 *PublicreportWater) InsertNotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWaterSetter) error { if len(related) == 0 { return nil } var err error - publicreportNotifyPhonePools1, err := insertPublicreportPoolNotifyPhonePools0(ctx, exec, related, publicreportPool0) + publicreportNotifyPhoneWaters1, err := insertPublicreportWaterNotifyPhoneWaters0(ctx, exec, related, publicreportWater0) if err != nil { return err } - publicreportPool0.R.NotifyPhonePools = append(publicreportPool0.R.NotifyPhonePools, publicreportNotifyPhonePools1...) + publicreportWater0.R.NotifyPhoneWaters = append(publicreportWater0.R.NotifyPhoneWaters, publicreportNotifyPhoneWaters1...) - for _, rel := range publicreportNotifyPhonePools1 { - rel.R.Pool = publicreportPool0 + for _, rel := range publicreportNotifyPhoneWaters1 { + rel.R.Water = publicreportWater0 } return nil } -func (publicreportPool0 *PublicreportPool) AttachNotifyPhonePools(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhonePool) error { +func (publicreportWater0 *PublicreportWater) AttachNotifyPhoneWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportNotifyPhoneWater) error { if len(related) == 0 { return nil } var err error - publicreportNotifyPhonePools1 := PublicreportNotifyPhonePoolSlice(related) + publicreportNotifyPhoneWaters1 := PublicreportNotifyPhoneWaterSlice(related) - _, err = attachPublicreportPoolNotifyPhonePools0(ctx, exec, len(related), publicreportNotifyPhonePools1, publicreportPool0) + _, err = attachPublicreportWaterNotifyPhoneWaters0(ctx, exec, len(related), publicreportNotifyPhoneWaters1, publicreportWater0) if err != nil { return err } - publicreportPool0.R.NotifyPhonePools = append(publicreportPool0.R.NotifyPhonePools, publicreportNotifyPhonePools1...) + publicreportWater0.R.NotifyPhoneWaters = append(publicreportWater0.R.NotifyPhoneWaters, publicreportNotifyPhoneWaters1...) for _, rel := range related { - rel.R.Pool = publicreportPool0 + rel.R.Water = publicreportWater0 } return nil } -func attachPublicreportPoolOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportPool0 *PublicreportPool, organization1 *Organization) (*PublicreportPool, error) { - setter := &PublicreportPoolSetter{ +func attachPublicreportWaterAddress0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, address1 *Address) (*PublicreportWater, error) { + setter := &PublicreportWaterSetter{ + AddressID: omitnull.From(address1.ID), + } + + err := publicreportWater0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachPublicreportWaterAddress0: %w", err) + } + + return publicreportWater0, nil +} + +func (publicreportWater0 *PublicreportWater) 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 = attachPublicreportWaterAddress0(ctx, exec, 1, publicreportWater0, address1) + if err != nil { + return err + } + + publicreportWater0.R.Address = address1 + + address1.R.Waters = append(address1.R.Waters, publicreportWater0) + + return nil +} + +func (publicreportWater0 *PublicreportWater) AttachAddress(ctx context.Context, exec bob.Executor, address1 *Address) error { + var err error + + _, err = attachPublicreportWaterAddress0(ctx, exec, 1, publicreportWater0, address1) + if err != nil { + return err + } + + publicreportWater0.R.Address = address1 + + 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: omitnull.From(organization1.ID), } - err := publicreportPool0.Update(ctx, exec, setter) + err := publicreportWater0.Update(ctx, exec, setter) if err != nil { - return nil, fmt.Errorf("attachPublicreportPoolOrganization0: %w", err) + return nil, fmt.Errorf("attachPublicreportWaterOrganization0: %w", err) } - return publicreportPool0, nil + return publicreportWater0, nil } -func (publicreportPool0 *PublicreportPool) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { +func (publicreportWater0 *PublicreportWater) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { var err error organization1, err := Organizations.Insert(related).One(ctx, exec) @@ -1392,51 +1488,51 @@ func (publicreportPool0 *PublicreportPool) InsertOrganization(ctx context.Contex return fmt.Errorf("inserting related objects: %w", err) } - _, err = attachPublicreportPoolOrganization0(ctx, exec, 1, publicreportPool0, organization1) + _, err = attachPublicreportWaterOrganization0(ctx, exec, 1, publicreportWater0, organization1) if err != nil { return err } - publicreportPool0.R.Organization = organization1 + publicreportWater0.R.Organization = organization1 - organization1.R.PublicreportPool = append(organization1.R.PublicreportPool, publicreportPool0) + organization1.R.Waters = append(organization1.R.Waters, publicreportWater0) return nil } -func (publicreportPool0 *PublicreportPool) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { +func (publicreportWater0 *PublicreportWater) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { var err error - _, err = attachPublicreportPoolOrganization0(ctx, exec, 1, publicreportPool0, organization1) + _, err = attachPublicreportWaterOrganization0(ctx, exec, 1, publicreportWater0, organization1) if err != nil { return err } - publicreportPool0.R.Organization = organization1 + publicreportWater0.R.Organization = organization1 - organization1.R.PublicreportPool = append(organization1.R.PublicreportPool, publicreportPool0) + organization1.R.Waters = append(organization1.R.Waters, publicreportWater0) return nil } -func attachPublicreportPoolImages0(ctx context.Context, exec bob.Executor, count int, publicreportPool0 *PublicreportPool, publicreportImages2 PublicreportImageSlice) (PublicreportPoolImageSlice, error) { - setters := make([]*PublicreportPoolImageSetter, count) +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] = &PublicreportPoolImageSetter{ - PoolID: omit.From(publicreportPool0.ID), + setters[i] = &PublicreportWaterImageSetter{ + WaterID: omit.From(publicreportWater0.ID), ImageID: omit.From(publicreportImages2[i].ID), } } - publicreportPoolImages1, err := PublicreportPoolImages.Insert(bob.ToMods(setters...)).All(ctx, exec) + publicreportWaterImages1, err := PublicreportWaterImages.Insert(bob.ToMods(setters...)).All(ctx, exec) if err != nil { - return nil, fmt.Errorf("attachPublicreportPoolImages0: %w", err) + return nil, fmt.Errorf("attachPublicreportWaterImages0: %w", err) } - return publicreportPoolImages1, nil + return publicreportWaterImages1, nil } -func (publicreportPool0 *PublicreportPool) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { +func (publicreportWater0 *PublicreportWater) InsertImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImageSetter) error { if len(related) == 0 { return nil } @@ -1449,20 +1545,20 @@ func (publicreportPool0 *PublicreportPool) InsertImages(ctx context.Context, exe } publicreportImages2 := PublicreportImageSlice(inserted) - _, err = attachPublicreportPoolImages0(ctx, exec, len(related), publicreportPool0, publicreportImages2) + _, err = attachPublicreportWaterImages0(ctx, exec, len(related), publicreportWater0, publicreportImages2) if err != nil { return err } - publicreportPool0.R.Images = append(publicreportPool0.R.Images, publicreportImages2...) + publicreportWater0.R.Images = append(publicreportWater0.R.Images, publicreportImages2...) for _, rel := range publicreportImages2 { - rel.R.Pools = append(rel.R.Pools, publicreportPool0) + rel.R.Waters = append(rel.R.Waters, publicreportWater0) } return nil } -func (publicreportPool0 *PublicreportPool) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { +func (publicreportWater0 *PublicreportWater) AttachImages(ctx context.Context, exec bob.Executor, related ...*PublicreportImage) error { if len(related) == 0 { return nil } @@ -1470,21 +1566,21 @@ func (publicreportPool0 *PublicreportPool) AttachImages(ctx context.Context, exe var err error publicreportImages2 := PublicreportImageSlice(related) - _, err = attachPublicreportPoolImages0(ctx, exec, len(related), publicreportPool0, publicreportImages2) + _, err = attachPublicreportWaterImages0(ctx, exec, len(related), publicreportWater0, publicreportImages2) if err != nil { return err } - publicreportPool0.R.Images = append(publicreportPool0.R.Images, publicreportImages2...) + publicreportWater0.R.Images = append(publicreportWater0.R.Images, publicreportImages2...) for _, rel := range related { - rel.R.Pools = append(rel.R.Pools, publicreportPool0) + rel.R.Waters = append(rel.R.Waters, publicreportWater0) } return nil } -type publicreportPoolWhere[Q psql.Filterable] struct { +type publicreportWaterWhere[Q psql.Filterable] struct { ID psql.WhereMod[Q, int32] AccessComments psql.WhereMod[Q, string] AccessGate psql.WhereMod[Q, bool] @@ -1492,10 +1588,10 @@ type publicreportPoolWhere[Q psql.Filterable] struct { AccessLocked psql.WhereMod[Q, bool] AccessDog psql.WhereMod[Q, bool] AccessOther psql.WhereMod[Q, bool] - Address psql.WhereMod[Q, string] + AddressRaw psql.WhereMod[Q, string] AddressCountry psql.WhereMod[Q, string] - AddressPostCode psql.WhereMod[Q, string] - AddressPlace 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] @@ -1520,14 +1616,15 @@ type publicreportPoolWhere[Q psql.Filterable] struct { ReporterContactConsent psql.WhereNullMod[Q, bool] Location psql.WhereNullMod[Q, string] AddressNumber psql.WhereMod[Q, string] + AddressID psql.WhereNullMod[Q, int32] } -func (publicreportPoolWhere[Q]) AliasedAs(alias string) publicreportPoolWhere[Q] { - return buildPublicreportPoolWhere[Q](buildPublicreportPoolColumns(alias)) +func (publicreportWaterWhere[Q]) AliasedAs(alias string) publicreportWaterWhere[Q] { + return buildPublicreportWaterWhere[Q](buildPublicreportWaterColumns(alias)) } -func buildPublicreportPoolWhere[Q psql.Filterable](cols publicreportPoolColumns) publicreportPoolWhere[Q] { - return publicreportPoolWhere[Q]{ +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), @@ -1535,10 +1632,10 @@ func buildPublicreportPoolWhere[Q psql.Filterable](cols publicreportPoolColumns) AccessLocked: psql.Where[Q, bool](cols.AccessLocked), AccessDog: psql.Where[Q, bool](cols.AccessDog), AccessOther: psql.Where[Q, bool](cols.AccessOther), - Address: psql.Where[Q, string](cols.Address), + AddressRaw: psql.Where[Q, string](cols.AddressRaw), AddressCountry: psql.Where[Q, string](cols.AddressCountry), - AddressPostCode: psql.Where[Q, string](cols.AddressPostCode), - AddressPlace: psql.Where[Q, string](cols.AddressPlace), + 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), @@ -1563,86 +1660,113 @@ func buildPublicreportPoolWhere[Q psql.Filterable](cols publicreportPoolColumns) 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), } } -func (o *PublicreportPool) Preload(name string, retrieved any) error { +func (o *PublicreportWater) Preload(name string, retrieved any) error { if o == nil { return nil } switch name { - case "NotifyEmailPools": - rels, ok := retrieved.(PublicreportNotifyEmailPoolSlice) + case "NotifyEmailWaters": + rels, ok := retrieved.(PublicreportNotifyEmailWaterSlice) if !ok { - return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name) + return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) } - o.R.NotifyEmailPools = rels + o.R.NotifyEmailWaters = rels for _, rel := range rels { if rel != nil { - rel.R.Pool = o + rel.R.Water = o } } return nil - case "NotifyPhonePools": - rels, ok := retrieved.(PublicreportNotifyPhonePoolSlice) + case "NotifyPhoneWaters": + rels, ok := retrieved.(PublicreportNotifyPhoneWaterSlice) if !ok { - return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name) + return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) } - o.R.NotifyPhonePools = rels + o.R.NotifyPhoneWaters = rels for _, rel := range rels { if rel != nil { - rel.R.Pool = o + 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 + + if rel != nil { + rel.R.Waters = PublicreportWaterSlice{o} + } + return nil case "Organization": rel, ok := retrieved.(*Organization) if !ok { - return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name) + return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) } o.R.Organization = rel if rel != nil { - rel.R.PublicreportPool = PublicreportPoolSlice{o} + rel.R.Waters = PublicreportWaterSlice{o} } return nil case "Images": rels, ok := retrieved.(PublicreportImageSlice) if !ok { - return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name) + return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name) } o.R.Images = rels for _, rel := range rels { if rel != nil { - rel.R.Pools = PublicreportPoolSlice{o} + rel.R.Waters = PublicreportWaterSlice{o} } } return nil default: - return fmt.Errorf("publicreportPool has no relationship %q", name) + return fmt.Errorf("publicreportWater has no relationship %q", name) } } -type publicreportPoolPreloader struct { +type publicreportWaterPreloader struct { + Address func(...psql.PreloadOption) psql.Preloader Organization func(...psql.PreloadOption) psql.Preloader } -func buildPublicreportPoolPreloader() publicreportPoolPreloader { - return publicreportPoolPreloader{ +func buildPublicreportWaterPreloader() publicreportWaterPreloader { + return publicreportWaterPreloader{ + Address: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Address, AddressSlice](psql.PreloadRel{ + Name: "Address", + Sides: []psql.PreloadSide{ + { + From: PublicreportWaters, + 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: PublicreportPools, + From: PublicreportWaters, To: Organizations, FromColumns: []string{"organization_id"}, ToColumns: []string{"id"}, @@ -1653,19 +1777,23 @@ func buildPublicreportPoolPreloader() publicreportPoolPreloader { } } -type publicreportPoolThenLoader[Q orm.Loadable] struct { - NotifyEmailPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +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] + Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } -func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoader[Q] { - type NotifyEmailPoolsLoadInterface interface { - LoadNotifyEmailPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error +func buildPublicreportWaterThenLoader[Q orm.Loadable]() publicreportWaterThenLoader[Q] { + type NotifyEmailWatersLoadInterface interface { + LoadNotifyEmailWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type NotifyPhonePoolsLoadInterface interface { - LoadNotifyPhonePools(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 @@ -1674,17 +1802,23 @@ func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoade LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - return publicreportPoolThenLoader[Q]{ - NotifyEmailPools: thenLoadBuilder[Q]( - "NotifyEmailPools", - func(ctx context.Context, exec bob.Executor, retrieved NotifyEmailPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadNotifyEmailPools(ctx, exec, mods...) + 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...) }, ), - NotifyPhonePools: thenLoadBuilder[Q]( - "NotifyPhonePools", - func(ctx context.Context, exec bob.Executor, retrieved NotifyPhonePoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadNotifyPhonePools(ctx, exec, mods...) + 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]( @@ -1702,35 +1836,35 @@ func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoade } } -// LoadNotifyEmailPools loads the publicreportPool's NotifyEmailPools into the .R struct -func (o *PublicreportPool) LoadNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if o == nil { return nil } // Reset the relationship - o.R.NotifyEmailPools = nil + o.R.NotifyEmailWaters = nil - related, err := o.NotifyEmailPools(mods...).All(ctx, exec) + related, err := o.NotifyEmailWaters(mods...).All(ctx, exec) if err != nil { return err } for _, rel := range related { - rel.R.Pool = o + rel.R.Water = o } - o.R.NotifyEmailPools = related + o.R.NotifyEmailWaters = related return nil } -// LoadNotifyEmailPools loads the publicreportPool's NotifyEmailPools into the .R struct -func (os PublicreportPoolSlice) LoadNotifyEmailPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 { if len(os) == 0 { return nil } - publicreportNotifyEmailPools, err := os.NotifyEmailPools(mods...).All(ctx, exec) + publicreportNotifyEmailWaters, err := os.NotifyEmailWaters(mods...).All(ctx, exec) if err != nil { return err } @@ -1740,7 +1874,7 @@ func (os PublicreportPoolSlice) LoadNotifyEmailPools(ctx context.Context, exec b continue } - o.R.NotifyEmailPools = nil + o.R.NotifyEmailWaters = nil } for _, o := range os { @@ -1748,50 +1882,50 @@ func (os PublicreportPoolSlice) LoadNotifyEmailPools(ctx context.Context, exec b continue } - for _, rel := range publicreportNotifyEmailPools { + for _, rel := range publicreportNotifyEmailWaters { - if !(o.ID == rel.PoolID) { + if !(o.ID == rel.WaterID) { continue } - rel.R.Pool = o + rel.R.Water = o - o.R.NotifyEmailPools = append(o.R.NotifyEmailPools, rel) + o.R.NotifyEmailWaters = append(o.R.NotifyEmailWaters, rel) } } return nil } -// LoadNotifyPhonePools loads the publicreportPool's NotifyPhonePools into the .R struct -func (o *PublicreportPool) LoadNotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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.NotifyPhonePools = nil + o.R.NotifyPhoneWaters = nil - related, err := o.NotifyPhonePools(mods...).All(ctx, exec) + related, err := o.NotifyPhoneWaters(mods...).All(ctx, exec) if err != nil { return err } for _, rel := range related { - rel.R.Pool = o + rel.R.Water = o } - o.R.NotifyPhonePools = related + o.R.NotifyPhoneWaters = related return nil } -// LoadNotifyPhonePools loads the publicreportPool's NotifyPhonePools into the .R struct -func (os PublicreportPoolSlice) LoadNotifyPhonePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 } - publicreportNotifyPhonePools, err := os.NotifyPhonePools(mods...).All(ctx, exec) + publicreportNotifyPhoneWaters, err := os.NotifyPhoneWaters(mods...).All(ctx, exec) if err != nil { return err } @@ -1801,7 +1935,7 @@ func (os PublicreportPoolSlice) LoadNotifyPhonePools(ctx context.Context, exec b continue } - o.R.NotifyPhonePools = nil + o.R.NotifyPhoneWaters = nil } for _, o := range os { @@ -1809,23 +1943,78 @@ func (os PublicreportPoolSlice) LoadNotifyPhonePools(ctx context.Context, exec b continue } - for _, rel := range publicreportNotifyPhonePools { + for _, rel := range publicreportNotifyPhoneWaters { - if !(o.ID == rel.PoolID) { + if !(o.ID == rel.WaterID) { continue } - rel.R.Pool = o + rel.R.Water = o - o.R.NotifyPhonePools = append(o.R.NotifyPhonePools, rel) + o.R.NotifyPhoneWaters = append(o.R.NotifyPhoneWaters, rel) } } return nil } -// LoadOrganization loads the publicreportPool's Organization into the .R struct -func (o *PublicreportPool) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 + 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 } @@ -1838,14 +2027,14 @@ func (o *PublicreportPool) LoadOrganization(ctx context.Context, exec bob.Execut return err } - related.R.PublicreportPool = PublicreportPoolSlice{o} + related.R.Waters = PublicreportWaterSlice{o} o.R.Organization = related return nil } -// LoadOrganization loads the publicreportPool's Organization into the .R struct -func (os PublicreportPoolSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 } @@ -1869,7 +2058,7 @@ func (os PublicreportPoolSlice) LoadOrganization(ctx context.Context, exec bob.E continue } - rel.R.PublicreportPool = append(rel.R.PublicreportPool, o) + rel.R.Waters = append(rel.R.Waters, o) o.R.Organization = rel break @@ -1879,8 +2068,8 @@ func (os PublicreportPoolSlice) LoadOrganization(ctx context.Context, exec bob.E return nil } -// LoadImages loads the publicreportPool's Images into the .R struct -func (o *PublicreportPool) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 } @@ -1894,15 +2083,15 @@ func (o *PublicreportPool) LoadImages(ctx context.Context, exec bob.Executor, mo } for _, rel := range related { - rel.R.Pools = PublicreportPoolSlice{o} + rel.R.Waters = PublicreportWaterSlice{o} } o.R.Images = related return nil } -// LoadImages loads the publicreportPool's Images into the .R struct -func (os PublicreportPoolSlice) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { +// 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 } @@ -1919,7 +2108,7 @@ func (os PublicreportPoolSlice) LoadImages(ctx context.Context, exec bob.Executo q := os.Images(append( mods, - sm.Columns(PublicreportPoolImages.Columns.PoolID.As("related_publicreport.pool.ID")), + sm.Columns(PublicreportWaterImages.Columns.WaterID.As("related_publicreport.water.ID")), )...) IDSlice := []int32{} @@ -1927,7 +2116,7 @@ func (os PublicreportPoolSlice) LoadImages(ctx context.Context, exec bob.Executo 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.pool.ID", &IDSlice[len(IDSlice)-1]) + row.ScheduleScanByName("related_publicreport.water.ID", &IDSlice[len(IDSlice)-1]) return nil, nil }, @@ -1951,7 +2140,7 @@ func (os PublicreportPoolSlice) LoadImages(ctx context.Context, exec bob.Executo continue } - rel.R.Pools = append(rel.R.Pools, o) + rel.R.Waters = append(rel.R.Waters, o) o.R.Images = append(o.R.Images, rel) } diff --git a/db/models/publicreport.water_image.bob.go b/db/models/publicreport.water_image.bob.go new file mode 100644 index 00000000..924f7c68 --- /dev/null +++ b/db/models/publicreport.water_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" +) + +// 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/sql/publicreport_image_with_json_by_pool_id.bob.go b/db/sql/publicreport_image_with_json_by_pool_id.bob.go deleted file mode 100644 index 3128bfd8..00000000 --- a/db/sql/publicreport_image_with_json_by_pool_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_pool_id.bob.sql -var formattedQueries_publicreport_image_with_json_by_pool_id string - -var publicreportImageWithJSONByPoolIDSQL = formattedQueries_publicreport_image_with_json_by_pool_id[171:975] - -type PublicreportImageWithJSONByPoolIDQuery = orm.ModQuery[*dialect.SelectQuery, publicreportImageWithJSONByPoolID, PublicreportImageWithJSONByPoolIDRow, []PublicreportImageWithJSONByPoolIDRow, publicreportImageWithJSONByPoolIDTransformer] - -func PublicreportImageWithJSONByPoolID(PoolID int32) *PublicreportImageWithJSONByPoolIDQuery { - var expressionTypArgs publicreportImageWithJSONByPoolID - - expressionTypArgs.PoolID = psql.Arg(PoolID) - - return &PublicreportImageWithJSONByPoolIDQuery{ - Query: orm.Query[publicreportImageWithJSONByPoolID, PublicreportImageWithJSONByPoolIDRow, []PublicreportImageWithJSONByPoolIDRow, publicreportImageWithJSONByPoolIDTransformer]{ - ExecQuery: orm.ExecQuery[publicreportImageWithJSONByPoolID]{ - BaseQuery: bob.BaseQuery[publicreportImageWithJSONByPoolID]{ - Expression: expressionTypArgs, - Dialect: dialect.Dialect, - QueryType: bob.QueryTypeSelect, - }, - }, - Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (PublicreportImageWithJSONByPoolIDRow, error)) { - return func(row *scan.Row) (any, error) { - var t PublicreportImageWithJSONByPoolIDRow - 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) (PublicreportImageWithJSONByPoolIDRow, error) { - return *(v.(*PublicreportImageWithJSONByPoolIDRow)), nil - } - }, - }, - Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) { - q.AppendSelect(expressionTypArgs.subExpr(9, 565)) - q.SetTable(expressionTypArgs.subExpr(571, 755)) - q.AppendWhere(expressionTypArgs.subExpr(763, 803)) - }), - } -} - -type PublicreportImageWithJSONByPoolIDRow = 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 publicreportImageWithJSONByPoolIDTransformer = bob.SliceTransformer[PublicreportImageWithJSONByPoolIDRow, []PublicreportImageWithJSONByPoolIDRow] - -type publicreportImageWithJSONByPoolID struct { - PoolID bob.Expression -} - -func (o publicreportImageWithJSONByPoolID) args() iter.Seq[orm.ArgWithPosition] { - return func(yield func(arg orm.ArgWithPosition) bool) { - if !yield(orm.ArgWithPosition{ - Name: "poolID", - Start: 801, - Stop: 803, - Expression: o.PoolID, - }) { - return - } - } -} - -func (o publicreportImageWithJSONByPoolID) raw(from, to int) string { - return publicreportImageWithJSONByPoolIDSQL[from:to] -} - -func (o publicreportImageWithJSONByPoolID) subExpr(from, to int) bob.Expression { - return orm.ArgsToExpression(publicreportImageWithJSONByPoolIDSQL, from, to, o.args()) -} - -func (o publicreportImageWithJSONByPoolID) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - return o.subExpr(0, len(publicreportImageWithJSONByPoolIDSQL)).WriteSQL(ctx, w, d, start) -} diff --git a/db/sql/publicreport_image_with_json_by_pool_id.bob.sql b/db/sql/publicreport_image_with_json_by_pool_id.bob.sql deleted file mode 100644 index d9b052b2..00000000 --- a/db/sql/publicreport_image_with_json_by_pool_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. - --- PublicreportImageWithJSONByPoolID -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"."pool_image" AS "publicreport.pool_image" ON ("publicreport.image"."id" = "publicreport.pool_image"."image_id") -WHERE ("publicreport.pool_image"."pool_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 new file mode 100644 index 00000000..30b16a93 --- /dev/null +++ b/db/sql/publicreport_image_with_json_by_water_id.bob.go @@ -0,0 +1,112 @@ +// 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_pool_id.sql b/db/sql/publicreport_image_with_json_by_water_id.sql similarity index 72% rename from db/sql/publicreport_image_with_json_by_pool_id.sql rename to db/sql/publicreport_image_with_json_by_water_id.sql index 08d57455..1ec6949e 100644 --- a/db/sql/publicreport_image_with_json_by_pool_id.sql +++ b/db/sql/publicreport_image_with_json_by_water_id.sql @@ -1,4 +1,4 @@ --- PublicreportImageWithJSONByPoolID +-- PublicreportImageWithJSONByWaterID SELECT "publicreport.image"."id" AS "id", "publicreport.image"."content_type" AS "content_type", @@ -11,5 +11,5 @@ SELECT "publicreport.image"."storage_size" AS "storage_size", "publicreport.image"."uploaded_filename" AS "uploaded_filename" FROM "publicreport"."image" AS "publicreport.image" -INNER JOIN "publicreport"."pool_image" AS "publicreport.pool_image" ON ("publicreport.image"."id" = "publicreport.pool_image"."image_id") -WHERE ("publicreport.pool_image"."pool_id" = $1) +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 index 23515444..4bf153c2 100644 --- a/db/sql/publicreport_publicid_suggestion.bob.go +++ b/db/sql/publicreport_publicid_suggestion.bob.go @@ -21,7 +21,7 @@ import ( //go:embed publicreport_publicid_suggestion.bob.sql var formattedQueries_publicreport_publicid_suggestion string -var publicreportPublicIDSuggestionSQL = formattedQueries_publicreport_publicid_suggestion[168:426] +var publicreportPublicIDSuggestionSQL = formattedQueries_publicreport_publicid_suggestion[168:428] type PublicreportPublicIDSuggestionQuery = orm.ModQuery[*dialect.SelectQuery, publicreportPublicIDSuggestion, PublicreportPublicIDSuggestionRow, []PublicreportPublicIDSuggestionRow, publicreportPublicIDSuggestionTransformer] @@ -60,12 +60,12 @@ func PublicreportPublicIDSuggestion(Arg1 string) *PublicreportPublicIDSuggestion Strategy: "UNION", All: true, Query: bob.BaseQuery[bob.Expression]{ - Expression: expressionTypArgs.subExpr(129, 237), + Expression: expressionTypArgs.subExpr(129, 239), QueryType: bob.QueryTypeSelect, Dialect: dialect.Dialect, }, }) - q.CombinedOrder.AppendOrder(expressionTypArgs.subExpr(249, 258)) + q.CombinedOrder.AppendOrder(expressionTypArgs.subExpr(251, 260)) }), } } @@ -95,8 +95,8 @@ func (o publicreportPublicIDSuggestion) args() iter.Seq[orm.ArgWithPosition] { if !yield(orm.ArgWithPosition{ Name: "arg1", - Start: 235, - Stop: 237, + Start: 237, + Stop: 239, Expression: o.Arg1, }) { return diff --git a/db/sql/publicreport_publicid_suggestion.bob.sql b/db/sql/publicreport_publicid_suggestion.bob.sql index 75de3064..2311ddd1 100644 --- a/db/sql/publicreport_publicid_suggestion.bob.sql +++ b/db/sql/publicreport_publicid_suggestion.bob.sql @@ -14,11 +14,11 @@ WHERE UNION ALL SELECT - 'pool' AS table_name, + 'water' AS table_name, public_id, location FROM - publicreport.pool + publicreport.water WHERE public_id LIKE $2 ORDER BY diff --git a/db/sql/publicreport_publicid_suggestion.sql b/db/sql/publicreport_publicid_suggestion.sql index a81f07fe..9fbfb9a0 100644 --- a/db/sql/publicreport_publicid_suggestion.sql +++ b/db/sql/publicreport_publicid_suggestion.sql @@ -11,11 +11,11 @@ WHERE UNION ALL SELECT - 'pool' AS table_name, + 'water' AS table_name, public_id, location FROM - publicreport.pool + publicreport.water WHERE public_id LIKE $1 ORDER BY diff --git a/db/sql/publicreport_publicid_table.bob.go b/db/sql/publicreport_publicid_table.bob.go index 48050e1b..a8b23cbc 100644 --- a/db/sql/publicreport_publicid_table.bob.go +++ b/db/sql/publicreport_publicid_table.bob.go @@ -20,7 +20,7 @@ import ( //go:embed publicreport_publicid_table.bob.sql var formattedQueries_publicreport_publicid_table string -var publicreportIDTableSQL = formattedQueries_publicreport_publicid_table[157:534] +var publicreportIDTableSQL = formattedQueries_publicreport_publicid_table[157:536] type PublicreportIDTableQuery = orm.ModQuery[*dialect.SelectQuery, publicreportIDTable, PublicreportIDTableRow, []PublicreportIDTableRow, publicreportIDTableTransformer] @@ -51,9 +51,9 @@ func PublicreportIDTable(PublicID string) *PublicreportIDTableQuery { }, }, Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) { - q.AppendCTE(expressionTypArgs.subExpr(5, 221)) - q.AppendSelect(expressionTypArgs.subExpr(231, 359)) - q.SetTable(expressionTypArgs.subExpr(365, 377)) + q.AppendCTE(expressionTypArgs.subExpr(5, 223)) + q.AppendSelect(expressionTypArgs.subExpr(233, 361)) + q.SetTable(expressionTypArgs.subExpr(367, 379)) }), } } @@ -83,8 +83,8 @@ func (o publicreportIDTable) args() iter.Seq[orm.ArgWithPosition] { if !yield(orm.ArgWithPosition{ Name: "publicID", - Start: 217, - Stop: 219, + Start: 219, + Stop: 221, Expression: o.PublicID, }) { return diff --git a/db/sql/publicreport_publicid_table.bob.sql b/db/sql/publicreport_publicid_table.bob.sql index 006ce6c0..2c9c643f 100644 --- a/db/sql/publicreport_publicid_table.bob.sql +++ b/db/sql/publicreport_publicid_table.bob.sql @@ -12,9 +12,9 @@ WITH found_tables AS ( UNION ALL SELECT - 'pool' as table_name, + 'water' as table_name, id - FROM publicreport.pool + FROM publicreport.water WHERE public_id = $2 ) SELECT diff --git a/db/sql/publicreport_publicid_table.sql b/db/sql/publicreport_publicid_table.sql index d1d8cee5..bd61f040 100644 --- a/db/sql/publicreport_publicid_table.sql +++ b/db/sql/publicreport_publicid_table.sql @@ -9,9 +9,9 @@ WITH found_tables AS ( UNION ALL SELECT - 'pool' as table_name, + 'water' as table_name, id - FROM publicreport.pool + FROM publicreport.water WHERE public_id = $1 ) SELECT diff --git a/html/static/js/address-or-report-suggestion.js b/html/static/js/address-or-report-suggestion.js index ba716a29..de41b5a6 100644 --- a/html/static/js/address-or-report-suggestion.js +++ b/html/static/js/address-or-report-suggestion.js @@ -269,7 +269,7 @@ function _formatReportID(id) { function _formatReportType(type) { if (type == "nuisance") { return "Mosquito Nuisance Report"; - } else if (type == "pool") { + } else if (type == "water") { return "Standing Water Report"; } else { return "Unknown Report Type"; diff --git a/html/static/js/report-table.js b/html/static/js/report-table.js index 2c804921..3ba46e30 100644 --- a/html/static/js/report-table.js +++ b/html/static/js/report-table.js @@ -35,7 +35,7 @@ class ReportTable extends HTMLElement { return "bg-danger"; case "quick": return "bg-primary"; - case "pool": + case "water": return "bg-success"; default: return "bg-secondary"; diff --git a/html/template/rmo/component/map-header.html b/html/template/rmo/component/map-header.html deleted file mode 100644 index fae7974a..00000000 --- a/html/template/rmo/component/map-header.html +++ /dev/null @@ -1,2 +0,0 @@ -{{ define "rmo/component/map-header.html" }} -{{ end }} diff --git a/html/template/rmo/component/map.html b/html/template/rmo/component/map.html deleted file mode 100644 index c4a5840d..00000000 --- a/html/template/rmo/component/map.html +++ /dev/null @@ -1,87 +0,0 @@ -{{ define "rmo/component/map.html" }} - - - - -{{ end }} diff --git a/html/template/rmo/mock/nuisance.html b/html/template/rmo/mock/nuisance.html deleted file mode 100644 index 4f69f5de..00000000 --- a/html/template/rmo/mock/nuisance.html +++ /dev/null @@ -1,525 +0,0 @@ -{{ template "base.html" . }} - -{{ define "title" }}Nuisance{{ end }} -{{ define "extraheader" }} - - - - - - - {{ template "photo-upload-header" }} - - -{{ end }} -{{ define "content" }} - {{ if .District }} - {{ template "header" . }} - {{ end }} -
-
-
-

Report Mosquito Nuisance

-

Help us identify mosquito activity in your area

-
-
- - -
- -
-
- -

Nuisance Location Information

-
-
-
-

- You can select the location by address or by moving the marker on - the map. -

-
-
- -
-
- - -
-
-
-

- You can also click on the map to mark the location precisely -

- - - - -
-
- {{ template "mosquito-color.svg" }} -

Mosquito Activity Information

-
-

- The time when mosquitoes are active can help us identify the species - and likely breeding sources. -

- - -
-
- -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
-
- - -
- -
-
- -

Potential Mosquito Sources

-
-

- Have you noticed any of these common mosquito breeding sources in - your area? -

- -
-
-
Did you know?
-

- Mosquitoes can breed in as little as a bottle cap of water! - Eliminating standing water is the most effective way to reduce - mosquito populations. -

-
-
- -
- -
-
-
-
- -
-
Stagnant Water
-

- Green pools, ponds, fountains, or birdbaths that aren't - maintained -

-
- - -
-
-
-
- - -
-
-
-
- -
-
Containers
-

- Buckets, planters, toys, tires, or any items that collect - rainwater -

-
- - -
-
-
-
- - -
-
-
-
- -
-
Sprinklers & Gutters
-

- Clogged street gutters, yard drains, or AC units that - collect water -

-
- - -
-
-
-
-
- - - -
-
- - - {{ template "photo-upload" }} -
-
-
- -
-
- -

Additional Information

-
- -
-
- - -
-
-
-
- -
-
-
-

- Thank you for reporting this mosquito issue. -

-

- After submission, you'll receive a confirmation with a report ID - and further information. -

-
- -
-
-
-
-{{ end }} diff --git a/html/template/rmo/mock/water.html b/html/template/rmo/mock/water.html deleted file mode 100644 index 662915bc..00000000 --- a/html/template/rmo/mock/water.html +++ /dev/null @@ -1,757 +0,0 @@ -{{ template "base.html" . }} - -{{ define "title" }}Standing Water{{ end }} -{{ define "extraheader" }} - - - - - - - {{ template "photo-upload-header" }} - - -{{ end }} -{{ define "content" }} - {{ if .District }} - {{ template "header" . }} - {{ end }} - -
-
- -
-
-

Report Standing Water

-

- Help us locate and treat potential mosquito production sources in - your area -

-
-
- - -
- -
-
- -

Photos

-
-

- Photos help us identify the severity of the issue and may contain - location data that can help us find the production source. -

-
- {{ template "photo-upload" }} -
-
- - -
-
- -

Additional Information

-
-

- Please provide any other information that might help us address this - mosquito production source. -

- -
-
- - -
-
-
- - -
-
- -

Location

-
-

- Please provide the location of the potential mosquito production - source. We may be able to extract this information from your photos - if they contain location data. -

-
-
-

- You can select the location by address or by moving the marker - on the map. -

-
-
- -
- - - - - - - - - - -
-
- - -
-
-
- -

- You can also click on the map to mark the location precisely -

- - -
- - -
- -
-
- -

Source Details

-
- -
-
- - -
- -
- -
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- -

Access Information

-
-

- Please provide any details about how to access the mosquito - source. This helps our technicians when they visit the site. -

- -
-
- - -
-
- -
-
- -
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
-
-
-
-
- - -
-
- -

Property Owner Information (if known)

-
- -
-
- - -
-
- - -
-
- - -
-
-
-
-
- - -
-
- - -
-
- - -
-
-
-
-
- - -
-
-
-

- Thank you for helping us keep our community safe from - mosquito-borne illnesses. -

-

- After submission, you will receive a confirmation with a report - ID for tracking purposes. -

-
- -
-
-
-
-
- - - -{{ end }} diff --git a/html/template/rmo/nuisance.html b/html/template/rmo/nuisance.html index 6b7adfbb..408f6ebe 100644 --- a/html/template/rmo/nuisance.html +++ b/html/template/rmo/nuisance.html @@ -27,161 +27,176 @@ - + {{ end }} {{ define "content" }} @@ -240,7 +255,7 @@ document.addEventListener('DOMContentLoaded', function() { - + diff --git a/html/template/rmo/water.html b/html/template/rmo/water.html index af3c1737..6d921e36 100644 --- a/html/template/rmo/water.html +++ b/html/template/rmo/water.html @@ -61,7 +61,7 @@ function setLocationInputs(location) { let latlngAccuracyType = document.getElementById('latlng-accuracy-type'); let latlngAccuracyValue = document.getElementById('latlng-accuracy-value'); let number = document.getElementById('address-number'); - let postcode = document.getElementById('address-postcode'); + let postalcode = document.getElementById('address-postalcode'); let place = document.getElementById('address-place'); let region = document.getElementById('address-region'); let street = document.getElementById('address-street'); @@ -71,16 +71,16 @@ function setLocationInputs(location) { const context = props.context || {}; // Populate structured fields - country.value = context.country.name; - latitude.value = props.coordinates.latitude; - longitude.value = props.coordinates.longitude; - latlngAccuracyType.value = props.coordinates.accuracy; - latlngAccuracyValue.value = "0"; - number.value = context.address.address_number; - postcode.value = context.postcode.name; - place.value = context.place.name; - region.value = context.region.name; - street.value = context.street.name; + country.value = context.iso_3166_a3; + latitude.value = location.geometry.coordinates[1]; + longitude.value = location.geometry.coordinates[0]; + latlngAccuracyType.value = props.precision; + latlngAccuracyValue.value = props.distance; + number.value = props.address_components.number; + postalcode.value = props.address_components.postal_code; + locality.value = context.locality.name; + region.value = props.context.whosonfirst.region.abbreviation; + street.value = props.address_components.street; } function toggleCollapse(something) { el = document.getElementById(something) diff --git a/platform/csv/csv.go b/platform/csv/csv.go index 862fe5f5..f30a52d2 100644 --- a/platform/csv/csv.go +++ b/platform/csv/csv.go @@ -18,6 +18,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/platform/geocode" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" //"github.com/Gleipnir-Technology/nidus-sync/h3utils" //"github.com/Gleipnir-Technology/nidus-sync/platform/geom" //"github.com/Gleipnir-Technology/nidus-sync/platform/text" @@ -53,8 +54,8 @@ func JobCommit(ctx context.Context, file_id int32) error { return fmt.Errorf("Failed to get all rows of file %d: %w", file_id, err) } for _, row := range rows { - a := geocode.Address{ - Country: enums.CountrytypeUsa, + a := types.Address{ + Country: "usa", Locality: row.AddressLocality, Number: row.AddressNumber, PostalCode: row.AddressPostalCode, @@ -62,7 +63,7 @@ func JobCommit(ctx context.Context, file_id int32) error { Street: row.AddressStreet, Unit: "", } - address, err := geocode.EnsureAddress(ctx, txn, org, a) + address, err := geocode.EnsureAddressWithGeocode(ctx, txn, org, a) if err != nil { //return fmt.Errorf("ensure address: %w", err) if address == nil { diff --git a/platform/csv/pool.go b/platform/csv/pool.go index 4975255a..5c6c08e5 100644 --- a/platform/csv/pool.go +++ b/platform/csv/pool.go @@ -19,6 +19,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/platform/geocode" "github.com/Gleipnir-Technology/nidus-sync/platform/geom" "github.com/Gleipnir-Technology/nidus-sync/platform/text" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" "github.com/Gleipnir-Technology/nidus-sync/stadia" "github.com/Gleipnir-Technology/nidus-sync/userfile" "github.com/aarondl/opt/omit" @@ -132,7 +133,7 @@ type jobGeocode struct { func geocodePool(ctx context.Context, txn bob.Tx, client *stadia.StadiaMaps, job *jobGeocode) error { pool := job.pool - a := geocode.Address{ + a := types.Address{ Number: pool.AddressNumber, Locality: pool.AddressLocality, PostalCode: pool.AddressPostalCode, diff --git a/platform/geocode/geocode.go b/platform/geocode/geocode.go index 93713f55..72a17171 100644 --- a/platform/geocode/geocode.go +++ b/platform/geocode/geocode.go @@ -10,35 +10,22 @@ import ( "github.com/Gleipnir-Technology/bob/dialect/psql" "github.com/Gleipnir-Technology/bob/dialect/psql/im" "github.com/Gleipnir-Technology/bob/dialect/psql/sm" - "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/h3utils" + "github.com/Gleipnir-Technology/nidus-sync/platform/types" "github.com/Gleipnir-Technology/nidus-sync/stadia" "github.com/stephenafamo/scan" //"github.com/rs/zerolog/log" "github.com/uber/h3-go/v4" ) -type Address struct { - Country enums.Countrytype - Locality string - Number string - PostalCode string - Region string - Street string - Unit string -} type GeocodeResult struct { - Address Address + Address types.Address Cell h3.Cell Longitude float64 Latitude float64 } -func (a Address) String() string { - return fmt.Sprintf("%s %s, %s, %s, %s, %s", a.Number, a.Street, a.Locality, a.Region, a.PostalCode, a.Country) -} - var client *stadia.StadiaMaps func InitializeStadia(key string) { @@ -47,9 +34,9 @@ func InitializeStadia(key string) { // Either get an address that matches, or create a new address. Either way, return an address // This will make a call to a structured geocode service, so it's slow. -func EnsureAddress(ctx context.Context, txn bob.Tx, org *models.Organization, a Address) (*models.Address, error) { +func EnsureAddressWithGeocode(ctx context.Context, txn bob.Tx, org *models.Organization, a types.Address) (*models.Address, error) { address, err := models.Addresses.Query( - models.SelectWhere.Addresses.Country.EQ(a.Country), + models.SelectWhere.Addresses.Country.EQ(a.CountryEnum()), models.SelectWhere.Addresses.Locality.EQ(a.Locality), models.SelectWhere.Addresses.Number.EQ(a.Number), models.SelectWhere.Addresses.PostalCode.EQ(a.PostalCode), @@ -92,7 +79,7 @@ func EnsureAddress(ctx context.Context, txn bob.Tx, org *models.Organization, a } return &models.Address{ - Country: geo.Address.Country, + Country: geo.Address.CountryEnum(), Created: created, H3cell: "", ID: row.ID, @@ -106,9 +93,9 @@ func EnsureAddress(ctx context.Context, txn bob.Tx, org *models.Organization, a }, nil } -func Geocode(ctx context.Context, org *models.Organization, a Address) (GeocodeResult, error) { +func Geocode(ctx context.Context, org *models.Organization, a types.Address) (GeocodeResult, error) { street := fmt.Sprintf("%s %s", a.Number, a.Street) - country_s := a.Country.String() + country_s := a.Country /* sublog := log.With(). Str("street", street). @@ -148,15 +135,10 @@ func Geocode(ctx context.Context, org *models.Organization, a Address) (GeocodeR if err != nil { return GeocodeResult{}, fmt.Errorf("failed to convert lat %f lng %f to h3 cell", longitude, latitude) } - var country enums.Countrytype country_s = strings.ToLower(feature.Properties.CountryA) - err = country.Scan(country_s) - if err != nil { - return GeocodeResult{}, fmt.Errorf("failed to scan country '%s': %w", country_s, err) - } return GeocodeResult{ - Address: Address{ - Country: country, + Address: types.Address{ + Country: country_s, Locality: feature.Properties.Locality, Number: feature.Properties.HouseNumber, PostalCode: feature.Properties.PostalCode, diff --git a/platform/publicreport/image.go b/platform/publicreport/image.go index 1a43f5b3..35f4f46c 100644 --- a/platform/publicreport/image.go +++ b/platform/publicreport/image.go @@ -33,23 +33,28 @@ func loadImagesForReportNuisance(ctx context.Context, org_id int32, report_ids [ rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( "i.storage_uuid AS uuid", - "ST_X(location) AS location.longitude", - "ST_Y(location) AS location.latitude", - "MAX(e.value) FILTER (WHERE e.name = 'Make') AS exif_make", - "MAX(e.value) FILTER (WHERE e.name = 'Model') AS exif_model", - "MAX(e.value) FILTER (WHERE e.name = 'DateTime') AS exif_datetime", + "COALESCE(ST_X(location), 0) AS \"location.longitude\"", + "COALESCE(ST_Y(location), 0) AS \"location.latitude\"", + "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 nuisance_id", ), sm.From("publicreport.image").As("i"), sm.LeftJoin("publicreport.image_exif").As("e").OnEQ( - psql.Quote("r", "id"), + psql.Quote("i", "id"), psql.Quote("e", "image_id"), ), sm.InnerJoin("publicreport.nuisance_image").As("ni").OnEQ( psql.Quote("ni", "image_id"), psql.Quote("i", "id"), ), - sm.Where(psql.Quote("ni", "nuisance_id").In(psql.Arg(report_ids))), + sm.Where(psql.Quote("ni", "nuisance_id").EQ(psql.Any(report_ids))), + sm.GroupBy( + //psql.Quote("i", "id"), + //psql.Quote("ni", "nuisance_id"), + psql.Raw("i.id, ni.nuisance_id"), + ), ), scan.StructMapper[types.Image]()) if err != nil { return nil, fmt.Errorf("get images: %w", err) diff --git a/platform/publicreport/nuisance.go b/platform/publicreport/nuisance.go index 905670a0..d527855c 100644 --- a/platform/publicreport/nuisance.go +++ b/platform/publicreport/nuisance.go @@ -18,45 +18,40 @@ import ( ) type Nuisance struct { - AdditionalInfo string `db:"additional_info"` - Address types.Address `db:"address"` - AddressAsGiven string `db:"address_as_given"` - Created time.Time `db:"created"` - Duration string `db:"duration"` - ID int32 `db:"id"` - Images []types.Image - 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"` - Location types.Location `db:"location"` - PublicID string `db:"public_id"` - Reporter Reporter `db:"reporter"` - SourceContainer bool `db:"source_container"` - SourceDescription string `db:"source_description"` - SourceGutter bool `db:"source_gutter"` - SourceStagnant bool `db:"source_stagnant"` - TODDay bool `db:"tod_day"` - TODEarly bool `db:"tod_early"` - TODEvening bool `db:"tod_evening"` - TODNight bool `db:"tod_night"` -} -type Reporter struct { - Email *string `db:"reporter_email"` - Name *string `db:"reporter_name"` - Phone *string `db:"reporter_phone"` + 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 `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:"tod_day"` + TODEarly bool `db:"tod_early" json:"tod_early"` + TODEvening bool `db:"tod_evening" json:"tod_evening"` + TODNight bool `db:"tod_night" json:"tod_night"` } func NuisanceReportForOrganization(ctx context.Context, org_id int32) ([]Nuisance, error) { reports, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( sm.Columns( "additional_info", - "address AS address_as_given", + "address_raw AS address_raw", "address_country AS \"address.country\"", + "address_locality AS \"address.locality\"", "address_number AS \"address.number\"", - "address_place AS \"address.place\"", - "address_postcode AS \"address.postcode\"", + "address_postal_code AS \"address.postal_code\"", "address_region AS \"address.region\"", "address_street AS \"address.street\"", "created", diff --git a/platform/report/notification.go b/platform/report/notification.go index 11b0cda7..a195ea21 100644 --- a/platform/report/notification.go +++ b/platform/report/notification.go @@ -193,8 +193,8 @@ func findSomeReport(ctx context.Context, report_id string) (result SomeReport, e switch row.FoundInTables[0] { case "nuisance": return newNuisance(ctx, report_id, int32(t)) - case "pool": - return newPool(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])) diff --git a/platform/report/report_pool.go b/platform/report/report_water.go similarity index 53% rename from platform/report/report_pool.go rename to platform/report/report_water.go index ffd4e03f..63030ed0 100644 --- a/platform/report/report_pool.go +++ b/platform/report/report_water.go @@ -21,50 +21,50 @@ import ( "github.com/stephenafamo/scan" ) -type Pool struct { +type Water struct { id int32 publicReportID string - row *models.PublicreportPool + row *models.PublicreportWater } -func (sr Pool) PublicReportID() string { +func (sr Water) PublicReportID() string { return sr.publicReportID } -func (sr Pool) addNotificationEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode { - setter := models.PublicreportNotifyEmailPoolSetter{ +func (sr Water) addNotificationEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode { + setter := models.PublicreportNotifyEmailWaterSetter{ Created: omit.From(time.Now()), Deleted: omitnull.FromPtr[time.Time](nil), - PoolID: omit.From(sr.id), EmailAddress: omit.From(email), + WaterID: omit.From(sr.id), } - _, err := models.PublicreportNotifyEmailPools.Insert(&setter).Exec(ctx, txn) + _, 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 Pool) addNotificationPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode { - setter := models.PublicreportNotifyPhonePoolSetter{ +func (sr Water) addNotificationPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode { + setter := models.PublicreportNotifyPhoneWaterSetter{ Created: omit.From(time.Now()), Deleted: omitnull.FromPtr[time.Time](nil), - PoolID: omit.From(sr.id), PhoneE164: omit.From(text.PhoneString(phone)), + WaterID: omit.From(sr.id), } - _, err := models.PublicreportNotifyPhonePools.Insert(&setter).Exec(ctx, txn) + _, 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 Pool) districtID(ctx context.Context) *int32 { +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.pool"), + sm.From("publicreport.water"), sm.Columns("organization_id"), sm.Where(psql.Quote("public_id").EQ(psql.Arg(sr.publicReportID))), ), scan.StructMapper[_Row]()) @@ -74,44 +74,44 @@ func (sr Pool) districtID(ctx context.Context) *int32 { } return row.OrganizationID } -func (sr Pool) reportID() int32 { +func (sr Water) reportID() int32 { return sr.id } -func (sr Pool) updateReporterConsent(ctx context.Context, txn bob.Tx, has_consent bool) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{ +func (sr Water) updateReporterConsent(ctx context.Context, txn bob.Tx, has_consent bool) *ErrorWithCode { + return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ ReporterContactConsent: omitnull.From(has_consent), }) } -func (sr Pool) updateReporterEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{ +func (sr Water) updateReporterEmail(ctx context.Context, txn bob.Tx, email string) *ErrorWithCode { + return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ ReporterEmail: omit.From(email), }) } -func (sr Pool) updateReporterName(ctx context.Context, txn bob.Tx, name string) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{ +func (sr Water) updateReporterName(ctx context.Context, txn bob.Tx, name string) *ErrorWithCode { + return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ ReporterName: omit.From(name), }) } -func (sr Pool) updateReportCol(ctx context.Context, txn bob.Tx, setter *models.PublicreportPoolSetter) *ErrorWithCode { +func (sr Water) updateReportCol(ctx context.Context, txn bob.Tx, 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 pool report in the database") + return newInternalError(err, "Failed to update water report in the database") } return nil } -func (sr Pool) updateReporterPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode { - return sr.updateReportCol(ctx, txn, &models.PublicreportPoolSetter{ +func (sr Water) updateReporterPhone(ctx context.Context, txn bob.Tx, phone text.E164) *ErrorWithCode { + return sr.updateReportCol(ctx, txn, &models.PublicreportWaterSetter{ ReporterPhone: omit.From(text.PhoneString(phone)), }) } -func newPool(ctx context.Context, public_id string, report_id int32) (Pool, *ErrorWithCode) { - row, err := models.FindPublicreportPool(ctx, db.PGInstance.BobDB, report_id) +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 pool report") - return Pool{}, newInternalError(err, "Failed to find pool report %d: %w", public_id, err) + 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 Pool{ + return Water{ id: report_id, publicReportID: public_id, row: row, diff --git a/platform/types/address.go b/platform/types/address.go index d2063c1d..12ed7516 100644 --- a/platform/types/address.go +++ b/platform/types/address.go @@ -1,5 +1,11 @@ package types +import ( + "fmt" + + "github.com/Gleipnir-Technology/nidus-sync/db/enums" +) + type Address struct { Country string `db:"country" json:"country"` Locality string `db:"locality" json:"locality"` @@ -9,3 +15,10 @@ type Address struct { Street string `db:"street" json:"street"` Unit string `db:"unit" json:"unit"` } + +func (a Address) String() string { + return fmt.Sprintf("%s %s, %s, %s, %s, %s", a.Number, a.Street, a.Locality, a.Region, a.PostalCode, a.Country) +} +func (a Address) CountryEnum() enums.Countrytype { + return enums.CountrytypeUsa +} diff --git a/platform/types/contact.go b/platform/types/contact.go new file mode 100644 index 00000000..4991a685 --- /dev/null +++ b/platform/types/contact.go @@ -0,0 +1,21 @@ +package types + +import ( + "encoding/json" +) + +type Contact struct { + Email *string `db:"email" json:"-"` + HasEmail bool `json:"has_email"` + HasPhone bool `json:"has_phone"` + Name *string `db:"name"` + Phone *string `db:"phone" json:"-"` +} + +func (c *Contact) MarshalJSON() ([]byte, error) { + to_marshal := make(map[string]interface{}, 0) + to_marshal["name"] = c.Name + to_marshal["has_email"] = (c.Email != nil && *c.Email != "") + to_marshal["has_phone"] = (c.Phone != nil && *c.Phone != "") + return json.Marshal(to_marshal) +} diff --git a/rmo/mock.go b/rmo/mock.go index fb69e55d..df1d7320 100644 --- a/rmo/mock.go +++ b/rmo/mock.go @@ -9,18 +9,15 @@ import ( ) type ContentMock struct { - District ContentDistrict - MapboxToken string - ReportID string - URL ContentURL + District ContentDistrict + ReportID string + URL ContentURL } func addMockRoutes(r chi.Router) { r.Get("/", renderMock("rmo/mock/root.html")) r.Get("/district/{slug}", renderMock("rmo/mock/district-root.html")) - r.Get("/district/{slug}/nuisance", renderMock("rmo/mock/nuisance.html")) r.Get("/district/{slug}/nuisance-submit-complete", renderMock("rmo/mock/nuisance-submit-complete.html")) - r.Get("/district/{slug}/water", renderMock("rmo/mock/water.html")) r.Get("/nuisance", renderMock("rmo/mock/nuisance.html")) r.Get("/nuisance-submit-complete", renderMock("rmo/mock/nuisance-submit-complete.html")) } @@ -51,9 +48,8 @@ func renderMock(t string) func(http.ResponseWriter, *http.Request) { URLLogo: config.MakeURLNidus("/api/district/%s/logo", slug), URLWebsite: "http://www.deltavcd.com/", }, - MapboxToken: config.MapboxToken, - ReportID: "abcd-1234-5678", - URL: makeContentURLMock(slug), + ReportID: "abcd-1234-5678", + URL: makeContentURLMock(slug), }, ) } diff --git a/rmo/nuisance.go b/rmo/nuisance.go index d66747c5..733561ba 100644 --- a/rmo/nuisance.go +++ b/rmo/nuisance.go @@ -9,7 +9,6 @@ import ( "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" @@ -36,9 +35,8 @@ func getNuisance(w http.ResponseWriter, r *http.Request) { w, "rmo/nuisance.html", ContentNuisance{ - District: nil, - MapboxToken: config.MapboxToken, - URL: makeContentURL(nil), + District: nil, + URL: makeContentURL(nil), }, ) } @@ -52,9 +50,8 @@ func getNuisanceDistrict(w http.ResponseWriter, r *http.Request) { w, "rmo/nuisance.html", ContentNuisance{ - District: newContentDistrict(district), - MapboxToken: config.MapboxToken, - URL: makeContentURL(nil), + District: newContentDistrict(district), + URL: makeContentURL(nil), }, ) } @@ -85,9 +82,9 @@ func postNuisance(w http.ResponseWriter, r *http.Request) { additional_info := r.PostFormValue("additional-info") address := r.PostFormValue("address") address_country := r.PostFormValue("address-country") + address_locality := r.PostFormValue("address-locality") address_number := r.PostFormValue("address-number") - address_place := r.PostFormValue("address-place") - address_postcode := r.PostFormValue("address-postcode") + address_postal_code := r.PostFormValue("address-postalcode") address_region := r.PostFormValue("address-region") address_street := r.PostFormValue("address-street") duration_str := postFormValueOrNone(r, "duration") @@ -170,16 +167,16 @@ func postNuisance(w http.ResponseWriter, r *http.Request) { } setter := models.PublicreportNuisanceSetter{ - AdditionalInfo: omit.From(additional_info), - Address: omit.From(address), - AddressCountry: omit.From(address_country), - AddressNumber: omit.From(address_number), - AddressPlace: omit.From(address_place), - AddressPostcode: omit.From(address_postcode), - AddressRegion: omit.From(address_region), - AddressStreet: omit.From(address_street), - Created: omit.From(time.Now()), - Duration: omit.From(duration), + AdditionalInfo: omit.From(additional_info), + AddressRaw: omit.From(address), + AddressCountry: omit.From(address_country), + AddressNumber: omit.From(address_number), + AddressLocality: omit.From(address_locality), + AddressPostalCode: omit.From(address_postal_code), + AddressRegion: omit.From(address_region), + AddressStreet: omit.From(address_street), + Created: omit.From(time.Now()), + Duration: omit.From(duration), //H3cell: omitnull.From(geospatial.Cell.String()), IsLocationBackyard: omit.From(is_location_backyard), IsLocationFrontyard: omit.From(is_location_frontyard), diff --git a/rmo/status.go b/rmo/status.go index 8b088e82..eb320da9 100644 --- a/rmo/status.go +++ b/rmo/status.go @@ -11,7 +11,6 @@ import ( "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/db/sql" @@ -27,18 +26,16 @@ import ( */) type ContentStatus struct { - District *ContentDistrict - Error string - MapboxToken string - ReportID string - URL ContentURL + District *ContentDistrict + Error string + ReportID string + URL ContentURL } type ContentStatusByID struct { - District *ContentDistrict - MapboxToken string - Report Report - Timeline []TimelineEntry - URL ContentURL + District *ContentDistrict + Report Report + Timeline []TimelineEntry + URL ContentURL } type DetailEntry struct { Name string @@ -84,10 +81,9 @@ func formatReportID(s string) string { func getStatus(w http.ResponseWriter, r *http.Request) { report_id_str := r.URL.Query().Get("report") content := ContentStatus{ - Error: "", - MapboxToken: config.MapboxToken, - ReportID: "", - URL: makeContentURL(nil), + Error: "", + ReportID: "", + URL: makeContentURL(nil), } if report_id_str == "" { html.RenderOrError(w, "rmo/status.html", content) @@ -121,7 +117,7 @@ func contentFromNuisance(ctx context.Context, report_id string) (result ContentS result.District = newContentDistrict(org) } result.Report.ID = report_id - result.Report.Address = nuisance.Address + result.Report.Address = nuisance.AddressRaw result.Report.Created = nuisance.Created result.Report.ImageCount = len(images) result.Report.Status = strings.Title(nuisance.Status.String()) @@ -205,15 +201,15 @@ func contentFromNuisance(ctx context.Context, report_id string) (result ContentS return result, err } -func contentFromPool(ctx context.Context, report_id string) (result ContentStatusByID, err error) { - pool, err := models.PublicreportPools.Query( - models.SelectWhere.PublicreportPools.PublicID.EQ(report_id), +func contentFromWater(ctx context.Context, report_id string) (result ContentStatusByID, err error) { + pool, 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 pool %s: %w", report_id, err) } - images, err := sql.PublicreportImageWithJSONByPoolID(pool.ID).All(ctx, db.PGInstance.BobDB) + images, err := sql.PublicreportImageWithJSONByWaterID(pool.ID).All(ctx, db.PGInstance.BobDB) if err != nil { return result, fmt.Errorf("Failed to get images %s: %w", report_id, err) } @@ -228,7 +224,7 @@ func contentFromPool(ctx context.Context, report_id string) (result ContentStatu } result.Report.ID = report_id - result.Report.Address = pool.Address + result.Report.Address = pool.AddressRaw result.Report.Created = pool.Created result.Report.ImageCount = len(images) result.Report.Status = strings.Title(pool.Status.String()) @@ -304,13 +300,12 @@ func getStatusByID(w http.ResponseWriter, r *http.Request) { case "nuisance": content, err = contentFromNuisance(ctx, report_id) case "pool": - content, err = contentFromPool(ctx, report_id) + content, err = contentFromWater(ctx, report_id) } if err != nil { respondError(w, "Failed to generate report content", err, http.StatusInternalServerError) return } - content.MapboxToken = config.MapboxToken content.URL = makeContentURL(nil) html.RenderOrError( w, diff --git a/rmo/water.go b/rmo/water.go index 341b4bef..9e523718 100644 --- a/rmo/water.go +++ b/rmo/water.go @@ -8,7 +8,6 @@ import ( "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" @@ -19,20 +18,18 @@ import ( "github.com/rs/zerolog/log" ) -type ContentPool struct { - District *ContentDistrict - MapboxToken string - URL ContentURL +type ContentWater struct { + District *ContentDistrict + URL ContentURL } func getWater(w http.ResponseWriter, r *http.Request) { html.RenderOrError( w, "rmo/water.html", - ContentPool{ - District: nil, - MapboxToken: config.MapboxToken, - URL: makeContentURL(nil), + ContentWater{ + District: nil, + URL: makeContentURL(nil), }, ) } @@ -45,10 +42,9 @@ func getWaterDistrict(w http.ResponseWriter, r *http.Request) { html.RenderOrError( w, "rmo/water.html", - ContentPool{ - District: newContentDistrict(district), - MapboxToken: config.MapboxToken, - URL: makeContentURL(district), + ContentWater{ + District: newContentDistrict(district), + URL: makeContentURL(district), }, ) } @@ -65,11 +61,11 @@ func postWater(w http.ResponseWriter, r *http.Request) { access_gate := boolFromForm(r, "access-gate") access_locked := boolFromForm(r, "access-locked") access_other := boolFromForm(r, "access-other") - address := r.FormValue("address") + address_raw := r.FormValue("address") address_country := r.FormValue("address-country") + address_locality := r.FormValue("address-locality") address_number := r.FormValue("address-number") - address_postcode := r.FormValue("address-postcode") - address_place := r.FormValue("address-place") + address_postalcode := r.FormValue("address-postalcode") address_region := r.FormValue("address-region") address_street := r.FormValue("address-street") comments := r.FormValue("comments") @@ -125,22 +121,22 @@ func postWater(w http.ResponseWriter, r *http.Request) { log.Warn().Err(err).Msg("Failed to match district") } - setter := models.PublicreportPoolSetter{ - 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), - Address: omit.From(address), - AddressCountry: omit.From(address_country), - AddressNumber: omit.From(address_number), - AddressPostCode: omit.From(address_postcode), - AddressPlace: omit.From(address_place), - AddressStreet: omit.From(address_street), - AddressRegion: omit.From(address_region), - Comments: omit.From(comments), - Created: omit.From(time.Now()), + 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), + AddressRaw: omit.From(address_raw), + AddressCountry: omit.From(address_country), + AddressLocality: omit.From(address_locality), + AddressNumber: omit.From(address_number), + AddressPostalCode: omit.From(address_postalcode), + 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), @@ -160,7 +156,7 @@ func postWater(w http.ResponseWriter, r *http.Request) { ReporterPhone: omit.From(""), Status: omit.From(enums.PublicreportReportstatustypeReported), } - pool, err := models.PublicreportPools.Insert(&setter).One(ctx, tx) + pool, err := models.PublicreportWaters.Insert(&setter).One(ctx, tx) if err != nil { respondError(w, "Failed to create database record", err, http.StatusInternalServerError) return @@ -179,15 +175,15 @@ func postWater(w http.ResponseWriter, r *http.Request) { } } log.Info().Int32("id", pool.ID).Str("public_id", pool.PublicID).Msg("Created pool report") - setters := make([]*models.PublicreportPoolImageSetter, 0) + setters := make([]*models.PublicreportWaterImageSetter, 0) for _, image := range images { - setters = append(setters, &models.PublicreportPoolImageSetter{ + setters = append(setters, &models.PublicreportWaterImageSetter{ ImageID: omit.From(int32(image.ID)), - PoolID: omit.From(int32(pool.ID)), + WaterID: omit.From(int32(pool.ID)), }) } if len(setters) > 0 { - _, err = models.PublicreportPoolImages.Insert(bob.ToMods(setters...)).Exec(r.Context(), tx) + _, err = models.PublicreportWaterImages.Insert(bob.ToMods(setters...)).Exec(r.Context(), tx) if err != nil { respondError(w, "Failed to save upload relationships", err, http.StatusInternalServerError) return diff --git a/sync/dash.go b/sync/dash.go index 32cee0bf..ddda7023 100644 --- a/sync/dash.go +++ b/sync/dash.go @@ -10,7 +10,6 @@ import ( "github.com/Gleipnir-Technology/bob/dialect/psql/sm" "github.com/Gleipnir-Technology/nidus-sync/auth" "github.com/Gleipnir-Technology/nidus-sync/background" - "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/html" @@ -53,13 +52,10 @@ type contentLayoutTest struct { User platform.User } type ContentDistrict struct { - MapboxToken string } func getDistrict(w http.ResponseWriter, r *http.Request) { - context := ContentDistrict{ - MapboxToken: config.MapboxToken, - } + context := ContentDistrict{} html.RenderOrError(w, "sync/district.html", &context) } @@ -135,7 +131,6 @@ func getSource(ctx context.Context, r *http.Request, org *models.Organization, u MapData: ComponentMap{ Center: latlng, //GeoJSON: - MapboxToken: config.MapboxToken, Markers: []MapMarker{ MapMarker{ LatLng: latlng, @@ -155,9 +150,7 @@ func getSource(ctx context.Context, r *http.Request, org *models.Organization, u func getStadia(ctx context.Context, r *http.Request, org *models.Organization, u *models.User) (*html.Response[contentDashboard], *nhttp.ErrorWithStatus) { data := contentDashboard{ - MapData: ComponentMap{ - MapboxToken: config.MapboxToken, - }, + MapData: ComponentMap{}, } return html.NewResponse("sync/stadia.html", data), nil } @@ -189,7 +182,6 @@ func getTrap(ctx context.Context, r *http.Request, org *models.Organization, use MapData: ComponentMap{ Center: latlng, //GeoJSON: - MapboxToken: config.MapboxToken, Markers: []MapMarker{ MapMarker{ LatLng: latlng, @@ -250,10 +242,8 @@ func dashboard(ctx context.Context, w http.ResponseWriter, org *models.Organizat CountServiceRequests: int(serviceCount), IsSyncOngoing: is_syncing, LastSync: lastSync, - MapData: ComponentMap{ - MapboxToken: config.MapboxToken, - }, - RecentRequests: requests, + MapData: ComponentMap{}, + RecentRequests: requests, } userContent, err := auth.ContentForUser(ctx, user) if err != nil { diff --git a/sync/types.go b/sync/types.go index 35dd1b7b..eb00e3f4 100644 --- a/sync/types.go +++ b/sync/types.go @@ -18,11 +18,10 @@ type MapMarker struct { LatLng h3.LatLng } type ComponentMap struct { - Center h3.LatLng - GeoJSON interface{} - MapboxToken string - Markers []MapMarker - Zoom int + Center h3.LatLng + GeoJSON interface{} + Markers []MapMarker + Zoom int } type ContentMockURLs struct { Dispatch string