Create a log for impersonation activities
This commit is contained in:
parent
b2eb98a66c
commit
d287fa44df
7 changed files with 1360 additions and 0 deletions
17
db/dberrors/log_impersonation.bob.go
Normal file
17
db/dberrors/log_impersonation.bob.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// 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 dberrors
|
||||
|
||||
var LogImpersonationErrors = &logImpersonationErrors{
|
||||
ErrUniqueLogImpersonationPkey: &UniqueConstraintError{
|
||||
schema: "",
|
||||
table: "log_impersonation",
|
||||
columns: []string{"id"},
|
||||
s: "log_impersonation_pkey",
|
||||
},
|
||||
}
|
||||
|
||||
type logImpersonationErrors struct {
|
||||
ErrUniqueLogImpersonationPkey *UniqueConstraintError
|
||||
}
|
||||
157
db/dbinfo/log_impersonation.bob.go
Normal file
157
db/dbinfo/log_impersonation.bob.go
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
// 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 dbinfo
|
||||
|
||||
import "github.com/aarondl/opt/null"
|
||||
|
||||
var LogImpersonations = Table[
|
||||
logImpersonationColumns,
|
||||
logImpersonationIndexes,
|
||||
logImpersonationForeignKeys,
|
||||
logImpersonationUniques,
|
||||
logImpersonationChecks,
|
||||
]{
|
||||
Schema: "",
|
||||
Name: "log_impersonation",
|
||||
Columns: logImpersonationColumns{
|
||||
BeginAt: column{
|
||||
Name: "begin_at",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
EndAt: column{
|
||||
Name: "end_at",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ID: column{
|
||||
Name: "id",
|
||||
DBType: "integer",
|
||||
Default: "nextval('log_impersonation_id_seq'::regclass)",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ImpersonatorID: column{
|
||||
Name: "impersonator_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
TargetID: column{
|
||||
Name: "target_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: logImpersonationIndexes{
|
||||
LogImpersonationPkey: index{
|
||||
Type: "btree",
|
||||
Name: "log_impersonation_pkey",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "log_impersonation_pkey",
|
||||
Columns: []string{"id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: logImpersonationForeignKeys{
|
||||
LogImpersonationLogImpersonationImpersonatorIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "log_impersonation.log_impersonation_impersonator_id_fkey",
|
||||
Columns: []string{"impersonator_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "user_",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
LogImpersonationLogImpersonationTargetIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "log_impersonation.log_impersonation_target_id_fkey",
|
||||
Columns: []string{"target_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "user_",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type logImpersonationColumns struct {
|
||||
BeginAt column
|
||||
EndAt column
|
||||
ID column
|
||||
ImpersonatorID column
|
||||
TargetID column
|
||||
}
|
||||
|
||||
func (c logImpersonationColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.BeginAt, c.EndAt, c.ID, c.ImpersonatorID, c.TargetID,
|
||||
}
|
||||
}
|
||||
|
||||
type logImpersonationIndexes struct {
|
||||
LogImpersonationPkey index
|
||||
}
|
||||
|
||||
func (i logImpersonationIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.LogImpersonationPkey,
|
||||
}
|
||||
}
|
||||
|
||||
type logImpersonationForeignKeys struct {
|
||||
LogImpersonationLogImpersonationImpersonatorIDFkey foreignKey
|
||||
LogImpersonationLogImpersonationTargetIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f logImpersonationForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.LogImpersonationLogImpersonationImpersonatorIDFkey, f.LogImpersonationLogImpersonationTargetIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
type logImpersonationUniques struct{}
|
||||
|
||||
func (u logImpersonationUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type logImpersonationChecks struct{}
|
||||
|
||||
func (c logImpersonationChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
12
db/migrations/00118_impersonation_log.sql
Normal file
12
db/migrations/00118_impersonation_log.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
-- +goose Up
|
||||
CREATE TABLE log_impersonation (
|
||||
begin_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
end_at TIMESTAMP WITHOUT TIME ZONE,
|
||||
id SERIAL NOT NULL,
|
||||
impersonator_id INTEGER NOT NULL REFERENCES user_(id),
|
||||
target_id INTEGER NOT NULL REFERENCES user_(id),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
-- +goose Down
|
||||
DROP TABLE log_impersonation;
|
||||
|
||||
|
|
@ -76,6 +76,7 @@ type preloaders struct {
|
|||
FileuploadPool fileuploadPoolPreloader
|
||||
H3Aggregation h3AggregationPreloader
|
||||
Lead leadPreloader
|
||||
LogImpersonation logImpersonationPreloader
|
||||
NoteAudio noteAudioPreloader
|
||||
NoteAudioBreadcrumb noteAudioBreadcrumbPreloader
|
||||
NoteAudioDatum noteAudioDatumPreloader
|
||||
|
|
@ -175,6 +176,7 @@ func getPreloaders() preloaders {
|
|||
FileuploadPool: buildFileuploadPoolPreloader(),
|
||||
H3Aggregation: buildH3AggregationPreloader(),
|
||||
Lead: buildLeadPreloader(),
|
||||
LogImpersonation: buildLogImpersonationPreloader(),
|
||||
NoteAudio: buildNoteAudioPreloader(),
|
||||
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbPreloader(),
|
||||
NoteAudioDatum: buildNoteAudioDatumPreloader(),
|
||||
|
|
@ -280,6 +282,7 @@ type thenLoaders[Q orm.Loadable] struct {
|
|||
FileuploadPool fileuploadPoolThenLoader[Q]
|
||||
H3Aggregation h3AggregationThenLoader[Q]
|
||||
Lead leadThenLoader[Q]
|
||||
LogImpersonation logImpersonationThenLoader[Q]
|
||||
NoteAudio noteAudioThenLoader[Q]
|
||||
NoteAudioBreadcrumb noteAudioBreadcrumbThenLoader[Q]
|
||||
NoteAudioDatum noteAudioDatumThenLoader[Q]
|
||||
|
|
@ -379,6 +382,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] {
|
|||
FileuploadPool: buildFileuploadPoolThenLoader[Q](),
|
||||
H3Aggregation: buildH3AggregationThenLoader[Q](),
|
||||
Lead: buildLeadThenLoader[Q](),
|
||||
LogImpersonation: buildLogImpersonationThenLoader[Q](),
|
||||
NoteAudio: buildNoteAudioThenLoader[Q](),
|
||||
NoteAudioBreadcrumb: buildNoteAudioBreadcrumbThenLoader[Q](),
|
||||
NoteAudioDatum: buildNoteAudioDatumThenLoader[Q](),
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
H3Aggregations h3AggregationWhere[Q]
|
||||
Jobs jobWhere[Q]
|
||||
Leads leadWhere[Q]
|
||||
LogImpersonations logImpersonationWhere[Q]
|
||||
NoteAudios noteAudioWhere[Q]
|
||||
NoteAudioBreadcrumbs noteAudioBreadcrumbWhere[Q]
|
||||
NoteAudioData noteAudioDatumWhere[Q]
|
||||
|
|
@ -186,6 +187,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
H3Aggregations h3AggregationWhere[Q]
|
||||
Jobs jobWhere[Q]
|
||||
Leads leadWhere[Q]
|
||||
LogImpersonations logImpersonationWhere[Q]
|
||||
NoteAudios noteAudioWhere[Q]
|
||||
NoteAudioBreadcrumbs noteAudioBreadcrumbWhere[Q]
|
||||
NoteAudioData noteAudioDatumWhere[Q]
|
||||
|
|
@ -291,6 +293,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
H3Aggregations: buildH3AggregationWhere[Q](H3Aggregations.Columns),
|
||||
Jobs: buildJobWhere[Q](Jobs.Columns),
|
||||
Leads: buildLeadWhere[Q](Leads.Columns),
|
||||
LogImpersonations: buildLogImpersonationWhere[Q](LogImpersonations.Columns),
|
||||
NoteAudios: buildNoteAudioWhere[Q](NoteAudios.Columns),
|
||||
NoteAudioBreadcrumbs: buildNoteAudioBreadcrumbWhere[Q](NoteAudioBreadcrumbs.Columns),
|
||||
NoteAudioData: buildNoteAudioDatumWhere[Q](NoteAudioData.Columns),
|
||||
|
|
|
|||
811
db/models/log_impersonation.bob.go
Normal file
811
db/models/log_impersonation.bob.go
Normal file
|
|
@ -0,0 +1,811 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/Gleipnir-Technology/bob/orm"
|
||||
"github.com/Gleipnir-Technology/bob/types/pgtypes"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
)
|
||||
|
||||
// LogImpersonation is an object representing the database table.
|
||||
type LogImpersonation struct {
|
||||
BeginAt time.Time `db:"begin_at" `
|
||||
EndAt null.Val[time.Time] `db:"end_at" `
|
||||
ID int32 `db:"id,pk" `
|
||||
ImpersonatorID int32 `db:"impersonator_id" `
|
||||
TargetID int32 `db:"target_id" `
|
||||
|
||||
R logImpersonationR `db:"-" `
|
||||
}
|
||||
|
||||
// LogImpersonationSlice is an alias for a slice of pointers to LogImpersonation.
|
||||
// This should almost always be used instead of []*LogImpersonation.
|
||||
type LogImpersonationSlice []*LogImpersonation
|
||||
|
||||
// LogImpersonations contains methods to work with the log_impersonation table
|
||||
var LogImpersonations = psql.NewTablex[*LogImpersonation, LogImpersonationSlice, *LogImpersonationSetter]("", "log_impersonation", buildLogImpersonationColumns("log_impersonation"))
|
||||
|
||||
// LogImpersonationsQuery is a query on the log_impersonation table
|
||||
type LogImpersonationsQuery = *psql.ViewQuery[*LogImpersonation, LogImpersonationSlice]
|
||||
|
||||
// logImpersonationR is where relationships are stored.
|
||||
type logImpersonationR struct {
|
||||
ImpersonatorUser *User // log_impersonation.log_impersonation_impersonator_id_fkey
|
||||
TargetUser *User // log_impersonation.log_impersonation_target_id_fkey
|
||||
}
|
||||
|
||||
func buildLogImpersonationColumns(alias string) logImpersonationColumns {
|
||||
return logImpersonationColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"begin_at", "end_at", "id", "impersonator_id", "target_id",
|
||||
).WithParent("log_impersonation"),
|
||||
tableAlias: alias,
|
||||
BeginAt: psql.Quote(alias, "begin_at"),
|
||||
EndAt: psql.Quote(alias, "end_at"),
|
||||
ID: psql.Quote(alias, "id"),
|
||||
ImpersonatorID: psql.Quote(alias, "impersonator_id"),
|
||||
TargetID: psql.Quote(alias, "target_id"),
|
||||
}
|
||||
}
|
||||
|
||||
type logImpersonationColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
BeginAt psql.Expression
|
||||
EndAt psql.Expression
|
||||
ID psql.Expression
|
||||
ImpersonatorID psql.Expression
|
||||
TargetID psql.Expression
|
||||
}
|
||||
|
||||
func (c logImpersonationColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (logImpersonationColumns) AliasedAs(alias string) logImpersonationColumns {
|
||||
return buildLogImpersonationColumns(alias)
|
||||
}
|
||||
|
||||
// LogImpersonationSetter is used for insert/upsert/update operations
|
||||
// All values are optional, and do not have to be set
|
||||
// Generated columns are not included
|
||||
type LogImpersonationSetter struct {
|
||||
BeginAt omit.Val[time.Time] `db:"begin_at" `
|
||||
EndAt omitnull.Val[time.Time] `db:"end_at" `
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
ImpersonatorID omit.Val[int32] `db:"impersonator_id" `
|
||||
TargetID omit.Val[int32] `db:"target_id" `
|
||||
}
|
||||
|
||||
func (s LogImpersonationSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
if s.BeginAt.IsValue() {
|
||||
vals = append(vals, "begin_at")
|
||||
}
|
||||
if !s.EndAt.IsUnset() {
|
||||
vals = append(vals, "end_at")
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if s.ImpersonatorID.IsValue() {
|
||||
vals = append(vals, "impersonator_id")
|
||||
}
|
||||
if s.TargetID.IsValue() {
|
||||
vals = append(vals, "target_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func (s LogImpersonationSetter) Overwrite(t *LogImpersonation) {
|
||||
if s.BeginAt.IsValue() {
|
||||
t.BeginAt = s.BeginAt.MustGet()
|
||||
}
|
||||
if !s.EndAt.IsUnset() {
|
||||
t.EndAt = s.EndAt.MustGetNull()
|
||||
}
|
||||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if s.ImpersonatorID.IsValue() {
|
||||
t.ImpersonatorID = s.ImpersonatorID.MustGet()
|
||||
}
|
||||
if s.TargetID.IsValue() {
|
||||
t.TargetID = s.TargetID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *LogImpersonationSetter) Apply(q *dialect.InsertQuery) {
|
||||
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
||||
return LogImpersonations.BeforeInsertHooks.RunHooks(ctx, exec, s)
|
||||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 5)
|
||||
if s.BeginAt.IsValue() {
|
||||
vals[0] = psql.Arg(s.BeginAt.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.EndAt.IsUnset() {
|
||||
vals[1] = psql.Arg(s.EndAt.MustGetNull())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
vals[2] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.ImpersonatorID.IsValue() {
|
||||
vals[3] = psql.Arg(s.ImpersonatorID.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.TargetID.IsValue() {
|
||||
vals[4] = psql.Arg(s.TargetID.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
||||
func (s LogImpersonationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
||||
return um.Set(s.Expressions()...)
|
||||
}
|
||||
|
||||
func (s LogImpersonationSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
|
||||
if s.BeginAt.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "begin_at")...),
|
||||
psql.Arg(s.BeginAt),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.EndAt.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "end_at")...),
|
||||
psql.Arg(s.EndAt),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "id")...),
|
||||
psql.Arg(s.ID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.ImpersonatorID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "impersonator_id")...),
|
||||
psql.Arg(s.ImpersonatorID),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.TargetID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "target_id")...),
|
||||
psql.Arg(s.TargetID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
// FindLogImpersonation retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindLogImpersonation(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LogImpersonation, error) {
|
||||
if len(cols) == 0 {
|
||||
return LogImpersonations.Query(
|
||||
sm.Where(LogImpersonations.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return LogImpersonations.Query(
|
||||
sm.Where(LogImpersonations.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Columns(LogImpersonations.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// LogImpersonationExists checks the presence of a single record by primary key
|
||||
func LogImpersonationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return LogImpersonations.Query(
|
||||
sm.Where(LogImpersonations.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after LogImpersonation is retrieved from the database
|
||||
func (o *LogImpersonation) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = LogImpersonations.AfterSelectHooks.RunHooks(ctx, exec, LogImpersonationSlice{o})
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = LogImpersonations.AfterInsertHooks.RunHooks(ctx, exec, LogImpersonationSlice{o})
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = LogImpersonations.AfterUpdateHooks.RunHooks(ctx, exec, LogImpersonationSlice{o})
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = LogImpersonations.AfterDeleteHooks.RunHooks(ctx, exec, LogImpersonationSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// primaryKeyVals returns the primary key values of the LogImpersonation
|
||||
func (o *LogImpersonation) primaryKeyVals() bob.Expression {
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *LogImpersonation) pkEQ() dialect.Expression {
|
||||
return psql.Quote("log_impersonation", "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 LogImpersonation
|
||||
func (o *LogImpersonation) Update(ctx context.Context, exec bob.Executor, s *LogImpersonationSetter) error {
|
||||
v, err := LogImpersonations.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 LogImpersonation record with an executor
|
||||
func (o *LogImpersonation) Delete(ctx context.Context, exec bob.Executor) error {
|
||||
_, err := LogImpersonations.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
// Reload refreshes the LogImpersonation using the executor
|
||||
func (o *LogImpersonation) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := LogImpersonations.Query(
|
||||
sm.Where(LogImpersonations.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 LogImpersonationSlice is retrieved from the database
|
||||
func (o LogImpersonationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = LogImpersonations.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeInsert:
|
||||
ctx, err = LogImpersonations.AfterInsertHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeUpdate:
|
||||
ctx, err = LogImpersonations.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
case bob.QueryTypeDelete:
|
||||
ctx, err = LogImpersonations.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (o LogImpersonationSlice) pkIN() dialect.Expression {
|
||||
if len(o) == 0 {
|
||||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Quote("log_impersonation", "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 LogImpersonationSlice) copyMatchingRows(from ...*LogImpersonation) {
|
||||
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 LogImpersonationSlice) 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 LogImpersonations.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 *LogImpersonation:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*LogImpersonation:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case LogImpersonationSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a LogImpersonation or a slice of LogImpersonation
|
||||
// then run the AfterUpdateHooks on the slice
|
||||
_, err = LogImpersonations.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
||||
func (o LogImpersonationSlice) 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 LogImpersonations.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 *LogImpersonation:
|
||||
o.copyMatchingRows(retrieved)
|
||||
case []*LogImpersonation:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
case LogImpersonationSlice:
|
||||
o.copyMatchingRows(retrieved...)
|
||||
default:
|
||||
// If the retrieved value is not a LogImpersonation or a slice of LogImpersonation
|
||||
// then run the AfterDeleteHooks on the slice
|
||||
_, err = LogImpersonations.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}))
|
||||
|
||||
q.AppendWhere(o.pkIN())
|
||||
})
|
||||
}
|
||||
|
||||
func (o LogImpersonationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LogImpersonationSetter) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := LogImpersonations.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o LogImpersonationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := LogImpersonations.Delete(o.DeleteMod()).Exec(ctx, exec)
|
||||
return err
|
||||
}
|
||||
|
||||
func (o LogImpersonationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
||||
if len(o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
o2, err := LogImpersonations.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.copyMatchingRows(o2...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ImpersonatorUser starts a query for related objects on user_
|
||||
func (o *LogImpersonation) ImpersonatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ImpersonatorID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os LogImpersonationSlice) ImpersonatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkImpersonatorID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkImpersonatorID = append(pkImpersonatorID, o.ImpersonatorID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkImpersonatorID), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// TargetUser starts a query for related objects on user_
|
||||
func (o *LogImpersonation) TargetUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.TargetID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os LogImpersonationSlice) TargetUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkTargetID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkTargetID = append(pkTargetID, o.TargetID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkTargetID), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
func attachLogImpersonationImpersonatorUser0(ctx context.Context, exec bob.Executor, count int, logImpersonation0 *LogImpersonation, user1 *User) (*LogImpersonation, error) {
|
||||
setter := &LogImpersonationSetter{
|
||||
ImpersonatorID: omit.From(user1.ID),
|
||||
}
|
||||
|
||||
err := logImpersonation0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachLogImpersonationImpersonatorUser0: %w", err)
|
||||
}
|
||||
|
||||
return logImpersonation0, nil
|
||||
}
|
||||
|
||||
func (logImpersonation0 *LogImpersonation) InsertImpersonatorUser(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 = attachLogImpersonationImpersonatorUser0(ctx, exec, 1, logImpersonation0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logImpersonation0.R.ImpersonatorUser = user1
|
||||
|
||||
user1.R.ImpersonatorLogImpersonations = append(user1.R.ImpersonatorLogImpersonations, logImpersonation0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (logImpersonation0 *LogImpersonation) AttachImpersonatorUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachLogImpersonationImpersonatorUser0(ctx, exec, 1, logImpersonation0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logImpersonation0.R.ImpersonatorUser = user1
|
||||
|
||||
user1.R.ImpersonatorLogImpersonations = append(user1.R.ImpersonatorLogImpersonations, logImpersonation0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachLogImpersonationTargetUser0(ctx context.Context, exec bob.Executor, count int, logImpersonation0 *LogImpersonation, user1 *User) (*LogImpersonation, error) {
|
||||
setter := &LogImpersonationSetter{
|
||||
TargetID: omit.From(user1.ID),
|
||||
}
|
||||
|
||||
err := logImpersonation0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachLogImpersonationTargetUser0: %w", err)
|
||||
}
|
||||
|
||||
return logImpersonation0, nil
|
||||
}
|
||||
|
||||
func (logImpersonation0 *LogImpersonation) InsertTargetUser(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 = attachLogImpersonationTargetUser0(ctx, exec, 1, logImpersonation0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logImpersonation0.R.TargetUser = user1
|
||||
|
||||
user1.R.TargetLogImpersonations = append(user1.R.TargetLogImpersonations, logImpersonation0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (logImpersonation0 *LogImpersonation) AttachTargetUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachLogImpersonationTargetUser0(ctx, exec, 1, logImpersonation0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logImpersonation0.R.TargetUser = user1
|
||||
|
||||
user1.R.TargetLogImpersonations = append(user1.R.TargetLogImpersonations, logImpersonation0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type logImpersonationWhere[Q psql.Filterable] struct {
|
||||
BeginAt psql.WhereMod[Q, time.Time]
|
||||
EndAt psql.WhereNullMod[Q, time.Time]
|
||||
ID psql.WhereMod[Q, int32]
|
||||
ImpersonatorID psql.WhereMod[Q, int32]
|
||||
TargetID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (logImpersonationWhere[Q]) AliasedAs(alias string) logImpersonationWhere[Q] {
|
||||
return buildLogImpersonationWhere[Q](buildLogImpersonationColumns(alias))
|
||||
}
|
||||
|
||||
func buildLogImpersonationWhere[Q psql.Filterable](cols logImpersonationColumns) logImpersonationWhere[Q] {
|
||||
return logImpersonationWhere[Q]{
|
||||
BeginAt: psql.Where[Q, time.Time](cols.BeginAt),
|
||||
EndAt: psql.WhereNull[Q, time.Time](cols.EndAt),
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
ImpersonatorID: psql.Where[Q, int32](cols.ImpersonatorID),
|
||||
TargetID: psql.Where[Q, int32](cols.TargetID),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *LogImpersonation) Preload(name string, retrieved any) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch name {
|
||||
case "ImpersonatorUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("logImpersonation cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ImpersonatorUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ImpersonatorLogImpersonations = LogImpersonationSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "TargetUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("logImpersonation cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.TargetUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.TargetLogImpersonations = LogImpersonationSlice{o}
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("logImpersonation has no relationship %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
type logImpersonationPreloader struct {
|
||||
ImpersonatorUser func(...psql.PreloadOption) psql.Preloader
|
||||
TargetUser func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildLogImpersonationPreloader() logImpersonationPreloader {
|
||||
return logImpersonationPreloader{
|
||||
ImpersonatorUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "ImpersonatorUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: LogImpersonations,
|
||||
To: Users,
|
||||
FromColumns: []string{"impersonator_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
TargetUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "TargetUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: LogImpersonations,
|
||||
To: Users,
|
||||
FromColumns: []string{"target_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type logImpersonationThenLoader[Q orm.Loadable] struct {
|
||||
ImpersonatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
TargetUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
func buildLogImpersonationThenLoader[Q orm.Loadable]() logImpersonationThenLoader[Q] {
|
||||
type ImpersonatorUserLoadInterface interface {
|
||||
LoadImpersonatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type TargetUserLoadInterface interface {
|
||||
LoadTargetUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
||||
return logImpersonationThenLoader[Q]{
|
||||
ImpersonatorUser: thenLoadBuilder[Q](
|
||||
"ImpersonatorUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImpersonatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImpersonatorUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
TargetUser: thenLoadBuilder[Q](
|
||||
"TargetUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved TargetUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadTargetUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadImpersonatorUser loads the logImpersonation's ImpersonatorUser into the .R struct
|
||||
func (o *LogImpersonation) LoadImpersonatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ImpersonatorUser = nil
|
||||
|
||||
related, err := o.ImpersonatorUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ImpersonatorLogImpersonations = LogImpersonationSlice{o}
|
||||
|
||||
o.R.ImpersonatorUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImpersonatorUser loads the logImpersonation's ImpersonatorUser into the .R struct
|
||||
func (os LogImpersonationSlice) LoadImpersonatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.ImpersonatorUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
|
||||
if !(o.ImpersonatorID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ImpersonatorLogImpersonations = append(rel.R.ImpersonatorLogImpersonations, o)
|
||||
|
||||
o.R.ImpersonatorUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadTargetUser loads the logImpersonation's TargetUser into the .R struct
|
||||
func (o *LogImpersonation) LoadTargetUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.TargetUser = nil
|
||||
|
||||
related, err := o.TargetUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.TargetLogImpersonations = LogImpersonationSlice{o}
|
||||
|
||||
o.R.TargetUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadTargetUser loads the logImpersonation's TargetUser into the .R struct
|
||||
func (os LogImpersonationSlice) LoadTargetUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.TargetUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
|
||||
if !(o.TargetID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.TargetLogImpersonations = append(rel.R.TargetLogImpersonations, o)
|
||||
|
||||
o.R.TargetUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -64,6 +64,8 @@ type userR struct {
|
|||
CreatorFiles FileuploadFileSlice // fileupload.file.file_creator_id_fkey
|
||||
FileuploadPool FileuploadPoolSlice // fileupload.pool.pool_creator_id_fkey
|
||||
CreatorLeads LeadSlice // lead.lead_creator_fkey
|
||||
ImpersonatorLogImpersonations LogImpersonationSlice // log_impersonation.log_impersonation_impersonator_id_fkey
|
||||
TargetLogImpersonations LogImpersonationSlice // log_impersonation.log_impersonation_target_id_fkey
|
||||
CreatorNoteAudios NoteAudioSlice // note_audio.note_audio_creator_id_fkey
|
||||
DeletorNoteAudios NoteAudioSlice // note_audio.note_audio_deletor_id_fkey
|
||||
CreatorNoteImages NoteImageSlice // note_image.note_image_creator_id_fkey
|
||||
|
|
@ -865,6 +867,54 @@ func (os UserSlice) CreatorLeads(mods ...bob.Mod[*dialect.SelectQuery]) LeadsQue
|
|||
)...)
|
||||
}
|
||||
|
||||
// ImpersonatorLogImpersonations starts a query for related objects on log_impersonation
|
||||
func (o *User) ImpersonatorLogImpersonations(mods ...bob.Mod[*dialect.SelectQuery]) LogImpersonationsQuery {
|
||||
return LogImpersonations.Query(append(mods,
|
||||
sm.Where(LogImpersonations.Columns.ImpersonatorID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) ImpersonatorLogImpersonations(mods ...bob.Mod[*dialect.SelectQuery]) LogImpersonationsQuery {
|
||||
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 LogImpersonations.Query(append(mods,
|
||||
sm.Where(psql.Group(LogImpersonations.Columns.ImpersonatorID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// TargetLogImpersonations starts a query for related objects on log_impersonation
|
||||
func (o *User) TargetLogImpersonations(mods ...bob.Mod[*dialect.SelectQuery]) LogImpersonationsQuery {
|
||||
return LogImpersonations.Query(append(mods,
|
||||
sm.Where(LogImpersonations.Columns.TargetID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) TargetLogImpersonations(mods ...bob.Mod[*dialect.SelectQuery]) LogImpersonationsQuery {
|
||||
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 LogImpersonations.Query(append(mods,
|
||||
sm.Where(psql.Group(LogImpersonations.Columns.TargetID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// CreatorNoteAudios starts a query for related objects on note_audio
|
||||
func (o *User) CreatorNoteAudios(mods ...bob.Mod[*dialect.SelectQuery]) NoteAudiosQuery {
|
||||
return NoteAudios.Query(append(mods,
|
||||
|
|
@ -1885,6 +1935,142 @@ func (user0 *User) AttachCreatorLeads(ctx context.Context, exec bob.Executor, re
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertUserImpersonatorLogImpersonations0(ctx context.Context, exec bob.Executor, logImpersonations1 []*LogImpersonationSetter, user0 *User) (LogImpersonationSlice, error) {
|
||||
for i := range logImpersonations1 {
|
||||
logImpersonations1[i].ImpersonatorID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := LogImpersonations.Insert(bob.ToMods(logImpersonations1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserImpersonatorLogImpersonations0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserImpersonatorLogImpersonations0(ctx context.Context, exec bob.Executor, count int, logImpersonations1 LogImpersonationSlice, user0 *User) (LogImpersonationSlice, error) {
|
||||
setter := &LogImpersonationSetter{
|
||||
ImpersonatorID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := logImpersonations1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserImpersonatorLogImpersonations0: %w", err)
|
||||
}
|
||||
|
||||
return logImpersonations1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertImpersonatorLogImpersonations(ctx context.Context, exec bob.Executor, related ...*LogImpersonationSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
logImpersonations1, err := insertUserImpersonatorLogImpersonations0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.ImpersonatorLogImpersonations = append(user0.R.ImpersonatorLogImpersonations, logImpersonations1...)
|
||||
|
||||
for _, rel := range logImpersonations1 {
|
||||
rel.R.ImpersonatorUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachImpersonatorLogImpersonations(ctx context.Context, exec bob.Executor, related ...*LogImpersonation) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
logImpersonations1 := LogImpersonationSlice(related)
|
||||
|
||||
_, err = attachUserImpersonatorLogImpersonations0(ctx, exec, len(related), logImpersonations1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.ImpersonatorLogImpersonations = append(user0.R.ImpersonatorLogImpersonations, logImpersonations1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.ImpersonatorUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertUserTargetLogImpersonations0(ctx context.Context, exec bob.Executor, logImpersonations1 []*LogImpersonationSetter, user0 *User) (LogImpersonationSlice, error) {
|
||||
for i := range logImpersonations1 {
|
||||
logImpersonations1[i].TargetID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := LogImpersonations.Insert(bob.ToMods(logImpersonations1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserTargetLogImpersonations0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserTargetLogImpersonations0(ctx context.Context, exec bob.Executor, count int, logImpersonations1 LogImpersonationSlice, user0 *User) (LogImpersonationSlice, error) {
|
||||
setter := &LogImpersonationSetter{
|
||||
TargetID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := logImpersonations1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserTargetLogImpersonations0: %w", err)
|
||||
}
|
||||
|
||||
return logImpersonations1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertTargetLogImpersonations(ctx context.Context, exec bob.Executor, related ...*LogImpersonationSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
logImpersonations1, err := insertUserTargetLogImpersonations0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.TargetLogImpersonations = append(user0.R.TargetLogImpersonations, logImpersonations1...)
|
||||
|
||||
for _, rel := range logImpersonations1 {
|
||||
rel.R.TargetUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachTargetLogImpersonations(ctx context.Context, exec bob.Executor, related ...*LogImpersonation) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
logImpersonations1 := LogImpersonationSlice(related)
|
||||
|
||||
_, err = attachUserTargetLogImpersonations0(ctx, exec, len(related), logImpersonations1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.TargetLogImpersonations = append(user0.R.TargetLogImpersonations, logImpersonations1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.TargetUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertUserCreatorNoteAudios0(ctx context.Context, exec bob.Executor, noteAudios1 []*NoteAudioSetter, user0 *User) (NoteAudioSlice, error) {
|
||||
for i := range noteAudios1 {
|
||||
noteAudios1[i].CreatorID = omit.From(user0.ID)
|
||||
|
|
@ -3191,6 +3377,34 @@ func (o *User) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "ImpersonatorLogImpersonations":
|
||||
rels, ok := retrieved.(LogImpersonationSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ImpersonatorLogImpersonations = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.ImpersonatorUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "TargetLogImpersonations":
|
||||
rels, ok := retrieved.(LogImpersonationSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.TargetLogImpersonations = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.TargetUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "CreatorNoteAudios":
|
||||
rels, ok := retrieved.(NoteAudioSlice)
|
||||
if !ok {
|
||||
|
|
@ -3464,6 +3678,8 @@ type userThenLoader[Q orm.Loadable] struct {
|
|||
CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
FileuploadPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorLeads func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ImpersonatorLogImpersonations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
TargetLogImpersonations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -3511,6 +3727,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
type CreatorLeadsLoadInterface interface {
|
||||
LoadCreatorLeads(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ImpersonatorLogImpersonationsLoadInterface interface {
|
||||
LoadImpersonatorLogImpersonations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type TargetLogImpersonationsLoadInterface interface {
|
||||
LoadTargetLogImpersonations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorNoteAudiosLoadInterface interface {
|
||||
LoadCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -3618,6 +3840,18 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
return retrieved.LoadCreatorLeads(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ImpersonatorLogImpersonations: thenLoadBuilder[Q](
|
||||
"ImpersonatorLogImpersonations",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImpersonatorLogImpersonationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadImpersonatorLogImpersonations(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
TargetLogImpersonations: thenLoadBuilder[Q](
|
||||
"TargetLogImpersonations",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved TargetLogImpersonationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadTargetLogImpersonations(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorNoteAudios: thenLoadBuilder[Q](
|
||||
"CreatorNoteAudios",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteAudiosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -4278,6 +4512,128 @@ func (os UserSlice) LoadCreatorLeads(ctx context.Context, exec bob.Executor, mod
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadImpersonatorLogImpersonations loads the user's ImpersonatorLogImpersonations into the .R struct
|
||||
func (o *User) LoadImpersonatorLogImpersonations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ImpersonatorLogImpersonations = nil
|
||||
|
||||
related, err := o.ImpersonatorLogImpersonations(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.ImpersonatorUser = o
|
||||
}
|
||||
|
||||
o.R.ImpersonatorLogImpersonations = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImpersonatorLogImpersonations loads the user's ImpersonatorLogImpersonations into the .R struct
|
||||
func (os UserSlice) LoadImpersonatorLogImpersonations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
logImpersonations, err := os.ImpersonatorLogImpersonations(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.ImpersonatorLogImpersonations = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range logImpersonations {
|
||||
|
||||
if !(o.ID == rel.ImpersonatorID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ImpersonatorUser = o
|
||||
|
||||
o.R.ImpersonatorLogImpersonations = append(o.R.ImpersonatorLogImpersonations, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadTargetLogImpersonations loads the user's TargetLogImpersonations into the .R struct
|
||||
func (o *User) LoadTargetLogImpersonations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.TargetLogImpersonations = nil
|
||||
|
||||
related, err := o.TargetLogImpersonations(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.TargetUser = o
|
||||
}
|
||||
|
||||
o.R.TargetLogImpersonations = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadTargetLogImpersonations loads the user's TargetLogImpersonations into the .R struct
|
||||
func (os UserSlice) LoadTargetLogImpersonations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
logImpersonations, err := os.TargetLogImpersonations(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.TargetLogImpersonations = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range logImpersonations {
|
||||
|
||||
if !(o.ID == rel.TargetID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.TargetUser = o
|
||||
|
||||
o.R.TargetLogImpersonations = append(o.R.TargetLogImpersonations, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorNoteAudios loads the user's CreatorNoteAudios into the .R struct
|
||||
func (o *User) LoadCreatorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue