This is an intermediate step between shifting from the old fs_* prefixed table names to an entire fieldseeker schema. At this point we have both, and we aren't doing much with the new schema but compiling.
805 lines
23 KiB
Go
805 lines
23 KiB
Go
// Code generated by BobGen psql v0.42.0. DO NOT EDIT.
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
|
|
|
package models
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/aarondl/opt/null"
|
|
"github.com/aarondl/opt/omit"
|
|
"github.com/aarondl/opt/omitnull"
|
|
"github.com/stephenafamo/bob"
|
|
"github.com/stephenafamo/bob/dialect/psql"
|
|
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
|
"github.com/stephenafamo/bob/dialect/psql/dm"
|
|
"github.com/stephenafamo/bob/dialect/psql/sm"
|
|
"github.com/stephenafamo/bob/dialect/psql/um"
|
|
"github.com/stephenafamo/bob/expr"
|
|
"github.com/stephenafamo/bob/mods"
|
|
"github.com/stephenafamo/bob/orm"
|
|
"github.com/stephenafamo/bob/types/pgtypes"
|
|
)
|
|
|
|
// OauthToken is an object representing the database table.
|
|
type OauthToken struct {
|
|
ID int32 `db:"id,pk" `
|
|
AccessToken string `db:"access_token" `
|
|
AccessTokenExpires time.Time `db:"access_token_expires" `
|
|
RefreshToken string `db:"refresh_token" `
|
|
Username string `db:"username" `
|
|
UserID int32 `db:"user_id" `
|
|
ArcgisID null.Val[string] `db:"arcgis_id" `
|
|
ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id" `
|
|
RefreshTokenExpires time.Time `db:"refresh_token_expires" `
|
|
InvalidatedAt null.Val[time.Time] `db:"invalidated_at" `
|
|
|
|
R oauthTokenR `db:"-" `
|
|
}
|
|
|
|
// OauthTokenSlice is an alias for a slice of pointers to OauthToken.
|
|
// This should almost always be used instead of []*OauthToken.
|
|
type OauthTokenSlice []*OauthToken
|
|
|
|
// OauthTokens contains methods to work with the oauth_token table
|
|
var OauthTokens = psql.NewTablex[*OauthToken, OauthTokenSlice, *OauthTokenSetter]("", "oauth_token", buildOauthTokenColumns("oauth_token"))
|
|
|
|
// OauthTokensQuery is a query on the oauth_token table
|
|
type OauthTokensQuery = *psql.ViewQuery[*OauthToken, OauthTokenSlice]
|
|
|
|
// oauthTokenR is where relationships are stored.
|
|
type oauthTokenR struct {
|
|
UserUser *User // oauth_token.oauth_token_user_id_fkey
|
|
}
|
|
|
|
func buildOauthTokenColumns(alias string) oauthTokenColumns {
|
|
return oauthTokenColumns{
|
|
ColumnsExpr: expr.NewColumnsExpr(
|
|
"id", "access_token", "access_token_expires", "refresh_token", "username", "user_id", "arcgis_id", "arcgis_license_type_id", "refresh_token_expires", "invalidated_at",
|
|
).WithParent("oauth_token"),
|
|
tableAlias: alias,
|
|
ID: psql.Quote(alias, "id"),
|
|
AccessToken: psql.Quote(alias, "access_token"),
|
|
AccessTokenExpires: psql.Quote(alias, "access_token_expires"),
|
|
RefreshToken: psql.Quote(alias, "refresh_token"),
|
|
Username: psql.Quote(alias, "username"),
|
|
UserID: psql.Quote(alias, "user_id"),
|
|
ArcgisID: psql.Quote(alias, "arcgis_id"),
|
|
ArcgisLicenseTypeID: psql.Quote(alias, "arcgis_license_type_id"),
|
|
RefreshTokenExpires: psql.Quote(alias, "refresh_token_expires"),
|
|
InvalidatedAt: psql.Quote(alias, "invalidated_at"),
|
|
}
|
|
}
|
|
|
|
type oauthTokenColumns struct {
|
|
expr.ColumnsExpr
|
|
tableAlias string
|
|
ID psql.Expression
|
|
AccessToken psql.Expression
|
|
AccessTokenExpires psql.Expression
|
|
RefreshToken psql.Expression
|
|
Username psql.Expression
|
|
UserID psql.Expression
|
|
ArcgisID psql.Expression
|
|
ArcgisLicenseTypeID psql.Expression
|
|
RefreshTokenExpires psql.Expression
|
|
InvalidatedAt psql.Expression
|
|
}
|
|
|
|
func (c oauthTokenColumns) Alias() string {
|
|
return c.tableAlias
|
|
}
|
|
|
|
func (oauthTokenColumns) AliasedAs(alias string) oauthTokenColumns {
|
|
return buildOauthTokenColumns(alias)
|
|
}
|
|
|
|
// OauthTokenSetter is used for insert/upsert/update operations
|
|
// All values are optional, and do not have to be set
|
|
// Generated columns are not included
|
|
type OauthTokenSetter struct {
|
|
ID omit.Val[int32] `db:"id,pk" `
|
|
AccessToken omit.Val[string] `db:"access_token" `
|
|
AccessTokenExpires omit.Val[time.Time] `db:"access_token_expires" `
|
|
RefreshToken omit.Val[string] `db:"refresh_token" `
|
|
Username omit.Val[string] `db:"username" `
|
|
UserID omit.Val[int32] `db:"user_id" `
|
|
ArcgisID omitnull.Val[string] `db:"arcgis_id" `
|
|
ArcgisLicenseTypeID omitnull.Val[string] `db:"arcgis_license_type_id" `
|
|
RefreshTokenExpires omit.Val[time.Time] `db:"refresh_token_expires" `
|
|
InvalidatedAt omitnull.Val[time.Time] `db:"invalidated_at" `
|
|
}
|
|
|
|
func (s OauthTokenSetter) SetColumns() []string {
|
|
vals := make([]string, 0, 10)
|
|
if s.ID.IsValue() {
|
|
vals = append(vals, "id")
|
|
}
|
|
if s.AccessToken.IsValue() {
|
|
vals = append(vals, "access_token")
|
|
}
|
|
if s.AccessTokenExpires.IsValue() {
|
|
vals = append(vals, "access_token_expires")
|
|
}
|
|
if s.RefreshToken.IsValue() {
|
|
vals = append(vals, "refresh_token")
|
|
}
|
|
if s.Username.IsValue() {
|
|
vals = append(vals, "username")
|
|
}
|
|
if s.UserID.IsValue() {
|
|
vals = append(vals, "user_id")
|
|
}
|
|
if !s.ArcgisID.IsUnset() {
|
|
vals = append(vals, "arcgis_id")
|
|
}
|
|
if !s.ArcgisLicenseTypeID.IsUnset() {
|
|
vals = append(vals, "arcgis_license_type_id")
|
|
}
|
|
if s.RefreshTokenExpires.IsValue() {
|
|
vals = append(vals, "refresh_token_expires")
|
|
}
|
|
if !s.InvalidatedAt.IsUnset() {
|
|
vals = append(vals, "invalidated_at")
|
|
}
|
|
return vals
|
|
}
|
|
|
|
func (s OauthTokenSetter) Overwrite(t *OauthToken) {
|
|
if s.ID.IsValue() {
|
|
t.ID = s.ID.MustGet()
|
|
}
|
|
if s.AccessToken.IsValue() {
|
|
t.AccessToken = s.AccessToken.MustGet()
|
|
}
|
|
if s.AccessTokenExpires.IsValue() {
|
|
t.AccessTokenExpires = s.AccessTokenExpires.MustGet()
|
|
}
|
|
if s.RefreshToken.IsValue() {
|
|
t.RefreshToken = s.RefreshToken.MustGet()
|
|
}
|
|
if s.Username.IsValue() {
|
|
t.Username = s.Username.MustGet()
|
|
}
|
|
if s.UserID.IsValue() {
|
|
t.UserID = s.UserID.MustGet()
|
|
}
|
|
if !s.ArcgisID.IsUnset() {
|
|
t.ArcgisID = s.ArcgisID.MustGetNull()
|
|
}
|
|
if !s.ArcgisLicenseTypeID.IsUnset() {
|
|
t.ArcgisLicenseTypeID = s.ArcgisLicenseTypeID.MustGetNull()
|
|
}
|
|
if s.RefreshTokenExpires.IsValue() {
|
|
t.RefreshTokenExpires = s.RefreshTokenExpires.MustGet()
|
|
}
|
|
if !s.InvalidatedAt.IsUnset() {
|
|
t.InvalidatedAt = s.InvalidatedAt.MustGetNull()
|
|
}
|
|
}
|
|
|
|
func (s *OauthTokenSetter) Apply(q *dialect.InsertQuery) {
|
|
q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
|
|
return OauthTokens.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, 10)
|
|
if s.ID.IsValue() {
|
|
vals[0] = psql.Arg(s.ID.MustGet())
|
|
} else {
|
|
vals[0] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.AccessToken.IsValue() {
|
|
vals[1] = psql.Arg(s.AccessToken.MustGet())
|
|
} else {
|
|
vals[1] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.AccessTokenExpires.IsValue() {
|
|
vals[2] = psql.Arg(s.AccessTokenExpires.MustGet())
|
|
} else {
|
|
vals[2] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.RefreshToken.IsValue() {
|
|
vals[3] = psql.Arg(s.RefreshToken.MustGet())
|
|
} else {
|
|
vals[3] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.Username.IsValue() {
|
|
vals[4] = psql.Arg(s.Username.MustGet())
|
|
} else {
|
|
vals[4] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.UserID.IsValue() {
|
|
vals[5] = psql.Arg(s.UserID.MustGet())
|
|
} else {
|
|
vals[5] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisID.IsUnset() {
|
|
vals[6] = psql.Arg(s.ArcgisID.MustGetNull())
|
|
} else {
|
|
vals[6] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.ArcgisLicenseTypeID.IsUnset() {
|
|
vals[7] = psql.Arg(s.ArcgisLicenseTypeID.MustGetNull())
|
|
} else {
|
|
vals[7] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if s.RefreshTokenExpires.IsValue() {
|
|
vals[8] = psql.Arg(s.RefreshTokenExpires.MustGet())
|
|
} else {
|
|
vals[8] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
if !s.InvalidatedAt.IsUnset() {
|
|
vals[9] = psql.Arg(s.InvalidatedAt.MustGetNull())
|
|
} else {
|
|
vals[9] = psql.Raw("DEFAULT")
|
|
}
|
|
|
|
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
|
}))
|
|
}
|
|
|
|
func (s OauthTokenSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|
return um.Set(s.Expressions()...)
|
|
}
|
|
|
|
func (s OauthTokenSetter) Expressions(prefix ...string) []bob.Expression {
|
|
exprs := make([]bob.Expression, 0, 10)
|
|
|
|
if s.ID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "id")...),
|
|
psql.Arg(s.ID),
|
|
}})
|
|
}
|
|
|
|
if s.AccessToken.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "access_token")...),
|
|
psql.Arg(s.AccessToken),
|
|
}})
|
|
}
|
|
|
|
if s.AccessTokenExpires.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "access_token_expires")...),
|
|
psql.Arg(s.AccessTokenExpires),
|
|
}})
|
|
}
|
|
|
|
if s.RefreshToken.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "refresh_token")...),
|
|
psql.Arg(s.RefreshToken),
|
|
}})
|
|
}
|
|
|
|
if s.Username.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "username")...),
|
|
psql.Arg(s.Username),
|
|
}})
|
|
}
|
|
|
|
if s.UserID.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "user_id")...),
|
|
psql.Arg(s.UserID),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisID.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_id")...),
|
|
psql.Arg(s.ArcgisID),
|
|
}})
|
|
}
|
|
|
|
if !s.ArcgisLicenseTypeID.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "arcgis_license_type_id")...),
|
|
psql.Arg(s.ArcgisLicenseTypeID),
|
|
}})
|
|
}
|
|
|
|
if s.RefreshTokenExpires.IsValue() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "refresh_token_expires")...),
|
|
psql.Arg(s.RefreshTokenExpires),
|
|
}})
|
|
}
|
|
|
|
if !s.InvalidatedAt.IsUnset() {
|
|
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
|
psql.Quote(append(prefix, "invalidated_at")...),
|
|
psql.Arg(s.InvalidatedAt),
|
|
}})
|
|
}
|
|
|
|
return exprs
|
|
}
|
|
|
|
// FindOauthToken retrieves a single record by primary key
|
|
// If cols is empty Find will return all columns.
|
|
func FindOauthToken(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*OauthToken, error) {
|
|
if len(cols) == 0 {
|
|
return OauthTokens.Query(
|
|
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
return OauthTokens.Query(
|
|
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
sm.Columns(OauthTokens.Columns.Only(cols...)),
|
|
).One(ctx, exec)
|
|
}
|
|
|
|
// OauthTokenExists checks the presence of a single record by primary key
|
|
func OauthTokenExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
|
return OauthTokens.Query(
|
|
sm.Where(OauthTokens.Columns.ID.EQ(psql.Arg(IDPK))),
|
|
).Exists(ctx, exec)
|
|
}
|
|
|
|
// AfterQueryHook is called after OauthToken is retrieved from the database
|
|
func (o *OauthToken) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = OauthTokens.AfterSelectHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = OauthTokens.AfterInsertHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = OauthTokens.AfterUpdateHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = OauthTokens.AfterDeleteHooks.RunHooks(ctx, exec, OauthTokenSlice{o})
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// primaryKeyVals returns the primary key values of the OauthToken
|
|
func (o *OauthToken) primaryKeyVals() bob.Expression {
|
|
return psql.Arg(o.ID)
|
|
}
|
|
|
|
func (o *OauthToken) pkEQ() dialect.Expression {
|
|
return psql.Quote("oauth_token", "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 OauthToken
|
|
func (o *OauthToken) Update(ctx context.Context, exec bob.Executor, s *OauthTokenSetter) error {
|
|
v, err := OauthTokens.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 OauthToken record with an executor
|
|
func (o *OauthToken) Delete(ctx context.Context, exec bob.Executor) error {
|
|
_, err := OauthTokens.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
// Reload refreshes the OauthToken using the executor
|
|
func (o *OauthToken) Reload(ctx context.Context, exec bob.Executor) error {
|
|
o2, err := OauthTokens.Query(
|
|
sm.Where(OauthTokens.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 OauthTokenSlice is retrieved from the database
|
|
func (o OauthTokenSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
|
var err error
|
|
|
|
switch queryType {
|
|
case bob.QueryTypeSelect:
|
|
ctx, err = OauthTokens.AfterSelectHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeInsert:
|
|
ctx, err = OauthTokens.AfterInsertHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeUpdate:
|
|
ctx, err = OauthTokens.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
case bob.QueryTypeDelete:
|
|
ctx, err = OauthTokens.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (o OauthTokenSlice) pkIN() dialect.Expression {
|
|
if len(o) == 0 {
|
|
return psql.Raw("NULL")
|
|
}
|
|
|
|
return psql.Quote("oauth_token", "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 OauthTokenSlice) copyMatchingRows(from ...*OauthToken) {
|
|
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 OauthTokenSlice) 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 OauthTokens.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 *OauthToken:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*OauthToken:
|
|
o.copyMatchingRows(retrieved...)
|
|
case OauthTokenSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a OauthToken or a slice of OauthToken
|
|
// then run the AfterUpdateHooks on the slice
|
|
_, err = OauthTokens.AfterUpdateHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
|
|
func (o OauthTokenSlice) 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 OauthTokens.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 *OauthToken:
|
|
o.copyMatchingRows(retrieved)
|
|
case []*OauthToken:
|
|
o.copyMatchingRows(retrieved...)
|
|
case OauthTokenSlice:
|
|
o.copyMatchingRows(retrieved...)
|
|
default:
|
|
// If the retrieved value is not a OauthToken or a slice of OauthToken
|
|
// then run the AfterDeleteHooks on the slice
|
|
_, err = OauthTokens.AfterDeleteHooks.RunHooks(ctx, exec, o)
|
|
}
|
|
|
|
return err
|
|
}))
|
|
|
|
q.AppendWhere(o.pkIN())
|
|
})
|
|
}
|
|
|
|
func (o OauthTokenSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals OauthTokenSetter) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := OauthTokens.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o OauthTokenSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
_, err := OauthTokens.Delete(o.DeleteMod()).Exec(ctx, exec)
|
|
return err
|
|
}
|
|
|
|
func (o OauthTokenSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
o2, err := OauthTokens.Query(sm.Where(o.pkIN())).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
o.copyMatchingRows(o2...)
|
|
|
|
return nil
|
|
}
|
|
|
|
// UserUser starts a query for related objects on user_
|
|
func (o *OauthToken) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
|
return Users.Query(append(mods,
|
|
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.UserID))),
|
|
)...)
|
|
}
|
|
|
|
func (os OauthTokenSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
|
pkUserID := make(pgtypes.Array[int32], 0, len(os))
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
pkUserID = append(pkUserID, o.UserID)
|
|
}
|
|
PKArgExpr := psql.Select(sm.Columns(
|
|
psql.F("unnest", psql.Cast(psql.Arg(pkUserID), "integer[]")),
|
|
))
|
|
|
|
return Users.Query(append(mods,
|
|
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
|
)...)
|
|
}
|
|
|
|
func attachOauthTokenUserUser0(ctx context.Context, exec bob.Executor, count int, oauthToken0 *OauthToken, user1 *User) (*OauthToken, error) {
|
|
setter := &OauthTokenSetter{
|
|
UserID: omit.From(user1.ID),
|
|
}
|
|
|
|
err := oauthToken0.Update(ctx, exec, setter)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("attachOauthTokenUserUser0: %w", err)
|
|
}
|
|
|
|
return oauthToken0, nil
|
|
}
|
|
|
|
func (oauthToken0 *OauthToken) InsertUserUser(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 = attachOauthTokenUserUser0(ctx, exec, 1, oauthToken0, user1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
oauthToken0.R.UserUser = user1
|
|
|
|
user1.R.UserOauthTokens = append(user1.R.UserOauthTokens, oauthToken0)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (oauthToken0 *OauthToken) AttachUserUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
|
var err error
|
|
|
|
_, err = attachOauthTokenUserUser0(ctx, exec, 1, oauthToken0, user1)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
oauthToken0.R.UserUser = user1
|
|
|
|
user1.R.UserOauthTokens = append(user1.R.UserOauthTokens, oauthToken0)
|
|
|
|
return nil
|
|
}
|
|
|
|
type oauthTokenWhere[Q psql.Filterable] struct {
|
|
ID psql.WhereMod[Q, int32]
|
|
AccessToken psql.WhereMod[Q, string]
|
|
AccessTokenExpires psql.WhereMod[Q, time.Time]
|
|
RefreshToken psql.WhereMod[Q, string]
|
|
Username psql.WhereMod[Q, string]
|
|
UserID psql.WhereMod[Q, int32]
|
|
ArcgisID psql.WhereNullMod[Q, string]
|
|
ArcgisLicenseTypeID psql.WhereNullMod[Q, string]
|
|
RefreshTokenExpires psql.WhereMod[Q, time.Time]
|
|
InvalidatedAt psql.WhereNullMod[Q, time.Time]
|
|
}
|
|
|
|
func (oauthTokenWhere[Q]) AliasedAs(alias string) oauthTokenWhere[Q] {
|
|
return buildOauthTokenWhere[Q](buildOauthTokenColumns(alias))
|
|
}
|
|
|
|
func buildOauthTokenWhere[Q psql.Filterable](cols oauthTokenColumns) oauthTokenWhere[Q] {
|
|
return oauthTokenWhere[Q]{
|
|
ID: psql.Where[Q, int32](cols.ID),
|
|
AccessToken: psql.Where[Q, string](cols.AccessToken),
|
|
AccessTokenExpires: psql.Where[Q, time.Time](cols.AccessTokenExpires),
|
|
RefreshToken: psql.Where[Q, string](cols.RefreshToken),
|
|
Username: psql.Where[Q, string](cols.Username),
|
|
UserID: psql.Where[Q, int32](cols.UserID),
|
|
ArcgisID: psql.WhereNull[Q, string](cols.ArcgisID),
|
|
ArcgisLicenseTypeID: psql.WhereNull[Q, string](cols.ArcgisLicenseTypeID),
|
|
RefreshTokenExpires: psql.Where[Q, time.Time](cols.RefreshTokenExpires),
|
|
InvalidatedAt: psql.WhereNull[Q, time.Time](cols.InvalidatedAt),
|
|
}
|
|
}
|
|
|
|
func (o *OauthToken) Preload(name string, retrieved any) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
switch name {
|
|
case "UserUser":
|
|
rel, ok := retrieved.(*User)
|
|
if !ok {
|
|
return fmt.Errorf("oauthToken cannot load %T as %q", retrieved, name)
|
|
}
|
|
|
|
o.R.UserUser = rel
|
|
|
|
if rel != nil {
|
|
rel.R.UserOauthTokens = OauthTokenSlice{o}
|
|
}
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("oauthToken has no relationship %q", name)
|
|
}
|
|
}
|
|
|
|
type oauthTokenPreloader struct {
|
|
UserUser func(...psql.PreloadOption) psql.Preloader
|
|
}
|
|
|
|
func buildOauthTokenPreloader() oauthTokenPreloader {
|
|
return oauthTokenPreloader{
|
|
UserUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
|
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
|
Name: "UserUser",
|
|
Sides: []psql.PreloadSide{
|
|
{
|
|
From: OauthTokens,
|
|
To: Users,
|
|
FromColumns: []string{"user_id"},
|
|
ToColumns: []string{"id"},
|
|
},
|
|
},
|
|
}, Users.Columns.Names(), opts...)
|
|
},
|
|
}
|
|
}
|
|
|
|
type oauthTokenThenLoader[Q orm.Loadable] struct {
|
|
UserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
|
}
|
|
|
|
func buildOauthTokenThenLoader[Q orm.Loadable]() oauthTokenThenLoader[Q] {
|
|
type UserUserLoadInterface interface {
|
|
LoadUserUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
|
}
|
|
|
|
return oauthTokenThenLoader[Q]{
|
|
UserUser: thenLoadBuilder[Q](
|
|
"UserUser",
|
|
func(ctx context.Context, exec bob.Executor, retrieved UserUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
return retrieved.LoadUserUser(ctx, exec, mods...)
|
|
},
|
|
),
|
|
}
|
|
}
|
|
|
|
// LoadUserUser loads the oauthToken's UserUser into the .R struct
|
|
func (o *OauthToken) LoadUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if o == nil {
|
|
return nil
|
|
}
|
|
|
|
// Reset the relationship
|
|
o.R.UserUser = nil
|
|
|
|
related, err := o.UserUser(mods...).One(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
related.R.UserOauthTokens = OauthTokenSlice{o}
|
|
|
|
o.R.UserUser = related
|
|
return nil
|
|
}
|
|
|
|
// LoadUserUser loads the oauthToken's UserUser into the .R struct
|
|
func (os OauthTokenSlice) LoadUserUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
|
if len(os) == 0 {
|
|
return nil
|
|
}
|
|
|
|
users, err := os.UserUser(mods...).All(ctx, exec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, o := range os {
|
|
if o == nil {
|
|
continue
|
|
}
|
|
|
|
for _, rel := range users {
|
|
|
|
if !(o.UserID == rel.ID) {
|
|
continue
|
|
}
|
|
|
|
rel.R.UserOauthTokens = append(rel.R.UserOauthTokens, o)
|
|
|
|
o.R.UserUser = rel
|
|
break
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type oauthTokenJoins[Q dialect.Joinable] struct {
|
|
typ string
|
|
UserUser modAs[Q, userColumns]
|
|
}
|
|
|
|
func (j oauthTokenJoins[Q]) aliasedAs(alias string) oauthTokenJoins[Q] {
|
|
return buildOauthTokenJoins[Q](buildOauthTokenColumns(alias), j.typ)
|
|
}
|
|
|
|
func buildOauthTokenJoins[Q dialect.Joinable](cols oauthTokenColumns, typ string) oauthTokenJoins[Q] {
|
|
return oauthTokenJoins[Q]{
|
|
typ: typ,
|
|
UserUser: modAs[Q, userColumns]{
|
|
c: Users.Columns,
|
|
f: func(to userColumns) bob.Mod[Q] {
|
|
mods := make(mods.QueryMods[Q], 0, 1)
|
|
|
|
{
|
|
mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On(
|
|
to.ID.EQ(cols.UserID),
|
|
))
|
|
}
|
|
|
|
return mods
|
|
},
|
|
},
|
|
}
|
|
}
|