Move imported districts to its own schema, add ref from organization

This will make it possible to assign reports to an organization
This commit is contained in:
Eli Ribble 2026-01-16 14:43:26 +00:00
parent 9b5140f0c2
commit 684c424131
No known key found for this signature in database
16 changed files with 1561 additions and 702 deletions

View file

@ -13,6 +13,7 @@ no_tests: true
psql:
schemas:
- "arcgis"
- "import"
- "public"
- "publicreport"
- "fieldseeker"

View file

@ -3,15 +3,15 @@
package dberrors
var DistrictErrors = &districtErrors{
var ImportDistrictErrors = &importDistrictErrors{
ErrUniqueDistrictPkey: &UniqueConstraintError{
schema: "",
schema: "import",
table: "district",
columns: []string{"gid"},
s: "district_pkey",
},
}
type districtErrors struct {
type importDistrictErrors struct {
ErrUniqueDistrictPkey *UniqueConstraintError
}

View file

@ -10,8 +10,26 @@ var OrganizationErrors = &organizationErrors{
columns: []string{"id"},
s: "organization_pkey",
},
ErrUniqueOrganizationImportDistrictGidKey: &UniqueConstraintError{
schema: "",
table: "organization",
columns: []string{"import_district_gid"},
s: "organization_import_district_gid_key",
},
ErrUniqueOrganizationWebsiteKey: &UniqueConstraintError{
schema: "",
table: "organization",
columns: []string{"website"},
s: "organization_website_key",
},
}
type organizationErrors struct {
ErrUniqueOrganizationPkey *UniqueConstraintError
ErrUniqueOrganizationImportDistrictGidKey *UniqueConstraintError
ErrUniqueOrganizationWebsiteKey *UniqueConstraintError
}

View file

@ -5,20 +5,20 @@ package dbinfo
import "github.com/aarondl/opt/null"
var Districts = Table[
districtColumns,
districtIndexes,
districtForeignKeys,
districtUniques,
districtChecks,
var ImportDistricts = Table[
importDistrictColumns,
importDistrictIndexes,
importDistrictForeignKeys,
importDistrictUniques,
importDistrictChecks,
]{
Schema: "",
Schema: "import",
Name: "district",
Columns: districtColumns{
Columns: importDistrictColumns{
Gid: column{
Name: "gid",
DBType: "integer",
Default: "nextval('district_gid_seq'::regclass)",
Default: "nextval('import.district_gid_seq'::regclass)",
Comment: "",
Nullable: false,
Generated: false,
@ -223,7 +223,7 @@ var Districts = Table[
AutoIncr: false,
},
},
Indexes: districtIndexes{
Indexes: importDistrictIndexes{
DistrictPkey: index{
Type: "btree",
Name: "district_pkey",
@ -268,7 +268,7 @@ var Districts = Table[
Comment: "",
}
type districtColumns struct {
type importDistrictColumns struct {
Gid column
ID column
Website column
@ -294,37 +294,37 @@ type districtColumns struct {
Geom4326 column
}
func (c districtColumns) AsSlice() []column {
func (c importDistrictColumns) AsSlice() []column {
return []column{
c.Gid, c.ID, c.Website, c.Contact, c.Address, c.Regionid, c.PostalCod, c.Phone1, c.Fax1, c.Agency, c.Code1, c.City1, c.ShapeLeng, c.Address2, c.GeneralMG, c.City2, c.PostalC1, c.Fax2, c.Phone2, c.ShapeLe1, c.ShapeArea, c.Geom, c.Geom4326,
}
}
type districtIndexes struct {
type importDistrictIndexes struct {
DistrictPkey index
DistrictGeomIdx index
}
func (i districtIndexes) AsSlice() []index {
func (i importDistrictIndexes) AsSlice() []index {
return []index{
i.DistrictPkey, i.DistrictGeomIdx,
}
}
type districtForeignKeys struct{}
type importDistrictForeignKeys struct{}
func (f districtForeignKeys) AsSlice() []foreignKey {
func (f importDistrictForeignKeys) AsSlice() []foreignKey {
return []foreignKey{}
}
type districtUniques struct{}
type importDistrictUniques struct{}
func (u districtUniques) AsSlice() []constraint {
func (u importDistrictUniques) AsSlice() []constraint {
return []constraint{}
}
type districtChecks struct{}
type importDistrictChecks struct{}
func (c districtChecks) AsSlice() []check {
func (c importDistrictChecks) AsSlice() []check {
return []check{}
}

View file

@ -60,6 +60,24 @@ var Organizations = Table[
Generated: false,
AutoIncr: false,
},
ImportDistrictGid: column{
Name: "import_district_gid",
DBType: "integer",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
Website: column{
Name: "website",
DBType: "text",
Default: "NULL",
Comment: "",
Nullable: true,
Generated: false,
AutoIncr: false,
},
},
Indexes: organizationIndexes{
OrganizationPkey: index{
@ -79,50 +97,120 @@ var Organizations = Table[
Where: "",
Include: []string{},
},
OrganizationImportDistrictGidKey: index{
Type: "btree",
Name: "organization_import_district_gid_key",
Columns: []indexColumn{
{
Name: "import_district_gid",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
OrganizationWebsiteKey: index{
Type: "btree",
Name: "organization_website_key",
Columns: []indexColumn{
{
Name: "website",
Desc: null.FromCond(false, true),
IsExpression: false,
},
},
Unique: true,
Comment: "",
NullsFirst: []bool{false},
NullsDistinct: false,
Where: "",
Include: []string{},
},
},
PrimaryKey: &constraint{
Name: "organization_pkey",
Columns: []string{"id"},
Comment: "",
},
ForeignKeys: organizationForeignKeys{
OrganizationOrganizationImportDistrictGidFkey: foreignKey{
constraint: constraint{
Name: "organization.organization_import_district_gid_fkey",
Columns: []string{"import_district_gid"},
Comment: "",
},
ForeignTable: "import.district",
ForeignColumns: []string{"gid"},
},
},
Uniques: organizationUniques{
OrganizationImportDistrictGidKey: constraint{
Name: "organization_import_district_gid_key",
Columns: []string{"import_district_gid"},
Comment: "",
},
OrganizationWebsiteKey: constraint{
Name: "organization_website_key",
Columns: []string{"website"},
Comment: "",
},
},
Comment: "",
}
type organizationColumns struct {
ID column
Name column
ArcgisID column
ArcgisName column
FieldseekerURL column
ID column
Name column
ArcgisID column
ArcgisName column
FieldseekerURL column
ImportDistrictGid column
Website column
}
func (c organizationColumns) AsSlice() []column {
return []column{
c.ID, c.Name, c.ArcgisID, c.ArcgisName, c.FieldseekerURL,
c.ID, c.Name, c.ArcgisID, c.ArcgisName, c.FieldseekerURL, c.ImportDistrictGid, c.Website,
}
}
type organizationIndexes struct {
OrganizationPkey index
OrganizationPkey index
OrganizationImportDistrictGidKey index
OrganizationWebsiteKey index
}
func (i organizationIndexes) AsSlice() []index {
return []index{
i.OrganizationPkey,
i.OrganizationPkey, i.OrganizationImportDistrictGidKey, i.OrganizationWebsiteKey,
}
}
type organizationForeignKeys struct{}
func (f organizationForeignKeys) AsSlice() []foreignKey {
return []foreignKey{}
type organizationForeignKeys struct {
OrganizationOrganizationImportDistrictGidFkey foreignKey
}
type organizationUniques struct{}
func (f organizationForeignKeys) AsSlice() []foreignKey {
return []foreignKey{
f.OrganizationOrganizationImportDistrictGidFkey,
}
}
type organizationUniques struct {
OrganizationImportDistrictGidKey constraint
OrganizationWebsiteKey constraint
}
func (u organizationUniques) AsSlice() []constraint {
return []constraint{}
return []constraint{
u.OrganizationImportDistrictGidKey, u.OrganizationWebsiteKey,
}
}
type organizationChecks struct{}

View file

@ -17,9 +17,6 @@ var (
arcgisUserPrivilegeWithParentsCascadingCtx = newContextual[bool]("arcgisUserPrivilegeWithParentsCascading")
arcgisUserPrivilegeRelUserUserCtx = newContextual[bool]("arcgis.user_.arcgis.user_privilege.arcgis.user_privilege.user_privilege_user_id_fkey")
// Relationship Contexts for district
districtWithParentsCascadingCtx = newContextual[bool]("districtWithParentsCascading")
// Relationship Contexts for fieldseeker.containerrelate
fieldseekerContainerrelateWithParentsCascadingCtx = newContextual[bool]("fieldseekerContainerrelateWithParentsCascading")
fieldseekerContainerrelateRelOrganizationCtx = newContextual[bool]("fieldseeker.containerrelate.organization.fieldseeker.containerrelate.containerrelate_organization_id_fkey")
@ -145,6 +142,10 @@ var (
h3AggregationWithParentsCascadingCtx = newContextual[bool]("h3AggregationWithParentsCascading")
h3AggregationRelOrganizationCtx = newContextual[bool]("h3_aggregation.organization.h3_aggregation.h3_aggregation_organization_id_fkey")
// Relationship Contexts for import.district
importDistrictWithParentsCascadingCtx = newContextual[bool]("importDistrictWithParentsCascading")
importDistrictRelImportDistrictGidOrganizationCtx = newContextual[bool]("import.district.organization.organization.organization_import_district_gid_fkey")
// Relationship Contexts for note_audio
noteAudioWithParentsCascadingCtx = newContextual[bool]("noteAudioWithParentsCascading")
noteAudioRelCreatorUserCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_creator_id_fkey")
@ -186,39 +187,40 @@ var (
oauthTokenRelUserUserCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey")
// Relationship Contexts for organization
organizationWithParentsCascadingCtx = newContextual[bool]("organizationWithParentsCascading")
organizationRelContainerrelatesCtx = newContextual[bool]("fieldseeker.containerrelate.organization.fieldseeker.containerrelate.containerrelate_organization_id_fkey")
organizationRelFieldscoutinglogsCtx = newContextual[bool]("fieldseeker.fieldscoutinglog.organization.fieldseeker.fieldscoutinglog.fieldscoutinglog_organization_id_fkey")
organizationRelHabitatrelatesCtx = newContextual[bool]("fieldseeker.habitatrelate.organization.fieldseeker.habitatrelate.habitatrelate_organization_id_fkey")
organizationRelInspectionsamplesCtx = newContextual[bool]("fieldseeker.inspectionsample.organization.fieldseeker.inspectionsample.inspectionsample_organization_id_fkey")
organizationRelInspectionsampledetailsCtx = newContextual[bool]("fieldseeker.inspectionsampledetail.organization.fieldseeker.inspectionsampledetail.inspectionsampledetail_organization_id_fkey")
organizationRelLinelocationsCtx = newContextual[bool]("fieldseeker.linelocation.organization.fieldseeker.linelocation.linelocation_organization_id_fkey")
organizationRelLocationtrackingsCtx = newContextual[bool]("fieldseeker.locationtracking.organization.fieldseeker.locationtracking.locationtracking_organization_id_fkey")
organizationRelMosquitoinspectionsCtx = newContextual[bool]("fieldseeker.mosquitoinspection.organization.fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey")
organizationRelPointlocationsCtx = newContextual[bool]("fieldseeker.pointlocation.organization.fieldseeker.pointlocation.pointlocation_organization_id_fkey")
organizationRelPolygonlocationsCtx = newContextual[bool]("fieldseeker.polygonlocation.organization.fieldseeker.polygonlocation.polygonlocation_organization_id_fkey")
organizationRelPoolsCtx = newContextual[bool]("fieldseeker.pool.organization.fieldseeker.pool.pool_organization_id_fkey")
organizationRelPooldetailsCtx = newContextual[bool]("fieldseeker.pooldetail.organization.fieldseeker.pooldetail.pooldetail_organization_id_fkey")
organizationRelProposedtreatmentareasCtx = newContextual[bool]("fieldseeker.proposedtreatmentarea.organization.fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey")
organizationRelQamosquitoinspectionsCtx = newContextual[bool]("fieldseeker.qamosquitoinspection.organization.fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey")
organizationRelRodentlocationsCtx = newContextual[bool]("fieldseeker.rodentlocation.organization.fieldseeker.rodentlocation.rodentlocation_organization_id_fkey")
organizationRelSamplecollectionsCtx = newContextual[bool]("fieldseeker.samplecollection.organization.fieldseeker.samplecollection.samplecollection_organization_id_fkey")
organizationRelSamplelocationsCtx = newContextual[bool]("fieldseeker.samplelocation.organization.fieldseeker.samplelocation.samplelocation_organization_id_fkey")
organizationRelServicerequestsCtx = newContextual[bool]("fieldseeker.servicerequest.organization.fieldseeker.servicerequest.servicerequest_organization_id_fkey")
organizationRelSpeciesabundancesCtx = newContextual[bool]("fieldseeker.speciesabundance.organization.fieldseeker.speciesabundance.speciesabundance_organization_id_fkey")
organizationRelStormdrainsCtx = newContextual[bool]("fieldseeker.stormdrain.organization.fieldseeker.stormdrain.stormdrain_organization_id_fkey")
organizationRelTimecardsCtx = newContextual[bool]("fieldseeker.timecard.organization.fieldseeker.timecard.timecard_organization_id_fkey")
organizationRelTrapdataCtx = newContextual[bool]("fieldseeker.trapdata.organization.fieldseeker.trapdata.trapdata_organization_id_fkey")
organizationRelTraplocationsCtx = newContextual[bool]("fieldseeker.traplocation.organization.fieldseeker.traplocation.traplocation_organization_id_fkey")
organizationRelTreatmentsCtx = newContextual[bool]("fieldseeker.treatment.organization.fieldseeker.treatment.treatment_organization_id_fkey")
organizationRelTreatmentareasCtx = newContextual[bool]("fieldseeker.treatmentarea.organization.fieldseeker.treatmentarea.treatmentarea_organization_id_fkey")
organizationRelZonesCtx = newContextual[bool]("fieldseeker.zones.organization.fieldseeker.zones.zones_organization_id_fkey")
organizationRelZones2sCtx = newContextual[bool]("fieldseeker.zones2.organization.fieldseeker.zones2.zones2_organization_id_fkey")
organizationRelFieldseekerSyncsCtx = newContextual[bool]("fieldseeker_sync.organization.fieldseeker_sync.fieldseeker_sync_organization_id_fkey")
organizationRelH3AggregationsCtx = newContextual[bool]("h3_aggregation.organization.h3_aggregation.h3_aggregation_organization_id_fkey")
organizationRelNoteAudiosCtx = newContextual[bool]("note_audio.organization.note_audio.note_audio_organization_id_fkey")
organizationRelNoteImagesCtx = newContextual[bool]("note_image.organization.note_image.note_image_organization_id_fkey")
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
organizationWithParentsCascadingCtx = newContextual[bool]("organizationWithParentsCascading")
organizationRelContainerrelatesCtx = newContextual[bool]("fieldseeker.containerrelate.organization.fieldseeker.containerrelate.containerrelate_organization_id_fkey")
organizationRelFieldscoutinglogsCtx = newContextual[bool]("fieldseeker.fieldscoutinglog.organization.fieldseeker.fieldscoutinglog.fieldscoutinglog_organization_id_fkey")
organizationRelHabitatrelatesCtx = newContextual[bool]("fieldseeker.habitatrelate.organization.fieldseeker.habitatrelate.habitatrelate_organization_id_fkey")
organizationRelInspectionsamplesCtx = newContextual[bool]("fieldseeker.inspectionsample.organization.fieldseeker.inspectionsample.inspectionsample_organization_id_fkey")
organizationRelInspectionsampledetailsCtx = newContextual[bool]("fieldseeker.inspectionsampledetail.organization.fieldseeker.inspectionsampledetail.inspectionsampledetail_organization_id_fkey")
organizationRelLinelocationsCtx = newContextual[bool]("fieldseeker.linelocation.organization.fieldseeker.linelocation.linelocation_organization_id_fkey")
organizationRelLocationtrackingsCtx = newContextual[bool]("fieldseeker.locationtracking.organization.fieldseeker.locationtracking.locationtracking_organization_id_fkey")
organizationRelMosquitoinspectionsCtx = newContextual[bool]("fieldseeker.mosquitoinspection.organization.fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey")
organizationRelPointlocationsCtx = newContextual[bool]("fieldseeker.pointlocation.organization.fieldseeker.pointlocation.pointlocation_organization_id_fkey")
organizationRelPolygonlocationsCtx = newContextual[bool]("fieldseeker.polygonlocation.organization.fieldseeker.polygonlocation.polygonlocation_organization_id_fkey")
organizationRelPoolsCtx = newContextual[bool]("fieldseeker.pool.organization.fieldseeker.pool.pool_organization_id_fkey")
organizationRelPooldetailsCtx = newContextual[bool]("fieldseeker.pooldetail.organization.fieldseeker.pooldetail.pooldetail_organization_id_fkey")
organizationRelProposedtreatmentareasCtx = newContextual[bool]("fieldseeker.proposedtreatmentarea.organization.fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey")
organizationRelQamosquitoinspectionsCtx = newContextual[bool]("fieldseeker.qamosquitoinspection.organization.fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey")
organizationRelRodentlocationsCtx = newContextual[bool]("fieldseeker.rodentlocation.organization.fieldseeker.rodentlocation.rodentlocation_organization_id_fkey")
organizationRelSamplecollectionsCtx = newContextual[bool]("fieldseeker.samplecollection.organization.fieldseeker.samplecollection.samplecollection_organization_id_fkey")
organizationRelSamplelocationsCtx = newContextual[bool]("fieldseeker.samplelocation.organization.fieldseeker.samplelocation.samplelocation_organization_id_fkey")
organizationRelServicerequestsCtx = newContextual[bool]("fieldseeker.servicerequest.organization.fieldseeker.servicerequest.servicerequest_organization_id_fkey")
organizationRelSpeciesabundancesCtx = newContextual[bool]("fieldseeker.speciesabundance.organization.fieldseeker.speciesabundance.speciesabundance_organization_id_fkey")
organizationRelStormdrainsCtx = newContextual[bool]("fieldseeker.stormdrain.organization.fieldseeker.stormdrain.stormdrain_organization_id_fkey")
organizationRelTimecardsCtx = newContextual[bool]("fieldseeker.timecard.organization.fieldseeker.timecard.timecard_organization_id_fkey")
organizationRelTrapdataCtx = newContextual[bool]("fieldseeker.trapdata.organization.fieldseeker.trapdata.trapdata_organization_id_fkey")
organizationRelTraplocationsCtx = newContextual[bool]("fieldseeker.traplocation.organization.fieldseeker.traplocation.traplocation_organization_id_fkey")
organizationRelTreatmentsCtx = newContextual[bool]("fieldseeker.treatment.organization.fieldseeker.treatment.treatment_organization_id_fkey")
organizationRelTreatmentareasCtx = newContextual[bool]("fieldseeker.treatmentarea.organization.fieldseeker.treatmentarea.treatmentarea_organization_id_fkey")
organizationRelZonesCtx = newContextual[bool]("fieldseeker.zones.organization.fieldseeker.zones.zones_organization_id_fkey")
organizationRelZones2sCtx = newContextual[bool]("fieldseeker.zones2.organization.fieldseeker.zones2.zones2_organization_id_fkey")
organizationRelFieldseekerSyncsCtx = newContextual[bool]("fieldseeker_sync.organization.fieldseeker_sync.fieldseeker_sync_organization_id_fkey")
organizationRelH3AggregationsCtx = newContextual[bool]("h3_aggregation.organization.h3_aggregation.h3_aggregation_organization_id_fkey")
organizationRelNoteAudiosCtx = newContextual[bool]("note_audio.organization.note_audio.note_audio_organization_id_fkey")
organizationRelNoteImagesCtx = newContextual[bool]("note_image.organization.note_image.note_image_organization_id_fkey")
organizationRelImportDistrictGidDistrictCtx = newContextual[bool]("import.district.organization.organization.organization_import_district_gid_fkey")
organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey")
// Relationship Contexts for publicreport.nuisance
publicreportNuisanceWithParentsCascadingCtx = newContextual[bool]("publicreportNuisanceWithParentsCascading")

View file

@ -20,7 +20,6 @@ import (
type Factory struct {
baseArcgisUserMods ArcgisUserModSlice
baseArcgisUserPrivilegeMods ArcgisUserPrivilegeModSlice
baseDistrictMods DistrictModSlice
baseFieldseekerContainerrelateMods FieldseekerContainerrelateModSlice
baseFieldseekerFieldscoutinglogMods FieldseekerFieldscoutinglogModSlice
baseFieldseekerHabitatrelateMods FieldseekerHabitatrelateModSlice
@ -53,6 +52,7 @@ type Factory struct {
baseGeometryColumnMods GeometryColumnModSlice
baseGooseDBVersionMods GooseDBVersionModSlice
baseH3AggregationMods H3AggregationModSlice
baseImportDistrictMods ImportDistrictModSlice
baseNoteAudioMods NoteAudioModSlice
baseNoteAudioBreadcrumbMods NoteAudioBreadcrumbModSlice
baseNoteAudioDatumMods NoteAudioDatumModSlice
@ -154,52 +154,6 @@ func (f *Factory) FromExistingArcgisUserPrivilege(m *models.ArcgisUserPrivilege)
return o
}
func (f *Factory) NewDistrict(mods ...DistrictMod) *DistrictTemplate {
return f.NewDistrictWithContext(context.Background(), mods...)
}
func (f *Factory) NewDistrictWithContext(ctx context.Context, mods ...DistrictMod) *DistrictTemplate {
o := &DistrictTemplate{f: f}
if f != nil {
f.baseDistrictMods.Apply(ctx, o)
}
DistrictModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingDistrict(m *models.District) *DistrictTemplate {
o := &DistrictTemplate{f: f, alreadyPersisted: true}
o.Gid = func() int32 { return m.Gid }
o.ID = func() null.Val[decimal.Decimal] { return m.ID }
o.Website = func() null.Val[string] { return m.Website }
o.Contact = func() null.Val[string] { return m.Contact }
o.Address = func() null.Val[string] { return m.Address }
o.Regionid = func() null.Val[decimal.Decimal] { return m.Regionid }
o.PostalCod = func() null.Val[decimal.Decimal] { return m.PostalCod }
o.Phone1 = func() null.Val[string] { return m.Phone1 }
o.Fax1 = func() null.Val[string] { return m.Fax1 }
o.Agency = func() null.Val[string] { return m.Agency }
o.Code1 = func() null.Val[string] { return m.Code1 }
o.City1 = func() null.Val[string] { return m.City1 }
o.ShapeLeng = func() null.Val[decimal.Decimal] { return m.ShapeLeng }
o.Address2 = func() null.Val[string] { return m.Address2 }
o.GeneralMG = func() null.Val[string] { return m.GeneralMG }
o.City2 = func() null.Val[string] { return m.City2 }
o.PostalC1 = func() null.Val[decimal.Decimal] { return m.PostalC1 }
o.Fax2 = func() null.Val[string] { return m.Fax2 }
o.Phone2 = func() null.Val[string] { return m.Phone2 }
o.ShapeLe1 = func() null.Val[decimal.Decimal] { return m.ShapeLe1 }
o.ShapeArea = func() null.Val[decimal.Decimal] { return m.ShapeArea }
o.Geom = func() null.Val[string] { return m.Geom }
o.Geom4326 = func() null.Val[string] { return m.Geom4326 }
return o
}
func (f *Factory) NewFieldseekerContainerrelate(mods ...FieldseekerContainerrelateMod) *FieldseekerContainerrelateTemplate {
return f.NewFieldseekerContainerrelateWithContext(context.Background(), mods...)
}
@ -2074,6 +2028,57 @@ func (f *Factory) FromExistingH3Aggregation(m *models.H3Aggregation) *H3Aggregat
return o
}
func (f *Factory) NewImportDistrict(mods ...ImportDistrictMod) *ImportDistrictTemplate {
return f.NewImportDistrictWithContext(context.Background(), mods...)
}
func (f *Factory) NewImportDistrictWithContext(ctx context.Context, mods ...ImportDistrictMod) *ImportDistrictTemplate {
o := &ImportDistrictTemplate{f: f}
if f != nil {
f.baseImportDistrictMods.Apply(ctx, o)
}
ImportDistrictModSlice(mods).Apply(ctx, o)
return o
}
func (f *Factory) FromExistingImportDistrict(m *models.ImportDistrict) *ImportDistrictTemplate {
o := &ImportDistrictTemplate{f: f, alreadyPersisted: true}
o.Gid = func() int32 { return m.Gid }
o.ID = func() null.Val[decimal.Decimal] { return m.ID }
o.Website = func() null.Val[string] { return m.Website }
o.Contact = func() null.Val[string] { return m.Contact }
o.Address = func() null.Val[string] { return m.Address }
o.Regionid = func() null.Val[decimal.Decimal] { return m.Regionid }
o.PostalCod = func() null.Val[decimal.Decimal] { return m.PostalCod }
o.Phone1 = func() null.Val[string] { return m.Phone1 }
o.Fax1 = func() null.Val[string] { return m.Fax1 }
o.Agency = func() null.Val[string] { return m.Agency }
o.Code1 = func() null.Val[string] { return m.Code1 }
o.City1 = func() null.Val[string] { return m.City1 }
o.ShapeLeng = func() null.Val[decimal.Decimal] { return m.ShapeLeng }
o.Address2 = func() null.Val[string] { return m.Address2 }
o.GeneralMG = func() null.Val[string] { return m.GeneralMG }
o.City2 = func() null.Val[string] { return m.City2 }
o.PostalC1 = func() null.Val[decimal.Decimal] { return m.PostalC1 }
o.Fax2 = func() null.Val[string] { return m.Fax2 }
o.Phone2 = func() null.Val[string] { return m.Phone2 }
o.ShapeLe1 = func() null.Val[decimal.Decimal] { return m.ShapeLe1 }
o.ShapeArea = func() null.Val[decimal.Decimal] { return m.ShapeArea }
o.Geom = func() null.Val[string] { return m.Geom }
o.Geom4326 = func() null.Val[string] { return m.Geom4326 }
ctx := context.Background()
if m.R.ImportDistrictGidOrganization != nil {
ImportDistrictMods.WithExistingImportDistrictGidOrganization(m.R.ImportDistrictGidOrganization).Apply(ctx, o)
}
return o
}
func (f *Factory) NewNoteAudio(mods ...NoteAudioMod) *NoteAudioTemplate {
return f.NewNoteAudioWithContext(context.Background(), mods...)
}
@ -2400,6 +2405,8 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
o.ArcgisID = func() null.Val[string] { return m.ArcgisID }
o.ArcgisName = func() null.Val[string] { return m.ArcgisName }
o.FieldseekerURL = func() null.Val[string] { return m.FieldseekerURL }
o.ImportDistrictGid = func() null.Val[int32] { return m.ImportDistrictGid }
o.Website = func() null.Val[string] { return m.Website }
ctx := context.Background()
if len(m.R.Containerrelates) > 0 {
@ -2495,6 +2502,9 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
if len(m.R.NoteImages) > 0 {
OrganizationMods.AddExistingNoteImages(m.R.NoteImages...).Apply(ctx, o)
}
if m.R.ImportDistrictGidDistrict != nil {
OrganizationMods.WithExistingImportDistrictGidDistrict(m.R.ImportDistrictGidDistrict).Apply(ctx, o)
}
if len(m.R.User) > 0 {
OrganizationMods.AddExistingUser(m.R.User...).Apply(ctx, o)
}
@ -2947,14 +2957,6 @@ func (f *Factory) AddBaseArcgisUserPrivilegeMod(mods ...ArcgisUserPrivilegeMod)
f.baseArcgisUserPrivilegeMods = append(f.baseArcgisUserPrivilegeMods, mods...)
}
func (f *Factory) ClearBaseDistrictMods() {
f.baseDistrictMods = nil
}
func (f *Factory) AddBaseDistrictMod(mods ...DistrictMod) {
f.baseDistrictMods = append(f.baseDistrictMods, mods...)
}
func (f *Factory) ClearBaseFieldseekerContainerrelateMods() {
f.baseFieldseekerContainerrelateMods = nil
}
@ -3211,6 +3213,14 @@ func (f *Factory) AddBaseH3AggregationMod(mods ...H3AggregationMod) {
f.baseH3AggregationMods = append(f.baseH3AggregationMods, mods...)
}
func (f *Factory) ClearBaseImportDistrictMods() {
f.baseImportDistrictMods = nil
}
func (f *Factory) AddBaseImportDistrictMod(mods ...ImportDistrictMod) {
f.baseImportDistrictMods = append(f.baseImportDistrictMods, mods...)
}
func (f *Factory) ClearBaseNoteAudioMods() {
f.baseNoteAudioMods = nil
}

View file

@ -36,11 +36,13 @@ func (mods OrganizationModSlice) Apply(ctx context.Context, n *OrganizationTempl
// OrganizationTemplate is an object representing the database table.
// all columns are optional and should be set by mods
type OrganizationTemplate struct {
ID func() int32
Name func() string
ArcgisID func() null.Val[string]
ArcgisName func() null.Val[string]
FieldseekerURL func() null.Val[string]
ID func() int32
Name func() string
ArcgisID func() null.Val[string]
ArcgisName func() null.Val[string]
FieldseekerURL func() null.Val[string]
ImportDistrictGid func() null.Val[int32]
Website func() null.Val[string]
r organizationR
f *Factory
@ -49,38 +51,39 @@ type OrganizationTemplate struct {
}
type organizationR struct {
Containerrelates []*organizationRContainerrelatesR
Fieldscoutinglogs []*organizationRFieldscoutinglogsR
Habitatrelates []*organizationRHabitatrelatesR
Inspectionsamples []*organizationRInspectionsamplesR
Inspectionsampledetails []*organizationRInspectionsampledetailsR
Linelocations []*organizationRLinelocationsR
Locationtrackings []*organizationRLocationtrackingsR
Mosquitoinspections []*organizationRMosquitoinspectionsR
Pointlocations []*organizationRPointlocationsR
Polygonlocations []*organizationRPolygonlocationsR
Pools []*organizationRPoolsR
Pooldetails []*organizationRPooldetailsR
Proposedtreatmentareas []*organizationRProposedtreatmentareasR
Qamosquitoinspections []*organizationRQamosquitoinspectionsR
Rodentlocations []*organizationRRodentlocationsR
Samplecollections []*organizationRSamplecollectionsR
Samplelocations []*organizationRSamplelocationsR
Servicerequests []*organizationRServicerequestsR
Speciesabundances []*organizationRSpeciesabundancesR
Stormdrains []*organizationRStormdrainsR
Timecards []*organizationRTimecardsR
Trapdata []*organizationRTrapdataR
Traplocations []*organizationRTraplocationsR
Treatments []*organizationRTreatmentsR
Treatmentareas []*organizationRTreatmentareasR
Zones []*organizationRZonesR
Zones2s []*organizationRZones2sR
FieldseekerSyncs []*organizationRFieldseekerSyncsR
H3Aggregations []*organizationRH3AggregationsR
NoteAudios []*organizationRNoteAudiosR
NoteImages []*organizationRNoteImagesR
User []*organizationRUserR
Containerrelates []*organizationRContainerrelatesR
Fieldscoutinglogs []*organizationRFieldscoutinglogsR
Habitatrelates []*organizationRHabitatrelatesR
Inspectionsamples []*organizationRInspectionsamplesR
Inspectionsampledetails []*organizationRInspectionsampledetailsR
Linelocations []*organizationRLinelocationsR
Locationtrackings []*organizationRLocationtrackingsR
Mosquitoinspections []*organizationRMosquitoinspectionsR
Pointlocations []*organizationRPointlocationsR
Polygonlocations []*organizationRPolygonlocationsR
Pools []*organizationRPoolsR
Pooldetails []*organizationRPooldetailsR
Proposedtreatmentareas []*organizationRProposedtreatmentareasR
Qamosquitoinspections []*organizationRQamosquitoinspectionsR
Rodentlocations []*organizationRRodentlocationsR
Samplecollections []*organizationRSamplecollectionsR
Samplelocations []*organizationRSamplelocationsR
Servicerequests []*organizationRServicerequestsR
Speciesabundances []*organizationRSpeciesabundancesR
Stormdrains []*organizationRStormdrainsR
Timecards []*organizationRTimecardsR
Trapdata []*organizationRTrapdataR
Traplocations []*organizationRTraplocationsR
Treatments []*organizationRTreatmentsR
Treatmentareas []*organizationRTreatmentareasR
Zones []*organizationRZonesR
Zones2s []*organizationRZones2sR
FieldseekerSyncs []*organizationRFieldseekerSyncsR
H3Aggregations []*organizationRH3AggregationsR
NoteAudios []*organizationRNoteAudiosR
NoteImages []*organizationRNoteImagesR
ImportDistrictGidDistrict *organizationRImportDistrictGidDistrictR
User []*organizationRUserR
}
type organizationRContainerrelatesR struct {
@ -207,6 +210,9 @@ type organizationRNoteImagesR struct {
number int
o *NoteImageTemplate
}
type organizationRImportDistrictGidDistrictR struct {
o *ImportDistrictTemplate
}
type organizationRUserR struct {
number int
o *UserTemplate
@ -625,6 +631,13 @@ func (t OrganizationTemplate) setModelRels(o *models.Organization) {
o.R.NoteImages = rel
}
if t.r.ImportDistrictGidDistrict != nil {
rel := t.r.ImportDistrictGidDistrict.o.Build()
rel.R.ImportDistrictGidOrganization = o
o.ImportDistrictGid = null.From(rel.Gid) // h2
o.R.ImportDistrictGidDistrict = rel
}
if t.r.User != nil {
rel := models.UserSlice{}
for _, r := range t.r.User {
@ -664,6 +677,14 @@ func (o OrganizationTemplate) BuildSetter() *models.OrganizationSetter {
val := o.FieldseekerURL()
m.FieldseekerURL = omitnull.FromNull(val)
}
if o.ImportDistrictGid != nil {
val := o.ImportDistrictGid()
m.ImportDistrictGid = omitnull.FromNull(val)
}
if o.Website != nil {
val := o.Website()
m.Website = omitnull.FromNull(val)
}
return m
}
@ -701,6 +722,12 @@ func (o OrganizationTemplate) Build() *models.Organization {
if o.FieldseekerURL != nil {
m.FieldseekerURL = o.FieldseekerURL()
}
if o.ImportDistrictGid != nil {
m.ImportDistrictGid = o.ImportDistrictGid()
}
if o.Website != nil {
m.Website = o.Website()
}
o.setModelRels(m)
@ -1353,6 +1380,25 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu
}
}
isImportDistrictGidDistrictDone, _ := organizationRelImportDistrictGidDistrictCtx.Value(ctx)
if !isImportDistrictGidDistrictDone && o.r.ImportDistrictGidDistrict != nil {
ctx = organizationRelImportDistrictGidDistrictCtx.WithValue(ctx, true)
if o.r.ImportDistrictGidDistrict.o.alreadyPersisted {
m.R.ImportDistrictGidDistrict = o.r.ImportDistrictGidDistrict.o.Build()
} else {
var rel31 *models.ImportDistrict
rel31, err = o.r.ImportDistrictGidDistrict.o.Create(ctx, exec)
if err != nil {
return err
}
err = m.AttachImportDistrictGidDistrict(ctx, exec, rel31)
if err != nil {
return err
}
}
}
isUserDone, _ := organizationRelUserCtx.Value(ctx)
if !isUserDone && o.r.User != nil {
ctx = organizationRelUserCtx.WithValue(ctx, true)
@ -1360,12 +1406,12 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu
if r.o.alreadyPersisted {
m.R.User = append(m.R.User, r.o.Build())
} else {
rel31, err := r.o.CreateMany(ctx, exec, r.number)
rel32, err := r.o.CreateMany(ctx, exec, r.number)
if err != nil {
return err
}
err = m.AttachUser(ctx, exec, rel31...)
err = m.AttachUser(ctx, exec, rel32...)
if err != nil {
return err
}
@ -1470,6 +1516,8 @@ func (m organizationMods) RandomizeAllColumns(f *faker.Faker) OrganizationMod {
OrganizationMods.RandomArcgisID(f),
OrganizationMods.RandomArcgisName(f),
OrganizationMods.RandomFieldseekerURL(f),
OrganizationMods.RandomImportDistrictGid(f),
OrganizationMods.RandomWebsite(f),
}
}
@ -1694,12 +1742,153 @@ func (m organizationMods) RandomFieldseekerURLNotNull(f *faker.Faker) Organizati
})
}
// Set the model columns to this value
func (m organizationMods) ImportDistrictGid(val null.Val[int32]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ImportDistrictGid = func() null.Val[int32] { return val }
})
}
// Set the Column from the function
func (m organizationMods) ImportDistrictGidFunc(f func() null.Val[int32]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ImportDistrictGid = f
})
}
// Clear any values for the column
func (m organizationMods) UnsetImportDistrictGid() OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ImportDistrictGid = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m organizationMods) RandomImportDistrictGid(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ImportDistrictGid = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m organizationMods) RandomImportDistrictGidNotNull(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ImportDistrictGid = func() null.Val[int32] {
if f == nil {
f = &defaultFaker
}
val := random_int32(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m organizationMods) Website(val null.Val[string]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.Website = func() null.Val[string] { return val }
})
}
// Set the Column from the function
func (m organizationMods) WebsiteFunc(f func() null.Val[string]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.Website = f
})
}
// Clear any values for the column
func (m organizationMods) UnsetWebsite() OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.Website = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m organizationMods) RandomWebsite(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.Website = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m organizationMods) RandomWebsiteNotNull(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.Website = func() null.Val[string] {
if f == nil {
f = &defaultFaker
}
val := random_string(f)
return null.From(val)
}
})
}
func (m organizationMods) WithParentsCascading() OrganizationMod {
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
if isDone, _ := organizationWithParentsCascadingCtx.Value(ctx); isDone {
return
}
ctx = organizationWithParentsCascadingCtx.WithValue(ctx, true)
{
related := o.f.NewImportDistrictWithContext(ctx, ImportDistrictMods.WithParentsCascading())
m.WithImportDistrictGidDistrict(related).Apply(ctx, o)
}
})
}
func (m organizationMods) WithImportDistrictGidDistrict(rel *ImportDistrictTemplate) OrganizationMod {
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
o.r.ImportDistrictGidDistrict = &organizationRImportDistrictGidDistrictR{
o: rel,
}
})
}
func (m organizationMods) WithNewImportDistrictGidDistrict(mods ...ImportDistrictMod) OrganizationMod {
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
related := o.f.NewImportDistrictWithContext(ctx, mods...)
m.WithImportDistrictGidDistrict(related).Apply(ctx, o)
})
}
func (m organizationMods) WithExistingImportDistrictGidDistrict(em *models.ImportDistrict) OrganizationMod {
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
o.r.ImportDistrictGidDistrict = &organizationRImportDistrictGidDistrictR{
o: o.f.FromExistingImportDistrict(em),
}
})
}
func (m organizationMods) WithoutImportDistrictGidDistrict() OrganizationMod {
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
o.r.ImportDistrictGidDistrict = nil
})
}

View file

@ -0,0 +1,6 @@
-- +goose Up
ALTER TABLE public.organization ADD COLUMN import_district_gid INTEGER UNIQUE REFERENCES import.district(gid);
ALTER TABLE public.organization ADD COLUMN website TEXT UNIQUE;
-- +goose Down
ALTER TABLE public.organization DROP COLUMN website;
ALTER TABLE public.organization DROP COLUMN import_district_gid;

View file

@ -63,6 +63,7 @@ type joins[Q dialect.Joinable] struct {
FieldseekerZones2s joinSet[fieldseekerZones2Joins[Q]]
FieldseekerSyncs joinSet[fieldseekerSyncJoins[Q]]
H3Aggregations joinSet[h3AggregationJoins[Q]]
ImportDistricts joinSet[importDistrictJoins[Q]]
NoteAudios joinSet[noteAudioJoins[Q]]
NoteAudioBreadcrumbs joinSet[noteAudioBreadcrumbJoins[Q]]
NoteAudioData joinSet[noteAudioDatumJoins[Q]]
@ -120,6 +121,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
FieldseekerZones2s: buildJoinSet[fieldseekerZones2Joins[Q]](FieldseekerZones2s.Columns, buildFieldseekerZones2Joins),
FieldseekerSyncs: buildJoinSet[fieldseekerSyncJoins[Q]](FieldseekerSyncs.Columns, buildFieldseekerSyncJoins),
H3Aggregations: buildJoinSet[h3AggregationJoins[Q]](H3Aggregations.Columns, buildH3AggregationJoins),
ImportDistricts: buildJoinSet[importDistrictJoins[Q]](ImportDistricts.Columns, buildImportDistrictJoins),
NoteAudios: buildJoinSet[noteAudioJoins[Q]](NoteAudios.Columns, buildNoteAudioJoins),
NoteAudioBreadcrumbs: buildJoinSet[noteAudioBreadcrumbJoins[Q]](NoteAudioBreadcrumbs.Columns, buildNoteAudioBreadcrumbJoins),
NoteAudioData: buildJoinSet[noteAudioDatumJoins[Q]](NoteAudioData.Columns, buildNoteAudioDatumJoins),

View file

@ -48,6 +48,7 @@ type preloaders struct {
FieldseekerZones2 fieldseekerZones2Preloader
FieldseekerSync fieldseekerSyncPreloader
H3Aggregation h3AggregationPreloader
ImportDistrict importDistrictPreloader
NoteAudio noteAudioPreloader
NoteAudioBreadcrumb noteAudioBreadcrumbPreloader
NoteAudioDatum noteAudioDatumPreloader
@ -97,6 +98,7 @@ func getPreloaders() preloaders {
FieldseekerZones2: buildFieldseekerZones2Preloader(),
FieldseekerSync: buildFieldseekerSyncPreloader(),
H3Aggregation: buildH3AggregationPreloader(),
ImportDistrict: buildImportDistrictPreloader(),
NoteAudio: buildNoteAudioPreloader(),
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbPreloader(),
NoteAudioDatum: buildNoteAudioDatumPreloader(),
@ -152,6 +154,7 @@ type thenLoaders[Q orm.Loadable] struct {
FieldseekerZones2 fieldseekerZones2ThenLoader[Q]
FieldseekerSync fieldseekerSyncThenLoader[Q]
H3Aggregation h3AggregationThenLoader[Q]
ImportDistrict importDistrictThenLoader[Q]
NoteAudio noteAudioThenLoader[Q]
NoteAudioBreadcrumb noteAudioBreadcrumbThenLoader[Q]
NoteAudioDatum noteAudioDatumThenLoader[Q]
@ -201,6 +204,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
FieldseekerZones2: buildFieldseekerZones2ThenLoader[Q](),
FieldseekerSync: buildFieldseekerSyncThenLoader[Q](),
H3Aggregation: buildH3AggregationThenLoader[Q](),
ImportDistrict: buildImportDistrictThenLoader[Q](),
NoteAudio: buildNoteAudioThenLoader[Q](),
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbThenLoader[Q](),
NoteAudioDatum: buildNoteAudioDatumThenLoader[Q](),

View file

@ -19,7 +19,6 @@ var (
func Where[Q psql.Filterable]() struct {
ArcgisUsers arcgisuserWhere[Q]
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
Districts districtWhere[Q]
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
FieldseekerFieldscoutinglogs fieldseekerFieldscoutinglogWhere[Q]
FieldseekerHabitatrelates fieldseekerHabitatrelateWhere[Q]
@ -52,6 +51,7 @@ func Where[Q psql.Filterable]() struct {
GeometryColumns geometryColumnWhere[Q]
GooseDBVersions gooseDBVersionWhere[Q]
H3Aggregations h3AggregationWhere[Q]
ImportDistricts importDistrictWhere[Q]
NoteAudios noteAudioWhere[Q]
NoteAudioBreadcrumbs noteAudioBreadcrumbWhere[Q]
NoteAudioData noteAudioDatumWhere[Q]
@ -76,7 +76,6 @@ func Where[Q psql.Filterable]() struct {
return struct {
ArcgisUsers arcgisuserWhere[Q]
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
Districts districtWhere[Q]
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
FieldseekerFieldscoutinglogs fieldseekerFieldscoutinglogWhere[Q]
FieldseekerHabitatrelates fieldseekerHabitatrelateWhere[Q]
@ -109,6 +108,7 @@ func Where[Q psql.Filterable]() struct {
GeometryColumns geometryColumnWhere[Q]
GooseDBVersions gooseDBVersionWhere[Q]
H3Aggregations h3AggregationWhere[Q]
ImportDistricts importDistrictWhere[Q]
NoteAudios noteAudioWhere[Q]
NoteAudioBreadcrumbs noteAudioBreadcrumbWhere[Q]
NoteAudioData noteAudioDatumWhere[Q]
@ -132,7 +132,6 @@ func Where[Q psql.Filterable]() struct {
}{
ArcgisUsers: buildArcgisUserWhere[Q](ArcgisUsers.Columns),
ArcgisUserPrivileges: buildArcgisUserPrivilegeWhere[Q](ArcgisUserPrivileges.Columns),
Districts: buildDistrictWhere[Q](Districts.Columns),
FieldseekerContainerrelates: buildFieldseekerContainerrelateWhere[Q](FieldseekerContainerrelates.Columns),
FieldseekerFieldscoutinglogs: buildFieldseekerFieldscoutinglogWhere[Q](FieldseekerFieldscoutinglogs.Columns),
FieldseekerHabitatrelates: buildFieldseekerHabitatrelateWhere[Q](FieldseekerHabitatrelates.Columns),
@ -165,6 +164,7 @@ func Where[Q psql.Filterable]() struct {
GeometryColumns: buildGeometryColumnWhere[Q](GeometryColumns.Columns),
GooseDBVersions: buildGooseDBVersionWhere[Q](GooseDBVersions.Columns),
H3Aggregations: buildH3AggregationWhere[Q](H3Aggregations.Columns),
ImportDistricts: buildImportDistrictWhere[Q](ImportDistricts.Columns),
NoteAudios: buildNoteAudioWhere[Q](NoteAudios.Columns),
NoteAudioBreadcrumbs: buildNoteAudioBreadcrumbWhere[Q](NoteAudioBreadcrumbs.Columns),
NoteAudioData: buildNoteAudioDatumWhere[Q](NoteAudioData.Columns),

View file

@ -5,6 +5,7 @@ package models
import (
"context"
"fmt"
"io"
"github.com/aarondl/opt/null"
@ -18,10 +19,13 @@ import (
"github.com/stephenafamo/bob/dialect/psql/sm"
"github.com/stephenafamo/bob/dialect/psql/um"
"github.com/stephenafamo/bob/expr"
"github.com/stephenafamo/bob/mods"
"github.com/stephenafamo/bob/orm"
"github.com/stephenafamo/bob/types/pgtypes"
)
// District is an object representing the database table.
type District struct {
// ImportDistrict is an object representing the database table.
type ImportDistrict struct {
Gid int32 `db:"gid,pk" `
ID null.Val[decimal.Decimal] `db:"id" `
Website null.Val[string] `db:"website" `
@ -45,23 +49,30 @@ type District struct {
ShapeArea null.Val[decimal.Decimal] `db:"shape_area" `
Geom null.Val[string] `db:"geom" `
Geom4326 null.Val[string] `db:"geom_4326,generated" `
R importDistrictR `db:"-" `
}
// DistrictSlice is an alias for a slice of pointers to District.
// This should almost always be used instead of []*District.
type DistrictSlice []*District
// ImportDistrictSlice is an alias for a slice of pointers to ImportDistrict.
// This should almost always be used instead of []*ImportDistrict.
type ImportDistrictSlice []*ImportDistrict
// Districts contains methods to work with the district table
var Districts = psql.NewTablex[*District, DistrictSlice, *DistrictSetter]("", "district", buildDistrictColumns("district"))
// ImportDistricts contains methods to work with the district table
var ImportDistricts = psql.NewTablex[*ImportDistrict, ImportDistrictSlice, *ImportDistrictSetter]("import", "district", buildImportDistrictColumns("import.district"))
// DistrictsQuery is a query on the district table
type DistrictsQuery = *psql.ViewQuery[*District, DistrictSlice]
// ImportDistrictsQuery is a query on the district table
type ImportDistrictsQuery = *psql.ViewQuery[*ImportDistrict, ImportDistrictSlice]
func buildDistrictColumns(alias string) districtColumns {
return districtColumns{
// importDistrictR is where relationships are stored.
type importDistrictR struct {
ImportDistrictGidOrganization *Organization // organization.organization_import_district_gid_fkey
}
func buildImportDistrictColumns(alias string) importDistrictColumns {
return importDistrictColumns{
ColumnsExpr: expr.NewColumnsExpr(
"gid", "id", "website", "contact", "address", "regionid", "postal_cod", "phone1", "fax1", "agency", "code1", "city1", "shape_leng", "address2", "general_mg", "city2", "postal_c_1", "fax2", "phone2", "shape_le_1", "shape_area", "geom", "geom_4326",
).WithParent("district"),
).WithParent("import.district"),
tableAlias: alias,
Gid: psql.Quote(alias, "gid"),
ID: psql.Quote(alias, "id"),
@ -89,7 +100,7 @@ func buildDistrictColumns(alias string) districtColumns {
}
}
type districtColumns struct {
type importDistrictColumns struct {
expr.ColumnsExpr
tableAlias string
Gid psql.Expression
@ -117,18 +128,18 @@ type districtColumns struct {
Geom4326 psql.Expression
}
func (c districtColumns) Alias() string {
func (c importDistrictColumns) Alias() string {
return c.tableAlias
}
func (districtColumns) AliasedAs(alias string) districtColumns {
return buildDistrictColumns(alias)
func (importDistrictColumns) AliasedAs(alias string) importDistrictColumns {
return buildImportDistrictColumns(alias)
}
// DistrictSetter is used for insert/upsert/update operations
// ImportDistrictSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type DistrictSetter struct {
type ImportDistrictSetter struct {
Gid omit.Val[int32] `db:"gid,pk" `
ID omitnull.Val[decimal.Decimal] `db:"id" `
Website omitnull.Val[string] `db:"website" `
@ -153,7 +164,7 @@ type DistrictSetter struct {
Geom omitnull.Val[string] `db:"geom" `
}
func (s DistrictSetter) SetColumns() []string {
func (s ImportDistrictSetter) SetColumns() []string {
vals := make([]string, 0, 22)
if s.Gid.IsValue() {
vals = append(vals, "gid")
@ -224,7 +235,7 @@ func (s DistrictSetter) SetColumns() []string {
return vals
}
func (s DistrictSetter) Overwrite(t *District) {
func (s ImportDistrictSetter) Overwrite(t *ImportDistrict) {
if s.Gid.IsValue() {
t.Gid = s.Gid.MustGet()
}
@ -293,9 +304,9 @@ func (s DistrictSetter) Overwrite(t *District) {
}
}
func (s *DistrictSetter) Apply(q *dialect.InsertQuery) {
func (s *ImportDistrictSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return Districts.BeforeInsertHooks.RunHooks(ctx, exec, s)
return ImportDistricts.BeforeInsertHooks.RunHooks(ctx, exec, s)
})
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
@ -436,11 +447,11 @@ func (s *DistrictSetter) Apply(q *dialect.InsertQuery) {
}))
}
func (s DistrictSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
func (s ImportDistrictSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s DistrictSetter) Expressions(prefix ...string) []bob.Expression {
func (s ImportDistrictSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 22)
if s.Gid.IsValue() {
@ -600,113 +611,114 @@ func (s DistrictSetter) Expressions(prefix ...string) []bob.Expression {
return exprs
}
// FindDistrict retrieves a single record by primary key
// FindImportDistrict retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindDistrict(ctx context.Context, exec bob.Executor, GidPK int32, cols ...string) (*District, error) {
func FindImportDistrict(ctx context.Context, exec bob.Executor, GidPK int32, cols ...string) (*ImportDistrict, error) {
if len(cols) == 0 {
return Districts.Query(
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(GidPK))),
return ImportDistricts.Query(
sm.Where(ImportDistricts.Columns.Gid.EQ(psql.Arg(GidPK))),
).One(ctx, exec)
}
return Districts.Query(
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(GidPK))),
sm.Columns(Districts.Columns.Only(cols...)),
return ImportDistricts.Query(
sm.Where(ImportDistricts.Columns.Gid.EQ(psql.Arg(GidPK))),
sm.Columns(ImportDistricts.Columns.Only(cols...)),
).One(ctx, exec)
}
// DistrictExists checks the presence of a single record by primary key
func DistrictExists(ctx context.Context, exec bob.Executor, GidPK int32) (bool, error) {
return Districts.Query(
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(GidPK))),
// ImportDistrictExists checks the presence of a single record by primary key
func ImportDistrictExists(ctx context.Context, exec bob.Executor, GidPK int32) (bool, error) {
return ImportDistricts.Query(
sm.Where(ImportDistricts.Columns.Gid.EQ(psql.Arg(GidPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after District is retrieved from the database
func (o *District) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
// AfterQueryHook is called after ImportDistrict is retrieved from the database
func (o *ImportDistrict) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = Districts.AfterSelectHooks.RunHooks(ctx, exec, DistrictSlice{o})
ctx, err = ImportDistricts.AfterSelectHooks.RunHooks(ctx, exec, ImportDistrictSlice{o})
case bob.QueryTypeInsert:
ctx, err = Districts.AfterInsertHooks.RunHooks(ctx, exec, DistrictSlice{o})
ctx, err = ImportDistricts.AfterInsertHooks.RunHooks(ctx, exec, ImportDistrictSlice{o})
case bob.QueryTypeUpdate:
ctx, err = Districts.AfterUpdateHooks.RunHooks(ctx, exec, DistrictSlice{o})
ctx, err = ImportDistricts.AfterUpdateHooks.RunHooks(ctx, exec, ImportDistrictSlice{o})
case bob.QueryTypeDelete:
ctx, err = Districts.AfterDeleteHooks.RunHooks(ctx, exec, DistrictSlice{o})
ctx, err = ImportDistricts.AfterDeleteHooks.RunHooks(ctx, exec, ImportDistrictSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the District
func (o *District) primaryKeyVals() bob.Expression {
// primaryKeyVals returns the primary key values of the ImportDistrict
func (o *ImportDistrict) primaryKeyVals() bob.Expression {
return psql.Arg(o.Gid)
}
func (o *District) pkEQ() dialect.Expression {
return psql.Quote("district", "gid").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
func (o *ImportDistrict) pkEQ() dialect.Expression {
return psql.Quote("import.district", "gid").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 District
func (o *District) Update(ctx context.Context, exec bob.Executor, s *DistrictSetter) error {
v, err := Districts.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
// Update uses an executor to update the ImportDistrict
func (o *ImportDistrict) Update(ctx context.Context, exec bob.Executor, s *ImportDistrictSetter) error {
v, err := ImportDistricts.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 District record with an executor
func (o *District) Delete(ctx context.Context, exec bob.Executor) error {
_, err := Districts.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
// Delete deletes a single ImportDistrict record with an executor
func (o *ImportDistrict) Delete(ctx context.Context, exec bob.Executor) error {
_, err := ImportDistricts.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the District using the executor
func (o *District) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := Districts.Query(
sm.Where(Districts.Columns.Gid.EQ(psql.Arg(o.Gid))),
// Reload refreshes the ImportDistrict using the executor
func (o *ImportDistrict) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := ImportDistricts.Query(
sm.Where(ImportDistricts.Columns.Gid.EQ(psql.Arg(o.Gid))),
).One(ctx, exec)
if err != nil {
return err
}
o2.R = o.R
*o = *o2
return nil
}
// AfterQueryHook is called after DistrictSlice is retrieved from the database
func (o DistrictSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
// AfterQueryHook is called after ImportDistrictSlice is retrieved from the database
func (o ImportDistrictSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = Districts.AfterSelectHooks.RunHooks(ctx, exec, o)
ctx, err = ImportDistricts.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = Districts.AfterInsertHooks.RunHooks(ctx, exec, o)
ctx, err = ImportDistricts.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = Districts.AfterUpdateHooks.RunHooks(ctx, exec, o)
ctx, err = ImportDistricts.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = Districts.AfterDeleteHooks.RunHooks(ctx, exec, o)
ctx, err = ImportDistricts.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o DistrictSlice) pkIN() dialect.Expression {
func (o ImportDistrictSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("district", "gid").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return psql.Quote("import.district", "gid").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()
@ -718,13 +730,13 @@ func (o DistrictSlice) 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 DistrictSlice) copyMatchingRows(from ...*District) {
func (o ImportDistrictSlice) copyMatchingRows(from ...*ImportDistrict) {
for i, old := range o {
for _, new := range from {
if new.Gid != old.Gid {
continue
}
new.R = old.R
o[i] = new
break
}
@ -732,25 +744,25 @@ func (o DistrictSlice) copyMatchingRows(from ...*District) {
}
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o DistrictSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
func (o ImportDistrictSlice) 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 Districts.BeforeUpdateHooks.RunHooks(ctx, exec, o)
return ImportDistricts.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 *District:
case *ImportDistrict:
o.copyMatchingRows(retrieved)
case []*District:
case []*ImportDistrict:
o.copyMatchingRows(retrieved...)
case DistrictSlice:
case ImportDistrictSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a District or a slice of District
// If the retrieved value is not a ImportDistrict or a slice of ImportDistrict
// then run the AfterUpdateHooks on the slice
_, err = Districts.AfterUpdateHooks.RunHooks(ctx, exec, o)
_, err = ImportDistricts.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
@ -761,25 +773,25 @@ func (o DistrictSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o DistrictSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
func (o ImportDistrictSlice) 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 Districts.BeforeDeleteHooks.RunHooks(ctx, exec, o)
return ImportDistricts.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 *District:
case *ImportDistrict:
o.copyMatchingRows(retrieved)
case []*District:
case []*ImportDistrict:
o.copyMatchingRows(retrieved...)
case DistrictSlice:
case ImportDistrictSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a District or a slice of District
// If the retrieved value is not a ImportDistrict or a slice of ImportDistrict
// then run the AfterDeleteHooks on the slice
_, err = Districts.AfterDeleteHooks.RunHooks(ctx, exec, o)
_, err = ImportDistricts.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
@ -789,30 +801,30 @@ func (o DistrictSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
})
}
func (o DistrictSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DistrictSetter) error {
func (o ImportDistrictSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ImportDistrictSetter) error {
if len(o) == 0 {
return nil
}
_, err := Districts.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
_, err := ImportDistricts.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o DistrictSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
func (o ImportDistrictSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := Districts.Delete(o.DeleteMod()).Exec(ctx, exec)
_, err := ImportDistricts.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o DistrictSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
func (o ImportDistrictSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := Districts.Query(sm.Where(o.pkIN())).All(ctx, exec)
o2, err := ImportDistricts.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
@ -822,7 +834,85 @@ func (o DistrictSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
return nil
}
type districtWhere[Q psql.Filterable] struct {
// ImportDistrictGidOrganization starts a query for related objects on organization
func (o *ImportDistrict) ImportDistrictGidOrganization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
return Organizations.Query(append(mods,
sm.Where(Organizations.Columns.ImportDistrictGid.EQ(psql.Arg(o.Gid))),
)...)
}
func (os ImportDistrictSlice) ImportDistrictGidOrganization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
pkGid := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkGid = append(pkGid, o.Gid)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkGid), "integer[]")),
))
return Organizations.Query(append(mods,
sm.Where(psql.Group(Organizations.Columns.ImportDistrictGid).OP("IN", PKArgExpr)),
)...)
}
func insertImportDistrictImportDistrictGidOrganization0(ctx context.Context, exec bob.Executor, organization1 *OrganizationSetter, importDistrict0 *ImportDistrict) (*Organization, error) {
organization1.ImportDistrictGid = omitnull.From(importDistrict0.Gid)
ret, err := Organizations.Insert(organization1).One(ctx, exec)
if err != nil {
return ret, fmt.Errorf("insertImportDistrictImportDistrictGidOrganization0: %w", err)
}
return ret, nil
}
func attachImportDistrictImportDistrictGidOrganization0(ctx context.Context, exec bob.Executor, count int, organization1 *Organization, importDistrict0 *ImportDistrict) (*Organization, error) {
setter := &OrganizationSetter{
ImportDistrictGid: omitnull.From(importDistrict0.Gid),
}
err := organization1.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachImportDistrictImportDistrictGidOrganization0: %w", err)
}
return organization1, nil
}
func (importDistrict0 *ImportDistrict) InsertImportDistrictGidOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
var err error
organization1, err := insertImportDistrictImportDistrictGidOrganization0(ctx, exec, related, importDistrict0)
if err != nil {
return err
}
importDistrict0.R.ImportDistrictGidOrganization = organization1
organization1.R.ImportDistrictGidDistrict = importDistrict0
return nil
}
func (importDistrict0 *ImportDistrict) AttachImportDistrictGidOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
var err error
_, err = attachImportDistrictImportDistrictGidOrganization0(ctx, exec, 1, organization1, importDistrict0)
if err != nil {
return err
}
importDistrict0.R.ImportDistrictGidOrganization = organization1
organization1.R.ImportDistrictGidDistrict = importDistrict0
return nil
}
type importDistrictWhere[Q psql.Filterable] struct {
Gid psql.WhereMod[Q, int32]
ID psql.WhereNullMod[Q, decimal.Decimal]
Website psql.WhereNullMod[Q, string]
@ -848,12 +938,12 @@ type districtWhere[Q psql.Filterable] struct {
Geom4326 psql.WhereNullMod[Q, string]
}
func (districtWhere[Q]) AliasedAs(alias string) districtWhere[Q] {
return buildDistrictWhere[Q](buildDistrictColumns(alias))
func (importDistrictWhere[Q]) AliasedAs(alias string) importDistrictWhere[Q] {
return buildImportDistrictWhere[Q](buildImportDistrictColumns(alias))
}
func buildDistrictWhere[Q psql.Filterable](cols districtColumns) districtWhere[Q] {
return districtWhere[Q]{
func buildImportDistrictWhere[Q psql.Filterable](cols importDistrictColumns) importDistrictWhere[Q] {
return importDistrictWhere[Q]{
Gid: psql.Where[Q, int32](cols.Gid),
ID: psql.WhereNull[Q, decimal.Decimal](cols.ID),
Website: psql.WhereNull[Q, string](cols.Website),
@ -879,3 +969,151 @@ func buildDistrictWhere[Q psql.Filterable](cols districtColumns) districtWhere[Q
Geom4326: psql.WhereNull[Q, string](cols.Geom4326),
}
}
func (o *ImportDistrict) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "ImportDistrictGidOrganization":
rel, ok := retrieved.(*Organization)
if !ok {
return fmt.Errorf("importDistrict cannot load %T as %q", retrieved, name)
}
o.R.ImportDistrictGidOrganization = rel
if rel != nil {
rel.R.ImportDistrictGidDistrict = o
}
return nil
default:
return fmt.Errorf("importDistrict has no relationship %q", name)
}
}
type importDistrictPreloader struct {
ImportDistrictGidOrganization func(...psql.PreloadOption) psql.Preloader
}
func buildImportDistrictPreloader() importDistrictPreloader {
return importDistrictPreloader{
ImportDistrictGidOrganization: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
Name: "ImportDistrictGidOrganization",
Sides: []psql.PreloadSide{
{
From: ImportDistricts,
To: Organizations,
FromColumns: []string{"gid"},
ToColumns: []string{"import_district_gid"},
},
},
}, Organizations.Columns.Names(), opts...)
},
}
}
type importDistrictThenLoader[Q orm.Loadable] struct {
ImportDistrictGidOrganization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildImportDistrictThenLoader[Q orm.Loadable]() importDistrictThenLoader[Q] {
type ImportDistrictGidOrganizationLoadInterface interface {
LoadImportDistrictGidOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return importDistrictThenLoader[Q]{
ImportDistrictGidOrganization: thenLoadBuilder[Q](
"ImportDistrictGidOrganization",
func(ctx context.Context, exec bob.Executor, retrieved ImportDistrictGidOrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImportDistrictGidOrganization(ctx, exec, mods...)
},
),
}
}
// LoadImportDistrictGidOrganization loads the importDistrict's ImportDistrictGidOrganization into the .R struct
func (o *ImportDistrict) LoadImportDistrictGidOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ImportDistrictGidOrganization = nil
related, err := o.ImportDistrictGidOrganization(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ImportDistrictGidDistrict = o
o.R.ImportDistrictGidOrganization = related
return nil
}
// LoadImportDistrictGidOrganization loads the importDistrict's ImportDistrictGidOrganization into the .R struct
func (os ImportDistrictSlice) LoadImportDistrictGidOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
organizations, err := os.ImportDistrictGidOrganization(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range organizations {
if !rel.ImportDistrictGid.IsValue() {
continue
}
if !(rel.ImportDistrictGid.IsValue() && o.Gid == rel.ImportDistrictGid.MustGet()) {
continue
}
rel.R.ImportDistrictGidDistrict = o
o.R.ImportDistrictGidOrganization = rel
break
}
}
return nil
}
type importDistrictJoins[Q dialect.Joinable] struct {
typ string
ImportDistrictGidOrganization modAs[Q, organizationColumns]
}
func (j importDistrictJoins[Q]) aliasedAs(alias string) importDistrictJoins[Q] {
return buildImportDistrictJoins[Q](buildImportDistrictColumns(alias), j.typ)
}
func buildImportDistrictJoins[Q dialect.Joinable](cols importDistrictColumns, typ string) importDistrictJoins[Q] {
return importDistrictJoins[Q]{
typ: typ,
ImportDistrictGidOrganization: modAs[Q, organizationColumns]{
c: Organizations.Columns,
f: func(to organizationColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
to.ImportDistrictGid.EQ(cols.Gid),
))
}
return mods
},
},
}
}

View file

@ -25,11 +25,13 @@ import (
// Organization is an object representing the database table.
type Organization struct {
ID int32 `db:"id,pk" `
Name string `db:"name" `
ArcgisID null.Val[string] `db:"arcgis_id" `
ArcgisName null.Val[string] `db:"arcgis_name" `
FieldseekerURL null.Val[string] `db:"fieldseeker_url" `
ID int32 `db:"id,pk" `
Name string `db:"name" `
ArcgisID null.Val[string] `db:"arcgis_id" `
ArcgisName null.Val[string] `db:"arcgis_name" `
FieldseekerURL null.Val[string] `db:"fieldseeker_url" `
ImportDistrictGid null.Val[int32] `db:"import_district_gid" `
Website null.Val[string] `db:"website" `
R organizationR `db:"-" `
@ -48,62 +50,67 @@ type OrganizationsQuery = *psql.ViewQuery[*Organization, OrganizationSlice]
// organizationR is where relationships are stored.
type organizationR struct {
Containerrelates FieldseekerContainerrelateSlice // fieldseeker.containerrelate.containerrelate_organization_id_fkey
Fieldscoutinglogs FieldseekerFieldscoutinglogSlice // fieldseeker.fieldscoutinglog.fieldscoutinglog_organization_id_fkey
Habitatrelates FieldseekerHabitatrelateSlice // fieldseeker.habitatrelate.habitatrelate_organization_id_fkey
Inspectionsamples FieldseekerInspectionsampleSlice // fieldseeker.inspectionsample.inspectionsample_organization_id_fkey
Inspectionsampledetails FieldseekerInspectionsampledetailSlice // fieldseeker.inspectionsampledetail.inspectionsampledetail_organization_id_fkey
Linelocations FieldseekerLinelocationSlice // fieldseeker.linelocation.linelocation_organization_id_fkey
Locationtrackings FieldseekerLocationtrackingSlice // fieldseeker.locationtracking.locationtracking_organization_id_fkey
Mosquitoinspections FieldseekerMosquitoinspectionSlice // fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey
Pointlocations FieldseekerPointlocationSlice // fieldseeker.pointlocation.pointlocation_organization_id_fkey
Polygonlocations FieldseekerPolygonlocationSlice // fieldseeker.polygonlocation.polygonlocation_organization_id_fkey
Pools FieldseekerPoolSlice // fieldseeker.pool.pool_organization_id_fkey
Pooldetails FieldseekerPooldetailSlice // fieldseeker.pooldetail.pooldetail_organization_id_fkey
Proposedtreatmentareas FieldseekerProposedtreatmentareaSlice // fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey
Qamosquitoinspections FieldseekerQamosquitoinspectionSlice // fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey
Rodentlocations FieldseekerRodentlocationSlice // fieldseeker.rodentlocation.rodentlocation_organization_id_fkey
Samplecollections FieldseekerSamplecollectionSlice // fieldseeker.samplecollection.samplecollection_organization_id_fkey
Samplelocations FieldseekerSamplelocationSlice // fieldseeker.samplelocation.samplelocation_organization_id_fkey
Servicerequests FieldseekerServicerequestSlice // fieldseeker.servicerequest.servicerequest_organization_id_fkey
Speciesabundances FieldseekerSpeciesabundanceSlice // fieldseeker.speciesabundance.speciesabundance_organization_id_fkey
Stormdrains FieldseekerStormdrainSlice // fieldseeker.stormdrain.stormdrain_organization_id_fkey
Timecards FieldseekerTimecardSlice // fieldseeker.timecard.timecard_organization_id_fkey
Trapdata FieldseekerTrapdatumSlice // fieldseeker.trapdata.trapdata_organization_id_fkey
Traplocations FieldseekerTraplocationSlice // fieldseeker.traplocation.traplocation_organization_id_fkey
Treatments FieldseekerTreatmentSlice // fieldseeker.treatment.treatment_organization_id_fkey
Treatmentareas FieldseekerTreatmentareaSlice // fieldseeker.treatmentarea.treatmentarea_organization_id_fkey
Zones FieldseekerZoneSlice // fieldseeker.zones.zones_organization_id_fkey
Zones2s FieldseekerZones2Slice // fieldseeker.zones2.zones2_organization_id_fkey
FieldseekerSyncs FieldseekerSyncSlice // fieldseeker_sync.fieldseeker_sync_organization_id_fkey
H3Aggregations H3AggregationSlice // h3_aggregation.h3_aggregation_organization_id_fkey
NoteAudios NoteAudioSlice // note_audio.note_audio_organization_id_fkey
NoteImages NoteImageSlice // note_image.note_image_organization_id_fkey
User UserSlice // user_.user__organization_id_fkey
Containerrelates FieldseekerContainerrelateSlice // fieldseeker.containerrelate.containerrelate_organization_id_fkey
Fieldscoutinglogs FieldseekerFieldscoutinglogSlice // fieldseeker.fieldscoutinglog.fieldscoutinglog_organization_id_fkey
Habitatrelates FieldseekerHabitatrelateSlice // fieldseeker.habitatrelate.habitatrelate_organization_id_fkey
Inspectionsamples FieldseekerInspectionsampleSlice // fieldseeker.inspectionsample.inspectionsample_organization_id_fkey
Inspectionsampledetails FieldseekerInspectionsampledetailSlice // fieldseeker.inspectionsampledetail.inspectionsampledetail_organization_id_fkey
Linelocations FieldseekerLinelocationSlice // fieldseeker.linelocation.linelocation_organization_id_fkey
Locationtrackings FieldseekerLocationtrackingSlice // fieldseeker.locationtracking.locationtracking_organization_id_fkey
Mosquitoinspections FieldseekerMosquitoinspectionSlice // fieldseeker.mosquitoinspection.mosquitoinspection_organization_id_fkey
Pointlocations FieldseekerPointlocationSlice // fieldseeker.pointlocation.pointlocation_organization_id_fkey
Polygonlocations FieldseekerPolygonlocationSlice // fieldseeker.polygonlocation.polygonlocation_organization_id_fkey
Pools FieldseekerPoolSlice // fieldseeker.pool.pool_organization_id_fkey
Pooldetails FieldseekerPooldetailSlice // fieldseeker.pooldetail.pooldetail_organization_id_fkey
Proposedtreatmentareas FieldseekerProposedtreatmentareaSlice // fieldseeker.proposedtreatmentarea.proposedtreatmentarea_organization_id_fkey
Qamosquitoinspections FieldseekerQamosquitoinspectionSlice // fieldseeker.qamosquitoinspection.qamosquitoinspection_organization_id_fkey
Rodentlocations FieldseekerRodentlocationSlice // fieldseeker.rodentlocation.rodentlocation_organization_id_fkey
Samplecollections FieldseekerSamplecollectionSlice // fieldseeker.samplecollection.samplecollection_organization_id_fkey
Samplelocations FieldseekerSamplelocationSlice // fieldseeker.samplelocation.samplelocation_organization_id_fkey
Servicerequests FieldseekerServicerequestSlice // fieldseeker.servicerequest.servicerequest_organization_id_fkey
Speciesabundances FieldseekerSpeciesabundanceSlice // fieldseeker.speciesabundance.speciesabundance_organization_id_fkey
Stormdrains FieldseekerStormdrainSlice // fieldseeker.stormdrain.stormdrain_organization_id_fkey
Timecards FieldseekerTimecardSlice // fieldseeker.timecard.timecard_organization_id_fkey
Trapdata FieldseekerTrapdatumSlice // fieldseeker.trapdata.trapdata_organization_id_fkey
Traplocations FieldseekerTraplocationSlice // fieldseeker.traplocation.traplocation_organization_id_fkey
Treatments FieldseekerTreatmentSlice // fieldseeker.treatment.treatment_organization_id_fkey
Treatmentareas FieldseekerTreatmentareaSlice // fieldseeker.treatmentarea.treatmentarea_organization_id_fkey
Zones FieldseekerZoneSlice // fieldseeker.zones.zones_organization_id_fkey
Zones2s FieldseekerZones2Slice // fieldseeker.zones2.zones2_organization_id_fkey
FieldseekerSyncs FieldseekerSyncSlice // fieldseeker_sync.fieldseeker_sync_organization_id_fkey
H3Aggregations H3AggregationSlice // h3_aggregation.h3_aggregation_organization_id_fkey
NoteAudios NoteAudioSlice // note_audio.note_audio_organization_id_fkey
NoteImages NoteImageSlice // note_image.note_image_organization_id_fkey
ImportDistrictGidDistrict *ImportDistrict // organization.organization_import_district_gid_fkey
User UserSlice // user_.user__organization_id_fkey
}
func buildOrganizationColumns(alias string) organizationColumns {
return organizationColumns{
ColumnsExpr: expr.NewColumnsExpr(
"id", "name", "arcgis_id", "arcgis_name", "fieldseeker_url",
"id", "name", "arcgis_id", "arcgis_name", "fieldseeker_url", "import_district_gid", "website",
).WithParent("organization"),
tableAlias: alias,
ID: psql.Quote(alias, "id"),
Name: psql.Quote(alias, "name"),
ArcgisID: psql.Quote(alias, "arcgis_id"),
ArcgisName: psql.Quote(alias, "arcgis_name"),
FieldseekerURL: psql.Quote(alias, "fieldseeker_url"),
tableAlias: alias,
ID: psql.Quote(alias, "id"),
Name: psql.Quote(alias, "name"),
ArcgisID: psql.Quote(alias, "arcgis_id"),
ArcgisName: psql.Quote(alias, "arcgis_name"),
FieldseekerURL: psql.Quote(alias, "fieldseeker_url"),
ImportDistrictGid: psql.Quote(alias, "import_district_gid"),
Website: psql.Quote(alias, "website"),
}
}
type organizationColumns struct {
expr.ColumnsExpr
tableAlias string
ID psql.Expression
Name psql.Expression
ArcgisID psql.Expression
ArcgisName psql.Expression
FieldseekerURL psql.Expression
tableAlias string
ID psql.Expression
Name psql.Expression
ArcgisID psql.Expression
ArcgisName psql.Expression
FieldseekerURL psql.Expression
ImportDistrictGid psql.Expression
Website psql.Expression
}
func (c organizationColumns) Alias() string {
@ -118,15 +125,17 @@ func (organizationColumns) AliasedAs(alias string) organizationColumns {
// All values are optional, and do not have to be set
// Generated columns are not included
type OrganizationSetter struct {
ID omit.Val[int32] `db:"id,pk" `
Name omit.Val[string] `db:"name" `
ArcgisID omitnull.Val[string] `db:"arcgis_id" `
ArcgisName omitnull.Val[string] `db:"arcgis_name" `
FieldseekerURL omitnull.Val[string] `db:"fieldseeker_url" `
ID omit.Val[int32] `db:"id,pk" `
Name omit.Val[string] `db:"name" `
ArcgisID omitnull.Val[string] `db:"arcgis_id" `
ArcgisName omitnull.Val[string] `db:"arcgis_name" `
FieldseekerURL omitnull.Val[string] `db:"fieldseeker_url" `
ImportDistrictGid omitnull.Val[int32] `db:"import_district_gid" `
Website omitnull.Val[string] `db:"website" `
}
func (s OrganizationSetter) SetColumns() []string {
vals := make([]string, 0, 5)
vals := make([]string, 0, 7)
if s.ID.IsValue() {
vals = append(vals, "id")
}
@ -142,6 +151,12 @@ func (s OrganizationSetter) SetColumns() []string {
if !s.FieldseekerURL.IsUnset() {
vals = append(vals, "fieldseeker_url")
}
if !s.ImportDistrictGid.IsUnset() {
vals = append(vals, "import_district_gid")
}
if !s.Website.IsUnset() {
vals = append(vals, "website")
}
return vals
}
@ -161,6 +176,12 @@ func (s OrganizationSetter) Overwrite(t *Organization) {
if !s.FieldseekerURL.IsUnset() {
t.FieldseekerURL = s.FieldseekerURL.MustGetNull()
}
if !s.ImportDistrictGid.IsUnset() {
t.ImportDistrictGid = s.ImportDistrictGid.MustGetNull()
}
if !s.Website.IsUnset() {
t.Website = s.Website.MustGetNull()
}
}
func (s *OrganizationSetter) Apply(q *dialect.InsertQuery) {
@ -169,7 +190,7 @@ func (s *OrganizationSetter) 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, 5)
vals := make([]bob.Expression, 7)
if s.ID.IsValue() {
vals[0] = psql.Arg(s.ID.MustGet())
} else {
@ -200,6 +221,18 @@ func (s *OrganizationSetter) Apply(q *dialect.InsertQuery) {
vals[4] = psql.Raw("DEFAULT")
}
if !s.ImportDistrictGid.IsUnset() {
vals[5] = psql.Arg(s.ImportDistrictGid.MustGetNull())
} else {
vals[5] = psql.Raw("DEFAULT")
}
if !s.Website.IsUnset() {
vals[6] = psql.Arg(s.Website.MustGetNull())
} else {
vals[6] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
@ -209,7 +242,7 @@ func (s OrganizationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
}
func (s OrganizationSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 5)
exprs := make([]bob.Expression, 0, 7)
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
@ -246,6 +279,20 @@ func (s OrganizationSetter) Expressions(prefix ...string) []bob.Expression {
}})
}
if !s.ImportDistrictGid.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "import_district_gid")...),
psql.Arg(s.ImportDistrictGid),
}})
}
if !s.Website.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "website")...),
psql.Arg(s.Website),
}})
}
return exprs
}
@ -1216,6 +1263,30 @@ func (os OrganizationSlice) NoteImages(mods ...bob.Mod[*dialect.SelectQuery]) No
)...)
}
// ImportDistrictGidDistrict starts a query for related objects on import.district
func (o *Organization) ImportDistrictGidDistrict(mods ...bob.Mod[*dialect.SelectQuery]) ImportDistrictsQuery {
return ImportDistricts.Query(append(mods,
sm.Where(ImportDistricts.Columns.Gid.EQ(psql.Arg(o.ImportDistrictGid))),
)...)
}
func (os OrganizationSlice) ImportDistrictGidDistrict(mods ...bob.Mod[*dialect.SelectQuery]) ImportDistrictsQuery {
pkImportDistrictGid := make(pgtypes.Array[null.Val[int32]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkImportDistrictGid = append(pkImportDistrictGid, o.ImportDistrictGid)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkImportDistrictGid), "integer[]")),
))
return ImportDistricts.Query(append(mods,
sm.Where(psql.Group(ImportDistricts.Columns.Gid).OP("IN", PKArgExpr)),
)...)
}
// User starts a query for related objects on user_
func (o *Organization) User(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
@ -3348,6 +3419,54 @@ func (organization0 *Organization) AttachNoteImages(ctx context.Context, exec bo
return nil
}
func attachOrganizationImportDistrictGidDistrict0(ctx context.Context, exec bob.Executor, count int, organization0 *Organization, importDistrict1 *ImportDistrict) (*Organization, error) {
setter := &OrganizationSetter{
ImportDistrictGid: omitnull.From(importDistrict1.Gid),
}
err := organization0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachOrganizationImportDistrictGidDistrict0: %w", err)
}
return organization0, nil
}
func (organization0 *Organization) InsertImportDistrictGidDistrict(ctx context.Context, exec bob.Executor, related *ImportDistrictSetter) error {
var err error
importDistrict1, err := ImportDistricts.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachOrganizationImportDistrictGidDistrict0(ctx, exec, 1, organization0, importDistrict1)
if err != nil {
return err
}
organization0.R.ImportDistrictGidDistrict = importDistrict1
importDistrict1.R.ImportDistrictGidOrganization = organization0
return nil
}
func (organization0 *Organization) AttachImportDistrictGidDistrict(ctx context.Context, exec bob.Executor, importDistrict1 *ImportDistrict) error {
var err error
_, err = attachOrganizationImportDistrictGidDistrict0(ctx, exec, 1, organization0, importDistrict1)
if err != nil {
return err
}
organization0.R.ImportDistrictGidDistrict = importDistrict1
importDistrict1.R.ImportDistrictGidOrganization = organization0
return nil
}
func insertOrganizationUser0(ctx context.Context, exec bob.Executor, users1 []*UserSetter, organization0 *Organization) (UserSlice, error) {
for i := range users1 {
users1[i].OrganizationID = omit.From(organization0.ID)
@ -3417,11 +3536,13 @@ func (organization0 *Organization) AttachUser(ctx context.Context, exec bob.Exec
}
type organizationWhere[Q psql.Filterable] struct {
ID psql.WhereMod[Q, int32]
Name psql.WhereMod[Q, string]
ArcgisID psql.WhereNullMod[Q, string]
ArcgisName psql.WhereNullMod[Q, string]
FieldseekerURL psql.WhereNullMod[Q, string]
ID psql.WhereMod[Q, int32]
Name psql.WhereMod[Q, string]
ArcgisID psql.WhereNullMod[Q, string]
ArcgisName psql.WhereNullMod[Q, string]
FieldseekerURL psql.WhereNullMod[Q, string]
ImportDistrictGid psql.WhereNullMod[Q, int32]
Website psql.WhereNullMod[Q, string]
}
func (organizationWhere[Q]) AliasedAs(alias string) organizationWhere[Q] {
@ -3430,11 +3551,13 @@ func (organizationWhere[Q]) AliasedAs(alias string) organizationWhere[Q] {
func buildOrganizationWhere[Q psql.Filterable](cols organizationColumns) organizationWhere[Q] {
return organizationWhere[Q]{
ID: psql.Where[Q, int32](cols.ID),
Name: psql.Where[Q, string](cols.Name),
ArcgisID: psql.WhereNull[Q, string](cols.ArcgisID),
ArcgisName: psql.WhereNull[Q, string](cols.ArcgisName),
FieldseekerURL: psql.WhereNull[Q, string](cols.FieldseekerURL),
ID: psql.Where[Q, int32](cols.ID),
Name: psql.Where[Q, string](cols.Name),
ArcgisID: psql.WhereNull[Q, string](cols.ArcgisID),
ArcgisName: psql.WhereNull[Q, string](cols.ArcgisName),
FieldseekerURL: psql.WhereNull[Q, string](cols.FieldseekerURL),
ImportDistrictGid: psql.WhereNull[Q, int32](cols.ImportDistrictGid),
Website: psql.WhereNull[Q, string](cols.Website),
}
}
@ -3878,6 +4001,18 @@ func (o *Organization) Preload(name string, retrieved any) error {
}
}
return nil
case "ImportDistrictGidDistrict":
rel, ok := retrieved.(*ImportDistrict)
if !ok {
return fmt.Errorf("organization cannot load %T as %q", retrieved, name)
}
o.R.ImportDistrictGidDistrict = rel
if rel != nil {
rel.R.ImportDistrictGidOrganization = o
}
return nil
case "User":
rels, ok := retrieved.(UserSlice)
if !ok {
@ -3897,45 +4032,62 @@ func (o *Organization) Preload(name string, retrieved any) error {
}
}
type organizationPreloader struct{}
type organizationPreloader struct {
ImportDistrictGidDistrict func(...psql.PreloadOption) psql.Preloader
}
func buildOrganizationPreloader() organizationPreloader {
return organizationPreloader{}
return organizationPreloader{
ImportDistrictGidDistrict: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*ImportDistrict, ImportDistrictSlice](psql.PreloadRel{
Name: "ImportDistrictGidDistrict",
Sides: []psql.PreloadSide{
{
From: Organizations,
To: ImportDistricts,
FromColumns: []string{"import_district_gid"},
ToColumns: []string{"gid"},
},
},
}, ImportDistricts.Columns.Names(), opts...)
},
}
}
type organizationThenLoader[Q orm.Loadable] struct {
Containerrelates func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Fieldscoutinglogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Habitatrelates func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Inspectionsamples func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Inspectionsampledetails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Linelocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Locationtrackings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Mosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pointlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Polygonlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pooldetails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Proposedtreatmentareas func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Qamosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Rodentlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Samplecollections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Samplelocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Servicerequests func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Speciesabundances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Stormdrains func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Timecards func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Trapdata func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Traplocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Treatments func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Treatmentareas func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Zones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Zones2s func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
FieldseekerSyncs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
User func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Containerrelates func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Fieldscoutinglogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Habitatrelates func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Inspectionsamples func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Inspectionsampledetails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Linelocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Locationtrackings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Mosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pointlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Polygonlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Pooldetails func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Proposedtreatmentareas func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Qamosquitoinspections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Rodentlocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Samplecollections func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Samplelocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Servicerequests func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Speciesabundances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Stormdrains func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Timecards func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Trapdata func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Traplocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Treatments func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Treatmentareas func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Zones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Zones2s func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
FieldseekerSyncs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
NoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ImportDistrictGidDistrict func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
User func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
@ -4032,6 +4184,9 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
type NoteImagesLoadInterface interface {
LoadNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ImportDistrictGidDistrictLoadInterface interface {
LoadImportDistrictGidDistrict(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type UserLoadInterface interface {
LoadUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
@ -4223,6 +4378,12 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] {
return retrieved.LoadNoteImages(ctx, exec, mods...)
},
),
ImportDistrictGidDistrict: thenLoadBuilder[Q](
"ImportDistrictGidDistrict",
func(ctx context.Context, exec bob.Executor, retrieved ImportDistrictGidDistrictLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadImportDistrictGidDistrict(ctx, exec, mods...)
},
),
User: thenLoadBuilder[Q](
"User",
func(ctx context.Context, exec bob.Executor, retrieved UserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
@ -6123,6 +6284,61 @@ func (os OrganizationSlice) LoadNoteImages(ctx context.Context, exec bob.Executo
return nil
}
// LoadImportDistrictGidDistrict loads the organization's ImportDistrictGidDistrict into the .R struct
func (o *Organization) LoadImportDistrictGidDistrict(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ImportDistrictGidDistrict = nil
related, err := o.ImportDistrictGidDistrict(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ImportDistrictGidOrganization = o
o.R.ImportDistrictGidDistrict = related
return nil
}
// LoadImportDistrictGidDistrict loads the organization's ImportDistrictGidDistrict into the .R struct
func (os OrganizationSlice) LoadImportDistrictGidDistrict(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
importDistricts, err := os.ImportDistrictGidDistrict(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range importDistricts {
if !o.ImportDistrictGid.IsValue() {
continue
}
if !(o.ImportDistrictGid.IsValue() && o.ImportDistrictGid.MustGet() == rel.Gid) {
continue
}
rel.R.ImportDistrictGidOrganization = o
o.R.ImportDistrictGidDistrict = rel
break
}
}
return nil
}
// LoadUser loads the organization's User into the .R struct
func (o *Organization) LoadUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
@ -8169,39 +8385,40 @@ func (os OrganizationSlice) LoadCountUser(ctx context.Context, exec bob.Executor
}
type organizationJoins[Q dialect.Joinable] struct {
typ string
Containerrelates modAs[Q, fieldseekerContainerrelateColumns]
Fieldscoutinglogs modAs[Q, fieldseekerFieldscoutinglogColumns]
Habitatrelates modAs[Q, fieldseekerHabitatrelateColumns]
Inspectionsamples modAs[Q, fieldseekerInspectionsampleColumns]
Inspectionsampledetails modAs[Q, fieldseekerInspectionsampledetailColumns]
Linelocations modAs[Q, fieldseekerLinelocationColumns]
Locationtrackings modAs[Q, fieldseekerLocationtrackingColumns]
Mosquitoinspections modAs[Q, fieldseekerMosquitoinspectionColumns]
Pointlocations modAs[Q, fieldseekerPointlocationColumns]
Polygonlocations modAs[Q, fieldseekerPolygonlocationColumns]
Pools modAs[Q, fieldseekerPoolColumns]
Pooldetails modAs[Q, fieldseekerPooldetailColumns]
Proposedtreatmentareas modAs[Q, fieldseekerProposedtreatmentareaColumns]
Qamosquitoinspections modAs[Q, fieldseekerQamosquitoinspectionColumns]
Rodentlocations modAs[Q, fieldseekerRodentlocationColumns]
Samplecollections modAs[Q, fieldseekerSamplecollectionColumns]
Samplelocations modAs[Q, fieldseekerSamplelocationColumns]
Servicerequests modAs[Q, fieldseekerServicerequestColumns]
Speciesabundances modAs[Q, fieldseekerSpeciesabundanceColumns]
Stormdrains modAs[Q, fieldseekerStormdrainColumns]
Timecards modAs[Q, fieldseekerTimecardColumns]
Trapdata modAs[Q, fieldseekerTrapdatumColumns]
Traplocations modAs[Q, fieldseekerTraplocationColumns]
Treatments modAs[Q, fieldseekerTreatmentColumns]
Treatmentareas modAs[Q, fieldseekerTreatmentareaColumns]
Zones modAs[Q, fieldseekerZoneColumns]
Zones2s modAs[Q, fieldseekerZones2Columns]
FieldseekerSyncs modAs[Q, fieldseekerSyncColumns]
H3Aggregations modAs[Q, h3AggregationColumns]
NoteAudios modAs[Q, noteAudioColumns]
NoteImages modAs[Q, noteImageColumns]
User modAs[Q, userColumns]
typ string
Containerrelates modAs[Q, fieldseekerContainerrelateColumns]
Fieldscoutinglogs modAs[Q, fieldseekerFieldscoutinglogColumns]
Habitatrelates modAs[Q, fieldseekerHabitatrelateColumns]
Inspectionsamples modAs[Q, fieldseekerInspectionsampleColumns]
Inspectionsampledetails modAs[Q, fieldseekerInspectionsampledetailColumns]
Linelocations modAs[Q, fieldseekerLinelocationColumns]
Locationtrackings modAs[Q, fieldseekerLocationtrackingColumns]
Mosquitoinspections modAs[Q, fieldseekerMosquitoinspectionColumns]
Pointlocations modAs[Q, fieldseekerPointlocationColumns]
Polygonlocations modAs[Q, fieldseekerPolygonlocationColumns]
Pools modAs[Q, fieldseekerPoolColumns]
Pooldetails modAs[Q, fieldseekerPooldetailColumns]
Proposedtreatmentareas modAs[Q, fieldseekerProposedtreatmentareaColumns]
Qamosquitoinspections modAs[Q, fieldseekerQamosquitoinspectionColumns]
Rodentlocations modAs[Q, fieldseekerRodentlocationColumns]
Samplecollections modAs[Q, fieldseekerSamplecollectionColumns]
Samplelocations modAs[Q, fieldseekerSamplelocationColumns]
Servicerequests modAs[Q, fieldseekerServicerequestColumns]
Speciesabundances modAs[Q, fieldseekerSpeciesabundanceColumns]
Stormdrains modAs[Q, fieldseekerStormdrainColumns]
Timecards modAs[Q, fieldseekerTimecardColumns]
Trapdata modAs[Q, fieldseekerTrapdatumColumns]
Traplocations modAs[Q, fieldseekerTraplocationColumns]
Treatments modAs[Q, fieldseekerTreatmentColumns]
Treatmentareas modAs[Q, fieldseekerTreatmentareaColumns]
Zones modAs[Q, fieldseekerZoneColumns]
Zones2s modAs[Q, fieldseekerZones2Columns]
FieldseekerSyncs modAs[Q, fieldseekerSyncColumns]
H3Aggregations modAs[Q, h3AggregationColumns]
NoteAudios modAs[Q, noteAudioColumns]
NoteImages modAs[Q, noteImageColumns]
ImportDistrictGidDistrict modAs[Q, importDistrictColumns]
User modAs[Q, userColumns]
}
func (j organizationJoins[Q]) aliasedAs(alias string) organizationJoins[Q] {
@ -8645,6 +8862,20 @@ func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ st
return mods
},
},
ImportDistrictGidDistrict: modAs[Q, importDistrictColumns]{
c: ImportDistricts.Columns,
f: func(to importDistrictColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, ImportDistricts.Name().As(to.Alias())).On(
to.Gid.EQ(cols.ImportDistrictGid),
))
}
return mods
},
},
User: modAs[Q, userColumns]{
c: Users.Columns,
f: func(to userColumns) bob.Mod[Q] {

View file

@ -11,8 +11,8 @@ import (
"github.com/stephenafamo/bob/dialect/psql/sm"
)
func DistrictForLocation(ctx context.Context, lng float64, lat float64) (*models.District, error) {
rows, err := models.Districts.Query(
func DistrictForLocation(ctx context.Context, lng float64, lat float64) (*models.ImportDistrict, error) {
rows, err := models.ImportDistricts.Query(
sm.Where(
psql.F("ST_Contains", psql.Raw("geom_4326"), psql.F("ST_SetSRID", psql.F("ST_MakePoint", psql.Arg(lng), psql.Arg(lat)), psql.Arg(4326))),
),