desktop/backend/model/currency.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"
)
// Currency is an object representing the database table.
type Currency struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
Name string `boil:"name" json:"name" toml:"name" yaml:"name"`
R *currencyR `boil:"-" json:"-" toml:"-" yaml:"-"`
L currencyL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var CurrencyColumns = struct {
ID string
Name string
}{
ID: "id",
Name: "name",
}
var CurrencyTableColumns = struct {
ID string
Name string
}{
ID: "currency.id",
Name: "currency.name",
}
// Generated where
var CurrencyWhere = struct {
ID whereHelperint64
Name whereHelperstring
}{
ID: whereHelperint64{field: "\"currency\".\"id\""},
Name: whereHelperstring{field: "\"currency\".\"name\""},
}
// CurrencyRels is where relationship names are stored.
var CurrencyRels = struct {
CurrencyAttributes string
Transactions string
}{
CurrencyAttributes: "CurrencyAttributes",
Transactions: "Transactions",
}
// currencyR is where relationships are stored.
type currencyR struct {
CurrencyAttributes CurrencyAttributeSlice `boil:"CurrencyAttributes" json:"CurrencyAttributes" toml:"CurrencyAttributes" yaml:"CurrencyAttributes"`
Transactions TransactionSlice `boil:"Transactions" json:"Transactions" toml:"Transactions" yaml:"Transactions"`
}
// NewStruct creates a new relationship struct
func (*currencyR) NewStruct() *currencyR {
return ¤cyR{}
}
func (r *currencyR) GetCurrencyAttributes() CurrencyAttributeSlice {
if r == nil {
return nil
}
return r.CurrencyAttributes
}
func (r *currencyR) GetTransactions() TransactionSlice {
if r == nil {
return nil
}
return r.Transactions
}
// currencyL is where Load methods for each relationship are stored.
type currencyL struct{}
var (
currencyAllColumns = []string{"id", "name"}
currencyColumnsWithoutDefault = []string{"name"}
currencyColumnsWithDefault = []string{"id"}
currencyPrimaryKeyColumns = []string{"id"}
currencyGeneratedColumns = []string{"id"}
)
type (
// CurrencySlice is an alias for a slice of pointers to Currency.
// This should almost always be used instead of []Currency.
CurrencySlice []*Currency
currencyQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
currencyType = reflect.TypeOf(&Currency{})
currencyMapping = queries.MakeStructMapping(currencyType)
currencyPrimaryKeyMapping, _ = queries.BindMapping(currencyType, currencyMapping, currencyPrimaryKeyColumns)
currencyInsertCacheMut sync.RWMutex
currencyInsertCache = make(map[string]insertCache)
currencyUpdateCacheMut sync.RWMutex
currencyUpdateCache = make(map[string]updateCache)
currencyUpsertCacheMut sync.RWMutex
currencyUpsertCache = 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 currency record from the query.
func (q currencyQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Currency, error) {
o := &Currency{}
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 currency")
}
return o, nil
}
// All returns all Currency records from the query.
func (q currencyQuery) All(ctx context.Context, exec boil.ContextExecutor) (CurrencySlice, error) {
var o []*Currency
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "model: failed to assign all query results to Currency slice")
}
return o, nil
}
// Count returns the count of all Currency records in the query.
func (q currencyQuery) 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 currency rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q currencyQuery) 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 currency exists")
}
return count > 0, nil
}
// CurrencyAttributes retrieves all the currency_attribute's CurrencyAttributes with an executor.
func (o *Currency) CurrencyAttributes(mods ...qm.QueryMod) currencyAttributeQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"currency_attributes\".\"currency_id\"=?", o.ID),
)
return CurrencyAttributes(queryMods...)
}
// Transactions retrieves all the transaction's Transactions with an executor.
func (o *Currency) Transactions(mods ...qm.QueryMod) transactionQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"transactions\".\"currency_id\"=?", o.ID),
)
return Transactions(queryMods...)
}
// LoadCurrencyAttributes 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 (currencyL) LoadCurrencyAttributes(ctx context.Context, e boil.ContextExecutor, singular bool, maybeCurrency interface{}, mods queries.Applicator) error {
var slice []*Currency
var object *Currency
if singular {
var ok bool
object, ok = maybeCurrency.(*Currency)
if !ok {
object = new(Currency)
ok = queries.SetFromEmbeddedStruct(&object, &maybeCurrency)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeCurrency))
}
}
} else {
s, ok := maybeCurrency.(*[]*Currency)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeCurrency)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeCurrency))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = ¤cyR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = ¤cyR{}
}
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(`currency_attributes`),
qm.WhereIn(`currency_attributes.currency_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 currency_attributes")
}
var resultSlice []*CurrencyAttribute
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice currency_attributes")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on currency_attributes")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for currency_attributes")
}
if singular {
object.R.CurrencyAttributes = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = ¤cyAttributeR{}
}
foreign.R.Currency = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.CurrencyID {
local.R.CurrencyAttributes = append(local.R.CurrencyAttributes, foreign)
if foreign.R == nil {
foreign.R = ¤cyAttributeR{}
}
foreign.R.Currency = local
break
}
}
}
return nil
}
// LoadTransactions 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 (currencyL) LoadTransactions(ctx context.Context, e boil.ContextExecutor, singular bool, maybeCurrency interface{}, mods queries.Applicator) error {
var slice []*Currency
var object *Currency
if singular {
var ok bool
object, ok = maybeCurrency.(*Currency)
if !ok {
object = new(Currency)
ok = queries.SetFromEmbeddedStruct(&object, &maybeCurrency)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeCurrency))
}
}
} else {
s, ok := maybeCurrency.(*[]*Currency)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeCurrency)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeCurrency))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = ¤cyR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = ¤cyR{}
}
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(`transactions`),
qm.WhereIn(`transactions.currency_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 transactions")
}
var resultSlice []*Transaction
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice transactions")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on transactions")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for transactions")
}
if singular {
object.R.Transactions = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &transactionR{}
}
foreign.R.Currency = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.CurrencyID {
local.R.Transactions = append(local.R.Transactions, foreign)
if foreign.R == nil {
foreign.R = &transactionR{}
}
foreign.R.Currency = local
break
}
}
}
return nil
}
// AddCurrencyAttributes adds the given related objects to the existing relationships
// of the currency, optionally inserting them as new records.
// Appends related to o.R.CurrencyAttributes.
// Sets related.R.Currency appropriately.
func (o *Currency) AddCurrencyAttributes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*CurrencyAttribute) error {
var err error
for _, rel := range related {
if insert {
rel.CurrencyID = o.ID
if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
} else {
updateQuery := fmt.Sprintf(
"UPDATE \"currency_attributes\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"currency_id"}),
strmangle.WhereClause("\"", "\"", 0, currencyAttributePrimaryKeyColumns),
)
values := []interface{}{o.ID, rel.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 foreign table")
}
rel.CurrencyID = o.ID
}
}
if o.R == nil {
o.R = ¤cyR{
CurrencyAttributes: related,
}
} else {
o.R.CurrencyAttributes = append(o.R.CurrencyAttributes, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = ¤cyAttributeR{
Currency: o,
}
} else {
rel.R.Currency = o
}
}
return nil
}
// AddTransactions adds the given related objects to the existing relationships
// of the currency, optionally inserting them as new records.
// Appends related to o.R.Transactions.
// Sets related.R.Currency appropriately.
func (o *Currency) AddTransactions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Transaction) error {
var err error
for _, rel := range related {
if insert {
rel.CurrencyID = o.ID
if err = rel.Insert(ctx, exec, boil.Infer()); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
} else {
updateQuery := fmt.Sprintf(
"UPDATE \"transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"currency_id"}),
strmangle.WhereClause("\"", "\"", 0, transactionPrimaryKeyColumns),
)
values := []interface{}{o.ID, rel.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 foreign table")
}
rel.CurrencyID = o.ID
}
}
if o.R == nil {
o.R = ¤cyR{
Transactions: related,
}
} else {
o.R.Transactions = append(o.R.Transactions, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &transactionR{
Currency: o,
}
} else {
rel.R.Currency = o
}
}
return nil
}
// Currencies retrieves all the records using an executor.
func Currencies(mods ...qm.QueryMod) currencyQuery {
mods = append(mods, qm.From("\"currency\""))
q := NewQuery(mods...)
if len(queries.GetSelect(q)) == 0 {
queries.SetSelect(q, []string{"\"currency\".*"})
}
return currencyQuery{q}
}
// FindCurrency retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindCurrency(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*Currency, error) {
currencyObj := &Currency{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"currency\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, currencyObj)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "model: unable to select from currency")
}
return currencyObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *Currency) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("model: no currency provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(currencyColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
currencyInsertCacheMut.RLock()
cache, cached := currencyInsertCache[key]
currencyInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
currencyAllColumns,
currencyColumnsWithDefault,
currencyColumnsWithoutDefault,
nzDefaults,
)
wl = strmangle.SetComplement(wl, currencyGeneratedColumns)
cache.valueMapping, err = queries.BindMapping(currencyType, currencyMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(currencyType, currencyMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"currency\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"currency\" %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 currency")
}
if !cached {
currencyInsertCacheMut.Lock()
currencyInsertCache[key] = cache
currencyInsertCacheMut.Unlock()
}
return nil
}
// Update uses an executor to update the Currency.
// 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 *Currency) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
currencyUpdateCacheMut.RLock()
cache, cached := currencyUpdateCache[key]
currencyUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
currencyAllColumns,
currencyPrimaryKeyColumns,
)
wl = strmangle.SetComplement(wl, currencyGeneratedColumns)
if len(wl) == 0 {
return 0, errors.New("model: unable to update currency, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"currency\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, currencyPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(currencyType, currencyMapping, append(wl, currencyPrimaryKeyColumns...))
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 currency row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by update for currency")
}
if !cached {
currencyUpdateCacheMut.Lock()
currencyUpdateCache[key] = cache
currencyUpdateCacheMut.Unlock()
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values.
func (q currencyQuery) 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 currency")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected for currency")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o CurrencySlice) 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)), currencyPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"currency\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, currencyPrimaryKeyColumns, 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 currency slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected all in update all currency")
}
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 *Currency) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("model: no currency provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(currencyColumnsWithDefault, 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)
currencyUpsertCacheMut.RLock()
cache, cached := currencyUpsertCache[key]
currencyUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
currencyAllColumns,
currencyColumnsWithDefault,
currencyColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
currencyAllColumns,
currencyPrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("model: unable to upsert currency, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(currencyPrimaryKeyColumns))
copy(conflict, currencyPrimaryKeyColumns)
}
cache.query = buildUpsertQuerySQLite(dialect, "\"currency\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(currencyType, currencyMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(currencyType, currencyMapping, 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 currency")
}
if !cached {
currencyUpsertCacheMut.Lock()
currencyUpsertCache[key] = cache
currencyUpsertCacheMut.Unlock()
}
return nil
}
// Delete deletes a single Currency record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *Currency) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("model: no Currency provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), currencyPrimaryKeyMapping)
sql := "DELETE FROM \"currency\" 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 currency")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by delete for currency")
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q currencyQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("model: no currencyQuery 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 currency")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for currency")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o CurrencySlice) 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)), currencyPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"currency\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, currencyPrimaryKeyColumns, 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 currency slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for currency")
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *Currency) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindCurrency(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 *CurrencySlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := CurrencySlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), currencyPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"currency\".* FROM \"currency\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, currencyPrimaryKeyColumns, 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 CurrencySlice")
}
*o = slice
return nil
}
// CurrencyExists checks if the Currency row exists.
func CurrencyExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"currency\" 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 currency exists")
}
return exists, nil
}
// Exists checks if the Currency row exists.
func (o *Currency) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
return CurrencyExists(ctx, exec, o.ID)
}