Also start the pattern of breaking out pool pages together in their own file. I think its easier to read this way.
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"
|
|
)
|
|
|
|
// PublicreportPoolPhoto is an object representing the database table.
|
|
type PublicreportPoolPhoto struct {
|
|
ID int32 `db:"id,pk" `
|
|
Size int64 `db:"size" `
|
|
Filename string `db:"filename" `
|
|
PoolID int32 `db:"pool_id" `
|
|
UUID uuid.UUID `db:"uuid" `
|
|
|
|
R publicreportPoolPhotoR `db:"-" `
|
|
}
|
|
|
|
// PublicreportPoolPhotoSlice is an alias for a slice of pointers to PublicreportPoolPhoto.
|
|
// This should almost always be used instead of []*PublicreportPoolPhoto.
|
|
type PublicreportPoolPhotoSlice []*PublicreportPoolPhoto
|
|
|
|
// PublicreportPoolPhotos contains methods to work with the pool_photo table
|
|
var PublicreportPoolPhotos = psql.NewTablex[*PublicreportPoolPhoto, PublicreportPoolPhotoSlice, *PublicreportPoolPhotoSetter]("publicreport", "pool_photo", buildPublicreportPoolPhotoColumns("publicreport.pool_photo"))
|
|
|
|
// PublicreportPoolPhotosQuery is a query on the pool_photo table
|
|
type PublicreportPoolPhotosQuery = *psql.ViewQuery[*PublicreportPoolPhoto, PublicreportPoolPhotoSlice]
|
|
|
|
// publicreportPoolPhotoR is where relationships are stored.
|
|
type publicreportPoolPhotoR struct {
|
|
Pool *PublicreportPool // publicreport.pool_photo.pool_photo_pool_id_fkey
|
|
}
|
|
|
|
func buildPublicreportPoolPhotoColumns(alias string) publicreportPoolPhotoColumns {
|
|
return publicreportPoolPhotoColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "size", "filename", "pool_id", "uuid",
|
|
).WithParent("publicreport.pool_photo"),
|
|
tableAlias: alias,
|
|
ID: psql.Quote(alias, "id"),
|
|
Size: psql.Quote(alias, "size"),
|
|
Filename: psql.Quote(alias, "filename"),
|
|
PoolID: psql.Quote(alias, "pool_id"),
|
|
UUID: psql.Quote(alias, "uuid"),
|
|
}
|
|
}
|
|
|
|
type publicreportPoolPhotoColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ID psql.Expression
|
|
Size psql.Expression
|
|
Filename psql.Expression
|
|
PoolID psql.Expression
|
|
UUID psql.Expression
|
|
}
|
|
|
|
func (c publicreportPoolPhotoColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (publicreportPoolPhotoColumns) AliasedAs(alias string) publicreportPoolPhotoColumns {
|
|
return buildPublicreportPoolPhotoColumns(alias)
|
|
}
|
|
|
|
// PublicreportPoolPhotoSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type PublicreportPoolPhotoSetter struct {
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
Size omit.Val[int64] `db:"size" `
|
|
Filename omit.Val[string] `db:"filename" `
|
|
PoolID omit.Val[int32] `db:"pool_id" `
|
|
UUID omit.Val[uuid.UUID] `db:"uuid" `
|
|
}
|
|
|
|
func (s PublicreportPoolPhotoSetter) 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.PoolID.IsValue() {
|
|
vals = append(vals, "pool_id")
|
|
}
|
|
if s.UUID.IsValue() {
|
|
vals = append(vals, "uuid")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s PublicreportPoolPhotoSetter) Overwrite(t *PublicreportPoolPhoto) {
|
|
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.PoolID.IsValue() {
|
|
t.PoolID = s.PoolID.MustGet()
|
|
}
|
|
if s.UUID.IsValue() {
|
|
t.UUID = s.UUID.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *PublicreportPoolPhotoSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return PublicreportPoolPhotos.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.PoolID.IsValue() {
|
|
vals[3] = psql.Arg(s.PoolID.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 PublicreportPoolPhotoSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s PublicreportPoolPhotoSetter) 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.PoolID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "pool_id")...),
|
|
psql.Arg(s.PoolID),
|
|
}})
|
|
}
|
|
|
|
if s.UUID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "uuid")...),
|
|
psql.Arg(s.UUID),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindPublicreportPoolPhoto retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindPublicreportPoolPhoto(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportPoolPhoto, error) {
|
|
if len(cols) == 0 {
|
|
return PublicreportPoolPhotos.Query(
|
|
sm.Where(PublicreportPoolPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return PublicreportPoolPhotos.Query(
|
|
sm.Where(PublicreportPoolPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(PublicreportPoolPhotos.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// PublicreportPoolPhotoExists checks the presence of a single record by primary key
|
|
func PublicreportPoolPhotoExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return PublicreportPoolPhotos.Query(
|
|
sm.Where(PublicreportPoolPhotos.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after PublicreportPoolPhoto is retrieved from the database
|
|
func (o *PublicreportPoolPhoto) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportPoolPhotos.AfterSelectHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportPoolPhotos.AfterInsertHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportPoolPhotos.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportPoolPhotos.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportPoolPhotoSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the PublicreportPoolPhoto
|
|
func (o *PublicreportPoolPhoto) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *PublicreportPoolPhoto) pkEQ() dialect.Expression {
|
|
return psql.Quote("publicreport.pool_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 PublicreportPoolPhoto
|
|
func (o *PublicreportPoolPhoto) Update(ctx context.Context, exec bob.Executor, s *PublicreportPoolPhotoSetter) error {
|
|
v, err := PublicreportPoolPhotos.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 PublicreportPoolPhoto record with an executor
|
|
func (o *PublicreportPoolPhoto) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := PublicreportPoolPhotos.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the PublicreportPoolPhoto using the executor
|
|
func (o *PublicreportPoolPhoto) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := PublicreportPoolPhotos.Query(
|
|
sm.Where(PublicreportPoolPhotos.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 PublicreportPoolPhotoSlice is retrieved from the database
|
|
func (o PublicreportPoolPhotoSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportPoolPhotos.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportPoolPhotos.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportPoolPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportPoolPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportPoolPhotoSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("publicreport.pool_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 PublicreportPoolPhotoSlice) copyMatchingRows(from ...*PublicreportPoolPhoto) {
|
|
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 PublicreportPoolPhotoSlice) 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 PublicreportPoolPhotos.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 *PublicreportPoolPhoto:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportPoolPhoto:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportPoolPhotoSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportPoolPhoto or a slice of PublicreportPoolPhoto
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = PublicreportPoolPhotos.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o PublicreportPoolPhotoSlice) 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 PublicreportPoolPhotos.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 *PublicreportPoolPhoto:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportPoolPhoto:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportPoolPhotoSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportPoolPhoto or a slice of PublicreportPoolPhoto
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = PublicreportPoolPhotos.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o PublicreportPoolPhotoSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportPoolPhotoSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportPoolPhotos.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportPoolPhotoSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportPoolPhotos.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportPoolPhotoSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := PublicreportPoolPhotos.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Pool starts a query for related objects on publicreport.pool
|
|
func (o *PublicreportPoolPhoto) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
|
return PublicreportPools.Query(append(mods,
|
|
sm.Where(PublicreportPools.Columns.ID.EQ(psql.Arg(o.PoolID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportPoolPhotoSlice) Pool(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
|
pkPoolID := make(pgtypes.Array[int32], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkPoolID = append(pkPoolID, o.PoolID)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkPoolID), "integer[]")),
|
|
))
|
|
|
|
return PublicreportPools.Query(append(mods,
|
|
sm.Where(psql.Group(PublicreportPools.Columns.ID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func attachPublicreportPoolPhotoPool0(ctx context.Context, exec bob.Executor, count int, publicreportPoolPhoto0 *PublicreportPoolPhoto, publicreportPool1 *PublicreportPool) (*PublicreportPoolPhoto, error) {
|
|
setter := &PublicreportPoolPhotoSetter{
|
|
PoolID: omit.From(publicreportPool1.ID),
|
|
}
|
|
|
|
err := publicreportPoolPhoto0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportPoolPhotoPool0: %w", err)
|
|
}
|
|
|
|
return publicreportPoolPhoto0, nil
|
|
}
|
|
|
|
func (publicreportPoolPhoto0 *PublicreportPoolPhoto) InsertPool(ctx context.Context, exec bob.Executor, related *PublicreportPoolSetter) error {
|
|
var err error
|
|
|
|
publicreportPool1, err := PublicreportPools.Insert(related).One(ctx, exec)
|
|
if err != nil {
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
|
}
|
|
|
|
_, err = attachPublicreportPoolPhotoPool0(ctx, exec, 1, publicreportPoolPhoto0, publicreportPool1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportPoolPhoto0.R.Pool = publicreportPool1
|
|
|
|
publicreportPool1.R.PoolPhotos = append(publicreportPool1.R.PoolPhotos, publicreportPoolPhoto0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (publicreportPoolPhoto0 *PublicreportPoolPhoto) AttachPool(ctx context.Context, exec bob.Executor, publicreportPool1 *PublicreportPool) error {
|
|
var err error
|
|
|
|
_, err = attachPublicreportPoolPhotoPool0(ctx, exec, 1, publicreportPoolPhoto0, publicreportPool1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportPoolPhoto0.R.Pool = publicreportPool1
|
|
|
|
publicreportPool1.R.PoolPhotos = append(publicreportPool1.R.PoolPhotos, publicreportPoolPhoto0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportPoolPhotoWhere[Q psql.Filterable] struct {
|
|
ID psql.WhereMod[Q, int32]
|
|
Size psql.WhereMod[Q, int64]
|
|
Filename psql.WhereMod[Q, string]
|
|
PoolID psql.WhereMod[Q, int32]
|
|
UUID psql.WhereMod[Q, uuid.UUID]
|
|
}
|
|
|
|
func (publicreportPoolPhotoWhere[Q]) AliasedAs(alias string) publicreportPoolPhotoWhere[Q] {
|
|
return buildPublicreportPoolPhotoWhere[Q](buildPublicreportPoolPhotoColumns(alias))
|
|
}
|
|
|
|
func buildPublicreportPoolPhotoWhere[Q psql.Filterable](cols publicreportPoolPhotoColumns) publicreportPoolPhotoWhere[Q] {
|
|
return publicreportPoolPhotoWhere[Q]{
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
Size: psql.Where[Q, int64](cols.Size),
|
|
Filename: psql.Where[Q, string](cols.Filename),
|
|
PoolID: psql.Where[Q, int32](cols.PoolID),
|
|
UUID: psql.Where[Q, uuid.UUID](cols.UUID),
|
|
}
|
|
}
|
|
|
|
func (o *PublicreportPoolPhoto) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "Pool":
|
|
rel, ok := retrieved.(*PublicreportPool)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportPoolPhoto cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Pool = rel
|
|
|
|
if rel != nil {
|
|
rel.R.PoolPhotos = PublicreportPoolPhotoSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("publicreportPoolPhoto has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type publicreportPoolPhotoPreloader struct {
|
|
Pool func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildPublicreportPoolPhotoPreloader() publicreportPoolPhotoPreloader {
|
|
return publicreportPoolPhotoPreloader{
|
|
Pool: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*PublicreportPool, PublicreportPoolSlice](psql.PreloadRel{
|
|
Name: "Pool",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: PublicreportPoolPhotos,
|
|
To: PublicreportPools,
|
|
FromColumns: []string{"pool_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, PublicreportPools.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type publicreportPoolPhotoThenLoader[Q orm.Loadable] struct {
|
|
Pool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildPublicreportPoolPhotoThenLoader[Q orm.Loadable]() publicreportPoolPhotoThenLoader[Q] {
|
|
type PoolLoadInterface interface {
|
|
LoadPool(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return publicreportPoolPhotoThenLoader[Q]{
|
|
Pool: thenLoadBuilder[Q](
|
|
"Pool",
|
|
func(ctx context.Context, exec bob.Executor, retrieved PoolLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadPool(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadPool loads the publicreportPoolPhoto's Pool into the .R struct
|
|
func (o *PublicreportPoolPhoto) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.Pool = nil
|
|
|
|
related, err := o.Pool(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.PoolPhotos = PublicreportPoolPhotoSlice{o}
|
|
|
|
o.R.Pool = related
|
|
return nil
|
|
}
|
|
|
|
// LoadPool loads the publicreportPoolPhoto's Pool into the .R struct
|
|
func (os PublicreportPoolPhotoSlice) LoadPool(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
publicreportPools, err := os.Pool(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range publicreportPools {
|
|
|
|
if !(o.PoolID == rel.ID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.PoolPhotos = append(rel.R.PoolPhotos, o)
|
|
|
|
o.R.Pool = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportPoolPhotoJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
Pool modAs[Q, publicreportPoolColumns]
|
|
}
|
|
|
|
func (j publicreportPoolPhotoJoins[Q]) aliasedAs(alias string) publicreportPoolPhotoJoins[Q] {
|
|
return buildPublicreportPoolPhotoJoins[Q](buildPublicreportPoolPhotoColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildPublicreportPoolPhotoJoins[Q dialect.Joinable](cols publicreportPoolPhotoColumns, typ string) publicreportPoolPhotoJoins[Q] {
|
|
return publicreportPoolPhotoJoins[Q]{
|
|
typ: typ,
|
|
Pool: modAs[Q, publicreportPoolColumns]{
|
|
c: PublicreportPools.Columns,
|
|
f: func(to publicreportPoolColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, PublicreportPools.Name().As(to.Alias())).On(
|
|
to.ID.EQ(cols.PoolID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
}
|
|
}
|