At this point it also appears that I'm correctly capturing the GPS location as both PostGIS data and as an H3 cell.
770 lines
23 KiB
Go
770 lines
23 KiB
Go
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. 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/aarondl/opt/null"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/aarondl/opt/omitnull"
|
|
"github.com/stephenafamo/bob"
|
|
"github.com/stephenafamo/bob/dialect/psql"
|
|
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
|
"github.com/stephenafamo/bob/dialect/psql/dm"
|
|
"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"
|
|
)
|
|
|
|
// 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" `
|
|
|
|
R publicreportQuickR `db:"-" `
|
|
}
|
|
|
|
// PublicreportQuickSlice is an alias for a slice of pointers to PublicreportQuick.
|
|
// This should almost always be used instead of []*PublicreportQuick.
|
|
type PublicreportQuickSlice []*PublicreportQuick
|
|
|
|
// PublicreportQuicks contains methods to work with the quick table
|
|
var PublicreportQuicks = psql.NewTablex[*PublicreportQuick, PublicreportQuickSlice, *PublicreportQuickSetter]("publicreport", "quick", buildPublicreportQuickColumns("publicreport.quick"))
|
|
|
|
// PublicreportQuicksQuery is a query on the quick table
|
|
type PublicreportQuicksQuery = *psql.ViewQuery[*PublicreportQuick, PublicreportQuickSlice]
|
|
|
|
// publicreportQuickR is where relationships are stored.
|
|
type publicreportQuickR struct {
|
|
QuickPhotos PublicreportQuickPhotoSlice // publicreport.quick_photo.quick_photo_quick_id_fkey
|
|
}
|
|
|
|
func buildPublicreportQuickColumns(alias string) publicreportQuickColumns {
|
|
return publicreportQuickColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "created", "comments", "location", "h3cell", "public_id", "reporter_email", "reporter_phone",
|
|
).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"),
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (c publicreportQuickColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (publicreportQuickColumns) AliasedAs(alias string) publicreportQuickColumns {
|
|
return buildPublicreportQuickColumns(alias)
|
|
}
|
|
|
|
// PublicreportQuickSetter is used for insert/upsert/update operations
|
|
// 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" `
|
|
}
|
|
|
|
func (s PublicreportQuickSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 8)
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if s.Created.IsValue() {
|
|
vals = append(vals, "created")
|
|
}
|
|
if s.Comments.IsValue() {
|
|
vals = append(vals, "comments")
|
|
}
|
|
if !s.Location.IsUnset() {
|
|
vals = append(vals, "location")
|
|
}
|
|
if !s.H3cell.IsUnset() {
|
|
vals = append(vals, "h3cell")
|
|
}
|
|
if s.PublicID.IsValue() {
|
|
vals = append(vals, "public_id")
|
|
}
|
|
if s.ReporterEmail.IsValue() {
|
|
vals = append(vals, "reporter_email")
|
|
}
|
|
if s.ReporterPhone.IsValue() {
|
|
vals = append(vals, "reporter_phone")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s PublicreportQuickSetter) Overwrite(t *PublicreportQuick) {
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if s.Created.IsValue() {
|
|
t.Created = s.Created.MustGet()
|
|
}
|
|
if s.Comments.IsValue() {
|
|
t.Comments = s.Comments.MustGet()
|
|
}
|
|
if !s.Location.IsUnset() {
|
|
t.Location = s.Location.MustGetNull()
|
|
}
|
|
if !s.H3cell.IsUnset() {
|
|
t.H3cell = s.H3cell.MustGetNull()
|
|
}
|
|
if s.PublicID.IsValue() {
|
|
t.PublicID = s.PublicID.MustGet()
|
|
}
|
|
if s.ReporterEmail.IsValue() {
|
|
t.ReporterEmail = s.ReporterEmail.MustGet()
|
|
}
|
|
if s.ReporterPhone.IsValue() {
|
|
t.ReporterPhone = s.ReporterPhone.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *PublicreportQuickSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return PublicreportQuicks.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, 8)
|
|
if s.ID.IsValue() {
|
|
vals[0] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
vals[1] = psql.Arg(s.Created.MustGet())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Comments.IsValue() {
|
|
vals[2] = psql.Arg(s.Comments.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Location.IsUnset() {
|
|
vals[3] = psql.Arg(s.Location.MustGetNull())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.H3cell.IsUnset() {
|
|
vals[4] = psql.Arg(s.H3cell.MustGetNull())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.PublicID.IsValue() {
|
|
vals[5] = psql.Arg(s.PublicID.MustGet())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.ReporterEmail.IsValue() {
|
|
vals[6] = psql.Arg(s.ReporterEmail.MustGet())
|
|
} else {
|
|
vals[6] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.ReporterPhone.IsValue() {
|
|
vals[7] = psql.Arg(s.ReporterPhone.MustGet())
|
|
} else {
|
|
vals[7] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s PublicreportQuickSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s PublicreportQuickSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 8)
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "created")...),
|
|
psql.Arg(s.Created),
|
|
}})
|
|
}
|
|
|
|
if s.Comments.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "comments")...),
|
|
psql.Arg(s.Comments),
|
|
}})
|
|
}
|
|
|
|
if !s.Location.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "location")...),
|
|
psql.Arg(s.Location),
|
|
}})
|
|
}
|
|
|
|
if !s.H3cell.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "h3cell")...),
|
|
psql.Arg(s.H3cell),
|
|
}})
|
|
}
|
|
|
|
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.ReporterEmail.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "reporter_email")...),
|
|
psql.Arg(s.ReporterEmail),
|
|
}})
|
|
}
|
|
|
|
if s.ReporterPhone.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "reporter_phone")...),
|
|
psql.Arg(s.ReporterPhone),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindPublicreportQuick retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindPublicreportQuick(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportQuick, error) {
|
|
if len(cols) == 0 {
|
|
return PublicreportQuicks.Query(
|
|
sm.Where(PublicreportQuicks.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return PublicreportQuicks.Query(
|
|
sm.Where(PublicreportQuicks.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(PublicreportQuicks.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// PublicreportQuickExists checks the presence of a single record by primary key
|
|
func PublicreportQuickExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return PublicreportQuicks.Query(
|
|
sm.Where(PublicreportQuicks.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after PublicreportQuick is retrieved from the database
|
|
func (o *PublicreportQuick) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportQuicks.AfterSelectHooks.RunHooks(ctx, exec, PublicreportQuickSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportQuicks.AfterInsertHooks.RunHooks(ctx, exec, PublicreportQuickSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportQuicks.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportQuickSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportQuicks.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportQuickSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the PublicreportQuick
|
|
func (o *PublicreportQuick) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *PublicreportQuick) pkEQ() dialect.Expression {
|
|
return psql.Quote("publicreport.quick", "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 PublicreportQuick
|
|
func (o *PublicreportQuick) Update(ctx context.Context, exec bob.Executor, s *PublicreportQuickSetter) error {
|
|
v, err := PublicreportQuicks.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 PublicreportQuick record with an executor
|
|
func (o *PublicreportQuick) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := PublicreportQuicks.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the PublicreportQuick using the executor
|
|
func (o *PublicreportQuick) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := PublicreportQuicks.Query(
|
|
sm.Where(PublicreportQuicks.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 PublicreportQuickSlice is retrieved from the database
|
|
func (o PublicreportQuickSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportQuicks.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportQuicks.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportQuicks.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportQuicks.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportQuickSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("publicreport.quick", "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 PublicreportQuickSlice) copyMatchingRows(from ...*PublicreportQuick) {
|
|
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 PublicreportQuickSlice) 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 PublicreportQuicks.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 *PublicreportQuick:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportQuick:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportQuickSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportQuick or a slice of PublicreportQuick
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = PublicreportQuicks.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o PublicreportQuickSlice) 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 PublicreportQuicks.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 *PublicreportQuick:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportQuick:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportQuickSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportQuick or a slice of PublicreportQuick
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = PublicreportQuicks.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o PublicreportQuickSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportQuickSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportQuicks.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportQuickSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportQuicks.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportQuickSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := PublicreportQuicks.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// QuickPhotos starts a query for related objects on publicreport.quick_photo
|
|
func (o *PublicreportQuick) QuickPhotos(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuickPhotosQuery {
|
|
return PublicreportQuickPhotos.Query(append(mods,
|
|
sm.Where(PublicreportQuickPhotos.Columns.QuickID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportQuickSlice) QuickPhotos(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuickPhotosQuery {
|
|
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 PublicreportQuickPhotos.Query(append(mods,
|
|
sm.Where(psql.Group(PublicreportQuickPhotos.Columns.QuickID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func insertPublicreportQuickQuickPhotos0(ctx context.Context, exec bob.Executor, publicreportQuickPhotos1 []*PublicreportQuickPhotoSetter, publicreportQuick0 *PublicreportQuick) (PublicreportQuickPhotoSlice, error) {
|
|
for i := range publicreportQuickPhotos1 {
|
|
publicreportQuickPhotos1[i].QuickID = omit.From(publicreportQuick0.ID)
|
|
}
|
|
|
|
ret, err := PublicreportQuickPhotos.Insert(bob.ToMods(publicreportQuickPhotos1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertPublicreportQuickQuickPhotos0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachPublicreportQuickQuickPhotos0(ctx context.Context, exec bob.Executor, count int, publicreportQuickPhotos1 PublicreportQuickPhotoSlice, publicreportQuick0 *PublicreportQuick) (PublicreportQuickPhotoSlice, error) {
|
|
setter := &PublicreportQuickPhotoSetter{
|
|
QuickID: omit.From(publicreportQuick0.ID),
|
|
}
|
|
|
|
err := publicreportQuickPhotos1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportQuickQuickPhotos0: %w", err)
|
|
}
|
|
|
|
return publicreportQuickPhotos1, nil
|
|
}
|
|
|
|
func (publicreportQuick0 *PublicreportQuick) InsertQuickPhotos(ctx context.Context, exec bob.Executor, related ...*PublicreportQuickPhotoSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
publicreportQuickPhotos1, err := insertPublicreportQuickQuickPhotos0(ctx, exec, related, publicreportQuick0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportQuick0.R.QuickPhotos = append(publicreportQuick0.R.QuickPhotos, publicreportQuickPhotos1...)
|
|
|
|
for _, rel := range publicreportQuickPhotos1 {
|
|
rel.R.Quick = publicreportQuick0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (publicreportQuick0 *PublicreportQuick) AttachQuickPhotos(ctx context.Context, exec bob.Executor, related ...*PublicreportQuickPhoto) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
publicreportQuickPhotos1 := PublicreportQuickPhotoSlice(related)
|
|
|
|
_, err = attachPublicreportQuickQuickPhotos0(ctx, exec, len(related), publicreportQuickPhotos1, publicreportQuick0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportQuick0.R.QuickPhotos = append(publicreportQuick0.R.QuickPhotos, publicreportQuickPhotos1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.Quick = publicreportQuick0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
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]
|
|
}
|
|
|
|
func (publicreportQuickWhere[Q]) AliasedAs(alias string) publicreportQuickWhere[Q] {
|
|
return buildPublicreportQuickWhere[Q](buildPublicreportQuickColumns(alias))
|
|
}
|
|
|
|
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),
|
|
}
|
|
}
|
|
|
|
func (o *PublicreportQuick) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "QuickPhotos":
|
|
rels, ok := retrieved.(PublicreportQuickPhotoSlice)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportQuick cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.QuickPhotos = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.Quick = o
|
|
}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("publicreportQuick has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type publicreportQuickPreloader struct{}
|
|
|
|
func buildPublicreportQuickPreloader() publicreportQuickPreloader {
|
|
return publicreportQuickPreloader{}
|
|
}
|
|
|
|
type publicreportQuickThenLoader[Q orm.Loadable] struct {
|
|
QuickPhotos func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildPublicreportQuickThenLoader[Q orm.Loadable]() publicreportQuickThenLoader[Q] {
|
|
type QuickPhotosLoadInterface interface {
|
|
LoadQuickPhotos(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return publicreportQuickThenLoader[Q]{
|
|
QuickPhotos: thenLoadBuilder[Q](
|
|
"QuickPhotos",
|
|
func(ctx context.Context, exec bob.Executor, retrieved QuickPhotosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadQuickPhotos(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadQuickPhotos loads the publicreportQuick's QuickPhotos into the .R struct
|
|
func (o *PublicreportQuick) LoadQuickPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.QuickPhotos = nil
|
|
|
|
related, err := o.QuickPhotos(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.Quick = o
|
|
}
|
|
|
|
o.R.QuickPhotos = related
|
|
return nil
|
|
}
|
|
|
|
// LoadQuickPhotos loads the publicreportQuick's QuickPhotos into the .R struct
|
|
func (os PublicreportQuickSlice) LoadQuickPhotos(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
publicreportQuickPhotos, err := os.QuickPhotos(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.QuickPhotos = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range publicreportQuickPhotos {
|
|
|
|
if !(o.ID == rel.QuickID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.Quick = o
|
|
|
|
o.R.QuickPhotos = append(o.R.QuickPhotos, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportQuickJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
QuickPhotos modAs[Q, publicreportQuickPhotoColumns]
|
|
}
|
|
|
|
func (j publicreportQuickJoins[Q]) aliasedAs(alias string) publicreportQuickJoins[Q] {
|
|
return buildPublicreportQuickJoins[Q](buildPublicreportQuickColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildPublicreportQuickJoins[Q dialect.Joinable](cols publicreportQuickColumns, typ string) publicreportQuickJoins[Q] {
|
|
return publicreportQuickJoins[Q]{
|
|
typ: typ,
|
|
QuickPhotos: modAs[Q, publicreportQuickPhotoColumns]{
|
|
c: PublicreportQuickPhotos.Columns,
|
|
f: func(to publicreportQuickPhotoColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, PublicreportQuickPhotos.Name().As(to.Alias())).On(
|
|
to.QuickID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
}
|
|
}
|