(Feat): Initial Commit
This commit is contained in:
962
internal/models/access_tokens.go
Normal file
962
internal/models/access_tokens.go
Normal file
@@ -0,0 +1,962 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// AccessToken is an object representing the database table.
|
||||
type AccessToken struct {
|
||||
Token string `boil:"token" json:"token" toml:"token" yaml:"token"`
|
||||
ValidUntil time.Time `boil:"valid_until" json:"valid_until" toml:"valid_until" yaml:"valid_until"`
|
||||
UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
|
||||
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *accessTokenR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L accessTokenL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var AccessTokenColumns = struct {
|
||||
Token string
|
||||
ValidUntil string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "token",
|
||||
ValidUntil: "valid_until",
|
||||
UserID: "user_id",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
var AccessTokenTableColumns = struct {
|
||||
Token string
|
||||
ValidUntil string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "access_tokens.token",
|
||||
ValidUntil: "access_tokens.valid_until",
|
||||
UserID: "access_tokens.user_id",
|
||||
CreatedAt: "access_tokens.created_at",
|
||||
UpdatedAt: "access_tokens.updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
type whereHelperstring struct{ field string }
|
||||
|
||||
func (w whereHelperstring) EQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
|
||||
func (w whereHelperstring) NEQ(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.NEQ, x) }
|
||||
func (w whereHelperstring) LT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
|
||||
func (w whereHelperstring) LTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LTE, x) }
|
||||
func (w whereHelperstring) GT(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
|
||||
func (w whereHelperstring) GTE(x string) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GTE, x) }
|
||||
func (w whereHelperstring) LIKE(x string) qm.QueryMod { return qm.Where(w.field+" LIKE ?", x) }
|
||||
func (w whereHelperstring) NLIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT LIKE ?", x) }
|
||||
func (w whereHelperstring) ILIKE(x string) qm.QueryMod { return qm.Where(w.field+" ILIKE ?", x) }
|
||||
func (w whereHelperstring) NILIKE(x string) qm.QueryMod { return qm.Where(w.field+" NOT ILIKE ?", x) }
|
||||
func (w whereHelperstring) SIMILAR(x string) qm.QueryMod { return qm.Where(w.field+" SIMILAR TO ?", x) }
|
||||
func (w whereHelperstring) NSIMILAR(x string) qm.QueryMod {
|
||||
return qm.Where(w.field+" NOT SIMILAR TO ?", x)
|
||||
}
|
||||
func (w whereHelperstring) IN(slice []string) qm.QueryMod {
|
||||
values := make([]interface{}, 0, len(slice))
|
||||
for _, value := range slice {
|
||||
values = append(values, value)
|
||||
}
|
||||
return qm.WhereIn(fmt.Sprintf("%s IN ?", w.field), values...)
|
||||
}
|
||||
func (w whereHelperstring) NIN(slice []string) qm.QueryMod {
|
||||
values := make([]interface{}, 0, len(slice))
|
||||
for _, value := range slice {
|
||||
values = append(values, value)
|
||||
}
|
||||
return qm.WhereNotIn(fmt.Sprintf("%s NOT IN ?", w.field), values...)
|
||||
}
|
||||
|
||||
type whereHelpertime_Time struct{ field string }
|
||||
|
||||
func (w whereHelpertime_Time) EQ(x time.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.EQ, x)
|
||||
}
|
||||
func (w whereHelpertime_Time) NEQ(x time.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.NEQ, x)
|
||||
}
|
||||
func (w whereHelpertime_Time) LT(x time.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LT, x)
|
||||
}
|
||||
func (w whereHelpertime_Time) LTE(x time.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LTE, x)
|
||||
}
|
||||
func (w whereHelpertime_Time) GT(x time.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GT, x)
|
||||
}
|
||||
func (w whereHelpertime_Time) GTE(x time.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GTE, x)
|
||||
}
|
||||
|
||||
var AccessTokenWhere = struct {
|
||||
Token whereHelperstring
|
||||
ValidUntil whereHelpertime_Time
|
||||
UserID whereHelperstring
|
||||
CreatedAt whereHelpertime_Time
|
||||
UpdatedAt whereHelpertime_Time
|
||||
}{
|
||||
Token: whereHelperstring{field: "\"access_tokens\".\"token\""},
|
||||
ValidUntil: whereHelpertime_Time{field: "\"access_tokens\".\"valid_until\""},
|
||||
UserID: whereHelperstring{field: "\"access_tokens\".\"user_id\""},
|
||||
CreatedAt: whereHelpertime_Time{field: "\"access_tokens\".\"created_at\""},
|
||||
UpdatedAt: whereHelpertime_Time{field: "\"access_tokens\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// AccessTokenRels is where relationship names are stored.
|
||||
var AccessTokenRels = struct {
|
||||
User string
|
||||
}{
|
||||
User: "User",
|
||||
}
|
||||
|
||||
// accessTokenR is where relationships are stored.
|
||||
type accessTokenR struct {
|
||||
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*accessTokenR) NewStruct() *accessTokenR {
|
||||
return &accessTokenR{}
|
||||
}
|
||||
|
||||
func (o *AccessToken) GetUser() *User {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return o.R.GetUser()
|
||||
}
|
||||
|
||||
func (r *accessTokenR) GetUser() *User {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.User
|
||||
}
|
||||
|
||||
// accessTokenL is where Load methods for each relationship are stored.
|
||||
type accessTokenL struct{}
|
||||
|
||||
var (
|
||||
accessTokenAllColumns = []string{"token", "valid_until", "user_id", "created_at", "updated_at"}
|
||||
accessTokenColumnsWithoutDefault = []string{"valid_until", "user_id", "created_at", "updated_at"}
|
||||
accessTokenColumnsWithDefault = []string{"token"}
|
||||
accessTokenPrimaryKeyColumns = []string{"token"}
|
||||
accessTokenGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// AccessTokenSlice is an alias for a slice of pointers to AccessToken.
|
||||
// This should almost always be used instead of []AccessToken.
|
||||
AccessTokenSlice []*AccessToken
|
||||
|
||||
accessTokenQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
accessTokenType = reflect.TypeOf(&AccessToken{})
|
||||
accessTokenMapping = queries.MakeStructMapping(accessTokenType)
|
||||
accessTokenPrimaryKeyMapping, _ = queries.BindMapping(accessTokenType, accessTokenMapping, accessTokenPrimaryKeyColumns)
|
||||
accessTokenInsertCacheMut sync.RWMutex
|
||||
accessTokenInsertCache = make(map[string]insertCache)
|
||||
accessTokenUpdateCacheMut sync.RWMutex
|
||||
accessTokenUpdateCache = make(map[string]updateCache)
|
||||
accessTokenUpsertCacheMut sync.RWMutex
|
||||
accessTokenUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
// One returns a single accessToken record from the query.
|
||||
func (q accessTokenQuery) One(ctx context.Context, exec boil.ContextExecutor) (*AccessToken, error) {
|
||||
o := &AccessToken{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for access_tokens")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all AccessToken records from the query.
|
||||
func (q accessTokenQuery) All(ctx context.Context, exec boil.ContextExecutor) (AccessTokenSlice, error) {
|
||||
var o []*AccessToken
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to AccessToken slice")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all AccessToken records in the query.
|
||||
func (q accessTokenQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count access_tokens rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q accessTokenQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if access_tokens exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// User pointed to by the foreign key.
|
||||
func (o *AccessToken) User(mods ...qm.QueryMod) userQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.UserID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
return Users(queryMods...)
|
||||
}
|
||||
|
||||
// LoadUser allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (accessTokenL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccessToken interface{}, mods queries.Applicator) error {
|
||||
var slice []*AccessToken
|
||||
var object *AccessToken
|
||||
|
||||
if singular {
|
||||
var ok bool
|
||||
object, ok = maybeAccessToken.(*AccessToken)
|
||||
if !ok {
|
||||
object = new(AccessToken)
|
||||
ok = queries.SetFromEmbeddedStruct(&object, &maybeAccessToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccessToken))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s, ok := maybeAccessToken.(*[]*AccessToken)
|
||||
if ok {
|
||||
slice = *s
|
||||
} else {
|
||||
ok = queries.SetFromEmbeddedStruct(&slice, maybeAccessToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccessToken))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := make(map[interface{}]struct{})
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &accessTokenR{}
|
||||
}
|
||||
args[object.UserID] = struct{}{}
|
||||
|
||||
} else {
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &accessTokenR{}
|
||||
}
|
||||
|
||||
args[obj.UserID] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
argsSlice := make([]interface{}, len(args))
|
||||
i := 0
|
||||
for arg := range args {
|
||||
argsSlice[i] = arg
|
||||
i++
|
||||
}
|
||||
|
||||
query := NewQuery(
|
||||
qm.From(`users`),
|
||||
qm.WhereIn(`users.id in ?`, argsSlice...),
|
||||
)
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load User")
|
||||
}
|
||||
|
||||
var resultSlice []*User
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice User")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for users")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.AccessTokens = append(foreign.R.AccessTokens, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.UserID == foreign.ID {
|
||||
local.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.AccessTokens = append(foreign.R.AccessTokens, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUser of the accessToken to the related item.
|
||||
// Sets o.R.User to related.
|
||||
// Adds o to related.R.AccessTokens.
|
||||
func (o *AccessToken) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"access_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 2, accessTokenPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.Token}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, updateQuery)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.UserID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &accessTokenR{
|
||||
User: related,
|
||||
}
|
||||
} else {
|
||||
o.R.User = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &userR{
|
||||
AccessTokens: AccessTokenSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.AccessTokens = append(related.R.AccessTokens, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessTokens retrieves all the records using an executor.
|
||||
func AccessTokens(mods ...qm.QueryMod) accessTokenQuery {
|
||||
mods = append(mods, qm.From("\"access_tokens\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"access_tokens\".*"})
|
||||
}
|
||||
|
||||
return accessTokenQuery{q}
|
||||
}
|
||||
|
||||
// FindAccessToken retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindAccessToken(ctx context.Context, exec boil.ContextExecutor, token string, selectCols ...string) (*AccessToken, error) {
|
||||
accessTokenObj := &AccessToken{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"access_tokens\" where \"token\"=$1", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, token)
|
||||
|
||||
err := q.Bind(ctx, exec, accessTokenObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from access_tokens")
|
||||
}
|
||||
|
||||
return accessTokenObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *AccessToken) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no access_tokens provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
if o.UpdatedAt.IsZero() {
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(accessTokenColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
accessTokenInsertCacheMut.RLock()
|
||||
cache, cached := accessTokenInsertCache[key]
|
||||
accessTokenInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
accessTokenAllColumns,
|
||||
accessTokenColumnsWithDefault,
|
||||
accessTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(accessTokenType, accessTokenMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(accessTokenType, accessTokenMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"access_tokens\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"access_tokens\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into access_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
accessTokenInsertCacheMut.Lock()
|
||||
accessTokenInsertCache[key] = cache
|
||||
accessTokenInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update uses an executor to update the AccessToken.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *AccessToken) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
var err error
|
||||
key := makeCacheKey(columns, nil)
|
||||
accessTokenUpdateCacheMut.RLock()
|
||||
cache, cached := accessTokenUpdateCache[key]
|
||||
accessTokenUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
accessTokenAllColumns,
|
||||
accessTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update access_tokens, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"access_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, wl),
|
||||
strmangle.WhereClause("\"", "\"", len(wl)+1, accessTokenPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(accessTokenType, accessTokenMapping, append(wl, accessTokenPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update access_tokens row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for access_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
accessTokenUpdateCacheMut.Lock()
|
||||
accessTokenUpdateCache[key] = cache
|
||||
accessTokenUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q accessTokenQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for access_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for access_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o AccessTokenSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), accessTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"access_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, accessTokenPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in accessToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all accessToken")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *AccessToken) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no access_tokens provided for upsert")
|
||||
}
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(accessTokenColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
accessTokenUpsertCacheMut.RLock()
|
||||
cache, cached := accessTokenUpsertCache[key]
|
||||
accessTokenUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
accessTokenAllColumns,
|
||||
accessTokenColumnsWithDefault,
|
||||
accessTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
accessTokenAllColumns,
|
||||
accessTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert access_tokens, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(accessTokenAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
|
||||
if len(accessTokenPrimaryKeyColumns) == 0 {
|
||||
return errors.New("models: unable to upsert access_tokens, could not build conflict column list")
|
||||
}
|
||||
|
||||
conflict = make([]string, len(accessTokenPrimaryKeyColumns))
|
||||
copy(conflict, accessTokenPrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQueryPostgres(dialect, "\"access_tokens\"", updateOnConflict, ret, update, conflict, insert, opts...)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(accessTokenType, accessTokenMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(accessTokenType, accessTokenMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert access_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
accessTokenUpsertCacheMut.Lock()
|
||||
accessTokenUpsertCache[key] = cache
|
||||
accessTokenUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single AccessToken record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *AccessToken) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no AccessToken provided for delete")
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), accessTokenPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"access_tokens\" WHERE \"token\"=$1"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from access_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for access_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q accessTokenQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no accessTokenQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from access_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for access_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o AccessTokenSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), accessTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"access_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, accessTokenPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from accessToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for access_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *AccessToken) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindAccessToken(ctx, exec, o.Token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *AccessTokenSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := AccessTokenSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), accessTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"access_tokens\".* FROM \"access_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, accessTokenPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in AccessTokenSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessTokenExists checks if the AccessToken row exists.
|
||||
func AccessTokenExists(ctx context.Context, exec boil.ContextExecutor, token string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"access_tokens\" where \"token\"=$1 limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, token)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, token)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if access_tokens exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the AccessToken row exists.
|
||||
func (o *AccessToken) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return AccessTokenExists(ctx, exec, o.Token)
|
||||
}
|
||||
701
internal/models/access_tokens_test.go
Normal file
701
internal/models/access_tokens_test.go
Normal file
@@ -0,0 +1,701 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testAccessTokens(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := AccessTokens()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := AccessTokens().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := AccessTokenSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := AccessTokenExists(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if AccessToken exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected AccessTokenExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
accessTokenFound, err := FindAccessToken(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if accessTokenFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = AccessTokens().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := AccessTokens().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
accessTokenOne := &AccessToken{}
|
||||
accessTokenTwo := &AccessToken{}
|
||||
if err = randomize.Struct(seed, accessTokenOne, accessTokenDBTypes, false, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, accessTokenTwo, accessTokenDBTypes, false, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = accessTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = accessTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := AccessTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
accessTokenOne := &AccessToken{}
|
||||
accessTokenTwo := &AccessToken{}
|
||||
if err = randomize.Struct(seed, accessTokenOne, accessTokenDBTypes, false, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, accessTokenTwo, accessTokenDBTypes, false, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = accessTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = accessTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(strmangle.SetMerge(accessTokenPrimaryKeyColumns, accessTokenColumnsWithoutDefault)...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokenToOneUserUsingUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local AccessToken
|
||||
var foreign User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, accessTokenDBTypes, false, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, userDBTypes, false, userColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize User struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.UserID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.User().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := AccessTokenSlice{&local}
|
||||
if err = local.L.LoadUser(ctx, tx, false, (*[]*AccessToken)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.User = nil
|
||||
if err = local.L.LoadUser(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testAccessTokenToOneSetOpUserUsingUser(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a AccessToken
|
||||
var b, c User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, accessTokenDBTypes, false, strmangle.SetComplement(accessTokenPrimaryKeyColumns, accessTokenColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*User{&b, &c} {
|
||||
err = a.SetUser(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.User != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.AccessTokens[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.UserID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.UserID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := AccessTokenSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := AccessTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
accessTokenDBTypes = map[string]string{`Token`: `uuid`, `ValidUntil`: `timestamp with time zone`, `UserID`: `uuid`, `CreatedAt`: `timestamp with time zone`, `UpdatedAt`: `timestamp with time zone`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testAccessTokensUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(accessTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(accessTokenAllColumns) == len(accessTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(accessTokenAllColumns) == len(accessTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AccessToken{}
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, accessTokenDBTypes, true, accessTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(accessTokenAllColumns, accessTokenPrimaryKeyColumns) {
|
||||
fields = accessTokenAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
accessTokenAllColumns,
|
||||
accessTokenPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := AccessTokenSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccessTokensUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(accessTokenAllColumns) == len(accessTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := AccessToken{}
|
||||
if err = randomize.Struct(seed, &o, accessTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert AccessToken: %s", err)
|
||||
}
|
||||
|
||||
count, err := AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, accessTokenDBTypes, false, accessTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize AccessToken struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert AccessToken: %s", err)
|
||||
}
|
||||
|
||||
count, err = AccessTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
928
internal/models/app_user_profiles.go
Normal file
928
internal/models/app_user_profiles.go
Normal file
@@ -0,0 +1,928 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/null/v8"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// AppUserProfile is an object representing the database table.
|
||||
type AppUserProfile struct {
|
||||
UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
|
||||
LegalAcceptedAt null.Time `boil:"legal_accepted_at" json:"legal_accepted_at,omitempty" toml:"legal_accepted_at" yaml:"legal_accepted_at,omitempty"`
|
||||
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *appUserProfileR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L appUserProfileL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var AppUserProfileColumns = struct {
|
||||
UserID string
|
||||
LegalAcceptedAt string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
UserID: "user_id",
|
||||
LegalAcceptedAt: "legal_accepted_at",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
var AppUserProfileTableColumns = struct {
|
||||
UserID string
|
||||
LegalAcceptedAt string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
UserID: "app_user_profiles.user_id",
|
||||
LegalAcceptedAt: "app_user_profiles.legal_accepted_at",
|
||||
CreatedAt: "app_user_profiles.created_at",
|
||||
UpdatedAt: "app_user_profiles.updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
type whereHelpernull_Time struct{ field string }
|
||||
|
||||
func (w whereHelpernull_Time) EQ(x null.Time) qm.QueryMod {
|
||||
return qmhelper.WhereNullEQ(w.field, false, x)
|
||||
}
|
||||
func (w whereHelpernull_Time) NEQ(x null.Time) qm.QueryMod {
|
||||
return qmhelper.WhereNullEQ(w.field, true, x)
|
||||
}
|
||||
func (w whereHelpernull_Time) LT(x null.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LT, x)
|
||||
}
|
||||
func (w whereHelpernull_Time) LTE(x null.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LTE, x)
|
||||
}
|
||||
func (w whereHelpernull_Time) GT(x null.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GT, x)
|
||||
}
|
||||
func (w whereHelpernull_Time) GTE(x null.Time) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GTE, x)
|
||||
}
|
||||
|
||||
func (w whereHelpernull_Time) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
|
||||
func (w whereHelpernull_Time) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
|
||||
|
||||
var AppUserProfileWhere = struct {
|
||||
UserID whereHelperstring
|
||||
LegalAcceptedAt whereHelpernull_Time
|
||||
CreatedAt whereHelpertime_Time
|
||||
UpdatedAt whereHelpertime_Time
|
||||
}{
|
||||
UserID: whereHelperstring{field: "\"app_user_profiles\".\"user_id\""},
|
||||
LegalAcceptedAt: whereHelpernull_Time{field: "\"app_user_profiles\".\"legal_accepted_at\""},
|
||||
CreatedAt: whereHelpertime_Time{field: "\"app_user_profiles\".\"created_at\""},
|
||||
UpdatedAt: whereHelpertime_Time{field: "\"app_user_profiles\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// AppUserProfileRels is where relationship names are stored.
|
||||
var AppUserProfileRels = struct {
|
||||
User string
|
||||
}{
|
||||
User: "User",
|
||||
}
|
||||
|
||||
// appUserProfileR is where relationships are stored.
|
||||
type appUserProfileR struct {
|
||||
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*appUserProfileR) NewStruct() *appUserProfileR {
|
||||
return &appUserProfileR{}
|
||||
}
|
||||
|
||||
func (o *AppUserProfile) GetUser() *User {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return o.R.GetUser()
|
||||
}
|
||||
|
||||
func (r *appUserProfileR) GetUser() *User {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.User
|
||||
}
|
||||
|
||||
// appUserProfileL is where Load methods for each relationship are stored.
|
||||
type appUserProfileL struct{}
|
||||
|
||||
var (
|
||||
appUserProfileAllColumns = []string{"user_id", "legal_accepted_at", "created_at", "updated_at"}
|
||||
appUserProfileColumnsWithoutDefault = []string{"user_id", "created_at", "updated_at"}
|
||||
appUserProfileColumnsWithDefault = []string{"legal_accepted_at"}
|
||||
appUserProfilePrimaryKeyColumns = []string{"user_id"}
|
||||
appUserProfileGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// AppUserProfileSlice is an alias for a slice of pointers to AppUserProfile.
|
||||
// This should almost always be used instead of []AppUserProfile.
|
||||
AppUserProfileSlice []*AppUserProfile
|
||||
|
||||
appUserProfileQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
appUserProfileType = reflect.TypeOf(&AppUserProfile{})
|
||||
appUserProfileMapping = queries.MakeStructMapping(appUserProfileType)
|
||||
appUserProfilePrimaryKeyMapping, _ = queries.BindMapping(appUserProfileType, appUserProfileMapping, appUserProfilePrimaryKeyColumns)
|
||||
appUserProfileInsertCacheMut sync.RWMutex
|
||||
appUserProfileInsertCache = make(map[string]insertCache)
|
||||
appUserProfileUpdateCacheMut sync.RWMutex
|
||||
appUserProfileUpdateCache = make(map[string]updateCache)
|
||||
appUserProfileUpsertCacheMut sync.RWMutex
|
||||
appUserProfileUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
// One returns a single appUserProfile record from the query.
|
||||
func (q appUserProfileQuery) One(ctx context.Context, exec boil.ContextExecutor) (*AppUserProfile, error) {
|
||||
o := &AppUserProfile{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for app_user_profiles")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all AppUserProfile records from the query.
|
||||
func (q appUserProfileQuery) All(ctx context.Context, exec boil.ContextExecutor) (AppUserProfileSlice, error) {
|
||||
var o []*AppUserProfile
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to AppUserProfile slice")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all AppUserProfile records in the query.
|
||||
func (q appUserProfileQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count app_user_profiles rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q appUserProfileQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if app_user_profiles exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// User pointed to by the foreign key.
|
||||
func (o *AppUserProfile) User(mods ...qm.QueryMod) userQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.UserID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
return Users(queryMods...)
|
||||
}
|
||||
|
||||
// LoadUser allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (appUserProfileL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAppUserProfile interface{}, mods queries.Applicator) error {
|
||||
var slice []*AppUserProfile
|
||||
var object *AppUserProfile
|
||||
|
||||
if singular {
|
||||
var ok bool
|
||||
object, ok = maybeAppUserProfile.(*AppUserProfile)
|
||||
if !ok {
|
||||
object = new(AppUserProfile)
|
||||
ok = queries.SetFromEmbeddedStruct(&object, &maybeAppUserProfile)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAppUserProfile))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s, ok := maybeAppUserProfile.(*[]*AppUserProfile)
|
||||
if ok {
|
||||
slice = *s
|
||||
} else {
|
||||
ok = queries.SetFromEmbeddedStruct(&slice, maybeAppUserProfile)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAppUserProfile))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := make(map[interface{}]struct{})
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &appUserProfileR{}
|
||||
}
|
||||
args[object.UserID] = struct{}{}
|
||||
|
||||
} else {
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &appUserProfileR{}
|
||||
}
|
||||
|
||||
args[obj.UserID] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
argsSlice := make([]interface{}, len(args))
|
||||
i := 0
|
||||
for arg := range args {
|
||||
argsSlice[i] = arg
|
||||
i++
|
||||
}
|
||||
|
||||
query := NewQuery(
|
||||
qm.From(`users`),
|
||||
qm.WhereIn(`users.id in ?`, argsSlice...),
|
||||
)
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load User")
|
||||
}
|
||||
|
||||
var resultSlice []*User
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice User")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for users")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.AppUserProfile = object
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.UserID == foreign.ID {
|
||||
local.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.AppUserProfile = local
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUser of the appUserProfile to the related item.
|
||||
// Sets o.R.User to related.
|
||||
// Adds o to related.R.AppUserProfile.
|
||||
func (o *AppUserProfile) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"app_user_profiles\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 2, appUserProfilePrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.UserID}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, updateQuery)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.UserID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &appUserProfileR{
|
||||
User: related,
|
||||
}
|
||||
} else {
|
||||
o.R.User = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &userR{
|
||||
AppUserProfile: o,
|
||||
}
|
||||
} else {
|
||||
related.R.AppUserProfile = o
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppUserProfiles retrieves all the records using an executor.
|
||||
func AppUserProfiles(mods ...qm.QueryMod) appUserProfileQuery {
|
||||
mods = append(mods, qm.From("\"app_user_profiles\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"app_user_profiles\".*"})
|
||||
}
|
||||
|
||||
return appUserProfileQuery{q}
|
||||
}
|
||||
|
||||
// FindAppUserProfile retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindAppUserProfile(ctx context.Context, exec boil.ContextExecutor, userID string, selectCols ...string) (*AppUserProfile, error) {
|
||||
appUserProfileObj := &AppUserProfile{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"app_user_profiles\" where \"user_id\"=$1", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, userID)
|
||||
|
||||
err := q.Bind(ctx, exec, appUserProfileObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from app_user_profiles")
|
||||
}
|
||||
|
||||
return appUserProfileObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *AppUserProfile) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no app_user_profiles provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
if o.UpdatedAt.IsZero() {
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(appUserProfileColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
appUserProfileInsertCacheMut.RLock()
|
||||
cache, cached := appUserProfileInsertCache[key]
|
||||
appUserProfileInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
appUserProfileAllColumns,
|
||||
appUserProfileColumnsWithDefault,
|
||||
appUserProfileColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(appUserProfileType, appUserProfileMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(appUserProfileType, appUserProfileMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"app_user_profiles\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"app_user_profiles\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into app_user_profiles")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
appUserProfileInsertCacheMut.Lock()
|
||||
appUserProfileInsertCache[key] = cache
|
||||
appUserProfileInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update uses an executor to update the AppUserProfile.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *AppUserProfile) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
var err error
|
||||
key := makeCacheKey(columns, nil)
|
||||
appUserProfileUpdateCacheMut.RLock()
|
||||
cache, cached := appUserProfileUpdateCache[key]
|
||||
appUserProfileUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
appUserProfileAllColumns,
|
||||
appUserProfilePrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update app_user_profiles, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"app_user_profiles\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, wl),
|
||||
strmangle.WhereClause("\"", "\"", len(wl)+1, appUserProfilePrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(appUserProfileType, appUserProfileMapping, append(wl, appUserProfilePrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update app_user_profiles row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for app_user_profiles")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
appUserProfileUpdateCacheMut.Lock()
|
||||
appUserProfileUpdateCache[key] = cache
|
||||
appUserProfileUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q appUserProfileQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for app_user_profiles")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for app_user_profiles")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o AppUserProfileSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), appUserProfilePrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"app_user_profiles\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, appUserProfilePrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in appUserProfile slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all appUserProfile")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *AppUserProfile) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no app_user_profiles provided for upsert")
|
||||
}
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(appUserProfileColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
appUserProfileUpsertCacheMut.RLock()
|
||||
cache, cached := appUserProfileUpsertCache[key]
|
||||
appUserProfileUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
appUserProfileAllColumns,
|
||||
appUserProfileColumnsWithDefault,
|
||||
appUserProfileColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
appUserProfileAllColumns,
|
||||
appUserProfilePrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert app_user_profiles, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(appUserProfileAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
|
||||
if len(appUserProfilePrimaryKeyColumns) == 0 {
|
||||
return errors.New("models: unable to upsert app_user_profiles, could not build conflict column list")
|
||||
}
|
||||
|
||||
conflict = make([]string, len(appUserProfilePrimaryKeyColumns))
|
||||
copy(conflict, appUserProfilePrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQueryPostgres(dialect, "\"app_user_profiles\"", updateOnConflict, ret, update, conflict, insert, opts...)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(appUserProfileType, appUserProfileMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(appUserProfileType, appUserProfileMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert app_user_profiles")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
appUserProfileUpsertCacheMut.Lock()
|
||||
appUserProfileUpsertCache[key] = cache
|
||||
appUserProfileUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single AppUserProfile record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *AppUserProfile) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no AppUserProfile provided for delete")
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), appUserProfilePrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"app_user_profiles\" WHERE \"user_id\"=$1"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from app_user_profiles")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for app_user_profiles")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q appUserProfileQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no appUserProfileQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from app_user_profiles")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for app_user_profiles")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o AppUserProfileSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), appUserProfilePrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"app_user_profiles\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, appUserProfilePrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from appUserProfile slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for app_user_profiles")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *AppUserProfile) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindAppUserProfile(ctx, exec, o.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *AppUserProfileSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := AppUserProfileSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), appUserProfilePrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"app_user_profiles\".* FROM \"app_user_profiles\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, appUserProfilePrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in AppUserProfileSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AppUserProfileExists checks if the AppUserProfile row exists.
|
||||
func AppUserProfileExists(ctx context.Context, exec boil.ContextExecutor, userID string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"app_user_profiles\" where \"user_id\"=$1 limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, userID)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, userID)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if app_user_profiles exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the AppUserProfile row exists.
|
||||
func (o *AppUserProfile) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return AppUserProfileExists(ctx, exec, o.UserID)
|
||||
}
|
||||
697
internal/models/app_user_profiles_test.go
Normal file
697
internal/models/app_user_profiles_test.go
Normal file
@@ -0,0 +1,697 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testAppUserProfiles(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := AppUserProfiles()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := AppUserProfiles().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := AppUserProfileSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := AppUserProfileExists(ctx, tx, o.UserID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if AppUserProfile exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected AppUserProfileExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
appUserProfileFound, err := FindAppUserProfile(ctx, tx, o.UserID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if appUserProfileFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = AppUserProfiles().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := AppUserProfiles().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
appUserProfileOne := &AppUserProfile{}
|
||||
appUserProfileTwo := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, appUserProfileOne, appUserProfileDBTypes, false, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, appUserProfileTwo, appUserProfileDBTypes, false, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = appUserProfileOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = appUserProfileTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := AppUserProfiles().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
appUserProfileOne := &AppUserProfile{}
|
||||
appUserProfileTwo := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, appUserProfileOne, appUserProfileDBTypes, false, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, appUserProfileTwo, appUserProfileDBTypes, false, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = appUserProfileOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = appUserProfileTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(strmangle.SetMerge(appUserProfilePrimaryKeyColumns, appUserProfileColumnsWithoutDefault)...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfileToOneUserUsingUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local AppUserProfile
|
||||
var foreign User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, appUserProfileDBTypes, false, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, userDBTypes, false, userColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize User struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.UserID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.User().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := AppUserProfileSlice{&local}
|
||||
if err = local.L.LoadUser(ctx, tx, false, (*[]*AppUserProfile)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.User = nil
|
||||
if err = local.L.LoadUser(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testAppUserProfileToOneSetOpUserUsingUser(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a AppUserProfile
|
||||
var b, c User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, appUserProfileDBTypes, false, strmangle.SetComplement(appUserProfilePrimaryKeyColumns, appUserProfileColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*User{&b, &c} {
|
||||
err = a.SetUser(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.User != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.AppUserProfile != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID)
|
||||
}
|
||||
|
||||
if exists, err := AppUserProfileExists(ctx, tx, a.UserID); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !exists {
|
||||
t.Error("want 'a' to exist")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := AppUserProfileSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := AppUserProfiles().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
appUserProfileDBTypes = map[string]string{`UserID`: `uuid`, `LegalAcceptedAt`: `timestamp with time zone`, `CreatedAt`: `timestamp with time zone`, `UpdatedAt`: `timestamp with time zone`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testAppUserProfilesUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(appUserProfilePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(appUserProfileAllColumns) == len(appUserProfilePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfilePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(appUserProfileAllColumns) == len(appUserProfilePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &AppUserProfile{}
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfileColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, appUserProfileDBTypes, true, appUserProfilePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(appUserProfileAllColumns, appUserProfilePrimaryKeyColumns) {
|
||||
fields = appUserProfileAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
appUserProfileAllColumns,
|
||||
appUserProfilePrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := AppUserProfileSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testAppUserProfilesUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(appUserProfileAllColumns) == len(appUserProfilePrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := AppUserProfile{}
|
||||
if err = randomize.Struct(seed, &o, appUserProfileDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert AppUserProfile: %s", err)
|
||||
}
|
||||
|
||||
count, err := AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, appUserProfileDBTypes, false, appUserProfilePrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize AppUserProfile struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert AppUserProfile: %s", err)
|
||||
}
|
||||
|
||||
count, err = AppUserProfiles().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
119
internal/models/boil_main_test.go
Normal file
119
internal/models/boil_main_test.go
Normal file
@@ -0,0 +1,119 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var flagDebugMode = flag.Bool("test.sqldebug", false, "Turns on debug mode for SQL statements")
|
||||
var flagConfigFile = flag.String("test.config", "", "Overrides the default config")
|
||||
|
||||
const outputDirDepth = 2
|
||||
|
||||
var (
|
||||
dbMain tester
|
||||
)
|
||||
|
||||
type tester interface {
|
||||
setup() error
|
||||
conn() (*sql.DB, error)
|
||||
teardown() error
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if dbMain == nil {
|
||||
fmt.Println("no dbMain tester interface was ready")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
|
||||
// Load configuration
|
||||
err = initViper()
|
||||
if err != nil {
|
||||
fmt.Println("unable to load config file")
|
||||
os.Exit(-2)
|
||||
}
|
||||
|
||||
// Set DebugMode so we can see generated sql statements
|
||||
boil.DebugMode = *flagDebugMode
|
||||
|
||||
if err = dbMain.setup(); err != nil {
|
||||
fmt.Println("Unable to execute setup:", err)
|
||||
os.Exit(-4)
|
||||
}
|
||||
|
||||
conn, err := dbMain.conn()
|
||||
if err != nil {
|
||||
fmt.Println("failed to get connection:", err)
|
||||
}
|
||||
|
||||
var code int
|
||||
boil.SetDB(conn)
|
||||
code = m.Run()
|
||||
|
||||
if err = dbMain.teardown(); err != nil {
|
||||
fmt.Println("Unable to execute teardown:", err)
|
||||
os.Exit(-5)
|
||||
}
|
||||
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func initViper() error {
|
||||
if flagConfigFile != nil && *flagConfigFile != "" {
|
||||
viper.SetConfigFile(*flagConfigFile)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
viper.SetConfigName("sqlboiler")
|
||||
|
||||
configHome := os.Getenv("XDG_CONFIG_HOME")
|
||||
homePath := os.Getenv("HOME")
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
wd = strings.Repeat("../", outputDirDepth)
|
||||
} else {
|
||||
wd = wd + strings.Repeat("/..", outputDirDepth)
|
||||
}
|
||||
|
||||
configPaths := []string{wd}
|
||||
if len(configHome) > 0 {
|
||||
configPaths = append(configPaths, filepath.Join(configHome, "sqlboiler"))
|
||||
} else {
|
||||
configPaths = append(configPaths, filepath.Join(homePath, ".config/sqlboiler"))
|
||||
}
|
||||
|
||||
for _, p := range configPaths {
|
||||
viper.AddConfigPath(p)
|
||||
}
|
||||
|
||||
// Ignore errors here, fall back to defaults and validation to provide errs
|
||||
_ = viper.ReadInConfig()
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
viper.AutomaticEnv()
|
||||
|
||||
return nil
|
||||
}
|
||||
38
internal/models/boil_queries.go
Normal file
38
internal/models/boil_queries.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/drivers"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
)
|
||||
|
||||
var dialect = drivers.Dialect{
|
||||
LQ: 0x22,
|
||||
RQ: 0x22,
|
||||
|
||||
UseIndexPlaceholders: true,
|
||||
UseLastInsertID: false,
|
||||
UseSchema: false,
|
||||
UseDefaultKeyword: true,
|
||||
UseAutoColumns: false,
|
||||
UseTopClause: false,
|
||||
UseOutputClause: false,
|
||||
UseCaseWhenExistsClause: false,
|
||||
}
|
||||
|
||||
// This is a dummy variable to prevent unused regexp import error
|
||||
var _ = ®exp.Regexp{}
|
||||
|
||||
// NewQuery initializes a new Query using the passed in QueryMods
|
||||
func NewQuery(mods ...qm.QueryMod) *queries.Query {
|
||||
q := &queries.Query{}
|
||||
queries.SetDialect(q, &dialect)
|
||||
qm.Apply(q, mods...)
|
||||
|
||||
return q
|
||||
}
|
||||
51
internal/models/boil_queries_test.go
Normal file
51
internal/models/boil_queries_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
)
|
||||
|
||||
var dbNameRand *rand.Rand
|
||||
|
||||
func MustTx(transactor boil.ContextTransactor, err error) boil.ContextTransactor {
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Cannot create a transactor: %s", err))
|
||||
}
|
||||
return transactor
|
||||
}
|
||||
|
||||
func newFKeyDestroyer(regex *regexp.Regexp, reader io.Reader) io.Reader {
|
||||
return &fKeyDestroyer{
|
||||
reader: reader,
|
||||
rgx: regex,
|
||||
}
|
||||
}
|
||||
|
||||
type fKeyDestroyer struct {
|
||||
reader io.Reader
|
||||
buf *bytes.Buffer
|
||||
rgx *regexp.Regexp
|
||||
}
|
||||
|
||||
func (f *fKeyDestroyer) Read(b []byte) (int, error) {
|
||||
if f.buf == nil {
|
||||
all, err := io.ReadAll(f.reader)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
all = bytes.Replace(all, []byte{'\r', '\n'}, []byte{'\n'}, -1)
|
||||
all = f.rgx.ReplaceAll(all, []byte{})
|
||||
f.buf = bytes.NewBuffer(all)
|
||||
}
|
||||
|
||||
return f.buf.Read(b)
|
||||
}
|
||||
76
internal/models/boil_relationship_test.go
Normal file
76
internal/models/boil_relationship_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestToOne tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOne(t *testing.T) {
|
||||
t.Run("AccessTokenToUserUsingUser", testAccessTokenToOneUserUsingUser)
|
||||
t.Run("AppUserProfileToUserUsingUser", testAppUserProfileToOneUserUsingUser)
|
||||
t.Run("ConfirmationTokenToUserUsingUser", testConfirmationTokenToOneUserUsingUser)
|
||||
t.Run("PasswordResetTokenToUserUsingUser", testPasswordResetTokenToOneUserUsingUser)
|
||||
t.Run("PushTokenToUserUsingUser", testPushTokenToOneUserUsingUser)
|
||||
t.Run("RefreshTokenToUserUsingUser", testRefreshTokenToOneUserUsingUser)
|
||||
}
|
||||
|
||||
// TestOneToOne tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestOneToOne(t *testing.T) {
|
||||
t.Run("UserToAppUserProfileUsingAppUserProfile", testUserOneToOneAppUserProfileUsingAppUserProfile)
|
||||
}
|
||||
|
||||
// TestToMany tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToMany(t *testing.T) {
|
||||
t.Run("UserToAccessTokens", testUserToManyAccessTokens)
|
||||
t.Run("UserToConfirmationTokens", testUserToManyConfirmationTokens)
|
||||
t.Run("UserToPasswordResetTokens", testUserToManyPasswordResetTokens)
|
||||
t.Run("UserToPushTokens", testUserToManyPushTokens)
|
||||
t.Run("UserToRefreshTokens", testUserToManyRefreshTokens)
|
||||
}
|
||||
|
||||
// TestToOneSet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOneSet(t *testing.T) {
|
||||
t.Run("AccessTokenToUserUsingAccessTokens", testAccessTokenToOneSetOpUserUsingUser)
|
||||
t.Run("AppUserProfileToUserUsingAppUserProfile", testAppUserProfileToOneSetOpUserUsingUser)
|
||||
t.Run("ConfirmationTokenToUserUsingConfirmationTokens", testConfirmationTokenToOneSetOpUserUsingUser)
|
||||
t.Run("PasswordResetTokenToUserUsingPasswordResetTokens", testPasswordResetTokenToOneSetOpUserUsingUser)
|
||||
t.Run("PushTokenToUserUsingPushTokens", testPushTokenToOneSetOpUserUsingUser)
|
||||
t.Run("RefreshTokenToUserUsingRefreshTokens", testRefreshTokenToOneSetOpUserUsingUser)
|
||||
}
|
||||
|
||||
// TestToOneRemove tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOneRemove(t *testing.T) {}
|
||||
|
||||
// TestOneToOneSet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestOneToOneSet(t *testing.T) {
|
||||
t.Run("UserToAppUserProfileUsingAppUserProfile", testUserOneToOneSetOpAppUserProfileUsingAppUserProfile)
|
||||
}
|
||||
|
||||
// TestOneToOneRemove tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestOneToOneRemove(t *testing.T) {}
|
||||
|
||||
// TestToManyAdd tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToManyAdd(t *testing.T) {
|
||||
t.Run("UserToAccessTokens", testUserToManyAddOpAccessTokens)
|
||||
t.Run("UserToConfirmationTokens", testUserToManyAddOpConfirmationTokens)
|
||||
t.Run("UserToPasswordResetTokens", testUserToManyAddOpPasswordResetTokens)
|
||||
t.Run("UserToPushTokens", testUserToManyAddOpPushTokens)
|
||||
t.Run("UserToRefreshTokens", testUserToManyAddOpRefreshTokens)
|
||||
}
|
||||
|
||||
// TestToManySet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToManySet(t *testing.T) {}
|
||||
|
||||
// TestToManyRemove tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToManyRemove(t *testing.T) {}
|
||||
179
internal/models/boil_suites_test.go
Normal file
179
internal/models/boil_suites_test.go
Normal file
@@ -0,0 +1,179 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
// This test suite runs each operation test in parallel.
|
||||
// Example, if your database has 3 tables, the suite will run:
|
||||
// table1, table2 and table3 Delete in parallel
|
||||
// table1, table2 and table3 Insert in parallel, and so forth.
|
||||
// It does NOT run each operation group in parallel.
|
||||
// Separating the tests thusly grants avoidance of Postgres deadlocks.
|
||||
func TestParent(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokens)
|
||||
t.Run("AppUserProfiles", testAppUserProfiles)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokens)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokens)
|
||||
t.Run("PushTokens", testPushTokens)
|
||||
t.Run("RefreshTokens", testRefreshTokens)
|
||||
t.Run("Users", testUsers)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensDelete)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesDelete)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensDelete)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensDelete)
|
||||
t.Run("PushTokens", testPushTokensDelete)
|
||||
t.Run("RefreshTokens", testRefreshTokensDelete)
|
||||
t.Run("Users", testUsersDelete)
|
||||
}
|
||||
|
||||
func TestQueryDeleteAll(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensQueryDeleteAll)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesQueryDeleteAll)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensQueryDeleteAll)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensQueryDeleteAll)
|
||||
t.Run("PushTokens", testPushTokensQueryDeleteAll)
|
||||
t.Run("RefreshTokens", testRefreshTokensQueryDeleteAll)
|
||||
t.Run("Users", testUsersQueryDeleteAll)
|
||||
}
|
||||
|
||||
func TestSliceDeleteAll(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensSliceDeleteAll)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesSliceDeleteAll)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensSliceDeleteAll)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensSliceDeleteAll)
|
||||
t.Run("PushTokens", testPushTokensSliceDeleteAll)
|
||||
t.Run("RefreshTokens", testRefreshTokensSliceDeleteAll)
|
||||
t.Run("Users", testUsersSliceDeleteAll)
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensExists)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesExists)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensExists)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensExists)
|
||||
t.Run("PushTokens", testPushTokensExists)
|
||||
t.Run("RefreshTokens", testRefreshTokensExists)
|
||||
t.Run("Users", testUsersExists)
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensFind)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesFind)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensFind)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensFind)
|
||||
t.Run("PushTokens", testPushTokensFind)
|
||||
t.Run("RefreshTokens", testRefreshTokensFind)
|
||||
t.Run("Users", testUsersFind)
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensBind)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesBind)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensBind)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensBind)
|
||||
t.Run("PushTokens", testPushTokensBind)
|
||||
t.Run("RefreshTokens", testRefreshTokensBind)
|
||||
t.Run("Users", testUsersBind)
|
||||
}
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensOne)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesOne)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensOne)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensOne)
|
||||
t.Run("PushTokens", testPushTokensOne)
|
||||
t.Run("RefreshTokens", testRefreshTokensOne)
|
||||
t.Run("Users", testUsersOne)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensAll)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesAll)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensAll)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensAll)
|
||||
t.Run("PushTokens", testPushTokensAll)
|
||||
t.Run("RefreshTokens", testRefreshTokensAll)
|
||||
t.Run("Users", testUsersAll)
|
||||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensCount)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesCount)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensCount)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensCount)
|
||||
t.Run("PushTokens", testPushTokensCount)
|
||||
t.Run("RefreshTokens", testRefreshTokensCount)
|
||||
t.Run("Users", testUsersCount)
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensInsert)
|
||||
t.Run("AccessTokens", testAccessTokensInsertWhitelist)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesInsert)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesInsertWhitelist)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensInsert)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensInsertWhitelist)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensInsert)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensInsertWhitelist)
|
||||
t.Run("PushTokens", testPushTokensInsert)
|
||||
t.Run("PushTokens", testPushTokensInsertWhitelist)
|
||||
t.Run("RefreshTokens", testRefreshTokensInsert)
|
||||
t.Run("RefreshTokens", testRefreshTokensInsertWhitelist)
|
||||
t.Run("Users", testUsersInsert)
|
||||
t.Run("Users", testUsersInsertWhitelist)
|
||||
}
|
||||
|
||||
func TestReload(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensReload)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesReload)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensReload)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensReload)
|
||||
t.Run("PushTokens", testPushTokensReload)
|
||||
t.Run("RefreshTokens", testRefreshTokensReload)
|
||||
t.Run("Users", testUsersReload)
|
||||
}
|
||||
|
||||
func TestReloadAll(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensReloadAll)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesReloadAll)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensReloadAll)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensReloadAll)
|
||||
t.Run("PushTokens", testPushTokensReloadAll)
|
||||
t.Run("RefreshTokens", testRefreshTokensReloadAll)
|
||||
t.Run("Users", testUsersReloadAll)
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensSelect)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesSelect)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensSelect)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensSelect)
|
||||
t.Run("PushTokens", testPushTokensSelect)
|
||||
t.Run("RefreshTokens", testRefreshTokensSelect)
|
||||
t.Run("Users", testUsersSelect)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensUpdate)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesUpdate)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensUpdate)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensUpdate)
|
||||
t.Run("PushTokens", testPushTokensUpdate)
|
||||
t.Run("RefreshTokens", testRefreshTokensUpdate)
|
||||
t.Run("Users", testUsersUpdate)
|
||||
}
|
||||
|
||||
func TestSliceUpdateAll(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensSliceUpdateAll)
|
||||
t.Run("AppUserProfiles", testAppUserProfilesSliceUpdateAll)
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensSliceUpdateAll)
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensSliceUpdateAll)
|
||||
t.Run("PushTokens", testPushTokensSliceUpdateAll)
|
||||
t.Run("RefreshTokens", testRefreshTokensSliceUpdateAll)
|
||||
t.Run("Users", testUsersSliceUpdateAll)
|
||||
}
|
||||
22
internal/models/boil_table_names.go
Normal file
22
internal/models/boil_table_names.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
var TableNames = struct {
|
||||
AccessTokens string
|
||||
AppUserProfiles string
|
||||
ConfirmationTokens string
|
||||
PasswordResetTokens string
|
||||
PushTokens string
|
||||
RefreshTokens string
|
||||
Users string
|
||||
}{
|
||||
AccessTokens: "access_tokens",
|
||||
AppUserProfiles: "app_user_profiles",
|
||||
ConfirmationTokens: "confirmation_tokens",
|
||||
PasswordResetTokens: "password_reset_tokens",
|
||||
PushTokens: "push_tokens",
|
||||
RefreshTokens: "refresh_tokens",
|
||||
Users: "users",
|
||||
}
|
||||
65
internal/models/boil_types.go
Normal file
65
internal/models/boil_types.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// M type is for providing columns and column values to UpdateAll.
|
||||
type M map[string]interface{}
|
||||
|
||||
// ErrSyncFail occurs during insert when the record could not be retrieved in
|
||||
// order to populate default value information. This usually happens when LastInsertId
|
||||
// fails or there was a primary key configuration that was not resolvable.
|
||||
var ErrSyncFail = errors.New("models: failed to synchronize data after insert")
|
||||
|
||||
type insertCache struct {
|
||||
query string
|
||||
retQuery string
|
||||
valueMapping []uint64
|
||||
retMapping []uint64
|
||||
}
|
||||
|
||||
type updateCache struct {
|
||||
query string
|
||||
valueMapping []uint64
|
||||
}
|
||||
|
||||
func makeCacheKey(cols boil.Columns, nzDefaults []string) string {
|
||||
buf := strmangle.GetBuffer()
|
||||
|
||||
buf.WriteString(strconv.Itoa(cols.Kind))
|
||||
for _, w := range cols.Cols {
|
||||
buf.WriteString(w)
|
||||
}
|
||||
|
||||
if len(nzDefaults) != 0 {
|
||||
buf.WriteByte('.')
|
||||
}
|
||||
for _, nz := range nzDefaults {
|
||||
buf.WriteString(nz)
|
||||
}
|
||||
|
||||
str := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
return str
|
||||
}
|
||||
|
||||
// Enum values for ProviderType
|
||||
const (
|
||||
ProviderTypeFCM string = "fcm"
|
||||
ProviderTypeApn string = "apn"
|
||||
)
|
||||
|
||||
func AllProviderType() []string {
|
||||
return []string{
|
||||
ProviderTypeFCM,
|
||||
ProviderTypeApn,
|
||||
}
|
||||
}
|
||||
7
internal/models/boil_view_names.go
Normal file
7
internal/models/boil_view_names.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
var ViewNames = struct {
|
||||
}{}
|
||||
910
internal/models/confirmation_tokens.go
Normal file
910
internal/models/confirmation_tokens.go
Normal file
@@ -0,0 +1,910 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// ConfirmationToken is an object representing the database table.
|
||||
type ConfirmationToken struct {
|
||||
Token string `boil:"token" json:"token" toml:"token" yaml:"token"`
|
||||
ValidUntil time.Time `boil:"valid_until" json:"valid_until" toml:"valid_until" yaml:"valid_until"`
|
||||
UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
|
||||
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *confirmationTokenR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L confirmationTokenL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var ConfirmationTokenColumns = struct {
|
||||
Token string
|
||||
ValidUntil string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "token",
|
||||
ValidUntil: "valid_until",
|
||||
UserID: "user_id",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
var ConfirmationTokenTableColumns = struct {
|
||||
Token string
|
||||
ValidUntil string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "confirmation_tokens.token",
|
||||
ValidUntil: "confirmation_tokens.valid_until",
|
||||
UserID: "confirmation_tokens.user_id",
|
||||
CreatedAt: "confirmation_tokens.created_at",
|
||||
UpdatedAt: "confirmation_tokens.updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var ConfirmationTokenWhere = struct {
|
||||
Token whereHelperstring
|
||||
ValidUntil whereHelpertime_Time
|
||||
UserID whereHelperstring
|
||||
CreatedAt whereHelpertime_Time
|
||||
UpdatedAt whereHelpertime_Time
|
||||
}{
|
||||
Token: whereHelperstring{field: "\"confirmation_tokens\".\"token\""},
|
||||
ValidUntil: whereHelpertime_Time{field: "\"confirmation_tokens\".\"valid_until\""},
|
||||
UserID: whereHelperstring{field: "\"confirmation_tokens\".\"user_id\""},
|
||||
CreatedAt: whereHelpertime_Time{field: "\"confirmation_tokens\".\"created_at\""},
|
||||
UpdatedAt: whereHelpertime_Time{field: "\"confirmation_tokens\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// ConfirmationTokenRels is where relationship names are stored.
|
||||
var ConfirmationTokenRels = struct {
|
||||
User string
|
||||
}{
|
||||
User: "User",
|
||||
}
|
||||
|
||||
// confirmationTokenR is where relationships are stored.
|
||||
type confirmationTokenR struct {
|
||||
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*confirmationTokenR) NewStruct() *confirmationTokenR {
|
||||
return &confirmationTokenR{}
|
||||
}
|
||||
|
||||
func (o *ConfirmationToken) GetUser() *User {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return o.R.GetUser()
|
||||
}
|
||||
|
||||
func (r *confirmationTokenR) GetUser() *User {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.User
|
||||
}
|
||||
|
||||
// confirmationTokenL is where Load methods for each relationship are stored.
|
||||
type confirmationTokenL struct{}
|
||||
|
||||
var (
|
||||
confirmationTokenAllColumns = []string{"token", "valid_until", "user_id", "created_at", "updated_at"}
|
||||
confirmationTokenColumnsWithoutDefault = []string{"valid_until", "user_id", "created_at", "updated_at"}
|
||||
confirmationTokenColumnsWithDefault = []string{"token"}
|
||||
confirmationTokenPrimaryKeyColumns = []string{"token"}
|
||||
confirmationTokenGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// ConfirmationTokenSlice is an alias for a slice of pointers to ConfirmationToken.
|
||||
// This should almost always be used instead of []ConfirmationToken.
|
||||
ConfirmationTokenSlice []*ConfirmationToken
|
||||
|
||||
confirmationTokenQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
confirmationTokenType = reflect.TypeOf(&ConfirmationToken{})
|
||||
confirmationTokenMapping = queries.MakeStructMapping(confirmationTokenType)
|
||||
confirmationTokenPrimaryKeyMapping, _ = queries.BindMapping(confirmationTokenType, confirmationTokenMapping, confirmationTokenPrimaryKeyColumns)
|
||||
confirmationTokenInsertCacheMut sync.RWMutex
|
||||
confirmationTokenInsertCache = make(map[string]insertCache)
|
||||
confirmationTokenUpdateCacheMut sync.RWMutex
|
||||
confirmationTokenUpdateCache = make(map[string]updateCache)
|
||||
confirmationTokenUpsertCacheMut sync.RWMutex
|
||||
confirmationTokenUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
// One returns a single confirmationToken record from the query.
|
||||
func (q confirmationTokenQuery) One(ctx context.Context, exec boil.ContextExecutor) (*ConfirmationToken, error) {
|
||||
o := &ConfirmationToken{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for confirmation_tokens")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all ConfirmationToken records from the query.
|
||||
func (q confirmationTokenQuery) All(ctx context.Context, exec boil.ContextExecutor) (ConfirmationTokenSlice, error) {
|
||||
var o []*ConfirmationToken
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to ConfirmationToken slice")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all ConfirmationToken records in the query.
|
||||
func (q confirmationTokenQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count confirmation_tokens rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q confirmationTokenQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if confirmation_tokens exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// User pointed to by the foreign key.
|
||||
func (o *ConfirmationToken) User(mods ...qm.QueryMod) userQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.UserID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
return Users(queryMods...)
|
||||
}
|
||||
|
||||
// LoadUser allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (confirmationTokenL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeConfirmationToken interface{}, mods queries.Applicator) error {
|
||||
var slice []*ConfirmationToken
|
||||
var object *ConfirmationToken
|
||||
|
||||
if singular {
|
||||
var ok bool
|
||||
object, ok = maybeConfirmationToken.(*ConfirmationToken)
|
||||
if !ok {
|
||||
object = new(ConfirmationToken)
|
||||
ok = queries.SetFromEmbeddedStruct(&object, &maybeConfirmationToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeConfirmationToken))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s, ok := maybeConfirmationToken.(*[]*ConfirmationToken)
|
||||
if ok {
|
||||
slice = *s
|
||||
} else {
|
||||
ok = queries.SetFromEmbeddedStruct(&slice, maybeConfirmationToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeConfirmationToken))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := make(map[interface{}]struct{})
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &confirmationTokenR{}
|
||||
}
|
||||
args[object.UserID] = struct{}{}
|
||||
|
||||
} else {
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &confirmationTokenR{}
|
||||
}
|
||||
|
||||
args[obj.UserID] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
argsSlice := make([]interface{}, len(args))
|
||||
i := 0
|
||||
for arg := range args {
|
||||
argsSlice[i] = arg
|
||||
i++
|
||||
}
|
||||
|
||||
query := NewQuery(
|
||||
qm.From(`users`),
|
||||
qm.WhereIn(`users.id in ?`, argsSlice...),
|
||||
)
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load User")
|
||||
}
|
||||
|
||||
var resultSlice []*User
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice User")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for users")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.ConfirmationTokens = append(foreign.R.ConfirmationTokens, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.UserID == foreign.ID {
|
||||
local.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.ConfirmationTokens = append(foreign.R.ConfirmationTokens, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUser of the confirmationToken to the related item.
|
||||
// Sets o.R.User to related.
|
||||
// Adds o to related.R.ConfirmationTokens.
|
||||
func (o *ConfirmationToken) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"confirmation_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 2, confirmationTokenPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.Token}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, updateQuery)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.UserID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &confirmationTokenR{
|
||||
User: related,
|
||||
}
|
||||
} else {
|
||||
o.R.User = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &userR{
|
||||
ConfirmationTokens: ConfirmationTokenSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.ConfirmationTokens = append(related.R.ConfirmationTokens, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfirmationTokens retrieves all the records using an executor.
|
||||
func ConfirmationTokens(mods ...qm.QueryMod) confirmationTokenQuery {
|
||||
mods = append(mods, qm.From("\"confirmation_tokens\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"confirmation_tokens\".*"})
|
||||
}
|
||||
|
||||
return confirmationTokenQuery{q}
|
||||
}
|
||||
|
||||
// FindConfirmationToken retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindConfirmationToken(ctx context.Context, exec boil.ContextExecutor, token string, selectCols ...string) (*ConfirmationToken, error) {
|
||||
confirmationTokenObj := &ConfirmationToken{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"confirmation_tokens\" where \"token\"=$1", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, token)
|
||||
|
||||
err := q.Bind(ctx, exec, confirmationTokenObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from confirmation_tokens")
|
||||
}
|
||||
|
||||
return confirmationTokenObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *ConfirmationToken) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no confirmation_tokens provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
if o.UpdatedAt.IsZero() {
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(confirmationTokenColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
confirmationTokenInsertCacheMut.RLock()
|
||||
cache, cached := confirmationTokenInsertCache[key]
|
||||
confirmationTokenInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
confirmationTokenAllColumns,
|
||||
confirmationTokenColumnsWithDefault,
|
||||
confirmationTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(confirmationTokenType, confirmationTokenMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(confirmationTokenType, confirmationTokenMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"confirmation_tokens\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"confirmation_tokens\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into confirmation_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
confirmationTokenInsertCacheMut.Lock()
|
||||
confirmationTokenInsertCache[key] = cache
|
||||
confirmationTokenInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update uses an executor to update the ConfirmationToken.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *ConfirmationToken) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
var err error
|
||||
key := makeCacheKey(columns, nil)
|
||||
confirmationTokenUpdateCacheMut.RLock()
|
||||
cache, cached := confirmationTokenUpdateCache[key]
|
||||
confirmationTokenUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
confirmationTokenAllColumns,
|
||||
confirmationTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update confirmation_tokens, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"confirmation_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, wl),
|
||||
strmangle.WhereClause("\"", "\"", len(wl)+1, confirmationTokenPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(confirmationTokenType, confirmationTokenMapping, append(wl, confirmationTokenPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update confirmation_tokens row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for confirmation_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
confirmationTokenUpdateCacheMut.Lock()
|
||||
confirmationTokenUpdateCache[key] = cache
|
||||
confirmationTokenUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q confirmationTokenQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for confirmation_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for confirmation_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o ConfirmationTokenSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), confirmationTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"confirmation_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, confirmationTokenPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in confirmationToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all confirmationToken")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *ConfirmationToken) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no confirmation_tokens provided for upsert")
|
||||
}
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(confirmationTokenColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
confirmationTokenUpsertCacheMut.RLock()
|
||||
cache, cached := confirmationTokenUpsertCache[key]
|
||||
confirmationTokenUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
confirmationTokenAllColumns,
|
||||
confirmationTokenColumnsWithDefault,
|
||||
confirmationTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
confirmationTokenAllColumns,
|
||||
confirmationTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert confirmation_tokens, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(confirmationTokenAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
|
||||
if len(confirmationTokenPrimaryKeyColumns) == 0 {
|
||||
return errors.New("models: unable to upsert confirmation_tokens, could not build conflict column list")
|
||||
}
|
||||
|
||||
conflict = make([]string, len(confirmationTokenPrimaryKeyColumns))
|
||||
copy(conflict, confirmationTokenPrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQueryPostgres(dialect, "\"confirmation_tokens\"", updateOnConflict, ret, update, conflict, insert, opts...)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(confirmationTokenType, confirmationTokenMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(confirmationTokenType, confirmationTokenMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert confirmation_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
confirmationTokenUpsertCacheMut.Lock()
|
||||
confirmationTokenUpsertCache[key] = cache
|
||||
confirmationTokenUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single ConfirmationToken record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *ConfirmationToken) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no ConfirmationToken provided for delete")
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), confirmationTokenPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"confirmation_tokens\" WHERE \"token\"=$1"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from confirmation_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for confirmation_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q confirmationTokenQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no confirmationTokenQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from confirmation_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for confirmation_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o ConfirmationTokenSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), confirmationTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"confirmation_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, confirmationTokenPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from confirmationToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for confirmation_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *ConfirmationToken) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindConfirmationToken(ctx, exec, o.Token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *ConfirmationTokenSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := ConfirmationTokenSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), confirmationTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"confirmation_tokens\".* FROM \"confirmation_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, confirmationTokenPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in ConfirmationTokenSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfirmationTokenExists checks if the ConfirmationToken row exists.
|
||||
func ConfirmationTokenExists(ctx context.Context, exec boil.ContextExecutor, token string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"confirmation_tokens\" where \"token\"=$1 limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, token)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, token)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if confirmation_tokens exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the ConfirmationToken row exists.
|
||||
func (o *ConfirmationToken) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return ConfirmationTokenExists(ctx, exec, o.Token)
|
||||
}
|
||||
701
internal/models/confirmation_tokens_test.go
Normal file
701
internal/models/confirmation_tokens_test.go
Normal file
@@ -0,0 +1,701 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testConfirmationTokens(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := ConfirmationTokens()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := ConfirmationTokens().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := ConfirmationTokenSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := ConfirmationTokenExists(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if ConfirmationToken exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected ConfirmationTokenExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
confirmationTokenFound, err := FindConfirmationToken(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if confirmationTokenFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = ConfirmationTokens().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := ConfirmationTokens().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
confirmationTokenOne := &ConfirmationToken{}
|
||||
confirmationTokenTwo := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, confirmationTokenOne, confirmationTokenDBTypes, false, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, confirmationTokenTwo, confirmationTokenDBTypes, false, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = confirmationTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = confirmationTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := ConfirmationTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
confirmationTokenOne := &ConfirmationToken{}
|
||||
confirmationTokenTwo := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, confirmationTokenOne, confirmationTokenDBTypes, false, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, confirmationTokenTwo, confirmationTokenDBTypes, false, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = confirmationTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = confirmationTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(strmangle.SetMerge(confirmationTokenPrimaryKeyColumns, confirmationTokenColumnsWithoutDefault)...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokenToOneUserUsingUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local ConfirmationToken
|
||||
var foreign User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, confirmationTokenDBTypes, false, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, userDBTypes, false, userColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize User struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.UserID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.User().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := ConfirmationTokenSlice{&local}
|
||||
if err = local.L.LoadUser(ctx, tx, false, (*[]*ConfirmationToken)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.User = nil
|
||||
if err = local.L.LoadUser(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testConfirmationTokenToOneSetOpUserUsingUser(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a ConfirmationToken
|
||||
var b, c User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, confirmationTokenDBTypes, false, strmangle.SetComplement(confirmationTokenPrimaryKeyColumns, confirmationTokenColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*User{&b, &c} {
|
||||
err = a.SetUser(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.User != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.ConfirmationTokens[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.UserID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.UserID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := ConfirmationTokenSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := ConfirmationTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
confirmationTokenDBTypes = map[string]string{`Token`: `uuid`, `ValidUntil`: `timestamp with time zone`, `UserID`: `uuid`, `CreatedAt`: `timestamp with time zone`, `UpdatedAt`: `timestamp with time zone`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testConfirmationTokensUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(confirmationTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(confirmationTokenAllColumns) == len(confirmationTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(confirmationTokenAllColumns) == len(confirmationTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, confirmationTokenDBTypes, true, confirmationTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(confirmationTokenAllColumns, confirmationTokenPrimaryKeyColumns) {
|
||||
fields = confirmationTokenAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
confirmationTokenAllColumns,
|
||||
confirmationTokenPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := ConfirmationTokenSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testConfirmationTokensUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(confirmationTokenAllColumns) == len(confirmationTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := ConfirmationToken{}
|
||||
if err = randomize.Struct(seed, &o, confirmationTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert ConfirmationToken: %s", err)
|
||||
}
|
||||
|
||||
count, err := ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, confirmationTokenDBTypes, false, confirmationTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize ConfirmationToken struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert ConfirmationToken: %s", err)
|
||||
}
|
||||
|
||||
count, err = ConfirmationTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
910
internal/models/password_reset_tokens.go
Normal file
910
internal/models/password_reset_tokens.go
Normal file
@@ -0,0 +1,910 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// PasswordResetToken is an object representing the database table.
|
||||
type PasswordResetToken struct {
|
||||
Token string `boil:"token" json:"token" toml:"token" yaml:"token"`
|
||||
ValidUntil time.Time `boil:"valid_until" json:"valid_until" toml:"valid_until" yaml:"valid_until"`
|
||||
UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
|
||||
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *passwordResetTokenR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L passwordResetTokenL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var PasswordResetTokenColumns = struct {
|
||||
Token string
|
||||
ValidUntil string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "token",
|
||||
ValidUntil: "valid_until",
|
||||
UserID: "user_id",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
var PasswordResetTokenTableColumns = struct {
|
||||
Token string
|
||||
ValidUntil string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "password_reset_tokens.token",
|
||||
ValidUntil: "password_reset_tokens.valid_until",
|
||||
UserID: "password_reset_tokens.user_id",
|
||||
CreatedAt: "password_reset_tokens.created_at",
|
||||
UpdatedAt: "password_reset_tokens.updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var PasswordResetTokenWhere = struct {
|
||||
Token whereHelperstring
|
||||
ValidUntil whereHelpertime_Time
|
||||
UserID whereHelperstring
|
||||
CreatedAt whereHelpertime_Time
|
||||
UpdatedAt whereHelpertime_Time
|
||||
}{
|
||||
Token: whereHelperstring{field: "\"password_reset_tokens\".\"token\""},
|
||||
ValidUntil: whereHelpertime_Time{field: "\"password_reset_tokens\".\"valid_until\""},
|
||||
UserID: whereHelperstring{field: "\"password_reset_tokens\".\"user_id\""},
|
||||
CreatedAt: whereHelpertime_Time{field: "\"password_reset_tokens\".\"created_at\""},
|
||||
UpdatedAt: whereHelpertime_Time{field: "\"password_reset_tokens\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// PasswordResetTokenRels is where relationship names are stored.
|
||||
var PasswordResetTokenRels = struct {
|
||||
User string
|
||||
}{
|
||||
User: "User",
|
||||
}
|
||||
|
||||
// passwordResetTokenR is where relationships are stored.
|
||||
type passwordResetTokenR struct {
|
||||
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*passwordResetTokenR) NewStruct() *passwordResetTokenR {
|
||||
return &passwordResetTokenR{}
|
||||
}
|
||||
|
||||
func (o *PasswordResetToken) GetUser() *User {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return o.R.GetUser()
|
||||
}
|
||||
|
||||
func (r *passwordResetTokenR) GetUser() *User {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.User
|
||||
}
|
||||
|
||||
// passwordResetTokenL is where Load methods for each relationship are stored.
|
||||
type passwordResetTokenL struct{}
|
||||
|
||||
var (
|
||||
passwordResetTokenAllColumns = []string{"token", "valid_until", "user_id", "created_at", "updated_at"}
|
||||
passwordResetTokenColumnsWithoutDefault = []string{"valid_until", "user_id", "created_at", "updated_at"}
|
||||
passwordResetTokenColumnsWithDefault = []string{"token"}
|
||||
passwordResetTokenPrimaryKeyColumns = []string{"token"}
|
||||
passwordResetTokenGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// PasswordResetTokenSlice is an alias for a slice of pointers to PasswordResetToken.
|
||||
// This should almost always be used instead of []PasswordResetToken.
|
||||
PasswordResetTokenSlice []*PasswordResetToken
|
||||
|
||||
passwordResetTokenQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
passwordResetTokenType = reflect.TypeOf(&PasswordResetToken{})
|
||||
passwordResetTokenMapping = queries.MakeStructMapping(passwordResetTokenType)
|
||||
passwordResetTokenPrimaryKeyMapping, _ = queries.BindMapping(passwordResetTokenType, passwordResetTokenMapping, passwordResetTokenPrimaryKeyColumns)
|
||||
passwordResetTokenInsertCacheMut sync.RWMutex
|
||||
passwordResetTokenInsertCache = make(map[string]insertCache)
|
||||
passwordResetTokenUpdateCacheMut sync.RWMutex
|
||||
passwordResetTokenUpdateCache = make(map[string]updateCache)
|
||||
passwordResetTokenUpsertCacheMut sync.RWMutex
|
||||
passwordResetTokenUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
// One returns a single passwordResetToken record from the query.
|
||||
func (q passwordResetTokenQuery) One(ctx context.Context, exec boil.ContextExecutor) (*PasswordResetToken, error) {
|
||||
o := &PasswordResetToken{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for password_reset_tokens")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all PasswordResetToken records from the query.
|
||||
func (q passwordResetTokenQuery) All(ctx context.Context, exec boil.ContextExecutor) (PasswordResetTokenSlice, error) {
|
||||
var o []*PasswordResetToken
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to PasswordResetToken slice")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all PasswordResetToken records in the query.
|
||||
func (q passwordResetTokenQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count password_reset_tokens rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q passwordResetTokenQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if password_reset_tokens exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// User pointed to by the foreign key.
|
||||
func (o *PasswordResetToken) User(mods ...qm.QueryMod) userQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.UserID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
return Users(queryMods...)
|
||||
}
|
||||
|
||||
// LoadUser allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (passwordResetTokenL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybePasswordResetToken interface{}, mods queries.Applicator) error {
|
||||
var slice []*PasswordResetToken
|
||||
var object *PasswordResetToken
|
||||
|
||||
if singular {
|
||||
var ok bool
|
||||
object, ok = maybePasswordResetToken.(*PasswordResetToken)
|
||||
if !ok {
|
||||
object = new(PasswordResetToken)
|
||||
ok = queries.SetFromEmbeddedStruct(&object, &maybePasswordResetToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePasswordResetToken))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s, ok := maybePasswordResetToken.(*[]*PasswordResetToken)
|
||||
if ok {
|
||||
slice = *s
|
||||
} else {
|
||||
ok = queries.SetFromEmbeddedStruct(&slice, maybePasswordResetToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePasswordResetToken))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := make(map[interface{}]struct{})
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &passwordResetTokenR{}
|
||||
}
|
||||
args[object.UserID] = struct{}{}
|
||||
|
||||
} else {
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &passwordResetTokenR{}
|
||||
}
|
||||
|
||||
args[obj.UserID] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
argsSlice := make([]interface{}, len(args))
|
||||
i := 0
|
||||
for arg := range args {
|
||||
argsSlice[i] = arg
|
||||
i++
|
||||
}
|
||||
|
||||
query := NewQuery(
|
||||
qm.From(`users`),
|
||||
qm.WhereIn(`users.id in ?`, argsSlice...),
|
||||
)
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load User")
|
||||
}
|
||||
|
||||
var resultSlice []*User
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice User")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for users")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.PasswordResetTokens = append(foreign.R.PasswordResetTokens, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.UserID == foreign.ID {
|
||||
local.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.PasswordResetTokens = append(foreign.R.PasswordResetTokens, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUser of the passwordResetToken to the related item.
|
||||
// Sets o.R.User to related.
|
||||
// Adds o to related.R.PasswordResetTokens.
|
||||
func (o *PasswordResetToken) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"password_reset_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 2, passwordResetTokenPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.Token}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, updateQuery)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.UserID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &passwordResetTokenR{
|
||||
User: related,
|
||||
}
|
||||
} else {
|
||||
o.R.User = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &userR{
|
||||
PasswordResetTokens: PasswordResetTokenSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.PasswordResetTokens = append(related.R.PasswordResetTokens, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PasswordResetTokens retrieves all the records using an executor.
|
||||
func PasswordResetTokens(mods ...qm.QueryMod) passwordResetTokenQuery {
|
||||
mods = append(mods, qm.From("\"password_reset_tokens\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"password_reset_tokens\".*"})
|
||||
}
|
||||
|
||||
return passwordResetTokenQuery{q}
|
||||
}
|
||||
|
||||
// FindPasswordResetToken retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindPasswordResetToken(ctx context.Context, exec boil.ContextExecutor, token string, selectCols ...string) (*PasswordResetToken, error) {
|
||||
passwordResetTokenObj := &PasswordResetToken{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"password_reset_tokens\" where \"token\"=$1", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, token)
|
||||
|
||||
err := q.Bind(ctx, exec, passwordResetTokenObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from password_reset_tokens")
|
||||
}
|
||||
|
||||
return passwordResetTokenObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *PasswordResetToken) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no password_reset_tokens provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
if o.UpdatedAt.IsZero() {
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(passwordResetTokenColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
passwordResetTokenInsertCacheMut.RLock()
|
||||
cache, cached := passwordResetTokenInsertCache[key]
|
||||
passwordResetTokenInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
passwordResetTokenAllColumns,
|
||||
passwordResetTokenColumnsWithDefault,
|
||||
passwordResetTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(passwordResetTokenType, passwordResetTokenMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(passwordResetTokenType, passwordResetTokenMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"password_reset_tokens\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"password_reset_tokens\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into password_reset_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
passwordResetTokenInsertCacheMut.Lock()
|
||||
passwordResetTokenInsertCache[key] = cache
|
||||
passwordResetTokenInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update uses an executor to update the PasswordResetToken.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *PasswordResetToken) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
var err error
|
||||
key := makeCacheKey(columns, nil)
|
||||
passwordResetTokenUpdateCacheMut.RLock()
|
||||
cache, cached := passwordResetTokenUpdateCache[key]
|
||||
passwordResetTokenUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
passwordResetTokenAllColumns,
|
||||
passwordResetTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update password_reset_tokens, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"password_reset_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, wl),
|
||||
strmangle.WhereClause("\"", "\"", len(wl)+1, passwordResetTokenPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(passwordResetTokenType, passwordResetTokenMapping, append(wl, passwordResetTokenPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update password_reset_tokens row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for password_reset_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
passwordResetTokenUpdateCacheMut.Lock()
|
||||
passwordResetTokenUpdateCache[key] = cache
|
||||
passwordResetTokenUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q passwordResetTokenQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for password_reset_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for password_reset_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o PasswordResetTokenSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), passwordResetTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"password_reset_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, passwordResetTokenPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in passwordResetToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all passwordResetToken")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *PasswordResetToken) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no password_reset_tokens provided for upsert")
|
||||
}
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(passwordResetTokenColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
passwordResetTokenUpsertCacheMut.RLock()
|
||||
cache, cached := passwordResetTokenUpsertCache[key]
|
||||
passwordResetTokenUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
passwordResetTokenAllColumns,
|
||||
passwordResetTokenColumnsWithDefault,
|
||||
passwordResetTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
passwordResetTokenAllColumns,
|
||||
passwordResetTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert password_reset_tokens, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(passwordResetTokenAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
|
||||
if len(passwordResetTokenPrimaryKeyColumns) == 0 {
|
||||
return errors.New("models: unable to upsert password_reset_tokens, could not build conflict column list")
|
||||
}
|
||||
|
||||
conflict = make([]string, len(passwordResetTokenPrimaryKeyColumns))
|
||||
copy(conflict, passwordResetTokenPrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQueryPostgres(dialect, "\"password_reset_tokens\"", updateOnConflict, ret, update, conflict, insert, opts...)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(passwordResetTokenType, passwordResetTokenMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(passwordResetTokenType, passwordResetTokenMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert password_reset_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
passwordResetTokenUpsertCacheMut.Lock()
|
||||
passwordResetTokenUpsertCache[key] = cache
|
||||
passwordResetTokenUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single PasswordResetToken record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *PasswordResetToken) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no PasswordResetToken provided for delete")
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), passwordResetTokenPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"password_reset_tokens\" WHERE \"token\"=$1"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from password_reset_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for password_reset_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q passwordResetTokenQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no passwordResetTokenQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from password_reset_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for password_reset_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o PasswordResetTokenSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), passwordResetTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"password_reset_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, passwordResetTokenPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from passwordResetToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for password_reset_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *PasswordResetToken) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindPasswordResetToken(ctx, exec, o.Token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *PasswordResetTokenSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := PasswordResetTokenSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), passwordResetTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"password_reset_tokens\".* FROM \"password_reset_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, passwordResetTokenPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in PasswordResetTokenSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PasswordResetTokenExists checks if the PasswordResetToken row exists.
|
||||
func PasswordResetTokenExists(ctx context.Context, exec boil.ContextExecutor, token string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"password_reset_tokens\" where \"token\"=$1 limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, token)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, token)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if password_reset_tokens exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the PasswordResetToken row exists.
|
||||
func (o *PasswordResetToken) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return PasswordResetTokenExists(ctx, exec, o.Token)
|
||||
}
|
||||
701
internal/models/password_reset_tokens_test.go
Normal file
701
internal/models/password_reset_tokens_test.go
Normal file
@@ -0,0 +1,701 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testPasswordResetTokens(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := PasswordResetTokens()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := PasswordResetTokens().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := PasswordResetTokenSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := PasswordResetTokenExists(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if PasswordResetToken exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected PasswordResetTokenExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
passwordResetTokenFound, err := FindPasswordResetToken(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if passwordResetTokenFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = PasswordResetTokens().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := PasswordResetTokens().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
passwordResetTokenOne := &PasswordResetToken{}
|
||||
passwordResetTokenTwo := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, passwordResetTokenOne, passwordResetTokenDBTypes, false, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, passwordResetTokenTwo, passwordResetTokenDBTypes, false, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = passwordResetTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = passwordResetTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := PasswordResetTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
passwordResetTokenOne := &PasswordResetToken{}
|
||||
passwordResetTokenTwo := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, passwordResetTokenOne, passwordResetTokenDBTypes, false, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, passwordResetTokenTwo, passwordResetTokenDBTypes, false, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = passwordResetTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = passwordResetTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(strmangle.SetMerge(passwordResetTokenPrimaryKeyColumns, passwordResetTokenColumnsWithoutDefault)...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokenToOneUserUsingUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local PasswordResetToken
|
||||
var foreign User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, passwordResetTokenDBTypes, false, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, userDBTypes, false, userColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize User struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.UserID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.User().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := PasswordResetTokenSlice{&local}
|
||||
if err = local.L.LoadUser(ctx, tx, false, (*[]*PasswordResetToken)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.User = nil
|
||||
if err = local.L.LoadUser(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testPasswordResetTokenToOneSetOpUserUsingUser(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a PasswordResetToken
|
||||
var b, c User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, passwordResetTokenDBTypes, false, strmangle.SetComplement(passwordResetTokenPrimaryKeyColumns, passwordResetTokenColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*User{&b, &c} {
|
||||
err = a.SetUser(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.User != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.PasswordResetTokens[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.UserID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.UserID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := PasswordResetTokenSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := PasswordResetTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
passwordResetTokenDBTypes = map[string]string{`Token`: `uuid`, `ValidUntil`: `timestamp with time zone`, `UserID`: `uuid`, `CreatedAt`: `timestamp with time zone`, `UpdatedAt`: `timestamp with time zone`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testPasswordResetTokensUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(passwordResetTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(passwordResetTokenAllColumns) == len(passwordResetTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(passwordResetTokenAllColumns) == len(passwordResetTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, passwordResetTokenDBTypes, true, passwordResetTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(passwordResetTokenAllColumns, passwordResetTokenPrimaryKeyColumns) {
|
||||
fields = passwordResetTokenAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
passwordResetTokenAllColumns,
|
||||
passwordResetTokenPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := PasswordResetTokenSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testPasswordResetTokensUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(passwordResetTokenAllColumns) == len(passwordResetTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := PasswordResetToken{}
|
||||
if err = randomize.Struct(seed, &o, passwordResetTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert PasswordResetToken: %s", err)
|
||||
}
|
||||
|
||||
count, err := PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, passwordResetTokenDBTypes, false, passwordResetTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize PasswordResetToken struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert PasswordResetToken: %s", err)
|
||||
}
|
||||
|
||||
count, err = PasswordResetTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
231
internal/models/psql_main_test.go
Normal file
231
internal/models/psql_main_test.go
Normal file
@@ -0,0 +1,231 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/drivers/sqlboiler-psql/driver"
|
||||
"github.com/friendsofgo/errors"
|
||||
"github.com/kat-co/vala"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var rgxPGFkey = regexp.MustCompile(`(?m)^ALTER TABLE .*\n\s+ADD CONSTRAINT .*? FOREIGN KEY .*?;\n`)
|
||||
|
||||
type pgTester struct {
|
||||
dbConn *sql.DB
|
||||
|
||||
dbName string
|
||||
host string
|
||||
user string
|
||||
pass string
|
||||
sslmode string
|
||||
port int
|
||||
|
||||
pgPassFile string
|
||||
|
||||
testDBName string
|
||||
skipSQLCmd bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
dbMain = &pgTester{}
|
||||
}
|
||||
|
||||
// setup dumps the database schema and imports it into a temporary randomly
|
||||
// generated test database so that tests can be run against it using the
|
||||
// generated sqlboiler ORM package.
|
||||
func (p *pgTester) setup() error {
|
||||
var err error
|
||||
|
||||
viper.SetDefault("psql.schema", "public")
|
||||
viper.SetDefault("psql.port", 5432)
|
||||
viper.SetDefault("psql.sslmode", "require")
|
||||
|
||||
p.dbName = viper.GetString("psql.dbname")
|
||||
p.host = viper.GetString("psql.host")
|
||||
p.user = viper.GetString("psql.user")
|
||||
p.pass = viper.GetString("psql.pass")
|
||||
p.port = viper.GetInt("psql.port")
|
||||
p.sslmode = viper.GetString("psql.sslmode")
|
||||
p.testDBName = viper.GetString("psql.testdbname")
|
||||
p.skipSQLCmd = viper.GetBool("psql.skipsqlcmd")
|
||||
|
||||
err = vala.BeginValidation().Validate(
|
||||
vala.StringNotEmpty(p.user, "psql.user"),
|
||||
vala.StringNotEmpty(p.host, "psql.host"),
|
||||
vala.Not(vala.Equals(p.port, 0, "psql.port")),
|
||||
vala.StringNotEmpty(p.dbName, "psql.dbname"),
|
||||
vala.StringNotEmpty(p.sslmode, "psql.sslmode"),
|
||||
).Check()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if no testing DB passed
|
||||
if len(p.testDBName) == 0 {
|
||||
// Create a randomized db name.
|
||||
p.testDBName = randomize.StableDBName(p.dbName)
|
||||
}
|
||||
|
||||
if err = p.makePGPassFile(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !p.skipSQLCmd {
|
||||
if err = p.dropTestDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = p.createTestDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dumpCmd := exec.Command("pg_dump", "--schema-only", p.dbName)
|
||||
dumpCmd.Env = append(os.Environ(), p.pgEnv()...)
|
||||
createCmd := exec.Command("psql", p.testDBName)
|
||||
createCmd.Env = append(os.Environ(), p.pgEnv()...)
|
||||
|
||||
r, w := io.Pipe()
|
||||
dumpCmdStderr := &bytes.Buffer{}
|
||||
createCmdStderr := &bytes.Buffer{}
|
||||
|
||||
dumpCmd.Stdout = w
|
||||
dumpCmd.Stderr = dumpCmdStderr
|
||||
|
||||
createCmd.Stdin = newFKeyDestroyer(rgxPGFkey, r)
|
||||
createCmd.Stderr = createCmdStderr
|
||||
|
||||
if err = dumpCmd.Start(); err != nil {
|
||||
return errors.Wrap(err, "failed to start pg_dump command")
|
||||
}
|
||||
if err = createCmd.Start(); err != nil {
|
||||
return errors.Wrap(err, "failed to start psql command")
|
||||
}
|
||||
|
||||
if err = dumpCmd.Wait(); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println(dumpCmdStderr.String())
|
||||
return errors.Wrap(err, "failed to wait for pg_dump command")
|
||||
}
|
||||
|
||||
_ = w.Close() // After dumpCmd is done, close the write end of the pipe
|
||||
|
||||
if err = createCmd.Wait(); err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println(createCmdStderr.String())
|
||||
return errors.Wrap(err, "failed to wait for psql command")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pgTester) runCmd(stdin, command string, args ...string) error {
|
||||
cmd := exec.Command(command, args...)
|
||||
cmd.Env = append(os.Environ(), p.pgEnv()...)
|
||||
|
||||
if len(stdin) != 0 {
|
||||
cmd.Stdin = strings.NewReader(stdin)
|
||||
}
|
||||
|
||||
stdout := &bytes.Buffer{}
|
||||
stderr := &bytes.Buffer{}
|
||||
cmd.Stdout = stdout
|
||||
cmd.Stderr = stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Println("failed running:", command, args)
|
||||
fmt.Println(stdout.String())
|
||||
fmt.Println(stderr.String())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pgTester) pgEnv() []string {
|
||||
return []string{
|
||||
fmt.Sprintf("PGHOST=%s", p.host),
|
||||
fmt.Sprintf("PGPORT=%d", p.port),
|
||||
fmt.Sprintf("PGUSER=%s", p.user),
|
||||
fmt.Sprintf("PGPASSFILE=%s", p.pgPassFile),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *pgTester) makePGPassFile() error {
|
||||
tmp, err := os.CreateTemp("", "pgpass")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create option file")
|
||||
}
|
||||
|
||||
fmt.Fprintf(tmp, "%s:%d:postgres:%s", p.host, p.port, p.user)
|
||||
if len(p.pass) != 0 {
|
||||
fmt.Fprintf(tmp, ":%s", p.pass)
|
||||
}
|
||||
fmt.Fprintln(tmp)
|
||||
|
||||
fmt.Fprintf(tmp, "%s:%d:%s:%s", p.host, p.port, p.dbName, p.user)
|
||||
if len(p.pass) != 0 {
|
||||
fmt.Fprintf(tmp, ":%s", p.pass)
|
||||
}
|
||||
fmt.Fprintln(tmp)
|
||||
|
||||
fmt.Fprintf(tmp, "%s:%d:%s:%s", p.host, p.port, p.testDBName, p.user)
|
||||
if len(p.pass) != 0 {
|
||||
fmt.Fprintf(tmp, ":%s", p.pass)
|
||||
}
|
||||
fmt.Fprintln(tmp)
|
||||
|
||||
p.pgPassFile = tmp.Name()
|
||||
return tmp.Close()
|
||||
}
|
||||
|
||||
func (p *pgTester) createTestDB() error {
|
||||
return p.runCmd("", "createdb", p.testDBName)
|
||||
}
|
||||
|
||||
func (p *pgTester) dropTestDB() error {
|
||||
return p.runCmd("", "dropdb", "--if-exists", p.testDBName)
|
||||
}
|
||||
|
||||
// teardown executes cleanup tasks when the tests finish running
|
||||
func (p *pgTester) teardown() error {
|
||||
var err error
|
||||
if err = p.dbConn.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
p.dbConn = nil
|
||||
|
||||
if !p.skipSQLCmd {
|
||||
if err = p.dropTestDB(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return os.Remove(p.pgPassFile)
|
||||
}
|
||||
|
||||
func (p *pgTester) conn() (*sql.DB, error) {
|
||||
if p.dbConn != nil {
|
||||
return p.dbConn, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
p.dbConn, err = sql.Open("postgres", driver.PSQLBuildQueryString(p.user, p.pass, p.testDBName, p.host, p.port, p.sslmode))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p.dbConn, nil
|
||||
}
|
||||
22
internal/models/psql_suites_test.go
Normal file
22
internal/models/psql_suites_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestUpsert(t *testing.T) {
|
||||
t.Run("AccessTokens", testAccessTokensUpsert)
|
||||
|
||||
t.Run("AppUserProfiles", testAppUserProfilesUpsert)
|
||||
|
||||
t.Run("ConfirmationTokens", testConfirmationTokensUpsert)
|
||||
|
||||
t.Run("PasswordResetTokens", testPasswordResetTokensUpsert)
|
||||
|
||||
t.Run("PushTokens", testPushTokensUpsert)
|
||||
|
||||
t.Run("RefreshTokens", testRefreshTokensUpsert)
|
||||
|
||||
t.Run("Users", testUsersUpsert)
|
||||
}
|
||||
99
internal/models/psql_upsert.go
Normal file
99
internal/models/psql_upsert.go
Normal file
@@ -0,0 +1,99 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/drivers"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
type UpsertOptions struct {
|
||||
conflictTarget string
|
||||
updateSet string
|
||||
}
|
||||
|
||||
type UpsertOptionFunc func(o *UpsertOptions)
|
||||
|
||||
func UpsertConflictTarget(conflictTarget string) UpsertOptionFunc {
|
||||
return func(o *UpsertOptions) {
|
||||
o.conflictTarget = conflictTarget
|
||||
}
|
||||
}
|
||||
|
||||
func UpsertUpdateSet(updateSet string) UpsertOptionFunc {
|
||||
return func(o *UpsertOptions) {
|
||||
o.updateSet = updateSet
|
||||
}
|
||||
}
|
||||
|
||||
// buildUpsertQueryPostgres builds a SQL statement string using the upsertData provided.
|
||||
func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnConflict bool, ret, update, conflict, whitelist []string, opts ...UpsertOptionFunc) string {
|
||||
conflict = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, conflict)
|
||||
whitelist = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, whitelist)
|
||||
ret = strmangle.IdentQuoteSlice(dia.LQ, dia.RQ, ret)
|
||||
|
||||
upsertOpts := &UpsertOptions{}
|
||||
for _, o := range opts {
|
||||
o(upsertOpts)
|
||||
}
|
||||
|
||||
buf := strmangle.GetBuffer()
|
||||
defer strmangle.PutBuffer(buf)
|
||||
|
||||
columns := "DEFAULT VALUES"
|
||||
if len(whitelist) != 0 {
|
||||
columns = fmt.Sprintf("(%s) VALUES (%s)",
|
||||
strings.Join(whitelist, ", "),
|
||||
strmangle.Placeholders(dia.UseIndexPlaceholders, len(whitelist), 1, 1))
|
||||
}
|
||||
|
||||
fmt.Fprintf(
|
||||
buf,
|
||||
"INSERT INTO %s %s ON CONFLICT ",
|
||||
tableName,
|
||||
columns,
|
||||
)
|
||||
|
||||
if upsertOpts.conflictTarget != "" {
|
||||
buf.WriteString(upsertOpts.conflictTarget)
|
||||
} else if len(conflict) != 0 {
|
||||
buf.WriteByte('(')
|
||||
buf.WriteString(strings.Join(conflict, ", "))
|
||||
buf.WriteByte(')')
|
||||
}
|
||||
buf.WriteByte(' ')
|
||||
|
||||
if !updateOnConflict || len(update) == 0 {
|
||||
buf.WriteString("DO NOTHING")
|
||||
} else {
|
||||
buf.WriteString("DO UPDATE SET ")
|
||||
|
||||
if upsertOpts.updateSet != "" {
|
||||
buf.WriteString(upsertOpts.updateSet)
|
||||
} else {
|
||||
for i, v := range update {
|
||||
if len(v) == 0 {
|
||||
continue
|
||||
}
|
||||
if i != 0 {
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
quoted := strmangle.IdentQuote(dia.LQ, dia.RQ, v)
|
||||
buf.WriteString(quoted)
|
||||
buf.WriteString(" = EXCLUDED.")
|
||||
buf.WriteString(quoted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(ret) != 0 {
|
||||
buf.WriteString(" RETURNING ")
|
||||
buf.WriteString(strings.Join(ret, ", "))
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
917
internal/models/push_tokens.go
Normal file
917
internal/models/push_tokens.go
Normal file
@@ -0,0 +1,917 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// PushToken is an object representing the database table.
|
||||
type PushToken struct {
|
||||
ID string `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
Token string `boil:"token" json:"token" toml:"token" yaml:"token"`
|
||||
Provider string `boil:"provider" json:"provider" toml:"provider" yaml:"provider"`
|
||||
UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
|
||||
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *pushTokenR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L pushTokenL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var PushTokenColumns = struct {
|
||||
ID string
|
||||
Token string
|
||||
Provider string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
ID: "id",
|
||||
Token: "token",
|
||||
Provider: "provider",
|
||||
UserID: "user_id",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
var PushTokenTableColumns = struct {
|
||||
ID string
|
||||
Token string
|
||||
Provider string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
ID: "push_tokens.id",
|
||||
Token: "push_tokens.token",
|
||||
Provider: "push_tokens.provider",
|
||||
UserID: "push_tokens.user_id",
|
||||
CreatedAt: "push_tokens.created_at",
|
||||
UpdatedAt: "push_tokens.updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var PushTokenWhere = struct {
|
||||
ID whereHelperstring
|
||||
Token whereHelperstring
|
||||
Provider whereHelperstring
|
||||
UserID whereHelperstring
|
||||
CreatedAt whereHelpertime_Time
|
||||
UpdatedAt whereHelpertime_Time
|
||||
}{
|
||||
ID: whereHelperstring{field: "\"push_tokens\".\"id\""},
|
||||
Token: whereHelperstring{field: "\"push_tokens\".\"token\""},
|
||||
Provider: whereHelperstring{field: "\"push_tokens\".\"provider\""},
|
||||
UserID: whereHelperstring{field: "\"push_tokens\".\"user_id\""},
|
||||
CreatedAt: whereHelpertime_Time{field: "\"push_tokens\".\"created_at\""},
|
||||
UpdatedAt: whereHelpertime_Time{field: "\"push_tokens\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// PushTokenRels is where relationship names are stored.
|
||||
var PushTokenRels = struct {
|
||||
User string
|
||||
}{
|
||||
User: "User",
|
||||
}
|
||||
|
||||
// pushTokenR is where relationships are stored.
|
||||
type pushTokenR struct {
|
||||
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*pushTokenR) NewStruct() *pushTokenR {
|
||||
return &pushTokenR{}
|
||||
}
|
||||
|
||||
func (o *PushToken) GetUser() *User {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return o.R.GetUser()
|
||||
}
|
||||
|
||||
func (r *pushTokenR) GetUser() *User {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.User
|
||||
}
|
||||
|
||||
// pushTokenL is where Load methods for each relationship are stored.
|
||||
type pushTokenL struct{}
|
||||
|
||||
var (
|
||||
pushTokenAllColumns = []string{"id", "token", "provider", "user_id", "created_at", "updated_at"}
|
||||
pushTokenColumnsWithoutDefault = []string{"token", "provider", "user_id", "created_at", "updated_at"}
|
||||
pushTokenColumnsWithDefault = []string{"id"}
|
||||
pushTokenPrimaryKeyColumns = []string{"id"}
|
||||
pushTokenGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// PushTokenSlice is an alias for a slice of pointers to PushToken.
|
||||
// This should almost always be used instead of []PushToken.
|
||||
PushTokenSlice []*PushToken
|
||||
|
||||
pushTokenQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
pushTokenType = reflect.TypeOf(&PushToken{})
|
||||
pushTokenMapping = queries.MakeStructMapping(pushTokenType)
|
||||
pushTokenPrimaryKeyMapping, _ = queries.BindMapping(pushTokenType, pushTokenMapping, pushTokenPrimaryKeyColumns)
|
||||
pushTokenInsertCacheMut sync.RWMutex
|
||||
pushTokenInsertCache = make(map[string]insertCache)
|
||||
pushTokenUpdateCacheMut sync.RWMutex
|
||||
pushTokenUpdateCache = make(map[string]updateCache)
|
||||
pushTokenUpsertCacheMut sync.RWMutex
|
||||
pushTokenUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
// One returns a single pushToken record from the query.
|
||||
func (q pushTokenQuery) One(ctx context.Context, exec boil.ContextExecutor) (*PushToken, error) {
|
||||
o := &PushToken{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for push_tokens")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all PushToken records from the query.
|
||||
func (q pushTokenQuery) All(ctx context.Context, exec boil.ContextExecutor) (PushTokenSlice, error) {
|
||||
var o []*PushToken
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to PushToken slice")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all PushToken records in the query.
|
||||
func (q pushTokenQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count push_tokens rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q pushTokenQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if push_tokens exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// User pointed to by the foreign key.
|
||||
func (o *PushToken) User(mods ...qm.QueryMod) userQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.UserID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
return Users(queryMods...)
|
||||
}
|
||||
|
||||
// LoadUser allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (pushTokenL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybePushToken interface{}, mods queries.Applicator) error {
|
||||
var slice []*PushToken
|
||||
var object *PushToken
|
||||
|
||||
if singular {
|
||||
var ok bool
|
||||
object, ok = maybePushToken.(*PushToken)
|
||||
if !ok {
|
||||
object = new(PushToken)
|
||||
ok = queries.SetFromEmbeddedStruct(&object, &maybePushToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePushToken))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s, ok := maybePushToken.(*[]*PushToken)
|
||||
if ok {
|
||||
slice = *s
|
||||
} else {
|
||||
ok = queries.SetFromEmbeddedStruct(&slice, maybePushToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePushToken))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := make(map[interface{}]struct{})
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &pushTokenR{}
|
||||
}
|
||||
args[object.UserID] = struct{}{}
|
||||
|
||||
} else {
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &pushTokenR{}
|
||||
}
|
||||
|
||||
args[obj.UserID] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
argsSlice := make([]interface{}, len(args))
|
||||
i := 0
|
||||
for arg := range args {
|
||||
argsSlice[i] = arg
|
||||
i++
|
||||
}
|
||||
|
||||
query := NewQuery(
|
||||
qm.From(`users`),
|
||||
qm.WhereIn(`users.id in ?`, argsSlice...),
|
||||
)
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load User")
|
||||
}
|
||||
|
||||
var resultSlice []*User
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice User")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for users")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.PushTokens = append(foreign.R.PushTokens, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.UserID == foreign.ID {
|
||||
local.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.PushTokens = append(foreign.R.PushTokens, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUser of the pushToken to the related item.
|
||||
// Sets o.R.User to related.
|
||||
// Adds o to related.R.PushTokens.
|
||||
func (o *PushToken) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"push_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 2, pushTokenPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.ID}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, updateQuery)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.UserID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &pushTokenR{
|
||||
User: related,
|
||||
}
|
||||
} else {
|
||||
o.R.User = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &userR{
|
||||
PushTokens: PushTokenSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.PushTokens = append(related.R.PushTokens, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PushTokens retrieves all the records using an executor.
|
||||
func PushTokens(mods ...qm.QueryMod) pushTokenQuery {
|
||||
mods = append(mods, qm.From("\"push_tokens\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"push_tokens\".*"})
|
||||
}
|
||||
|
||||
return pushTokenQuery{q}
|
||||
}
|
||||
|
||||
// FindPushToken retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindPushToken(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*PushToken, error) {
|
||||
pushTokenObj := &PushToken{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"push_tokens\" where \"id\"=$1", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, pushTokenObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from push_tokens")
|
||||
}
|
||||
|
||||
return pushTokenObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *PushToken) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no push_tokens provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
if o.UpdatedAt.IsZero() {
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(pushTokenColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
pushTokenInsertCacheMut.RLock()
|
||||
cache, cached := pushTokenInsertCache[key]
|
||||
pushTokenInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
pushTokenAllColumns,
|
||||
pushTokenColumnsWithDefault,
|
||||
pushTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(pushTokenType, pushTokenMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(pushTokenType, pushTokenMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"push_tokens\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"push_tokens\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into push_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
pushTokenInsertCacheMut.Lock()
|
||||
pushTokenInsertCache[key] = cache
|
||||
pushTokenInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update uses an executor to update the PushToken.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *PushToken) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
var err error
|
||||
key := makeCacheKey(columns, nil)
|
||||
pushTokenUpdateCacheMut.RLock()
|
||||
cache, cached := pushTokenUpdateCache[key]
|
||||
pushTokenUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
pushTokenAllColumns,
|
||||
pushTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update push_tokens, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"push_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, wl),
|
||||
strmangle.WhereClause("\"", "\"", len(wl)+1, pushTokenPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(pushTokenType, pushTokenMapping, append(wl, pushTokenPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update push_tokens row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for push_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
pushTokenUpdateCacheMut.Lock()
|
||||
pushTokenUpdateCache[key] = cache
|
||||
pushTokenUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q pushTokenQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for push_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for push_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o PushTokenSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), pushTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"push_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, pushTokenPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in pushToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all pushToken")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *PushToken) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no push_tokens provided for upsert")
|
||||
}
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(pushTokenColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
pushTokenUpsertCacheMut.RLock()
|
||||
cache, cached := pushTokenUpsertCache[key]
|
||||
pushTokenUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
pushTokenAllColumns,
|
||||
pushTokenColumnsWithDefault,
|
||||
pushTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
pushTokenAllColumns,
|
||||
pushTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert push_tokens, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(pushTokenAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
|
||||
if len(pushTokenPrimaryKeyColumns) == 0 {
|
||||
return errors.New("models: unable to upsert push_tokens, could not build conflict column list")
|
||||
}
|
||||
|
||||
conflict = make([]string, len(pushTokenPrimaryKeyColumns))
|
||||
copy(conflict, pushTokenPrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQueryPostgres(dialect, "\"push_tokens\"", updateOnConflict, ret, update, conflict, insert, opts...)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(pushTokenType, pushTokenMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(pushTokenType, pushTokenMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert push_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
pushTokenUpsertCacheMut.Lock()
|
||||
pushTokenUpsertCache[key] = cache
|
||||
pushTokenUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single PushToken record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *PushToken) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no PushToken provided for delete")
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), pushTokenPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"push_tokens\" WHERE \"id\"=$1"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from push_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for push_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q pushTokenQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no pushTokenQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from push_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for push_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o PushTokenSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), pushTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"push_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, pushTokenPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from pushToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for push_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *PushToken) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindPushToken(ctx, exec, o.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *PushTokenSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := PushTokenSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), pushTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"push_tokens\".* FROM \"push_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, pushTokenPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in PushTokenSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PushTokenExists checks if the PushToken row exists.
|
||||
func PushTokenExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"push_tokens\" where \"id\"=$1 limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, iD)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, iD)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if push_tokens exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the PushToken row exists.
|
||||
func (o *PushToken) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return PushTokenExists(ctx, exec, o.ID)
|
||||
}
|
||||
701
internal/models/push_tokens_test.go
Normal file
701
internal/models/push_tokens_test.go
Normal file
@@ -0,0 +1,701 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testPushTokens(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := PushTokens()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := PushTokens().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := PushTokenSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := PushTokenExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if PushToken exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected PushTokenExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
pushTokenFound, err := FindPushToken(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if pushTokenFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = PushTokens().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := PushTokens().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
pushTokenOne := &PushToken{}
|
||||
pushTokenTwo := &PushToken{}
|
||||
if err = randomize.Struct(seed, pushTokenOne, pushTokenDBTypes, false, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, pushTokenTwo, pushTokenDBTypes, false, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = pushTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = pushTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := PushTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
pushTokenOne := &PushToken{}
|
||||
pushTokenTwo := &PushToken{}
|
||||
if err = randomize.Struct(seed, pushTokenOne, pushTokenDBTypes, false, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, pushTokenTwo, pushTokenDBTypes, false, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = pushTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = pushTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(strmangle.SetMerge(pushTokenPrimaryKeyColumns, pushTokenColumnsWithoutDefault)...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokenToOneUserUsingUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local PushToken
|
||||
var foreign User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, pushTokenDBTypes, false, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, userDBTypes, false, userColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize User struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.UserID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.User().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := PushTokenSlice{&local}
|
||||
if err = local.L.LoadUser(ctx, tx, false, (*[]*PushToken)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.User = nil
|
||||
if err = local.L.LoadUser(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testPushTokenToOneSetOpUserUsingUser(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a PushToken
|
||||
var b, c User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, pushTokenDBTypes, false, strmangle.SetComplement(pushTokenPrimaryKeyColumns, pushTokenColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*User{&b, &c} {
|
||||
err = a.SetUser(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.User != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.PushTokens[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.UserID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.UserID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := PushTokenSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := PushTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
pushTokenDBTypes = map[string]string{`ID`: `uuid`, `Token`: `text`, `Provider`: `enum.provider_type('fcm','apn')`, `UserID`: `uuid`, `CreatedAt`: `timestamp with time zone`, `UpdatedAt`: `timestamp with time zone`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testPushTokensUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(pushTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(pushTokenAllColumns) == len(pushTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(pushTokenAllColumns) == len(pushTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &PushToken{}
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, pushTokenDBTypes, true, pushTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(pushTokenAllColumns, pushTokenPrimaryKeyColumns) {
|
||||
fields = pushTokenAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
pushTokenAllColumns,
|
||||
pushTokenPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := PushTokenSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testPushTokensUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(pushTokenAllColumns) == len(pushTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := PushToken{}
|
||||
if err = randomize.Struct(seed, &o, pushTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert PushToken: %s", err)
|
||||
}
|
||||
|
||||
count, err := PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, pushTokenDBTypes, false, pushTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize PushToken struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert PushToken: %s", err)
|
||||
}
|
||||
|
||||
count, err = PushTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
903
internal/models/refresh_tokens.go
Normal file
903
internal/models/refresh_tokens.go
Normal file
@@ -0,0 +1,903 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qm"
|
||||
"github.com/aarondl/sqlboiler/v4/queries/qmhelper"
|
||||
"github.com/aarondl/strmangle"
|
||||
"github.com/friendsofgo/errors"
|
||||
)
|
||||
|
||||
// RefreshToken is an object representing the database table.
|
||||
type RefreshToken struct {
|
||||
Token string `boil:"token" json:"token" toml:"token" yaml:"token"`
|
||||
UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
|
||||
CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
|
||||
UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
|
||||
|
||||
R *refreshTokenR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L refreshTokenL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var RefreshTokenColumns = struct {
|
||||
Token string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "token",
|
||||
UserID: "user_id",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
var RefreshTokenTableColumns = struct {
|
||||
Token string
|
||||
UserID string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}{
|
||||
Token: "refresh_tokens.token",
|
||||
UserID: "refresh_tokens.user_id",
|
||||
CreatedAt: "refresh_tokens.created_at",
|
||||
UpdatedAt: "refresh_tokens.updated_at",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var RefreshTokenWhere = struct {
|
||||
Token whereHelperstring
|
||||
UserID whereHelperstring
|
||||
CreatedAt whereHelpertime_Time
|
||||
UpdatedAt whereHelpertime_Time
|
||||
}{
|
||||
Token: whereHelperstring{field: "\"refresh_tokens\".\"token\""},
|
||||
UserID: whereHelperstring{field: "\"refresh_tokens\".\"user_id\""},
|
||||
CreatedAt: whereHelpertime_Time{field: "\"refresh_tokens\".\"created_at\""},
|
||||
UpdatedAt: whereHelpertime_Time{field: "\"refresh_tokens\".\"updated_at\""},
|
||||
}
|
||||
|
||||
// RefreshTokenRels is where relationship names are stored.
|
||||
var RefreshTokenRels = struct {
|
||||
User string
|
||||
}{
|
||||
User: "User",
|
||||
}
|
||||
|
||||
// refreshTokenR is where relationships are stored.
|
||||
type refreshTokenR struct {
|
||||
User *User `boil:"User" json:"User" toml:"User" yaml:"User"`
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*refreshTokenR) NewStruct() *refreshTokenR {
|
||||
return &refreshTokenR{}
|
||||
}
|
||||
|
||||
func (o *RefreshToken) GetUser() *User {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return o.R.GetUser()
|
||||
}
|
||||
|
||||
func (r *refreshTokenR) GetUser() *User {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return r.User
|
||||
}
|
||||
|
||||
// refreshTokenL is where Load methods for each relationship are stored.
|
||||
type refreshTokenL struct{}
|
||||
|
||||
var (
|
||||
refreshTokenAllColumns = []string{"token", "user_id", "created_at", "updated_at"}
|
||||
refreshTokenColumnsWithoutDefault = []string{"user_id", "created_at", "updated_at"}
|
||||
refreshTokenColumnsWithDefault = []string{"token"}
|
||||
refreshTokenPrimaryKeyColumns = []string{"token"}
|
||||
refreshTokenGeneratedColumns = []string{}
|
||||
)
|
||||
|
||||
type (
|
||||
// RefreshTokenSlice is an alias for a slice of pointers to RefreshToken.
|
||||
// This should almost always be used instead of []RefreshToken.
|
||||
RefreshTokenSlice []*RefreshToken
|
||||
|
||||
refreshTokenQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
refreshTokenType = reflect.TypeOf(&RefreshToken{})
|
||||
refreshTokenMapping = queries.MakeStructMapping(refreshTokenType)
|
||||
refreshTokenPrimaryKeyMapping, _ = queries.BindMapping(refreshTokenType, refreshTokenMapping, refreshTokenPrimaryKeyColumns)
|
||||
refreshTokenInsertCacheMut sync.RWMutex
|
||||
refreshTokenInsertCache = make(map[string]insertCache)
|
||||
refreshTokenUpdateCacheMut sync.RWMutex
|
||||
refreshTokenUpdateCache = make(map[string]updateCache)
|
||||
refreshTokenUpsertCacheMut sync.RWMutex
|
||||
refreshTokenUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
// One returns a single refreshToken record from the query.
|
||||
func (q refreshTokenQuery) One(ctx context.Context, exec boil.ContextExecutor) (*RefreshToken, error) {
|
||||
o := &RefreshToken{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: failed to execute a one query for refresh_tokens")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all RefreshToken records from the query.
|
||||
func (q refreshTokenQuery) All(ctx context.Context, exec boil.ContextExecutor) (RefreshTokenSlice, error) {
|
||||
var o []*RefreshToken
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "models: failed to assign all query results to RefreshToken slice")
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all RefreshToken records in the query.
|
||||
func (q refreshTokenQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to count refresh_tokens rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q refreshTokenQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: failed to check if refresh_tokens exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// User pointed to by the foreign key.
|
||||
func (o *RefreshToken) User(mods ...qm.QueryMod) userQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.UserID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
return Users(queryMods...)
|
||||
}
|
||||
|
||||
// LoadUser allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (refreshTokenL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeRefreshToken interface{}, mods queries.Applicator) error {
|
||||
var slice []*RefreshToken
|
||||
var object *RefreshToken
|
||||
|
||||
if singular {
|
||||
var ok bool
|
||||
object, ok = maybeRefreshToken.(*RefreshToken)
|
||||
if !ok {
|
||||
object = new(RefreshToken)
|
||||
ok = queries.SetFromEmbeddedStruct(&object, &maybeRefreshToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeRefreshToken))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s, ok := maybeRefreshToken.(*[]*RefreshToken)
|
||||
if ok {
|
||||
slice = *s
|
||||
} else {
|
||||
ok = queries.SetFromEmbeddedStruct(&slice, maybeRefreshToken)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeRefreshToken))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args := make(map[interface{}]struct{})
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &refreshTokenR{}
|
||||
}
|
||||
args[object.UserID] = struct{}{}
|
||||
|
||||
} else {
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &refreshTokenR{}
|
||||
}
|
||||
|
||||
args[obj.UserID] = struct{}{}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
argsSlice := make([]interface{}, len(args))
|
||||
i := 0
|
||||
for arg := range args {
|
||||
argsSlice[i] = arg
|
||||
i++
|
||||
}
|
||||
|
||||
query := NewQuery(
|
||||
qm.From(`users`),
|
||||
qm.WhereIn(`users.id in ?`, argsSlice...),
|
||||
)
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load User")
|
||||
}
|
||||
|
||||
var resultSlice []*User
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice User")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for users")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users")
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.RefreshTokens = append(foreign.R.RefreshTokens, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.UserID == foreign.ID {
|
||||
local.R.User = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &userR{}
|
||||
}
|
||||
foreign.R.RefreshTokens = append(foreign.R.RefreshTokens, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetUser of the refreshToken to the related item.
|
||||
// Sets o.R.User to related.
|
||||
// Adds o to related.R.RefreshTokens.
|
||||
func (o *RefreshToken) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"refresh_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 2, refreshTokenPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.Token}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, updateQuery)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.UserID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &refreshTokenR{
|
||||
User: related,
|
||||
}
|
||||
} else {
|
||||
o.R.User = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &userR{
|
||||
RefreshTokens: RefreshTokenSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.RefreshTokens = append(related.R.RefreshTokens, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RefreshTokens retrieves all the records using an executor.
|
||||
func RefreshTokens(mods ...qm.QueryMod) refreshTokenQuery {
|
||||
mods = append(mods, qm.From("\"refresh_tokens\""))
|
||||
q := NewQuery(mods...)
|
||||
if len(queries.GetSelect(q)) == 0 {
|
||||
queries.SetSelect(q, []string{"\"refresh_tokens\".*"})
|
||||
}
|
||||
|
||||
return refreshTokenQuery{q}
|
||||
}
|
||||
|
||||
// FindRefreshToken retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindRefreshToken(ctx context.Context, exec boil.ContextExecutor, token string, selectCols ...string) (*RefreshToken, error) {
|
||||
refreshTokenObj := &RefreshToken{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"refresh_tokens\" where \"token\"=$1", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, token)
|
||||
|
||||
err := q.Bind(ctx, exec, refreshTokenObj)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "models: unable to select from refresh_tokens")
|
||||
}
|
||||
|
||||
return refreshTokenObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *RefreshToken) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no refresh_tokens provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
if o.UpdatedAt.IsZero() {
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(refreshTokenColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
refreshTokenInsertCacheMut.RLock()
|
||||
cache, cached := refreshTokenInsertCache[key]
|
||||
refreshTokenInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
refreshTokenAllColumns,
|
||||
refreshTokenColumnsWithDefault,
|
||||
refreshTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(refreshTokenType, refreshTokenMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(refreshTokenType, refreshTokenMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"refresh_tokens\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"refresh_tokens\" %sDEFAULT VALUES%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to insert into refresh_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
refreshTokenInsertCacheMut.Lock()
|
||||
refreshTokenInsertCache[key] = cache
|
||||
refreshTokenInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update uses an executor to update the RefreshToken.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *RefreshToken) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
var err error
|
||||
key := makeCacheKey(columns, nil)
|
||||
refreshTokenUpdateCacheMut.RLock()
|
||||
cache, cached := refreshTokenUpdateCache[key]
|
||||
refreshTokenUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
refreshTokenAllColumns,
|
||||
refreshTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if !columns.IsWhitelist() {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("models: unable to update refresh_tokens, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"refresh_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, wl),
|
||||
strmangle.WhereClause("\"", "\"", len(wl)+1, refreshTokenPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(refreshTokenType, refreshTokenMapping, append(wl, refreshTokenPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, values)
|
||||
}
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update refresh_tokens row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by update for refresh_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
refreshTokenUpdateCacheMut.Lock()
|
||||
refreshTokenUpdateCache[key] = cache
|
||||
refreshTokenUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q refreshTokenQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all for refresh_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for refresh_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o RefreshTokenSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("models: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), refreshTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"refresh_tokens\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 1, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, refreshTokenPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to update all in refreshToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all refreshToken")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
|
||||
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
|
||||
func (o *RefreshToken) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error {
|
||||
if o == nil {
|
||||
return errors.New("models: no refresh_tokens provided for upsert")
|
||||
}
|
||||
if !boil.TimestampsAreSkipped(ctx) {
|
||||
currTime := time.Now().In(boil.GetLocation())
|
||||
|
||||
if o.CreatedAt.IsZero() {
|
||||
o.CreatedAt = currTime
|
||||
}
|
||||
o.UpdatedAt = currTime
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(refreshTokenColumnsWithDefault, o)
|
||||
|
||||
// Build cache key in-line uglily - mysql vs psql problems
|
||||
buf := strmangle.GetBuffer()
|
||||
if updateOnConflict {
|
||||
buf.WriteByte('t')
|
||||
} else {
|
||||
buf.WriteByte('f')
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range conflictColumns {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(updateColumns.Kind))
|
||||
for _, c := range updateColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(strconv.Itoa(insertColumns.Kind))
|
||||
for _, c := range insertColumns.Cols {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
buf.WriteByte('.')
|
||||
for _, c := range nzDefaults {
|
||||
buf.WriteString(c)
|
||||
}
|
||||
key := buf.String()
|
||||
strmangle.PutBuffer(buf)
|
||||
|
||||
refreshTokenUpsertCacheMut.RLock()
|
||||
cache, cached := refreshTokenUpsertCache[key]
|
||||
refreshTokenUpsertCacheMut.RUnlock()
|
||||
|
||||
var err error
|
||||
|
||||
if !cached {
|
||||
insert, _ := insertColumns.InsertColumnSet(
|
||||
refreshTokenAllColumns,
|
||||
refreshTokenColumnsWithDefault,
|
||||
refreshTokenColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
update := updateColumns.UpdateColumnSet(
|
||||
refreshTokenAllColumns,
|
||||
refreshTokenPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if updateOnConflict && len(update) == 0 {
|
||||
return errors.New("models: unable to upsert refresh_tokens, could not build update column list")
|
||||
}
|
||||
|
||||
ret := strmangle.SetComplement(refreshTokenAllColumns, strmangle.SetIntersect(insert, update))
|
||||
|
||||
conflict := conflictColumns
|
||||
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
|
||||
if len(refreshTokenPrimaryKeyColumns) == 0 {
|
||||
return errors.New("models: unable to upsert refresh_tokens, could not build conflict column list")
|
||||
}
|
||||
|
||||
conflict = make([]string, len(refreshTokenPrimaryKeyColumns))
|
||||
copy(conflict, refreshTokenPrimaryKeyColumns)
|
||||
}
|
||||
cache.query = buildUpsertQueryPostgres(dialect, "\"refresh_tokens\"", updateOnConflict, ret, update, conflict, insert, opts...)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(refreshTokenType, refreshTokenMapping, insert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ret) != 0 {
|
||||
cache.retMapping, err = queries.BindMapping(refreshTokenType, refreshTokenMapping, ret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
var returns []interface{}
|
||||
if len(cache.retMapping) != 0 {
|
||||
returns = queries.PtrsFromMapping(value, cache.retMapping)
|
||||
}
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, cache.query)
|
||||
fmt.Fprintln(writer, vals)
|
||||
}
|
||||
if len(cache.retMapping) != 0 {
|
||||
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil // Postgres doesn't return anything when there's no update
|
||||
}
|
||||
} else {
|
||||
_, err = exec.ExecContext(ctx, cache.query, vals...)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to upsert refresh_tokens")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
refreshTokenUpsertCacheMut.Lock()
|
||||
refreshTokenUpsertCache[key] = cache
|
||||
refreshTokenUpsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes a single RefreshToken record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *RefreshToken) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("models: no RefreshToken provided for delete")
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), refreshTokenPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"refresh_tokens\" WHERE \"token\"=$1"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args...)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete from refresh_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for refresh_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q refreshTokenQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("models: no refreshTokenQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from refresh_tokens")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for refresh_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o RefreshTokenSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), refreshTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"refresh_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, refreshTokenPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, args)
|
||||
}
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: unable to delete all from refreshToken slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for refresh_tokens")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *RefreshToken) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindRefreshToken(ctx, exec, o.Token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *RefreshTokenSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := RefreshTokenSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), refreshTokenPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"refresh_tokens\".* FROM \"refresh_tokens\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, refreshTokenPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "models: unable to reload all in RefreshTokenSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RefreshTokenExists checks if the RefreshToken row exists.
|
||||
func RefreshTokenExists(ctx context.Context, exec boil.ContextExecutor, token string) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"refresh_tokens\" where \"token\"=$1 limit 1)"
|
||||
|
||||
if boil.IsDebug(ctx) {
|
||||
writer := boil.DebugWriterFrom(ctx)
|
||||
fmt.Fprintln(writer, sql)
|
||||
fmt.Fprintln(writer, token)
|
||||
}
|
||||
row := exec.QueryRowContext(ctx, sql, token)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "models: unable to check if refresh_tokens exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// Exists checks if the RefreshToken row exists.
|
||||
func (o *RefreshToken) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
return RefreshTokenExists(ctx, exec, o.Token)
|
||||
}
|
||||
701
internal/models/refresh_tokens_test.go
Normal file
701
internal/models/refresh_tokens_test.go
Normal file
@@ -0,0 +1,701 @@
|
||||
// Code generated by SQLBoiler 4.19.5 (https://github.com/aarondl/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/aarondl/randomize"
|
||||
"github.com/aarondl/sqlboiler/v4/boil"
|
||||
"github.com/aarondl/sqlboiler/v4/queries"
|
||||
"github.com/aarondl/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testRefreshTokens(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := RefreshTokens()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := RefreshTokens().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := RefreshTokenSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := RefreshTokenExists(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if RefreshToken exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected RefreshTokenExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
refreshTokenFound, err := FindRefreshToken(ctx, tx, o.Token)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if refreshTokenFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = RefreshTokens().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := RefreshTokens().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
refreshTokenOne := &RefreshToken{}
|
||||
refreshTokenTwo := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, refreshTokenOne, refreshTokenDBTypes, false, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, refreshTokenTwo, refreshTokenDBTypes, false, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = refreshTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = refreshTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := RefreshTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
refreshTokenOne := &RefreshToken{}
|
||||
refreshTokenTwo := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, refreshTokenOne, refreshTokenDBTypes, false, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, refreshTokenTwo, refreshTokenDBTypes, false, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = refreshTokenOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = refreshTokenTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(strmangle.SetMerge(refreshTokenPrimaryKeyColumns, refreshTokenColumnsWithoutDefault)...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokenToOneUserUsingUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local RefreshToken
|
||||
var foreign User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, refreshTokenDBTypes, false, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, userDBTypes, false, userColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize User struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.UserID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.User().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := RefreshTokenSlice{&local}
|
||||
if err = local.L.LoadUser(ctx, tx, false, (*[]*RefreshToken)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.User = nil
|
||||
if err = local.L.LoadUser(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.User == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testRefreshTokenToOneSetOpUserUsingUser(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a RefreshToken
|
||||
var b, c User
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, refreshTokenDBTypes, false, strmangle.SetComplement(refreshTokenPrimaryKeyColumns, refreshTokenColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, userDBTypes, false, strmangle.SetComplement(userPrimaryKeyColumns, userColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*User{&b, &c} {
|
||||
err = a.SetUser(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.User != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.RefreshTokens[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.UserID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.UserID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.UserID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.UserID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := RefreshTokenSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := RefreshTokens().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
refreshTokenDBTypes = map[string]string{`Token`: `uuid`, `UserID`: `uuid`, `CreatedAt`: `timestamp with time zone`, `UpdatedAt`: `timestamp with time zone`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testRefreshTokensUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(refreshTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(refreshTokenAllColumns) == len(refreshTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(refreshTokenAllColumns) == len(refreshTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &RefreshToken{}
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, refreshTokenDBTypes, true, refreshTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(refreshTokenAllColumns, refreshTokenPrimaryKeyColumns) {
|
||||
fields = refreshTokenAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
refreshTokenAllColumns,
|
||||
refreshTokenPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := RefreshTokenSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testRefreshTokensUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(refreshTokenAllColumns) == len(refreshTokenPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := RefreshToken{}
|
||||
if err = randomize.Struct(seed, &o, refreshTokenDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert RefreshToken: %s", err)
|
||||
}
|
||||
|
||||
count, err := RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, refreshTokenDBTypes, false, refreshTokenPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize RefreshToken struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert RefreshToken: %s", err)
|
||||
}
|
||||
|
||||
count, err = RefreshTokens().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
1986
internal/models/users.go
Normal file
1986
internal/models/users.go
Normal file
File diff suppressed because it is too large
Load Diff
1470
internal/models/users_test.go
Normal file
1470
internal/models/users_test.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user