2928 lines
80 KiB
Go
2928 lines
80 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"
|
|
)
|
|
|
|
// User is an object representing the database table.
|
|
type User struct {
|
|
ID int32 `db:"id,pk" `
|
|
ArcgisAccessToken null.Val[string] `db:"arcgis_access_token" `
|
|
ArcgisLicense null.Val[enums.Arcgislicensetype] `db:"arcgis_license" `
|
|
ArcgisRefreshToken null.Val[string] `db:"arcgis_refresh_token" `
|
|
ArcgisRefreshTokenExpires null.Val[time.Time] `db:"arcgis_refresh_token_expires" `
|
|
ArcgisRole null.Val[string] `db:"arcgis_role" `
|
|
DisplayName string `db:"display_name" `
|
|
Email null.Val[string] `db:"email" `
|
|
OrganizationID int32 `db:"organization_id" `
|
|
Username string `db:"username" `
|
|
PasswordHashType enums.Hashtype `db:"password_hash_type" `
|
|
PasswordHash string `db:"password_hash" `
|
|
|
|
R userR `db:"-" `
|
|
|
|
C userC `db:"-" `
|
|
}
|
|
|
|
// UserSlice is an alias for a slice of pointers to User.
|
|
// This should almost always be used instead of []*User.
|
|
type UserSlice []*User
|
|
|
|
// Users contains methods to work with the user_ table
|
|
var Users = psql.NewTablex[*User, UserSlice, *UserSetter]("", "user_", buildUserColumns("user_"))
|
|
|
|
// UsersQuery is a query on the user_ table
|
|
type UsersQuery = *psql.ViewQuery[*User, UserSlice]
|
|
|
|
// userR is where relationships are stored.
|
|
type userR struct {
|
|
PublicUserUser ArcgisUserSlice // arcgis.user_.user__public_user_id_fkey
|
|
CreatorFiles FileuploadFileSlice // fileupload.file.file_creator_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
|
|
DeletorNoteImages NoteImageSlice // note_image.note_image_deletor_id_fkey
|
|
UserNotifications NotificationSlice // notification.notification_user_id_fkey
|
|
UserOauthTokens OauthTokenSlice // oauth_token.oauth_token_user_id_fkey
|
|
Organization *Organization // user_.user__organization_id_fkey
|
|
}
|
|
|
|
func buildUserColumns(alias string) userColumns {
|
|
return userColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "arcgis_access_token", "arcgis_license", "arcgis_refresh_token", "arcgis_refresh_token_expires", "arcgis_role", "display_name", "email", "organization_id", "username", "password_hash_type", "password_hash",
|
|
).WithParent("user_"),
|
|
tableAlias: alias,
|
|
ID: psql.Quote(alias, "id"),
|
|
ArcgisAccessToken: psql.Quote(alias, "arcgis_access_token"),
|
|
ArcgisLicense: psql.Quote(alias, "arcgis_license"),
|
|
ArcgisRefreshToken: psql.Quote(alias, "arcgis_refresh_token"),
|
|
ArcgisRefreshTokenExpires: psql.Quote(alias, "arcgis_refresh_token_expires"),
|
|
ArcgisRole: psql.Quote(alias, "arcgis_role"),
|
|
DisplayName: psql.Quote(alias, "display_name"),
|
|
Email: psql.Quote(alias, "email"),
|
|
OrganizationID: psql.Quote(alias, "organization_id"),
|
|
Username: psql.Quote(alias, "username"),
|
|
PasswordHashType: psql.Quote(alias, "password_hash_type"),
|
|
PasswordHash: psql.Quote(alias, "password_hash"),
|
|
}
|
|
}
|
|
|
|
type userColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ID psql.Expression
|
|
ArcgisAccessToken psql.Expression
|
|
ArcgisLicense psql.Expression
|
|
ArcgisRefreshToken psql.Expression
|
|
ArcgisRefreshTokenExpires psql.Expression
|
|
ArcgisRole psql.Expression
|
|
DisplayName psql.Expression
|
|
Email psql.Expression
|
|
OrganizationID psql.Expression
|
|
Username psql.Expression
|
|
PasswordHashType psql.Expression
|
|
PasswordHash psql.Expression
|
|
}
|
|
|
|
func (c userColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (userColumns) AliasedAs(alias string) userColumns {
|
|
return buildUserColumns(alias)
|
|
}
|
|
|
|
// UserSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type UserSetter struct {
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
ArcgisAccessToken omitnull.Val[string] `db:"arcgis_access_token" `
|
|
ArcgisLicense omitnull.Val[enums.Arcgislicensetype] `db:"arcgis_license" `
|
|
ArcgisRefreshToken omitnull.Val[string] `db:"arcgis_refresh_token" `
|
|
ArcgisRefreshTokenExpires omitnull.Val[time.Time] `db:"arcgis_refresh_token_expires" `
|
|
ArcgisRole omitnull.Val[string] `db:"arcgis_role" `
|
|
DisplayName omit.Val[string] `db:"display_name" `
|
|
Email omitnull.Val[string] `db:"email" `
|
|
OrganizationID omit.Val[int32] `db:"organization_id" `
|
|
Username omit.Val[string] `db:"username" `
|
|
PasswordHashType omit.Val[enums.Hashtype] `db:"password_hash_type" `
|
|
PasswordHash omit.Val[string] `db:"password_hash" `
|
|
}
|
|
|
|
func (s UserSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 12)
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if !s.ArcgisAccessToken.IsUnset() {
|
|
vals = append(vals, "arcgis_access_token")
|
|
}
|
|
if !s.ArcgisLicense.IsUnset() {
|
|
vals = append(vals, "arcgis_license")
|
|
}
|
|
if !s.ArcgisRefreshToken.IsUnset() {
|
|
vals = append(vals, "arcgis_refresh_token")
|
|
}
|
|
if !s.ArcgisRefreshTokenExpires.IsUnset() {
|
|
vals = append(vals, "arcgis_refresh_token_expires")
|
|
}
|
|
if !s.ArcgisRole.IsUnset() {
|
|
vals = append(vals, "arcgis_role")
|
|
}
|
|
if s.DisplayName.IsValue() {
|
|
vals = append(vals, "display_name")
|
|
}
|
|
if !s.Email.IsUnset() {
|
|
vals = append(vals, "email")
|
|
}
|
|
if s.OrganizationID.IsValue() {
|
|
vals = append(vals, "organization_id")
|
|
}
|
|
if s.Username.IsValue() {
|
|
vals = append(vals, "username")
|
|
}
|
|
if s.PasswordHashType.IsValue() {
|
|
vals = append(vals, "password_hash_type")
|
|
}
|
|
if s.PasswordHash.IsValue() {
|
|
vals = append(vals, "password_hash")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s UserSetter) Overwrite(t *User) {
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if !s.ArcgisAccessToken.IsUnset() {
|
|
t.ArcgisAccessToken = s.ArcgisAccessToken.MustGetNull()
|
|
}
|
|
if !s.ArcgisLicense.IsUnset() {
|
|
t.ArcgisLicense = s.ArcgisLicense.MustGetNull()
|
|
}
|
|
if !s.ArcgisRefreshToken.IsUnset() {
|
|
t.ArcgisRefreshToken = s.ArcgisRefreshToken.MustGetNull()
|
|
}
|
|
if !s.ArcgisRefreshTokenExpires.IsUnset() {
|
|
t.ArcgisRefreshTokenExpires = s.ArcgisRefreshTokenExpires.MustGetNull()
|
|
}
|
|
if !s.ArcgisRole.IsUnset() {
|
|
t.ArcgisRole = s.ArcgisRole.MustGetNull()
|
|
}
|
|
if s.DisplayName.IsValue() {
|
|
t.DisplayName = s.DisplayName.MustGet()
|
|
}
|
|
if !s.Email.IsUnset() {
|
|
t.Email = s.Email.MustGetNull()
|
|
}
|
|
if s.OrganizationID.IsValue() {
|
|
t.OrganizationID = s.OrganizationID.MustGet()
|
|
}
|
|
if s.Username.IsValue() {
|
|
t.Username = s.Username.MustGet()
|
|
}
|
|
if s.PasswordHashType.IsValue() {
|
|
t.PasswordHashType = s.PasswordHashType.MustGet()
|
|
}
|
|
if s.PasswordHash.IsValue() {
|
|
t.PasswordHash = s.PasswordHash.MustGet()
|
|
}
|
|
}
|
|
|
|
func (s *UserSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return Users.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, 12)
|
|
if s.ID.IsValue() {
|
|
vals[0] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisAccessToken.IsUnset() {
|
|
vals[1] = psql.Arg(s.ArcgisAccessToken.MustGetNull())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisLicense.IsUnset() {
|
|
vals[2] = psql.Arg(s.ArcgisLicense.MustGetNull())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisRefreshToken.IsUnset() {
|
|
vals[3] = psql.Arg(s.ArcgisRefreshToken.MustGetNull())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisRefreshTokenExpires.IsUnset() {
|
|
vals[4] = psql.Arg(s.ArcgisRefreshTokenExpires.MustGetNull())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisRole.IsUnset() {
|
|
vals[5] = psql.Arg(s.ArcgisRole.MustGetNull())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.DisplayName.IsValue() {
|
|
vals[6] = psql.Arg(s.DisplayName.MustGet())
|
|
} else {
|
|
vals[6] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.Email.IsUnset() {
|
|
vals[7] = psql.Arg(s.Email.MustGetNull())
|
|
} else {
|
|
vals[7] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.OrganizationID.IsValue() {
|
|
vals[8] = psql.Arg(s.OrganizationID.MustGet())
|
|
} else {
|
|
vals[8] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Username.IsValue() {
|
|
vals[9] = psql.Arg(s.Username.MustGet())
|
|
} else {
|
|
vals[9] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.PasswordHashType.IsValue() {
|
|
vals[10] = psql.Arg(s.PasswordHashType.MustGet())
|
|
} else {
|
|
vals[10] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.PasswordHash.IsValue() {
|
|
vals[11] = psql.Arg(s.PasswordHash.MustGet())
|
|
} else {
|
|
vals[11] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s UserSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s UserSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 12)
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisAccessToken.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_access_token")...),
|
|
psql.Arg(s.ArcgisAccessToken),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisLicense.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_license")...),
|
|
psql.Arg(s.ArcgisLicense),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisRefreshToken.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_refresh_token")...),
|
|
psql.Arg(s.ArcgisRefreshToken),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisRefreshTokenExpires.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_refresh_token_expires")...),
|
|
psql.Arg(s.ArcgisRefreshTokenExpires),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisRole.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_role")...),
|
|
psql.Arg(s.ArcgisRole),
|
|
}})
|
|
}
|
|
|
|
if s.DisplayName.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "display_name")...),
|
|
psql.Arg(s.DisplayName),
|
|
}})
|
|
}
|
|
|
|
if !s.Email.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "email")...),
|
|
psql.Arg(s.Email),
|
|
}})
|
|
}
|
|
|
|
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.Username.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "username")...),
|
|
psql.Arg(s.Username),
|
|
}})
|
|
}
|
|
|
|
if s.PasswordHashType.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "password_hash_type")...),
|
|
psql.Arg(s.PasswordHashType),
|
|
}})
|
|
}
|
|
|
|
if s.PasswordHash.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "password_hash")...),
|
|
psql.Arg(s.PasswordHash),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindUser retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindUser(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*User, error) {
|
|
if len(cols) == 0 {
|
|
return Users.Query(
|
|
sm.Where(Users.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return Users.Query(
|
|
sm.Where(Users.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(Users.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// UserExists checks the presence of a single record by primary key
|
|
func UserExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return Users.Query(
|
|
sm.Where(Users.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after User is retrieved from the database
|
|
func (o *User) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = Users.AfterSelectHooks.RunHooks(ctx, exec, UserSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = Users.AfterInsertHooks.RunHooks(ctx, exec, UserSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = Users.AfterUpdateHooks.RunHooks(ctx, exec, UserSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = Users.AfterDeleteHooks.RunHooks(ctx, exec, UserSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the User
|
|
func (o *User) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *User) pkEQ() dialect.Expression {
|
|
return psql.Quote("user_", "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 User
|
|
func (o *User) Update(ctx context.Context, exec bob.Executor, s *UserSetter) error {
|
|
v, err := Users.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 User record with an executor
|
|
func (o *User) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := Users.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the User using the executor
|
|
func (o *User) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := Users.Query(
|
|
sm.Where(Users.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 UserSlice is retrieved from the database
|
|
func (o UserSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = Users.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = Users.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = Users.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = Users.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o UserSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("user_", "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 UserSlice) copyMatchingRows(from ...*User) {
|
|
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 UserSlice) 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 Users.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 *User:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*User:
|
|
o.copyMatchingRows(retrieved...)
|
|
case UserSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a User or a slice of User
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = Users.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o UserSlice) 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 Users.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 *User:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*User:
|
|
o.copyMatchingRows(retrieved...)
|
|
case UserSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a User or a slice of User
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = Users.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o UserSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals UserSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := Users.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o UserSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := Users.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o UserSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := Users.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// PublicUserUser starts a query for related objects on arcgis.user_
|
|
func (o *User) PublicUserUser(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisUsersQuery {
|
|
return ArcgisUsers.Query(append(mods,
|
|
sm.Where(ArcgisUsers.Columns.PublicUserID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) PublicUserUser(mods ...bob.Mod[*dialect.SelectQuery]) ArcgisUsersQuery {
|
|
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 ArcgisUsers.Query(append(mods,
|
|
sm.Where(psql.Group(ArcgisUsers.Columns.PublicUserID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// CreatorFiles starts a query for related objects on fileupload.file
|
|
func (o *User) CreatorFiles(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadFilesQuery {
|
|
return FileuploadFiles.Query(append(mods,
|
|
sm.Where(FileuploadFiles.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) CreatorFiles(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadFilesQuery {
|
|
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 FileuploadFiles.Query(append(mods,
|
|
sm.Where(psql.Group(FileuploadFiles.Columns.CreatorID).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,
|
|
sm.Where(NoteAudios.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) CreatorNoteAudios(mods ...bob.Mod[*dialect.SelectQuery]) NoteAudiosQuery {
|
|
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 NoteAudios.Query(append(mods,
|
|
sm.Where(psql.Group(NoteAudios.Columns.CreatorID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// DeletorNoteAudios starts a query for related objects on note_audio
|
|
func (o *User) DeletorNoteAudios(mods ...bob.Mod[*dialect.SelectQuery]) NoteAudiosQuery {
|
|
return NoteAudios.Query(append(mods,
|
|
sm.Where(NoteAudios.Columns.DeletorID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) DeletorNoteAudios(mods ...bob.Mod[*dialect.SelectQuery]) NoteAudiosQuery {
|
|
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 NoteAudios.Query(append(mods,
|
|
sm.Where(psql.Group(NoteAudios.Columns.DeletorID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// CreatorNoteImages starts a query for related objects on note_image
|
|
func (o *User) CreatorNoteImages(mods ...bob.Mod[*dialect.SelectQuery]) NoteImagesQuery {
|
|
return NoteImages.Query(append(mods,
|
|
sm.Where(NoteImages.Columns.CreatorID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) CreatorNoteImages(mods ...bob.Mod[*dialect.SelectQuery]) NoteImagesQuery {
|
|
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 NoteImages.Query(append(mods,
|
|
sm.Where(psql.Group(NoteImages.Columns.CreatorID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// DeletorNoteImages starts a query for related objects on note_image
|
|
func (o *User) DeletorNoteImages(mods ...bob.Mod[*dialect.SelectQuery]) NoteImagesQuery {
|
|
return NoteImages.Query(append(mods,
|
|
sm.Where(NoteImages.Columns.DeletorID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) DeletorNoteImages(mods ...bob.Mod[*dialect.SelectQuery]) NoteImagesQuery {
|
|
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 NoteImages.Query(append(mods,
|
|
sm.Where(psql.Group(NoteImages.Columns.DeletorID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// UserNotifications starts a query for related objects on notification
|
|
func (o *User) UserNotifications(mods ...bob.Mod[*dialect.SelectQuery]) NotificationsQuery {
|
|
return Notifications.Query(append(mods,
|
|
sm.Where(Notifications.Columns.UserID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) UserNotifications(mods ...bob.Mod[*dialect.SelectQuery]) NotificationsQuery {
|
|
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 Notifications.Query(append(mods,
|
|
sm.Where(psql.Group(Notifications.Columns.UserID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// UserOauthTokens starts a query for related objects on oauth_token
|
|
func (o *User) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) OauthTokensQuery {
|
|
return OauthTokens.Query(append(mods,
|
|
sm.Where(OauthTokens.Columns.UserID.EQ(psql.Arg(o.ID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) OauthTokensQuery {
|
|
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 OauthTokens.Query(append(mods,
|
|
sm.Where(psql.Group(OauthTokens.Columns.UserID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
// Organization starts a query for related objects on organization
|
|
func (o *User) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery {
|
|
return Organizations.Query(append(mods,
|
|
sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))),
|
|
)...)
|
|
}
|
|
|
|
func (os UserSlice) 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 insertUserPublicUserUser0(ctx context.Context, exec bob.Executor, arcgisusers1 []*ArcgisUserSetter, user0 *User) (ArcgisUserSlice, error) {
|
|
for i := range arcgisusers1 {
|
|
arcgisusers1[i].PublicUserID = omit.From(user0.ID)
|
|
}
|
|
|
|
ret, err := ArcgisUsers.Insert(bob.ToMods(arcgisusers1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserPublicUserUser0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserPublicUserUser0(ctx context.Context, exec bob.Executor, count int, arcgisusers1 ArcgisUserSlice, user0 *User) (ArcgisUserSlice, error) {
|
|
setter := &ArcgisUserSetter{
|
|
PublicUserID: omit.From(user0.ID),
|
|
}
|
|
|
|
err := arcgisusers1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserPublicUserUser0: %w", err)
|
|
}
|
|
|
|
return arcgisusers1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertPublicUserUser(ctx context.Context, exec bob.Executor, related ...*ArcgisUserSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
arcgisusers1, err := insertUserPublicUserUser0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.PublicUserUser = append(user0.R.PublicUserUser, arcgisusers1...)
|
|
|
|
for _, rel := range arcgisusers1 {
|
|
rel.R.PublicUserUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachPublicUserUser(ctx context.Context, exec bob.Executor, related ...*ArcgisUser) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
arcgisusers1 := ArcgisUserSlice(related)
|
|
|
|
_, err = attachUserPublicUserUser0(ctx, exec, len(related), arcgisusers1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.PublicUserUser = append(user0.R.PublicUserUser, arcgisusers1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.PublicUserUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func insertUserCreatorFiles0(ctx context.Context, exec bob.Executor, fileuploadFiles1 []*FileuploadFileSetter, user0 *User) (FileuploadFileSlice, error) {
|
|
for i := range fileuploadFiles1 {
|
|
fileuploadFiles1[i].CreatorID = omit.From(user0.ID)
|
|
}
|
|
|
|
ret, err := FileuploadFiles.Insert(bob.ToMods(fileuploadFiles1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserCreatorFiles0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserCreatorFiles0(ctx context.Context, exec bob.Executor, count int, fileuploadFiles1 FileuploadFileSlice, user0 *User) (FileuploadFileSlice, error) {
|
|
setter := &FileuploadFileSetter{
|
|
CreatorID: omit.From(user0.ID),
|
|
}
|
|
|
|
err := fileuploadFiles1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserCreatorFiles0: %w", err)
|
|
}
|
|
|
|
return fileuploadFiles1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertCreatorFiles(ctx context.Context, exec bob.Executor, related ...*FileuploadFileSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
fileuploadFiles1, err := insertUserCreatorFiles0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.CreatorFiles = append(user0.R.CreatorFiles, fileuploadFiles1...)
|
|
|
|
for _, rel := range fileuploadFiles1 {
|
|
rel.R.CreatorUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachCreatorFiles(ctx context.Context, exec bob.Executor, related ...*FileuploadFile) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
fileuploadFiles1 := FileuploadFileSlice(related)
|
|
|
|
_, err = attachUserCreatorFiles0(ctx, exec, len(related), fileuploadFiles1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.CreatorFiles = append(user0.R.CreatorFiles, fileuploadFiles1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.CreatorUser = 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)
|
|
}
|
|
|
|
ret, err := NoteAudios.Insert(bob.ToMods(noteAudios1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserCreatorNoteAudios0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserCreatorNoteAudios0(ctx context.Context, exec bob.Executor, count int, noteAudios1 NoteAudioSlice, user0 *User) (NoteAudioSlice, error) {
|
|
setter := &NoteAudioSetter{
|
|
CreatorID: omit.From(user0.ID),
|
|
}
|
|
|
|
err := noteAudios1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserCreatorNoteAudios0: %w", err)
|
|
}
|
|
|
|
return noteAudios1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertCreatorNoteAudios(ctx context.Context, exec bob.Executor, related ...*NoteAudioSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
noteAudios1, err := insertUserCreatorNoteAudios0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.CreatorNoteAudios = append(user0.R.CreatorNoteAudios, noteAudios1...)
|
|
|
|
for _, rel := range noteAudios1 {
|
|
rel.R.CreatorUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachCreatorNoteAudios(ctx context.Context, exec bob.Executor, related ...*NoteAudio) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
noteAudios1 := NoteAudioSlice(related)
|
|
|
|
_, err = attachUserCreatorNoteAudios0(ctx, exec, len(related), noteAudios1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.CreatorNoteAudios = append(user0.R.CreatorNoteAudios, noteAudios1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.CreatorUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func insertUserDeletorNoteAudios0(ctx context.Context, exec bob.Executor, noteAudios1 []*NoteAudioSetter, user0 *User) (NoteAudioSlice, error) {
|
|
for i := range noteAudios1 {
|
|
noteAudios1[i].DeletorID = omitnull.From(user0.ID)
|
|
}
|
|
|
|
ret, err := NoteAudios.Insert(bob.ToMods(noteAudios1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserDeletorNoteAudios0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserDeletorNoteAudios0(ctx context.Context, exec bob.Executor, count int, noteAudios1 NoteAudioSlice, user0 *User) (NoteAudioSlice, error) {
|
|
setter := &NoteAudioSetter{
|
|
DeletorID: omitnull.From(user0.ID),
|
|
}
|
|
|
|
err := noteAudios1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserDeletorNoteAudios0: %w", err)
|
|
}
|
|
|
|
return noteAudios1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertDeletorNoteAudios(ctx context.Context, exec bob.Executor, related ...*NoteAudioSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
noteAudios1, err := insertUserDeletorNoteAudios0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.DeletorNoteAudios = append(user0.R.DeletorNoteAudios, noteAudios1...)
|
|
|
|
for _, rel := range noteAudios1 {
|
|
rel.R.DeletorUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachDeletorNoteAudios(ctx context.Context, exec bob.Executor, related ...*NoteAudio) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
noteAudios1 := NoteAudioSlice(related)
|
|
|
|
_, err = attachUserDeletorNoteAudios0(ctx, exec, len(related), noteAudios1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.DeletorNoteAudios = append(user0.R.DeletorNoteAudios, noteAudios1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.DeletorUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func insertUserCreatorNoteImages0(ctx context.Context, exec bob.Executor, noteImages1 []*NoteImageSetter, user0 *User) (NoteImageSlice, error) {
|
|
for i := range noteImages1 {
|
|
noteImages1[i].CreatorID = omit.From(user0.ID)
|
|
}
|
|
|
|
ret, err := NoteImages.Insert(bob.ToMods(noteImages1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserCreatorNoteImages0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserCreatorNoteImages0(ctx context.Context, exec bob.Executor, count int, noteImages1 NoteImageSlice, user0 *User) (NoteImageSlice, error) {
|
|
setter := &NoteImageSetter{
|
|
CreatorID: omit.From(user0.ID),
|
|
}
|
|
|
|
err := noteImages1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserCreatorNoteImages0: %w", err)
|
|
}
|
|
|
|
return noteImages1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertCreatorNoteImages(ctx context.Context, exec bob.Executor, related ...*NoteImageSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
noteImages1, err := insertUserCreatorNoteImages0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.CreatorNoteImages = append(user0.R.CreatorNoteImages, noteImages1...)
|
|
|
|
for _, rel := range noteImages1 {
|
|
rel.R.CreatorUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachCreatorNoteImages(ctx context.Context, exec bob.Executor, related ...*NoteImage) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
noteImages1 := NoteImageSlice(related)
|
|
|
|
_, err = attachUserCreatorNoteImages0(ctx, exec, len(related), noteImages1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.CreatorNoteImages = append(user0.R.CreatorNoteImages, noteImages1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.CreatorUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func insertUserDeletorNoteImages0(ctx context.Context, exec bob.Executor, noteImages1 []*NoteImageSetter, user0 *User) (NoteImageSlice, error) {
|
|
for i := range noteImages1 {
|
|
noteImages1[i].DeletorID = omitnull.From(user0.ID)
|
|
}
|
|
|
|
ret, err := NoteImages.Insert(bob.ToMods(noteImages1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserDeletorNoteImages0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserDeletorNoteImages0(ctx context.Context, exec bob.Executor, count int, noteImages1 NoteImageSlice, user0 *User) (NoteImageSlice, error) {
|
|
setter := &NoteImageSetter{
|
|
DeletorID: omitnull.From(user0.ID),
|
|
}
|
|
|
|
err := noteImages1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserDeletorNoteImages0: %w", err)
|
|
}
|
|
|
|
return noteImages1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertDeletorNoteImages(ctx context.Context, exec bob.Executor, related ...*NoteImageSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
noteImages1, err := insertUserDeletorNoteImages0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.DeletorNoteImages = append(user0.R.DeletorNoteImages, noteImages1...)
|
|
|
|
for _, rel := range noteImages1 {
|
|
rel.R.DeletorUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachDeletorNoteImages(ctx context.Context, exec bob.Executor, related ...*NoteImage) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
noteImages1 := NoteImageSlice(related)
|
|
|
|
_, err = attachUserDeletorNoteImages0(ctx, exec, len(related), noteImages1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.DeletorNoteImages = append(user0.R.DeletorNoteImages, noteImages1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.DeletorUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func insertUserUserNotifications0(ctx context.Context, exec bob.Executor, notifications1 []*NotificationSetter, user0 *User) (NotificationSlice, error) {
|
|
for i := range notifications1 {
|
|
notifications1[i].UserID = omit.From(user0.ID)
|
|
}
|
|
|
|
ret, err := Notifications.Insert(bob.ToMods(notifications1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserUserNotifications0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserUserNotifications0(ctx context.Context, exec bob.Executor, count int, notifications1 NotificationSlice, user0 *User) (NotificationSlice, error) {
|
|
setter := &NotificationSetter{
|
|
UserID: omit.From(user0.ID),
|
|
}
|
|
|
|
err := notifications1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserUserNotifications0: %w", err)
|
|
}
|
|
|
|
return notifications1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertUserNotifications(ctx context.Context, exec bob.Executor, related ...*NotificationSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
notifications1, err := insertUserUserNotifications0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.UserNotifications = append(user0.R.UserNotifications, notifications1...)
|
|
|
|
for _, rel := range notifications1 {
|
|
rel.R.UserUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachUserNotifications(ctx context.Context, exec bob.Executor, related ...*Notification) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
notifications1 := NotificationSlice(related)
|
|
|
|
_, err = attachUserUserNotifications0(ctx, exec, len(related), notifications1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.UserNotifications = append(user0.R.UserNotifications, notifications1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.UserUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func insertUserUserOauthTokens0(ctx context.Context, exec bob.Executor, oauthTokens1 []*OauthTokenSetter, user0 *User) (OauthTokenSlice, error) {
|
|
for i := range oauthTokens1 {
|
|
oauthTokens1[i].UserID = omit.From(user0.ID)
|
|
}
|
|
|
|
ret, err := OauthTokens.Insert(bob.ToMods(oauthTokens1...)).All(ctx, exec)
|
|
if err != nil {
|
|
return ret, fmt.Errorf("insertUserUserOauthTokens0: %w", err)
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func attachUserUserOauthTokens0(ctx context.Context, exec bob.Executor, count int, oauthTokens1 OauthTokenSlice, user0 *User) (OauthTokenSlice, error) {
|
|
setter := &OauthTokenSetter{
|
|
UserID: omit.From(user0.ID),
|
|
}
|
|
|
|
err := oauthTokens1.UpdateAll(ctx, exec, *setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserUserOauthTokens0: %w", err)
|
|
}
|
|
|
|
return oauthTokens1, nil
|
|
}
|
|
|
|
func (user0 *User) InsertUserOauthTokens(ctx context.Context, exec bob.Executor, related ...*OauthTokenSetter) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
|
|
oauthTokens1, err := insertUserUserOauthTokens0(ctx, exec, related, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.UserOauthTokens = append(user0.R.UserOauthTokens, oauthTokens1...)
|
|
|
|
for _, rel := range oauthTokens1 {
|
|
rel.R.UserUser = user0
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachUserOauthTokens(ctx context.Context, exec bob.Executor, related ...*OauthToken) error {
|
|
if len(related) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var err error
|
|
oauthTokens1 := OauthTokenSlice(related)
|
|
|
|
_, err = attachUserUserOauthTokens0(ctx, exec, len(related), oauthTokens1, user0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.UserOauthTokens = append(user0.R.UserOauthTokens, oauthTokens1...)
|
|
|
|
for _, rel := range related {
|
|
rel.R.UserUser = user0
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func attachUserOrganization0(ctx context.Context, exec bob.Executor, count int, user0 *User, organization1 *Organization) (*User, error) {
|
|
setter := &UserSetter{
|
|
OrganizationID: omit.From(organization1.ID),
|
|
}
|
|
|
|
err := user0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachUserOrganization0: %w", err)
|
|
}
|
|
|
|
return user0, nil
|
|
}
|
|
|
|
func (user0 *User) 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 = attachUserOrganization0(ctx, exec, 1, user0, organization1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.Organization = organization1
|
|
|
|
organization1.R.User = append(organization1.R.User, user0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (user0 *User) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error {
|
|
var err error
|
|
|
|
_, err = attachUserOrganization0(ctx, exec, 1, user0, organization1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user0.R.Organization = organization1
|
|
|
|
organization1.R.User = append(organization1.R.User, user0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type userWhere[Q psql.Filterable] struct {
|
|
ID psql.WhereMod[Q, int32]
|
|
ArcgisAccessToken psql.WhereNullMod[Q, string]
|
|
ArcgisLicense psql.WhereNullMod[Q, enums.Arcgislicensetype]
|
|
ArcgisRefreshToken psql.WhereNullMod[Q, string]
|
|
ArcgisRefreshTokenExpires psql.WhereNullMod[Q, time.Time]
|
|
ArcgisRole psql.WhereNullMod[Q, string]
|
|
DisplayName psql.WhereMod[Q, string]
|
|
Email psql.WhereNullMod[Q, string]
|
|
OrganizationID psql.WhereMod[Q, int32]
|
|
Username psql.WhereMod[Q, string]
|
|
PasswordHashType psql.WhereMod[Q, enums.Hashtype]
|
|
PasswordHash psql.WhereMod[Q, string]
|
|
}
|
|
|
|
func (userWhere[Q]) AliasedAs(alias string) userWhere[Q] {
|
|
return buildUserWhere[Q](buildUserColumns(alias))
|
|
}
|
|
|
|
func buildUserWhere[Q psql.Filterable](cols userColumns) userWhere[Q] {
|
|
return userWhere[Q]{
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
ArcgisAccessToken: psql.WhereNull[Q, string](cols.ArcgisAccessToken),
|
|
ArcgisLicense: psql.WhereNull[Q, enums.Arcgislicensetype](cols.ArcgisLicense),
|
|
ArcgisRefreshToken: psql.WhereNull[Q, string](cols.ArcgisRefreshToken),
|
|
ArcgisRefreshTokenExpires: psql.WhereNull[Q, time.Time](cols.ArcgisRefreshTokenExpires),
|
|
ArcgisRole: psql.WhereNull[Q, string](cols.ArcgisRole),
|
|
DisplayName: psql.Where[Q, string](cols.DisplayName),
|
|
Email: psql.WhereNull[Q, string](cols.Email),
|
|
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
|
Username: psql.Where[Q, string](cols.Username),
|
|
PasswordHashType: psql.Where[Q, enums.Hashtype](cols.PasswordHashType),
|
|
PasswordHash: psql.Where[Q, string](cols.PasswordHash),
|
|
}
|
|
}
|
|
|
|
func (o *User) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "PublicUserUser":
|
|
rels, ok := retrieved.(ArcgisUserSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.PublicUserUser = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.PublicUserUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "CreatorFiles":
|
|
rels, ok := retrieved.(FileuploadFileSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.CreatorFiles = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.CreatorUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "CreatorNoteAudios":
|
|
rels, ok := retrieved.(NoteAudioSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.CreatorNoteAudios = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.CreatorUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "DeletorNoteAudios":
|
|
rels, ok := retrieved.(NoteAudioSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.DeletorNoteAudios = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.DeletorUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "CreatorNoteImages":
|
|
rels, ok := retrieved.(NoteImageSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.CreatorNoteImages = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.CreatorUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "DeletorNoteImages":
|
|
rels, ok := retrieved.(NoteImageSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.DeletorNoteImages = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.DeletorUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "UserNotifications":
|
|
rels, ok := retrieved.(NotificationSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.UserNotifications = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.UserUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "UserOauthTokens":
|
|
rels, ok := retrieved.(OauthTokenSlice)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.UserOauthTokens = rels
|
|
|
|
for _, rel := range rels {
|
|
if rel != nil {
|
|
rel.R.UserUser = o
|
|
}
|
|
}
|
|
return nil
|
|
case "Organization":
|
|
rel, ok := retrieved.(*Organization)
|
|
if !ok {
|
|
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.Organization = rel
|
|
|
|
if rel != nil {
|
|
rel.R.User = UserSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("user has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type userPreloader struct {
|
|
Organization func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildUserPreloader() userPreloader {
|
|
return userPreloader{
|
|
Organization: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{
|
|
Name: "Organization",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: Users,
|
|
To: Organizations,
|
|
FromColumns: []string{"organization_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, Organizations.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type userThenLoader[Q orm.Loadable] struct {
|
|
PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
CreatorFiles 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]
|
|
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|
type PublicUserUserLoadInterface interface {
|
|
LoadPublicUserUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorFilesLoadInterface interface {
|
|
LoadCreatorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorNoteAudiosLoadInterface interface {
|
|
LoadCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type DeletorNoteAudiosLoadInterface interface {
|
|
LoadDeletorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorNoteImagesLoadInterface interface {
|
|
LoadCreatorNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type DeletorNoteImagesLoadInterface interface {
|
|
LoadDeletorNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type UserNotificationsLoadInterface interface {
|
|
LoadUserNotifications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type UserOauthTokensLoadInterface interface {
|
|
LoadUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type OrganizationLoadInterface interface {
|
|
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return userThenLoader[Q]{
|
|
PublicUserUser: thenLoadBuilder[Q](
|
|
"PublicUserUser",
|
|
func(ctx context.Context, exec bob.Executor, retrieved PublicUserUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadPublicUserUser(ctx, exec, mods...)
|
|
},
|
|
),
|
|
CreatorFiles: thenLoadBuilder[Q](
|
|
"CreatorFiles",
|
|
func(ctx context.Context, exec bob.Executor, retrieved CreatorFilesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCreatorFiles(ctx, exec, mods...)
|
|
},
|
|
),
|
|
CreatorNoteAudios: thenLoadBuilder[Q](
|
|
"CreatorNoteAudios",
|
|
func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteAudiosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCreatorNoteAudios(ctx, exec, mods...)
|
|
},
|
|
),
|
|
DeletorNoteAudios: thenLoadBuilder[Q](
|
|
"DeletorNoteAudios",
|
|
func(ctx context.Context, exec bob.Executor, retrieved DeletorNoteAudiosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadDeletorNoteAudios(ctx, exec, mods...)
|
|
},
|
|
),
|
|
CreatorNoteImages: thenLoadBuilder[Q](
|
|
"CreatorNoteImages",
|
|
func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCreatorNoteImages(ctx, exec, mods...)
|
|
},
|
|
),
|
|
DeletorNoteImages: thenLoadBuilder[Q](
|
|
"DeletorNoteImages",
|
|
func(ctx context.Context, exec bob.Executor, retrieved DeletorNoteImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadDeletorNoteImages(ctx, exec, mods...)
|
|
},
|
|
),
|
|
UserNotifications: thenLoadBuilder[Q](
|
|
"UserNotifications",
|
|
func(ctx context.Context, exec bob.Executor, retrieved UserNotificationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadUserNotifications(ctx, exec, mods...)
|
|
},
|
|
),
|
|
UserOauthTokens: thenLoadBuilder[Q](
|
|
"UserOauthTokens",
|
|
func(ctx context.Context, exec bob.Executor, retrieved UserOauthTokensLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadUserOauthTokens(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...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadPublicUserUser loads the user's PublicUserUser into the .R struct
|
|
func (o *User) LoadPublicUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.PublicUserUser = nil
|
|
|
|
related, err := o.PublicUserUser(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.PublicUserUser = o
|
|
}
|
|
|
|
o.R.PublicUserUser = related
|
|
return nil
|
|
}
|
|
|
|
// LoadPublicUserUser loads the user's PublicUserUser into the .R struct
|
|
func (os UserSlice) LoadPublicUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
arcgisusers, err := os.PublicUserUser(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.PublicUserUser = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range arcgisusers {
|
|
|
|
if !(o.ID == rel.PublicUserID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.PublicUserUser = o
|
|
|
|
o.R.PublicUserUser = append(o.R.PublicUserUser, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorFiles loads the user's CreatorFiles into the .R struct
|
|
func (o *User) LoadCreatorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.CreatorFiles = nil
|
|
|
|
related, err := o.CreatorFiles(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.CreatorUser = o
|
|
}
|
|
|
|
o.R.CreatorFiles = related
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorFiles loads the user's CreatorFiles into the .R struct
|
|
func (os UserSlice) LoadCreatorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
fileuploadFiles, err := os.CreatorFiles(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.CreatorFiles = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range fileuploadFiles {
|
|
|
|
if !(o.ID == rel.CreatorID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.CreatorUser = o
|
|
|
|
o.R.CreatorFiles = append(o.R.CreatorFiles, 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 {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.CreatorNoteAudios = nil
|
|
|
|
related, err := o.CreatorNoteAudios(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.CreatorUser = o
|
|
}
|
|
|
|
o.R.CreatorNoteAudios = related
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorNoteAudios loads the user's CreatorNoteAudios into the .R struct
|
|
func (os UserSlice) LoadCreatorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
noteAudios, err := os.CreatorNoteAudios(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.CreatorNoteAudios = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range noteAudios {
|
|
|
|
if !(o.ID == rel.CreatorID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.CreatorUser = o
|
|
|
|
o.R.CreatorNoteAudios = append(o.R.CreatorNoteAudios, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadDeletorNoteAudios loads the user's DeletorNoteAudios into the .R struct
|
|
func (o *User) LoadDeletorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.DeletorNoteAudios = nil
|
|
|
|
related, err := o.DeletorNoteAudios(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.DeletorUser = o
|
|
}
|
|
|
|
o.R.DeletorNoteAudios = related
|
|
return nil
|
|
}
|
|
|
|
// LoadDeletorNoteAudios loads the user's DeletorNoteAudios into the .R struct
|
|
func (os UserSlice) LoadDeletorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
noteAudios, err := os.DeletorNoteAudios(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.DeletorNoteAudios = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range noteAudios {
|
|
|
|
if !rel.DeletorID.IsValue() {
|
|
continue
|
|
}
|
|
if !(rel.DeletorID.IsValue() && o.ID == rel.DeletorID.MustGet()) {
|
|
continue
|
|
}
|
|
|
|
rel.R.DeletorUser = o
|
|
|
|
o.R.DeletorNoteAudios = append(o.R.DeletorNoteAudios, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorNoteImages loads the user's CreatorNoteImages into the .R struct
|
|
func (o *User) LoadCreatorNoteImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.CreatorNoteImages = nil
|
|
|
|
related, err := o.CreatorNoteImages(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.CreatorUser = o
|
|
}
|
|
|
|
o.R.CreatorNoteImages = related
|
|
return nil
|
|
}
|
|
|
|
// LoadCreatorNoteImages loads the user's CreatorNoteImages into the .R struct
|
|
func (os UserSlice) LoadCreatorNoteImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
noteImages, err := os.CreatorNoteImages(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.CreatorNoteImages = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range noteImages {
|
|
|
|
if !(o.ID == rel.CreatorID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.CreatorUser = o
|
|
|
|
o.R.CreatorNoteImages = append(o.R.CreatorNoteImages, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadDeletorNoteImages loads the user's DeletorNoteImages into the .R struct
|
|
func (o *User) LoadDeletorNoteImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.DeletorNoteImages = nil
|
|
|
|
related, err := o.DeletorNoteImages(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.DeletorUser = o
|
|
}
|
|
|
|
o.R.DeletorNoteImages = related
|
|
return nil
|
|
}
|
|
|
|
// LoadDeletorNoteImages loads the user's DeletorNoteImages into the .R struct
|
|
func (os UserSlice) LoadDeletorNoteImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
noteImages, err := os.DeletorNoteImages(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.DeletorNoteImages = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range noteImages {
|
|
|
|
if !rel.DeletorID.IsValue() {
|
|
continue
|
|
}
|
|
if !(rel.DeletorID.IsValue() && o.ID == rel.DeletorID.MustGet()) {
|
|
continue
|
|
}
|
|
|
|
rel.R.DeletorUser = o
|
|
|
|
o.R.DeletorNoteImages = append(o.R.DeletorNoteImages, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadUserNotifications loads the user's UserNotifications into the .R struct
|
|
func (o *User) LoadUserNotifications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.UserNotifications = nil
|
|
|
|
related, err := o.UserNotifications(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.UserUser = o
|
|
}
|
|
|
|
o.R.UserNotifications = related
|
|
return nil
|
|
}
|
|
|
|
// LoadUserNotifications loads the user's UserNotifications into the .R struct
|
|
func (os UserSlice) LoadUserNotifications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
notifications, err := os.UserNotifications(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.UserNotifications = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range notifications {
|
|
|
|
if !(o.ID == rel.UserID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.UserUser = o
|
|
|
|
o.R.UserNotifications = append(o.R.UserNotifications, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadUserOauthTokens loads the user's UserOauthTokens into the .R struct
|
|
func (o *User) LoadUserOauthTokens(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.UserOauthTokens = nil
|
|
|
|
related, err := o.UserOauthTokens(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, rel := range related {
|
|
rel.R.UserUser = o
|
|
}
|
|
|
|
o.R.UserOauthTokens = related
|
|
return nil
|
|
}
|
|
|
|
// LoadUserOauthTokens loads the user's UserOauthTokens into the .R struct
|
|
func (os UserSlice) LoadUserOauthTokens(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
oauthTokens, err := os.UserOauthTokens(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
o.R.UserOauthTokens = nil
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range oauthTokens {
|
|
|
|
if !(o.ID == rel.UserID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.UserUser = o
|
|
|
|
o.R.UserOauthTokens = append(o.R.UserOauthTokens, rel)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadOrganization loads the user's Organization into the .R struct
|
|
func (o *User) 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.User = UserSlice{o}
|
|
|
|
o.R.Organization = related
|
|
return nil
|
|
}
|
|
|
|
// LoadOrganization loads the user's Organization into the .R struct
|
|
func (os UserSlice) 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.User = append(rel.R.User, o)
|
|
|
|
o.R.Organization = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// userC is where relationship counts are stored.
|
|
type userC struct {
|
|
PublicUserUser *int64
|
|
CreatorFiles *int64
|
|
CreatorNoteAudios *int64
|
|
DeletorNoteAudios *int64
|
|
CreatorNoteImages *int64
|
|
DeletorNoteImages *int64
|
|
UserNotifications *int64
|
|
UserOauthTokens *int64
|
|
}
|
|
|
|
// PreloadCount sets a count in the C struct by name
|
|
func (o *User) PreloadCount(name string, count int64) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "PublicUserUser":
|
|
o.C.PublicUserUser = &count
|
|
case "CreatorFiles":
|
|
o.C.CreatorFiles = &count
|
|
case "CreatorNoteAudios":
|
|
o.C.CreatorNoteAudios = &count
|
|
case "DeletorNoteAudios":
|
|
o.C.DeletorNoteAudios = &count
|
|
case "CreatorNoteImages":
|
|
o.C.CreatorNoteImages = &count
|
|
case "DeletorNoteImages":
|
|
o.C.DeletorNoteImages = &count
|
|
case "UserNotifications":
|
|
o.C.UserNotifications = &count
|
|
case "UserOauthTokens":
|
|
o.C.UserOauthTokens = &count
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type userCountPreloader struct {
|
|
PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader
|
|
}
|
|
|
|
func buildUserCountPreloader() userCountPreloader {
|
|
return userCountPreloader{
|
|
PublicUserUser: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("PublicUserUser", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(ArcgisUsers.Name()),
|
|
sm.Where(psql.Quote(ArcgisUsers.Alias(), "public_user_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
CreatorFiles: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("CreatorFiles", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(FileuploadFiles.Name()),
|
|
sm.Where(psql.Quote(FileuploadFiles.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
CreatorNoteAudios: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("CreatorNoteAudios", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(NoteAudios.Name()),
|
|
sm.Where(psql.Quote(NoteAudios.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
DeletorNoteAudios: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("DeletorNoteAudios", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(NoteAudios.Name()),
|
|
sm.Where(psql.Quote(NoteAudios.Alias(), "deletor_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
CreatorNoteImages: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("CreatorNoteImages", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(NoteImages.Name()),
|
|
sm.Where(psql.Quote(NoteImages.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
DeletorNoteImages: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("DeletorNoteImages", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(NoteImages.Name()),
|
|
sm.Where(psql.Quote(NoteImages.Alias(), "deletor_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
UserNotifications: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("UserNotifications", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(Notifications.Name()),
|
|
sm.Where(psql.Quote(Notifications.Alias(), "user_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
UserOauthTokens: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader {
|
|
return countPreloader[*User]("UserOauthTokens", func(parent string) bob.Expression {
|
|
// Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk)
|
|
if parent == "" {
|
|
parent = Users.Alias()
|
|
}
|
|
|
|
subqueryMods := []bob.Mod[*dialect.SelectQuery]{
|
|
sm.Columns(psql.Raw("count(*)")),
|
|
|
|
sm.From(OauthTokens.Name()),
|
|
sm.Where(psql.Quote(OauthTokens.Alias(), "user_id").EQ(psql.Quote(parent, "id"))),
|
|
}
|
|
subqueryMods = append(subqueryMods, mods...)
|
|
return psql.Group(psql.Select(subqueryMods...).Expression)
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
type userCountThenLoader[Q orm.Loadable] struct {
|
|
PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
CreatorFiles 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]
|
|
DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] {
|
|
type PublicUserUserCountInterface interface {
|
|
LoadCountPublicUserUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorFilesCountInterface interface {
|
|
LoadCountCreatorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorNoteAudiosCountInterface interface {
|
|
LoadCountCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type DeletorNoteAudiosCountInterface interface {
|
|
LoadCountDeletorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type CreatorNoteImagesCountInterface interface {
|
|
LoadCountCreatorNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type DeletorNoteImagesCountInterface interface {
|
|
LoadCountDeletorNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type UserNotificationsCountInterface interface {
|
|
LoadCountUserNotifications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
type UserOauthTokensCountInterface interface {
|
|
LoadCountUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return userCountThenLoader[Q]{
|
|
PublicUserUser: countThenLoadBuilder[Q](
|
|
"PublicUserUser",
|
|
func(ctx context.Context, exec bob.Executor, retrieved PublicUserUserCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountPublicUserUser(ctx, exec, mods...)
|
|
},
|
|
),
|
|
CreatorFiles: countThenLoadBuilder[Q](
|
|
"CreatorFiles",
|
|
func(ctx context.Context, exec bob.Executor, retrieved CreatorFilesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountCreatorFiles(ctx, exec, mods...)
|
|
},
|
|
),
|
|
CreatorNoteAudios: countThenLoadBuilder[Q](
|
|
"CreatorNoteAudios",
|
|
func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteAudiosCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountCreatorNoteAudios(ctx, exec, mods...)
|
|
},
|
|
),
|
|
DeletorNoteAudios: countThenLoadBuilder[Q](
|
|
"DeletorNoteAudios",
|
|
func(ctx context.Context, exec bob.Executor, retrieved DeletorNoteAudiosCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountDeletorNoteAudios(ctx, exec, mods...)
|
|
},
|
|
),
|
|
CreatorNoteImages: countThenLoadBuilder[Q](
|
|
"CreatorNoteImages",
|
|
func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteImagesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountCreatorNoteImages(ctx, exec, mods...)
|
|
},
|
|
),
|
|
DeletorNoteImages: countThenLoadBuilder[Q](
|
|
"DeletorNoteImages",
|
|
func(ctx context.Context, exec bob.Executor, retrieved DeletorNoteImagesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountDeletorNoteImages(ctx, exec, mods...)
|
|
},
|
|
),
|
|
UserNotifications: countThenLoadBuilder[Q](
|
|
"UserNotifications",
|
|
func(ctx context.Context, exec bob.Executor, retrieved UserNotificationsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountUserNotifications(ctx, exec, mods...)
|
|
},
|
|
),
|
|
UserOauthTokens: countThenLoadBuilder[Q](
|
|
"UserOauthTokens",
|
|
func(ctx context.Context, exec bob.Executor, retrieved UserOauthTokensCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadCountUserOauthTokens(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadCountPublicUserUser loads the count of PublicUserUser into the C struct
|
|
func (o *User) LoadCountPublicUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.PublicUserUser(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.PublicUserUser = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountPublicUserUser loads the count of PublicUserUser for a slice
|
|
func (os UserSlice) LoadCountPublicUserUser(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.LoadCountPublicUserUser(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountCreatorFiles loads the count of CreatorFiles into the C struct
|
|
func (o *User) LoadCountCreatorFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.CreatorFiles(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.CreatorFiles = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountCreatorFiles loads the count of CreatorFiles for a slice
|
|
func (os UserSlice) LoadCountCreatorFiles(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.LoadCountCreatorFiles(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountCreatorNoteAudios loads the count of CreatorNoteAudios into the C struct
|
|
func (o *User) LoadCountCreatorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.CreatorNoteAudios(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.CreatorNoteAudios = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountCreatorNoteAudios loads the count of CreatorNoteAudios for a slice
|
|
func (os UserSlice) LoadCountCreatorNoteAudios(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.LoadCountCreatorNoteAudios(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountDeletorNoteAudios loads the count of DeletorNoteAudios into the C struct
|
|
func (o *User) LoadCountDeletorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.DeletorNoteAudios(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.DeletorNoteAudios = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountDeletorNoteAudios loads the count of DeletorNoteAudios for a slice
|
|
func (os UserSlice) LoadCountDeletorNoteAudios(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.LoadCountDeletorNoteAudios(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountCreatorNoteImages loads the count of CreatorNoteImages into the C struct
|
|
func (o *User) LoadCountCreatorNoteImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.CreatorNoteImages(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.CreatorNoteImages = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountCreatorNoteImages loads the count of CreatorNoteImages for a slice
|
|
func (os UserSlice) LoadCountCreatorNoteImages(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.LoadCountCreatorNoteImages(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountDeletorNoteImages loads the count of DeletorNoteImages into the C struct
|
|
func (o *User) LoadCountDeletorNoteImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.DeletorNoteImages(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.DeletorNoteImages = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountDeletorNoteImages loads the count of DeletorNoteImages for a slice
|
|
func (os UserSlice) LoadCountDeletorNoteImages(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.LoadCountDeletorNoteImages(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountUserNotifications loads the count of UserNotifications into the C struct
|
|
func (o *User) LoadCountUserNotifications(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.UserNotifications(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.UserNotifications = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountUserNotifications loads the count of UserNotifications for a slice
|
|
func (os UserSlice) LoadCountUserNotifications(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.LoadCountUserNotifications(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// LoadCountUserOauthTokens loads the count of UserOauthTokens into the C struct
|
|
func (o *User) LoadCountUserOauthTokens(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
count, err := o.UserOauthTokens(mods...).Count(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.C.UserOauthTokens = &count
|
|
return nil
|
|
}
|
|
|
|
// LoadCountUserOauthTokens loads the count of UserOauthTokens for a slice
|
|
func (os UserSlice) LoadCountUserOauthTokens(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.LoadCountUserOauthTokens(ctx, exec, mods...); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type userJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
PublicUserUser modAs[Q, arcgisuserColumns]
|
|
CreatorFiles modAs[Q, fileuploadFileColumns]
|
|
CreatorNoteAudios modAs[Q, noteAudioColumns]
|
|
DeletorNoteAudios modAs[Q, noteAudioColumns]
|
|
CreatorNoteImages modAs[Q, noteImageColumns]
|
|
DeletorNoteImages modAs[Q, noteImageColumns]
|
|
UserNotifications modAs[Q, notificationColumns]
|
|
UserOauthTokens modAs[Q, oauthTokenColumns]
|
|
Organization modAs[Q, organizationColumns]
|
|
}
|
|
|
|
func (j userJoins[Q]) aliasedAs(alias string) userJoins[Q] {
|
|
return buildUserJoins[Q](buildUserColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[Q] {
|
|
return userJoins[Q]{
|
|
typ: typ,
|
|
PublicUserUser: modAs[Q, arcgisuserColumns]{
|
|
c: ArcgisUsers.Columns,
|
|
f: func(to arcgisuserColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, ArcgisUsers.Name().As(to.Alias())).On(
|
|
to.PublicUserID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
CreatorFiles: modAs[Q, fileuploadFileColumns]{
|
|
c: FileuploadFiles.Columns,
|
|
f: func(to fileuploadFileColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, FileuploadFiles.Name().As(to.Alias())).On(
|
|
to.CreatorID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
CreatorNoteAudios: modAs[Q, noteAudioColumns]{
|
|
c: NoteAudios.Columns,
|
|
f: func(to noteAudioColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, NoteAudios.Name().As(to.Alias())).On(
|
|
to.CreatorID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
DeletorNoteAudios: modAs[Q, noteAudioColumns]{
|
|
c: NoteAudios.Columns,
|
|
f: func(to noteAudioColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, NoteAudios.Name().As(to.Alias())).On(
|
|
to.DeletorID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
CreatorNoteImages: modAs[Q, noteImageColumns]{
|
|
c: NoteImages.Columns,
|
|
f: func(to noteImageColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, NoteImages.Name().As(to.Alias())).On(
|
|
to.CreatorID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
DeletorNoteImages: modAs[Q, noteImageColumns]{
|
|
c: NoteImages.Columns,
|
|
f: func(to noteImageColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, NoteImages.Name().As(to.Alias())).On(
|
|
to.DeletorID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
UserNotifications: modAs[Q, notificationColumns]{
|
|
c: Notifications.Columns,
|
|
f: func(to notificationColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, Notifications.Name().As(to.Alias())).On(
|
|
to.UserID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
UserOauthTokens: modAs[Q, oauthTokenColumns]{
|
|
c: OauthTokens.Columns,
|
|
f: func(to oauthTokenColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, OauthTokens.Name().As(to.Alias())).On(
|
|
to.UserID.EQ(cols.ID),
|
|
))
|
|
}
|
|
|
|
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
|
|
},
|
|
},
|
|
}
|
|
}
|