Bunch of work around assigning reports to districts
I added some DB schema to track logos and to relate reports to organizations. I reworked how GPS data comes from EXIF data on images because it wasn't working for JPEGs. I might have broken PNGs in the process. Also made the config options for domain names more standardized.
This commit is contained in:
parent
486a2d98c2
commit
61d8d14fc2
41 changed files with 3029 additions and 337 deletions
|
|
@ -79,6 +79,7 @@ type joins[Q dialect.Joinable] struct {
|
|||
Organizations joinSet[organizationJoins[Q]]
|
||||
PublicreportImages joinSet[publicreportImageJoins[Q]]
|
||||
PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]]
|
||||
PublicreportNuisances joinSet[publicreportNuisanceJoins[Q]]
|
||||
PublicreportPools joinSet[publicreportPoolJoins[Q]]
|
||||
PublicreportPoolImages joinSet[publicreportPoolImageJoins[Q]]
|
||||
PublicreportQuicks joinSet[publicreportQuickJoins[Q]]
|
||||
|
|
@ -143,6 +144,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] {
|
|||
Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins),
|
||||
PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins),
|
||||
PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins),
|
||||
PublicreportNuisances: buildJoinSet[publicreportNuisanceJoins[Q]](PublicreportNuisances.Columns, buildPublicreportNuisanceJoins),
|
||||
PublicreportPools: buildJoinSet[publicreportPoolJoins[Q]](PublicreportPools.Columns, buildPublicreportPoolJoins),
|
||||
PublicreportPoolImages: buildJoinSet[publicreportPoolImageJoins[Q]](PublicreportPoolImages.Columns, buildPublicreportPoolImageJoins),
|
||||
PublicreportQuicks: buildJoinSet[publicreportQuickJoins[Q]](PublicreportQuicks.Columns, buildPublicreportQuickJoins),
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ type preloaders struct {
|
|||
Organization organizationPreloader
|
||||
PublicreportImage publicreportImagePreloader
|
||||
PublicreportImageExif publicreportImageExifPreloader
|
||||
PublicreportNuisance publicreportNuisancePreloader
|
||||
PublicreportPool publicreportPoolPreloader
|
||||
PublicreportPoolImage publicreportPoolImagePreloader
|
||||
PublicreportQuick publicreportQuickPreloader
|
||||
|
|
@ -120,6 +121,7 @@ func getPreloaders() preloaders {
|
|||
Organization: buildOrganizationPreloader(),
|
||||
PublicreportImage: buildPublicreportImagePreloader(),
|
||||
PublicreportImageExif: buildPublicreportImageExifPreloader(),
|
||||
PublicreportNuisance: buildPublicreportNuisancePreloader(),
|
||||
PublicreportPool: buildPublicreportPoolPreloader(),
|
||||
PublicreportPoolImage: buildPublicreportPoolImagePreloader(),
|
||||
PublicreportQuick: buildPublicreportQuickPreloader(),
|
||||
|
|
@ -182,6 +184,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
Organization organizationThenLoader[Q]
|
||||
PublicreportImage publicreportImageThenLoader[Q]
|
||||
PublicreportImageExif publicreportImageExifThenLoader[Q]
|
||||
PublicreportNuisance publicreportNuisanceThenLoader[Q]
|
||||
PublicreportPool publicreportPoolThenLoader[Q]
|
||||
PublicreportPoolImage publicreportPoolImageThenLoader[Q]
|
||||
PublicreportQuick publicreportQuickThenLoader[Q]
|
||||
|
|
@ -238,6 +241,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
Organization: buildOrganizationThenLoader[Q](),
|
||||
PublicreportImage: buildPublicreportImageThenLoader[Q](),
|
||||
PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](),
|
||||
PublicreportNuisance: buildPublicreportNuisanceThenLoader[Q](),
|
||||
PublicreportPool: buildPublicreportPoolThenLoader[Q](),
|
||||
PublicreportPoolImage: buildPublicreportPoolImageThenLoader[Q](),
|
||||
PublicreportQuick: buildPublicreportQuickThenLoader[Q](),
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -5,6 +5,7 @@ package models
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
|
|
@ -19,6 +20,9 @@ import (
|
|||
"github.com/stephenafamo/bob/dialect/psql/sm"
|
||||
"github.com/stephenafamo/bob/dialect/psql/um"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
"github.com/stephenafamo/bob/mods"
|
||||
"github.com/stephenafamo/bob/orm"
|
||||
"github.com/stephenafamo/bob/types/pgtypes"
|
||||
)
|
||||
|
||||
// PublicreportNuisance is an object representing the database table.
|
||||
|
|
@ -50,6 +54,9 @@ type PublicreportNuisance struct {
|
|||
Address string `db:"address" `
|
||||
Location null.Val[string] `db:"location" `
|
||||
Status enums.PublicreportReportstatustype `db:"status" `
|
||||
OrganizationID null.Val[int32] `db:"organization_id" `
|
||||
|
||||
R publicreportNuisanceR `db:"-" `
|
||||
}
|
||||
|
||||
// PublicreportNuisanceSlice is an alias for a slice of pointers to PublicreportNuisance.
|
||||
|
|
@ -62,10 +69,15 @@ var PublicreportNuisances = psql.NewTablex[*PublicreportNuisance, PublicreportNu
|
|||
// PublicreportNuisancesQuery is a query on the nuisance table
|
||||
type PublicreportNuisancesQuery = *psql.ViewQuery[*PublicreportNuisance, PublicreportNuisanceSlice]
|
||||
|
||||
// publicreportNuisanceR is where relationships are stored.
|
||||
type publicreportNuisanceR struct {
|
||||
Organization *Organization // publicreport.nuisance.nuisance_organization_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns {
|
||||
return publicreportNuisanceColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "additional_info", "created", "duration", "email", "inspection_type", "source_location", "preferred_date_range", "preferred_time", "request_call", "severity", "source_container", "source_description", "source_roof", "source_stagnant", "time_of_day_day", "time_of_day_early", "time_of_day_evening", "time_of_day_night", "public_id", "reporter_address", "reporter_email", "reporter_name", "reporter_phone", "address", "location", "status",
|
||||
"id", "additional_info", "created", "duration", "email", "inspection_type", "source_location", "preferred_date_range", "preferred_time", "request_call", "severity", "source_container", "source_description", "source_roof", "source_stagnant", "time_of_day_day", "time_of_day_early", "time_of_day_evening", "time_of_day_night", "public_id", "reporter_address", "reporter_email", "reporter_name", "reporter_phone", "address", "location", "status", "organization_id",
|
||||
).WithParent("publicreport.nuisance"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
|
|
@ -95,6 +107,7 @@ func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns
|
|||
Address: psql.Quote(alias, "address"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
Status: psql.Quote(alias, "status"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +141,7 @@ type publicreportNuisanceColumns struct {
|
|||
Address psql.Expression
|
||||
Location psql.Expression
|
||||
Status psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportNuisanceColumns) Alias() string {
|
||||
|
|
@ -169,10 +183,11 @@ type PublicreportNuisanceSetter struct {
|
|||
Address omit.Val[string] `db:"address" `
|
||||
Location omitnull.Val[string] `db:"location" `
|
||||
Status omit.Val[enums.PublicreportReportstatustype] `db:"status" `
|
||||
OrganizationID omitnull.Val[int32] `db:"organization_id" `
|
||||
}
|
||||
|
||||
func (s PublicreportNuisanceSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 27)
|
||||
vals := make([]string, 0, 28)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
|
|
@ -254,6 +269,9 @@ func (s PublicreportNuisanceSetter) SetColumns() []string {
|
|||
if s.Status.IsValue() {
|
||||
vals = append(vals, "status")
|
||||
}
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -339,6 +357,9 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) {
|
|||
if s.Status.IsValue() {
|
||||
t.Status = s.Status.MustGet()
|
||||
}
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
t.OrganizationID = s.OrganizationID.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -347,7 +368,7 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 27)
|
||||
vals := make([]bob.Expression, 28)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
|
|
@ -510,6 +531,12 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[26] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
vals[27] = psql.Arg(s.OrganizationID.MustGetNull())
|
||||
} else {
|
||||
vals[27] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -519,7 +546,7 @@ func (s PublicreportNuisanceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 27)
|
||||
exprs := make([]bob.Expression, 0, 28)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -710,6 +737,13 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "organization_id")...),
|
||||
psql.Arg(s.OrganizationID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -771,6 +805,7 @@ func (o *PublicreportNuisance) Update(ctx context.Context, exec bob.Executor, s
|
|||
return err
|
||||
}
|
||||
|
||||
o.R = v.R
|
||||
*o = *v
|
||||
|
||||
return nil
|
||||
|
|
@ -790,7 +825,7 @@ func (o *PublicreportNuisance) Reload(ctx context.Context, exec bob.Executor) er
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o2.R = o.R
|
||||
*o = *o2
|
||||
|
||||
return nil
|
||||
|
|
@ -837,7 +872,7 @@ func (o PublicreportNuisanceSlice) copyMatchingRows(from ...*PublicreportNuisanc
|
|||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
}
|
||||
|
|
@ -935,6 +970,78 @@ func (o PublicreportNuisanceSlice) ReloadAll(ctx context.Context, exec bob.Execu
|
|||
return nil
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *PublicreportNuisance) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportNuisanceSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkOrganizationID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportNuisanceOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, organization1 *Organization) (*PublicreportNuisance, error) {
|
||||
setter := &PublicreportNuisanceSetter{
|
||||
OrganizationID: omitnull.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := publicreportNuisance0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportNuisanceOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportNuisance0, nil
|
||||
}
|
||||
|
||||
func (publicreportNuisance0 *PublicreportNuisance) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportNuisanceOrganization0(ctx, exec, 1, publicreportNuisance0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportNuisance0.R.Organization = organization1
|
||||
|
||||
organization1.R.Nuisances = append(organization1.R.Nuisances, publicreportNuisance0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportNuisance0 *PublicreportNuisance) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportNuisanceOrganization0(ctx, exec, 1, publicreportNuisance0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportNuisance0.R.Organization = organization1
|
||||
|
||||
organization1.R.Nuisances = append(organization1.R.Nuisances, publicreportNuisance0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportNuisanceWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
AdditionalInfo psql.WhereMod[Q, string]
|
||||
|
|
@ -963,6 +1070,7 @@ type publicreportNuisanceWhere[Q psql.Filterable] struct {
|
|||
Address psql.WhereMod[Q, string]
|
||||
Location psql.WhereNullMod[Q, string]
|
||||
Status psql.WhereMod[Q, enums.PublicreportReportstatustype]
|
||||
OrganizationID psql.WhereNullMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportNuisanceWhere[Q]) AliasedAs(alias string) publicreportNuisanceWhere[Q] {
|
||||
|
|
@ -998,5 +1106,154 @@ func buildPublicreportNuisanceWhere[Q psql.Filterable](cols publicreportNuisance
|
|||
Address: psql.Where[Q, string](cols.Address),
|
||||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status),
|
||||
OrganizationID: psql.WhereNull[Q, int32](cols.OrganizationID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PublicreportNuisance) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Nuisances = PublicreportNuisanceSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("publicreportNuisance has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportNuisancePreloader struct {
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportNuisancePreloader() publicreportNuisancePreloader {
|
||||
return publicreportNuisancePreloader{
|
||||
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "Organization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportNuisances,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"organization_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportNuisanceThenLoader[Q orm.Loadable] struct {
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportNuisanceThenLoader[Q orm.Loadable]() publicreportNuisanceThenLoader[Q] {
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportNuisanceThenLoader[Q]{
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadOrganization loads the publicreportNuisance's Organization into the .R struct
|
||||
func (o *PublicreportNuisance) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Organization = nil
|
||||
|
||||
related, err := o.Organization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.Nuisances = PublicreportNuisanceSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the publicreportNuisance's Organization into the .R struct
|
||||
func (os PublicreportNuisanceSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.Organization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
if !o.OrganizationID.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.OrganizationID.IsValue() && o.OrganizationID.MustGet() == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Nuisances = append(rel.R.Nuisances, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type publicreportNuisanceJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Organization modAs[Q, organizationColumns]
|
||||
}
|
||||
|
||||
func (j publicreportNuisanceJoins[Q]) aliasedAs(alias string) publicreportNuisanceJoins[Q] {
|
||||
return buildPublicreportNuisanceJoins[Q](buildPublicreportNuisanceColumns(alias), j.typ)
|
||||
}
|
||||
|
||||
func buildPublicreportNuisanceJoins[Q dialect.Joinable](cols publicreportNuisanceColumns, typ string) publicreportNuisanceJoins[Q] {
|
||||
return publicreportNuisanceJoins[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
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ type PublicreportPool struct {
|
|||
ReporterPhone string `db:"reporter_phone" `
|
||||
Subscribe bool `db:"subscribe" `
|
||||
Status enums.PublicreportReportstatustype `db:"status" `
|
||||
OrganizationID null.Val[int32] `db:"organization_id" `
|
||||
|
||||
R publicreportPoolR `db:"-" `
|
||||
|
||||
|
|
@ -77,13 +78,14 @@ type PublicreportPoolsQuery = *psql.ViewQuery[*PublicreportPool, PublicreportPoo
|
|||
|
||||
// publicreportPoolR is where relationships are stored.
|
||||
type publicreportPoolR struct {
|
||||
Images PublicreportImageSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey
|
||||
Organization *Organization // publicreport.pool.pool_organization_id_fkey
|
||||
Images PublicreportImageSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportPoolColumns(alias string) publicreportPoolColumns {
|
||||
return publicreportPoolColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address", "address_country", "address_post_code", "address_place", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "location", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "subscribe", "status",
|
||||
"id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address", "address_country", "address_post_code", "address_place", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "location", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "subscribe", "status", "organization_id",
|
||||
).WithParent("publicreport.pool"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
|
|
@ -116,6 +118,7 @@ func buildPublicreportPoolColumns(alias string) publicreportPoolColumns {
|
|||
ReporterPhone: psql.Quote(alias, "reporter_phone"),
|
||||
Subscribe: psql.Quote(alias, "subscribe"),
|
||||
Status: psql.Quote(alias, "status"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +155,7 @@ type publicreportPoolColumns struct {
|
|||
ReporterPhone psql.Expression
|
||||
Subscribe psql.Expression
|
||||
Status psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportPoolColumns) Alias() string {
|
||||
|
|
@ -196,10 +200,11 @@ type PublicreportPoolSetter struct {
|
|||
ReporterPhone omit.Val[string] `db:"reporter_phone" `
|
||||
Subscribe omit.Val[bool] `db:"subscribe" `
|
||||
Status omit.Val[enums.PublicreportReportstatustype] `db:"status" `
|
||||
OrganizationID omitnull.Val[int32] `db:"organization_id" `
|
||||
}
|
||||
|
||||
func (s PublicreportPoolSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 30)
|
||||
vals := make([]string, 0, 31)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
|
|
@ -290,6 +295,9 @@ func (s PublicreportPoolSetter) SetColumns() []string {
|
|||
if s.Status.IsValue() {
|
||||
vals = append(vals, "status")
|
||||
}
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -384,6 +392,9 @@ func (s PublicreportPoolSetter) Overwrite(t *PublicreportPool) {
|
|||
if s.Status.IsValue() {
|
||||
t.Status = s.Status.MustGet()
|
||||
}
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
t.OrganizationID = s.OrganizationID.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -392,7 +403,7 @@ func (s *PublicreportPoolSetter) 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, 30)
|
||||
vals := make([]bob.Expression, 31)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
|
|
@ -573,6 +584,12 @@ func (s *PublicreportPoolSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[29] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
vals[30] = psql.Arg(s.OrganizationID.MustGetNull())
|
||||
} else {
|
||||
vals[30] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -582,7 +599,7 @@ func (s PublicreportPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 30)
|
||||
exprs := make([]bob.Expression, 0, 31)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -794,6 +811,13 @@ func (s PublicreportPoolSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "organization_id")...),
|
||||
psql.Arg(s.OrganizationID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -1020,6 +1044,30 @@ func (o PublicreportPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor)
|
|||
return nil
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *PublicreportPool) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportPoolSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkOrganizationID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Images starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportPool) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
|
|
@ -1049,6 +1097,54 @@ func (os PublicreportPoolSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) Pu
|
|||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportPoolOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportPool0 *PublicreportPool, organization1 *Organization) (*PublicreportPool, error) {
|
||||
setter := &PublicreportPoolSetter{
|
||||
OrganizationID: omitnull.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := publicreportPool0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportPoolOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportPool0, nil
|
||||
}
|
||||
|
||||
func (publicreportPool0 *PublicreportPool) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportPoolOrganization0(ctx, exec, 1, publicreportPool0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPool0.R.Organization = organization1
|
||||
|
||||
organization1.R.PublicreportPool = append(organization1.R.PublicreportPool, publicreportPool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportPool0 *PublicreportPool) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportPoolOrganization0(ctx, exec, 1, publicreportPool0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportPool0.R.Organization = organization1
|
||||
|
||||
organization1.R.PublicreportPool = append(organization1.R.PublicreportPool, publicreportPool0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportPoolImages0(ctx context.Context, exec bob.Executor, count int, publicreportPool0 *PublicreportPool, publicreportImages2 PublicreportImageSlice) (PublicreportPoolImageSlice, error) {
|
||||
setters := make([]*PublicreportPoolImageSetter, count)
|
||||
for i := range count {
|
||||
|
|
@ -1145,6 +1241,7 @@ type publicreportPoolWhere[Q psql.Filterable] struct {
|
|||
ReporterPhone psql.WhereMod[Q, string]
|
||||
Subscribe psql.WhereMod[Q, bool]
|
||||
Status psql.WhereMod[Q, enums.PublicreportReportstatustype]
|
||||
OrganizationID psql.WhereNullMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportPoolWhere[Q]) AliasedAs(alias string) publicreportPoolWhere[Q] {
|
||||
|
|
@ -1183,6 +1280,7 @@ func buildPublicreportPoolWhere[Q psql.Filterable](cols publicreportPoolColumns)
|
|||
ReporterPhone: psql.Where[Q, string](cols.ReporterPhone),
|
||||
Subscribe: psql.Where[Q, bool](cols.Subscribe),
|
||||
Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status),
|
||||
OrganizationID: psql.WhereNull[Q, int32](cols.OrganizationID),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1192,6 +1290,18 @@ func (o *PublicreportPool) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportPool cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.PublicreportPool = PublicreportPoolSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Images":
|
||||
rels, ok := retrieved.(PublicreportImageSlice)
|
||||
if !ok {
|
||||
|
|
@ -1211,22 +1321,48 @@ func (o *PublicreportPool) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
|
||||
type publicreportPoolPreloader struct{}
|
||||
type publicreportPoolPreloader struct {
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportPoolPreloader() publicreportPoolPreloader {
|
||||
return publicreportPoolPreloader{}
|
||||
return publicreportPoolPreloader{
|
||||
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "Organization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportPools,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"organization_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportPoolThenLoader[Q orm.Loadable] struct {
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoader[Q] {
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ImagesLoadInterface interface {
|
||||
LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportPoolThenLoader[Q]{
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Images: thenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -1236,6 +1372,61 @@ func buildPublicreportPoolThenLoader[Q orm.Loadable]() publicreportPoolThenLoade
|
|||
}
|
||||
}
|
||||
|
||||
// LoadOrganization loads the publicreportPool's Organization into the .R struct
|
||||
func (o *PublicreportPool) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Organization = nil
|
||||
|
||||
related, err := o.Organization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.PublicreportPool = PublicreportPoolSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the publicreportPool's Organization into the .R struct
|
||||
func (os PublicreportPoolSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.Organization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
if !o.OrganizationID.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.OrganizationID.IsValue() && o.OrganizationID.MustGet() == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.PublicreportPool = append(rel.R.PublicreportPool, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImages loads the publicreportPool's Images into the .R struct
|
||||
func (o *PublicreportPool) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -1414,8 +1605,9 @@ func (os PublicreportPoolSlice) LoadCountImages(ctx context.Context, exec bob.Ex
|
|||
}
|
||||
|
||||
type publicreportPoolJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Images modAs[Q, publicreportImageColumns]
|
||||
typ string
|
||||
Organization modAs[Q, organizationColumns]
|
||||
Images modAs[Q, publicreportImageColumns]
|
||||
}
|
||||
|
||||
func (j publicreportPoolJoins[Q]) aliasedAs(alias string) publicreportPoolJoins[Q] {
|
||||
|
|
@ -1425,6 +1617,20 @@ func (j publicreportPoolJoins[Q]) aliasedAs(alias string) publicreportPoolJoins[
|
|||
func buildPublicreportPoolJoins[Q dialect.Joinable](cols publicreportPoolColumns, typ string) publicreportPoolJoins[Q] {
|
||||
return publicreportPoolJoins[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
|
||||
},
|
||||
},
|
||||
Images: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
|
|
@ -29,16 +29,17 @@ import (
|
|||
|
||||
// PublicreportQuick is an object representing the database table.
|
||||
type PublicreportQuick struct {
|
||||
ID int32 `db:"id,pk" `
|
||||
Created time.Time `db:"created" `
|
||||
Comments string `db:"comments" `
|
||||
Location null.Val[string] `db:"location" `
|
||||
H3cell null.Val[string] `db:"h3cell" `
|
||||
PublicID string `db:"public_id" `
|
||||
ReporterEmail string `db:"reporter_email" `
|
||||
ReporterPhone string `db:"reporter_phone" `
|
||||
Address string `db:"address" `
|
||||
Status enums.PublicreportReportstatustype `db:"status" `
|
||||
ID int32 `db:"id,pk" `
|
||||
Created time.Time `db:"created" `
|
||||
Comments string `db:"comments" `
|
||||
Location null.Val[string] `db:"location" `
|
||||
H3cell null.Val[string] `db:"h3cell" `
|
||||
PublicID string `db:"public_id" `
|
||||
ReporterEmail string `db:"reporter_email" `
|
||||
ReporterPhone string `db:"reporter_phone" `
|
||||
Address string `db:"address" `
|
||||
Status enums.PublicreportReportstatustype `db:"status" `
|
||||
OrganizationID null.Val[int32] `db:"organization_id" `
|
||||
|
||||
R publicreportQuickR `db:"-" `
|
||||
|
||||
|
|
@ -57,41 +58,44 @@ type PublicreportQuicksQuery = *psql.ViewQuery[*PublicreportQuick, PublicreportQ
|
|||
|
||||
// publicreportQuickR is where relationships are stored.
|
||||
type publicreportQuickR struct {
|
||||
Images PublicreportImageSlice // publicreport.quick_image.quick_image_image_id_fkeypublicreport.quick_image.quick_image_quick_id_fkey
|
||||
Organization *Organization // publicreport.quick.quick_organization_id_fkey
|
||||
Images PublicreportImageSlice // publicreport.quick_image.quick_image_image_id_fkeypublicreport.quick_image.quick_image_quick_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportQuickColumns(alias string) publicreportQuickColumns {
|
||||
return publicreportQuickColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "created", "comments", "location", "h3cell", "public_id", "reporter_email", "reporter_phone", "address", "status",
|
||||
"id", "created", "comments", "location", "h3cell", "public_id", "reporter_email", "reporter_phone", "address", "status", "organization_id",
|
||||
).WithParent("publicreport.quick"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Comments: psql.Quote(alias, "comments"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
H3cell: psql.Quote(alias, "h3cell"),
|
||||
PublicID: psql.Quote(alias, "public_id"),
|
||||
ReporterEmail: psql.Quote(alias, "reporter_email"),
|
||||
ReporterPhone: psql.Quote(alias, "reporter_phone"),
|
||||
Address: psql.Quote(alias, "address"),
|
||||
Status: psql.Quote(alias, "status"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Comments: psql.Quote(alias, "comments"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
H3cell: psql.Quote(alias, "h3cell"),
|
||||
PublicID: psql.Quote(alias, "public_id"),
|
||||
ReporterEmail: psql.Quote(alias, "reporter_email"),
|
||||
ReporterPhone: psql.Quote(alias, "reporter_phone"),
|
||||
Address: psql.Quote(alias, "address"),
|
||||
Status: psql.Quote(alias, "status"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ID psql.Expression
|
||||
Created psql.Expression
|
||||
Comments psql.Expression
|
||||
Location psql.Expression
|
||||
H3cell psql.Expression
|
||||
PublicID psql.Expression
|
||||
ReporterEmail psql.Expression
|
||||
ReporterPhone psql.Expression
|
||||
Address psql.Expression
|
||||
Status psql.Expression
|
||||
tableAlias string
|
||||
ID psql.Expression
|
||||
Created psql.Expression
|
||||
Comments psql.Expression
|
||||
Location psql.Expression
|
||||
H3cell psql.Expression
|
||||
PublicID psql.Expression
|
||||
ReporterEmail psql.Expression
|
||||
ReporterPhone psql.Expression
|
||||
Address psql.Expression
|
||||
Status psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportQuickColumns) Alias() string {
|
||||
|
|
@ -106,20 +110,21 @@ func (publicreportQuickColumns) AliasedAs(alias string) publicreportQuickColumns
|
|||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type PublicreportQuickSetter struct {
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Comments omit.Val[string] `db:"comments" `
|
||||
Location omitnull.Val[string] `db:"location" `
|
||||
H3cell omitnull.Val[string] `db:"h3cell" `
|
||||
PublicID omit.Val[string] `db:"public_id" `
|
||||
ReporterEmail omit.Val[string] `db:"reporter_email" `
|
||||
ReporterPhone omit.Val[string] `db:"reporter_phone" `
|
||||
Address omit.Val[string] `db:"address" `
|
||||
Status omit.Val[enums.PublicreportReportstatustype] `db:"status" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Comments omit.Val[string] `db:"comments" `
|
||||
Location omitnull.Val[string] `db:"location" `
|
||||
H3cell omitnull.Val[string] `db:"h3cell" `
|
||||
PublicID omit.Val[string] `db:"public_id" `
|
||||
ReporterEmail omit.Val[string] `db:"reporter_email" `
|
||||
ReporterPhone omit.Val[string] `db:"reporter_phone" `
|
||||
Address omit.Val[string] `db:"address" `
|
||||
Status omit.Val[enums.PublicreportReportstatustype] `db:"status" `
|
||||
OrganizationID omitnull.Val[int32] `db:"organization_id" `
|
||||
}
|
||||
|
||||
func (s PublicreportQuickSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 10)
|
||||
vals := make([]string, 0, 11)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
|
|
@ -150,6 +155,9 @@ func (s PublicreportQuickSetter) SetColumns() []string {
|
|||
if s.Status.IsValue() {
|
||||
vals = append(vals, "status")
|
||||
}
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +192,9 @@ func (s PublicreportQuickSetter) Overwrite(t *PublicreportQuick) {
|
|||
if s.Status.IsValue() {
|
||||
t.Status = s.Status.MustGet()
|
||||
}
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
t.OrganizationID = s.OrganizationID.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportQuickSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -192,7 +203,7 @@ func (s *PublicreportQuickSetter) 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, 10)
|
||||
vals := make([]bob.Expression, 11)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
|
|
@ -253,6 +264,12 @@ func (s *PublicreportQuickSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[9] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
vals[10] = psql.Arg(s.OrganizationID.MustGetNull())
|
||||
} else {
|
||||
vals[10] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -262,7 +279,7 @@ func (s PublicreportQuickSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PublicreportQuickSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 10)
|
||||
exprs := make([]bob.Expression, 0, 11)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -334,6 +351,13 @@ func (s PublicreportQuickSetter) Expressions(prefix ...string) []bob.Expression
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.OrganizationID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "organization_id")...),
|
||||
psql.Arg(s.OrganizationID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -560,6 +584,30 @@ func (o PublicreportQuickSlice) ReloadAll(ctx context.Context, exec bob.Executor
|
|||
return nil
|
||||
}
|
||||
|
||||
// Organization starts a query for related objects on organization
|
||||
func (o *PublicreportQuick) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportQuickSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
||||
pkOrganizationID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
|
||||
))
|
||||
|
||||
return Organizations.Query(append(mods,
|
||||
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Images starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportQuick) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
|
|
@ -589,6 +637,54 @@ func (os PublicreportQuickSlice) Images(mods ...bob.Mod[*dialect.SelectQuery]) P
|
|||
)...)
|
||||
}
|
||||
|
||||
func attachPublicreportQuickOrganization0(ctx context.Context, exec bob.Executor, count int, publicreportQuick0 *PublicreportQuick, organization1 *Organization) (*PublicreportQuick, error) {
|
||||
setter := &PublicreportQuickSetter{
|
||||
OrganizationID: omitnull.From(organization1.ID),
|
||||
}
|
||||
|
||||
err := publicreportQuick0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportQuickOrganization0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportQuick0, nil
|
||||
}
|
||||
|
||||
func (publicreportQuick0 *PublicreportQuick) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
|
||||
var err error
|
||||
|
||||
organization1, err := Organizations.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportQuickOrganization0(ctx, exec, 1, publicreportQuick0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuick0.R.Organization = organization1
|
||||
|
||||
organization1.R.Quicks = append(organization1.R.Quicks, publicreportQuick0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportQuick0 *PublicreportQuick) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportQuickOrganization0(ctx, exec, 1, publicreportQuick0, organization1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportQuick0.R.Organization = organization1
|
||||
|
||||
organization1.R.Quicks = append(organization1.R.Quicks, publicreportQuick0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportQuickImages0(ctx context.Context, exec bob.Executor, count int, publicreportQuick0 *PublicreportQuick, publicreportImages2 PublicreportImageSlice) (PublicreportQuickImageSlice, error) {
|
||||
setters := make([]*PublicreportQuickImageSetter, count)
|
||||
for i := range count {
|
||||
|
|
@ -655,16 +751,17 @@ func (publicreportQuick0 *PublicreportQuick) AttachImages(ctx context.Context, e
|
|||
}
|
||||
|
||||
type publicreportQuickWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Comments psql.WhereMod[Q, string]
|
||||
Location psql.WhereNullMod[Q, string]
|
||||
H3cell psql.WhereNullMod[Q, string]
|
||||
PublicID psql.WhereMod[Q, string]
|
||||
ReporterEmail psql.WhereMod[Q, string]
|
||||
ReporterPhone psql.WhereMod[Q, string]
|
||||
Address psql.WhereMod[Q, string]
|
||||
Status psql.WhereMod[Q, enums.PublicreportReportstatustype]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Comments psql.WhereMod[Q, string]
|
||||
Location psql.WhereNullMod[Q, string]
|
||||
H3cell psql.WhereNullMod[Q, string]
|
||||
PublicID psql.WhereMod[Q, string]
|
||||
ReporterEmail psql.WhereMod[Q, string]
|
||||
ReporterPhone psql.WhereMod[Q, string]
|
||||
Address psql.WhereMod[Q, string]
|
||||
Status psql.WhereMod[Q, enums.PublicreportReportstatustype]
|
||||
OrganizationID psql.WhereNullMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportQuickWhere[Q]) AliasedAs(alias string) publicreportQuickWhere[Q] {
|
||||
|
|
@ -673,16 +770,17 @@ func (publicreportQuickWhere[Q]) AliasedAs(alias string) publicreportQuickWhere[
|
|||
|
||||
func buildPublicreportQuickWhere[Q psql.Filterable](cols publicreportQuickColumns) publicreportQuickWhere[Q] {
|
||||
return publicreportQuickWhere[Q]{
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Comments: psql.Where[Q, string](cols.Comments),
|
||||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
H3cell: psql.WhereNull[Q, string](cols.H3cell),
|
||||
PublicID: psql.Where[Q, string](cols.PublicID),
|
||||
ReporterEmail: psql.Where[Q, string](cols.ReporterEmail),
|
||||
ReporterPhone: psql.Where[Q, string](cols.ReporterPhone),
|
||||
Address: psql.Where[Q, string](cols.Address),
|
||||
Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Comments: psql.Where[Q, string](cols.Comments),
|
||||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
H3cell: psql.WhereNull[Q, string](cols.H3cell),
|
||||
PublicID: psql.Where[Q, string](cols.PublicID),
|
||||
ReporterEmail: psql.Where[Q, string](cols.ReporterEmail),
|
||||
ReporterPhone: psql.Where[Q, string](cols.ReporterPhone),
|
||||
Address: psql.Where[Q, string](cols.Address),
|
||||
Status: psql.Where[Q, enums.PublicreportReportstatustype](cols.Status),
|
||||
OrganizationID: psql.WhereNull[Q, int32](cols.OrganizationID),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -692,6 +790,18 @@ func (o *PublicreportQuick) Preload(name string, retrieved any) error {
|
|||
}
|
||||
|
||||
switch name {
|
||||
case "Organization":
|
||||
rel, ok := retrieved.(*Organization)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportQuick cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.Organization = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.Quicks = PublicreportQuickSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Images":
|
||||
rels, ok := retrieved.(PublicreportImageSlice)
|
||||
if !ok {
|
||||
|
|
@ -711,22 +821,48 @@ func (o *PublicreportQuick) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
|
||||
type publicreportQuickPreloader struct{}
|
||||
type publicreportQuickPreloader struct {
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportQuickPreloader() publicreportQuickPreloader {
|
||||
return publicreportQuickPreloader{}
|
||||
return publicreportQuickPreloader{
|
||||
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
||||
Name: "Organization",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportQuicks,
|
||||
To: Organizations,
|
||||
FromColumns: []string{"organization_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportQuickThenLoader[Q orm.Loadable] struct {
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildPublicreportQuickThenLoader[Q orm.Loadable]() publicreportQuickThenLoader[Q] {
|
||||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ImagesLoadInterface interface {
|
||||
LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return publicreportQuickThenLoader[Q]{
|
||||
Organization: thenLoadBuilder[Q](
|
||||
"Organization",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Images: thenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -736,6 +872,61 @@ func buildPublicreportQuickThenLoader[Q orm.Loadable]() publicreportQuickThenLoa
|
|||
}
|
||||
}
|
||||
|
||||
// LoadOrganization loads the publicreportQuick's Organization into the .R struct
|
||||
func (o *PublicreportQuick) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.Organization = nil
|
||||
|
||||
related, err := o.Organization(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.Quicks = PublicreportQuickSlice{o}
|
||||
|
||||
o.R.Organization = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOrganization loads the publicreportQuick's Organization into the .R struct
|
||||
func (os PublicreportQuickSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
organizations, err := os.Organization(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range organizations {
|
||||
if !o.OrganizationID.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.OrganizationID.IsValue() && o.OrganizationID.MustGet() == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Quicks = append(rel.R.Quicks, o)
|
||||
|
||||
o.R.Organization = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImages loads the publicreportQuick's Images into the .R struct
|
||||
func (o *PublicreportQuick) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
@ -914,8 +1105,9 @@ func (os PublicreportQuickSlice) LoadCountImages(ctx context.Context, exec bob.E
|
|||
}
|
||||
|
||||
type publicreportQuickJoins[Q dialect.Joinable] struct {
|
||||
typ string
|
||||
Images modAs[Q, publicreportImageColumns]
|
||||
typ string
|
||||
Organization modAs[Q, organizationColumns]
|
||||
Images modAs[Q, publicreportImageColumns]
|
||||
}
|
||||
|
||||
func (j publicreportQuickJoins[Q]) aliasedAs(alias string) publicreportQuickJoins[Q] {
|
||||
|
|
@ -925,6 +1117,20 @@ func (j publicreportQuickJoins[Q]) aliasedAs(alias string) publicreportQuickJoin
|
|||
func buildPublicreportQuickJoins[Q dialect.Joinable](cols publicreportQuickColumns, typ string) publicreportQuickJoins[Q] {
|
||||
return publicreportQuickJoins[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
|
||||
},
|
||||
},
|
||||
Images: modAs[Q, publicreportImageColumns]{
|
||||
c: PublicreportImages.Columns,
|
||||
f: func(to publicreportImageColumns) bob.Mod[Q] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue