go-ssb-room/admindb/sqlite/models/pinned_notices.go

944 lines
26 KiB
Go

// Code generated by SQLBoiler 4.4.0 (https://github.com/volatiletech/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"
"strings"
"sync"
"time"
"github.com/friendsofgo/errors"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
"github.com/volatiletech/sqlboiler/v4/queries/qmhelper"
"github.com/volatiletech/strmangle"
)
// PinnedNotice is an object representing the database table.
type PinnedNotice struct {
Name string `boil:"name" json:"name" toml:"name" yaml:"name"`
NoticeID int64 `boil:"notice_id" json:"notice_id" toml:"notice_id" yaml:"notice_id"`
Language string `boil:"language" json:"language" toml:"language" yaml:"language"`
R *pinnedNoticeR `boil:"-" json:"-" toml:"-" yaml:"-"`
L pinnedNoticeL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var PinnedNoticeColumns = struct {
Name string
NoticeID string
Language string
}{
Name: "name",
NoticeID: "notice_id",
Language: "language",
}
// Generated where
var PinnedNoticeWhere = struct {
Name whereHelperstring
NoticeID whereHelperint64
Language whereHelperstring
}{
Name: whereHelperstring{field: "\"pinned_notices\".\"name\""},
NoticeID: whereHelperint64{field: "\"pinned_notices\".\"notice_id\""},
Language: whereHelperstring{field: "\"pinned_notices\".\"language\""},
}
// PinnedNoticeRels is where relationship names are stored.
var PinnedNoticeRels = struct {
Notice string
}{
Notice: "Notice",
}
// pinnedNoticeR is where relationships are stored.
type pinnedNoticeR struct {
Notice *Notice `boil:"Notice" json:"Notice" toml:"Notice" yaml:"Notice"`
}
// NewStruct creates a new relationship struct
func (*pinnedNoticeR) NewStruct() *pinnedNoticeR {
return &pinnedNoticeR{}
}
// pinnedNoticeL is where Load methods for each relationship are stored.
type pinnedNoticeL struct{}
var (
pinnedNoticeAllColumns = []string{"name", "notice_id", "language"}
pinnedNoticeColumnsWithoutDefault = []string{"name", "notice_id", "language"}
pinnedNoticeColumnsWithDefault = []string{}
pinnedNoticePrimaryKeyColumns = []string{"name", "language"}
)
type (
// PinnedNoticeSlice is an alias for a slice of pointers to PinnedNotice.
// This should generally be used opposed to []PinnedNotice.
PinnedNoticeSlice []*PinnedNotice
// PinnedNoticeHook is the signature for custom PinnedNotice hook methods
PinnedNoticeHook func(context.Context, boil.ContextExecutor, *PinnedNotice) error
pinnedNoticeQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
pinnedNoticeType = reflect.TypeOf(&PinnedNotice{})
pinnedNoticeMapping = queries.MakeStructMapping(pinnedNoticeType)
pinnedNoticePrimaryKeyMapping, _ = queries.BindMapping(pinnedNoticeType, pinnedNoticeMapping, pinnedNoticePrimaryKeyColumns)
pinnedNoticeInsertCacheMut sync.RWMutex
pinnedNoticeInsertCache = make(map[string]insertCache)
pinnedNoticeUpdateCacheMut sync.RWMutex
pinnedNoticeUpdateCache = make(map[string]updateCache)
pinnedNoticeUpsertCacheMut sync.RWMutex
pinnedNoticeUpsertCache = 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
)
var pinnedNoticeBeforeInsertHooks []PinnedNoticeHook
var pinnedNoticeBeforeUpdateHooks []PinnedNoticeHook
var pinnedNoticeBeforeDeleteHooks []PinnedNoticeHook
var pinnedNoticeBeforeUpsertHooks []PinnedNoticeHook
var pinnedNoticeAfterInsertHooks []PinnedNoticeHook
var pinnedNoticeAfterSelectHooks []PinnedNoticeHook
var pinnedNoticeAfterUpdateHooks []PinnedNoticeHook
var pinnedNoticeAfterDeleteHooks []PinnedNoticeHook
var pinnedNoticeAfterUpsertHooks []PinnedNoticeHook
// doBeforeInsertHooks executes all "before insert" hooks.
func (o *PinnedNotice) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeBeforeInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *PinnedNotice) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeBeforeUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *PinnedNotice) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeBeforeDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *PinnedNotice) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeBeforeUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterInsertHooks executes all "after Insert" hooks.
func (o *PinnedNotice) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeAfterInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterSelectHooks executes all "after Select" hooks.
func (o *PinnedNotice) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeAfterSelectHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpdateHooks executes all "after Update" hooks.
func (o *PinnedNotice) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeAfterUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *PinnedNotice) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeAfterDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *PinnedNotice) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range pinnedNoticeAfterUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// AddPinnedNoticeHook registers your hook function for all future operations.
func AddPinnedNoticeHook(hookPoint boil.HookPoint, pinnedNoticeHook PinnedNoticeHook) {
switch hookPoint {
case boil.BeforeInsertHook:
pinnedNoticeBeforeInsertHooks = append(pinnedNoticeBeforeInsertHooks, pinnedNoticeHook)
case boil.BeforeUpdateHook:
pinnedNoticeBeforeUpdateHooks = append(pinnedNoticeBeforeUpdateHooks, pinnedNoticeHook)
case boil.BeforeDeleteHook:
pinnedNoticeBeforeDeleteHooks = append(pinnedNoticeBeforeDeleteHooks, pinnedNoticeHook)
case boil.BeforeUpsertHook:
pinnedNoticeBeforeUpsertHooks = append(pinnedNoticeBeforeUpsertHooks, pinnedNoticeHook)
case boil.AfterInsertHook:
pinnedNoticeAfterInsertHooks = append(pinnedNoticeAfterInsertHooks, pinnedNoticeHook)
case boil.AfterSelectHook:
pinnedNoticeAfterSelectHooks = append(pinnedNoticeAfterSelectHooks, pinnedNoticeHook)
case boil.AfterUpdateHook:
pinnedNoticeAfterUpdateHooks = append(pinnedNoticeAfterUpdateHooks, pinnedNoticeHook)
case boil.AfterDeleteHook:
pinnedNoticeAfterDeleteHooks = append(pinnedNoticeAfterDeleteHooks, pinnedNoticeHook)
case boil.AfterUpsertHook:
pinnedNoticeAfterUpsertHooks = append(pinnedNoticeAfterUpsertHooks, pinnedNoticeHook)
}
}
// One returns a single pinnedNotice record from the query.
func (q pinnedNoticeQuery) One(ctx context.Context, exec boil.ContextExecutor) (*PinnedNotice, error) {
o := &PinnedNotice{}
queries.SetLimit(q.Query, 1)
err := q.Bind(ctx, exec, o)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: failed to execute a one query for pinned_notices")
}
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
return o, nil
}
// All returns all PinnedNotice records from the query.
func (q pinnedNoticeQuery) All(ctx context.Context, exec boil.ContextExecutor) (PinnedNoticeSlice, error) {
var o []*PinnedNotice
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to PinnedNotice slice")
}
if len(pinnedNoticeAfterSelectHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
}
}
return o, nil
}
// Count returns the count of all PinnedNotice records in the query.
func (q pinnedNoticeQuery) 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 pinned_notices rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q pinnedNoticeQuery) 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 pinned_notices exists")
}
return count > 0, nil
}
// Notice pointed to by the foreign key.
func (o *PinnedNotice) Notice(mods ...qm.QueryMod) noticeQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.NoticeID),
}
queryMods = append(queryMods, mods...)
query := Notices(queryMods...)
queries.SetFrom(query.Query, "\"notices\"")
return query
}
// LoadNotice allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (pinnedNoticeL) LoadNotice(ctx context.Context, e boil.ContextExecutor, singular bool, maybePinnedNotice interface{}, mods queries.Applicator) error {
var slice []*PinnedNotice
var object *PinnedNotice
if singular {
object = maybePinnedNotice.(*PinnedNotice)
} else {
slice = *maybePinnedNotice.(*[]*PinnedNotice)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &pinnedNoticeR{}
}
args = append(args, object.NoticeID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &pinnedNoticeR{}
}
for _, a := range args {
if a == obj.NoticeID {
continue Outer
}
}
args = append(args, obj.NoticeID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`notices`),
qm.WhereIn(`notices.id in ?`, args...),
)
if mods != nil {
mods.Apply(query)
}
results, err := query.QueryContext(ctx, e)
if err != nil {
return errors.Wrap(err, "failed to eager load Notice")
}
var resultSlice []*Notice
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Notice")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for notices")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for notices")
}
if len(pinnedNoticeAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Notice = foreign
if foreign.R == nil {
foreign.R = &noticeR{}
}
foreign.R.PinnedNotice = object
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.NoticeID == foreign.ID {
local.R.Notice = foreign
if foreign.R == nil {
foreign.R = &noticeR{}
}
foreign.R.PinnedNotice = local
break
}
}
}
return nil
}
// SetNotice of the pinnedNotice to the related item.
// Sets o.R.Notice to related.
// Adds o to related.R.PinnedNotice.
func (o *PinnedNotice) SetNotice(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Notice) 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 \"pinned_notices\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"notice_id"}),
strmangle.WhereClause("\"", "\"", 0, pinnedNoticePrimaryKeyColumns),
)
values := []interface{}{related.ID, o.Name, o.Language}
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.NoticeID = related.ID
if o.R == nil {
o.R = &pinnedNoticeR{
Notice: related,
}
} else {
o.R.Notice = related
}
if related.R == nil {
related.R = &noticeR{
PinnedNotice: o,
}
} else {
related.R.PinnedNotice = o
}
return nil
}
// PinnedNotices retrieves all the records using an executor.
func PinnedNotices(mods ...qm.QueryMod) pinnedNoticeQuery {
mods = append(mods, qm.From("\"pinned_notices\""))
return pinnedNoticeQuery{NewQuery(mods...)}
}
// FindPinnedNotice retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindPinnedNotice(ctx context.Context, exec boil.ContextExecutor, name string, language string, selectCols ...string) (*PinnedNotice, error) {
pinnedNoticeObj := &PinnedNotice{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"pinned_notices\" where \"name\"=? AND \"language\"=?", sel,
)
q := queries.Raw(query, name, language)
err := q.Bind(ctx, exec, pinnedNoticeObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from pinned_notices")
}
return pinnedNoticeObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *PinnedNotice) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("models: no pinned_notices provided for insertion")
}
var err error
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(pinnedNoticeColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
pinnedNoticeInsertCacheMut.RLock()
cache, cached := pinnedNoticeInsertCache[key]
pinnedNoticeInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
pinnedNoticeAllColumns,
pinnedNoticeColumnsWithDefault,
pinnedNoticeColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(pinnedNoticeType, pinnedNoticeMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(pinnedNoticeType, pinnedNoticeMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"pinned_notices\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"pinned_notices\" %sDEFAULT VALUES%s"
}
var queryOutput, queryReturning string
if len(cache.retMapping) != 0 {
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"pinned_notices\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, pinnedNoticePrimaryKeyColumns))
}
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)
}
_, err = exec.ExecContext(ctx, cache.query, vals...)
if err != nil {
return errors.Wrap(err, "models: unable to insert into pinned_notices")
}
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.Name,
o.Language,
}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, cache.retQuery)
fmt.Fprintln(writer, identifierCols...)
}
err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
if err != nil {
return errors.Wrap(err, "models: unable to populate default values for pinned_notices")
}
CacheNoHooks:
if !cached {
pinnedNoticeInsertCacheMut.Lock()
pinnedNoticeInsertCache[key] = cache
pinnedNoticeInsertCacheMut.Unlock()
}
return o.doAfterInsertHooks(ctx, exec)
}
// Update uses an executor to update the PinnedNotice.
// 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 *PinnedNotice) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
return 0, err
}
key := makeCacheKey(columns, nil)
pinnedNoticeUpdateCacheMut.RLock()
cache, cached := pinnedNoticeUpdateCache[key]
pinnedNoticeUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
pinnedNoticeAllColumns,
pinnedNoticePrimaryKeyColumns,
)
if !columns.IsWhitelist() {
wl = strmangle.SetComplement(wl, []string{"created_at"})
}
if len(wl) == 0 {
return 0, errors.New("models: unable to update pinned_notices, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"pinned_notices\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, pinnedNoticePrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(pinnedNoticeType, pinnedNoticeMapping, append(wl, pinnedNoticePrimaryKeyColumns...))
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 pinned_notices row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by update for pinned_notices")
}
if !cached {
pinnedNoticeUpdateCacheMut.Lock()
pinnedNoticeUpdateCache[key] = cache
pinnedNoticeUpdateCacheMut.Unlock()
}
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
}
// UpdateAll updates all rows with the specified column values.
func (q pinnedNoticeQuery) 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 pinned_notices")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for pinned_notices")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o PinnedNoticeSlice) 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)), pinnedNoticePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"pinned_notices\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, pinnedNoticePrimaryKeyColumns, 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 pinnedNotice slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all pinnedNotice")
}
return rowsAff, nil
}
// Delete deletes a single PinnedNotice record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *PinnedNotice) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("models: no PinnedNotice provided for delete")
}
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
return 0, err
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), pinnedNoticePrimaryKeyMapping)
sql := "DELETE FROM \"pinned_notices\" WHERE \"name\"=? AND \"language\"=?"
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 pinned_notices")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for pinned_notices")
}
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
return 0, err
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q pinnedNoticeQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("models: no pinnedNoticeQuery 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 pinned_notices")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for pinned_notices")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o PinnedNoticeSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if len(o) == 0 {
return 0, nil
}
if len(pinnedNoticeBeforeDeleteHooks) != 0 {
for _, obj := range o {
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
return 0, err
}
}
}
var args []interface{}
for _, obj := range o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), pinnedNoticePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"pinned_notices\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, pinnedNoticePrimaryKeyColumns, 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 pinnedNotice slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for pinned_notices")
}
if len(pinnedNoticeAfterDeleteHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
return 0, err
}
}
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *PinnedNotice) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindPinnedNotice(ctx, exec, o.Name, o.Language)
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 *PinnedNoticeSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := PinnedNoticeSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), pinnedNoticePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"pinned_notices\".* FROM \"pinned_notices\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, pinnedNoticePrimaryKeyColumns, 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 PinnedNoticeSlice")
}
*o = slice
return nil
}
// PinnedNoticeExists checks if the PinnedNotice row exists.
func PinnedNoticeExists(ctx context.Context, exec boil.ContextExecutor, name string, language string) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"pinned_notices\" where \"name\"=? AND \"language\"=? limit 1)"
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, sql)
fmt.Fprintln(writer, name, language)
}
row := exec.QueryRowContext(ctx, sql, name, language)
err := row.Scan(&exists)
if err != nil {
return false, errors.Wrap(err, "models: unable to check if pinned_notices exists")
}
return exists, nil
}