Remove a bunch of generated bob, add feature and review tasks
This commit is contained in:
parent
662188485e
commit
527e82031e
206 changed files with 5761 additions and 141269 deletions
|
|
@ -15,7 +15,6 @@ 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"
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
|
|
@ -30,8 +29,6 @@ type ArcgisLayerField struct {
|
|||
Type enums.ArcgisFieldtype `db:"type_" `
|
||||
|
||||
R arcgisLayerFieldR `db:"-" `
|
||||
|
||||
C arcgisLayerFieldC `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisLayerFieldSlice is an alias for a slice of pointers to ArcgisLayerField.
|
||||
|
|
@ -1047,220 +1044,3 @@ func (os ArcgisLayerFieldSlice) LoadParcelMappings(ctx context.Context, exec bob
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// arcgisLayerFieldC is where relationship counts are stored.
|
||||
type arcgisLayerFieldC struct {
|
||||
AddressMappings *int64
|
||||
ParcelMappings *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *ArcgisLayerField) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "AddressMappings":
|
||||
o.C.AddressMappings = &count
|
||||
case "ParcelMappings":
|
||||
o.C.ParcelMappings = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisLayerFieldCountPreloader struct {
|
||||
AddressMappings func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
ParcelMappings func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisLayerFieldCountPreloader() arcgisLayerFieldCountPreloader {
|
||||
return arcgisLayerFieldCountPreloader{
|
||||
AddressMappings: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisLayerField]("AddressMappings", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisLayerFields.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisAddressMappings.Name()),
|
||||
sm.Where(psql.Quote(ArcgisAddressMappings.Alias(), "layer_feature_service_item_id").EQ(psql.Quote(parent, "layer_feature_service_item_id"))),
|
||||
sm.Where(psql.Quote(ArcgisAddressMappings.Alias(), "layer_index").EQ(psql.Quote(parent, "layer_index"))),
|
||||
sm.Where(psql.Quote(ArcgisAddressMappings.Alias(), "layer_field_name").EQ(psql.Quote(parent, "name"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
ParcelMappings: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisLayerField]("ParcelMappings", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisLayerFields.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisParcelMappings.Name()),
|
||||
sm.Where(psql.Quote(ArcgisParcelMappings.Alias(), "layer_feature_service_item_id").EQ(psql.Quote(parent, "layer_feature_service_item_id"))),
|
||||
sm.Where(psql.Quote(ArcgisParcelMappings.Alias(), "layer_index").EQ(psql.Quote(parent, "layer_index"))),
|
||||
sm.Where(psql.Quote(ArcgisParcelMappings.Alias(), "layer_field_name").EQ(psql.Quote(parent, "name"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisLayerFieldCountThenLoader[Q orm.Loadable] struct {
|
||||
AddressMappings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ParcelMappings func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisLayerFieldCountThenLoader[Q orm.Loadable]() arcgisLayerFieldCountThenLoader[Q] {
|
||||
type AddressMappingsCountInterface interface {
|
||||
LoadCountAddressMappings(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ParcelMappingsCountInterface interface {
|
||||
LoadCountParcelMappings(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisLayerFieldCountThenLoader[Q]{
|
||||
AddressMappings: countThenLoadBuilder[Q](
|
||||
"AddressMappings",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved AddressMappingsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountAddressMappings(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ParcelMappings: countThenLoadBuilder[Q](
|
||||
"ParcelMappings",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ParcelMappingsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountParcelMappings(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountAddressMappings loads the count of AddressMappings into the C struct
|
||||
func (o *ArcgisLayerField) LoadCountAddressMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.AddressMappings(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.AddressMappings = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountAddressMappings loads the count of AddressMappings for a slice
|
||||
func (os ArcgisLayerFieldSlice) LoadCountAddressMappings(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.LoadCountAddressMappings(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountParcelMappings loads the count of ParcelMappings into the C struct
|
||||
func (o *ArcgisLayerField) LoadCountParcelMappings(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.ParcelMappings(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.ParcelMappings = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountParcelMappings loads the count of ParcelMappings for a slice
|
||||
func (os ArcgisLayerFieldSlice) LoadCountParcelMappings(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.LoadCountParcelMappings(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisLayerFieldJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
AddressMappings modAs[Q, arcgisAddressMappingColumns]
|
||||
Layer modAs[Q, arcgisLayerColumns]
|
||||
ParcelMappings modAs[Q, arcgisParcelMappingColumns]
|
||||
}
|
||||
|
||||
func (j arcgisLayerFieldJoins[Q]) aliasedAs(alias string) arcgisLayerFieldJoins[Q] {
|
||||
return buildArcgisLayerFieldJoins[Q](buildArcgisLayerFieldColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisLayerFieldJoins[Q dialect.Joinable](cols arcgisLayerFieldColumns, typ string) arcgisLayerFieldJoins[Q] {
|
||||
return arcgisLayerFieldJoins[Q]{
|
||||
typ: typ,
|
||||
AddressMappings: modAs[Q, arcgisAddressMappingColumns]{
|
||||
c: ArcgisAddressMappings.Columns,
|
||||
f: func(to arcgisAddressMappingColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisAddressMappings.Name().As(to.Alias())).On(
|
||||
to.LayerFeatureServiceItemID.EQ(cols.LayerFeatureServiceItemID), to.LayerIndex.EQ(cols.LayerIndex), to.LayerFieldName.EQ(cols.Name),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
Layer: modAs[Q, arcgisLayerColumns]{
|
||||
c: ArcgisLayers.Columns,
|
||||
f: func(to arcgisLayerColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisLayers.Name().As(to.Alias())).On(
|
||||
to.FeatureServiceItemID.EQ(cols.LayerFeatureServiceItemID), to.Index.EQ(cols.LayerIndex),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
ParcelMappings: modAs[Q, arcgisParcelMappingColumns]{
|
||||
c: ArcgisParcelMappings.Columns,
|
||||
f: func(to arcgisParcelMappingColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisParcelMappings.Name().As(to.Alias())).On(
|
||||
to.LayerFeatureServiceItemID.EQ(cols.LayerFeatureServiceItemID), to.LayerIndex.EQ(cols.LayerIndex), to.LayerFieldName.EQ(cols.Name),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue