// 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) }