960 lines
25 KiB
Go
960 lines
25 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 {
|
|
PinnedNotice string
|
|
}{
|
|
PinnedNotice: "PinnedNotice",
|
|
}
|
|
|
|
// noticeR is where relationships are stored.
|
|
type noticeR struct {
|
|
PinnedNotice *PinnedNotice `boil:"PinnedNotice" json:"PinnedNotice" toml:"PinnedNotice" yaml:"PinnedNotice"`
|
|
}
|
|
|
|
// NewStruct creates a new relationship struct
|
|
func (*noticeR) NewStruct() *noticeR {
|
|
return ¬iceR{}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// PinnedNotice pointed to by the foreign key.
|
|
func (o *Notice) PinnedNotice(mods ...qm.QueryMod) pinnedNoticeQuery {
|
|
queryMods := []qm.QueryMod{
|
|
qm.Where("\"notice_id\" = ?", o.ID),
|
|
}
|
|
|
|
queryMods = append(queryMods, mods...)
|
|
|
|
query := PinnedNotices(queryMods...)
|
|
queries.SetFrom(query.Query, "\"pinned_notices\"")
|
|
|
|
return query
|
|
}
|
|
|
|
// LoadPinnedNotice allows an eager lookup of values, cached into the
|
|
// loaded structs of the objects. This is for a 1-1 relationship.
|
|
func (noticeL) LoadPinnedNotice(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 = ¬iceR{}
|
|
}
|
|
args = append(args, object.ID)
|
|
} else {
|
|
Outer:
|
|
for _, obj := range slice {
|
|
if obj.R == nil {
|
|
obj.R = ¬iceR{}
|
|
}
|
|
|
|
for _, a := range args {
|
|
if a == obj.ID {
|
|
continue Outer
|
|
}
|
|
}
|
|
|
|
args = append(args, obj.ID)
|
|
}
|
|
}
|
|
|
|
if len(args) == 0 {
|
|
return nil
|
|
}
|
|
|
|
query := NewQuery(
|
|
qm.From(`pinned_notices`),
|
|
qm.WhereIn(`pinned_notices.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 PinnedNotice")
|
|
}
|
|
|
|
var resultSlice []*PinnedNotice
|
|
if err = queries.Bind(results, &resultSlice); err != nil {
|
|
return errors.Wrap(err, "failed to bind eager loaded slice PinnedNotice")
|
|
}
|
|
|
|
if err = results.Close(); err != nil {
|
|
return errors.Wrap(err, "failed to close results of eager load for pinned_notices")
|
|
}
|
|
if err = results.Err(); err != nil {
|
|
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for pinned_notices")
|
|
}
|
|
|
|
if len(noticeAfterSelectHooks) != 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.PinnedNotice = foreign
|
|
if foreign.R == nil {
|
|
foreign.R = &pinnedNoticeR{}
|
|
}
|
|
foreign.R.Notice = object
|
|
}
|
|
|
|
for _, local := range slice {
|
|
for _, foreign := range resultSlice {
|
|
if local.ID == foreign.NoticeID {
|
|
local.R.PinnedNotice = foreign
|
|
if foreign.R == nil {
|
|
foreign.R = &pinnedNoticeR{}
|
|
}
|
|
foreign.R.Notice = local
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// SetPinnedNotice of the notice to the related item.
|
|
// Sets o.R.PinnedNotice to related.
|
|
// Adds o to related.R.Notice.
|
|
func (o *Notice) SetPinnedNotice(ctx context.Context, exec boil.ContextExecutor, insert bool, related *PinnedNotice) error {
|
|
var err error
|
|
|
|
if insert {
|
|
related.NoticeID = o.ID
|
|
|
|
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
|
return errors.Wrap(err, "failed to insert into foreign table")
|
|
}
|
|
} else {
|
|
updateQuery := fmt.Sprintf(
|
|
"UPDATE \"pinned_notices\" SET %s WHERE %s",
|
|
strmangle.SetParamNames("\"", "\"", 0, []string{"notice_id"}),
|
|
strmangle.WhereClause("\"", "\"", 0, pinnedNoticePrimaryKeyColumns),
|
|
)
|
|
values := []interface{}{o.ID, related.Name, related.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 foreign table")
|
|
}
|
|
|
|
related.NoticeID = o.ID
|
|
|
|
}
|
|
|
|
if o.R == nil {
|
|
o.R = ¬iceR{
|
|
PinnedNotice: related,
|
|
}
|
|
} else {
|
|
o.R.PinnedNotice = related
|
|
}
|
|
|
|
if related.R == nil {
|
|
related.R = &pinnedNoticeR{
|
|
Notice: o,
|
|
}
|
|
} else {
|
|
related.R.Notice = o
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 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
|
|
}
|