desktop/backend/model/tag_attributes.go
// Code generated by SQLBoiler 4.15.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 model
import (
"context"
"database/sql"
"fmt"
"reflect"
"strconv"
"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"
)
// TagAttribute is an object representing the database table.
type TagAttribute struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
TagID int64 `boil:"tag_id" json:"tag_id" toml:"tag_id" yaml:"tag_id"`
Name string `boil:"name" json:"name" toml:"name" yaml:"name"`
Value string `boil:"value" json:"value" toml:"value" yaml:"value"`
R *tagAttributeR `boil:"-" json:"-" toml:"-" yaml:"-"`
L tagAttributeL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var TagAttributeColumns = struct {
ID string
TagID string
Name string
Value string
}{
ID: "id",
TagID: "tag_id",
Name: "name",
Value: "value",
}
var TagAttributeTableColumns = struct {
ID string
TagID string
Name string
Value string
}{
ID: "tag_attributes.id",
TagID: "tag_attributes.tag_id",
Name: "tag_attributes.name",
Value: "tag_attributes.value",
}
// Generated where
var TagAttributeWhere = struct {
ID whereHelperint64
TagID whereHelperint64
Name whereHelperstring
Value whereHelperstring
}{
ID: whereHelperint64{field: "\"tag_attributes\".\"id\""},
TagID: whereHelperint64{field: "\"tag_attributes\".\"tag_id\""},
Name: whereHelperstring{field: "\"tag_attributes\".\"name\""},
Value: whereHelperstring{field: "\"tag_attributes\".\"value\""},
}
// TagAttributeRels is where relationship names are stored.
var TagAttributeRels = struct {
Tag string
}{
Tag: "Tag",
}
// tagAttributeR is where relationships are stored.
type tagAttributeR struct {
Tag *Tag `boil:"Tag" json:"Tag" toml:"Tag" yaml:"Tag"`
}
// NewStruct creates a new relationship struct
func (*tagAttributeR) NewStruct() *tagAttributeR {
return &tagAttributeR{}
}
func (r *tagAttributeR) GetTag() *Tag {
if r == nil {
return nil
}
return r.Tag
}
// tagAttributeL is where Load methods for each relationship are stored.
type tagAttributeL struct{}
var (
tagAttributeAllColumns = []string{"id", "tag_id", "name", "value"}
tagAttributeColumnsWithoutDefault = []string{"tag_id", "name", "value"}
tagAttributeColumnsWithDefault = []string{"id"}
tagAttributePrimaryKeyColumns = []string{"id"}
tagAttributeGeneratedColumns = []string{"id"}
)
type (
// TagAttributeSlice is an alias for a slice of pointers to TagAttribute.
// This should almost always be used instead of []TagAttribute.
TagAttributeSlice []*TagAttribute
tagAttributeQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
tagAttributeType = reflect.TypeOf(&TagAttribute{})
tagAttributeMapping = queries.MakeStructMapping(tagAttributeType)
tagAttributePrimaryKeyMapping, _ = queries.BindMapping(tagAttributeType, tagAttributeMapping, tagAttributePrimaryKeyColumns)
tagAttributeInsertCacheMut sync.RWMutex
tagAttributeInsertCache = make(map[string]insertCache)
tagAttributeUpdateCacheMut sync.RWMutex
tagAttributeUpdateCache = make(map[string]updateCache)
tagAttributeUpsertCacheMut sync.RWMutex
tagAttributeUpsertCache = 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 tagAttribute record from the query.
func (q tagAttributeQuery) One(ctx context.Context, exec boil.ContextExecutor) (*TagAttribute, error) {
o := &TagAttribute{}
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, "model: failed to execute a one query for tag_attributes")
}
return o, nil
}
// All returns all TagAttribute records from the query.
func (q tagAttributeQuery) All(ctx context.Context, exec boil.ContextExecutor) (TagAttributeSlice, error) {
var o []*TagAttribute
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "model: failed to assign all query results to TagAttribute slice")
}
return o, nil
}
// Count returns the count of all TagAttribute records in the query.
func (q tagAttributeQuery) 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, "model: failed to count tag_attributes rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q tagAttributeQuery) 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, "model: failed to check if tag_attributes exists")
}
return count > 0, nil
}
// Tag pointed to by the foreign key.
func (o *TagAttribute) Tag(mods ...qm.QueryMod) tagQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.TagID),
}
queryMods = append(queryMods, mods...)
return Tags(queryMods...)
}
// LoadTag allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (tagAttributeL) LoadTag(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTagAttribute interface{}, mods queries.Applicator) error {
var slice []*TagAttribute
var object *TagAttribute
if singular {
var ok bool
object, ok = maybeTagAttribute.(*TagAttribute)
if !ok {
object = new(TagAttribute)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTagAttribute)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTagAttribute))
}
}
} else {
s, ok := maybeTagAttribute.(*[]*TagAttribute)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTagAttribute)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTagAttribute))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &tagAttributeR{}
}
args = append(args, object.TagID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &tagAttributeR{}
}
for _, a := range args {
if a == obj.TagID {
continue Outer
}
}
args = append(args, obj.TagID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`tag`),
qm.WhereIn(`tag.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 Tag")
}
var resultSlice []*Tag
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Tag")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for tag")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for tag")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Tag = foreign
if foreign.R == nil {
foreign.R = &tagR{}
}
foreign.R.TagAttributes = append(foreign.R.TagAttributes, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.TagID == foreign.ID {
local.R.Tag = foreign
if foreign.R == nil {
foreign.R = &tagR{}
}
foreign.R.TagAttributes = append(foreign.R.TagAttributes, local)
break
}
}
}
return nil
}
// SetTag of the tagAttribute to the related item.
// Sets o.R.Tag to related.
// Adds o to related.R.TagAttributes.
func (o *TagAttribute) SetTag(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Tag) 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 \"tag_attributes\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"tag_id"}),
strmangle.WhereClause("\"", "\"", 0, tagAttributePrimaryKeyColumns),
)
values := []interface{}{related.ID, o.ID}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, updateQuery)
fmt.Fprintln(writer, values)
}
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
return errors.Wrap(err, "failed to update local table")
}
o.TagID = related.ID
if o.R == nil {
o.R = &tagAttributeR{
Tag: related,
}
} else {
o.R.Tag = related
}
if related.R == nil {
related.R = &tagR{
TagAttributes: TagAttributeSlice{o},
}
} else {
related.R.TagAttributes = append(related.R.TagAttributes, o)
}
return nil
}
// TagAttributes retrieves all the records using an executor.
func TagAttributes(mods ...qm.QueryMod) tagAttributeQuery {
mods = append(mods, qm.From("\"tag_attributes\""))
q := NewQuery(mods...)
if len(queries.GetSelect(q)) == 0 {
queries.SetSelect(q, []string{"\"tag_attributes\".*"})
}
return tagAttributeQuery{q}
}
// FindTagAttribute retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindTagAttribute(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*TagAttribute, error) {
tagAttributeObj := &TagAttribute{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"tag_attributes\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, tagAttributeObj)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "model: unable to select from tag_attributes")
}
return tagAttributeObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *TagAttribute) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("model: no tag_attributes provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(tagAttributeColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
tagAttributeInsertCacheMut.RLock()
cache, cached := tagAttributeInsertCache[key]
tagAttributeInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
tagAttributeAllColumns,
tagAttributeColumnsWithDefault,
tagAttributeColumnsWithoutDefault,
nzDefaults,
)
wl = strmangle.SetComplement(wl, tagAttributeGeneratedColumns)
cache.valueMapping, err = queries.BindMapping(tagAttributeType, tagAttributeMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(tagAttributeType, tagAttributeMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"tag_attributes\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"tag_attributes\" %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, "model: unable to insert into tag_attributes")
}
if !cached {
tagAttributeInsertCacheMut.Lock()
tagAttributeInsertCache[key] = cache
tagAttributeInsertCacheMut.Unlock()
}
return nil
}
// Update uses an executor to update the TagAttribute.
// 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 *TagAttribute) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
tagAttributeUpdateCacheMut.RLock()
cache, cached := tagAttributeUpdateCache[key]
tagAttributeUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
tagAttributeAllColumns,
tagAttributePrimaryKeyColumns,
)
wl = strmangle.SetComplement(wl, tagAttributeGeneratedColumns)
if len(wl) == 0 {
return 0, errors.New("model: unable to update tag_attributes, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"tag_attributes\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, tagAttributePrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(tagAttributeType, tagAttributeMapping, append(wl, tagAttributePrimaryKeyColumns...))
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, "model: unable to update tag_attributes row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by update for tag_attributes")
}
if !cached {
tagAttributeUpdateCacheMut.Lock()
tagAttributeUpdateCache[key] = cache
tagAttributeUpdateCacheMut.Unlock()
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values.
func (q tagAttributeQuery) 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, "model: unable to update all for tag_attributes")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected for tag_attributes")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o TagAttributeSlice) 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("model: 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)), tagAttributePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"tag_attributes\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, tagAttributePrimaryKeyColumns, 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, "model: unable to update all in tagAttribute slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected all in update all tagAttribute")
}
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 *TagAttribute) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("model: no tag_attributes provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(tagAttributeColumnsWithDefault, 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)
tagAttributeUpsertCacheMut.RLock()
cache, cached := tagAttributeUpsertCache[key]
tagAttributeUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
tagAttributeAllColumns,
tagAttributeColumnsWithDefault,
tagAttributeColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
tagAttributeAllColumns,
tagAttributePrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("model: unable to upsert tag_attributes, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(tagAttributePrimaryKeyColumns))
copy(conflict, tagAttributePrimaryKeyColumns)
}
cache.query = buildUpsertQuerySQLite(dialect, "\"tag_attributes\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(tagAttributeType, tagAttributeMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(tagAttributeType, tagAttributeMapping, 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, "model: unable to upsert tag_attributes")
}
if !cached {
tagAttributeUpsertCacheMut.Lock()
tagAttributeUpsertCache[key] = cache
tagAttributeUpsertCacheMut.Unlock()
}
return nil
}
// Delete deletes a single TagAttribute record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *TagAttribute) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("model: no TagAttribute provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), tagAttributePrimaryKeyMapping)
sql := "DELETE FROM \"tag_attributes\" 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, "model: unable to delete from tag_attributes")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by delete for tag_attributes")
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q tagAttributeQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("model: no tagAttributeQuery provided for delete all")
}
queries.SetDelete(q.Query)
result, err := q.Query.ExecContext(ctx, exec)
if err != nil {
return 0, errors.Wrap(err, "model: unable to delete all from tag_attributes")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for tag_attributes")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o TagAttributeSlice) 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)), tagAttributePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"tag_attributes\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, tagAttributePrimaryKeyColumns, 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, "model: unable to delete all from tagAttribute slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for tag_attributes")
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *TagAttribute) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindTagAttribute(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 *TagAttributeSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := TagAttributeSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), tagAttributePrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"tag_attributes\".* FROM \"tag_attributes\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, tagAttributePrimaryKeyColumns, len(*o))
q := queries.Raw(sql, args...)
err := q.Bind(ctx, exec, &slice)
if err != nil {
return errors.Wrap(err, "model: unable to reload all in TagAttributeSlice")
}
*o = slice
return nil
}
// TagAttributeExists checks if the TagAttribute row exists.
func TagAttributeExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"tag_attributes\" 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, "model: unable to check if tag_attributes exists")
}
return exists, nil
}
// Exists checks if the TagAttribute row exists.
func (o *TagAttribute) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
return TagAttributeExists(ctx, exec, o.ID)
}