This is an intermediate step between shifting from the old fs_* prefixed table names to an entire fieldseeker schema. At this point we have both, and we aren't doing much with the new schema but compiling.
703 lines
21 KiB
Go
703 lines
21 KiB
Go
// Code generated by BobGen psql v0.42.0. 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/aarondl/opt/omit"
|
|
"github.com/stephenafamo/bob"
|
|
"github.com/stephenafamo/bob/dialect/psql"
|
|
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
|
"github.com/stephenafamo/bob/dialect/psql/dm"
|
|
"github.com/stephenafamo/bob/dialect/psql/sm"
|
|
"github.com/stephenafamo/bob/dialect/psql/um"
|
|
"github.com/stephenafamo/bob/expr"
|
|
"github.com/stephenafamo/bob/mods"
|
|
"github.com/stephenafamo/bob/orm"
|
|
"github.com/stephenafamo/bob/types/pgtypes"
|
|
)
|
|
|
|
// FieldseekerSync is an object representing the database table.
|
|
type FieldseekerSync struct {
|
|
ID int32 `db:"id,pk" `
|
|
Created time.Time `db:"created" `
|
|
RecordsCreated int32 `db:"records_created" `
|
|
RecordsUpdated int32 `db:"records_updated" `
|
|
RecordsUnchanged int32 `db:"records_unchanged" `
|
|
OrganizationID int32 `db:"organization_id" `
|
|
|
|
R fieldseekerSyncR `db:"-" `
|
|
}
|
|
|
|
// FieldseekerSyncSlice is an alias for a slice of pointers to FieldseekerSync.
|
|
// This should almost always be used instead of []*FieldseekerSync.
|
|
type FieldseekerSyncSlice []*FieldseekerSync
|
|
|
|
// FieldseekerSyncs contains methods to work with the fieldseeker_sync table
|
|
var FieldseekerSyncs = psql.NewTablex[*FieldseekerSync, FieldseekerSyncSlice, *FieldseekerSyncSetter]("", "fieldseeker_sync", buildFieldseekerSyncColumns("fieldseeker_sync"))
|
|
|
|
// FieldseekerSyncsQuery is a query on the fieldseeker_sync table
|
|
type FieldseekerSyncsQuery = *psql.ViewQuery[*FieldseekerSync, FieldseekerSyncSlice]
|
|
|
|
// fieldseekerSyncR is where relationships are stored.
|
|
type fieldseekerSyncR struct {
|
|
Organization *Organization // fieldseeker_sync.fieldseeker_sync_organization_id_fkey
|
|
}
|
|
|
|
func buildFieldseekerSyncColumns(alias string) fieldseekerSyncColumns {
|
|
return fieldseekerSyncColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "created", "records_created", "records_updated", "records_unchanged", "organization_id",
|
|
).WithParent("fieldseeker_sync"),
|
|
tableAlias: alias,
|
|
ID: psql.Quote(alias, "id"),
|
|
Created: psql.Quote(alias, "created"),
|
|
RecordsCreated: psql.Quote(alias, "records_created"),
|
|
RecordsUpdated: psql.Quote(alias, "records_updated"),
|
|
RecordsUnchanged: psql.Quote(alias, "records_unchanged"),
|
|
OrganizationID: psql.Quote(alias, "organization_id"),
|
|
}
|
|
}
|
|
|
|
type fieldseekerSyncColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ID psql.Expression
|
|
Created psql.Expression
|
|
RecordsCreated psql.Expression
|
|
RecordsUpdated psql.Expression
|
|
RecordsUnchanged psql.Expression
|
|
OrganizationID psql.Expression
|
|
}
|
|
|
|
func (c fieldseekerSyncColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (fieldseekerSyncColumns) AliasedAs(alias string) fieldseekerSyncColumns {
|
|
return buildFieldseekerSyncColumns(alias)
|
|
}
|
|
|
|
// FieldseekerSyncSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type FieldseekerSyncSetter struct {
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
Created omit.Val[time.Time] `db:"created" `
|
|
RecordsCreated omit.Val[int32] `db:"records_created" `
|
|
RecordsUpdated omit.Val[int32] `db:"records_updated" `
|
|
RecordsUnchanged omit.Val[int32] `db:"records_unchanged" `
|
|
OrganizationID omit.Val[int32] `db:"organization_id" `
|
|
}
|
|
|
|
func (s FieldseekerSyncSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 6)
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if s.Created.IsValue() {
|
|
vals = append(vals, "created")
|
|
}
|
|
if s.RecordsCreated.IsValue() {
|
|
vals = append(vals, "records_created")
|
|
}
|
|
if s.RecordsUpdated.IsValue() {
|
|
vals = append(vals, "records_updated")
|
|
}
|
|
if s.RecordsUnchanged.IsValue() {
|
|
vals = append(vals, "records_unchanged")
|
|
}
|
|
if s.OrganizationID.IsValue() {
|
|
vals = append(vals, "organization_id")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s FieldseekerSyncSetter) Overwrite(t *FieldseekerSync) {
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if s.Created.IsValue() {
|
|
t.Created = s.Created.MustGet()
|
|
}
|
|
if s.RecordsCreated.IsValue() {
|
|
t.RecordsCreated = s.RecordsCreated.MustGet()
|
|
}
|
|
if s.RecordsUpdated.IsValue() {
|
|
t.RecordsUpdated = s.RecordsUpdated.MustGet()
|
|
}
|
|
if s.RecordsUnchanged.IsValue() {
|
|
t.RecordsUnchanged = s.RecordsUnchanged.MustGet()
|
|
}
|
|
if s.OrganizationID.IsValue() {
|
|
t.OrganizationID = s.OrganizationID.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *FieldseekerSyncSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return FieldseekerSyncs.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, 6)
|
|
if s.ID.IsValue() {
|
|
vals[0] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
vals[1] = psql.Arg(s.Created.MustGet())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.RecordsCreated.IsValue() {
|
|
vals[2] = psql.Arg(s.RecordsCreated.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.RecordsUpdated.IsValue() {
|
|
vals[3] = psql.Arg(s.RecordsUpdated.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.RecordsUnchanged.IsValue() {
|
|
vals[4] = psql.Arg(s.RecordsUnchanged.MustGet())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.OrganizationID.IsValue() {
|
|
vals[5] = psql.Arg(s.OrganizationID.MustGet())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s FieldseekerSyncSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s FieldseekerSyncSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 6)
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if s.Created.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "created")...),
|
|
psql.Arg(s.Created),
|
|
}})
|
|
}
|
|
|
|
if s.RecordsCreated.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "records_created")...),
|
|
psql.Arg(s.RecordsCreated),
|
|
}})
|
|
}
|
|
|
|
if s.RecordsUpdated.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "records_updated")...),
|
|
psql.Arg(s.RecordsUpdated),
|
|
}})
|
|
}
|
|
|
|
if s.RecordsUnchanged.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "records_unchanged")...),
|
|
psql.Arg(s.RecordsUnchanged),
|
|
}})
|
|
}
|
|
|
|
if s.OrganizationID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "organization_id")...),
|
|
psql.Arg(s.OrganizationID),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindFieldseekerSync retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindFieldseekerSync(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*FieldseekerSync, error) {
|
|
if len(cols) == 0 {
|
|
return FieldseekerSyncs.Query(
|
|
sm.Where(FieldseekerSyncs.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return FieldseekerSyncs.Query(
|
|
sm.Where(FieldseekerSyncs.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(FieldseekerSyncs.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// FieldseekerSyncExists checks the presence of a single record by primary key
|
|
func FieldseekerSyncExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return FieldseekerSyncs.Query(
|
|
sm.Where(FieldseekerSyncs.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after FieldseekerSync is retrieved from the database
|
|
func (o *FieldseekerSync) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = FieldseekerSyncs.AfterSelectHooks.RunHooks(ctx, exec, FieldseekerSyncSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = FieldseekerSyncs.AfterInsertHooks.RunHooks(ctx, exec, FieldseekerSyncSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = FieldseekerSyncs.AfterUpdateHooks.RunHooks(ctx, exec, FieldseekerSyncSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = FieldseekerSyncs.AfterDeleteHooks.RunHooks(ctx, exec, FieldseekerSyncSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the FieldseekerSync
|
|
func (o *FieldseekerSync) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *FieldseekerSync) pkEQ() dialect.Expression {
|
|
return psql.Quote("fieldseeker_sync", "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 FieldseekerSync
|
|
func (o *FieldseekerSync) Update(ctx context.Context, exec bob.Executor, s *FieldseekerSyncSetter) error {
|
|
v, err := FieldseekerSyncs.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 FieldseekerSync record with an executor
|
|
func (o *FieldseekerSync) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := FieldseekerSyncs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the FieldseekerSync using the executor
|
|
func (o *FieldseekerSync) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := FieldseekerSyncs.Query(
|
|
sm.Where(FieldseekerSyncs.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 FieldseekerSyncSlice is retrieved from the database
|
|
func (o FieldseekerSyncSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = FieldseekerSyncs.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = FieldseekerSyncs.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = FieldseekerSyncs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = FieldseekerSyncs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o FieldseekerSyncSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("fieldseeker_sync", "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 FieldseekerSyncSlice) copyMatchingRows(from ...*FieldseekerSync) {
|
|
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 FieldseekerSyncSlice) 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 FieldseekerSyncs.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 *FieldseekerSync:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*FieldseekerSync:
|
|
o.copyMatchingRows(retrieved...)
|
|
case FieldseekerSyncSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a FieldseekerSync or a slice of FieldseekerSync
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = FieldseekerSyncs.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o FieldseekerSyncSlice) 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 FieldseekerSyncs.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 *FieldseekerSync:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*FieldseekerSync:
|
|
o.copyMatchingRows(retrieved...)
|
|
case FieldseekerSyncSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a FieldseekerSync or a slice of FieldseekerSync
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = FieldseekerSyncs.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o FieldseekerSyncSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FieldseekerSyncSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := FieldseekerSyncs.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o FieldseekerSyncSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := FieldseekerSyncs.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o FieldseekerSyncSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := FieldseekerSyncs.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Organization starts a query for related objects on organization
|
|
func (o *FieldseekerSync) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
|
return Organizations.Query(append(mods,
|
|
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
|
)...)
|
|
}
|
|
|
|
func (os FieldseekerSyncSlice) 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)),
|
|
)...)
|
|
}
|
|
|
|
func attachFieldseekerSyncOrganization0(ctx context.Context, exec bob.Executor, count int, fieldseekerSync0 *FieldseekerSync, organization1 *Organization) (*FieldseekerSync, error) {
|
|
setter := &FieldseekerSyncSetter{
|
|
OrganizationID: omit.From(organization1.ID),
|
|
}
|
|
|
|
err := fieldseekerSync0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachFieldseekerSyncOrganization0: %w", err)
|
|
}
|
|
|
|
return fieldseekerSync0, nil
|
|
}
|
|
|
|
func (fieldseekerSync0 *FieldseekerSync) 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 = attachFieldseekerSyncOrganization0(ctx, exec, 1, fieldseekerSync0, organization1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fieldseekerSync0.R.Organization = organization1
|
|
|
|
organization1.R.FieldseekerSyncs = append(organization1.R.FieldseekerSyncs, fieldseekerSync0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (fieldseekerSync0 *FieldseekerSync) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
|
var err error
|
|
|
|
_, err = attachFieldseekerSyncOrganization0(ctx, exec, 1, fieldseekerSync0, organization1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fieldseekerSync0.R.Organization = organization1
|
|
|
|
organization1.R.FieldseekerSyncs = append(organization1.R.FieldseekerSyncs, fieldseekerSync0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type fieldseekerSyncWhere[Q psql.Filterable] struct {
|
|
ID psql.WhereMod[Q, int32]
|
|
Created psql.WhereMod[Q, time.Time]
|
|
RecordsCreated psql.WhereMod[Q, int32]
|
|
RecordsUpdated psql.WhereMod[Q, int32]
|
|
RecordsUnchanged psql.WhereMod[Q, int32]
|
|
OrganizationID psql.WhereMod[Q, int32]
|
|
}
|
|
|
|
func (fieldseekerSyncWhere[Q]) AliasedAs(alias string) fieldseekerSyncWhere[Q] {
|
|
return buildFieldseekerSyncWhere[Q](buildFieldseekerSyncColumns(alias))
|
|
}
|
|
|
|
func buildFieldseekerSyncWhere[Q psql.Filterable](cols fieldseekerSyncColumns) fieldseekerSyncWhere[Q] {
|
|
return fieldseekerSyncWhere[Q]{
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
Created: psql.Where[Q, time.Time](cols.Created),
|
|
RecordsCreated: psql.Where[Q, int32](cols.RecordsCreated),
|
|
RecordsUpdated: psql.Where[Q, int32](cols.RecordsUpdated),
|
|
RecordsUnchanged: psql.Where[Q, int32](cols.RecordsUnchanged),
|
|
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
|
}
|
|
}
|
|
|
|
func (o *FieldseekerSync) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "Organization":
|
|
rel, ok := retrieved.(*Organization)
|
|
if !ok {
|
|
return fmt.Errorf("fieldseekerSync cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Organization = rel
|
|
|
|
if rel != nil {
|
|
rel.R.FieldseekerSyncs = FieldseekerSyncSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("fieldseekerSync has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type fieldseekerSyncPreloader struct {
|
|
Organization func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildFieldseekerSyncPreloader() fieldseekerSyncPreloader {
|
|
return fieldseekerSyncPreloader{
|
|
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
|
Name: "Organization",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: FieldseekerSyncs,
|
|
To: Organizations,
|
|
FromColumns: []string{"organization_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, Organizations.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type fieldseekerSyncThenLoader[Q orm.Loadable] struct {
|
|
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildFieldseekerSyncThenLoader[Q orm.Loadable]() fieldseekerSyncThenLoader[Q] {
|
|
type OrganizationLoadInterface interface {
|
|
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return fieldseekerSyncThenLoader[Q]{
|
|
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...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadOrganization loads the fieldseekerSync's Organization into the .R struct
|
|
func (o *FieldseekerSync) 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.FieldseekerSyncs = FieldseekerSyncSlice{o}
|
|
|
|
o.R.Organization = related
|
|
return nil
|
|
}
|
|
|
|
// LoadOrganization loads the fieldseekerSync's Organization into the .R struct
|
|
func (os FieldseekerSyncSlice) 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.FieldseekerSyncs = append(rel.R.FieldseekerSyncs, o)
|
|
|
|
o.R.Organization = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type fieldseekerSyncJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
Organization modAs[Q, organizationColumns]
|
|
}
|
|
|
|
func (j fieldseekerSyncJoins[Q]) aliasedAs(alias string) fieldseekerSyncJoins[Q] {
|
|
return buildFieldseekerSyncJoins[Q](buildFieldseekerSyncColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildFieldseekerSyncJoins[Q dialect.Joinable](cols fieldseekerSyncColumns, typ string) fieldseekerSyncJoins[Q] {
|
|
return fieldseekerSyncJoins[Q]{
|
|
typ: typ,
|
|
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
|
|
},
|
|
},
|
|
}
|
|
}
|