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"
|
||||
"github.com/aarondl/opt/null"
|
||||
|
|
@ -35,8 +34,6 @@ type ArcgisAccount struct {
|
|||
URLTiles null.Val[string] `db:"url_tiles" `
|
||||
|
||||
R arcgisAccountR `db:"-" `
|
||||
|
||||
C arcgisAccountC `db:"-" `
|
||||
}
|
||||
|
||||
// ArcgisAccountSlice is an alias for a slice of pointers to ArcgisAccount.
|
||||
|
|
@ -1446,368 +1443,3 @@ func (os ArcgisAccountSlice) LoadArcgisAccountOrganizations(ctx context.Context,
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// arcgisAccountC is where relationship counts are stored.
|
||||
type arcgisAccountC struct {
|
||||
ArcgisAccountOauthTokens *int64
|
||||
ServiceFeatures *int64
|
||||
ServiceMaps *int64
|
||||
ArcgisAccountOrganizations *int64
|
||||
}
|
||||
|
||||
// PreloadCount sets a count in the C struct by name
|
||||
func (o *ArcgisAccount) PreloadCount(name string, count int64) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "ArcgisAccountOauthTokens":
|
||||
o.C.ArcgisAccountOauthTokens = &count
|
||||
case "ServiceFeatures":
|
||||
o.C.ServiceFeatures = &count
|
||||
case "ServiceMaps":
|
||||
o.C.ServiceMaps = &count
|
||||
case "ArcgisAccountOrganizations":
|
||||
o.C.ArcgisAccountOrganizations = &count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisAccountCountPreloader struct {
|
||||
ArcgisAccountOauthTokens func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
ServiceFeatures func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
ServiceMaps func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
ArcgisAccountOrganizations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
||||
}
|
||||
|
||||
func buildArcgisAccountCountPreloader() arcgisAccountCountPreloader {
|
||||
return arcgisAccountCountPreloader{
|
||||
ArcgisAccountOauthTokens: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisAccount]("ArcgisAccountOauthTokens", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisAccounts.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisOauthTokens.Name()),
|
||||
sm.Where(psql.Quote(ArcgisOauthTokens.Alias(), "arcgis_account_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
ServiceFeatures: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisAccount]("ServiceFeatures", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisAccounts.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisServiceFeatures.Name()),
|
||||
sm.Where(psql.Quote(ArcgisServiceFeatures.Alias(), "account_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
ServiceMaps: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisAccount]("ServiceMaps", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisAccounts.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(ArcgisServiceMaps.Name()),
|
||||
sm.Where(psql.Quote(ArcgisServiceMaps.Alias(), "account_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
ArcgisAccountOrganizations: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
||||
return countPreloader[*ArcgisAccount]("ArcgisAccountOrganizations", func(parent string) bob.Expression {
|
||||
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
||||
if parent == "" {
|
||||
parent = ArcgisAccounts.Alias()
|
||||
}
|
||||
|
||||
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
||||
sm.Columns(psql.Raw("count(*)")),
|
||||
|
||||
sm.From(Organizations.Name()),
|
||||
sm.Where(psql.Quote(Organizations.Alias(), "arcgis_account_id").EQ(psql.Quote(parent, "id"))),
|
||||
}
|
||||
subqueryMods = append(subqueryMods, mods...)
|
||||
return psql.Group(psql.Select(subqueryMods...).Expression)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type arcgisAccountCountThenLoader[Q orm.Loadable] struct {
|
||||
ArcgisAccountOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ServiceFeatures func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ServiceMaps func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ArcgisAccountOrganizations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildArcgisAccountCountThenLoader[Q orm.Loadable]() arcgisAccountCountThenLoader[Q] {
|
||||
type ArcgisAccountOauthTokensCountInterface interface {
|
||||
LoadCountArcgisAccountOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ServiceFeaturesCountInterface interface {
|
||||
LoadCountServiceFeatures(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ServiceMapsCountInterface interface {
|
||||
LoadCountServiceMaps(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ArcgisAccountOrganizationsCountInterface interface {
|
||||
LoadCountArcgisAccountOrganizations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return arcgisAccountCountThenLoader[Q]{
|
||||
ArcgisAccountOauthTokens: countThenLoadBuilder[Q](
|
||||
"ArcgisAccountOauthTokens",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ArcgisAccountOauthTokensCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountArcgisAccountOauthTokens(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ServiceFeatures: countThenLoadBuilder[Q](
|
||||
"ServiceFeatures",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ServiceFeaturesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountServiceFeatures(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ServiceMaps: countThenLoadBuilder[Q](
|
||||
"ServiceMaps",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ServiceMapsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountServiceMaps(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ArcgisAccountOrganizations: countThenLoadBuilder[Q](
|
||||
"ArcgisAccountOrganizations",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ArcgisAccountOrganizationsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadCountArcgisAccountOrganizations(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadCountArcgisAccountOauthTokens loads the count of ArcgisAccountOauthTokens into the C struct
|
||||
func (o *ArcgisAccount) LoadCountArcgisAccountOauthTokens(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.ArcgisAccountOauthTokens(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.ArcgisAccountOauthTokens = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountArcgisAccountOauthTokens loads the count of ArcgisAccountOauthTokens for a slice
|
||||
func (os ArcgisAccountSlice) LoadCountArcgisAccountOauthTokens(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.LoadCountArcgisAccountOauthTokens(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountServiceFeatures loads the count of ServiceFeatures into the C struct
|
||||
func (o *ArcgisAccount) LoadCountServiceFeatures(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.ServiceFeatures(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.ServiceFeatures = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountServiceFeatures loads the count of ServiceFeatures for a slice
|
||||
func (os ArcgisAccountSlice) LoadCountServiceFeatures(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.LoadCountServiceFeatures(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountServiceMaps loads the count of ServiceMaps into the C struct
|
||||
func (o *ArcgisAccount) LoadCountServiceMaps(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.ServiceMaps(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.ServiceMaps = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountServiceMaps loads the count of ServiceMaps for a slice
|
||||
func (os ArcgisAccountSlice) LoadCountServiceMaps(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.LoadCountServiceMaps(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountArcgisAccountOrganizations loads the count of ArcgisAccountOrganizations into the C struct
|
||||
func (o *ArcgisAccount) LoadCountArcgisAccountOrganizations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
count, err := o.ArcgisAccountOrganizations(mods...).Count(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.C.ArcgisAccountOrganizations = &count
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCountArcgisAccountOrganizations loads the count of ArcgisAccountOrganizations for a slice
|
||||
func (os ArcgisAccountSlice) LoadCountArcgisAccountOrganizations(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.LoadCountArcgisAccountOrganizations(ctx, exec, mods...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type arcgisAccountJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Organization modAs[Q, organizationColumns]
|
||||
ArcgisAccountOauthTokens modAs[Q, arcgisOauthTokenColumns]
|
||||
ServiceFeatures modAs[Q, arcgisServiceFeatureColumns]
|
||||
ServiceMaps modAs[Q, arcgisServiceMapColumns]
|
||||
ArcgisAccountOrganizations modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
func (j arcgisAccountJoins[Q]) aliasedAs(alias string) arcgisAccountJoins[Q] {
|
||||
return buildArcgisAccountJoins[Q](buildArcgisAccountColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildArcgisAccountJoins[Q dialect.Joinable](cols arcgisAccountColumns, typ string) arcgisAccountJoins[Q] {
|
||||
return arcgisAccountJoins[Q]{
|
||||
typ: typ,
|
||||
Organization: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
|
||||
to.ID.EQ(cols.OrganizationID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
ArcgisAccountOauthTokens: modAs[Q, arcgisOauthTokenColumns]{
|
||||
c: ArcgisOauthTokens.Columns,
|
||||
f: func(to arcgisOauthTokenColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisOauthTokens.Name().As(to.Alias())).On(
|
||||
to.ArcgisAccountID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
ServiceFeatures: 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, ArcgisServiceFeatures.Name().As(to.Alias())).On(
|
||||
to.AccountID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
ServiceMaps: modAs[Q, arcgisServiceMapColumns]{
|
||||
c: ArcgisServiceMaps.Columns,
|
||||
f: func(to arcgisServiceMapColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, ArcgisServiceMaps.Name().As(to.Alias())).On(
|
||||
to.AccountID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
ArcgisAccountOrganizations: modAs[Q, organizationColumns]{
|
||||
c: Organizations.Columns,
|
||||
f: func(to organizationColumns) bob.Mod[Q] {
|
||||
mods := make(mods.QueryMods[Q], 0, 1)
|
||||
|
||||
{
|
||||
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
|
||||
to.ArcgisAccountID.EQ(cols.ID),
|
||||
))
|
||||
}
|
||||
|
||||
return mods
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue