1167 lines
35 KiB
Go
1167 lines
35 KiB
Go
// Code generated by BobGen psql v0.42.5. 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/Gleipnir-Technology/bob"
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
|
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
|
"github.com/Gleipnir-Technology/bob/expr"
|
|
"github.com/Gleipnir-Technology/bob/orm"
|
|
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
|
"github.com/aarondl/opt/null"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/aarondl/opt/omitnull"
|
|
"github.com/google/uuid"
|
|
"github.com/stephenafamo/scan"
|
|
)
|
|
|
|
// PublicreportImage is an object representing the database table.
|
|
type PublicreportImage struct {
|
|
ID int32 `db:"id,pk" `
|
|
ContentType string `db:"content_type" `
|
|
Created time.Time `db:"created" `
|
|
ResolutionX int32 `db:"resolution_x" `
|
|
ResolutionY int32 `db:"resolution_y" `
|
|
StorageUUID uuid.UUID `db:"storage_uuid" `
|
|
StorageSize int64 `db:"storage_size" `
|
|
UploadedFilename string `db:"uploaded_filename" `
|
|
Location null.Val[string] `db:"location" `
|
|
|
|
R publicreportImageR `db:"-" `
|
|
}
|
|
|
|
// PublicreportImageSlice is an alias for a slice of pointers to PublicreportImage.
|
|
// This should almost always be used instead of []*PublicreportImage.
|
|
type PublicreportImageSlice []*PublicreportImage
|
|
|
|
// PublicreportImages contains methods to work with the image table
|
|
var PublicreportImages = psql.NewTablex[*PublicreportImage, PublicreportImageSlice, *PublicreportImageSetter]("publicreport", "image", buildPublicreportImageColumns("publicreport.image"))
|
|
|
|
// PublicreportImagesQuery is a query on the image table
|
|
type PublicreportImagesQuery = *psql.ViewQuery[*PublicreportImage, PublicreportImageSlice]
|
|
|
|
// publicreportImageR is where relationships are stored.
|
|
type publicreportImageR struct {
|
|
ImageExifs PublicreportImageExifSlice // publicreport.image_exif.image_exif_image_id_fkey
|
|
Nuisances PublicreportNuisanceSlice // publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey
|
|
Pools PublicreportPoolSlice // publicreport.pool_image.pool_image_image_id_fkeypublicreport.pool_image.pool_image_pool_id_fkey
|
|
}
|
|
|
|
func buildPublicreportImageColumns(alias string) publicreportImageColumns {
|
|
return publicreportImageColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "content_type", "created", "resolution_x", "resolution_y", "storage_uuid", "storage_size", "uploaded_filename", "location",
|
|
).WithParent("publicreport.image"),
|
|
tableAlias: alias,
|
|
ID: psql.Quote(alias, "id"),
|
|
ContentType: psql.Quote(alias, "content_type"),
|
|
Created: psql.Quote(alias, "created"),
|
|
ResolutionX: psql.Quote(alias, "resolution_x"),
|
|
ResolutionY: psql.Quote(alias, "resolution_y"),
|
|
StorageUUID: psql.Quote(alias, "storage_uuid"),
|
|
StorageSize: psql.Quote(alias, "storage_size"),
|
|
UploadedFilename: psql.Quote(alias, "uploaded_filename"),
|
|
Location: psql.Quote(alias, "location"),
|
|
}
|
|
}
|
|
|
|
type publicreportImageColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ID psql.Expression
|
|
ContentType psql.Expression
|
|
Created psql.Expression
|
|
ResolutionX psql.Expression
|
|
ResolutionY psql.Expression
|
|
StorageUUID psql.Expression
|
|
StorageSize psql.Expression
|
|
UploadedFilename psql.Expression
|
|
Location psql.Expression
|
|
}
|
|
|
|
func (c publicreportImageColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (publicreportImageColumns) AliasedAs(alias string) publicreportImageColumns {
|
|
return buildPublicreportImageColumns(alias)
|
|
}
|
|
|
|
// PublicreportImageSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type PublicreportImageSetter struct {
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
ContentType omit.Val[string] `db:"content_type" `
|
|
Created omit.Val[time.Time] `db:"created" `
|
|
ResolutionX omit.Val[int32] `db:"resolution_x" `
|
|
ResolutionY omit.Val[int32] `db:"resolution_y" `
|
|
StorageUUID omit.Val[uuid.UUID] `db:"storage_uuid" `
|
|
StorageSize omit.Val[int64] `db:"storage_size" `
|
|
UploadedFilename omit.Val[string] `db:"uploaded_filename" `
|
|
Location omitnull.Val[string] `db:"location" `
|
|
}
|
|
|
|
func (s PublicreportImageSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 9)
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if s.ContentType.IsValue() {
|
|
vals = append(vals, "content_type")
|
|
}
|
|
if s.Created.IsValue() {
|
|
vals = append(vals, "created")
|
|
}
|
|
if s.ResolutionX.IsValue() {
|
|
vals = append(vals, "resolution_x")
|
|
}
|
|
if s.ResolutionY.IsValue() {
|
|
vals = append(vals, "resolution_y")
|
|
}
|
|
if s.StorageUUID.IsValue() {
|
|
vals = append(vals, "storage_uuid")
|
|
}
|
|
if s.StorageSize.IsValue() {
|
|
vals = append(vals, "storage_size")
|
|
}
|
|
if s.UploadedFilename.IsValue() {
|
|
vals = append(vals, "uploaded_filename")
|
|
}
|
|
if !s.Location.IsUnset() {
|
|
vals = append(vals, "location")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s PublicreportImageSetter) Overwrite(t *PublicreportImage) {
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if s.ContentType.IsValue() {
|
|
t.ContentType = s.ContentType.MustGet()
|
|
}
|
|
if s.Created.IsValue() {
|
|
t.Created = s.Created.MustGet()
|
|
}
|
|
if s.ResolutionX.IsValue() {
|
|
t.ResolutionX = s.ResolutionX.MustGet()
|
|
}
|
|
if s.ResolutionY.IsValue() {
|
|
t.ResolutionY = s.ResolutionY.MustGet()
|
|
}
|
|
if s.StorageUUID.IsValue() {
|
|
t.StorageUUID = s.StorageUUID.MustGet()
|
|
}
|
|
if s.StorageSize.IsValue() {
|
|
t.StorageSize = s.StorageSize.MustGet()
|
|
}
|
|
if s.UploadedFilename.IsValue() {
|
|
t.UploadedFilename = s.UploadedFilename.MustGet()
|
|
}
|
|
if !s.Location.IsUnset() {
|
|
t.Location = s.Location.MustGetNull()
|
|
}
|
|
}
|
|
|
|
func (s *PublicreportImageSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return PublicreportImages.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, 9)
|
|
if s.ID.IsValue() {
|
|
vals[0] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.ContentType.IsValue() {
|
|
vals[1] = psql.Arg(s.ContentType.MustGet())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
vals[2] = psql.Arg(s.Created.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.ResolutionX.IsValue() {
|
|
vals[3] = psql.Arg(s.ResolutionX.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.ResolutionY.IsValue() {
|
|
vals[4] = psql.Arg(s.ResolutionY.MustGet())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.StorageUUID.IsValue() {
|
|
vals[5] = psql.Arg(s.StorageUUID.MustGet())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.StorageSize.IsValue() {
|
|
vals[6] = psql.Arg(s.StorageSize.MustGet())
|
|
} else {
|
|
vals[6] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.UploadedFilename.IsValue() {
|
|
vals[7] = psql.Arg(s.UploadedFilename.MustGet())
|
|
} else {
|
|
vals[7] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Location.IsUnset() {
|
|
vals[8] = psql.Arg(s.Location.MustGetNull())
|
|
} else {
|
|
vals[8] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s PublicreportImageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s PublicreportImageSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 9)
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if s.ContentType.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "content_type")...),
|
|
psql.Arg(s.ContentType),
|
|
}})
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "created")...),
|
|
psql.Arg(s.Created),
|
|
}})
|
|
}
|
|
|
|
if s.ResolutionX.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "resolution_x")...),
|
|
psql.Arg(s.ResolutionX),
|
|
}})
|
|
}
|
|
|
|
if s.ResolutionY.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "resolution_y")...),
|
|
psql.Arg(s.ResolutionY),
|
|
}})
|
|
}
|
|
|
|
if s.StorageUUID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "storage_uuid")...),
|
|
psql.Arg(s.StorageUUID),
|
|
}})
|
|
}
|
|
|
|
if s.StorageSize.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "storage_size")...),
|
|
psql.Arg(s.StorageSize),
|
|
}})
|
|
}
|
|
|
|
if s.UploadedFilename.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "uploaded_filename")...),
|
|
psql.Arg(s.UploadedFilename),
|
|
}})
|
|
}
|
|
|
|
if !s.Location.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "location")...),
|
|
psql.Arg(s.Location),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindPublicreportImage retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindPublicreportImage(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*PublicreportImage, error) {
|
|
if len(cols) == 0 {
|
|
return PublicreportImages.Query(
|
|
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return PublicreportImages.Query(
|
|
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(PublicreportImages.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// PublicreportImageExists checks the presence of a single record by primary key
|
|
func PublicreportImageExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return PublicreportImages.Query(
|
|
sm.Where(PublicreportImages.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after PublicreportImage is retrieved from the database
|
|
func (o *PublicreportImage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportImages.AfterSelectHooks.RunHooks(ctx, exec, PublicreportImageSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportImages.AfterInsertHooks.RunHooks(ctx, exec, PublicreportImageSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportImages.AfterUpdateHooks.RunHooks(ctx, exec, PublicreportImageSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportImages.AfterDeleteHooks.RunHooks(ctx, exec, PublicreportImageSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the PublicreportImage
|
|
func (o *PublicreportImage) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *PublicreportImage) pkEQ() dialect.Expression {
|
|
return psql.Quote("publicreport.image", "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 PublicreportImage
|
|
func (o *PublicreportImage) Update(ctx context.Context, exec bob.Executor, s *PublicreportImageSetter) error {
|
|
v, err := PublicreportImages.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 PublicreportImage record with an executor
|
|
func (o *PublicreportImage) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := PublicreportImages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the PublicreportImage using the executor
|
|
func (o *PublicreportImage) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := PublicreportImages.Query(
|
|
sm.Where(PublicreportImages.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 PublicreportImageSlice is retrieved from the database
|
|
func (o PublicreportImageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = PublicreportImages.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = PublicreportImages.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = PublicreportImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = PublicreportImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportImageSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("publicreport.image", "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 PublicreportImageSlice) copyMatchingRows(from ...*PublicreportImage) {
|
|
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 PublicreportImageSlice) 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 PublicreportImages.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 *PublicreportImage:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportImage:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportImageSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportImage or a slice of PublicreportImage
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = PublicreportImages.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o PublicreportImageSlice) 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 PublicreportImages.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 *PublicreportImage:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*PublicreportImage:
|
|
o.copyMatchingRows(retrieved...)
|
|
case PublicreportImageSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a PublicreportImage or a slice of PublicreportImage
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = PublicreportImages.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o PublicreportImageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PublicreportImageSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportImages.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportImageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := PublicreportImages.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o PublicreportImageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := PublicreportImages.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// ImageExifs starts a query for related objects on publicreport.image_exif
|
|
func (o *PublicreportImage) ImageExifs(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImageExifsQuery {
|
|
return PublicreportImageExifs.Query(append(mods,
|
|
sm.Where(PublicreportImageExifs.Columns.ImageID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportImageSlice) ImageExifs(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImageExifsQuery {
|
|
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 PublicreportImageExifs.Query(append(mods,
|
|
sm.Where(psql.Group(PublicreportImageExifs.Columns.ImageID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// Nuisances starts a query for related objects on publicreport.nuisance
|
|
func (o *PublicreportImage) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
|
|
return PublicreportNuisances.Query(append(mods,
|
|
sm.InnerJoin(PublicreportNuisanceImages.NameAs()).On(
|
|
PublicreportNuisances.Columns.ID.EQ(PublicreportNuisanceImages.Columns.NuisanceID)),
|
|
sm.Where(PublicreportNuisanceImages.Columns.ImageID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportImageSlice) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
|
|
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 PublicreportNuisances.Query(append(mods,
|
|
sm.InnerJoin(PublicreportNuisanceImages.NameAs()).On(
|
|
PublicreportNuisances.Columns.ID.EQ(PublicreportNuisanceImages.Columns.NuisanceID),
|
|
),
|
|
sm.Where(psql.Group(PublicreportNuisanceImages.Columns.ImageID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// Pools starts a query for related objects on publicreport.pool
|
|
func (o *PublicreportImage) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
|
return PublicreportPools.Query(append(mods,
|
|
sm.InnerJoin(PublicreportPoolImages.NameAs()).On(
|
|
PublicreportPools.Columns.ID.EQ(PublicreportPoolImages.Columns.PoolID)),
|
|
sm.Where(PublicreportPoolImages.Columns.ImageID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os PublicreportImageSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportPoolsQuery {
|
|
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 PublicreportPools.Query(append(mods,
|
|
sm.InnerJoin(PublicreportPoolImages.NameAs()).On(
|
|
PublicreportPools.Columns.ID.EQ(PublicreportPoolImages.Columns.PoolID),
|
|
),
|
|
sm.Where(psql.Group(PublicreportPoolImages.Columns.ImageID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func insertPublicreportImageImageExifs0(ctx context.Context, exec bob.Executor, publicreportImageExifs1 []*PublicreportImageExifSetter, publicreportImage0 *PublicreportImage) (PublicreportImageExifSlice, error) {
|
|
for i := range publicreportImageExifs1 {
|
|
publicreportImageExifs1[i].ImageID = omit.From(publicreportImage0.ID)
|
|
}
|
|
|
|
ret, err := PublicreportImageExifs.Insert(bob.ToMods(publicreportImageExifs1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertPublicreportImageImageExifs0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachPublicreportImageImageExifs0(ctx context.Context, exec bob.Executor, count int, publicreportImageExifs1 PublicreportImageExifSlice, publicreportImage0 *PublicreportImage) (PublicreportImageExifSlice, error) {
|
|
setter := &PublicreportImageExifSetter{
|
|
ImageID: omit.From(publicreportImage0.ID),
|
|
}
|
|
|
|
err := publicreportImageExifs1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportImageImageExifs0: %w", err)
|
|
}
|
|
|
|
return publicreportImageExifs1, nil
|
|
}
|
|
|
|
func (publicreportImage0 *PublicreportImage) InsertImageExifs(ctx context.Context, exec bob.Executor, related ...*PublicreportImageExifSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
publicreportImageExifs1, err := insertPublicreportImageImageExifs0(ctx, exec, related, publicreportImage0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportImage0.R.ImageExifs = append(publicreportImage0.R.ImageExifs, publicreportImageExifs1...)
|
|
|
|
for _, rel := range publicreportImageExifs1 {
|
|
rel.R.Image = publicreportImage0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (publicreportImage0 *PublicreportImage) AttachImageExifs(ctx context.Context, exec bob.Executor, related ...*PublicreportImageExif) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
publicreportImageExifs1 := PublicreportImageExifSlice(related)
|
|
|
|
_, err = attachPublicreportImageImageExifs0(ctx, exec, len(related), publicreportImageExifs1, publicreportImage0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportImage0.R.ImageExifs = append(publicreportImage0.R.ImageExifs, publicreportImageExifs1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.Image = publicreportImage0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func attachPublicreportImageNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportNuisances2 PublicreportNuisanceSlice) (PublicreportNuisanceImageSlice, error) {
|
|
setters := make([]*PublicreportNuisanceImageSetter, count)
|
|
for i := range count {
|
|
setters[i] = &PublicreportNuisanceImageSetter{
|
|
ImageID: omit.From(publicreportImage0.ID),
|
|
NuisanceID: omit.From(publicreportNuisances2[i].ID),
|
|
}
|
|
}
|
|
|
|
publicreportNuisanceImages1, err := PublicreportNuisanceImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportImageNuisances0: %w", err)
|
|
}
|
|
|
|
return publicreportNuisanceImages1, nil
|
|
}
|
|
|
|
func (publicreportImage0 *PublicreportImage) InsertNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
inserted, err := PublicreportNuisances.Insert(bob.ToMods(related...)).All(ctx, exec)
|
|
if err != nil {
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
|
}
|
|
publicreportNuisances2 := PublicreportNuisanceSlice(inserted)
|
|
|
|
_, err = attachPublicreportImageNuisances0(ctx, exec, len(related), publicreportImage0, publicreportNuisances2)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportImage0.R.Nuisances = append(publicreportImage0.R.Nuisances, publicreportNuisances2...)
|
|
|
|
for _, rel := range publicreportNuisances2 {
|
|
rel.R.Images = append(rel.R.Images, publicreportImage0)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (publicreportImage0 *PublicreportImage) AttachNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
publicreportNuisances2 := PublicreportNuisanceSlice(related)
|
|
|
|
_, err = attachPublicreportImageNuisances0(ctx, exec, len(related), publicreportImage0, publicreportNuisances2)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportImage0.R.Nuisances = append(publicreportImage0.R.Nuisances, publicreportNuisances2...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.Images = append(rel.R.Images, publicreportImage0)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func attachPublicreportImagePools0(ctx context.Context, exec bob.Executor, count int, publicreportImage0 *PublicreportImage, publicreportPools2 PublicreportPoolSlice) (PublicreportPoolImageSlice, error) {
|
|
setters := make([]*PublicreportPoolImageSetter, count)
|
|
for i := range count {
|
|
setters[i] = &PublicreportPoolImageSetter{
|
|
ImageID: omit.From(publicreportImage0.ID),
|
|
PoolID: omit.From(publicreportPools2[i].ID),
|
|
}
|
|
}
|
|
|
|
publicreportPoolImages1, err := PublicreportPoolImages.Insert(bob.ToMods(setters...)).All(ctx, exec)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachPublicreportImagePools0: %w", err)
|
|
}
|
|
|
|
return publicreportPoolImages1, nil
|
|
}
|
|
|
|
func (publicreportImage0 *PublicreportImage) InsertPools(ctx context.Context, exec bob.Executor, related ...*PublicreportPoolSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
inserted, err := PublicreportPools.Insert(bob.ToMods(related...)).All(ctx, exec)
|
|
if err != nil {
|
|
return fmt.Errorf("inserting related objects: %w", err)
|
|
}
|
|
publicreportPools2 := PublicreportPoolSlice(inserted)
|
|
|
|
_, err = attachPublicreportImagePools0(ctx, exec, len(related), publicreportImage0, publicreportPools2)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportImage0.R.Pools = append(publicreportImage0.R.Pools, publicreportPools2...)
|
|
|
|
for _, rel := range publicreportPools2 {
|
|
rel.R.Images = append(rel.R.Images, publicreportImage0)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (publicreportImage0 *PublicreportImage) AttachPools(ctx context.Context, exec bob.Executor, related ...*PublicreportPool) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
publicreportPools2 := PublicreportPoolSlice(related)
|
|
|
|
_, err = attachPublicreportImagePools0(ctx, exec, len(related), publicreportImage0, publicreportPools2)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
publicreportImage0.R.Pools = append(publicreportImage0.R.Pools, publicreportPools2...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.Images = append(rel.R.Images, publicreportImage0)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type publicreportImageWhere[Q psql.Filterable] struct {
|
|
ID psql.WhereMod[Q, int32]
|
|
ContentType psql.WhereMod[Q, string]
|
|
Created psql.WhereMod[Q, time.Time]
|
|
ResolutionX psql.WhereMod[Q, int32]
|
|
ResolutionY psql.WhereMod[Q, int32]
|
|
StorageUUID psql.WhereMod[Q, uuid.UUID]
|
|
StorageSize psql.WhereMod[Q, int64]
|
|
UploadedFilename psql.WhereMod[Q, string]
|
|
Location psql.WhereNullMod[Q, string]
|
|
}
|
|
|
|
func (publicreportImageWhere[Q]) AliasedAs(alias string) publicreportImageWhere[Q] {
|
|
return buildPublicreportImageWhere[Q](buildPublicreportImageColumns(alias))
|
|
}
|
|
|
|
func buildPublicreportImageWhere[Q psql.Filterable](cols publicreportImageColumns) publicreportImageWhere[Q] {
|
|
return publicreportImageWhere[Q]{
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
ContentType: psql.Where[Q, string](cols.ContentType),
|
|
Created: psql.Where[Q, time.Time](cols.Created),
|
|
ResolutionX: psql.Where[Q, int32](cols.ResolutionX),
|
|
ResolutionY: psql.Where[Q, int32](cols.ResolutionY),
|
|
StorageUUID: psql.Where[Q, uuid.UUID](cols.StorageUUID),
|
|
StorageSize: psql.Where[Q, int64](cols.StorageSize),
|
|
UploadedFilename: psql.Where[Q, string](cols.UploadedFilename),
|
|
Location: psql.WhereNull[Q, string](cols.Location),
|
|
}
|
|
}
|
|
|
|
func (o *PublicreportImage) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "ImageExifs":
|
|
rels, ok := retrieved.(PublicreportImageExifSlice)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.ImageExifs = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.Image = o
|
|
}
|
|
}
|
|
return nil
|
|
case "Nuisances":
|
|
rels, ok := retrieved.(PublicreportNuisanceSlice)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Nuisances = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.Images = PublicreportImageSlice{o}
|
|
}
|
|
}
|
|
return nil
|
|
case "Pools":
|
|
rels, ok := retrieved.(PublicreportPoolSlice)
|
|
if !ok {
|
|
return fmt.Errorf("publicreportImage cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Pools = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.Images = PublicreportImageSlice{o}
|
|
}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("publicreportImage has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type publicreportImagePreloader struct{}
|
|
|
|
func buildPublicreportImagePreloader() publicreportImagePreloader {
|
|
return publicreportImagePreloader{}
|
|
}
|
|
|
|
type publicreportImageThenLoader[Q orm.Loadable] struct {
|
|
ImageExifs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildPublicreportImageThenLoader[Q orm.Loadable]() publicreportImageThenLoader[Q] {
|
|
type ImageExifsLoadInterface interface {
|
|
LoadImageExifs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type NuisancesLoadInterface interface {
|
|
LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type PoolsLoadInterface interface {
|
|
LoadPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return publicreportImageThenLoader[Q]{
|
|
ImageExifs: thenLoadBuilder[Q](
|
|
"ImageExifs",
|
|
func(ctx context.Context, exec bob.Executor, retrieved ImageExifsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadImageExifs(ctx, exec, mods...)
|
|
},
|
|
),
|
|
Nuisances: thenLoadBuilder[Q](
|
|
"Nuisances",
|
|
func(ctx context.Context, exec bob.Executor, retrieved NuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadNuisances(ctx, exec, mods...)
|
|
},
|
|
),
|
|
Pools: thenLoadBuilder[Q](
|
|
"Pools",
|
|
func(ctx context.Context, exec bob.Executor, retrieved PoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadPools(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadImageExifs loads the publicreportImage's ImageExifs into the .R struct
|
|
func (o *PublicreportImage) LoadImageExifs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.ImageExifs = nil
|
|
|
|
related, err := o.ImageExifs(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.Image = o
|
|
}
|
|
|
|
o.R.ImageExifs = related
|
|
return nil
|
|
}
|
|
|
|
// LoadImageExifs loads the publicreportImage's ImageExifs into the .R struct
|
|
func (os PublicreportImageSlice) LoadImageExifs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
publicreportImageExifs, err := os.ImageExifs(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.ImageExifs = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range publicreportImageExifs {
|
|
|
|
if !(o.ID == rel.ImageID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.Image = o
|
|
|
|
o.R.ImageExifs = append(o.R.ImageExifs, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadNuisances loads the publicreportImage's Nuisances into the .R struct
|
|
func (o *PublicreportImage) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.Nuisances = nil
|
|
|
|
related, err := o.Nuisances(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.Images = PublicreportImageSlice{o}
|
|
}
|
|
|
|
o.R.Nuisances = related
|
|
return nil
|
|
}
|
|
|
|
// LoadNuisances loads the publicreportImage's Nuisances into the .R struct
|
|
func (os PublicreportImageSlice) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
// since we are changing the columns, we need to check if the original columns were set or add the defaults
|
|
sq := dialect.SelectQuery{}
|
|
for _, mod := range mods {
|
|
mod.Apply(&sq)
|
|
}
|
|
|
|
if len(sq.SelectList.Columns) == 0 {
|
|
mods = append(mods, sm.Columns(PublicreportNuisances.Columns))
|
|
}
|
|
|
|
q := os.Nuisances(append(
|
|
mods,
|
|
sm.Columns(PublicreportNuisanceImages.Columns.ImageID.As("related_publicreport.image.ID")),
|
|
)...)
|
|
|
|
IDSlice := []int32{}
|
|
|
|
mapper := scan.Mod(scan.StructMapper[*PublicreportNuisance](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
|
|
return func(row *scan.Row) (any, error) {
|
|
IDSlice = append(IDSlice, *new(int32))
|
|
row.ScheduleScanByName("related_publicreport.image.ID", &IDSlice[len(IDSlice)-1])
|
|
|
|
return nil, nil
|
|
},
|
|
func(any, any) error {
|
|
return nil
|
|
}
|
|
})
|
|
|
|
publicreportNuisances, err := bob.Allx[bob.SliceTransformer[*PublicreportNuisance, PublicreportNuisanceSlice]](ctx, exec, q, mapper)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
o.R.Nuisances = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
for i, rel := range publicreportNuisances {
|
|
if !(o.ID == IDSlice[i]) {
|
|
continue
|
|
}
|
|
|
|
rel.R.Images = append(rel.R.Images, o)
|
|
|
|
o.R.Nuisances = append(o.R.Nuisances, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadPools loads the publicreportImage's Pools into the .R struct
|
|
func (o *PublicreportImage) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.Pools = nil
|
|
|
|
related, err := o.Pools(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.Images = PublicreportImageSlice{o}
|
|
}
|
|
|
|
o.R.Pools = related
|
|
return nil
|
|
}
|
|
|
|
// LoadPools loads the publicreportImage's Pools into the .R struct
|
|
func (os PublicreportImageSlice) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
// since we are changing the columns, we need to check if the original columns were set or add the defaults
|
|
sq := dialect.SelectQuery{}
|
|
for _, mod := range mods {
|
|
mod.Apply(&sq)
|
|
}
|
|
|
|
if len(sq.SelectList.Columns) == 0 {
|
|
mods = append(mods, sm.Columns(PublicreportPools.Columns))
|
|
}
|
|
|
|
q := os.Pools(append(
|
|
mods,
|
|
sm.Columns(PublicreportPoolImages.Columns.ImageID.As("related_publicreport.image.ID")),
|
|
)...)
|
|
|
|
IDSlice := []int32{}
|
|
|
|
mapper := scan.Mod(scan.StructMapper[*PublicreportPool](), func(ctx context.Context, cols []string) (scan.BeforeFunc, func(any, any) error) {
|
|
return func(row *scan.Row) (any, error) {
|
|
IDSlice = append(IDSlice, *new(int32))
|
|
row.ScheduleScanByName("related_publicreport.image.ID", &IDSlice[len(IDSlice)-1])
|
|
|
|
return nil, nil
|
|
},
|
|
func(any, any) error {
|
|
return nil
|
|
}
|
|
})
|
|
|
|
publicreportPools, err := bob.Allx[bob.SliceTransformer[*PublicreportPool, PublicreportPoolSlice]](ctx, exec, q, mapper)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
o.R.Pools = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
for i, rel := range publicreportPools {
|
|
if !(o.ID == IDSlice[i]) {
|
|
continue
|
|
}
|
|
|
|
rel.R.Images = append(rel.R.Images, o)
|
|
|
|
o.R.Pools = append(o.R.Pools, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|