678 lines
20 KiB
Go
678 lines
20 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"
|
|
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/google/uuid"
|
|
"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"
|
|
)
|
|
|
|
// PublicreportQuickPhoto is an object representing the database table.
|
|
type PublicreportQuickPhoto struct {
|
|
ID int32 `db:"id,pk" `
|
|
Size int64 `db:"size" `
|
|
Filename string `db:"filename" `
|
|
QuickID int32 `db:"quick_id" `
|
|
UUID uuid.UUID `db:"uuid" `
|
|
|
|
R publicreportQuickPhotoR `db:"-" `
|
|
}
|
|
|
|
// PublicreportQuickPhotoSlice is an alias for a slice of pointers to PublicreportQuickPhoto.
|
|
// This should almost always be used instead of []*PublicreportQuickPhoto.
|
|
type PublicreportQuickPhotoSlice []*PublicreportQuickPhoto
|
|
|
|
// PublicreportQuickPhotos contains methods to work with the quick_photo table
|
|
var PublicreportQuickPhotos = psql.NewTablex[*PublicreportQuickPhoto, PublicreportQuickPhotoSlice, *PublicreportQuickPhotoSetter]("publicreport", "quick_photo", buildPublicreportQuickPhotoColumns("publicreport.quick_photo"))
|
|
|
|
// PublicreportQuickPhotosQuery is a query on the quick_photo table
|
|
type PublicreportQuickPhotosQuery = *psql.ViewQuery[*PublicreportQuickPhoto, PublicreportQuickPhotoSlice]
|
|
|
|
// publicreportQuickPhotoR is where relationships are stored.
|
|
type publicreportQuickPhotoR struct {
|
|
Quick *PublicreportQuick // publicreport.quick_photo.quick_photo_quick_id_fkey
|
|
}
|
|
|
|
func buildPublicreportQuickPhotoColumns(alias string) publicreportQuickPhotoColumns {
|
|
return publicreportQuickPhotoColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "size", "filename", "quick_id", "uuid",
|
|
).WithParent("publicreport.quick_photo"),
|
|
tableAlias: alias,
|
|
ID: psql.Quote(alias, "id"),
|
|
Size: psql.Quote(alias, "size"),
|
|
Filename: psql.Quote(alias, "filename"),
|
|
QuickID: psql.Quote(alias, "quick_id"),
|
|
UUID: psql.Quote(alias, "uuid"),
|
|
}
|
|
}
|
|
|
|
type publicreportQuickPhotoColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ID psql.Expression
|
|
Size psql.Expression
|
|
Filename psql.Expression
|
|
QuickID psql.Expression
|
|
UUID psql.Expression
|
|
}
|
|
|
|
func (c publicreportQuickPhotoColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (publicreportQuickPhotoColumns) AliasedAs(alias string) publicreportQuickPhotoColumns {
|
|
return buildPublicreportQuickPhotoColumns(alias)
|
|
}
|
|
|
|
// PublicreportQuickPhotoSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type PublicreportQuickPhotoSetter struct {
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
Size omit.Val[int64] `db:"size" `
|
|
Filename omit.Val[string] `db:"filename" `
|
|
QuickID omit.Val[int32] `db:"quick_id" `
|
|
UUID omit.Val[uuid.UUID] `db:"uuid" `
|
|
}
|
|
|
|
func (s PublicreportQuickPhotoSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 5)
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if s.Size.IsValue() {
|
|
vals = append(vals, "size")
|
|
}
|
|
if s.Filename.IsValue() {
|
|
vals = append(vals, "filename")
|
|
}
|
|
if s.QuickID.IsValue() {
|
|
vals = append(vals, "quick_id")
|
|
}
|
|
if s.UUID.IsValue() {
|
|
vals = append(vals, "uuid")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s PublicreportQuickPhotoSetter) Overwrite(t *PublicreportQuickPhoto) {
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if s.Size.IsValue() {
|
|
t.Size = s.Size.MustGet()
|
|
}
|
|
if s.Filename.IsValue() {
|
|
t.Filename = s.Filename.MustGet()
|
|
}
|
|
if s.QuickID.IsValue() {
|
|
t.QuickID = s.QuickID.MustGet()
|
|
}
|
|
if s.UUID.IsValue() {
|
|
t.UUID = s.UUID.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *PublicreportQuickPhotoSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return PublicreportQuickPhotos.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
|
})
|
|
|
|
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
|
vals := make([]bob.Expression, 5)
|
|
if s.ID.IsValue() {
|
|
vals[0] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Size.IsValue() {
|
|
vals[1] = psql.Arg(s.Size.MustGet())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Filename.IsValue() {
|
|
vals[2] = psql.Arg(s.Filename.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.QuickID.IsValue() {
|
|
vals[3] = psql.Arg(s.QuickID.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.UUID.IsValue() {
|
|
vals[4] = psql.Arg(s.UUID.MustGet())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s PublicreportQuickPhotoSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s PublicreportQuickPhotoSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 5)
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if s.Size.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "size")...),
|
|
psql.Arg(s.Size),
|
|
}})
|
|
}
|
|
|
|
if s.Filename.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "filename")...),
|
|
psql.Arg(s.Filename),
|
|
}})
|
|
}
|
|
|
|
if s.QuickID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "quick_id")...),
|
|
psql.Arg(s.QuickID),
|
|
}})
|
|
}
|
|
|
|
if s.UUID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "uuid")...),
|
|
psql.Arg(s.UUID),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindPublicreportQuickPhoto retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindPublicreportQuickPhoto(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportQuickPhoto, error) {
|
|
if len(cols) == 0 {
|
|
return PublicreportQuickPhotos.Query(
|
|
sm.Where(PublicreportQuickPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return PublicreportQuickPhotos.Query(
|
|
sm.Where(PublicreportQuickPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(PublicreportQuickPhotos.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// PublicreportQuickPhotoExists checks the presence of a single record by primary key
|
|
func PublicreportQuickPhotoExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return PublicreportQuickPhotos.Query(
|
|
sm.Where(PublicreportQuickPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after PublicreportQuickPhoto is retrieved from the database
|
|
func (o *PublicreportQuickPhoto) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportQuickPhotos.AfterSelectHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportQuickPhotos.AfterInsertHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportQuickPhotos.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportQuickPhotos.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportQuickPhotoSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the PublicreportQuickPhoto
|
|
func (o *PublicreportQuickPhoto) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *PublicreportQuickPhoto) pkEQ() dialect.Expression {
|
|
return psql.Quote("publicreport.quick_photo", "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 PublicreportQuickPhoto
|
|
func (o *PublicreportQuickPhoto) Update(ctx context.Context, exec bob.Executor, s *PublicreportQuickPhotoSetter) error {
|
|
v, err := PublicreportQuickPhotos.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 PublicreportQuickPhoto record with an executor
|
|
func (o *PublicreportQuickPhoto) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := PublicreportQuickPhotos.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the PublicreportQuickPhoto using the executor
|
|
func (o *PublicreportQuickPhoto) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := PublicreportQuickPhotos.Query(
|
|
sm.Where(PublicreportQuickPhotos.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 PublicreportQuickPhotoSlice is retrieved from the database
|
|
func (o PublicreportQuickPhotoSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportQuickPhotos.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportQuickPhotos.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportQuickPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportQuickPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportQuickPhotoSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("publicreport.quick_photo", "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 PublicreportQuickPhotoSlice) copyMatchingRows(from ...*PublicreportQuickPhoto) {
|
|
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 PublicreportQuickPhotoSlice) 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 PublicreportQuickPhotos.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 *PublicreportQuickPhoto:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportQuickPhoto:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportQuickPhotoSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportQuickPhoto or a slice of PublicreportQuickPhoto
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = PublicreportQuickPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o PublicreportQuickPhotoSlice) 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 PublicreportQuickPhotos.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 *PublicreportQuickPhoto:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportQuickPhoto:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportQuickPhotoSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportQuickPhoto or a slice of PublicreportQuickPhoto
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = PublicreportQuickPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o PublicreportQuickPhotoSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportQuickPhotoSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportQuickPhotos.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportQuickPhotoSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportQuickPhotos.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportQuickPhotoSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := PublicreportQuickPhotos.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Quick starts a query for related objects on publicreport.quick
|
|
func (o *PublicreportQuickPhoto) Quick(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuicksQuery {
|
|
return PublicreportQuicks.Query(append(mods,
|
|
sm.Where(PublicreportQuicks.Columns.ID.EQ(psql.Arg(o.QuickID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportQuickPhotoSlice) Quick(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportQuicksQuery {
|
|
pkQuickID := make(pgtypes.Array[int32], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkQuickID = append(pkQuickID, o.QuickID)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkQuickID), "integer[]")),
|
|
))
|
|
|
|
return PublicreportQuicks.Query(append(mods,
|
|
sm.Where(psql.Group(PublicreportQuicks.Columns.ID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func attachPublicreportQuickPhotoQuick0(ctx context.Context, exec bob.Executor, count int, publicreportQuickPhoto0 *PublicreportQuickPhoto, publicreportQuick1 *PublicreportQuick) (*PublicreportQuickPhoto, error) {
|
|
setter := &PublicreportQuickPhotoSetter{
|
|
QuickID: omit.From(publicreportQuick1.ID),
|
|
}
|
|
|
|
err := publicreportQuickPhoto0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportQuickPhotoQuick0: %w", err)
|
|
}
|
|
|
|
return publicreportQuickPhoto0, nil
|
|
}
|
|
|
|
func (publicreportQuickPhoto0 *PublicreportQuickPhoto) InsertQuick(ctx context.Context, exec bob.Executor, related *PublicreportQuickSetter) error {
|
|
var err error
|
|
|
|
publicreportQuick1, err := PublicreportQuicks.Insert(related).One(ctx, exec)
|
|
if err != nil {
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
|
}
|
|
|
|
_, err = attachPublicreportQuickPhotoQuick0(ctx, exec, 1, publicreportQuickPhoto0, publicreportQuick1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportQuickPhoto0.R.Quick = publicreportQuick1
|
|
|
|
publicreportQuick1.R.QuickPhotos = append(publicreportQuick1.R.QuickPhotos, publicreportQuickPhoto0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (publicreportQuickPhoto0 *PublicreportQuickPhoto) AttachQuick(ctx context.Context, exec bob.Executor, publicreportQuick1 *PublicreportQuick) error {
|
|
var err error
|
|
|
|
_, err = attachPublicreportQuickPhotoQuick0(ctx, exec, 1, publicreportQuickPhoto0, publicreportQuick1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportQuickPhoto0.R.Quick = publicreportQuick1
|
|
|
|
publicreportQuick1.R.QuickPhotos = append(publicreportQuick1.R.QuickPhotos, publicreportQuickPhoto0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportQuickPhotoWhere[Q psql.Filterable] struct {
|
|
ID psql.WhereMod[Q, int32]
|
|
Size psql.WhereMod[Q, int64]
|
|
Filename psql.WhereMod[Q, string]
|
|
QuickID psql.WhereMod[Q, int32]
|
|
UUID psql.WhereMod[Q, uuid.UUID]
|
|
}
|
|
|
|
func (publicreportQuickPhotoWhere[Q]) AliasedAs(alias string) publicreportQuickPhotoWhere[Q] {
|
|
return buildPublicreportQuickPhotoWhere[Q](buildPublicreportQuickPhotoColumns(alias))
|
|
}
|
|
|
|
func buildPublicreportQuickPhotoWhere[Q psql.Filterable](cols publicreportQuickPhotoColumns) publicreportQuickPhotoWhere[Q] {
|
|
return publicreportQuickPhotoWhere[Q]{
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
Size: psql.Where[Q, int64](cols.Size),
|
|
Filename: psql.Where[Q, string](cols.Filename),
|
|
QuickID: psql.Where[Q, int32](cols.QuickID),
|
|
UUID: psql.Where[Q, uuid.UUID](cols.UUID),
|
|
}
|
|
}
|
|
|
|
func (o *PublicreportQuickPhoto) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "Quick":
|
|
rel, ok := retrieved.(*PublicreportQuick)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportQuickPhoto cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Quick = rel
|
|
|
|
if rel != nil {
|
|
rel.R.QuickPhotos = PublicreportQuickPhotoSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("publicreportQuickPhoto has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type publicreportQuickPhotoPreloader struct {
|
|
Quick func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildPublicreportQuickPhotoPreloader() publicreportQuickPhotoPreloader {
|
|
return publicreportQuickPhotoPreloader{
|
|
Quick: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*PublicreportQuick, PublicreportQuickSlice](psql.PreloadRel{
|
|
Name: "Quick",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: PublicreportQuickPhotos,
|
|
To: PublicreportQuicks,
|
|
FromColumns: []string{"quick_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, PublicreportQuicks.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type publicreportQuickPhotoThenLoader[Q orm.Loadable] struct {
|
|
Quick func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildPublicreportQuickPhotoThenLoader[Q orm.Loadable]() publicreportQuickPhotoThenLoader[Q] {
|
|
type QuickLoadInterface interface {
|
|
LoadQuick(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return publicreportQuickPhotoThenLoader[Q]{
|
|
Quick: thenLoadBuilder[Q](
|
|
"Quick",
|
|
func(ctx context.Context, exec bob.Executor, retrieved QuickLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadQuick(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadQuick loads the publicreportQuickPhoto's Quick into the .R struct
|
|
func (o *PublicreportQuickPhoto) LoadQuick(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.Quick = nil
|
|
|
|
related, err := o.Quick(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.QuickPhotos = PublicreportQuickPhotoSlice{o}
|
|
|
|
o.R.Quick = related
|
|
return nil
|
|
}
|
|
|
|
// LoadQuick loads the publicreportQuickPhoto's Quick into the .R struct
|
|
func (os PublicreportQuickPhotoSlice) LoadQuick(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
publicreportQuicks, err := os.Quick(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range publicreportQuicks {
|
|
|
|
if !(o.QuickID == rel.ID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.QuickPhotos = append(rel.R.QuickPhotos, o)
|
|
|
|
o.R.Quick = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportQuickPhotoJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
Quick modAs[Q, publicreportQuickColumns]
|
|
}
|
|
|
|
func (j publicreportQuickPhotoJoins[Q]) aliasedAs(alias string) publicreportQuickPhotoJoins[Q] {
|
|
return buildPublicreportQuickPhotoJoins[Q](buildPublicreportQuickPhotoColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildPublicreportQuickPhotoJoins[Q dialect.Joinable](cols publicreportQuickPhotoColumns, typ string) publicreportQuickPhotoJoins[Q] {
|
|
return publicreportQuickPhotoJoins[Q]{
|
|
typ: typ,
|
|
Quick: modAs[Q, publicreportQuickColumns]{
|
|
c: PublicreportQuicks.Columns,
|
|
f: func(to publicreportQuickColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, PublicreportQuicks.Name().As(to.Alias())).On(
|
|
to.ID.EQ(cols.QuickID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
}
|
|
}
|