go-ssb-room/roomdb/sqlite/models/notices.go

1071 lines
28 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"
)
// Notice is an object representing the database table.
type Notice struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
Title string `boil:"title" json:"title" toml:"title" yaml:"title"`
Content string `boil:"content" json:"content" toml:"content" yaml:"content"`
Language string `boil:"language" json:"language" toml:"language" yaml:"language"`
R *noticeR `boil:"-" json:"-" toml:"-" yaml:"-"`
L noticeL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var NoticeColumns = struct {
ID string
Title string
Content string
Language string
}{
ID: "id",
Title: "title",
Content: "content",
Language: "language",
}
// Generated where
var NoticeWhere = struct {
ID whereHelperint64
Title whereHelperstring
Content whereHelperstring
Language whereHelperstring
}{
ID: whereHelperint64{field: "\"notices\".\"id\""},
Title: whereHelperstring{field: "\"notices\".\"title\""},
Content: whereHelperstring{field: "\"notices\".\"content\""},
Language: whereHelperstring{field: "\"notices\".\"language\""},
}
// NoticeRels is where relationship names are stored.
var NoticeRels = struct {
Pins string
}{
Pins: "Pins",
}
// noticeR is where relationships are stored.
type noticeR struct {
Pins PinSlice `boil:"Pins" json:"Pins" toml:"Pins" yaml:"Pins"`
}
// NewStruct creates a new relationship struct
func (*noticeR) NewStruct() *noticeR {
return &noticeR{}
}
// noticeL is where Load methods for each relationship are stored.
type noticeL struct{}
var (
noticeAllColumns = []string{"id", "title", "content", "language"}
noticeColumnsWithoutDefault = []string{}
noticeColumnsWithDefault = []string{"id", "title", "content", "language"}
noticePrimaryKeyColumns = []string{"id"}
)
type (
// NoticeSlice is an alias for a slice of pointers to Notice.
// This should generally be used opposed to []Notice.
NoticeSlice []*Notice
// NoticeHook is the signature for custom Notice hook methods
NoticeHook func(context.Context, boil.ContextExecutor, *Notice) error
noticeQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
noticeType = reflect.TypeOf(&Notice{})
noticeMapping = queries.MakeStructMapping(noticeType)
noticePrimaryKeyMapping, _ = queries.BindMapping(noticeType, noticeMapping, noticePrimaryKeyColumns)
noticeInsertCacheMut sync.RWMutex
noticeInsertCache = make(map[string]insertCache)
noticeUpdateCacheMut sync.RWMutex
noticeUpdateCache = make(map[string]updateCache)
noticeUpsertCacheMut sync.RWMutex
noticeUpsertCache = 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 noticeBeforeInsertHooks []NoticeHook
var noticeBeforeUpdateHooks []NoticeHook
var noticeBeforeDeleteHooks []NoticeHook
var noticeBeforeUpsertHooks []NoticeHook
var noticeAfterInsertHooks []NoticeHook
var noticeAfterSelectHooks []NoticeHook
var noticeAfterUpdateHooks []NoticeHook
var noticeAfterDeleteHooks []NoticeHook
var noticeAfterUpsertHooks []NoticeHook
// doBeforeInsertHooks executes all "before insert" hooks.
func (o *Notice) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeBeforeInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpdateHooks executes all "before Update" hooks.
func (o *Notice) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeBeforeUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeDeleteHooks executes all "before Delete" hooks.
func (o *Notice) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeBeforeDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *Notice) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeBeforeUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterInsertHooks executes all "after Insert" hooks.
func (o *Notice) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeAfterInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterSelectHooks executes all "after Select" hooks.
func (o *Notice) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeAfterSelectHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpdateHooks executes all "after Update" hooks.
func (o *Notice) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeAfterUpdateHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterDeleteHooks executes all "after Delete" hooks.
func (o *Notice) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeAfterDeleteHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *Notice) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range noticeAfterUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// AddNoticeHook registers your hook function for all future operations.
func AddNoticeHook(hookPoint boil.HookPoint, noticeHook NoticeHook) {
switch hookPoint {
case boil.BeforeInsertHook:
noticeBeforeInsertHooks = append(noticeBeforeInsertHooks, noticeHook)
case boil.BeforeUpdateHook:
noticeBeforeUpdateHooks = append(noticeBeforeUpdateHooks, noticeHook)
case boil.BeforeDeleteHook:
noticeBeforeDeleteHooks = append(noticeBeforeDeleteHooks, noticeHook)
case boil.BeforeUpsertHook:
noticeBeforeUpsertHooks = append(noticeBeforeUpsertHooks, noticeHook)
case boil.AfterInsertHook:
noticeAfterInsertHooks = append(noticeAfterInsertHooks, noticeHook)
case boil.AfterSelectHook:
noticeAfterSelectHooks = append(noticeAfterSelectHooks, noticeHook)
case boil.AfterUpdateHook:
noticeAfterUpdateHooks = append(noticeAfterUpdateHooks, noticeHook)
case boil.AfterDeleteHook:
noticeAfterDeleteHooks = append(noticeAfterDeleteHooks, noticeHook)
case boil.AfterUpsertHook:
noticeAfterUpsertHooks = append(noticeAfterUpsertHooks, noticeHook)
}
}
// One returns a single notice record from the query.
func (q noticeQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Notice, error) {
o := &Notice{}
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 notices")
}
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
return o, nil
}
// All returns all Notice records from the query.
func (q noticeQuery) All(ctx context.Context, exec boil.ContextExecutor) (NoticeSlice, error) {
var o []*Notice
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to Notice slice")
}
if len(noticeAfterSelectHooks) != 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 Notice records in the query.
func (q noticeQuery) 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 notices rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q noticeQuery) 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 notices exists")
}
return count > 0, nil
}
// Pins retrieves all the pin's Pins with an executor.
func (o *Notice) Pins(mods ...qm.QueryMod) pinQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.InnerJoin("\"pin_notices\" on \"pins\".\"id\" = \"pin_notices\".\"pin_id\""),
qm.Where("\"pin_notices\".\"notice_id\"=?", o.ID),
)
query := Pins(queryMods...)
queries.SetFrom(query.Query, "\"pins\"")
if len(queries.GetSelect(query.Query)) == 0 {
queries.SetSelect(query.Query, []string{"\"pins\".*"})
}
return query
}
// LoadPins allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for a 1-M or N-M relationship.
func (noticeL) LoadPins(ctx context.Context, e boil.ContextExecutor, singular bool, maybeNotice interface{}, mods queries.Applicator) error {
var slice []*Notice
var object *Notice
if singular {
object = maybeNotice.(*Notice)
} else {
slice = *maybeNotice.(*[]*Notice)
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &noticeR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &noticeR{}
}
for _, a := range args {
if a == obj.ID {
continue Outer
}
}
args = append(args, obj.ID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.Select("\"pins\".id, \"pins\".name, \"a\".\"notice_id\""),
qm.From("\"pins\""),
qm.InnerJoin("\"pin_notices\" as \"a\" on \"pins\".\"id\" = \"a\".\"pin_id\""),
qm.WhereIn("\"a\".\"notice_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 pins")
}
var resultSlice []*Pin
var localJoinCols []int64
for results.Next() {
one := new(Pin)
var localJoinCol int64
err = results.Scan(&one.ID, &one.Name, &localJoinCol)
if err != nil {
return errors.Wrap(err, "failed to scan eager loaded results for pins")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "failed to plebian-bind eager loaded slice pins")
}
resultSlice = append(resultSlice, one)
localJoinCols = append(localJoinCols, localJoinCol)
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on pins")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for pins")
}
if len(pinAfterSelectHooks) != 0 {
for _, obj := range resultSlice {
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
return err
}
}
}
if singular {
object.R.Pins = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &pinR{}
}
foreign.R.Notices = append(foreign.R.Notices, object)
}
return nil
}
for i, foreign := range resultSlice {
localJoinCol := localJoinCols[i]
for _, local := range slice {
if local.ID == localJoinCol {
local.R.Pins = append(local.R.Pins, foreign)
if foreign.R == nil {
foreign.R = &pinR{}
}
foreign.R.Notices = append(foreign.R.Notices, local)
break
}
}
}
return nil
}
// AddPins adds the given related objects to the existing relationships
// of the notice, optionally inserting them as new records.
// Appends related to o.R.Pins.
// Sets related.R.Notices appropriately.
func (o *Notice) AddPins(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Pin) error {
var err error
for _, rel := range related {
if insert {
if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
}
}
for _, rel := range related {
query := "insert into \"pin_notices\" (\"notice_id\", \"pin_id\") values (?, ?)"
values := []interface{}{o.ID, rel.ID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, query)
fmt.Fprintln(writer, values)
}
_, err = exec.ExecContext(ctx, query, values...)
if err != nil {
return errors.Wrap(err, "failed to insert into join table")
}
}
if o.R == nil {
o.R = &noticeR{
Pins: related,
}
} else {
o.R.Pins = append(o.R.Pins, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &pinR{
Notices: NoticeSlice{o},
}
} else {
rel.R.Notices = append(rel.R.Notices, o)
}
}
return nil
}
// SetPins removes all previously related items of the
// notice replacing them completely with the passed
// in related items, optionally inserting them as new records.
// Sets o.R.Notices's Pins accordingly.
// Replaces o.R.Pins with related.
// Sets related.R.Notices's Pins accordingly.
func (o *Notice) SetPins(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Pin) error {
query := "delete from \"pin_notices\" where \"notice_id\" = ?"
values := []interface{}{o.ID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, query)
fmt.Fprintln(writer, values)
}
_, err := exec.ExecContext(ctx, query, values...)
if err != nil {
return errors.Wrap(err, "failed to remove relationships before set")
}
removePinsFromNoticesSlice(o, related)
if o.R != nil {
o.R.Pins = nil
}
return o.AddPins(ctx, exec, insert, related...)
}
// RemovePins relationships from objects passed in.
// Removes related items from R.Pins (uses pointer comparison, removal does not keep order)
// Sets related.R.Notices.
func (o *Notice) RemovePins(ctx context.Context, exec boil.ContextExecutor, related ...*Pin) error {
var err error
query := fmt.Sprintf(
"delete from \"pin_notices\" where \"notice_id\" = ? and \"pin_id\" in (%s)",
strmangle.Placeholders(dialect.UseIndexPlaceholders, len(related), 2, 1),
)
values := []interface{}{o.ID}
for _, rel := range related {
values = append(values, rel.ID)
}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, query)
fmt.Fprintln(writer, values)
}
_, err = exec.ExecContext(ctx, query, values...)
if err != nil {
return errors.Wrap(err, "failed to remove relationships before set")
}
removePinsFromNoticesSlice(o, related)
if o.R == nil {
return nil
}
for _, rel := range related {
for i, ri := range o.R.Pins {
if rel != ri {
continue
}
ln := len(o.R.Pins)
if ln > 1 && i < ln-1 {
o.R.Pins[i] = o.R.Pins[ln-1]
}
o.R.Pins = o.R.Pins[:ln-1]
break
}
}
return nil
}
func removePinsFromNoticesSlice(o *Notice, related []*Pin) {
for _, rel := range related {
if rel.R == nil {
continue
}
for i, ri := range rel.R.Notices {
if o.ID != ri.ID {
continue
}
ln := len(rel.R.Notices)
if ln > 1 && i < ln-1 {
rel.R.Notices[i] = rel.R.Notices[ln-1]
}
rel.R.Notices = rel.R.Notices[:ln-1]
break
}
}
}
// Notices retrieves all the records using an executor.
func Notices(mods ...qm.QueryMod) noticeQuery {
mods = append(mods, qm.From("\"notices\""))
return noticeQuery{NewQuery(mods...)}
}
// FindNotice retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindNotice(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*Notice, error) {
noticeObj := &Notice{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"notices\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, noticeObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from notices")
}
return noticeObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *Notice) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("models: no notices provided for insertion")
}
var err error
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(noticeColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
noticeInsertCacheMut.RLock()
cache, cached := noticeInsertCache[key]
noticeInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
noticeAllColumns,
noticeColumnsWithDefault,
noticeColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(noticeType, noticeMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(noticeType, noticeMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"notices\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"notices\" %sDEFAULT VALUES%s"
}
var queryOutput, queryReturning string
if len(cache.retMapping) != 0 {
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"notices\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, noticePrimaryKeyColumns))
}
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)
}
result, err := exec.ExecContext(ctx, cache.query, vals...)
if err != nil {
return errors.Wrap(err, "models: unable to insert into notices")
}
var lastID int64
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
lastID, err = result.LastInsertId()
if err != nil {
return ErrSyncFail
}
o.ID = int64(lastID)
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == noticeMapping["id"] {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.ID,
}
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 notices")
}
CacheNoHooks:
if !cached {
noticeInsertCacheMut.Lock()
noticeInsertCache[key] = cache
noticeInsertCacheMut.Unlock()
}
return o.doAfterInsertHooks(ctx, exec)
}
// Update uses an executor to update the Notice.
// 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 *Notice) 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)
noticeUpdateCacheMut.RLock()
cache, cached := noticeUpdateCache[key]
noticeUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
noticeAllColumns,
noticePrimaryKeyColumns,
)
if !columns.IsWhitelist() {
wl = strmangle.SetComplement(wl, []string{"created_at"})
}
if len(wl) == 0 {
return 0, errors.New("models: unable to update notices, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"notices\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, noticePrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(noticeType, noticeMapping, append(wl, noticePrimaryKeyColumns...))
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 notices row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by update for notices")
}
if !cached {
noticeUpdateCacheMut.Lock()
noticeUpdateCache[key] = cache
noticeUpdateCacheMut.Unlock()
}
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
}
// UpdateAll updates all rows with the specified column values.
func (q noticeQuery) 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 notices")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected for notices")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o NoticeSlice) 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)), noticePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"notices\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, noticePrimaryKeyColumns, 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 notice slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all notice")
}
return rowsAff, nil
}
// Delete deletes a single Notice record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *Notice) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("models: no Notice provided for delete")
}
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
return 0, err
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), noticePrimaryKeyMapping)
sql := "DELETE FROM \"notices\" WHERE \"id\"=?"
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 notices")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by delete for notices")
}
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
return 0, err
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q noticeQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("models: no noticeQuery 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 notices")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for notices")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o NoticeSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if len(o) == 0 {
return 0, nil
}
if len(noticeBeforeDeleteHooks) != 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)), noticePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"notices\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, noticePrimaryKeyColumns, 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 notice slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for notices")
}
if len(noticeAfterDeleteHooks) != 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 *Notice) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindNotice(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 *NoticeSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := NoticeSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), noticePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"notices\".* FROM \"notices\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, noticePrimaryKeyColumns, 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 NoticeSlice")
}
*o = slice
return nil
}
// NoticeExists checks if the Notice row exists.
func NoticeExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"notices\" where \"id\"=? 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 notices exists")
}
return exists, nil
}