1356 lines
36 KiB
Go
1356 lines
36 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"
|
|
)
|
|
|
|
// Signal is an object representing the database table.
|
|
type Signal struct {
|
|
Addressed null.Val[time.Time] `db:"addressed" `
|
|
Addressor null.Val[int32] `db:"addressor" `
|
|
Created time.Time `db:"created" `
|
|
Creator int32 `db:"creator" `
|
|
ID int32 `db:"id,pk" `
|
|
OrganizationID int32 `db:"organization_id" `
|
|
Species null.Val[enums.Mosquitospecies] `db:"species" `
|
|
Title string `db:"title" `
|
|
Type enums.Signaltype `db:"type_" `
|
|
|
|
R signalR `db:"-" `
|
|
|
|
C signalC `db:"-" `
|
|
}
|
|
|
|
// SignalSlice is an alias for a slice of pointers to Signal.
|
|
// This should almost always be used instead of []*Signal.
|
|
type SignalSlice []*Signal
|
|
|
|
// Signals contains methods to work with the signal table
|
|
var Signals = psql.NewTablex[*Signal, SignalSlice, *SignalSetter]("", "signal", buildSignalColumns("signal"))
|
|
|
|
// SignalsQuery is a query on the signal table
|
|
type SignalsQuery = *psql.ViewQuery[*Signal, SignalSlice]
|
|
|
|
// signalR is where relationships are stored.
|
|
type signalR struct {
|
|
AddressorUser *User // signal.signal_addressor_fkey
|
|
CreatorUser *User // signal.signal_creator_fkey
|
|
Organization *Organization // signal.signal_organization_id_fkey
|
|
SignalPools SignalPoolSlice // signal_pool.signal_pool_signal_id_fkey
|
|
}
|
|
|
|
func buildSignalColumns(alias string) signalColumns {
|
|
return signalColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"addressed", "addressor", "created", "creator", "id", "organization_id", "species", "title", "type_",
|
|
).WithParent("signal"),
|
|
tableAlias: alias,
|
|
Addressed: psql.Quote(alias, "addressed"),
|
|
Addressor: psql.Quote(alias, "addressor"),
|
|
Created: psql.Quote(alias, "created"),
|
|
Creator: psql.Quote(alias, "creator"),
|
|
ID: psql.Quote(alias, "id"),
|
|
OrganizationID: psql.Quote(alias, "organization_id"),
|
|
Species: psql.Quote(alias, "species"),
|
|
Title: psql.Quote(alias, "title"),
|
|
Type: psql.Quote(alias, "type_"),
|
|
}
|
|
}
|
|
|
|
type signalColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
Addressed psql.Expression
|
|
Addressor psql.Expression
|
|
Created psql.Expression
|
|
Creator psql.Expression
|
|
ID psql.Expression
|
|
OrganizationID psql.Expression
|
|
Species psql.Expression
|
|
Title psql.Expression
|
|
Type psql.Expression
|
|
}
|
|
|
|
func (c signalColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (signalColumns) AliasedAs(alias string) signalColumns {
|
|
return buildSignalColumns(alias)
|
|
}
|
|
|
|
// SignalSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type SignalSetter struct {
|
|
Addressed omitnull.Val[time.Time] `db:"addressed" `
|
|
Addressor omitnull.Val[int32] `db:"addressor" `
|
|
Created omit.Val[time.Time] `db:"created" `
|
|
Creator omit.Val[int32] `db:"creator" `
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
OrganizationID omit.Val[int32] `db:"organization_id" `
|
|
Species omitnull.Val[enums.Mosquitospecies] `db:"species" `
|
|
Title omit.Val[string] `db:"title" `
|
|
Type omit.Val[enums.Signaltype] `db:"type_" `
|
|
}
|
|
|
|
func (s SignalSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 9)
|
|
if !s.Addressed.IsUnset() {
|
|
vals = append(vals, "addressed")
|
|
}
|
|
if !s.Addressor.IsUnset() {
|
|
vals = append(vals, "addressor")
|
|
}
|
|
if s.Created.IsValue() {
|
|
vals = append(vals, "created")
|
|
}
|
|
if s.Creator.IsValue() {
|
|
vals = append(vals, "creator")
|
|
}
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if s.OrganizationID.IsValue() {
|
|
vals = append(vals, "organization_id")
|
|
}
|
|
if !s.Species.IsUnset() {
|
|
vals = append(vals, "species")
|
|
}
|
|
if s.Title.IsValue() {
|
|
vals = append(vals, "title")
|
|
}
|
|
if s.Type.IsValue() {
|
|
vals = append(vals, "type_")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s SignalSetter) Overwrite(t *Signal) {
|
|
if !s.Addressed.IsUnset() {
|
|
t.Addressed = s.Addressed.MustGetNull()
|
|
}
|
|
if !s.Addressor.IsUnset() {
|
|
t.Addressor = s.Addressor.MustGetNull()
|
|
}
|
|
if s.Created.IsValue() {
|
|
t.Created = s.Created.MustGet()
|
|
}
|
|
if s.Creator.IsValue() {
|
|
t.Creator = s.Creator.MustGet()
|
|
}
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if s.OrganizationID.IsValue() {
|
|
t.OrganizationID = s.OrganizationID.MustGet()
|
|
}
|
|
if !s.Species.IsUnset() {
|
|
t.Species = s.Species.MustGetNull()
|
|
}
|
|
if s.Title.IsValue() {
|
|
t.Title = s.Title.MustGet()
|
|
}
|
|
if s.Type.IsValue() {
|
|
t.Type = s.Type.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *SignalSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return Signals.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.Addressed.IsUnset() {
|
|
vals[0] = psql.Arg(s.Addressed.MustGetNull())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Addressor.IsUnset() {
|
|
vals[1] = psql.Arg(s.Addressor.MustGetNull())
|
|
} 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.Creator.IsValue() {
|
|
vals[3] = psql.Arg(s.Creator.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.ID.IsValue() {
|
|
vals[4] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.OrganizationID.IsValue() {
|
|
vals[5] = psql.Arg(s.OrganizationID.MustGet())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Species.IsUnset() {
|
|
vals[6] = psql.Arg(s.Species.MustGetNull())
|
|
} else {
|
|
vals[6] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Title.IsValue() {
|
|
vals[7] = psql.Arg(s.Title.MustGet())
|
|
} else {
|
|
vals[7] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Type.IsValue() {
|
|
vals[8] = psql.Arg(s.Type.MustGet())
|
|
} else {
|
|
vals[8] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s SignalSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s SignalSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 9)
|
|
|
|
if !s.Addressed.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "addressed")...),
|
|
psql.Arg(s.Addressed),
|
|
}})
|
|
}
|
|
|
|
if !s.Addressor.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "addressor")...),
|
|
psql.Arg(s.Addressor),
|
|
}})
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "created")...),
|
|
psql.Arg(s.Created),
|
|
}})
|
|
}
|
|
|
|
if s.Creator.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "creator")...),
|
|
psql.Arg(s.Creator),
|
|
}})
|
|
}
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
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.Species.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "species")...),
|
|
psql.Arg(s.Species),
|
|
}})
|
|
}
|
|
|
|
if s.Title.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "title")...),
|
|
psql.Arg(s.Title),
|
|
}})
|
|
}
|
|
|
|
if s.Type.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "type_")...),
|
|
psql.Arg(s.Type),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindSignal retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindSignal(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Signal, error) {
|
|
if len(cols) == 0 {
|
|
return Signals.Query(
|
|
sm.Where(Signals.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return Signals.Query(
|
|
sm.Where(Signals.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(Signals.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// SignalExists checks the presence of a single record by primary key
|
|
func SignalExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return Signals.Query(
|
|
sm.Where(Signals.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after Signal is retrieved from the database
|
|
func (o *Signal) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = Signals.AfterSelectHooks.RunHooks(ctx, exec, SignalSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = Signals.AfterInsertHooks.RunHooks(ctx, exec, SignalSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = Signals.AfterUpdateHooks.RunHooks(ctx, exec, SignalSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = Signals.AfterDeleteHooks.RunHooks(ctx, exec, SignalSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the Signal
|
|
func (o *Signal) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *Signal) pkEQ() dialect.Expression {
|
|
return psql.Quote("signal", "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 Signal
|
|
func (o *Signal) Update(ctx context.Context, exec bob.Executor, s *SignalSetter) error {
|
|
v, err := Signals.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 Signal record with an executor
|
|
func (o *Signal) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := Signals.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the Signal using the executor
|
|
func (o *Signal) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := Signals.Query(
|
|
sm.Where(Signals.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 SignalSlice is retrieved from the database
|
|
func (o SignalSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = Signals.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = Signals.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = Signals.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = Signals.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o SignalSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("signal", "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 SignalSlice) copyMatchingRows(from ...*Signal) {
|
|
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 SignalSlice) 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 Signals.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 *Signal:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*Signal:
|
|
o.copyMatchingRows(retrieved...)
|
|
case SignalSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a Signal or a slice of Signal
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = Signals.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o SignalSlice) 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 Signals.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 *Signal:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*Signal:
|
|
o.copyMatchingRows(retrieved...)
|
|
case SignalSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a Signal or a slice of Signal
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = Signals.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o SignalSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals SignalSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := Signals.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o SignalSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := Signals.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o SignalSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := Signals.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// AddressorUser starts a query for related objects on user_
|
|
func (o *Signal) AddressorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
|
return Users.Query(append(mods,
|
|
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.Addressor))),
|
|
)...)
|
|
}
|
|
|
|
func (os SignalSlice) AddressorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
|
pkAddressor := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkAddressor = append(pkAddressor, o.Addressor)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkAddressor), "integer[]")),
|
|
))
|
|
|
|
return Users.Query(append(mods,
|
|
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// CreatorUser starts a query for related objects on user_
|
|
func (o *Signal) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
|
return Users.Query(append(mods,
|
|
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.Creator))),
|
|
)...)
|
|
}
|
|
|
|
func (os SignalSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
|
pkCreator := make(pgtypes.Array[int32], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkCreator = append(pkCreator, o.Creator)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkCreator), "integer[]")),
|
|
))
|
|
|
|
return Users.Query(append(mods,
|
|
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// Organization starts a query for related objects on organization
|
|
func (o *Signal) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
|
return Organizations.Query(append(mods,
|
|
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
|
)...)
|
|
}
|
|
|
|
func (os SignalSlice) 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)),
|
|
)...)
|
|
}
|
|
|
|
// SignalPools starts a query for related objects on signal_pool
|
|
func (o *Signal) SignalPools(mods ...bob.Mod[*dialect.SelectQuery]) SignalPoolsQuery {
|
|
return SignalPools.Query(append(mods,
|
|
sm.Where(SignalPools.Columns.SignalID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os SignalSlice) SignalPools(mods ...bob.Mod[*dialect.SelectQuery]) SignalPoolsQuery {
|
|
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 SignalPools.Query(append(mods,
|
|
sm.Where(psql.Group(SignalPools.Columns.SignalID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func attachSignalAddressorUser0(ctx context.Context, exec bob.Executor, count int, signal0 *Signal, user1 *User) (*Signal, error) {
|
|
setter := &SignalSetter{
|
|
Addressor: omitnull.From(user1.ID),
|
|
}
|
|
|
|
err := signal0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachSignalAddressorUser0: %w", err)
|
|
}
|
|
|
|
return signal0, nil
|
|
}
|
|
|
|
func (signal0 *Signal) InsertAddressorUser(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 = attachSignalAddressorUser0(ctx, exec, 1, signal0, user1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signal0.R.AddressorUser = user1
|
|
|
|
user1.R.AddressorSignals = append(user1.R.AddressorSignals, signal0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (signal0 *Signal) AttachAddressorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
|
var err error
|
|
|
|
_, err = attachSignalAddressorUser0(ctx, exec, 1, signal0, user1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signal0.R.AddressorUser = user1
|
|
|
|
user1.R.AddressorSignals = append(user1.R.AddressorSignals, signal0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func attachSignalCreatorUser0(ctx context.Context, exec bob.Executor, count int, signal0 *Signal, user1 *User) (*Signal, error) {
|
|
setter := &SignalSetter{
|
|
Creator: omit.From(user1.ID),
|
|
}
|
|
|
|
err := signal0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachSignalCreatorUser0: %w", err)
|
|
}
|
|
|
|
return signal0, nil
|
|
}
|
|
|
|
func (signal0 *Signal) 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 = attachSignalCreatorUser0(ctx, exec, 1, signal0, user1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signal0.R.CreatorUser = user1
|
|
|
|
user1.R.CreatorSignals = append(user1.R.CreatorSignals, signal0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (signal0 *Signal) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
|
var err error
|
|
|
|
_, err = attachSignalCreatorUser0(ctx, exec, 1, signal0, user1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signal0.R.CreatorUser = user1
|
|
|
|
user1.R.CreatorSignals = append(user1.R.CreatorSignals, signal0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func attachSignalOrganization0(ctx context.Context, exec bob.Executor, count int, signal0 *Signal, organization1 *Organization) (*Signal, error) {
|
|
setter := &SignalSetter{
|
|
OrganizationID: omit.From(organization1.ID),
|
|
}
|
|
|
|
err := signal0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachSignalOrganization0: %w", err)
|
|
}
|
|
|
|
return signal0, nil
|
|
}
|
|
|
|
func (signal0 *Signal) 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 = attachSignalOrganization0(ctx, exec, 1, signal0, organization1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signal0.R.Organization = organization1
|
|
|
|
organization1.R.Signals = append(organization1.R.Signals, signal0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (signal0 *Signal) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
|
var err error
|
|
|
|
_, err = attachSignalOrganization0(ctx, exec, 1, signal0, organization1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
signal0.R.Organization = organization1
|
|
|
|
organization1.R.Signals = append(organization1.R.Signals, signal0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type signalWhere[Q psql.Filterable] struct {
|
|
Addressed psql.WhereNullMod[Q, time.Time]
|
|
Addressor psql.WhereNullMod[Q, int32]
|
|
Created psql.WhereMod[Q, time.Time]
|
|
Creator psql.WhereMod[Q, int32]
|
|
ID psql.WhereMod[Q, int32]
|
|
OrganizationID psql.WhereMod[Q, int32]
|
|
Species psql.WhereNullMod[Q, enums.Mosquitospecies]
|
|
Title psql.WhereMod[Q, string]
|
|
Type psql.WhereMod[Q, enums.Signaltype]
|
|
}
|
|
|
|
func (signalWhere[Q]) AliasedAs(alias string) signalWhere[Q] {
|
|
return buildSignalWhere[Q](buildSignalColumns(alias))
|
|
}
|
|
|
|
func buildSignalWhere[Q psql.Filterable](cols signalColumns) signalWhere[Q] {
|
|
return signalWhere[Q]{
|
|
Addressed: psql.WhereNull[Q, time.Time](cols.Addressed),
|
|
Addressor: psql.WhereNull[Q, int32](cols.Addressor),
|
|
Created: psql.Where[Q, time.Time](cols.Created),
|
|
Creator: psql.Where[Q, int32](cols.Creator),
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
|
Species: psql.WhereNull[Q, enums.Mosquitospecies](cols.Species),
|
|
Title: psql.Where[Q, string](cols.Title),
|
|
Type: psql.Where[Q, enums.Signaltype](cols.Type),
|
|
}
|
|
}
|
|
|
|
func (o *Signal) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "AddressorUser":
|
|
rel, ok := retrieved.(*User)
|
|
if !ok {
|
|
return fmt.Errorf("signal cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.AddressorUser = rel
|
|
|
|
if rel != nil {
|
|
rel.R.AddressorSignals = SignalSlice{o}
|
|
}
|
|
return nil
|
|
case "CreatorUser":
|
|
rel, ok := retrieved.(*User)
|
|
if !ok {
|
|
return fmt.Errorf("signal cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.CreatorUser = rel
|
|
|
|
if rel != nil {
|
|
rel.R.CreatorSignals = SignalSlice{o}
|
|
}
|
|
return nil
|
|
case "Organization":
|
|
rel, ok := retrieved.(*Organization)
|
|
if !ok {
|
|
return fmt.Errorf("signal cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Organization = rel
|
|
|
|
if rel != nil {
|
|
rel.R.Signals = SignalSlice{o}
|
|
}
|
|
return nil
|
|
case "SignalPools":
|
|
rels, ok := retrieved.(SignalPoolSlice)
|
|
if !ok {
|
|
return fmt.Errorf("signal cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.SignalPools = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.Signal = o
|
|
}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("signal has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type signalPreloader struct {
|
|
AddressorUser func(...psql.PreloadOption) psql.Preloader
|
|
CreatorUser func(...psql.PreloadOption) psql.Preloader
|
|
Organization func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildSignalPreloader() signalPreloader {
|
|
return signalPreloader{
|
|
AddressorUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
|
Name: "AddressorUser",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: Signals,
|
|
To: Users,
|
|
FromColumns: []string{"addressor"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, Users.Columns.Names(), opts...)
|
|
},
|
|
CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
|
Name: "CreatorUser",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: Signals,
|
|
To: Users,
|
|
FromColumns: []string{"creator"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, Users.Columns.Names(), opts...)
|
|
},
|
|
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
|
Name: "Organization",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: Signals,
|
|
To: Organizations,
|
|
FromColumns: []string{"organization_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, Organizations.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type signalThenLoader[Q orm.Loadable] struct {
|
|
AddressorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
SignalPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildSignalThenLoader[Q orm.Loadable]() signalThenLoader[Q] {
|
|
type AddressorUserLoadInterface interface {
|
|
LoadAddressorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorUserLoadInterface interface {
|
|
LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type OrganizationLoadInterface interface {
|
|
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type SignalPoolsLoadInterface interface {
|
|
LoadSignalPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return signalThenLoader[Q]{
|
|
AddressorUser: thenLoadBuilder[Q](
|
|
"AddressorUser",
|
|
func(ctx context.Context, exec bob.Executor, retrieved AddressorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadAddressorUser(ctx, exec, mods...)
|
|
},
|
|
),
|
|
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...)
|
|
},
|
|
),
|
|
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...)
|
|
},
|
|
),
|
|
SignalPools: thenLoadBuilder[Q](
|
|
"SignalPools",
|
|
func(ctx context.Context, exec bob.Executor, retrieved SignalPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadSignalPools(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadAddressorUser loads the signal's AddressorUser into the .R struct
|
|
func (o *Signal) LoadAddressorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.AddressorUser = nil
|
|
|
|
related, err := o.AddressorUser(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.AddressorSignals = SignalSlice{o}
|
|
|
|
o.R.AddressorUser = related
|
|
return nil
|
|
}
|
|
|
|
// LoadAddressorUser loads the signal's AddressorUser into the .R struct
|
|
func (os SignalSlice) LoadAddressorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
users, err := os.AddressorUser(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range users {
|
|
if !o.Addressor.IsValue() {
|
|
continue
|
|
}
|
|
|
|
if !(o.Addressor.IsValue() && o.Addressor.MustGet() == rel.ID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.AddressorSignals = append(rel.R.AddressorSignals, o)
|
|
|
|
o.R.AddressorUser = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorUser loads the signal's CreatorUser into the .R struct
|
|
func (o *Signal) 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.CreatorSignals = SignalSlice{o}
|
|
|
|
o.R.CreatorUser = related
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorUser loads the signal's CreatorUser into the .R struct
|
|
func (os SignalSlice) 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.Creator == rel.ID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.CreatorSignals = append(rel.R.CreatorSignals, o)
|
|
|
|
o.R.CreatorUser = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadOrganization loads the signal's Organization into the .R struct
|
|
func (o *Signal) 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.Signals = SignalSlice{o}
|
|
|
|
o.R.Organization = related
|
|
return nil
|
|
}
|
|
|
|
// LoadOrganization loads the signal's Organization into the .R struct
|
|
func (os SignalSlice) 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.Signals = append(rel.R.Signals, o)
|
|
|
|
o.R.Organization = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadSignalPools loads the signal's SignalPools into the .R struct
|
|
func (o *Signal) LoadSignalPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.SignalPools = nil
|
|
|
|
related, err := o.SignalPools(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.Signal = o
|
|
}
|
|
|
|
o.R.SignalPools = related
|
|
return nil
|
|
}
|
|
|
|
// LoadSignalPools loads the signal's SignalPools into the .R struct
|
|
func (os SignalSlice) LoadSignalPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
signalPools, err := os.SignalPools(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.SignalPools = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range signalPools {
|
|
|
|
if !(o.ID == rel.SignalID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.Signal = o
|
|
|
|
o.R.SignalPools = append(o.R.SignalPools, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// signalC is where relationship counts are stored.
|
|
type signalC struct {
|
|
SignalPools *int64
|
|
}
|
|
|
|
// PreloadCount sets a count in the C struct by name
|
|
func (o *Signal) PreloadCount(name string, count int64) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "SignalPools":
|
|
o.C.SignalPools = &count
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type signalCountPreloader struct {
|
|
SignalPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
}
|
|
|
|
func buildSignalCountPreloader() signalCountPreloader {
|
|
return signalCountPreloader{
|
|
SignalPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*Signal]("SignalPools", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Signals.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(SignalPools.Name()),
|
|
sm.Where(psql.Quote(SignalPools.Alias(), "signal_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
type signalCountThenLoader[Q orm.Loadable] struct {
|
|
SignalPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildSignalCountThenLoader[Q orm.Loadable]() signalCountThenLoader[Q] {
|
|
type SignalPoolsCountInterface interface {
|
|
LoadCountSignalPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return signalCountThenLoader[Q]{
|
|
SignalPools: countThenLoadBuilder[Q](
|
|
"SignalPools",
|
|
func(ctx context.Context, exec bob.Executor, retrieved SignalPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountSignalPools(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadCountSignalPools loads the count of SignalPools into the C struct
|
|
func (o *Signal) LoadCountSignalPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.SignalPools(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.SignalPools = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountSignalPools loads the count of SignalPools for a slice
|
|
func (os SignalSlice) LoadCountSignalPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if err := o.LoadCountSignalPools(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type signalJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
AddressorUser modAs[Q, userColumns]
|
|
CreatorUser modAs[Q, userColumns]
|
|
Organization modAs[Q, organizationColumns]
|
|
SignalPools modAs[Q, signalPoolColumns]
|
|
}
|
|
|
|
func (j signalJoins[Q]) aliasedAs(alias string) signalJoins[Q] {
|
|
return buildSignalJoins[Q](buildSignalColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildSignalJoins[Q dialect.Joinable](cols signalColumns, typ string) signalJoins[Q] {
|
|
return signalJoins[Q]{
|
|
typ: typ,
|
|
AddressorUser: 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.Addressor),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
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.Creator),
|
|
))
|
|
}
|
|
|
|
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
|
|
},
|
|
},
|
|
SignalPools: modAs[Q, signalPoolColumns]{
|
|
c: SignalPools.Columns,
|
|
f: func(to signalPoolColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, SignalPools.Name().As(to.Alias())).On(
|
|
to.SignalID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
}
|
|
}
|