desktop/backend/model/account_entity.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"
)
// AccountEntity is an object representing the database table.
type AccountEntity struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
AccountID int64 `boil:"account_id" json:"account_id" toml:"account_id" yaml:"account_id"`
EntityID int64 `boil:"entity_id" json:"entity_id" toml:"entity_id" yaml:"entity_id"`
R *accountEntityR `boil:"-" json:"-" toml:"-" yaml:"-"`
L accountEntityL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var AccountEntityColumns = struct {
ID string
AccountID string
EntityID string
}{
ID: "id",
AccountID: "account_id",
EntityID: "entity_id",
}
var AccountEntityTableColumns = struct {
ID string
AccountID string
EntityID string
}{
ID: "account_entity.id",
AccountID: "account_entity.account_id",
EntityID: "account_entity.entity_id",
}
// Generated where
var AccountEntityWhere = struct {
ID whereHelperint64
AccountID whereHelperint64
EntityID whereHelperint64
}{
ID: whereHelperint64{field: "\"account_entity\".\"id\""},
AccountID: whereHelperint64{field: "\"account_entity\".\"account_id\""},
EntityID: whereHelperint64{field: "\"account_entity\".\"entity_id\""},
}
// AccountEntityRels is where relationship names are stored.
var AccountEntityRels = struct {
Entity string
Account string
}{
Entity: "Entity",
Account: "Account",
}
// accountEntityR is where relationships are stored.
type accountEntityR struct {
Entity *Entity `boil:"Entity" json:"Entity" toml:"Entity" yaml:"Entity"`
Account *Account `boil:"Account" json:"Account" toml:"Account" yaml:"Account"`
}
// NewStruct creates a new relationship struct
func (*accountEntityR) NewStruct() *accountEntityR {
return &accountEntityR{}
}
func (r *accountEntityR) GetEntity() *Entity {
if r == nil {
return nil
}
return r.Entity
}
func (r *accountEntityR) GetAccount() *Account {
if r == nil {
return nil
}
return r.Account
}
// accountEntityL is where Load methods for each relationship are stored.
type accountEntityL struct{}
var (
accountEntityAllColumns = []string{"id", "account_id", "entity_id"}
accountEntityColumnsWithoutDefault = []string{"account_id", "entity_id"}
accountEntityColumnsWithDefault = []string{"id"}
accountEntityPrimaryKeyColumns = []string{"id"}
accountEntityGeneratedColumns = []string{"id"}
)
type (
// AccountEntitySlice is an alias for a slice of pointers to AccountEntity.
// This should almost always be used instead of []AccountEntity.
AccountEntitySlice []*AccountEntity
accountEntityQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
accountEntityType = reflect.TypeOf(&AccountEntity{})
accountEntityMapping = queries.MakeStructMapping(accountEntityType)
accountEntityPrimaryKeyMapping, _ = queries.BindMapping(accountEntityType, accountEntityMapping, accountEntityPrimaryKeyColumns)
accountEntityInsertCacheMut sync.RWMutex
accountEntityInsertCache = make(map[string]insertCache)
accountEntityUpdateCacheMut sync.RWMutex
accountEntityUpdateCache = make(map[string]updateCache)
accountEntityUpsertCacheMut sync.RWMutex
accountEntityUpsertCache = 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 accountEntity record from the query.
func (q accountEntityQuery) One(ctx context.Context, exec boil.ContextExecutor) (*AccountEntity, error) {
o := &AccountEntity{}
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 account_entity")
}
return o, nil
}
// All returns all AccountEntity records from the query.
func (q accountEntityQuery) All(ctx context.Context, exec boil.ContextExecutor) (AccountEntitySlice, error) {
var o []*AccountEntity
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "model: failed to assign all query results to AccountEntity slice")
}
return o, nil
}
// Count returns the count of all AccountEntity records in the query.
func (q accountEntityQuery) 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 account_entity rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q accountEntityQuery) 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 account_entity exists")
}
return count > 0, nil
}
// Entity pointed to by the foreign key.
func (o *AccountEntity) Entity(mods ...qm.QueryMod) entityQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.EntityID),
}
queryMods = append(queryMods, mods...)
return Entities(queryMods...)
}
// Account pointed to by the foreign key.
func (o *AccountEntity) Account(mods ...qm.QueryMod) accountQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.AccountID),
}
queryMods = append(queryMods, mods...)
return Accounts(queryMods...)
}
// LoadEntity allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (accountEntityL) LoadEntity(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccountEntity interface{}, mods queries.Applicator) error {
var slice []*AccountEntity
var object *AccountEntity
if singular {
var ok bool
object, ok = maybeAccountEntity.(*AccountEntity)
if !ok {
object = new(AccountEntity)
ok = queries.SetFromEmbeddedStruct(&object, &maybeAccountEntity)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccountEntity))
}
}
} else {
s, ok := maybeAccountEntity.(*[]*AccountEntity)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeAccountEntity)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccountEntity))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &accountEntityR{}
}
args = append(args, object.EntityID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &accountEntityR{}
}
for _, a := range args {
if a == obj.EntityID {
continue Outer
}
}
args = append(args, obj.EntityID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`entity`),
qm.WhereIn(`entity.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 Entity")
}
var resultSlice []*Entity
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Entity")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for entity")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for entity")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Entity = foreign
if foreign.R == nil {
foreign.R = &entityR{}
}
foreign.R.AccountEntities = append(foreign.R.AccountEntities, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.EntityID == foreign.ID {
local.R.Entity = foreign
if foreign.R == nil {
foreign.R = &entityR{}
}
foreign.R.AccountEntities = append(foreign.R.AccountEntities, local)
break
}
}
}
return nil
}
// LoadAccount allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (accountEntityL) LoadAccount(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccountEntity interface{}, mods queries.Applicator) error {
var slice []*AccountEntity
var object *AccountEntity
if singular {
var ok bool
object, ok = maybeAccountEntity.(*AccountEntity)
if !ok {
object = new(AccountEntity)
ok = queries.SetFromEmbeddedStruct(&object, &maybeAccountEntity)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccountEntity))
}
}
} else {
s, ok := maybeAccountEntity.(*[]*AccountEntity)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeAccountEntity)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccountEntity))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &accountEntityR{}
}
args = append(args, object.AccountID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &accountEntityR{}
}
for _, a := range args {
if a == obj.AccountID {
continue Outer
}
}
args = append(args, obj.AccountID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`account`),
qm.WhereIn(`account.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 Account")
}
var resultSlice []*Account
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Account")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for account")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for account")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Account = foreign
if foreign.R == nil {
foreign.R = &accountR{}
}
foreign.R.AccountEntities = append(foreign.R.AccountEntities, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.AccountID == foreign.ID {
local.R.Account = foreign
if foreign.R == nil {
foreign.R = &accountR{}
}
foreign.R.AccountEntities = append(foreign.R.AccountEntities, local)
break
}
}
}
return nil
}
// SetEntity of the accountEntity to the related item.
// Sets o.R.Entity to related.
// Adds o to related.R.AccountEntities.
func (o *AccountEntity) SetEntity(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Entity) 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 \"account_entity\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"entity_id"}),
strmangle.WhereClause("\"", "\"", 0, accountEntityPrimaryKeyColumns),
)
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.EntityID = related.ID
if o.R == nil {
o.R = &accountEntityR{
Entity: related,
}
} else {
o.R.Entity = related
}
if related.R == nil {
related.R = &entityR{
AccountEntities: AccountEntitySlice{o},
}
} else {
related.R.AccountEntities = append(related.R.AccountEntities, o)
}
return nil
}
// SetAccount of the accountEntity to the related item.
// Sets o.R.Account to related.
// Adds o to related.R.AccountEntities.
func (o *AccountEntity) SetAccount(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Account) 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 \"account_entity\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"account_id"}),
strmangle.WhereClause("\"", "\"", 0, accountEntityPrimaryKeyColumns),
)
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.AccountID = related.ID
if o.R == nil {
o.R = &accountEntityR{
Account: related,
}
} else {
o.R.Account = related
}
if related.R == nil {
related.R = &accountR{
AccountEntities: AccountEntitySlice{o},
}
} else {
related.R.AccountEntities = append(related.R.AccountEntities, o)
}
return nil
}
// AccountEntities retrieves all the records using an executor.
func AccountEntities(mods ...qm.QueryMod) accountEntityQuery {
mods = append(mods, qm.From("\"account_entity\""))
q := NewQuery(mods...)
if len(queries.GetSelect(q)) == 0 {
queries.SetSelect(q, []string{"\"account_entity\".*"})
}
return accountEntityQuery{q}
}
// FindAccountEntity retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindAccountEntity(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*AccountEntity, error) {
accountEntityObj := &AccountEntity{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"account_entity\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, accountEntityObj)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "model: unable to select from account_entity")
}
return accountEntityObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *AccountEntity) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("model: no account_entity provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(accountEntityColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
accountEntityInsertCacheMut.RLock()
cache, cached := accountEntityInsertCache[key]
accountEntityInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
accountEntityAllColumns,
accountEntityColumnsWithDefault,
accountEntityColumnsWithoutDefault,
nzDefaults,
)
wl = strmangle.SetComplement(wl, accountEntityGeneratedColumns)
cache.valueMapping, err = queries.BindMapping(accountEntityType, accountEntityMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(accountEntityType, accountEntityMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"account_entity\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"account_entity\" %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 account_entity")
}
if !cached {
accountEntityInsertCacheMut.Lock()
accountEntityInsertCache[key] = cache
accountEntityInsertCacheMut.Unlock()
}
return nil
}
// Update uses an executor to update the AccountEntity.
// 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 *AccountEntity) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
accountEntityUpdateCacheMut.RLock()
cache, cached := accountEntityUpdateCache[key]
accountEntityUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
accountEntityAllColumns,
accountEntityPrimaryKeyColumns,
)
wl = strmangle.SetComplement(wl, accountEntityGeneratedColumns)
if len(wl) == 0 {
return 0, errors.New("model: unable to update account_entity, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"account_entity\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, accountEntityPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(accountEntityType, accountEntityMapping, append(wl, accountEntityPrimaryKeyColumns...))
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 account_entity row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by update for account_entity")
}
if !cached {
accountEntityUpdateCacheMut.Lock()
accountEntityUpdateCache[key] = cache
accountEntityUpdateCacheMut.Unlock()
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values.
func (q accountEntityQuery) 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 account_entity")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected for account_entity")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o AccountEntitySlice) 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)), accountEntityPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"account_entity\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, accountEntityPrimaryKeyColumns, 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 accountEntity slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected all in update all accountEntity")
}
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 *AccountEntity) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("model: no account_entity provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(accountEntityColumnsWithDefault, 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)
accountEntityUpsertCacheMut.RLock()
cache, cached := accountEntityUpsertCache[key]
accountEntityUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
accountEntityAllColumns,
accountEntityColumnsWithDefault,
accountEntityColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
accountEntityAllColumns,
accountEntityPrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("model: unable to upsert account_entity, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(accountEntityPrimaryKeyColumns))
copy(conflict, accountEntityPrimaryKeyColumns)
}
cache.query = buildUpsertQuerySQLite(dialect, "\"account_entity\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(accountEntityType, accountEntityMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(accountEntityType, accountEntityMapping, 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 account_entity")
}
if !cached {
accountEntityUpsertCacheMut.Lock()
accountEntityUpsertCache[key] = cache
accountEntityUpsertCacheMut.Unlock()
}
return nil
}
// Delete deletes a single AccountEntity record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *AccountEntity) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("model: no AccountEntity provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), accountEntityPrimaryKeyMapping)
sql := "DELETE FROM \"account_entity\" 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 account_entity")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by delete for account_entity")
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q accountEntityQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("model: no accountEntityQuery 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 account_entity")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for account_entity")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o AccountEntitySlice) 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)), accountEntityPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"account_entity\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, accountEntityPrimaryKeyColumns, 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 accountEntity slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for account_entity")
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *AccountEntity) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindAccountEntity(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 *AccountEntitySlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := AccountEntitySlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), accountEntityPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"account_entity\".* FROM \"account_entity\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, accountEntityPrimaryKeyColumns, 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 AccountEntitySlice")
}
*o = slice
return nil
}
// AccountEntityExists checks if the AccountEntity row exists.
func AccountEntityExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"account_entity\" 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 account_entity exists")
}
return exists, nil
}
// Exists checks if the AccountEntity row exists.
func (o *AccountEntity) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
return AccountEntityExists(ctx, exec, o.ID)
}