Add data for handling parcel images
This commit is contained in:
parent
9613cac11a
commit
91fe244da8
69 changed files with 20850 additions and 1976 deletions
|
|
@ -37,6 +37,8 @@ type Address struct {
|
|||
Unit string `db:"unit" `
|
||||
|
||||
R addressR `db:"-" `
|
||||
|
||||
C addressC `db:"-" `
|
||||
}
|
||||
|
||||
// AddressSlice is an alias for a slice of pointers to Address.
|
||||
|
|
@ -51,7 +53,8 @@ type AddressesQuery = *psql.ViewQuery[*Address, AddressSlice]
|
|||
|
||||
// addressR is where relationships are stored.
|
||||
type addressR struct {
|
||||
Site *Site // site.site_address_id_fkey
|
||||
Residents ResidentSlice // resident.resident_address_id_fkey
|
||||
Site *Site // site.site_address_id_fkey
|
||||
}
|
||||
|
||||
func buildAddressColumns(alias string) addressColumns {
|
||||
|
|
@ -554,6 +557,30 @@ func (o AddressSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Residents starts a query for related objects on resident
|
||||
func (o *Address) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
return Residents.Query(append(mods,
|
||||
sm.Where(Residents.Columns.AddressID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os AddressSlice) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return Residents.Query(append(mods,
|
||||
sm.Where(psql.Group(Residents.Columns.AddressID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Site starts a query for related objects on site
|
||||
func (o *Address) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
|
|
@ -578,6 +605,74 @@ func (os AddressSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
|||
)...)
|
||||
}
|
||||
|
||||
func insertAddressResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, address0 *Address) (ResidentSlice, error) {
|
||||
for i := range residents1 {
|
||||
residents1[i].AddressID = omit.From(address0.ID)
|
||||
}
|
||||
|
||||
ret, err := Residents.Insert(bob.ToMods(residents1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertAddressResidents0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachAddressResidents0(ctx context.Context, exec bob.Executor, count int, residents1 ResidentSlice, address0 *Address) (ResidentSlice, error) {
|
||||
setter := &ResidentSetter{
|
||||
AddressID: omit.From(address0.ID),
|
||||
}
|
||||
|
||||
err := residents1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachAddressResidents0: %w", err)
|
||||
}
|
||||
|
||||
return residents1, nil
|
||||
}
|
||||
|
||||
func (address0 *Address) InsertResidents(ctx context.Context, exec bob.Executor, related ...*ResidentSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
residents1, err := insertAddressResidents0(ctx, exec, related, address0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
address0.R.Residents = append(address0.R.Residents, residents1...)
|
||||
|
||||
for _, rel := range residents1 {
|
||||
rel.R.Address = address0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (address0 *Address) AttachResidents(ctx context.Context, exec bob.Executor, related ...*Resident) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
residents1 := ResidentSlice(related)
|
||||
|
||||
_, err = attachAddressResidents0(ctx, exec, len(related), residents1, address0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
address0.R.Residents = append(address0.R.Residents, residents1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Address = address0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertAddressSite0(ctx context.Context, exec bob.Executor, site1 *SiteSetter, address0 *Address) (*Site, error) {
|
||||
site1.AddressID = omit.From(address0.ID)
|
||||
|
||||
|
|
@ -670,6 +765,20 @@ func (o *Address) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "Residents":
|
||||
rels, ok := retrieved.(ResidentSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("address cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Residents = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Address = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "Site":
|
||||
rel, ok := retrieved.(*Site)
|
||||
if !ok {
|
||||
|
|
@ -710,15 +819,25 @@ func buildAddressPreloader() addressPreloader {
|
|||
}
|
||||
|
||||
type addressThenLoader[Q orm.Loadable] struct {
|
||||
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Residents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
|
||||
type ResidentsLoadInterface interface {
|
||||
LoadResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SiteLoadInterface interface {
|
||||
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return addressThenLoader[Q]{
|
||||
Residents: thenLoadBuilder[Q](
|
||||
"Residents",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ResidentsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadResidents(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Site: thenLoadBuilder[Q](
|
||||
"Site",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -728,6 +847,67 @@ func buildAddressThenLoader[Q orm.Loadable]() addressThenLoader[Q] {
|
|||
}
|
||||
}
|
||||
|
||||
// LoadResidents loads the address's Residents into the .R struct
|
||||
func (o *Address) LoadResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Residents = nil
|
||||
|
||||
related, err := o.Residents(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Address = o
|
||||
}
|
||||
|
||||
o.R.Residents = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadResidents loads the address's Residents into the .R struct
|
||||
func (os AddressSlice) LoadResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
residents, err := os.Residents(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Residents = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range residents {
|
||||
|
||||
if !(o.ID == rel.AddressID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Address = o
|
||||
|
||||
o.R.Residents = append(o.R.Residents, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSite loads the address's Site into the .R struct
|
||||
func (o *Address) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -780,9 +960,103 @@ func (os AddressSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...
|
|||
return nil
|
||||
}
|
||||
|
||||
// addressC is where relationship counts are stored.
|
||||
type addressC struct {
|
||||
Residents *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *Address) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Residents":
|
||||
o.C.Residents = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type addressCountPreloader struct {
|
||||
Residents func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildAddressCountPreloader() addressCountPreloader {
|
||||
return addressCountPreloader{
|
||||
Residents: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Address]("Residents", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Addresses.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Residents.Name()),
|
||||
sm.Where(psql.Quote(Residents.Alias(), "address_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type addressCountThenLoader[Q orm.Loadable] struct {
|
||||
Residents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildAddressCountThenLoader[Q orm.Loadable]() addressCountThenLoader[Q] {
|
||||
type ResidentsCountInterface interface {
|
||||
LoadCountResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return addressCountThenLoader[Q]{
|
||||
Residents: countThenLoadBuilder[Q](
|
||||
"Residents",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ResidentsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountResidents(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountResidents loads the count of Residents into the C struct
|
||||
func (o *Address) LoadCountResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.Residents(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.Residents = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountResidents loads the count of Residents for a slice
|
||||
func (os AddressSlice) LoadCountResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountResidents(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type addressJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Site modAs[Q, siteColumns]
|
||||
typ string
|
||||
Residents modAs[Q, residentColumns]
|
||||
Site modAs[Q, siteColumns]
|
||||
}
|
||||
|
||||
func (j addressJoins[Q]) aliasedAs(alias string) addressJoins[Q] {
|
||||
|
|
@ -792,6 +1066,20 @@ func (j addressJoins[Q]) aliasedAs(alias string) addressJoins[Q] {
|
|||
func buildAddressJoins[Q dialect.Joinable](cols addressColumns, typ string) addressJoins[Q] {
|
||||
return addressJoins[Q]{
|
||||
typ: typ,
|
||||
Residents: modAs[Q, residentColumns]{
|
||||
c: Residents.Columns,
|
||||
f: func(to residentColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Residents.Name().As(to.Alias())).On(
|
||||
to.AddressID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Site: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
1813
db/models/arcgis.account.bob.go
Normal file
1813
db/models/arcgis.account.bob.go
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -44,7 +44,7 @@ type ArcgisLayersQuery = *psql.ViewQuery[*ArcgisLayer, ArcgisLayerSlice]
|
|||
|
||||
// arcgisLayerR is where relationships are stored.
|
||||
type arcgisLayerR struct {
|
||||
FeatureServiceItemFeatureService *ArcgisFeatureService // arcgis.layer.layer_feature_service_item_id_fkey
|
||||
FeatureServiceItemServiceFeature *ArcgisServiceFeature // arcgis.layer.layer_feature_service_item_id_fkey
|
||||
LayerFields ArcgisLayerFieldSlice // arcgis.layer_field.layer_field_layer_feature_service_item_id_layer_index_fkey
|
||||
}
|
||||
|
||||
|
|
@ -404,14 +404,14 @@ func (o ArcgisLayerSlice) ReloadAll(ctx context.Context, exec bob.Executor) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
// FeatureServiceItemFeatureService starts a query for related objects on arcgis.feature_service
|
||||
func (o *ArcgisLayer) FeatureServiceItemFeatureService(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisFeatureServicesQuery {
|
||||
return ArcgisFeatureServices.Query(append(mods,
|
||||
sm.Where(ArcgisFeatureServices.Columns.ItemID.EQ(psql.Arg(o.FeatureServiceItemID))),
|
||||
// FeatureServiceItemServiceFeature starts a query for related objects on arcgis.service_feature
|
||||
func (o *ArcgisLayer) FeatureServiceItemServiceFeature(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisServiceFeaturesQuery {
|
||||
return ArcgisServiceFeatures.Query(append(mods,
|
||||
sm.Where(ArcgisServiceFeatures.Columns.ItemID.EQ(psql.Arg(o.FeatureServiceItemID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisLayerSlice) FeatureServiceItemFeatureService(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisFeatureServicesQuery {
|
||||
func (os ArcgisLayerSlice) FeatureServiceItemServiceFeature(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisServiceFeaturesQuery {
|
||||
pkFeatureServiceItemID := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
|
|
@ -423,8 +423,8 @@ func (os ArcgisLayerSlice) FeatureServiceItemFeatureService(mods ...bob.Mod[*dia
|
|||
psql.F("unnest", psql.Cast(psql.Arg(pkFeatureServiceItemID), "text[]")),
|
||||
))
|
||||
|
||||
return ArcgisFeatureServices.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisFeatureServices.Columns.ItemID).OP("IN", PKArgExpr)),
|
||||
return ArcgisServiceFeatures.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisServiceFeatures.Columns.ItemID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -456,50 +456,50 @@ func (os ArcgisLayerSlice) LayerFields(mods ...bob.Mod[*dialect.SelectQuery]) Ar
|
|||
)...)
|
||||
}
|
||||
|
||||
func attachArcgisLayerFeatureServiceItemFeatureService0(ctx context.Context, exec bob.Executor, count int, arcgisLayer0 *ArcgisLayer, arcgisFeatureService1 *ArcgisFeatureService) (*ArcgisLayer, error) {
|
||||
func attachArcgisLayerFeatureServiceItemServiceFeature0(ctx context.Context, exec bob.Executor, count int, arcgisLayer0 *ArcgisLayer, arcgisServiceFeature1 *ArcgisServiceFeature) (*ArcgisLayer, error) {
|
||||
setter := &ArcgisLayerSetter{
|
||||
FeatureServiceItemID: omit.From(arcgisFeatureService1.ItemID),
|
||||
FeatureServiceItemID: omit.From(arcgisServiceFeature1.ItemID),
|
||||
}
|
||||
|
||||
err := arcgisLayer0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisLayerFeatureServiceItemFeatureService0: %w", err)
|
||||
return nil, fmt.Errorf("attachArcgisLayerFeatureServiceItemServiceFeature0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisLayer0, nil
|
||||
}
|
||||
|
||||
func (arcgisLayer0 *ArcgisLayer) InsertFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, related *ArcgisFeatureServiceSetter) error {
|
||||
func (arcgisLayer0 *ArcgisLayer) InsertFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, related *ArcgisServiceFeatureSetter) error {
|
||||
var err error
|
||||
|
||||
arcgisFeatureService1, err := ArcgisFeatureServices.Insert(related).One(ctx, exec)
|
||||
arcgisServiceFeature1, err := ArcgisServiceFeatures.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisLayerFeatureServiceItemFeatureService0(ctx, exec, 1, arcgisLayer0, arcgisFeatureService1)
|
||||
_, err = attachArcgisLayerFeatureServiceItemServiceFeature0(ctx, exec, 1, arcgisLayer0, arcgisServiceFeature1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisLayer0.R.FeatureServiceItemFeatureService = arcgisFeatureService1
|
||||
arcgisLayer0.R.FeatureServiceItemServiceFeature = arcgisServiceFeature1
|
||||
|
||||
arcgisFeatureService1.R.FeatureServiceItemLayers = append(arcgisFeatureService1.R.FeatureServiceItemLayers, arcgisLayer0)
|
||||
arcgisServiceFeature1.R.FeatureServiceItemLayers = append(arcgisServiceFeature1.R.FeatureServiceItemLayers, arcgisLayer0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisLayer0 *ArcgisLayer) AttachFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, arcgisFeatureService1 *ArcgisFeatureService) error {
|
||||
func (arcgisLayer0 *ArcgisLayer) AttachFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, arcgisServiceFeature1 *ArcgisServiceFeature) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisLayerFeatureServiceItemFeatureService0(ctx, exec, 1, arcgisLayer0, arcgisFeatureService1)
|
||||
_, err = attachArcgisLayerFeatureServiceItemServiceFeature0(ctx, exec, 1, arcgisLayer0, arcgisServiceFeature1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisLayer0.R.FeatureServiceItemFeatureService = arcgisFeatureService1
|
||||
arcgisLayer0.R.FeatureServiceItemServiceFeature = arcgisServiceFeature1
|
||||
|
||||
arcgisFeatureService1.R.FeatureServiceItemLayers = append(arcgisFeatureService1.R.FeatureServiceItemLayers, arcgisLayer0)
|
||||
arcgisServiceFeature1.R.FeatureServiceItemLayers = append(arcgisServiceFeature1.R.FeatureServiceItemLayers, arcgisLayer0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -598,13 +598,13 @@ func (o *ArcgisLayer) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "FeatureServiceItemFeatureService":
|
||||
rel, ok := retrieved.(*ArcgisFeatureService)
|
||||
case "FeatureServiceItemServiceFeature":
|
||||
rel, ok := retrieved.(*ArcgisServiceFeature)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisLayer cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.FeatureServiceItemFeatureService = rel
|
||||
o.R.FeatureServiceItemServiceFeature = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.FeatureServiceItemLayers = ArcgisLayerSlice{o}
|
||||
|
|
@ -630,45 +630,45 @@ func (o *ArcgisLayer) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
type arcgisLayerPreloader struct {
|
||||
FeatureServiceItemFeatureService func(...psql.PreloadOption) psql.Preloader
|
||||
FeatureServiceItemServiceFeature func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisLayerPreloader() arcgisLayerPreloader {
|
||||
return arcgisLayerPreloader{
|
||||
FeatureServiceItemFeatureService: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*ArcgisFeatureService, ArcgisFeatureServiceSlice](psql.PreloadRel{
|
||||
Name: "FeatureServiceItemFeatureService",
|
||||
FeatureServiceItemServiceFeature: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*ArcgisServiceFeature, ArcgisServiceFeatureSlice](psql.PreloadRel{
|
||||
Name: "FeatureServiceItemServiceFeature",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisLayers,
|
||||
To: ArcgisFeatureServices,
|
||||
To: ArcgisServiceFeatures,
|
||||
FromColumns: []string{"feature_service_item_id"},
|
||||
ToColumns: []string{"item_id"},
|
||||
},
|
||||
},
|
||||
}, ArcgisFeatureServices.Columns.Names(), opts...)
|
||||
}, ArcgisServiceFeatures.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisLayerThenLoader[Q orm.Loadable] struct {
|
||||
FeatureServiceItemFeatureService func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
FeatureServiceItemServiceFeature func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
LayerFields func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisLayerThenLoader[Q orm.Loadable]() arcgisLayerThenLoader[Q] {
|
||||
type FeatureServiceItemFeatureServiceLoadInterface interface {
|
||||
LoadFeatureServiceItemFeatureService(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
type FeatureServiceItemServiceFeatureLoadInterface interface {
|
||||
LoadFeatureServiceItemServiceFeature(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type LayerFieldsLoadInterface interface {
|
||||
LoadLayerFields(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisLayerThenLoader[Q]{
|
||||
FeatureServiceItemFeatureService: thenLoadBuilder[Q](
|
||||
"FeatureServiceItemFeatureService",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemFeatureServiceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFeatureServiceItemFeatureService(ctx, exec, mods...)
|
||||
FeatureServiceItemServiceFeature: thenLoadBuilder[Q](
|
||||
"FeatureServiceItemServiceFeature",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved FeatureServiceItemServiceFeatureLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadFeatureServiceItemServiceFeature(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
LayerFields: thenLoadBuilder[Q](
|
||||
|
|
@ -680,33 +680,33 @@ func buildArcgisLayerThenLoader[Q orm.Loadable]() arcgisLayerThenLoader[Q] {
|
|||
}
|
||||
}
|
||||
|
||||
// LoadFeatureServiceItemFeatureService loads the arcgisLayer's FeatureServiceItemFeatureService into the .R struct
|
||||
func (o *ArcgisLayer) LoadFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadFeatureServiceItemServiceFeature loads the arcgisLayer's FeatureServiceItemServiceFeature into the .R struct
|
||||
func (o *ArcgisLayer) LoadFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.FeatureServiceItemFeatureService = nil
|
||||
o.R.FeatureServiceItemServiceFeature = nil
|
||||
|
||||
related, err := o.FeatureServiceItemFeatureService(mods...).One(ctx, exec)
|
||||
related, err := o.FeatureServiceItemServiceFeature(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.FeatureServiceItemLayers = ArcgisLayerSlice{o}
|
||||
|
||||
o.R.FeatureServiceItemFeatureService = related
|
||||
o.R.FeatureServiceItemServiceFeature = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadFeatureServiceItemFeatureService loads the arcgisLayer's FeatureServiceItemFeatureService into the .R struct
|
||||
func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
// LoadFeatureServiceItemServiceFeature loads the arcgisLayer's FeatureServiceItemServiceFeature into the .R struct
|
||||
func (os ArcgisLayerSlice) LoadFeatureServiceItemServiceFeature(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisFeatureServices, err := os.FeatureServiceItemFeatureService(mods...).All(ctx, exec)
|
||||
arcgisServiceFeatures, err := os.FeatureServiceItemServiceFeature(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -716,7 +716,7 @@ func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Cont
|
|||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisFeatureServices {
|
||||
for _, rel := range arcgisServiceFeatures {
|
||||
|
||||
if !(o.FeatureServiceItemID == rel.ItemID) {
|
||||
continue
|
||||
|
|
@ -724,7 +724,7 @@ func (os ArcgisLayerSlice) LoadFeatureServiceItemFeatureService(ctx context.Cont
|
|||
|
||||
rel.R.FeatureServiceItemLayers = append(rel.R.FeatureServiceItemLayers, o)
|
||||
|
||||
o.R.FeatureServiceItemFeatureService = rel
|
||||
o.R.FeatureServiceItemServiceFeature = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -893,7 +893,7 @@ func (os ArcgisLayerSlice) LoadCountLayerFields(ctx context.Context, exec bob.Ex
|
|||
|
||||
type arcgisLayerJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
FeatureServiceItemFeatureService modAs[Q, arcgisFeatureServiceColumns]
|
||||
FeatureServiceItemServiceFeature modAs[Q, arcgisServiceFeatureColumns]
|
||||
LayerFields modAs[Q, arcgisLayerFieldColumns]
|
||||
}
|
||||
|
||||
|
|
@ -904,13 +904,13 @@ func (j arcgisLayerJoins[Q]) aliasedAs(alias string) arcgisLayerJoins[Q] {
|
|||
func buildArcgisLayerJoins[Q dialect.Joinable](cols arcgisLayerColumns, typ string) arcgisLayerJoins[Q] {
|
||||
return arcgisLayerJoins[Q]{
|
||||
typ: typ,
|
||||
FeatureServiceItemFeatureService: modAs[Q, arcgisFeatureServiceColumns]{
|
||||
c: ArcgisFeatureServices.Columns,
|
||||
f: func(to arcgisFeatureServiceColumns) bob.Mod[Q] {
|
||||
FeatureServiceItemServiceFeature: modAs[Q, arcgisServiceFeatureColumns]{
|
||||
c: ArcgisServiceFeatures.Columns,
|
||||
f: func(to arcgisServiceFeatureColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisFeatureServices.Name().As(to.Alias())).On(
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisServiceFeatures.Name().As(to.Alias())).On(
|
||||
to.ItemID.EQ(cols.FeatureServiceItemID),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
1034
db/models/arcgis.oauth_token.bob.go
Normal file
1034
db/models/arcgis.oauth_token.bob.go
Normal file
File diff suppressed because it is too large
Load diff
1227
db/models/arcgis.service_feature.bob.go
Normal file
1227
db/models/arcgis.service_feature.bob.go
Normal file
File diff suppressed because it is too large
Load diff
677
db/models/arcgis.service_map.bob.go
Normal file
677
db/models/arcgis.service_map.bob.go
Normal file
|
|
@ -0,0 +1,677 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// ArcgisServiceMap is an object representing the database table.
|
||||
type ArcgisServiceMap struct {
|
||||
AccountID string `db:"account_id" `
|
||||
ArcgisID string `db:"arcgis_id,pk" `
|
||||
Name string `db:"name" `
|
||||
Title string `db:"title" `
|
||||
URL string `db:"url" `
|
||||
|
||||
R arcgisServiceMapR `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisServiceMapSlice is an alias for a slice of pointers to ArcgisServiceMap.
|
||||
// This should almost always be used instead of []*ArcgisServiceMap.
|
||||
type ArcgisServiceMapSlice []*ArcgisServiceMap
|
||||
|
||||
// ArcgisServiceMaps contains methods to work with the service_map table
|
||||
var ArcgisServiceMaps = psql.NewTablex[*ArcgisServiceMap, ArcgisServiceMapSlice, *ArcgisServiceMapSetter]("arcgis", "service_map", buildArcgisServiceMapColumns("arcgis.service_map"))
|
||||
|
||||
// ArcgisServiceMapsQuery is a query on the service_map table
|
||||
type ArcgisServiceMapsQuery = *psql.ViewQuery[*ArcgisServiceMap, ArcgisServiceMapSlice]
|
||||
|
||||
// arcgisServiceMapR is where relationships are stored.
|
||||
type arcgisServiceMapR struct {
|
||||
Account *ArcgisAccount // arcgis.service_map.service_map_account_id_fkey
|
||||
}
|
||||
|
||||
func buildArcgisServiceMapColumns(alias string) arcgisServiceMapColumns {
|
||||
return arcgisServiceMapColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"account_id", "arcgis_id", "name", "title", "url",
|
||||
).WithParent("arcgis.service_map"),
|
||||
tableAlias: alias,
|
||||
AccountID: psql.Quote(alias, "account_id"),
|
||||
ArcgisID: psql.Quote(alias, "arcgis_id"),
|
||||
Name: psql.Quote(alias, "name"),
|
||||
Title: psql.Quote(alias, "title"),
|
||||
URL: psql.Quote(alias, "url"),
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisServiceMapColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
AccountID psql.Expression
|
||||
ArcgisID psql.Expression
|
||||
Name psql.Expression
|
||||
Title psql.Expression
|
||||
URL psql.Expression
|
||||
}
|
||||
|
||||
func (c arcgisServiceMapColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (arcgisServiceMapColumns) AliasedAs(alias string) arcgisServiceMapColumns {
|
||||
return buildArcgisServiceMapColumns(alias)
|
||||
}
|
||||
|
||||
// ArcgisServiceMapSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ArcgisServiceMapSetter struct {
|
||||
AccountID omit.Val[string] `db:"account_id" `
|
||||
ArcgisID omit.Val[string] `db:"arcgis_id,pk" `
|
||||
Name omit.Val[string] `db:"name" `
|
||||
Title omit.Val[string] `db:"title" `
|
||||
URL omit.Val[string] `db:"url" `
|
||||
}
|
||||
|
||||
func (s ArcgisServiceMapSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.AccountID.IsValue() {
|
||||
vals = append(vals, "account_id")
|
||||
}
|
||||
if s.ArcgisID.IsValue() {
|
||||
vals = append(vals, "arcgis_id")
|
||||
}
|
||||
if s.Name.IsValue() {
|
||||
vals = append(vals, "name")
|
||||
}
|
||||
if s.Title.IsValue() {
|
||||
vals = append(vals, "title")
|
||||
}
|
||||
if s.URL.IsValue() {
|
||||
vals = append(vals, "url")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ArcgisServiceMapSetter) Overwrite(t *ArcgisServiceMap) {
|
||||
if s.AccountID.IsValue() {
|
||||
t.AccountID = s.AccountID.MustGet()
|
||||
}
|
||||
if s.ArcgisID.IsValue() {
|
||||
t.ArcgisID = s.ArcgisID.MustGet()
|
||||
}
|
||||
if s.Name.IsValue() {
|
||||
t.Name = s.Name.MustGet()
|
||||
}
|
||||
if s.Title.IsValue() {
|
||||
t.Title = s.Title.MustGet()
|
||||
}
|
||||
if s.URL.IsValue() {
|
||||
t.URL = s.URL.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ArcgisServiceMapSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ArcgisServiceMaps.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 5)
|
||||
if s.AccountID.IsValue() {
|
||||
vals[0] = psql.Arg(s.AccountID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ArcgisID.IsValue() {
|
||||
vals[1] = psql.Arg(s.ArcgisID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Name.IsValue() {
|
||||
vals[2] = psql.Arg(s.Name.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Title.IsValue() {
|
||||
vals[3] = psql.Arg(s.Title.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.URL.IsValue() {
|
||||
vals[4] = psql.Arg(s.URL.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ArcgisServiceMapSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ArcgisServiceMapSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.AccountID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "account_id")...),
|
||||
psql.Arg(s.AccountID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ArcgisID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "arcgis_id")...),
|
||||
psql.Arg(s.ArcgisID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Name.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "name")...),
|
||||
psql.Arg(s.Name),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Title.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "title")...),
|
||||
psql.Arg(s.Title),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.URL.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "url")...),
|
||||
psql.Arg(s.URL),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindArcgisServiceMap retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindArcgisServiceMap(ctx context.Context, exec bob.Executor, ArcgisIDPK string, cols ...string) (*ArcgisServiceMap, error) {
|
||||
if len(cols) == 0 {
|
||||
return ArcgisServiceMaps.Query(
|
||||
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(ArcgisIDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return ArcgisServiceMaps.Query(
|
||||
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(ArcgisIDPK))),
|
||||
sm.Columns(ArcgisServiceMaps.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ArcgisServiceMapExists checks the presence of a single record by primary key
|
||||
func ArcgisServiceMapExists(ctx context.Context, exec bob.Executor, ArcgisIDPK string) (bool, error) {
|
||||
return ArcgisServiceMaps.Query(
|
||||
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(ArcgisIDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisServiceMap is retrieved from the database
|
||||
func (o *ArcgisServiceMap) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisServiceMaps.AfterSelectHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisServiceMaps.AfterInsertHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisServiceMaps.AfterUpdateHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisServiceMaps.AfterDeleteHooks.RunHooks(ctx, exec, ArcgisServiceMapSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the ArcgisServiceMap
|
||||
func (o *ArcgisServiceMap) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ArcgisID)
|
||||
}
|
||||
|
||||
func (o *ArcgisServiceMap) pkEQ() dialect.Expression {
|
||||
return psql.Quote("arcgis.service_map", "arcgis_id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the ArcgisServiceMap
|
||||
func (o *ArcgisServiceMap) Update(ctx context.Context, exec bob.Executor, s *ArcgisServiceMapSetter) error {
|
||||
v, err := ArcgisServiceMaps.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 ArcgisServiceMap record with an executor
|
||||
func (o *ArcgisServiceMap) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := ArcgisServiceMaps.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the ArcgisServiceMap using the executor
|
||||
func (o *ArcgisServiceMap) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := ArcgisServiceMaps.Query(
|
||||
sm.Where(ArcgisServiceMaps.Columns.ArcgisID.EQ(psql.Arg(o.ArcgisID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ArcgisServiceMapSlice is retrieved from the database
|
||||
func (o ArcgisServiceMapSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ArcgisServiceMaps.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ArcgisServiceMaps.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ArcgisServiceMaps.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ArcgisServiceMaps.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisServiceMapSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("arcgis.service_map", "arcgis_id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o ArcgisServiceMapSlice) copyMatchingRows(from ...*ArcgisServiceMap) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ArcgisID != old.ArcgisID {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisServiceMapSlice) 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 ArcgisServiceMaps.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 *ArcgisServiceMap:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisServiceMap:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisServiceMapSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisServiceMap or a slice of ArcgisServiceMap
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = ArcgisServiceMaps.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ArcgisServiceMapSlice) 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 ArcgisServiceMaps.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 *ArcgisServiceMap:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ArcgisServiceMap:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ArcgisServiceMapSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ArcgisServiceMap or a slice of ArcgisServiceMap
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = ArcgisServiceMaps.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ArcgisServiceMapSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ArcgisServiceMapSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisServiceMaps.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisServiceMapSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ArcgisServiceMaps.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ArcgisServiceMapSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := ArcgisServiceMaps.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Account starts a query for related objects on arcgis.account
|
||||
func (o *ArcgisServiceMap) Account(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisAccountsQuery {
|
||||
return ArcgisAccounts.Query(append(mods,
|
||||
sm.Where(ArcgisAccounts.Columns.ID.EQ(psql.Arg(o.AccountID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ArcgisServiceMapSlice) Account(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisAccountsQuery {
|
||||
pkAccountID := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkAccountID = append(pkAccountID, o.AccountID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkAccountID), "text[]")),
|
||||
))
|
||||
|
||||
return ArcgisAccounts.Query(append(mods,
|
||||
sm.Where(psql.Group(ArcgisAccounts.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachArcgisServiceMapAccount0(ctx context.Context, exec bob.Executor, count int, arcgisServiceMap0 *ArcgisServiceMap, arcgisAccount1 *ArcgisAccount) (*ArcgisServiceMap, error) {
|
||||
setter := &ArcgisServiceMapSetter{
|
||||
AccountID: omit.From(arcgisAccount1.ID),
|
||||
}
|
||||
|
||||
err := arcgisServiceMap0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachArcgisServiceMapAccount0: %w", err)
|
||||
}
|
||||
|
||||
return arcgisServiceMap0, nil
|
||||
}
|
||||
|
||||
func (arcgisServiceMap0 *ArcgisServiceMap) InsertAccount(ctx context.Context, exec bob.Executor, related *ArcgisAccountSetter) error {
|
||||
var err error
|
||||
|
||||
arcgisAccount1, err := ArcgisAccounts.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachArcgisServiceMapAccount0(ctx, exec, 1, arcgisServiceMap0, arcgisAccount1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisServiceMap0.R.Account = arcgisAccount1
|
||||
|
||||
arcgisAccount1.R.ServiceMaps = append(arcgisAccount1.R.ServiceMaps, arcgisServiceMap0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arcgisServiceMap0 *ArcgisServiceMap) AttachAccount(ctx context.Context, exec bob.Executor, arcgisAccount1 *ArcgisAccount) error {
|
||||
var err error
|
||||
|
||||
_, err = attachArcgisServiceMapAccount0(ctx, exec, 1, arcgisServiceMap0, arcgisAccount1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
arcgisServiceMap0.R.Account = arcgisAccount1
|
||||
|
||||
arcgisAccount1.R.ServiceMaps = append(arcgisAccount1.R.ServiceMaps, arcgisServiceMap0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisServiceMapWhere[Q psql.Filterable] struct {
|
||||
AccountID psql.WhereMod[Q, string]
|
||||
ArcgisID psql.WhereMod[Q, string]
|
||||
Name psql.WhereMod[Q, string]
|
||||
Title psql.WhereMod[Q, string]
|
||||
URL psql.WhereMod[Q, string]
|
||||
}
|
||||
|
||||
func (arcgisServiceMapWhere[Q]) AliasedAs(alias string) arcgisServiceMapWhere[Q] {
|
||||
return buildArcgisServiceMapWhere[Q](buildArcgisServiceMapColumns(alias))
|
||||
}
|
||||
|
||||
func buildArcgisServiceMapWhere[Q psql.Filterable](cols arcgisServiceMapColumns) arcgisServiceMapWhere[Q] {
|
||||
return arcgisServiceMapWhere[Q]{
|
||||
AccountID: psql.Where[Q, string](cols.AccountID),
|
||||
ArcgisID: psql.Where[Q, string](cols.ArcgisID),
|
||||
Name: psql.Where[Q, string](cols.Name),
|
||||
Title: psql.Where[Q, string](cols.Title),
|
||||
URL: psql.Where[Q, string](cols.URL),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ArcgisServiceMap) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Account":
|
||||
rel, ok := retrieved.(*ArcgisAccount)
|
||||
if !ok {
|
||||
return fmt.Errorf("arcgisServiceMap cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Account = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ServiceMaps = ArcgisServiceMapSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("arcgisServiceMap has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisServiceMapPreloader struct {
|
||||
Account func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisServiceMapPreloader() arcgisServiceMapPreloader {
|
||||
return arcgisServiceMapPreloader{
|
||||
Account: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*ArcgisAccount, ArcgisAccountSlice](psql.PreloadRel{
|
||||
Name: "Account",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ArcgisServiceMaps,
|
||||
To: ArcgisAccounts,
|
||||
FromColumns: []string{"account_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, ArcgisAccounts.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisServiceMapThenLoader[Q orm.Loadable] struct {
|
||||
Account func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisServiceMapThenLoader[Q orm.Loadable]() arcgisServiceMapThenLoader[Q] {
|
||||
type AccountLoadInterface interface {
|
||||
LoadAccount(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisServiceMapThenLoader[Q]{
|
||||
Account: thenLoadBuilder[Q](
|
||||
"Account",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved AccountLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadAccount(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadAccount loads the arcgisServiceMap's Account into the .R struct
|
||||
func (o *ArcgisServiceMap) LoadAccount(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Account = nil
|
||||
|
||||
related, err := o.Account(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ServiceMaps = ArcgisServiceMapSlice{o}
|
||||
|
||||
o.R.Account = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadAccount loads the arcgisServiceMap's Account into the .R struct
|
||||
func (os ArcgisServiceMapSlice) LoadAccount(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
arcgisAccounts, err := os.Account(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range arcgisAccounts {
|
||||
|
||||
if !(o.AccountID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ServiceMaps = append(rel.R.ServiceMaps, o)
|
||||
|
||||
o.R.Account = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisServiceMapJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Account modAs[Q, arcgisAccountColumns]
|
||||
}
|
||||
|
||||
func (j arcgisServiceMapJoins[Q]) aliasedAs(alias string) arcgisServiceMapJoins[Q] {
|
||||
return buildArcgisServiceMapJoins[Q](buildArcgisServiceMapColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisServiceMapJoins[Q dialect.Joinable](cols arcgisServiceMapColumns, typ string) arcgisServiceMapJoins[Q] {
|
||||
return arcgisServiceMapJoins[Q]{
|
||||
typ: typ,
|
||||
Account: modAs[Q, arcgisAccountColumns]{
|
||||
c: ArcgisAccounts.Columns,
|
||||
f: func(to arcgisAccountColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisAccounts.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.AccountID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -21,9 +21,11 @@ var (
|
|||
)
|
||||
|
||||
type preloadCounts struct {
|
||||
ArcgisFeatureService arcgisFeatureServiceCountPreloader
|
||||
Address addressCountPreloader
|
||||
ArcgisAccount arcgisAccountCountPreloader
|
||||
ArcgisLayer arcgisLayerCountPreloader
|
||||
ArcgisLayerField arcgisLayerFieldCountPreloader
|
||||
ArcgisServiceFeature arcgisServiceFeatureCountPreloader
|
||||
ArcgisUser arcgisuserCountPreloader
|
||||
CommsEmailContact commsEmailContactCountPreloader
|
||||
CommsEmailTemplate commsEmailTemplateCountPreloader
|
||||
|
|
@ -33,18 +35,22 @@ type preloadCounts struct {
|
|||
NoteAudio noteAudioCountPreloader
|
||||
NoteImage noteImageCountPreloader
|
||||
Organization organizationCountPreloader
|
||||
Parcel parcelCountPreloader
|
||||
PublicreportImage publicreportImageCountPreloader
|
||||
PublicreportNuisance publicreportNuisanceCountPreloader
|
||||
PublicreportPool publicreportPoolCountPreloader
|
||||
PublicreportQuick publicreportQuickCountPreloader
|
||||
Site siteCountPreloader
|
||||
User userCountPreloader
|
||||
}
|
||||
|
||||
func getPreloadCount() preloadCounts {
|
||||
return preloadCounts{
|
||||
ArcgisFeatureService: buildArcgisFeatureServiceCountPreloader(),
|
||||
Address: buildAddressCountPreloader(),
|
||||
ArcgisAccount: buildArcgisAccountCountPreloader(),
|
||||
ArcgisLayer: buildArcgisLayerCountPreloader(),
|
||||
ArcgisLayerField: buildArcgisLayerFieldCountPreloader(),
|
||||
ArcgisServiceFeature: buildArcgisServiceFeatureCountPreloader(),
|
||||
ArcgisUser: buildArcgisUserCountPreloader(),
|
||||
CommsEmailContact: buildCommsEmailContactCountPreloader(),
|
||||
CommsEmailTemplate: buildCommsEmailTemplateCountPreloader(),
|
||||
|
|
@ -54,18 +60,22 @@ func getPreloadCount() preloadCounts {
|
|||
NoteAudio: buildNoteAudioCountPreloader(),
|
||||
NoteImage: buildNoteImageCountPreloader(),
|
||||
Organization: buildOrganizationCountPreloader(),
|
||||
Parcel: buildParcelCountPreloader(),
|
||||
PublicreportImage: buildPublicreportImageCountPreloader(),
|
||||
PublicreportNuisance: buildPublicreportNuisanceCountPreloader(),
|
||||
PublicreportPool: buildPublicreportPoolCountPreloader(),
|
||||
PublicreportQuick: buildPublicreportQuickCountPreloader(),
|
||||
Site: buildSiteCountPreloader(),
|
||||
User: buildUserCountPreloader(),
|
||||
}
|
||||
}
|
||||
|
||||
type thenLoadCounts[Q orm.Loadable] struct {
|
||||
ArcgisFeatureService arcgisFeatureServiceCountThenLoader[Q]
|
||||
Address addressCountThenLoader[Q]
|
||||
ArcgisAccount arcgisAccountCountThenLoader[Q]
|
||||
ArcgisLayer arcgisLayerCountThenLoader[Q]
|
||||
ArcgisLayerField arcgisLayerFieldCountThenLoader[Q]
|
||||
ArcgisServiceFeature arcgisServiceFeatureCountThenLoader[Q]
|
||||
ArcgisUser arcgisuserCountThenLoader[Q]
|
||||
CommsEmailContact commsEmailContactCountThenLoader[Q]
|
||||
CommsEmailTemplate commsEmailTemplateCountThenLoader[Q]
|
||||
|
|
@ -75,18 +85,22 @@ type thenLoadCounts[Q orm.Loadable] struct {
|
|||
NoteAudio noteAudioCountThenLoader[Q]
|
||||
NoteImage noteImageCountThenLoader[Q]
|
||||
Organization organizationCountThenLoader[Q]
|
||||
Parcel parcelCountThenLoader[Q]
|
||||
PublicreportImage publicreportImageCountThenLoader[Q]
|
||||
PublicreportNuisance publicreportNuisanceCountThenLoader[Q]
|
||||
PublicreportPool publicreportPoolCountThenLoader[Q]
|
||||
PublicreportQuick publicreportQuickCountThenLoader[Q]
|
||||
Site siteCountThenLoader[Q]
|
||||
User userCountThenLoader[Q]
|
||||
}
|
||||
|
||||
func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
|
||||
return thenLoadCounts[Q]{
|
||||
ArcgisFeatureService: buildArcgisFeatureServiceCountThenLoader[Q](),
|
||||
Address: buildAddressCountThenLoader[Q](),
|
||||
ArcgisAccount: buildArcgisAccountCountThenLoader[Q](),
|
||||
ArcgisLayer: buildArcgisLayerCountThenLoader[Q](),
|
||||
ArcgisLayerField: buildArcgisLayerFieldCountThenLoader[Q](),
|
||||
ArcgisServiceFeature: buildArcgisServiceFeatureCountThenLoader[Q](),
|
||||
ArcgisUser: buildArcgisUserCountThenLoader[Q](),
|
||||
CommsEmailContact: buildCommsEmailContactCountThenLoader[Q](),
|
||||
CommsEmailTemplate: buildCommsEmailTemplateCountThenLoader[Q](),
|
||||
|
|
@ -96,10 +110,12 @@ func getThenLoadCount[Q orm.Loadable]() thenLoadCounts[Q] {
|
|||
NoteAudio: buildNoteAudioCountThenLoader[Q](),
|
||||
NoteImage: buildNoteImageCountThenLoader[Q](),
|
||||
Organization: buildOrganizationCountThenLoader[Q](),
|
||||
Parcel: buildParcelCountThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageCountThenLoader[Q](),
|
||||
PublicreportNuisance: buildPublicreportNuisanceCountThenLoader[Q](),
|
||||
PublicreportPool: buildPublicreportPoolCountThenLoader[Q](),
|
||||
PublicreportQuick: buildPublicreportQuickCountThenLoader[Q](),
|
||||
Site: buildSiteCountThenLoader[Q](),
|
||||
User: buildUserCountThenLoader[Q](),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,14 @@ func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] {
|
|||
|
||||
type joins[Q dialect.Joinable] struct {
|
||||
Addresses joinSet[addressJoins[Q]]
|
||||
ArcgisAccounts joinSet[arcgisAccountJoins[Q]]
|
||||
ArcgisAddressMappings joinSet[arcgisAddressMappingJoins[Q]]
|
||||
ArcgisFeatureServices joinSet[arcgisFeatureServiceJoins[Q]]
|
||||
ArcgisLayers joinSet[arcgisLayerJoins[Q]]
|
||||
ArcgisLayerFields joinSet[arcgisLayerFieldJoins[Q]]
|
||||
ArcgisOauthTokens joinSet[arcgisOauthTokenJoins[Q]]
|
||||
ArcgisParcelMappings joinSet[arcgisParcelMappingJoins[Q]]
|
||||
ArcgisServiceFeatures joinSet[arcgisServiceFeatureJoins[Q]]
|
||||
ArcgisServiceMaps joinSet[arcgisServiceMapJoins[Q]]
|
||||
ArcgisUsers joinSet[arcgisuserJoins[Q]]
|
||||
ArcgisUserPrivileges joinSet[arcgisUserPrivilegeJoins[Q]]
|
||||
CommsEmailContacts joinSet[commsEmailContactJoins[Q]]
|
||||
|
|
@ -46,6 +49,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
CommsPhones joinSet[commsPhoneJoins[Q]]
|
||||
CommsTextJobs joinSet[commsTextJobJoins[Q]]
|
||||
CommsTextLogs joinSet[commsTextLogJoins[Q]]
|
||||
ComplianceReportRequests joinSet[complianceReportRequestJoins[Q]]
|
||||
DistrictSubscriptionEmails joinSet[districtSubscriptionEmailJoins[Q]]
|
||||
DistrictSubscriptionPhones joinSet[districtSubscriptionPhoneJoins[Q]]
|
||||
FieldseekerContainerrelates joinSet[fieldseekerContainerrelateJoins[Q]]
|
||||
|
|
@ -89,8 +93,8 @@ type joins[Q dialect.Joinable] struct {
|
|||
NoteImageBreadcrumbs joinSet[noteImageBreadcrumbJoins[Q]]
|
||||
NoteImageData joinSet[noteImageDatumJoins[Q]]
|
||||
Notifications joinSet[notificationJoins[Q]]
|
||||
OauthTokens joinSet[oauthTokenJoins[Q]]
|
||||
Organizations joinSet[organizationJoins[Q]]
|
||||
Parcels joinSet[parcelJoins[Q]]
|
||||
Pools joinSet[poolJoins[Q]]
|
||||
PublicreportImages joinSet[publicreportImageJoins[Q]]
|
||||
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
|
||||
|
|
@ -106,6 +110,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
PublicreportQuickImages joinSet[publicreportQuickImageJoins[Q]]
|
||||
PublicreportSubscribeEmails joinSet[publicreportSubscribeEmailJoins[Q]]
|
||||
PublicreportSubscribePhones joinSet[publicreportSubscribePhoneJoins[Q]]
|
||||
Residents joinSet[residentJoins[Q]]
|
||||
Sites joinSet[siteJoins[Q]]
|
||||
Users joinSet[userJoins[Q]]
|
||||
}
|
||||
|
|
@ -121,11 +126,14 @@ func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q
|
|||
func getJoins[Q dialect.Joinable]() joins[Q] {
|
||||
return joins[Q]{
|
||||
Addresses: buildJoinSet[addressJoins[Q]](Addresses.Columns, buildAddressJoins),
|
||||
ArcgisAccounts: buildJoinSet[arcgisAccountJoins[Q]](ArcgisAccounts.Columns, buildArcgisAccountJoins),
|
||||
ArcgisAddressMappings: buildJoinSet[arcgisAddressMappingJoins[Q]](ArcgisAddressMappings.Columns, buildArcgisAddressMappingJoins),
|
||||
ArcgisFeatureServices: buildJoinSet[arcgisFeatureServiceJoins[Q]](ArcgisFeatureServices.Columns, buildArcgisFeatureServiceJoins),
|
||||
ArcgisLayers: buildJoinSet[arcgisLayerJoins[Q]](ArcgisLayers.Columns, buildArcgisLayerJoins),
|
||||
ArcgisLayerFields: buildJoinSet[arcgisLayerFieldJoins[Q]](ArcgisLayerFields.Columns, buildArcgisLayerFieldJoins),
|
||||
ArcgisOauthTokens: buildJoinSet[arcgisOauthTokenJoins[Q]](ArcgisOauthTokens.Columns, buildArcgisOauthTokenJoins),
|
||||
ArcgisParcelMappings: buildJoinSet[arcgisParcelMappingJoins[Q]](ArcgisParcelMappings.Columns, buildArcgisParcelMappingJoins),
|
||||
ArcgisServiceFeatures: buildJoinSet[arcgisServiceFeatureJoins[Q]](ArcgisServiceFeatures.Columns, buildArcgisServiceFeatureJoins),
|
||||
ArcgisServiceMaps: buildJoinSet[arcgisServiceMapJoins[Q]](ArcgisServiceMaps.Columns, buildArcgisServiceMapJoins),
|
||||
ArcgisUsers: buildJoinSet[arcgisuserJoins[Q]](ArcgisUsers.Columns, buildArcgisUserJoins),
|
||||
ArcgisUserPrivileges: buildJoinSet[arcgisUserPrivilegeJoins[Q]](ArcgisUserPrivileges.Columns, buildArcgisUserPrivilegeJoins),
|
||||
CommsEmailContacts: buildJoinSet[commsEmailContactJoins[Q]](CommsEmailContacts.Columns, buildCommsEmailContactJoins),
|
||||
|
|
@ -134,6 +142,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
CommsPhones: buildJoinSet[commsPhoneJoins[Q]](CommsPhones.Columns, buildCommsPhoneJoins),
|
||||
CommsTextJobs: buildJoinSet[commsTextJobJoins[Q]](CommsTextJobs.Columns, buildCommsTextJobJoins),
|
||||
CommsTextLogs: buildJoinSet[commsTextLogJoins[Q]](CommsTextLogs.Columns, buildCommsTextLogJoins),
|
||||
ComplianceReportRequests: buildJoinSet[complianceReportRequestJoins[Q]](ComplianceReportRequests.Columns, buildComplianceReportRequestJoins),
|
||||
DistrictSubscriptionEmails: buildJoinSet[districtSubscriptionEmailJoins[Q]](DistrictSubscriptionEmails.Columns, buildDistrictSubscriptionEmailJoins),
|
||||
DistrictSubscriptionPhones: buildJoinSet[districtSubscriptionPhoneJoins[Q]](DistrictSubscriptionPhones.Columns, buildDistrictSubscriptionPhoneJoins),
|
||||
FieldseekerContainerrelates: buildJoinSet[fieldseekerContainerrelateJoins[Q]](FieldseekerContainerrelates.Columns, buildFieldseekerContainerrelateJoins),
|
||||
|
|
@ -177,8 +186,8 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
NoteImageBreadcrumbs: buildJoinSet[noteImageBreadcrumbJoins[Q]](NoteImageBreadcrumbs.Columns, buildNoteImageBreadcrumbJoins),
|
||||
NoteImageData: buildJoinSet[noteImageDatumJoins[Q]](NoteImageData.Columns, buildNoteImageDatumJoins),
|
||||
Notifications: buildJoinSet[notificationJoins[Q]](Notifications.Columns, buildNotificationJoins),
|
||||
OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins),
|
||||
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
|
||||
Parcels: buildJoinSet[parcelJoins[Q]](Parcels.Columns, buildParcelJoins),
|
||||
Pools: buildJoinSet[poolJoins[Q]](Pools.Columns, buildPoolJoins),
|
||||
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
|
||||
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
|
||||
|
|
@ -194,6 +203,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
PublicreportQuickImages: buildJoinSet[publicreportQuickImageJoins[Q]](PublicreportQuickImages.Columns, buildPublicreportQuickImageJoins),
|
||||
PublicreportSubscribeEmails: buildJoinSet[publicreportSubscribeEmailJoins[Q]](PublicreportSubscribeEmails.Columns, buildPublicreportSubscribeEmailJoins),
|
||||
PublicreportSubscribePhones: buildJoinSet[publicreportSubscribePhoneJoins[Q]](PublicreportSubscribePhones.Columns, buildPublicreportSubscribePhoneJoins),
|
||||
Residents: buildJoinSet[residentJoins[Q]](Residents.Columns, buildResidentJoins),
|
||||
Sites: buildJoinSet[siteJoins[Q]](Sites.Columns, buildSiteJoins),
|
||||
Users: buildJoinSet[userJoins[Q]](Users.Columns, buildUserJoins),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,14 @@ var Preload = getPreloaders()
|
|||
|
||||
type preloaders struct {
|
||||
Address addressPreloader
|
||||
ArcgisAccount arcgisAccountPreloader
|
||||
ArcgisAddressMapping arcgisAddressMappingPreloader
|
||||
ArcgisFeatureService arcgisFeatureServicePreloader
|
||||
ArcgisLayer arcgisLayerPreloader
|
||||
ArcgisLayerField arcgisLayerFieldPreloader
|
||||
ArcgisOauthToken arcgisOauthTokenPreloader
|
||||
ArcgisParcelMapping arcgisParcelMappingPreloader
|
||||
ArcgisServiceFeature arcgisServiceFeaturePreloader
|
||||
ArcgisServiceMap arcgisServiceMapPreloader
|
||||
ArcgisUser arcgisuserPreloader
|
||||
ArcgisUserPrivilege arcgisUserPrivilegePreloader
|
||||
CommsEmailContact commsEmailContactPreloader
|
||||
|
|
@ -31,6 +34,7 @@ type preloaders struct {
|
|||
CommsPhone commsPhonePreloader
|
||||
CommsTextJob commsTextJobPreloader
|
||||
CommsTextLog commsTextLogPreloader
|
||||
ComplianceReportRequest complianceReportRequestPreloader
|
||||
DistrictSubscriptionEmail districtSubscriptionEmailPreloader
|
||||
DistrictSubscriptionPhone districtSubscriptionPhonePreloader
|
||||
FieldseekerContainerrelate fieldseekerContainerrelatePreloader
|
||||
|
|
@ -74,8 +78,8 @@ type preloaders struct {
|
|||
NoteImageBreadcrumb noteImageBreadcrumbPreloader
|
||||
NoteImageDatum noteImageDatumPreloader
|
||||
Notification notificationPreloader
|
||||
OauthToken oauthTokenPreloader
|
||||
Organization organizationPreloader
|
||||
Parcel parcelPreloader
|
||||
Pool poolPreloader
|
||||
PublicreportImage publicreportImagePreloader
|
||||
PublicreportImageExif publicreportImageExifPreloader
|
||||
|
|
@ -91,6 +95,7 @@ type preloaders struct {
|
|||
PublicreportQuickImage publicreportQuickImagePreloader
|
||||
PublicreportSubscribeEmail publicreportSubscribeEmailPreloader
|
||||
PublicreportSubscribePhone publicreportSubscribePhonePreloader
|
||||
Resident residentPreloader
|
||||
Site sitePreloader
|
||||
User userPreloader
|
||||
}
|
||||
|
|
@ -98,11 +103,14 @@ type preloaders struct {
|
|||
func getPreloaders() preloaders {
|
||||
return preloaders{
|
||||
Address: buildAddressPreloader(),
|
||||
ArcgisAccount: buildArcgisAccountPreloader(),
|
||||
ArcgisAddressMapping: buildArcgisAddressMappingPreloader(),
|
||||
ArcgisFeatureService: buildArcgisFeatureServicePreloader(),
|
||||
ArcgisLayer: buildArcgisLayerPreloader(),
|
||||
ArcgisLayerField: buildArcgisLayerFieldPreloader(),
|
||||
ArcgisOauthToken: buildArcgisOauthTokenPreloader(),
|
||||
ArcgisParcelMapping: buildArcgisParcelMappingPreloader(),
|
||||
ArcgisServiceFeature: buildArcgisServiceFeaturePreloader(),
|
||||
ArcgisServiceMap: buildArcgisServiceMapPreloader(),
|
||||
ArcgisUser: buildArcgisUserPreloader(),
|
||||
ArcgisUserPrivilege: buildArcgisUserPrivilegePreloader(),
|
||||
CommsEmailContact: buildCommsEmailContactPreloader(),
|
||||
|
|
@ -111,6 +119,7 @@ func getPreloaders() preloaders {
|
|||
CommsPhone: buildCommsPhonePreloader(),
|
||||
CommsTextJob: buildCommsTextJobPreloader(),
|
||||
CommsTextLog: buildCommsTextLogPreloader(),
|
||||
ComplianceReportRequest: buildComplianceReportRequestPreloader(),
|
||||
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailPreloader(),
|
||||
DistrictSubscriptionPhone: buildDistrictSubscriptionPhonePreloader(),
|
||||
FieldseekerContainerrelate: buildFieldseekerContainerrelatePreloader(),
|
||||
|
|
@ -154,8 +163,8 @@ func getPreloaders() preloaders {
|
|||
NoteImageBreadcrumb: buildNoteImageBreadcrumbPreloader(),
|
||||
NoteImageDatum: buildNoteImageDatumPreloader(),
|
||||
Notification: buildNotificationPreloader(),
|
||||
OauthToken: buildOauthTokenPreloader(),
|
||||
Organization: buildOrganizationPreloader(),
|
||||
Parcel: buildParcelPreloader(),
|
||||
Pool: buildPoolPreloader(),
|
||||
PublicreportImage: buildPublicreportImagePreloader(),
|
||||
PublicreportImageExif: buildPublicreportImageExifPreloader(),
|
||||
|
|
@ -171,6 +180,7 @@ func getPreloaders() preloaders {
|
|||
PublicreportQuickImage: buildPublicreportQuickImagePreloader(),
|
||||
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailPreloader(),
|
||||
PublicreportSubscribePhone: buildPublicreportSubscribePhonePreloader(),
|
||||
Resident: buildResidentPreloader(),
|
||||
Site: buildSitePreloader(),
|
||||
User: buildUserPreloader(),
|
||||
}
|
||||
|
|
@ -184,11 +194,14 @@ var (
|
|||
|
||||
type thenLoaders[Q orm.Loadable] struct {
|
||||
Address addressThenLoader[Q]
|
||||
ArcgisAccount arcgisAccountThenLoader[Q]
|
||||
ArcgisAddressMapping arcgisAddressMappingThenLoader[Q]
|
||||
ArcgisFeatureService arcgisFeatureServiceThenLoader[Q]
|
||||
ArcgisLayer arcgisLayerThenLoader[Q]
|
||||
ArcgisLayerField arcgisLayerFieldThenLoader[Q]
|
||||
ArcgisOauthToken arcgisOauthTokenThenLoader[Q]
|
||||
ArcgisParcelMapping arcgisParcelMappingThenLoader[Q]
|
||||
ArcgisServiceFeature arcgisServiceFeatureThenLoader[Q]
|
||||
ArcgisServiceMap arcgisServiceMapThenLoader[Q]
|
||||
ArcgisUser arcgisuserThenLoader[Q]
|
||||
ArcgisUserPrivilege arcgisUserPrivilegeThenLoader[Q]
|
||||
CommsEmailContact commsEmailContactThenLoader[Q]
|
||||
|
|
@ -197,6 +210,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
CommsPhone commsPhoneThenLoader[Q]
|
||||
CommsTextJob commsTextJobThenLoader[Q]
|
||||
CommsTextLog commsTextLogThenLoader[Q]
|
||||
ComplianceReportRequest complianceReportRequestThenLoader[Q]
|
||||
DistrictSubscriptionEmail districtSubscriptionEmailThenLoader[Q]
|
||||
DistrictSubscriptionPhone districtSubscriptionPhoneThenLoader[Q]
|
||||
FieldseekerContainerrelate fieldseekerContainerrelateThenLoader[Q]
|
||||
|
|
@ -240,8 +254,8 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
NoteImageBreadcrumb noteImageBreadcrumbThenLoader[Q]
|
||||
NoteImageDatum noteImageDatumThenLoader[Q]
|
||||
Notification notificationThenLoader[Q]
|
||||
OauthToken oauthTokenThenLoader[Q]
|
||||
Organization organizationThenLoader[Q]
|
||||
Parcel parcelThenLoader[Q]
|
||||
Pool poolThenLoader[Q]
|
||||
PublicreportImage publicreportImageThenLoader[Q]
|
||||
PublicreportImageExif publicreportImageExifThenLoader[Q]
|
||||
|
|
@ -257,6 +271,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
PublicreportQuickImage publicreportQuickImageThenLoader[Q]
|
||||
PublicreportSubscribeEmail publicreportSubscribeEmailThenLoader[Q]
|
||||
PublicreportSubscribePhone publicreportSubscribePhoneThenLoader[Q]
|
||||
Resident residentThenLoader[Q]
|
||||
Site siteThenLoader[Q]
|
||||
User userThenLoader[Q]
|
||||
}
|
||||
|
|
@ -264,11 +279,14 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
||||
return thenLoaders[Q]{
|
||||
Address: buildAddressThenLoader[Q](),
|
||||
ArcgisAccount: buildArcgisAccountThenLoader[Q](),
|
||||
ArcgisAddressMapping: buildArcgisAddressMappingThenLoader[Q](),
|
||||
ArcgisFeatureService: buildArcgisFeatureServiceThenLoader[Q](),
|
||||
ArcgisLayer: buildArcgisLayerThenLoader[Q](),
|
||||
ArcgisLayerField: buildArcgisLayerFieldThenLoader[Q](),
|
||||
ArcgisOauthToken: buildArcgisOauthTokenThenLoader[Q](),
|
||||
ArcgisParcelMapping: buildArcgisParcelMappingThenLoader[Q](),
|
||||
ArcgisServiceFeature: buildArcgisServiceFeatureThenLoader[Q](),
|
||||
ArcgisServiceMap: buildArcgisServiceMapThenLoader[Q](),
|
||||
ArcgisUser: buildArcgisUserThenLoader[Q](),
|
||||
ArcgisUserPrivilege: buildArcgisUserPrivilegeThenLoader[Q](),
|
||||
CommsEmailContact: buildCommsEmailContactThenLoader[Q](),
|
||||
|
|
@ -277,6 +295,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
CommsPhone: buildCommsPhoneThenLoader[Q](),
|
||||
CommsTextJob: buildCommsTextJobThenLoader[Q](),
|
||||
CommsTextLog: buildCommsTextLogThenLoader[Q](),
|
||||
ComplianceReportRequest: buildComplianceReportRequestThenLoader[Q](),
|
||||
DistrictSubscriptionEmail: buildDistrictSubscriptionEmailThenLoader[Q](),
|
||||
DistrictSubscriptionPhone: buildDistrictSubscriptionPhoneThenLoader[Q](),
|
||||
FieldseekerContainerrelate: buildFieldseekerContainerrelateThenLoader[Q](),
|
||||
|
|
@ -320,8 +339,8 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
NoteImageBreadcrumb: buildNoteImageBreadcrumbThenLoader[Q](),
|
||||
NoteImageDatum: buildNoteImageDatumThenLoader[Q](),
|
||||
Notification: buildNotificationThenLoader[Q](),
|
||||
OauthToken: buildOauthTokenThenLoader[Q](),
|
||||
Organization: buildOrganizationThenLoader[Q](),
|
||||
Parcel: buildParcelThenLoader[Q](),
|
||||
Pool: buildPoolThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageThenLoader[Q](),
|
||||
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
|
||||
|
|
@ -337,6 +356,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
PublicreportQuickImage: buildPublicreportQuickImageThenLoader[Q](),
|
||||
PublicreportSubscribeEmail: buildPublicreportSubscribeEmailThenLoader[Q](),
|
||||
PublicreportSubscribePhone: buildPublicreportSubscribePhoneThenLoader[Q](),
|
||||
Resident: buildResidentThenLoader[Q](),
|
||||
Site: buildSiteThenLoader[Q](),
|
||||
User: buildUserThenLoader[Q](),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,19 +18,24 @@ var (
|
|||
|
||||
func Where[Q psql.Filterable]() struct {
|
||||
Addresses addressWhere[Q]
|
||||
ArcgisAccounts arcgisAccountWhere[Q]
|
||||
ArcgisAddressMappings arcgisAddressMappingWhere[Q]
|
||||
ArcgisFeatureServices arcgisFeatureServiceWhere[Q]
|
||||
ArcgisLayers arcgisLayerWhere[Q]
|
||||
ArcgisLayerFields arcgisLayerFieldWhere[Q]
|
||||
ArcgisOauthTokens arcgisOauthTokenWhere[Q]
|
||||
ArcgisParcelMappings arcgisParcelMappingWhere[Q]
|
||||
ArcgisServiceFeatures arcgisServiceFeatureWhere[Q]
|
||||
ArcgisServiceMaps arcgisServiceMapWhere[Q]
|
||||
ArcgisUsers arcgisuserWhere[Q]
|
||||
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
|
||||
CommsEmailContacts commsEmailContactWhere[Q]
|
||||
CommsEmailLogs commsEmailLogWhere[Q]
|
||||
CommsEmailTemplates commsEmailTemplateWhere[Q]
|
||||
CommsMailers commsMailerWhere[Q]
|
||||
CommsPhones commsPhoneWhere[Q]
|
||||
CommsTextJobs commsTextJobWhere[Q]
|
||||
CommsTextLogs commsTextLogWhere[Q]
|
||||
ComplianceReportRequests complianceReportRequestWhere[Q]
|
||||
DistrictSubscriptionEmails districtSubscriptionEmailWhere[Q]
|
||||
DistrictSubscriptionPhones districtSubscriptionPhoneWhere[Q]
|
||||
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
|
||||
|
|
@ -77,7 +82,6 @@ func Where[Q psql.Filterable]() struct {
|
|||
NoteImageBreadcrumbs noteImageBreadcrumbWhere[Q]
|
||||
NoteImageData noteImageDatumWhere[Q]
|
||||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
Parcels parcelWhere[Q]
|
||||
Pools poolWhere[Q]
|
||||
|
|
@ -98,6 +102,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
|
||||
RasterColumns rasterColumnWhere[Q]
|
||||
RasterOverviews rasterOverviewWhere[Q]
|
||||
Residents residentWhere[Q]
|
||||
Sessions sessionWhere[Q]
|
||||
Sites siteWhere[Q]
|
||||
SpatialRefSys spatialRefSyWhere[Q]
|
||||
|
|
@ -105,19 +110,24 @@ func Where[Q psql.Filterable]() struct {
|
|||
} {
|
||||
return struct {
|
||||
Addresses addressWhere[Q]
|
||||
ArcgisAccounts arcgisAccountWhere[Q]
|
||||
ArcgisAddressMappings arcgisAddressMappingWhere[Q]
|
||||
ArcgisFeatureServices arcgisFeatureServiceWhere[Q]
|
||||
ArcgisLayers arcgisLayerWhere[Q]
|
||||
ArcgisLayerFields arcgisLayerFieldWhere[Q]
|
||||
ArcgisOauthTokens arcgisOauthTokenWhere[Q]
|
||||
ArcgisParcelMappings arcgisParcelMappingWhere[Q]
|
||||
ArcgisServiceFeatures arcgisServiceFeatureWhere[Q]
|
||||
ArcgisServiceMaps arcgisServiceMapWhere[Q]
|
||||
ArcgisUsers arcgisuserWhere[Q]
|
||||
ArcgisUserPrivileges arcgisUserPrivilegeWhere[Q]
|
||||
CommsEmailContacts commsEmailContactWhere[Q]
|
||||
CommsEmailLogs commsEmailLogWhere[Q]
|
||||
CommsEmailTemplates commsEmailTemplateWhere[Q]
|
||||
CommsMailers commsMailerWhere[Q]
|
||||
CommsPhones commsPhoneWhere[Q]
|
||||
CommsTextJobs commsTextJobWhere[Q]
|
||||
CommsTextLogs commsTextLogWhere[Q]
|
||||
ComplianceReportRequests complianceReportRequestWhere[Q]
|
||||
DistrictSubscriptionEmails districtSubscriptionEmailWhere[Q]
|
||||
DistrictSubscriptionPhones districtSubscriptionPhoneWhere[Q]
|
||||
FieldseekerContainerrelates fieldseekerContainerrelateWhere[Q]
|
||||
|
|
@ -164,7 +174,6 @@ func Where[Q psql.Filterable]() struct {
|
|||
NoteImageBreadcrumbs noteImageBreadcrumbWhere[Q]
|
||||
NoteImageData noteImageDatumWhere[Q]
|
||||
Notifications notificationWhere[Q]
|
||||
OauthTokens oauthTokenWhere[Q]
|
||||
Organizations organizationWhere[Q]
|
||||
Parcels parcelWhere[Q]
|
||||
Pools poolWhere[Q]
|
||||
|
|
@ -185,25 +194,31 @@ func Where[Q psql.Filterable]() struct {
|
|||
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
|
||||
RasterColumns rasterColumnWhere[Q]
|
||||
RasterOverviews rasterOverviewWhere[Q]
|
||||
Residents residentWhere[Q]
|
||||
Sessions sessionWhere[Q]
|
||||
Sites siteWhere[Q]
|
||||
SpatialRefSys spatialRefSyWhere[Q]
|
||||
Users userWhere[Q]
|
||||
}{
|
||||
Addresses: buildAddressWhere[Q](Addresses.Columns),
|
||||
ArcgisAccounts: buildArcgisAccountWhere[Q](ArcgisAccounts.Columns),
|
||||
ArcgisAddressMappings: buildArcgisAddressMappingWhere[Q](ArcgisAddressMappings.Columns),
|
||||
ArcgisFeatureServices: buildArcgisFeatureServiceWhere[Q](ArcgisFeatureServices.Columns),
|
||||
ArcgisLayers: buildArcgisLayerWhere[Q](ArcgisLayers.Columns),
|
||||
ArcgisLayerFields: buildArcgisLayerFieldWhere[Q](ArcgisLayerFields.Columns),
|
||||
ArcgisOauthTokens: buildArcgisOauthTokenWhere[Q](ArcgisOauthTokens.Columns),
|
||||
ArcgisParcelMappings: buildArcgisParcelMappingWhere[Q](ArcgisParcelMappings.Columns),
|
||||
ArcgisServiceFeatures: buildArcgisServiceFeatureWhere[Q](ArcgisServiceFeatures.Columns),
|
||||
ArcgisServiceMaps: buildArcgisServiceMapWhere[Q](ArcgisServiceMaps.Columns),
|
||||
ArcgisUsers: buildArcgisUserWhere[Q](ArcgisUsers.Columns),
|
||||
ArcgisUserPrivileges: buildArcgisUserPrivilegeWhere[Q](ArcgisUserPrivileges.Columns),
|
||||
CommsEmailContacts: buildCommsEmailContactWhere[Q](CommsEmailContacts.Columns),
|
||||
CommsEmailLogs: buildCommsEmailLogWhere[Q](CommsEmailLogs.Columns),
|
||||
CommsEmailTemplates: buildCommsEmailTemplateWhere[Q](CommsEmailTemplates.Columns),
|
||||
CommsMailers: buildCommsMailerWhere[Q](CommsMailers.Columns),
|
||||
CommsPhones: buildCommsPhoneWhere[Q](CommsPhones.Columns),
|
||||
CommsTextJobs: buildCommsTextJobWhere[Q](CommsTextJobs.Columns),
|
||||
CommsTextLogs: buildCommsTextLogWhere[Q](CommsTextLogs.Columns),
|
||||
ComplianceReportRequests: buildComplianceReportRequestWhere[Q](ComplianceReportRequests.Columns),
|
||||
DistrictSubscriptionEmails: buildDistrictSubscriptionEmailWhere[Q](DistrictSubscriptionEmails.Columns),
|
||||
DistrictSubscriptionPhones: buildDistrictSubscriptionPhoneWhere[Q](DistrictSubscriptionPhones.Columns),
|
||||
FieldseekerContainerrelates: buildFieldseekerContainerrelateWhere[Q](FieldseekerContainerrelates.Columns),
|
||||
|
|
@ -250,7 +265,6 @@ func Where[Q psql.Filterable]() struct {
|
|||
NoteImageBreadcrumbs: buildNoteImageBreadcrumbWhere[Q](NoteImageBreadcrumbs.Columns),
|
||||
NoteImageData: buildNoteImageDatumWhere[Q](NoteImageData.Columns),
|
||||
Notifications: buildNotificationWhere[Q](Notifications.Columns),
|
||||
OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns),
|
||||
Organizations: buildOrganizationWhere[Q](Organizations.Columns),
|
||||
Parcels: buildParcelWhere[Q](Parcels.Columns),
|
||||
Pools: buildPoolWhere[Q](Pools.Columns),
|
||||
|
|
@ -271,6 +285,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
PublicreportSubscribePhones: buildPublicreportSubscribePhoneWhere[Q](PublicreportSubscribePhones.Columns),
|
||||
RasterColumns: buildRasterColumnWhere[Q](RasterColumns.Columns),
|
||||
RasterOverviews: buildRasterOverviewWhere[Q](RasterOverviews.Columns),
|
||||
Residents: buildResidentWhere[Q](Residents.Columns),
|
||||
Sessions: buildSessionWhere[Q](Sessions.Columns),
|
||||
Sites: buildSiteWhere[Q](Sites.Columns),
|
||||
SpatialRefSys: buildSpatialRefSyWhere[Q](SpatialRefSys.Columns),
|
||||
|
|
|
|||
400
db/models/comms.mailer.bob.go
Normal file
400
db/models/comms.mailer.bob.go
Normal file
|
|
@ -0,0 +1,400 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// CommsMailer is an object representing the database table.
|
||||
type CommsMailer struct {
|
||||
Created time.Time `db:"created" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Type enums.CommsMailertype `db:"type_" `
|
||||
}
|
||||
|
||||
// CommsMailerSlice is an alias for a slice of pointers to CommsMailer.
|
||||
// This should almost always be used instead of []*CommsMailer.
|
||||
type CommsMailerSlice []*CommsMailer
|
||||
|
||||
// CommsMailers contains methods to work with the mailer table
|
||||
var CommsMailers = psql.NewTablex[*CommsMailer, CommsMailerSlice, *CommsMailerSetter]("comms", "mailer", buildCommsMailerColumns("comms.mailer"))
|
||||
|
||||
// CommsMailersQuery is a query on the mailer table
|
||||
type CommsMailersQuery = *psql.ViewQuery[*CommsMailer, CommsMailerSlice]
|
||||
|
||||
func buildCommsMailerColumns(alias string) commsMailerColumns {
|
||||
return commsMailerColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "id", "type_",
|
||||
).WithParent("comms.mailer"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Type: psql.Quote(alias, "type_"),
|
||||
}
|
||||
}
|
||||
|
||||
type commsMailerColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Created psql.Expression
|
||||
ID psql.Expression
|
||||
Type psql.Expression
|
||||
}
|
||||
|
||||
func (c commsMailerColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (commsMailerColumns) AliasedAs(alias string) commsMailerColumns {
|
||||
return buildCommsMailerColumns(alias)
|
||||
}
|
||||
|
||||
// CommsMailerSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type CommsMailerSetter struct {
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Type omit.Val[enums.CommsMailertype] `db:"type_" `
|
||||
}
|
||||
|
||||
func (s CommsMailerSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 3)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
vals = append(vals, "type_")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s CommsMailerSetter) Overwrite(t *CommsMailer) {
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
t.Type = s.Type.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CommsMailerSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return CommsMailers.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 3)
|
||||
if s.Created.IsValue() {
|
||||
vals[0] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[1] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
vals[2] = psql.Arg(s.Type.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s CommsMailerSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s CommsMailerSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 3)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "type_")...),
|
||||
psql.Arg(s.Type),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindCommsMailer retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindCommsMailer(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*CommsMailer, error) {
|
||||
if len(cols) == 0 {
|
||||
return CommsMailers.Query(
|
||||
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return CommsMailers.Query(
|
||||
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(CommsMailers.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// CommsMailerExists checks the presence of a single record by primary key
|
||||
func CommsMailerExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return CommsMailers.Query(
|
||||
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after CommsMailer is retrieved from the database
|
||||
func (o *CommsMailer) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = CommsMailers.AfterSelectHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = CommsMailers.AfterInsertHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = CommsMailers.AfterUpdateHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = CommsMailers.AfterDeleteHooks.RunHooks(ctx, exec, CommsMailerSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the CommsMailer
|
||||
func (o *CommsMailer) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *CommsMailer) pkEQ() dialect.Expression {
|
||||
return psql.Quote("comms.mailer", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the CommsMailer
|
||||
func (o *CommsMailer) Update(ctx context.Context, exec bob.Executor, s *CommsMailerSetter) error {
|
||||
v, err := CommsMailers.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single CommsMailer record with an executor
|
||||
func (o *CommsMailer) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := CommsMailers.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the CommsMailer using the executor
|
||||
func (o *CommsMailer) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := CommsMailers.Query(
|
||||
sm.Where(CommsMailers.Columns.ID.EQ(psql.Arg(o.ID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after CommsMailerSlice is retrieved from the database
|
||||
func (o CommsMailerSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = CommsMailers.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = CommsMailers.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = CommsMailers.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = CommsMailers.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o CommsMailerSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("comms.mailer", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o CommsMailerSlice) copyMatchingRows(from ...*CommsMailer) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o CommsMailerSlice) 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 CommsMailers.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 *CommsMailer:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*CommsMailer:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case CommsMailerSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a CommsMailer or a slice of CommsMailer
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = CommsMailers.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o CommsMailerSlice) 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 CommsMailers.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 *CommsMailer:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*CommsMailer:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case CommsMailerSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a CommsMailer or a slice of CommsMailer
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = CommsMailers.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o CommsMailerSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals CommsMailerSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := CommsMailers.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o CommsMailerSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := CommsMailers.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o CommsMailerSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := CommsMailers.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsMailerWhere[Q psql.Filterable] struct {
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Type psql.WhereMod[Q, enums.CommsMailertype]
|
||||
}
|
||||
|
||||
func (commsMailerWhere[Q]) AliasedAs(alias string) commsMailerWhere[Q] {
|
||||
return buildCommsMailerWhere[Q](buildCommsMailerColumns(alias))
|
||||
}
|
||||
|
||||
func buildCommsMailerWhere[Q psql.Filterable](cols commsMailerColumns) commsMailerWhere[Q] {
|
||||
return commsMailerWhere[Q]{
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Type: psql.Where[Q, enums.CommsMailertype](cols.Type),
|
||||
}
|
||||
}
|
||||
|
|
@ -57,6 +57,7 @@ type commsPhoneR struct {
|
|||
PhoneE164NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_phone_e164_fkey
|
||||
PhoneE164NotifyPhonePools PublicreportNotifyPhonePoolSlice // publicreport.notify_phone_pool.notify_phone_pool_phone_e164_fkey
|
||||
PhoneE164SubscribePhones PublicreportSubscribePhoneSlice // publicreport.subscribe_phone.subscribe_phone_phone_e164_fkey
|
||||
PhoneMobileResidents ResidentSlice // resident.resident_phone_mobile_fkey
|
||||
}
|
||||
|
||||
func buildCommsPhoneColumns(alias string) commsPhoneColumns {
|
||||
|
|
@ -626,6 +627,30 @@ func (os CommsPhoneSlice) PhoneE164SubscribePhones(mods ...bob.Mod[*dialect.Sele
|
|||
)...)
|
||||
}
|
||||
|
||||
// PhoneMobileResidents starts a query for related objects on resident
|
||||
func (o *CommsPhone) PhoneMobileResidents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
return Residents.Query(append(mods,
|
||||
sm.Where(Residents.Columns.PhoneMobile.EQ(psql.Arg(o.E164))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os CommsPhoneSlice) PhoneMobileResidents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
pkE164 := make(pgtypes.Array[string], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkE164 = append(pkE164, o.E164)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkE164), "text[]")),
|
||||
))
|
||||
|
||||
return Residents.Query(append(mods,
|
||||
sm.Where(psql.Group(Residents.Columns.PhoneMobile).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertCommsPhoneDestinationTextJobs0(ctx context.Context, exec bob.Executor, commsTextJobs1 []*CommsTextJobSetter, commsPhone0 *CommsPhone) (CommsTextJobSlice, error) {
|
||||
for i := range commsTextJobs1 {
|
||||
commsTextJobs1[i].Destination = omit.From(commsPhone0.E164)
|
||||
|
|
@ -1235,6 +1260,74 @@ func (commsPhone0 *CommsPhone) AttachPhoneE164SubscribePhones(ctx context.Contex
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertCommsPhonePhoneMobileResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, commsPhone0 *CommsPhone) (ResidentSlice, error) {
|
||||
for i := range residents1 {
|
||||
residents1[i].PhoneMobile = omitnull.From(commsPhone0.E164)
|
||||
}
|
||||
|
||||
ret, err := Residents.Insert(bob.ToMods(residents1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertCommsPhonePhoneMobileResidents0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachCommsPhonePhoneMobileResidents0(ctx context.Context, exec bob.Executor, count int, residents1 ResidentSlice, commsPhone0 *CommsPhone) (ResidentSlice, error) {
|
||||
setter := &ResidentSetter{
|
||||
PhoneMobile: omitnull.From(commsPhone0.E164),
|
||||
}
|
||||
|
||||
err := residents1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachCommsPhonePhoneMobileResidents0: %w", err)
|
||||
}
|
||||
|
||||
return residents1, nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) InsertPhoneMobileResidents(ctx context.Context, exec bob.Executor, related ...*ResidentSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
residents1, err := insertCommsPhonePhoneMobileResidents0(ctx, exec, related, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.PhoneMobileResidents = append(commsPhone0.R.PhoneMobileResidents, residents1...)
|
||||
|
||||
for _, rel := range residents1 {
|
||||
rel.R.PhoneMobilePhone = commsPhone0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (commsPhone0 *CommsPhone) AttachPhoneMobileResidents(ctx context.Context, exec bob.Executor, related ...*Resident) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
residents1 := ResidentSlice(related)
|
||||
|
||||
_, err = attachCommsPhonePhoneMobileResidents0(ctx, exec, len(related), residents1, commsPhone0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commsPhone0.R.PhoneMobileResidents = append(commsPhone0.R.PhoneMobileResidents, residents1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.PhoneMobilePhone = commsPhone0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsPhoneWhere[Q psql.Filterable] struct {
|
||||
E164 psql.WhereMod[Q, string]
|
||||
IsSubscribed psql.WhereMod[Q, bool]
|
||||
|
|
@ -1385,6 +1478,20 @@ func (o *CommsPhone) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "PhoneMobileResidents":
|
||||
rels, ok := retrieved.(ResidentSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("commsPhone cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.PhoneMobileResidents = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.PhoneMobilePhone = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("commsPhone has no relationship %q", name)
|
||||
}
|
||||
|
|
@ -1406,6 +1513,7 @@ type commsPhoneThenLoader[Q orm.Loadable] struct {
|
|||
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
|
||||
|
|
@ -1436,6 +1544,9 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
|
|||
type PhoneE164SubscribePhonesLoadInterface interface {
|
||||
LoadPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PhoneMobileResidentsLoadInterface interface {
|
||||
LoadPhoneMobileResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return commsPhoneThenLoader[Q]{
|
||||
DestinationTextJobs: thenLoadBuilder[Q](
|
||||
|
|
@ -1492,6 +1603,12 @@ func buildCommsPhoneThenLoader[Q orm.Loadable]() commsPhoneThenLoader[Q] {
|
|||
return retrieved.LoadPhoneE164SubscribePhones(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
PhoneMobileResidents: thenLoadBuilder[Q](
|
||||
"PhoneMobileResidents",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PhoneMobileResidentsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadPhoneMobileResidents(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2070,6 +2187,70 @@ func (os CommsPhoneSlice) LoadPhoneE164SubscribePhones(ctx context.Context, exec
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadPhoneMobileResidents loads the commsPhone's PhoneMobileResidents into the .R struct
|
||||
func (o *CommsPhone) LoadPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.PhoneMobileResidents = nil
|
||||
|
||||
related, err := o.PhoneMobileResidents(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.PhoneMobilePhone = o
|
||||
}
|
||||
|
||||
o.R.PhoneMobileResidents = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPhoneMobileResidents loads the commsPhone's PhoneMobileResidents into the .R struct
|
||||
func (os CommsPhoneSlice) LoadPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
residents, err := os.PhoneMobileResidents(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.PhoneMobileResidents = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range residents {
|
||||
|
||||
if !rel.PhoneMobile.IsValue() {
|
||||
continue
|
||||
}
|
||||
if !(rel.PhoneMobile.IsValue() && o.E164 == rel.PhoneMobile.MustGet()) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.PhoneMobilePhone = o
|
||||
|
||||
o.R.PhoneMobileResidents = append(o.R.PhoneMobileResidents, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// commsPhoneC is where relationship counts are stored.
|
||||
type commsPhoneC struct {
|
||||
DestinationTextJobs *int64
|
||||
|
|
@ -2081,6 +2262,7 @@ type commsPhoneC struct {
|
|||
PhoneE164NotifyPhoneNuisances *int64
|
||||
PhoneE164NotifyPhonePools *int64
|
||||
PhoneE164SubscribePhones *int64
|
||||
PhoneMobileResidents *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
|
|
@ -2108,6 +2290,8 @@ func (o *CommsPhone) PreloadCount(name string, count int64) error {
|
|||
o.C.PhoneE164NotifyPhonePools = &count
|
||||
case "PhoneE164SubscribePhones":
|
||||
o.C.PhoneE164SubscribePhones = &count
|
||||
case "PhoneMobileResidents":
|
||||
o.C.PhoneMobileResidents = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -2122,6 +2306,7 @@ type commsPhoneCountPreloader struct {
|
|||
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
||||
|
|
@ -2282,6 +2467,23 @@ func buildCommsPhoneCountPreloader() commsPhoneCountPreloader {
|
|||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
PhoneMobileResidents: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*CommsPhone]("PhoneMobileResidents", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = CommsPhones.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Residents.Name()),
|
||||
sm.Where(psql.Quote(Residents.Alias(), "phone_mobile").EQ(psql.Quote(parent, "e164"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2295,6 +2497,7 @@ type commsPhoneCountThenLoader[Q orm.Loadable] struct {
|
|||
PhoneE164NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneE164NotifyPhonePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneE164SubscribePhones func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
PhoneMobileResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[Q] {
|
||||
|
|
@ -2325,6 +2528,9 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
|
|||
type PhoneE164SubscribePhonesCountInterface interface {
|
||||
LoadCountPhoneE164SubscribePhones(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type PhoneMobileResidentsCountInterface interface {
|
||||
LoadCountPhoneMobileResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return commsPhoneCountThenLoader[Q]{
|
||||
DestinationTextJobs: countThenLoadBuilder[Q](
|
||||
|
|
@ -2381,6 +2587,12 @@ func buildCommsPhoneCountThenLoader[Q orm.Loadable]() commsPhoneCountThenLoader[
|
|||
return retrieved.LoadCountPhoneE164SubscribePhones(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
PhoneMobileResidents: countThenLoadBuilder[Q](
|
||||
"PhoneMobileResidents",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved PhoneMobileResidentsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountPhoneMobileResidents(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2654,6 +2866,36 @@ func (os CommsPhoneSlice) LoadCountPhoneE164SubscribePhones(ctx context.Context,
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPhoneMobileResidents loads the count of PhoneMobileResidents into the C struct
|
||||
func (o *CommsPhone) LoadCountPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.PhoneMobileResidents(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.PhoneMobileResidents = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountPhoneMobileResidents loads the count of PhoneMobileResidents for a slice
|
||||
func (os CommsPhoneSlice) LoadCountPhoneMobileResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountPhoneMobileResidents(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type commsPhoneJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
DestinationTextJobs modAs[Q, commsTextJobColumns]
|
||||
|
|
@ -2665,6 +2907,7 @@ type commsPhoneJoins[Q dialect.Joinable] struct {
|
|||
PhoneE164NotifyPhoneNuisances modAs[Q, publicreportNotifyPhoneNuisanceColumns]
|
||||
PhoneE164NotifyPhonePools modAs[Q, publicreportNotifyPhonePoolColumns]
|
||||
PhoneE164SubscribePhones modAs[Q, publicreportSubscribePhoneColumns]
|
||||
PhoneMobileResidents modAs[Q, residentColumns]
|
||||
}
|
||||
|
||||
func (j commsPhoneJoins[Q]) aliasedAs(alias string) commsPhoneJoins[Q] {
|
||||
|
|
@ -2805,6 +3048,20 @@ func buildCommsPhoneJoins[Q dialect.Joinable](cols commsPhoneColumns, typ string
|
|||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
PhoneMobileResidents: modAs[Q, residentColumns]{
|
||||
c: Residents.Columns,
|
||||
f: func(to residentColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Residents.Name().As(to.Alias())).On(
|
||||
to.PhoneMobile.EQ(cols.E164),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
|
|
|
|||
888
db/models/compliance_report_request.bob.go
Normal file
888
db/models/compliance_report_request.bob.go
Normal file
|
|
@ -0,0 +1,888 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/omit"
|
||||
)
|
||||
|
||||
// ComplianceReportRequest is an object representing the database table.
|
||||
type ComplianceReportRequest struct {
|
||||
Created time.Time `db:"created" `
|
||||
Creator int32 `db:"creator" `
|
||||
ID int32 `db:"id,pk" `
|
||||
PublicID string `db:"public_id" `
|
||||
SiteID int32 `db:"site_id" `
|
||||
SiteVersion int32 `db:"site_version" `
|
||||
|
||||
R complianceReportRequestR `db:"-" `
|
||||
}
|
||||
|
||||
// ComplianceReportRequestSlice is an alias for a slice of pointers to ComplianceReportRequest.
|
||||
// This should almost always be used instead of []*ComplianceReportRequest.
|
||||
type ComplianceReportRequestSlice []*ComplianceReportRequest
|
||||
|
||||
// ComplianceReportRequests contains methods to work with the compliance_report_request table
|
||||
var ComplianceReportRequests = psql.NewTablex[*ComplianceReportRequest, ComplianceReportRequestSlice, *ComplianceReportRequestSetter]("", "compliance_report_request", buildComplianceReportRequestColumns("compliance_report_request"))
|
||||
|
||||
// ComplianceReportRequestsQuery is a query on the compliance_report_request table
|
||||
type ComplianceReportRequestsQuery = *psql.ViewQuery[*ComplianceReportRequest, ComplianceReportRequestSlice]
|
||||
|
||||
// complianceReportRequestR is where relationships are stored.
|
||||
type complianceReportRequestR struct {
|
||||
CreatorUser *User // compliance_report_request.compliance_report_request_creator_fkey
|
||||
Site *Site // compliance_report_request.compliance_report_request_site_id_site_version_fkey
|
||||
}
|
||||
|
||||
func buildComplianceReportRequestColumns(alias string) complianceReportRequestColumns {
|
||||
return complianceReportRequestColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "creator", "id", "public_id", "site_id", "site_version",
|
||||
).WithParent("compliance_report_request"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Creator: psql.Quote(alias, "creator"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
PublicID: psql.Quote(alias, "public_id"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
SiteVersion: psql.Quote(alias, "site_version"),
|
||||
}
|
||||
}
|
||||
|
||||
type complianceReportRequestColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Created psql.Expression
|
||||
Creator psql.Expression
|
||||
ID psql.Expression
|
||||
PublicID psql.Expression
|
||||
SiteID psql.Expression
|
||||
SiteVersion psql.Expression
|
||||
}
|
||||
|
||||
func (c complianceReportRequestColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (complianceReportRequestColumns) AliasedAs(alias string) complianceReportRequestColumns {
|
||||
return buildComplianceReportRequestColumns(alias)
|
||||
}
|
||||
|
||||
// ComplianceReportRequestSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ComplianceReportRequestSetter struct {
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Creator omit.Val[int32] `db:"creator" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
PublicID omit.Val[string] `db:"public_id" `
|
||||
SiteID omit.Val[int32] `db:"site_id" `
|
||||
SiteVersion omit.Val[int32] `db:"site_version" `
|
||||
}
|
||||
|
||||
func (s ComplianceReportRequestSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 6)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if s.Creator.IsValue() {
|
||||
vals = append(vals, "creator")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.PublicID.IsValue() {
|
||||
vals = append(vals, "public_id")
|
||||
}
|
||||
if s.SiteID.IsValue() {
|
||||
vals = append(vals, "site_id")
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals = append(vals, "site_version")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s ComplianceReportRequestSetter) Overwrite(t *ComplianceReportRequest) {
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
if s.Creator.IsValue() {
|
||||
t.Creator = s.Creator.MustGet()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.PublicID.IsValue() {
|
||||
t.PublicID = s.PublicID.MustGet()
|
||||
}
|
||||
if s.SiteID.IsValue() {
|
||||
t.SiteID = s.SiteID.MustGet()
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
t.SiteVersion = s.SiteVersion.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ComplianceReportRequestSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return ComplianceReportRequests.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 6)
|
||||
if s.Created.IsValue() {
|
||||
vals[0] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Creator.IsValue() {
|
||||
vals[1] = psql.Arg(s.Creator.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[2] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.PublicID.IsValue() {
|
||||
vals[3] = psql.Arg(s.PublicID.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.SiteID.IsValue() {
|
||||
vals[4] = psql.Arg(s.SiteID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals[5] = psql.Arg(s.SiteVersion.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s ComplianceReportRequestSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s ComplianceReportRequestSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 6)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Creator.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "creator")...),
|
||||
psql.Arg(s.Creator),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.PublicID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "public_id")...),
|
||||
psql.Arg(s.PublicID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.SiteID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_id")...),
|
||||
psql.Arg(s.SiteID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_version")...),
|
||||
psql.Arg(s.SiteVersion),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindComplianceReportRequest retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindComplianceReportRequest(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*ComplianceReportRequest, error) {
|
||||
if len(cols) == 0 {
|
||||
return ComplianceReportRequests.Query(
|
||||
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return ComplianceReportRequests.Query(
|
||||
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(ComplianceReportRequests.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// ComplianceReportRequestExists checks the presence of a single record by primary key
|
||||
func ComplianceReportRequestExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return ComplianceReportRequests.Query(
|
||||
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ComplianceReportRequest is retrieved from the database
|
||||
func (o *ComplianceReportRequest) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ComplianceReportRequests.AfterSelectHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ComplianceReportRequests.AfterInsertHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ComplianceReportRequests.AfterUpdateHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ComplianceReportRequests.AfterDeleteHooks.RunHooks(ctx, exec, ComplianceReportRequestSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the ComplianceReportRequest
|
||||
func (o *ComplianceReportRequest) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *ComplianceReportRequest) pkEQ() dialect.Expression {
|
||||
return psql.Quote("compliance_report_request", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
||||
// Update uses an executor to update the ComplianceReportRequest
|
||||
func (o *ComplianceReportRequest) Update(ctx context.Context, exec bob.Executor, s *ComplianceReportRequestSetter) error {
|
||||
v, err := ComplianceReportRequests.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 ComplianceReportRequest record with an executor
|
||||
func (o *ComplianceReportRequest) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := ComplianceReportRequests.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the ComplianceReportRequest using the executor
|
||||
func (o *ComplianceReportRequest) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := ComplianceReportRequests.Query(
|
||||
sm.Where(ComplianceReportRequests.Columns.ID.EQ(psql.Arg(o.ID))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after ComplianceReportRequestSlice is retrieved from the database
|
||||
func (o ComplianceReportRequestSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = ComplianceReportRequests.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = ComplianceReportRequests.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = ComplianceReportRequests.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = ComplianceReportRequests.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ComplianceReportRequestSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("compliance_report_request", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
}
|
||||
return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
// copyMatchingRows finds models in the given slice that have the same primary key
|
||||
// then it first copies the existing relationships from the old model to the new model
|
||||
// and then replaces the old model in the slice with the new model
|
||||
func (o ComplianceReportRequestSlice) copyMatchingRows(from ...*ComplianceReportRequest) {
|
||||
for i, old := range o {
|
||||
for _, new := range from {
|
||||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
|
||||
func (o ComplianceReportRequestSlice) 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 ComplianceReportRequests.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 *ComplianceReportRequest:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ComplianceReportRequest:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ComplianceReportRequestSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ComplianceReportRequest or a slice of ComplianceReportRequest
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = ComplianceReportRequests.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o ComplianceReportRequestSlice) 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 ComplianceReportRequests.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 *ComplianceReportRequest:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*ComplianceReportRequest:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case ComplianceReportRequestSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a ComplianceReportRequest or a slice of ComplianceReportRequest
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = ComplianceReportRequests.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o ComplianceReportRequestSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals ComplianceReportRequestSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ComplianceReportRequests.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ComplianceReportRequestSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := ComplianceReportRequests.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o ComplianceReportRequestSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := ComplianceReportRequests.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreatorUser starts a query for related objects on user_
|
||||
func (o *ComplianceReportRequest) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.Creator))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ComplianceReportRequestSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkCreator := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkCreator = append(pkCreator, o.Creator)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkCreator), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Site starts a query for related objects on site
|
||||
func (o *ComplianceReportRequest) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ComplianceReportRequestSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkSiteID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkSiteVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkSiteID = append(pkSiteID, o.SiteID)
|
||||
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachComplianceReportRequestCreatorUser0(ctx context.Context, exec bob.Executor, count int, complianceReportRequest0 *ComplianceReportRequest, user1 *User) (*ComplianceReportRequest, error) {
|
||||
setter := &ComplianceReportRequestSetter{
|
||||
Creator: omit.From(user1.ID),
|
||||
}
|
||||
|
||||
err := complianceReportRequest0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachComplianceReportRequestCreatorUser0: %w", err)
|
||||
}
|
||||
|
||||
return complianceReportRequest0, nil
|
||||
}
|
||||
|
||||
func (complianceReportRequest0 *ComplianceReportRequest) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
|
||||
var err error
|
||||
|
||||
user1, err := Users.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachComplianceReportRequestCreatorUser0(ctx, exec, 1, complianceReportRequest0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
complianceReportRequest0.R.CreatorUser = user1
|
||||
|
||||
user1.R.CreatorComplianceReportRequests = append(user1.R.CreatorComplianceReportRequests, complianceReportRequest0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (complianceReportRequest0 *ComplianceReportRequest) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachComplianceReportRequestCreatorUser0(ctx, exec, 1, complianceReportRequest0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
complianceReportRequest0.R.CreatorUser = user1
|
||||
|
||||
user1.R.CreatorComplianceReportRequests = append(user1.R.CreatorComplianceReportRequests, complianceReportRequest0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachComplianceReportRequestSite0(ctx context.Context, exec bob.Executor, count int, complianceReportRequest0 *ComplianceReportRequest, site1 *Site) (*ComplianceReportRequest, error) {
|
||||
setter := &ComplianceReportRequestSetter{
|
||||
SiteID: omit.From(site1.ID),
|
||||
SiteVersion: omit.From(site1.Version),
|
||||
}
|
||||
|
||||
err := complianceReportRequest0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachComplianceReportRequestSite0: %w", err)
|
||||
}
|
||||
|
||||
return complianceReportRequest0, nil
|
||||
}
|
||||
|
||||
func (complianceReportRequest0 *ComplianceReportRequest) InsertSite(ctx context.Context, exec bob.Executor, related *SiteSetter) error {
|
||||
var err error
|
||||
|
||||
site1, err := Sites.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachComplianceReportRequestSite0(ctx, exec, 1, complianceReportRequest0, site1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
complianceReportRequest0.R.Site = site1
|
||||
|
||||
site1.R.ComplianceReportRequests = append(site1.R.ComplianceReportRequests, complianceReportRequest0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (complianceReportRequest0 *ComplianceReportRequest) AttachSite(ctx context.Context, exec bob.Executor, site1 *Site) error {
|
||||
var err error
|
||||
|
||||
_, err = attachComplianceReportRequestSite0(ctx, exec, 1, complianceReportRequest0, site1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
complianceReportRequest0.R.Site = site1
|
||||
|
||||
site1.R.ComplianceReportRequests = append(site1.R.ComplianceReportRequests, complianceReportRequest0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type complianceReportRequestWhere[Q psql.Filterable] struct {
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Creator psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
PublicID psql.WhereMod[Q, string]
|
||||
SiteID psql.WhereMod[Q, int32]
|
||||
SiteVersion psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (complianceReportRequestWhere[Q]) AliasedAs(alias string) complianceReportRequestWhere[Q] {
|
||||
return buildComplianceReportRequestWhere[Q](buildComplianceReportRequestColumns(alias))
|
||||
}
|
||||
|
||||
func buildComplianceReportRequestWhere[Q psql.Filterable](cols complianceReportRequestColumns) complianceReportRequestWhere[Q] {
|
||||
return complianceReportRequestWhere[Q]{
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Creator: psql.Where[Q, int32](cols.Creator),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
PublicID: psql.Where[Q, string](cols.PublicID),
|
||||
SiteID: psql.Where[Q, int32](cols.SiteID),
|
||||
SiteVersion: psql.Where[Q, int32](cols.SiteVersion),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ComplianceReportRequest) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "CreatorUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("complianceReportRequest cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.CreatorUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.CreatorComplianceReportRequests = ComplianceReportRequestSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Site":
|
||||
rel, ok := retrieved.(*Site)
|
||||
if !ok {
|
||||
return fmt.Errorf("complianceReportRequest cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Site = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ComplianceReportRequests = ComplianceReportRequestSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("complianceReportRequest has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type complianceReportRequestPreloader struct {
|
||||
CreatorUser func(...psql.PreloadOption) psql.Preloader
|
||||
Site func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildComplianceReportRequestPreloader() complianceReportRequestPreloader {
|
||||
return complianceReportRequestPreloader{
|
||||
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "CreatorUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ComplianceReportRequests,
|
||||
To: Users,
|
||||
FromColumns: []string{"creator"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
Site: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Site, SiteSlice](psql.PreloadRel{
|
||||
Name: "Site",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: ComplianceReportRequests,
|
||||
To: Sites,
|
||||
FromColumns: []string{"site_id", "site_version"},
|
||||
ToColumns: []string{"id", "version"},
|
||||
},
|
||||
},
|
||||
}, Sites.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type complianceReportRequestThenLoader[Q orm.Loadable] struct {
|
||||
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildComplianceReportRequestThenLoader[Q orm.Loadable]() complianceReportRequestThenLoader[Q] {
|
||||
type CreatorUserLoadInterface interface {
|
||||
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SiteLoadInterface interface {
|
||||
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return complianceReportRequestThenLoader[Q]{
|
||||
CreatorUser: thenLoadBuilder[Q](
|
||||
"CreatorUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCreatorUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Site: thenLoadBuilder[Q](
|
||||
"Site",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadSite(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCreatorUser loads the complianceReportRequest's CreatorUser into the .R struct
|
||||
func (o *ComplianceReportRequest) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.CreatorUser = nil
|
||||
|
||||
related, err := o.CreatorUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.CreatorComplianceReportRequests = ComplianceReportRequestSlice{o}
|
||||
|
||||
o.R.CreatorUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorUser loads the complianceReportRequest's CreatorUser into the .R struct
|
||||
func (os ComplianceReportRequestSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.CreatorUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
|
||||
if !(o.Creator == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.CreatorComplianceReportRequests = append(rel.R.CreatorComplianceReportRequests, o)
|
||||
|
||||
o.R.CreatorUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSite loads the complianceReportRequest's Site into the .R struct
|
||||
func (o *ComplianceReportRequest) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Site = nil
|
||||
|
||||
related, err := o.Site(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ComplianceReportRequests = ComplianceReportRequestSlice{o}
|
||||
|
||||
o.R.Site = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSite loads the complianceReportRequest's Site into the .R struct
|
||||
func (os ComplianceReportRequestSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sites, err := os.Site(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range sites {
|
||||
|
||||
if !(o.SiteID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.SiteVersion == rel.Version) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ComplianceReportRequests = append(rel.R.ComplianceReportRequests, o)
|
||||
|
||||
o.R.Site = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type complianceReportRequestJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
CreatorUser modAs[Q, userColumns]
|
||||
Site modAs[Q, siteColumns]
|
||||
}
|
||||
|
||||
func (j complianceReportRequestJoins[Q]) aliasedAs(alias string) complianceReportRequestJoins[Q] {
|
||||
return buildComplianceReportRequestJoins[Q](buildComplianceReportRequestColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildComplianceReportRequestJoins[Q dialect.Joinable](cols complianceReportRequestColumns, typ string) complianceReportRequestJoins[Q] {
|
||||
return complianceReportRequestJoins[Q]{
|
||||
typ: typ,
|
||||
CreatorUser: modAs[Q, userColumns]{
|
||||
c: Users.Columns,
|
||||
f: func(to userColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.Creator),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Site: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.SiteID), to.Version.EQ(cols.SiteVersion),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -5,6 +5,7 @@ package models
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
|
|
@ -14,15 +15,24 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/mods"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
)
|
||||
|
||||
// Parcel is an object representing the database table.
|
||||
type Parcel struct {
|
||||
Apn string `db:"apn" `
|
||||
Description string `db:"description" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Geometry string `db:"geometry" `
|
||||
Apn null.Val[string] `db:"apn" `
|
||||
Description null.Val[string] `db:"description" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Geometry string `db:"geometry" `
|
||||
|
||||
R parcelR `db:"-" `
|
||||
|
||||
C parcelC `db:"-" `
|
||||
}
|
||||
|
||||
// ParcelSlice is an alias for a slice of pointers to Parcel.
|
||||
|
|
@ -35,6 +45,11 @@ var Parcels = psql.NewTablex[*Parcel, ParcelSlice, *ParcelSetter]("", "parcel",
|
|||
// ParcelsQuery is a query on the parcel table
|
||||
type ParcelsQuery = *psql.ViewQuery[*Parcel, ParcelSlice]
|
||||
|
||||
// parcelR is where relationships are stored.
|
||||
type parcelR struct {
|
||||
Sites SiteSlice // site.site_parcel_id_fkey
|
||||
}
|
||||
|
||||
func buildParcelColumns(alias string) parcelColumns {
|
||||
return parcelColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
|
|
@ -69,18 +84,18 @@ func (parcelColumns) AliasedAs(alias string) parcelColumns {
|
|||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type ParcelSetter struct {
|
||||
Apn omit.Val[string] `db:"apn" `
|
||||
Description omit.Val[string] `db:"description" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Geometry omit.Val[string] `db:"geometry" `
|
||||
Apn omitnull.Val[string] `db:"apn" `
|
||||
Description omitnull.Val[string] `db:"description" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Geometry omit.Val[string] `db:"geometry" `
|
||||
}
|
||||
|
||||
func (s ParcelSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 4)
|
||||
if s.Apn.IsValue() {
|
||||
if !s.Apn.IsUnset() {
|
||||
vals = append(vals, "apn")
|
||||
}
|
||||
if s.Description.IsValue() {
|
||||
if !s.Description.IsUnset() {
|
||||
vals = append(vals, "description")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
|
|
@ -93,11 +108,11 @@ func (s ParcelSetter) SetColumns() []string {
|
|||
}
|
||||
|
||||
func (s ParcelSetter) Overwrite(t *Parcel) {
|
||||
if s.Apn.IsValue() {
|
||||
t.Apn = s.Apn.MustGet()
|
||||
if !s.Apn.IsUnset() {
|
||||
t.Apn = s.Apn.MustGetNull()
|
||||
}
|
||||
if s.Description.IsValue() {
|
||||
t.Description = s.Description.MustGet()
|
||||
if !s.Description.IsUnset() {
|
||||
t.Description = s.Description.MustGetNull()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
|
|
@ -114,14 +129,14 @@ func (s *ParcelSetter) 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, 4)
|
||||
if s.Apn.IsValue() {
|
||||
vals[0] = psql.Arg(s.Apn.MustGet())
|
||||
if !s.Apn.IsUnset() {
|
||||
vals[0] = psql.Arg(s.Apn.MustGetNull())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Description.IsValue() {
|
||||
vals[1] = psql.Arg(s.Description.MustGet())
|
||||
if !s.Description.IsUnset() {
|
||||
vals[1] = psql.Arg(s.Description.MustGetNull())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
|
@ -149,14 +164,14 @@ func (s ParcelSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
func (s ParcelSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 4)
|
||||
|
||||
if s.Apn.IsValue() {
|
||||
if !s.Apn.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "apn")...),
|
||||
psql.Arg(s.Apn),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Description.IsValue() {
|
||||
if !s.Description.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "description")...),
|
||||
psql.Arg(s.Description),
|
||||
|
|
@ -238,6 +253,7 @@ func (o *Parcel) Update(ctx context.Context, exec bob.Executor, s *ParcelSetter)
|
|||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
|
|
@ -257,7 +273,7 @@ func (o *Parcel) Reload(ctx context.Context, exec bob.Executor) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
|
|
@ -304,7 +320,7 @@ func (o ParcelSlice) copyMatchingRows(from ...*Parcel) {
|
|||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
|
|
@ -402,9 +418,101 @@ func (o ParcelSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Sites starts a query for related objects on site
|
||||
func (o *Parcel) Sites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.ParcelID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ParcelSlice) Sites(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.ParcelID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func insertParcelSites0(ctx context.Context, exec bob.Executor, sites1 []*SiteSetter, parcel0 *Parcel) (SiteSlice, error) {
|
||||
for i := range sites1 {
|
||||
sites1[i].ParcelID = omit.From(parcel0.ID)
|
||||
}
|
||||
|
||||
ret, err := Sites.Insert(bob.ToMods(sites1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertParcelSites0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachParcelSites0(ctx context.Context, exec bob.Executor, count int, sites1 SiteSlice, parcel0 *Parcel) (SiteSlice, error) {
|
||||
setter := &SiteSetter{
|
||||
ParcelID: omit.From(parcel0.ID),
|
||||
}
|
||||
|
||||
err := sites1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachParcelSites0: %w", err)
|
||||
}
|
||||
|
||||
return sites1, nil
|
||||
}
|
||||
|
||||
func (parcel0 *Parcel) InsertSites(ctx context.Context, exec bob.Executor, related ...*SiteSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
sites1, err := insertParcelSites0(ctx, exec, related, parcel0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parcel0.R.Sites = append(parcel0.R.Sites, sites1...)
|
||||
|
||||
for _, rel := range sites1 {
|
||||
rel.R.Parcel = parcel0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (parcel0 *Parcel) AttachSites(ctx context.Context, exec bob.Executor, related ...*Site) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
sites1 := SiteSlice(related)
|
||||
|
||||
_, err = attachParcelSites0(ctx, exec, len(related), sites1, parcel0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parcel0.R.Sites = append(parcel0.R.Sites, sites1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Parcel = parcel0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type parcelWhere[Q psql.Filterable] struct {
|
||||
Apn psql.WhereMod[Q, string]
|
||||
Description psql.WhereMod[Q, string]
|
||||
Apn psql.WhereNullMod[Q, string]
|
||||
Description psql.WhereNullMod[Q, string]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Geometry psql.WhereMod[Q, string]
|
||||
}
|
||||
|
|
@ -415,9 +523,242 @@ func (parcelWhere[Q]) AliasedAs(alias string) parcelWhere[Q] {
|
|||
|
||||
func buildParcelWhere[Q psql.Filterable](cols parcelColumns) parcelWhere[Q] {
|
||||
return parcelWhere[Q]{
|
||||
Apn: psql.Where[Q, string](cols.Apn),
|
||||
Description: psql.Where[Q, string](cols.Description),
|
||||
Apn: psql.WhereNull[Q, string](cols.Apn),
|
||||
Description: psql.WhereNull[Q, string](cols.Description),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Geometry: psql.Where[Q, string](cols.Geometry),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Parcel) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Sites":
|
||||
rels, ok := retrieved.(SiteSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("parcel cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Sites = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.Parcel = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("parcel has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type parcelPreloader struct{}
|
||||
|
||||
func buildParcelPreloader() parcelPreloader {
|
||||
return parcelPreloader{}
|
||||
}
|
||||
|
||||
type parcelThenLoader[Q orm.Loadable] struct {
|
||||
Sites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildParcelThenLoader[Q orm.Loadable]() parcelThenLoader[Q] {
|
||||
type SitesLoadInterface interface {
|
||||
LoadSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return parcelThenLoader[Q]{
|
||||
Sites: thenLoadBuilder[Q](
|
||||
"Sites",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SitesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadSites(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadSites loads the parcel's Sites into the .R struct
|
||||
func (o *Parcel) LoadSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Sites = nil
|
||||
|
||||
related, err := o.Sites(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.Parcel = o
|
||||
}
|
||||
|
||||
o.R.Sites = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSites loads the parcel's Sites into the .R struct
|
||||
func (os ParcelSlice) LoadSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sites, err := os.Sites(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.Sites = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range sites {
|
||||
|
||||
if !(o.ID == rel.ParcelID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Parcel = o
|
||||
|
||||
o.R.Sites = append(o.R.Sites, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parcelC is where relationship counts are stored.
|
||||
type parcelC struct {
|
||||
Sites *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *Parcel) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Sites":
|
||||
o.C.Sites = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type parcelCountPreloader struct {
|
||||
Sites func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildParcelCountPreloader() parcelCountPreloader {
|
||||
return parcelCountPreloader{
|
||||
Sites: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*Parcel]("Sites", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = Parcels.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Sites.Name()),
|
||||
sm.Where(psql.Quote(Sites.Alias(), "parcel_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type parcelCountThenLoader[Q orm.Loadable] struct {
|
||||
Sites func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildParcelCountThenLoader[Q orm.Loadable]() parcelCountThenLoader[Q] {
|
||||
type SitesCountInterface interface {
|
||||
LoadCountSites(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return parcelCountThenLoader[Q]{
|
||||
Sites: countThenLoadBuilder[Q](
|
||||
"Sites",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SitesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountSites(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountSites loads the count of Sites into the C struct
|
||||
func (o *Parcel) LoadCountSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.Sites(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.Sites = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountSites loads the count of Sites for a slice
|
||||
func (os ParcelSlice) LoadCountSites(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if err := o.LoadCountSites(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type parcelJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Sites modAs[Q, siteColumns]
|
||||
}
|
||||
|
||||
func (j parcelJoins[Q]) aliasedAs(alias string) parcelJoins[Q] {
|
||||
return buildParcelJoins[Q](buildParcelColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildParcelJoins[Q dialect.Joinable](cols parcelColumns, typ string) parcelJoins[Q] {
|
||||
return parcelJoins[Q]{
|
||||
typ: typ,
|
||||
Sites: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
|
||||
to.ParcelID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,18 +20,17 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
)
|
||||
|
||||
// Pool is an object representing the database table.
|
||||
type Pool struct {
|
||||
Condition enums.Poolconditiontype `db:"condition" `
|
||||
Created time.Time `db:"created" `
|
||||
CreatorID int32 `db:"creator_id" `
|
||||
ID int32 `db:"id,pk" `
|
||||
SiteID null.Val[int32] `db:"site_id" `
|
||||
Condition enums.Poolconditiontype `db:"condition" `
|
||||
Created time.Time `db:"created" `
|
||||
CreatorID int32 `db:"creator_id" `
|
||||
ID int32 `db:"id,pk" `
|
||||
SiteID int32 `db:"site_id" `
|
||||
SiteVersion int32 `db:"site_version" `
|
||||
|
||||
R poolR `db:"-" `
|
||||
}
|
||||
|
|
@ -49,30 +48,33 @@ type PoolsQuery = *psql.ViewQuery[*Pool, PoolSlice]
|
|||
// poolR is where relationships are stored.
|
||||
type poolR struct {
|
||||
CreatorUser *User // pool.pool_creator_id_fkey
|
||||
Site *Site // pool.pool_site_id_site_version_fkey
|
||||
}
|
||||
|
||||
func buildPoolColumns(alias string) poolColumns {
|
||||
return poolColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"condition", "created", "creator_id", "id", "site_id",
|
||||
"condition", "created", "creator_id", "id", "site_id", "site_version",
|
||||
).WithParent("pool"),
|
||||
tableAlias: alias,
|
||||
Condition: psql.Quote(alias, "condition"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
CreatorID: psql.Quote(alias, "creator_id"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
tableAlias: alias,
|
||||
Condition: psql.Quote(alias, "condition"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
CreatorID: psql.Quote(alias, "creator_id"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
SiteVersion: psql.Quote(alias, "site_version"),
|
||||
}
|
||||
}
|
||||
|
||||
type poolColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
Condition psql.Expression
|
||||
Created psql.Expression
|
||||
CreatorID psql.Expression
|
||||
ID psql.Expression
|
||||
SiteID psql.Expression
|
||||
tableAlias string
|
||||
Condition psql.Expression
|
||||
Created psql.Expression
|
||||
CreatorID psql.Expression
|
||||
ID psql.Expression
|
||||
SiteID psql.Expression
|
||||
SiteVersion psql.Expression
|
||||
}
|
||||
|
||||
func (c poolColumns) Alias() string {
|
||||
|
|
@ -87,15 +89,16 @@ func (poolColumns) AliasedAs(alias string) poolColumns {
|
|||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PoolSetter struct {
|
||||
Condition omit.Val[enums.Poolconditiontype] `db:"condition" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
CreatorID omit.Val[int32] `db:"creator_id" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
SiteID omitnull.Val[int32] `db:"site_id" `
|
||||
Condition omit.Val[enums.Poolconditiontype] `db:"condition" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
CreatorID omit.Val[int32] `db:"creator_id" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
SiteID omit.Val[int32] `db:"site_id" `
|
||||
SiteVersion omit.Val[int32] `db:"site_version" `
|
||||
}
|
||||
|
||||
func (s PoolSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
vals := make([]string, 0, 6)
|
||||
if s.Condition.IsValue() {
|
||||
vals = append(vals, "condition")
|
||||
}
|
||||
|
|
@ -108,9 +111,12 @@ func (s PoolSetter) SetColumns() []string {
|
|||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if !s.SiteID.IsUnset() {
|
||||
if s.SiteID.IsValue() {
|
||||
vals = append(vals, "site_id")
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals = append(vals, "site_version")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -127,8 +133,11 @@ func (s PoolSetter) Overwrite(t *Pool) {
|
|||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if !s.SiteID.IsUnset() {
|
||||
t.SiteID = s.SiteID.MustGetNull()
|
||||
if s.SiteID.IsValue() {
|
||||
t.SiteID = s.SiteID.MustGet()
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
t.SiteVersion = s.SiteVersion.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +147,7 @@ func (s *PoolSetter) 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, 6)
|
||||
if s.Condition.IsValue() {
|
||||
vals[0] = psql.Arg(s.Condition.MustGet())
|
||||
} else {
|
||||
|
|
@ -163,12 +172,18 @@ func (s *PoolSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.SiteID.IsUnset() {
|
||||
vals[4] = psql.Arg(s.SiteID.MustGetNull())
|
||||
if s.SiteID.IsValue() {
|
||||
vals[4] = psql.Arg(s.SiteID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals[5] = psql.Arg(s.SiteVersion.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -178,7 +193,7 @@ func (s PoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PoolSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
exprs := make([]bob.Expression, 0, 6)
|
||||
|
||||
if s.Condition.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -208,13 +223,20 @@ func (s PoolSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.SiteID.IsUnset() {
|
||||
if s.SiteID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_id")...),
|
||||
psql.Arg(s.SiteID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_version")...),
|
||||
psql.Arg(s.SiteVersion),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -465,6 +487,34 @@ func (os PoolSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuer
|
|||
)...)
|
||||
}
|
||||
|
||||
// Site starts a query for related objects on site
|
||||
func (o *Pool) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PoolSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkSiteID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkSiteVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkSiteID = append(pkSiteID, o.SiteID)
|
||||
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPoolCreatorUser0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, user1 *User) (*Pool, error) {
|
||||
setter := &PoolSetter{
|
||||
CreatorID: omit.From(user1.ID),
|
||||
|
|
@ -513,12 +563,62 @@ func (pool0 *Pool) AttachCreatorUser(ctx context.Context, exec bob.Executor, use
|
|||
return nil
|
||||
}
|
||||
|
||||
func attachPoolSite0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, site1 *Site) (*Pool, error) {
|
||||
setter := &PoolSetter{
|
||||
SiteID: omit.From(site1.ID),
|
||||
SiteVersion: omit.From(site1.Version),
|
||||
}
|
||||
|
||||
err := pool0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPoolSite0: %w", err)
|
||||
}
|
||||
|
||||
return pool0, nil
|
||||
}
|
||||
|
||||
func (pool0 *Pool) InsertSite(ctx context.Context, exec bob.Executor, related *SiteSetter) error {
|
||||
var err error
|
||||
|
||||
site1, err := Sites.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPoolSite0(ctx, exec, 1, pool0, site1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pool0.R.Site = site1
|
||||
|
||||
site1.R.Pools = append(site1.R.Pools, pool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pool0 *Pool) AttachSite(ctx context.Context, exec bob.Executor, site1 *Site) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPoolSite0(ctx, exec, 1, pool0, site1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pool0.R.Site = site1
|
||||
|
||||
site1.R.Pools = append(site1.R.Pools, pool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type poolWhere[Q psql.Filterable] struct {
|
||||
Condition psql.WhereMod[Q, enums.Poolconditiontype]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
CreatorID psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
SiteID psql.WhereNullMod[Q, int32]
|
||||
Condition psql.WhereMod[Q, enums.Poolconditiontype]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
CreatorID psql.WhereMod[Q, int32]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
SiteID psql.WhereMod[Q, int32]
|
||||
SiteVersion psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (poolWhere[Q]) AliasedAs(alias string) poolWhere[Q] {
|
||||
|
|
@ -527,11 +627,12 @@ func (poolWhere[Q]) AliasedAs(alias string) poolWhere[Q] {
|
|||
|
||||
func buildPoolWhere[Q psql.Filterable](cols poolColumns) poolWhere[Q] {
|
||||
return poolWhere[Q]{
|
||||
Condition: psql.Where[Q, enums.Poolconditiontype](cols.Condition),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
CreatorID: psql.Where[Q, int32](cols.CreatorID),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
SiteID: psql.WhereNull[Q, int32](cols.SiteID),
|
||||
Condition: psql.Where[Q, enums.Poolconditiontype](cols.Condition),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
CreatorID: psql.Where[Q, int32](cols.CreatorID),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
SiteID: psql.Where[Q, int32](cols.SiteID),
|
||||
SiteVersion: psql.Where[Q, int32](cols.SiteVersion),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -553,6 +654,18 @@ func (o *Pool) Preload(name string, retrieved any) error {
|
|||
rel.R.CreatorPools = PoolSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Site":
|
||||
rel, ok := retrieved.(*Site)
|
||||
if !ok {
|
||||
return fmt.Errorf("pool cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Site = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Pools = PoolSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("pool has no relationship %q", name)
|
||||
}
|
||||
|
|
@ -560,6 +673,7 @@ func (o *Pool) Preload(name string, retrieved any) error {
|
|||
|
||||
type poolPreloader struct {
|
||||
CreatorUser func(...psql.PreloadOption) psql.Preloader
|
||||
Site func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPoolPreloader() poolPreloader {
|
||||
|
|
@ -577,17 +691,34 @@ func buildPoolPreloader() poolPreloader {
|
|||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
Site: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Site, SiteSlice](psql.PreloadRel{
|
||||
Name: "Site",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: Pools,
|
||||
To: Sites,
|
||||
FromColumns: []string{"site_id", "site_version"},
|
||||
ToColumns: []string{"id", "version"},
|
||||
},
|
||||
},
|
||||
}, Sites.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type poolThenLoader[Q orm.Loadable] struct {
|
||||
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Site func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPoolThenLoader[Q orm.Loadable]() poolThenLoader[Q] {
|
||||
type CreatorUserLoadInterface interface {
|
||||
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type SiteLoadInterface interface {
|
||||
LoadSite(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return poolThenLoader[Q]{
|
||||
CreatorUser: thenLoadBuilder[Q](
|
||||
|
|
@ -596,6 +727,12 @@ func buildPoolThenLoader[Q orm.Loadable]() poolThenLoader[Q] {
|
|||
return retrieved.LoadCreatorUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Site: thenLoadBuilder[Q](
|
||||
"Site",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved SiteLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadSite(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -651,9 +788,66 @@ func (os PoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadSite loads the pool's Site into the .R struct
|
||||
func (o *Pool) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Site = nil
|
||||
|
||||
related, err := o.Site(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.Pools = PoolSlice{o}
|
||||
|
||||
o.R.Site = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadSite loads the pool's Site into the .R struct
|
||||
func (os PoolSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sites, err := os.Site(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range sites {
|
||||
|
||||
if !(o.SiteID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.SiteVersion == rel.Version) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Pools = append(rel.R.Pools, o)
|
||||
|
||||
o.R.Site = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type poolJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
CreatorUser modAs[Q, userColumns]
|
||||
Site modAs[Q, siteColumns]
|
||||
}
|
||||
|
||||
func (j poolJoins[Q]) aliasedAs(alias string) poolJoins[Q] {
|
||||
|
|
@ -674,6 +868,20 @@ func buildPoolJoins[Q dialect.Joinable](cols poolColumns, typ string) poolJoins[
|
|||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Site: modAs[Q, siteColumns]{
|
||||
c: Sites.Columns,
|
||||
f: func(to siteColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Sites.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.SiteID), to.Version.EQ(cols.SiteVersion),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
|
|
|
|||
1295
db/models/resident.bob.go
Normal file
1295
db/models/resident.bob.go
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue