nidus-sync/db/models/fileupload.pool.bob.go

1816 lines
55 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/mods"
"github.com/Gleipnir-Technology/bob/orm"
"github.com/Gleipnir-Technology/bob/types/pgtypes"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/null"
"github.com/aarondl/opt/omit"
"github.com/aarondl/opt/omitnull"
)
// FileuploadPool is an object representing the database table.
type FileuploadPool struct {
AddressCity string `db:"address_city" `
AddressPostalCode string `db:"address_postal_code" `
AddressStreet string `db:"address_street" `
Committed bool `db:"committed" `
Condition enums.FileuploadPoolconditiontype `db:"condition" `
Created time.Time `db:"created" `
CreatorID int32 `db:"creator_id" `
CSVFile int32 `db:"csv_file" `
Deleted null.Val[time.Time] `db:"deleted" `
Geom null.Val[string] `db:"geom" `
H3cell null.Val[string] `db:"h3cell" `
ID int32 `db:"id,pk" `
IsInDistrict bool `db:"is_in_district" `
IsNew bool `db:"is_new" `
Notes string `db:"notes" `
OrganizationID int32 `db:"organization_id" `
PropertyOwnerName string `db:"property_owner_name" `
PropertyOwnerPhoneE164 null.Val[string] `db:"property_owner_phone_e164" `
ResidentOwned null.Val[bool] `db:"resident_owned" `
ResidentPhoneE164 null.Val[string] `db:"resident_phone_e164" `
LineNumber int32 `db:"line_number" `
Tags pgtypes.HStore `db:"tags" `
R fileuploadPoolR `db:"-" `
}
// FileuploadPoolSlice is an alias for a slice of pointers to FileuploadPool.
// This should almost always be used instead of []*FileuploadPool.
type FileuploadPoolSlice []*FileuploadPool
// FileuploadPools contains methods to work with the pool table
var FileuploadPools = psql.NewTablex[*FileuploadPool, FileuploadPoolSlice, *FileuploadPoolSetter]("fileupload", "pool", buildFileuploadPoolColumns("fileupload.pool"))
// FileuploadPoolsQuery is a query on the pool table
type FileuploadPoolsQuery = *psql.ViewQuery[*FileuploadPool, FileuploadPoolSlice]
// fileuploadPoolR is where relationships are stored.
type fileuploadPoolR struct {
CreatorUser *User // fileupload.pool.pool_creator_id_fkey
CSVFileCSV *FileuploadCSV // fileupload.pool.pool_csv_file_fkey
Organization *Organization // fileupload.pool.pool_organization_id_fkey
PropertyOwnerPhoneE164Phone *CommsPhone // fileupload.pool.pool_property_owner_phone_e164_fkey
ResidentPhoneE164Phone *CommsPhone // fileupload.pool.pool_resident_phone_e164_fkey
}
func buildFileuploadPoolColumns(alias string) fileuploadPoolColumns {
return fileuploadPoolColumns{
ColumnsExpr: expr.NewColumnsExpr(
"address_city", "address_postal_code", "address_street", "committed", "condition", "created", "creator_id", "csv_file", "deleted", "geom", "h3cell", "id", "is_in_district", "is_new", "notes", "organization_id", "property_owner_name", "property_owner_phone_e164", "resident_owned", "resident_phone_e164", "line_number", "tags",
).WithParent("fileupload.pool"),
tableAlias: alias,
AddressCity: psql.Quote(alias, "address_city"),
AddressPostalCode: psql.Quote(alias, "address_postal_code"),
AddressStreet: psql.Quote(alias, "address_street"),
Committed: psql.Quote(alias, "committed"),
Condition: psql.Quote(alias, "condition"),
Created: psql.Quote(alias, "created"),
CreatorID: psql.Quote(alias, "creator_id"),
CSVFile: psql.Quote(alias, "csv_file"),
Deleted: psql.Quote(alias, "deleted"),
Geom: psql.Quote(alias, "geom"),
H3cell: psql.Quote(alias, "h3cell"),
ID: psql.Quote(alias, "id"),
IsInDistrict: psql.Quote(alias, "is_in_district"),
IsNew: psql.Quote(alias, "is_new"),
Notes: psql.Quote(alias, "notes"),
OrganizationID: psql.Quote(alias, "organization_id"),
PropertyOwnerName: psql.Quote(alias, "property_owner_name"),
PropertyOwnerPhoneE164: psql.Quote(alias, "property_owner_phone_e164"),
ResidentOwned: psql.Quote(alias, "resident_owned"),
ResidentPhoneE164: psql.Quote(alias, "resident_phone_e164"),
LineNumber: psql.Quote(alias, "line_number"),
Tags: psql.Quote(alias, "tags"),
}
}
type fileuploadPoolColumns struct {
expr.ColumnsExpr
tableAlias string
AddressCity psql.Expression
AddressPostalCode psql.Expression
AddressStreet psql.Expression
Committed psql.Expression
Condition psql.Expression
Created psql.Expression
CreatorID psql.Expression
CSVFile psql.Expression
Deleted psql.Expression
Geom psql.Expression
H3cell psql.Expression
ID psql.Expression
IsInDistrict psql.Expression
IsNew psql.Expression
Notes psql.Expression
OrganizationID psql.Expression
PropertyOwnerName psql.Expression
PropertyOwnerPhoneE164 psql.Expression
ResidentOwned psql.Expression
ResidentPhoneE164 psql.Expression
LineNumber psql.Expression
Tags psql.Expression
}
func (c fileuploadPoolColumns) Alias() string {
return c.tableAlias
}
func (fileuploadPoolColumns) AliasedAs(alias string) fileuploadPoolColumns {
return buildFileuploadPoolColumns(alias)
}
// FileuploadPoolSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type FileuploadPoolSetter struct {
AddressCity omit.Val[string] `db:"address_city" `
AddressPostalCode omit.Val[string] `db:"address_postal_code" `
AddressStreet omit.Val[string] `db:"address_street" `
Committed omit.Val[bool] `db:"committed" `
Condition omit.Val[enums.FileuploadPoolconditiontype] `db:"condition" `
Created omit.Val[time.Time] `db:"created" `
CreatorID omit.Val[int32] `db:"creator_id" `
CSVFile omit.Val[int32] `db:"csv_file" `
Deleted omitnull.Val[time.Time] `db:"deleted" `
Geom omitnull.Val[string] `db:"geom" `
H3cell omitnull.Val[string] `db:"h3cell" `
ID omit.Val[int32] `db:"id,pk" `
IsInDistrict omit.Val[bool] `db:"is_in_district" `
IsNew omit.Val[bool] `db:"is_new" `
Notes omit.Val[string] `db:"notes" `
OrganizationID omit.Val[int32] `db:"organization_id" `
PropertyOwnerName omit.Val[string] `db:"property_owner_name" `
PropertyOwnerPhoneE164 omitnull.Val[string] `db:"property_owner_phone_e164" `
ResidentOwned omitnull.Val[bool] `db:"resident_owned" `
ResidentPhoneE164 omitnull.Val[string] `db:"resident_phone_e164" `
LineNumber omit.Val[int32] `db:"line_number" `
Tags omit.Val[pgtypes.HStore] `db:"tags" `
}
func (s FileuploadPoolSetter) SetColumns() []string {
vals := make([]string, 0, 22)
if s.AddressCity.IsValue() {
vals = append(vals, "address_city")
}
if s.AddressPostalCode.IsValue() {
vals = append(vals, "address_postal_code")
}
if s.AddressStreet.IsValue() {
vals = append(vals, "address_street")
}
if s.Committed.IsValue() {
vals = append(vals, "committed")
}
if s.Condition.IsValue() {
vals = append(vals, "condition")
}
if s.Created.IsValue() {
vals = append(vals, "created")
}
if s.CreatorID.IsValue() {
vals = append(vals, "creator_id")
}
if s.CSVFile.IsValue() {
vals = append(vals, "csv_file")
}
if !s.Deleted.IsUnset() {
vals = append(vals, "deleted")
}
if !s.Geom.IsUnset() {
vals = append(vals, "geom")
}
if !s.H3cell.IsUnset() {
vals = append(vals, "h3cell")
}
if s.ID.IsValue() {
vals = append(vals, "id")
}
if s.IsInDistrict.IsValue() {
vals = append(vals, "is_in_district")
}
if s.IsNew.IsValue() {
vals = append(vals, "is_new")
}
if s.Notes.IsValue() {
vals = append(vals, "notes")
}
if s.OrganizationID.IsValue() {
vals = append(vals, "organization_id")
}
if s.PropertyOwnerName.IsValue() {
vals = append(vals, "property_owner_name")
}
if !s.PropertyOwnerPhoneE164.IsUnset() {
vals = append(vals, "property_owner_phone_e164")
}
if !s.ResidentOwned.IsUnset() {
vals = append(vals, "resident_owned")
}
if !s.ResidentPhoneE164.IsUnset() {
vals = append(vals, "resident_phone_e164")
}
if s.LineNumber.IsValue() {
vals = append(vals, "line_number")
}
if s.Tags.IsValue() {
vals = append(vals, "tags")
}
return vals
}
func (s FileuploadPoolSetter) Overwrite(t *FileuploadPool) {
if s.AddressCity.IsValue() {
t.AddressCity = s.AddressCity.MustGet()
}
if s.AddressPostalCode.IsValue() {
t.AddressPostalCode = s.AddressPostalCode.MustGet()
}
if s.AddressStreet.IsValue() {
t.AddressStreet = s.AddressStreet.MustGet()
}
if s.Committed.IsValue() {
t.Committed = s.Committed.MustGet()
}
if s.Condition.IsValue() {
t.Condition = s.Condition.MustGet()
}
if s.Created.IsValue() {
t.Created = s.Created.MustGet()
}
if s.CreatorID.IsValue() {
t.CreatorID = s.CreatorID.MustGet()
}
if s.CSVFile.IsValue() {
t.CSVFile = s.CSVFile.MustGet()
}
if !s.Deleted.IsUnset() {
t.Deleted = s.Deleted.MustGetNull()
}
if !s.Geom.IsUnset() {
t.Geom = s.Geom.MustGetNull()
}
if !s.H3cell.IsUnset() {
t.H3cell = s.H3cell.MustGetNull()
}
if s.ID.IsValue() {
t.ID = s.ID.MustGet()
}
if s.IsInDistrict.IsValue() {
t.IsInDistrict = s.IsInDistrict.MustGet()
}
if s.IsNew.IsValue() {
t.IsNew = s.IsNew.MustGet()
}
if s.Notes.IsValue() {
t.Notes = s.Notes.MustGet()
}
if s.OrganizationID.IsValue() {
t.OrganizationID = s.OrganizationID.MustGet()
}
if s.PropertyOwnerName.IsValue() {
t.PropertyOwnerName = s.PropertyOwnerName.MustGet()
}
if !s.PropertyOwnerPhoneE164.IsUnset() {
t.PropertyOwnerPhoneE164 = s.PropertyOwnerPhoneE164.MustGetNull()
}
if !s.ResidentOwned.IsUnset() {
t.ResidentOwned = s.ResidentOwned.MustGetNull()
}
if !s.ResidentPhoneE164.IsUnset() {
t.ResidentPhoneE164 = s.ResidentPhoneE164.MustGetNull()
}
if s.LineNumber.IsValue() {
t.LineNumber = s.LineNumber.MustGet()
}
if s.Tags.IsValue() {
t.Tags = s.Tags.MustGet()
}
}
func (s *FileuploadPoolSetter) Apply(q *dialect.InsertQuery) {
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
return FileuploadPools.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, 22)
if s.AddressCity.IsValue() {
vals[0] = psql.Arg(s.AddressCity.MustGet())
} else {
vals[0] = psql.Raw("DEFAULT")
}
if s.AddressPostalCode.IsValue() {
vals[1] = psql.Arg(s.AddressPostalCode.MustGet())
} else {
vals[1] = psql.Raw("DEFAULT")
}
if s.AddressStreet.IsValue() {
vals[2] = psql.Arg(s.AddressStreet.MustGet())
} else {
vals[2] = psql.Raw("DEFAULT")
}
if s.Committed.IsValue() {
vals[3] = psql.Arg(s.Committed.MustGet())
} else {
vals[3] = psql.Raw("DEFAULT")
}
if s.Condition.IsValue() {
vals[4] = psql.Arg(s.Condition.MustGet())
} else {
vals[4] = psql.Raw("DEFAULT")
}
if s.Created.IsValue() {
vals[5] = psql.Arg(s.Created.MustGet())
} else {
vals[5] = psql.Raw("DEFAULT")
}
if s.CreatorID.IsValue() {
vals[6] = psql.Arg(s.CreatorID.MustGet())
} else {
vals[6] = psql.Raw("DEFAULT")
}
if s.CSVFile.IsValue() {
vals[7] = psql.Arg(s.CSVFile.MustGet())
} else {
vals[7] = psql.Raw("DEFAULT")
}
if !s.Deleted.IsUnset() {
vals[8] = psql.Arg(s.Deleted.MustGetNull())
} else {
vals[8] = psql.Raw("DEFAULT")
}
if !s.Geom.IsUnset() {
vals[9] = psql.Arg(s.Geom.MustGetNull())
} else {
vals[9] = psql.Raw("DEFAULT")
}
if !s.H3cell.IsUnset() {
vals[10] = psql.Arg(s.H3cell.MustGetNull())
} else {
vals[10] = psql.Raw("DEFAULT")
}
if s.ID.IsValue() {
vals[11] = psql.Arg(s.ID.MustGet())
} else {
vals[11] = psql.Raw("DEFAULT")
}
if s.IsInDistrict.IsValue() {
vals[12] = psql.Arg(s.IsInDistrict.MustGet())
} else {
vals[12] = psql.Raw("DEFAULT")
}
if s.IsNew.IsValue() {
vals[13] = psql.Arg(s.IsNew.MustGet())
} else {
vals[13] = psql.Raw("DEFAULT")
}
if s.Notes.IsValue() {
vals[14] = psql.Arg(s.Notes.MustGet())
} else {
vals[14] = psql.Raw("DEFAULT")
}
if s.OrganizationID.IsValue() {
vals[15] = psql.Arg(s.OrganizationID.MustGet())
} else {
vals[15] = psql.Raw("DEFAULT")
}
if s.PropertyOwnerName.IsValue() {
vals[16] = psql.Arg(s.PropertyOwnerName.MustGet())
} else {
vals[16] = psql.Raw("DEFAULT")
}
if !s.PropertyOwnerPhoneE164.IsUnset() {
vals[17] = psql.Arg(s.PropertyOwnerPhoneE164.MustGetNull())
} else {
vals[17] = psql.Raw("DEFAULT")
}
if !s.ResidentOwned.IsUnset() {
vals[18] = psql.Arg(s.ResidentOwned.MustGetNull())
} else {
vals[18] = psql.Raw("DEFAULT")
}
if !s.ResidentPhoneE164.IsUnset() {
vals[19] = psql.Arg(s.ResidentPhoneE164.MustGetNull())
} else {
vals[19] = psql.Raw("DEFAULT")
}
if s.LineNumber.IsValue() {
vals[20] = psql.Arg(s.LineNumber.MustGet())
} else {
vals[20] = psql.Raw("DEFAULT")
}
if s.Tags.IsValue() {
vals[21] = psql.Arg(s.Tags.MustGet())
} else {
vals[21] = psql.Raw("DEFAULT")
}
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
}))
}
func (s FileuploadPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
return um.Set(s.Expressions()...)
}
func (s FileuploadPoolSetter) Expressions(prefix ...string) []bob.Expression {
exprs := make([]bob.Expression, 0, 22)
if s.AddressCity.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "address_city")...),
psql.Arg(s.AddressCity),
}})
}
if s.AddressPostalCode.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "address_postal_code")...),
psql.Arg(s.AddressPostalCode),
}})
}
if s.AddressStreet.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "address_street")...),
psql.Arg(s.AddressStreet),
}})
}
if s.Committed.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "committed")...),
psql.Arg(s.Committed),
}})
}
if s.Condition.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "condition")...),
psql.Arg(s.Condition),
}})
}
if s.Created.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "created")...),
psql.Arg(s.Created),
}})
}
if s.CreatorID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "creator_id")...),
psql.Arg(s.CreatorID),
}})
}
if s.CSVFile.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "csv_file")...),
psql.Arg(s.CSVFile),
}})
}
if !s.Deleted.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "deleted")...),
psql.Arg(s.Deleted),
}})
}
if !s.Geom.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "geom")...),
psql.Arg(s.Geom),
}})
}
if !s.H3cell.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "h3cell")...),
psql.Arg(s.H3cell),
}})
}
if s.ID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "id")...),
psql.Arg(s.ID),
}})
}
if s.IsInDistrict.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "is_in_district")...),
psql.Arg(s.IsInDistrict),
}})
}
if s.IsNew.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "is_new")...),
psql.Arg(s.IsNew),
}})
}
if s.Notes.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "notes")...),
psql.Arg(s.Notes),
}})
}
if s.OrganizationID.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "organization_id")...),
psql.Arg(s.OrganizationID),
}})
}
if s.PropertyOwnerName.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "property_owner_name")...),
psql.Arg(s.PropertyOwnerName),
}})
}
if !s.PropertyOwnerPhoneE164.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "property_owner_phone_e164")...),
psql.Arg(s.PropertyOwnerPhoneE164),
}})
}
if !s.ResidentOwned.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "resident_owned")...),
psql.Arg(s.ResidentOwned),
}})
}
if !s.ResidentPhoneE164.IsUnset() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "resident_phone_e164")...),
psql.Arg(s.ResidentPhoneE164),
}})
}
if s.LineNumber.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "line_number")...),
psql.Arg(s.LineNumber),
}})
}
if s.Tags.IsValue() {
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
psql.Quote(append(prefix, "tags")...),
psql.Arg(s.Tags),
}})
}
return exprs
}
// FindFileuploadPool retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindFileuploadPool(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*FileuploadPool, error) {
if len(cols) == 0 {
return FileuploadPools.Query(
sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(IDPK))),
).One(ctx, exec)
}
return FileuploadPools.Query(
sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(IDPK))),
sm.Columns(FileuploadPools.Columns.Only(cols...)),
).One(ctx, exec)
}
// FileuploadPoolExists checks the presence of a single record by primary key
func FileuploadPoolExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
return FileuploadPools.Query(
sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(IDPK))),
).Exists(ctx, exec)
}
// AfterQueryHook is called after FileuploadPool is retrieved from the database
func (o *FileuploadPool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = FileuploadPools.AfterSelectHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o})
case bob.QueryTypeInsert:
ctx, err = FileuploadPools.AfterInsertHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o})
case bob.QueryTypeUpdate:
ctx, err = FileuploadPools.AfterUpdateHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o})
case bob.QueryTypeDelete:
ctx, err = FileuploadPools.AfterDeleteHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o})
}
return err
}
// primaryKeyVals returns the primary key values of the FileuploadPool
func (o *FileuploadPool) primaryKeyVals() bob.Expression {
return psql.Arg(o.ID)
}
func (o *FileuploadPool) pkEQ() dialect.Expression {
return psql.Quote("fileupload.pool", "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 FileuploadPool
func (o *FileuploadPool) Update(ctx context.Context, exec bob.Executor, s *FileuploadPoolSetter) error {
v, err := FileuploadPools.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 FileuploadPool record with an executor
func (o *FileuploadPool) Delete(ctx context.Context, exec bob.Executor) error {
_, err := FileuploadPools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
return err
}
// Reload refreshes the FileuploadPool using the executor
func (o *FileuploadPool) Reload(ctx context.Context, exec bob.Executor) error {
o2, err := FileuploadPools.Query(
sm.Where(FileuploadPools.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 FileuploadPoolSlice is retrieved from the database
func (o FileuploadPoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
var err error
switch queryType {
case bob.QueryTypeSelect:
ctx, err = FileuploadPools.AfterSelectHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeInsert:
ctx, err = FileuploadPools.AfterInsertHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeUpdate:
ctx, err = FileuploadPools.AfterUpdateHooks.RunHooks(ctx, exec, o)
case bob.QueryTypeDelete:
ctx, err = FileuploadPools.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}
func (o FileuploadPoolSlice) pkIN() dialect.Expression {
if len(o) == 0 {
return psql.Raw("NULL")
}
return psql.Quote("fileupload.pool", "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 FileuploadPoolSlice) copyMatchingRows(from ...*FileuploadPool) {
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 FileuploadPoolSlice) 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 FileuploadPools.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 *FileuploadPool:
o.copyMatchingRows(retrieved)
case []*FileuploadPool:
o.copyMatchingRows(retrieved...)
case FileuploadPoolSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a FileuploadPool or a slice of FileuploadPool
// then run the AfterUpdateHooks on the slice
_, err = FileuploadPools.AfterUpdateHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o FileuploadPoolSlice) 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 FileuploadPools.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 *FileuploadPool:
o.copyMatchingRows(retrieved)
case []*FileuploadPool:
o.copyMatchingRows(retrieved...)
case FileuploadPoolSlice:
o.copyMatchingRows(retrieved...)
default:
// If the retrieved value is not a FileuploadPool or a slice of FileuploadPool
// then run the AfterDeleteHooks on the slice
_, err = FileuploadPools.AfterDeleteHooks.RunHooks(ctx, exec, o)
}
return err
}))
q.AppendWhere(o.pkIN())
})
}
func (o FileuploadPoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FileuploadPoolSetter) error {
if len(o) == 0 {
return nil
}
_, err := FileuploadPools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
return err
}
func (o FileuploadPoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
_, err := FileuploadPools.Delete(o.DeleteMod()).Exec(ctx, exec)
return err
}
func (o FileuploadPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
if len(o) == 0 {
return nil
}
o2, err := FileuploadPools.Query(sm.Where(o.pkIN())).All(ctx, exec)
if err != nil {
return err
}
o.copyMatchingRows(o2...)
return nil
}
// CreatorUser starts a query for related objects on user_
func (o *FileuploadPool) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
return Users.Query(append(mods,
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.CreatorID))),
)...)
}
func (os FileuploadPoolSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
pkCreatorID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkCreatorID = append(pkCreatorID, o.CreatorID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkCreatorID), "integer[]")),
))
return Users.Query(append(mods,
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// CSVFileCSV starts a query for related objects on fileupload.csv
func (o *FileuploadPool) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery {
return FileuploadCSVS.Query(append(mods,
sm.Where(FileuploadCSVS.Columns.FileID.EQ(psql.Arg(o.CSVFile))),
)...)
}
func (os FileuploadPoolSlice) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery {
pkCSVFile := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkCSVFile = append(pkCSVFile, o.CSVFile)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkCSVFile), "integer[]")),
))
return FileuploadCSVS.Query(append(mods,
sm.Where(psql.Group(FileuploadCSVS.Columns.FileID).OP("IN", PKArgExpr)),
)...)
}
// Organization starts a query for related objects on organization
func (o *FileuploadPool) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
return Organizations.Query(append(mods,
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
)...)
}
func (os FileuploadPoolSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
pkOrganizationID := make(pgtypes.Array[int32], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkOrganizationID = append(pkOrganizationID, o.OrganizationID)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")),
))
return Organizations.Query(append(mods,
sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)),
)...)
}
// PropertyOwnerPhoneE164Phone starts a query for related objects on comms.phone
func (o *FileuploadPool) PropertyOwnerPhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.PropertyOwnerPhoneE164))),
)...)
}
func (os FileuploadPoolSlice) PropertyOwnerPhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
pkPropertyOwnerPhoneE164 := make(pgtypes.Array[null.Val[string]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkPropertyOwnerPhoneE164 = append(pkPropertyOwnerPhoneE164, o.PropertyOwnerPhoneE164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkPropertyOwnerPhoneE164), "text[]")),
))
return CommsPhones.Query(append(mods,
sm.Where(psql.Group(CommsPhones.Columns.E164).OP("IN", PKArgExpr)),
)...)
}
// ResidentPhoneE164Phone starts a query for related objects on comms.phone
func (o *FileuploadPool) ResidentPhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
return CommsPhones.Query(append(mods,
sm.Where(CommsPhones.Columns.E164.EQ(psql.Arg(o.ResidentPhoneE164))),
)...)
}
func (os FileuploadPoolSlice) ResidentPhoneE164Phone(mods ...bob.Mod[*dialect.SelectQuery]) CommsPhonesQuery {
pkResidentPhoneE164 := make(pgtypes.Array[null.Val[string]], 0, len(os))
for _, o := range os {
if o == nil {
continue
}
pkResidentPhoneE164 = append(pkResidentPhoneE164, o.ResidentPhoneE164)
}
PKArgExpr := psql.Select(sm.Columns(
psql.F("unnest", psql.Cast(psql.Arg(pkResidentPhoneE164), "text[]")),
))
return CommsPhones.Query(append(mods,
sm.Where(psql.Group(CommsPhones.Columns.E164).OP("IN", PKArgExpr)),
)...)
}
func attachFileuploadPoolCreatorUser0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, user1 *User) (*FileuploadPool, error) {
setter := &FileuploadPoolSetter{
CreatorID: omit.From(user1.ID),
}
err := fileuploadPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachFileuploadPoolCreatorUser0: %w", err)
}
return fileuploadPool0, nil
}
func (fileuploadPool0 *FileuploadPool) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
var err error
user1, err := Users.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachFileuploadPoolCreatorUser0(ctx, exec, 1, fileuploadPool0, user1)
if err != nil {
return err
}
fileuploadPool0.R.CreatorUser = user1
user1.R.CreatorPools = append(user1.R.CreatorPools, fileuploadPool0)
return nil
}
func (fileuploadPool0 *FileuploadPool) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
var err error
_, err = attachFileuploadPoolCreatorUser0(ctx, exec, 1, fileuploadPool0, user1)
if err != nil {
return err
}
fileuploadPool0.R.CreatorUser = user1
user1.R.CreatorPools = append(user1.R.CreatorPools, fileuploadPool0)
return nil
}
func attachFileuploadPoolCSVFileCSV0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, fileuploadCSV1 *FileuploadCSV) (*FileuploadPool, error) {
setter := &FileuploadPoolSetter{
CSVFile: omit.From(fileuploadCSV1.FileID),
}
err := fileuploadPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachFileuploadPoolCSVFileCSV0: %w", err)
}
return fileuploadPool0, nil
}
func (fileuploadPool0 *FileuploadPool) InsertCSVFileCSV(ctx context.Context, exec bob.Executor, related *FileuploadCSVSetter) error {
var err error
fileuploadCSV1, err := FileuploadCSVS.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachFileuploadPoolCSVFileCSV0(ctx, exec, 1, fileuploadPool0, fileuploadCSV1)
if err != nil {
return err
}
fileuploadPool0.R.CSVFileCSV = fileuploadCSV1
fileuploadCSV1.R.CSVFilePools = append(fileuploadCSV1.R.CSVFilePools, fileuploadPool0)
return nil
}
func (fileuploadPool0 *FileuploadPool) AttachCSVFileCSV(ctx context.Context, exec bob.Executor, fileuploadCSV1 *FileuploadCSV) error {
var err error
_, err = attachFileuploadPoolCSVFileCSV0(ctx, exec, 1, fileuploadPool0, fileuploadCSV1)
if err != nil {
return err
}
fileuploadPool0.R.CSVFileCSV = fileuploadCSV1
fileuploadCSV1.R.CSVFilePools = append(fileuploadCSV1.R.CSVFilePools, fileuploadPool0)
return nil
}
func attachFileuploadPoolOrganization0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, organization1 *Organization) (*FileuploadPool, error) {
setter := &FileuploadPoolSetter{
OrganizationID: omit.From(organization1.ID),
}
err := fileuploadPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachFileuploadPoolOrganization0: %w", err)
}
return fileuploadPool0, nil
}
func (fileuploadPool0 *FileuploadPool) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error {
var err error
organization1, err := Organizations.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachFileuploadPoolOrganization0(ctx, exec, 1, fileuploadPool0, organization1)
if err != nil {
return err
}
fileuploadPool0.R.Organization = organization1
organization1.R.Pools = append(organization1.R.Pools, fileuploadPool0)
return nil
}
func (fileuploadPool0 *FileuploadPool) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
var err error
_, err = attachFileuploadPoolOrganization0(ctx, exec, 1, fileuploadPool0, organization1)
if err != nil {
return err
}
fileuploadPool0.R.Organization = organization1
organization1.R.Pools = append(organization1.R.Pools, fileuploadPool0)
return nil
}
func attachFileuploadPoolPropertyOwnerPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, commsPhone1 *CommsPhone) (*FileuploadPool, error) {
setter := &FileuploadPoolSetter{
PropertyOwnerPhoneE164: omitnull.From(commsPhone1.E164),
}
err := fileuploadPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachFileuploadPoolPropertyOwnerPhoneE164Phone0: %w", err)
}
return fileuploadPool0, nil
}
func (fileuploadPool0 *FileuploadPool) InsertPropertyOwnerPhoneE164Phone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
var err error
commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachFileuploadPoolPropertyOwnerPhoneE164Phone0(ctx, exec, 1, fileuploadPool0, commsPhone1)
if err != nil {
return err
}
fileuploadPool0.R.PropertyOwnerPhoneE164Phone = commsPhone1
commsPhone1.R.PropertyOwnerPhoneE164Pools = append(commsPhone1.R.PropertyOwnerPhoneE164Pools, fileuploadPool0)
return nil
}
func (fileuploadPool0 *FileuploadPool) AttachPropertyOwnerPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachFileuploadPoolPropertyOwnerPhoneE164Phone0(ctx, exec, 1, fileuploadPool0, commsPhone1)
if err != nil {
return err
}
fileuploadPool0.R.PropertyOwnerPhoneE164Phone = commsPhone1
commsPhone1.R.PropertyOwnerPhoneE164Pools = append(commsPhone1.R.PropertyOwnerPhoneE164Pools, fileuploadPool0)
return nil
}
func attachFileuploadPoolResidentPhoneE164Phone0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, commsPhone1 *CommsPhone) (*FileuploadPool, error) {
setter := &FileuploadPoolSetter{
ResidentPhoneE164: omitnull.From(commsPhone1.E164),
}
err := fileuploadPool0.Update(ctx, exec, setter)
if err != nil {
return nil, fmt.Errorf("attachFileuploadPoolResidentPhoneE164Phone0: %w", err)
}
return fileuploadPool0, nil
}
func (fileuploadPool0 *FileuploadPool) InsertResidentPhoneE164Phone(ctx context.Context, exec bob.Executor, related *CommsPhoneSetter) error {
var err error
commsPhone1, err := CommsPhones.Insert(related).One(ctx, exec)
if err != nil {
return fmt.Errorf("inserting related objects: %w", err)
}
_, err = attachFileuploadPoolResidentPhoneE164Phone0(ctx, exec, 1, fileuploadPool0, commsPhone1)
if err != nil {
return err
}
fileuploadPool0.R.ResidentPhoneE164Phone = commsPhone1
commsPhone1.R.ResidentPhoneE164Pools = append(commsPhone1.R.ResidentPhoneE164Pools, fileuploadPool0)
return nil
}
func (fileuploadPool0 *FileuploadPool) AttachResidentPhoneE164Phone(ctx context.Context, exec bob.Executor, commsPhone1 *CommsPhone) error {
var err error
_, err = attachFileuploadPoolResidentPhoneE164Phone0(ctx, exec, 1, fileuploadPool0, commsPhone1)
if err != nil {
return err
}
fileuploadPool0.R.ResidentPhoneE164Phone = commsPhone1
commsPhone1.R.ResidentPhoneE164Pools = append(commsPhone1.R.ResidentPhoneE164Pools, fileuploadPool0)
return nil
}
type fileuploadPoolWhere[Q psql.Filterable] struct {
AddressCity psql.WhereMod[Q, string]
AddressPostalCode psql.WhereMod[Q, string]
AddressStreet psql.WhereMod[Q, string]
Committed psql.WhereMod[Q, bool]
Condition psql.WhereMod[Q, enums.FileuploadPoolconditiontype]
Created psql.WhereMod[Q, time.Time]
CreatorID psql.WhereMod[Q, int32]
CSVFile psql.WhereMod[Q, int32]
Deleted psql.WhereNullMod[Q, time.Time]
Geom psql.WhereNullMod[Q, string]
H3cell psql.WhereNullMod[Q, string]
ID psql.WhereMod[Q, int32]
IsInDistrict psql.WhereMod[Q, bool]
IsNew psql.WhereMod[Q, bool]
Notes psql.WhereMod[Q, string]
OrganizationID psql.WhereMod[Q, int32]
PropertyOwnerName psql.WhereMod[Q, string]
PropertyOwnerPhoneE164 psql.WhereNullMod[Q, string]
ResidentOwned psql.WhereNullMod[Q, bool]
ResidentPhoneE164 psql.WhereNullMod[Q, string]
LineNumber psql.WhereMod[Q, int32]
Tags psql.WhereMod[Q, pgtypes.HStore]
}
func (fileuploadPoolWhere[Q]) AliasedAs(alias string) fileuploadPoolWhere[Q] {
return buildFileuploadPoolWhere[Q](buildFileuploadPoolColumns(alias))
}
func buildFileuploadPoolWhere[Q psql.Filterable](cols fileuploadPoolColumns) fileuploadPoolWhere[Q] {
return fileuploadPoolWhere[Q]{
AddressCity: psql.Where[Q, string](cols.AddressCity),
AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode),
AddressStreet: psql.Where[Q, string](cols.AddressStreet),
Committed: psql.Where[Q, bool](cols.Committed),
Condition: psql.Where[Q, enums.FileuploadPoolconditiontype](cols.Condition),
Created: psql.Where[Q, time.Time](cols.Created),
CreatorID: psql.Where[Q, int32](cols.CreatorID),
CSVFile: psql.Where[Q, int32](cols.CSVFile),
Deleted: psql.WhereNull[Q, time.Time](cols.Deleted),
Geom: psql.WhereNull[Q, string](cols.Geom),
H3cell: psql.WhereNull[Q, string](cols.H3cell),
ID: psql.Where[Q, int32](cols.ID),
IsInDistrict: psql.Where[Q, bool](cols.IsInDistrict),
IsNew: psql.Where[Q, bool](cols.IsNew),
Notes: psql.Where[Q, string](cols.Notes),
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
PropertyOwnerName: psql.Where[Q, string](cols.PropertyOwnerName),
PropertyOwnerPhoneE164: psql.WhereNull[Q, string](cols.PropertyOwnerPhoneE164),
ResidentOwned: psql.WhereNull[Q, bool](cols.ResidentOwned),
ResidentPhoneE164: psql.WhereNull[Q, string](cols.ResidentPhoneE164),
LineNumber: psql.Where[Q, int32](cols.LineNumber),
Tags: psql.Where[Q, pgtypes.HStore](cols.Tags),
}
}
func (o *FileuploadPool) Preload(name string, retrieved any) error {
if o == nil {
return nil
}
switch name {
case "CreatorUser":
rel, ok := retrieved.(*User)
if !ok {
return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name)
}
o.R.CreatorUser = rel
if rel != nil {
rel.R.CreatorPools = FileuploadPoolSlice{o}
}
return nil
case "CSVFileCSV":
rel, ok := retrieved.(*FileuploadCSV)
if !ok {
return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name)
}
o.R.CSVFileCSV = rel
if rel != nil {
rel.R.CSVFilePools = FileuploadPoolSlice{o}
}
return nil
case "Organization":
rel, ok := retrieved.(*Organization)
if !ok {
return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name)
}
o.R.Organization = rel
if rel != nil {
rel.R.Pools = FileuploadPoolSlice{o}
}
return nil
case "PropertyOwnerPhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name)
}
o.R.PropertyOwnerPhoneE164Phone = rel
if rel != nil {
rel.R.PropertyOwnerPhoneE164Pools = FileuploadPoolSlice{o}
}
return nil
case "ResidentPhoneE164Phone":
rel, ok := retrieved.(*CommsPhone)
if !ok {
return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name)
}
o.R.ResidentPhoneE164Phone = rel
if rel != nil {
rel.R.ResidentPhoneE164Pools = FileuploadPoolSlice{o}
}
return nil
default:
return fmt.Errorf("fileuploadPool has no relationship %q", name)
}
}
type fileuploadPoolPreloader struct {
CreatorUser func(...psql.PreloadOption) psql.Preloader
CSVFileCSV func(...psql.PreloadOption) psql.Preloader
Organization func(...psql.PreloadOption) psql.Preloader
PropertyOwnerPhoneE164Phone func(...psql.PreloadOption) psql.Preloader
ResidentPhoneE164Phone func(...psql.PreloadOption) psql.Preloader
}
func buildFileuploadPoolPreloader() fileuploadPoolPreloader {
return fileuploadPoolPreloader{
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*User, UserSlice](psql.PreloadRel{
Name: "CreatorUser",
Sides: []psql.PreloadSide{
{
From: FileuploadPools,
To: Users,
FromColumns: []string{"creator_id"},
ToColumns: []string{"id"},
},
},
}, Users.Columns.Names(), opts...)
},
CSVFileCSV: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*FileuploadCSV, FileuploadCSVSlice](psql.PreloadRel{
Name: "CSVFileCSV",
Sides: []psql.PreloadSide{
{
From: FileuploadPools,
To: FileuploadCSVS,
FromColumns: []string{"csv_file"},
ToColumns: []string{"file_id"},
},
},
}, FileuploadCSVS.Columns.Names(), opts...)
},
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
Name: "Organization",
Sides: []psql.PreloadSide{
{
From: FileuploadPools,
To: Organizations,
FromColumns: []string{"organization_id"},
ToColumns: []string{"id"},
},
},
}, Organizations.Columns.Names(), opts...)
},
PropertyOwnerPhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "PropertyOwnerPhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: FileuploadPools,
To: CommsPhones,
FromColumns: []string{"property_owner_phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
ResidentPhoneE164Phone: func(opts ...psql.PreloadOption) psql.Preloader {
return psql.Preload[*CommsPhone, CommsPhoneSlice](psql.PreloadRel{
Name: "ResidentPhoneE164Phone",
Sides: []psql.PreloadSide{
{
From: FileuploadPools,
To: CommsPhones,
FromColumns: []string{"resident_phone_e164"},
ToColumns: []string{"e164"},
},
},
}, CommsPhones.Columns.Names(), opts...)
},
}
}
type fileuploadPoolThenLoader[Q orm.Loadable] struct {
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
CSVFileCSV func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
PropertyOwnerPhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
ResidentPhoneE164Phone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}
func buildFileuploadPoolThenLoader[Q orm.Loadable]() fileuploadPoolThenLoader[Q] {
type CreatorUserLoadInterface interface {
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type CSVFileCSVLoadInterface interface {
LoadCSVFileCSV(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type OrganizationLoadInterface interface {
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type PropertyOwnerPhoneE164PhoneLoadInterface interface {
LoadPropertyOwnerPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
type ResidentPhoneE164PhoneLoadInterface interface {
LoadResidentPhoneE164Phone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
}
return fileuploadPoolThenLoader[Q]{
CreatorUser: thenLoadBuilder[Q](
"CreatorUser",
func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCreatorUser(ctx, exec, mods...)
},
),
CSVFileCSV: thenLoadBuilder[Q](
"CSVFileCSV",
func(ctx context.Context, exec bob.Executor, retrieved CSVFileCSVLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadCSVFileCSV(ctx, exec, mods...)
},
),
Organization: thenLoadBuilder[Q](
"Organization",
func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadOrganization(ctx, exec, mods...)
},
),
PropertyOwnerPhoneE164Phone: thenLoadBuilder[Q](
"PropertyOwnerPhoneE164Phone",
func(ctx context.Context, exec bob.Executor, retrieved PropertyOwnerPhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadPropertyOwnerPhoneE164Phone(ctx, exec, mods...)
},
),
ResidentPhoneE164Phone: thenLoadBuilder[Q](
"ResidentPhoneE164Phone",
func(ctx context.Context, exec bob.Executor, retrieved ResidentPhoneE164PhoneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
return retrieved.LoadResidentPhoneE164Phone(ctx, exec, mods...)
},
),
}
}
// LoadCreatorUser loads the fileuploadPool's CreatorUser into the .R struct
func (o *FileuploadPool) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.CreatorUser = nil
related, err := o.CreatorUser(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.CreatorPools = FileuploadPoolSlice{o}
o.R.CreatorUser = related
return nil
}
// LoadCreatorUser loads the fileuploadPool's CreatorUser into the .R struct
func (os FileuploadPoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
users, err := os.CreatorUser(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range users {
if !(o.CreatorID == rel.ID) {
continue
}
rel.R.CreatorPools = append(rel.R.CreatorPools, o)
o.R.CreatorUser = rel
break
}
}
return nil
}
// LoadCSVFileCSV loads the fileuploadPool's CSVFileCSV into the .R struct
func (o *FileuploadPool) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.CSVFileCSV = nil
related, err := o.CSVFileCSV(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.CSVFilePools = FileuploadPoolSlice{o}
o.R.CSVFileCSV = related
return nil
}
// LoadCSVFileCSV loads the fileuploadPool's CSVFileCSV into the .R struct
func (os FileuploadPoolSlice) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
fileuploadCSVS, err := os.CSVFileCSV(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range fileuploadCSVS {
if !(o.CSVFile == rel.FileID) {
continue
}
rel.R.CSVFilePools = append(rel.R.CSVFilePools, o)
o.R.CSVFileCSV = rel
break
}
}
return nil
}
// LoadOrganization loads the fileuploadPool's Organization into the .R struct
func (o *FileuploadPool) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.Organization = nil
related, err := o.Organization(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.Pools = FileuploadPoolSlice{o}
o.R.Organization = related
return nil
}
// LoadOrganization loads the fileuploadPool's Organization into the .R struct
func (os FileuploadPoolSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
organizations, err := os.Organization(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range organizations {
if !(o.OrganizationID == rel.ID) {
continue
}
rel.R.Pools = append(rel.R.Pools, o)
o.R.Organization = rel
break
}
}
return nil
}
// LoadPropertyOwnerPhoneE164Phone loads the fileuploadPool's PropertyOwnerPhoneE164Phone into the .R struct
func (o *FileuploadPool) LoadPropertyOwnerPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.PropertyOwnerPhoneE164Phone = nil
related, err := o.PropertyOwnerPhoneE164Phone(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.PropertyOwnerPhoneE164Pools = FileuploadPoolSlice{o}
o.R.PropertyOwnerPhoneE164Phone = related
return nil
}
// LoadPropertyOwnerPhoneE164Phone loads the fileuploadPool's PropertyOwnerPhoneE164Phone into the .R struct
func (os FileuploadPoolSlice) LoadPropertyOwnerPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsPhones, err := os.PropertyOwnerPhoneE164Phone(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsPhones {
if !o.PropertyOwnerPhoneE164.IsValue() {
continue
}
if !(o.PropertyOwnerPhoneE164.IsValue() && o.PropertyOwnerPhoneE164.MustGet() == rel.E164) {
continue
}
rel.R.PropertyOwnerPhoneE164Pools = append(rel.R.PropertyOwnerPhoneE164Pools, o)
o.R.PropertyOwnerPhoneE164Phone = rel
break
}
}
return nil
}
// LoadResidentPhoneE164Phone loads the fileuploadPool's ResidentPhoneE164Phone into the .R struct
func (o *FileuploadPool) LoadResidentPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if o == nil {
return nil
}
// Reset the relationship
o.R.ResidentPhoneE164Phone = nil
related, err := o.ResidentPhoneE164Phone(mods...).One(ctx, exec)
if err != nil {
return err
}
related.R.ResidentPhoneE164Pools = FileuploadPoolSlice{o}
o.R.ResidentPhoneE164Phone = related
return nil
}
// LoadResidentPhoneE164Phone loads the fileuploadPool's ResidentPhoneE164Phone into the .R struct
func (os FileuploadPoolSlice) LoadResidentPhoneE164Phone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
if len(os) == 0 {
return nil
}
commsPhones, err := os.ResidentPhoneE164Phone(mods...).All(ctx, exec)
if err != nil {
return err
}
for _, o := range os {
if o == nil {
continue
}
for _, rel := range commsPhones {
if !o.ResidentPhoneE164.IsValue() {
continue
}
if !(o.ResidentPhoneE164.IsValue() && o.ResidentPhoneE164.MustGet() == rel.E164) {
continue
}
rel.R.ResidentPhoneE164Pools = append(rel.R.ResidentPhoneE164Pools, o)
o.R.ResidentPhoneE164Phone = rel
break
}
}
return nil
}
type fileuploadPoolJoins[Q dialect.Joinable] struct {
typ string
CreatorUser modAs[Q, userColumns]
CSVFileCSV modAs[Q, fileuploadCSVColumns]
Organization modAs[Q, organizationColumns]
PropertyOwnerPhoneE164Phone modAs[Q, commsPhoneColumns]
ResidentPhoneE164Phone modAs[Q, commsPhoneColumns]
}
func (j fileuploadPoolJoins[Q]) aliasedAs(alias string) fileuploadPoolJoins[Q] {
return buildFileuploadPoolJoins[Q](buildFileuploadPoolColumns(alias), j.typ)
}
func buildFileuploadPoolJoins[Q dialect.Joinable](cols fileuploadPoolColumns, typ string) fileuploadPoolJoins[Q] {
return fileuploadPoolJoins[Q]{
typ: typ,
CreatorUser: modAs[Q, userColumns]{
c: Users.Columns,
f: func(to userColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On(
to.ID.EQ(cols.CreatorID),
))
}
return mods
},
},
CSVFileCSV: modAs[Q, fileuploadCSVColumns]{
c: FileuploadCSVS.Columns,
f: func(to fileuploadCSVColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, FileuploadCSVS.Name().As(to.Alias())).On(
to.FileID.EQ(cols.CSVFile),
))
}
return mods
},
},
Organization: modAs[Q, organizationColumns]{
c: Organizations.Columns,
f: func(to organizationColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On(
to.ID.EQ(cols.OrganizationID),
))
}
return mods
},
},
PropertyOwnerPhoneE164Phone: modAs[Q, commsPhoneColumns]{
c: CommsPhones.Columns,
f: func(to commsPhoneColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsPhones.Name().As(to.Alias())).On(
to.E164.EQ(cols.PropertyOwnerPhoneE164),
))
}
return mods
},
},
ResidentPhoneE164Phone: modAs[Q, commsPhoneColumns]{
c: CommsPhones.Columns,
f: func(to commsPhoneColumns) bob.Mod[Q] {
mods := make(mods.QueryMods[Q], 0, 1)
{
mods = append(mods, dialect.Join[Q](typ, CommsPhones.Name().As(to.Alias())).On(
to.E164.EQ(cols.ResidentPhoneE164),
))
}
return mods
},
},
}
}