desktop/backend/model/transactions.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"
)
// Transaction is an object representing the database table.
type Transaction struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
CurrencyID int64 `boil:"currency_id" json:"currency_id" toml:"currency_id" yaml:"currency_id"`
EntityID int64 `boil:"entity_id" json:"entity_id" toml:"entity_id" yaml:"entity_id"`
Memo string `boil:"memo" json:"memo" toml:"memo" yaml:"memo"`
Date string `boil:"date" json:"date" toml:"date" yaml:"date"`
R *transactionR `boil:"-" json:"-" toml:"-" yaml:"-"`
L transactionL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var TransactionColumns = struct {
ID string
CurrencyID string
EntityID string
Memo string
Date string
}{
ID: "id",
CurrencyID: "currency_id",
EntityID: "entity_id",
Memo: "memo",
Date: "date",
}
var TransactionTableColumns = struct {
ID string
CurrencyID string
EntityID string
Memo string
Date string
}{
ID: "transactions.id",
CurrencyID: "transactions.currency_id",
EntityID: "transactions.entity_id",
Memo: "transactions.memo",
Date: "transactions.date",
}
// Generated where
var TransactionWhere = struct {
ID whereHelperint64
CurrencyID whereHelperint64
EntityID whereHelperint64
Memo whereHelperstring
Date whereHelperstring
}{
ID: whereHelperint64{field: "\"transactions\".\"id\""},
CurrencyID: whereHelperint64{field: "\"transactions\".\"currency_id\""},
EntityID: whereHelperint64{field: "\"transactions\".\"entity_id\""},
Memo: whereHelperstring{field: "\"transactions\".\"memo\""},
Date: whereHelperstring{field: "\"transactions\".\"date\""},
}
// TransactionRels is where relationship names are stored.
var TransactionRels = struct {
Entity string
Currency string
AttachmentTransactions string
NoteTransactions string
Splits string
TagTransactions string
TransactionsAttributes string
TransactionsHashes string
}{
Entity: "Entity",
Currency: "Currency",
AttachmentTransactions: "AttachmentTransactions",
NoteTransactions: "NoteTransactions",
Splits: "Splits",
TagTransactions: "TagTransactions",
TransactionsAttributes: "TransactionsAttributes",
TransactionsHashes: "TransactionsHashes",
}
// transactionR is where relationships are stored.
type transactionR struct {
Entity *Entity `boil:"Entity" json:"Entity" toml:"Entity" yaml:"Entity"`
Currency *Currency `boil:"Currency" json:"Currency" toml:"Currency" yaml:"Currency"`
AttachmentTransactions AttachmentTransactionSlice `boil:"AttachmentTransactions" json:"AttachmentTransactions" toml:"AttachmentTransactions" yaml:"AttachmentTransactions"`
NoteTransactions NoteTransactionSlice `boil:"NoteTransactions" json:"NoteTransactions" toml:"NoteTransactions" yaml:"NoteTransactions"`
Splits SplitSlice `boil:"Splits" json:"Splits" toml:"Splits" yaml:"Splits"`
TagTransactions TagTransactionSlice `boil:"TagTransactions" json:"TagTransactions" toml:"TagTransactions" yaml:"TagTransactions"`
TransactionsAttributes TransactionsAttributeSlice `boil:"TransactionsAttributes" json:"TransactionsAttributes" toml:"TransactionsAttributes" yaml:"TransactionsAttributes"`
TransactionsHashes TransactionsHashSlice `boil:"TransactionsHashes" json:"TransactionsHashes" toml:"TransactionsHashes" yaml:"TransactionsHashes"`
}
// NewStruct creates a new relationship struct
func (*transactionR) NewStruct() *transactionR {
return &transactionR{}
}
func (r *transactionR) GetEntity() *Entity {
if r == nil {
return nil
}
return r.Entity
}
func (r *transactionR) GetCurrency() *Currency {
if r == nil {
return nil
}
return r.Currency
}
func (r *transactionR) GetAttachmentTransactions() AttachmentTransactionSlice {
if r == nil {
return nil
}
return r.AttachmentTransactions
}
func (r *transactionR) GetNoteTransactions() NoteTransactionSlice {
if r == nil {
return nil
}
return r.NoteTransactions
}
func (r *transactionR) GetSplits() SplitSlice {
if r == nil {
return nil
}
return r.Splits
}
func (r *transactionR) GetTagTransactions() TagTransactionSlice {
if r == nil {
return nil
}
return r.TagTransactions
}
func (r *transactionR) GetTransactionsAttributes() TransactionsAttributeSlice {
if r == nil {
return nil
}
return r.TransactionsAttributes
}
func (r *transactionR) GetTransactionsHashes() TransactionsHashSlice {
if r == nil {
return nil
}
return r.TransactionsHashes
}
// transactionL is where Load methods for each relationship are stored.
type transactionL struct{}
var (
transactionAllColumns = []string{"id", "currency_id", "entity_id", "memo", "date"}
transactionColumnsWithoutDefault = []string{"currency_id", "entity_id", "memo", "date"}
transactionColumnsWithDefault = []string{"id"}
transactionPrimaryKeyColumns = []string{"id"}
transactionGeneratedColumns = []string{"id"}
)
type (
// TransactionSlice is an alias for a slice of pointers to Transaction.
// This should almost always be used instead of []Transaction.
TransactionSlice []*Transaction
transactionQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
transactionType = reflect.TypeOf(&Transaction{})
transactionMapping = queries.MakeStructMapping(transactionType)
transactionPrimaryKeyMapping, _ = queries.BindMapping(transactionType, transactionMapping, transactionPrimaryKeyColumns)
transactionInsertCacheMut sync.RWMutex
transactionInsertCache = make(map[string]insertCache)
transactionUpdateCacheMut sync.RWMutex
transactionUpdateCache = make(map[string]updateCache)
transactionUpsertCacheMut sync.RWMutex
transactionUpsertCache = 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 transaction record from the query.
func (q transactionQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Transaction, error) {
o := &Transaction{}
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 transactions")
}
return o, nil
}
// All returns all Transaction records from the query.
func (q transactionQuery) All(ctx context.Context, exec boil.ContextExecutor) (TransactionSlice, error) {
var o []*Transaction
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "model: failed to assign all query results to Transaction slice")
}
return o, nil
}
// Count returns the count of all Transaction records in the query.
func (q transactionQuery) 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 transactions rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q transactionQuery) 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 transactions exists")
}
return count > 0, nil
}
// Entity pointed to by the foreign key.
func (o *Transaction) Entity(mods ...qm.QueryMod) entityQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.EntityID),
}
queryMods = append(queryMods, mods...)
return Entities(queryMods...)
}
// Currency pointed to by the foreign key.
func (o *Transaction) Currency(mods ...qm.QueryMod) currencyQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.CurrencyID),
}
queryMods = append(queryMods, mods...)
return Currencies(queryMods...)
}
// AttachmentTransactions retrieves all the attachment_transaction's AttachmentTransactions with an executor.
func (o *Transaction) AttachmentTransactions(mods ...qm.QueryMod) attachmentTransactionQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"attachment_transactions\".\"transactions_id\"=?", o.ID),
)
return AttachmentTransactions(queryMods...)
}
// NoteTransactions retrieves all the note_transaction's NoteTransactions with an executor.
func (o *Transaction) NoteTransactions(mods ...qm.QueryMod) noteTransactionQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"note_transactions\".\"transactions_id\"=?", o.ID),
)
return NoteTransactions(queryMods...)
}
// Splits retrieves all the split's Splits with an executor.
func (o *Transaction) Splits(mods ...qm.QueryMod) splitQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"splits\".\"transactions_id\"=?", o.ID),
)
return Splits(queryMods...)
}
// TagTransactions retrieves all the tag_transaction's TagTransactions with an executor.
func (o *Transaction) TagTransactions(mods ...qm.QueryMod) tagTransactionQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"tag_transactions\".\"transactions_id\"=?", o.ID),
)
return TagTransactions(queryMods...)
}
// TransactionsAttributes retrieves all the transactions_attribute's TransactionsAttributes with an executor.
func (o *Transaction) TransactionsAttributes(mods ...qm.QueryMod) transactionsAttributeQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"transactions_attributes\".\"transactions_id\"=?", o.ID),
)
return TransactionsAttributes(queryMods...)
}
// TransactionsHashes retrieves all the transactions_hash's TransactionsHashes with an executor.
func (o *Transaction) TransactionsHashes(mods ...qm.QueryMod) transactionsHashQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("\"transactions_hash\".\"transactions_id\"=?", o.ID),
)
return TransactionsHashes(queryMods...)
}
// LoadEntity allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (transactionL) LoadEntity(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.EntityID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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.Transactions = append(foreign.R.Transactions, 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.Transactions = append(foreign.R.Transactions, local)
break
}
}
}
return nil
}
// LoadCurrency allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (transactionL) LoadCurrency(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.CurrencyID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
for _, a := range args {
if a == obj.CurrencyID {
continue Outer
}
}
args = append(args, obj.CurrencyID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`currency`),
qm.WhereIn(`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")
}
var resultSlice []*Currency
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Currency")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for currency")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for currency")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Currency = foreign
if foreign.R == nil {
foreign.R = ¤cyR{}
}
foreign.R.Transactions = append(foreign.R.Transactions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.CurrencyID == foreign.ID {
local.R.Currency = foreign
if foreign.R == nil {
foreign.R = ¤cyR{}
}
foreign.R.Transactions = append(foreign.R.Transactions, local)
break
}
}
}
return nil
}
// LoadAttachmentTransactions 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 (transactionL) LoadAttachmentTransactions(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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(`attachment_transactions`),
qm.WhereIn(`attachment_transactions.transactions_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 attachment_transactions")
}
var resultSlice []*AttachmentTransaction
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice attachment_transactions")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on attachment_transactions")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for attachment_transactions")
}
if singular {
object.R.AttachmentTransactions = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &attachmentTransactionR{}
}
foreign.R.Transaction = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.TransactionsID {
local.R.AttachmentTransactions = append(local.R.AttachmentTransactions, foreign)
if foreign.R == nil {
foreign.R = &attachmentTransactionR{}
}
foreign.R.Transaction = local
break
}
}
}
return nil
}
// LoadNoteTransactions 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 (transactionL) LoadNoteTransactions(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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(`note_transactions`),
qm.WhereIn(`note_transactions.transactions_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 note_transactions")
}
var resultSlice []*NoteTransaction
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice note_transactions")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on note_transactions")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for note_transactions")
}
if singular {
object.R.NoteTransactions = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = ¬eTransactionR{}
}
foreign.R.Transaction = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.TransactionsID {
local.R.NoteTransactions = append(local.R.NoteTransactions, foreign)
if foreign.R == nil {
foreign.R = ¬eTransactionR{}
}
foreign.R.Transaction = local
break
}
}
}
return nil
}
// LoadSplits 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 (transactionL) LoadSplits(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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(`splits`),
qm.WhereIn(`splits.transactions_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 splits")
}
var resultSlice []*Split
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice splits")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on splits")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for splits")
}
if singular {
object.R.Splits = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &splitR{}
}
foreign.R.Transaction = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.TransactionsID {
local.R.Splits = append(local.R.Splits, foreign)
if foreign.R == nil {
foreign.R = &splitR{}
}
foreign.R.Transaction = local
break
}
}
}
return nil
}
// LoadTagTransactions 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 (transactionL) LoadTagTransactions(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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(`tag_transactions`),
qm.WhereIn(`tag_transactions.transactions_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_transactions")
}
var resultSlice []*TagTransaction
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice tag_transactions")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on tag_transactions")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for tag_transactions")
}
if singular {
object.R.TagTransactions = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &tagTransactionR{}
}
foreign.R.Transaction = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.TransactionsID {
local.R.TagTransactions = append(local.R.TagTransactions, foreign)
if foreign.R == nil {
foreign.R = &tagTransactionR{}
}
foreign.R.Transaction = local
break
}
}
}
return nil
}
// LoadTransactionsAttributes 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 (transactionL) LoadTransactionsAttributes(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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_attributes`),
qm.WhereIn(`transactions_attributes.transactions_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_attributes")
}
var resultSlice []*TransactionsAttribute
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice transactions_attributes")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on transactions_attributes")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for transactions_attributes")
}
if singular {
object.R.TransactionsAttributes = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &transactionsAttributeR{}
}
foreign.R.Transaction = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.TransactionsID {
local.R.TransactionsAttributes = append(local.R.TransactionsAttributes, foreign)
if foreign.R == nil {
foreign.R = &transactionsAttributeR{}
}
foreign.R.Transaction = local
break
}
}
}
return nil
}
// LoadTransactionsHashes 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 (transactionL) LoadTransactionsHashes(ctx context.Context, e boil.ContextExecutor, singular bool, maybeTransaction interface{}, mods queries.Applicator) error {
var slice []*Transaction
var object *Transaction
if singular {
var ok bool
object, ok = maybeTransaction.(*Transaction)
if !ok {
object = new(Transaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeTransaction))
}
}
} else {
s, ok := maybeTransaction.(*[]*Transaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = &transactionR{}
}
args = append(args, object.ID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = &transactionR{}
}
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_hash`),
qm.WhereIn(`transactions_hash.transactions_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_hash")
}
var resultSlice []*TransactionsHash
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice transactions_hash")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results in eager load on transactions_hash")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for transactions_hash")
}
if singular {
object.R.TransactionsHashes = resultSlice
for _, foreign := range resultSlice {
if foreign.R == nil {
foreign.R = &transactionsHashR{}
}
foreign.R.Transaction = object
}
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.TransactionsID {
local.R.TransactionsHashes = append(local.R.TransactionsHashes, foreign)
if foreign.R == nil {
foreign.R = &transactionsHashR{}
}
foreign.R.Transaction = local
break
}
}
}
return nil
}
// SetEntity of the transaction to the related item.
// Sets o.R.Entity to related.
// Adds o to related.R.Transactions.
func (o *Transaction) 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 \"transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"entity_id"}),
strmangle.WhereClause("\"", "\"", 0, transactionPrimaryKeyColumns),
)
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 = &transactionR{
Entity: related,
}
} else {
o.R.Entity = related
}
if related.R == nil {
related.R = &entityR{
Transactions: TransactionSlice{o},
}
} else {
related.R.Transactions = append(related.R.Transactions, o)
}
return nil
}
// SetCurrency of the transaction to the related item.
// Sets o.R.Currency to related.
// Adds o to related.R.Transactions.
func (o *Transaction) SetCurrency(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Currency) 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 \"transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"currency_id"}),
strmangle.WhereClause("\"", "\"", 0, transactionPrimaryKeyColumns),
)
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.CurrencyID = related.ID
if o.R == nil {
o.R = &transactionR{
Currency: related,
}
} else {
o.R.Currency = related
}
if related.R == nil {
related.R = ¤cyR{
Transactions: TransactionSlice{o},
}
} else {
related.R.Transactions = append(related.R.Transactions, o)
}
return nil
}
// AddAttachmentTransactions adds the given related objects to the existing relationships
// of the transaction, optionally inserting them as new records.
// Appends related to o.R.AttachmentTransactions.
// Sets related.R.Transaction appropriately.
func (o *Transaction) AddAttachmentTransactions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AttachmentTransaction) error {
var err error
for _, rel := range related {
if insert {
rel.TransactionsID = 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 \"attachment_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, attachmentTransactionPrimaryKeyColumns),
)
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.TransactionsID = o.ID
}
}
if o.R == nil {
o.R = &transactionR{
AttachmentTransactions: related,
}
} else {
o.R.AttachmentTransactions = append(o.R.AttachmentTransactions, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &attachmentTransactionR{
Transaction: o,
}
} else {
rel.R.Transaction = o
}
}
return nil
}
// AddNoteTransactions adds the given related objects to the existing relationships
// of the transaction, optionally inserting them as new records.
// Appends related to o.R.NoteTransactions.
// Sets related.R.Transaction appropriately.
func (o *Transaction) AddNoteTransactions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*NoteTransaction) error {
var err error
for _, rel := range related {
if insert {
rel.TransactionsID = 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 \"note_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, noteTransactionPrimaryKeyColumns),
)
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.TransactionsID = o.ID
}
}
if o.R == nil {
o.R = &transactionR{
NoteTransactions: related,
}
} else {
o.R.NoteTransactions = append(o.R.NoteTransactions, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = ¬eTransactionR{
Transaction: o,
}
} else {
rel.R.Transaction = o
}
}
return nil
}
// AddSplits adds the given related objects to the existing relationships
// of the transaction, optionally inserting them as new records.
// Appends related to o.R.Splits.
// Sets related.R.Transaction appropriately.
func (o *Transaction) AddSplits(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Split) error {
var err error
for _, rel := range related {
if insert {
rel.TransactionsID = 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 \"splits\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, splitPrimaryKeyColumns),
)
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.TransactionsID = o.ID
}
}
if o.R == nil {
o.R = &transactionR{
Splits: related,
}
} else {
o.R.Splits = append(o.R.Splits, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &splitR{
Transaction: o,
}
} else {
rel.R.Transaction = o
}
}
return nil
}
// AddTagTransactions adds the given related objects to the existing relationships
// of the transaction, optionally inserting them as new records.
// Appends related to o.R.TagTransactions.
// Sets related.R.Transaction appropriately.
func (o *Transaction) AddTagTransactions(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*TagTransaction) error {
var err error
for _, rel := range related {
if insert {
rel.TransactionsID = 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 \"tag_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, tagTransactionPrimaryKeyColumns),
)
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.TransactionsID = o.ID
}
}
if o.R == nil {
o.R = &transactionR{
TagTransactions: related,
}
} else {
o.R.TagTransactions = append(o.R.TagTransactions, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &tagTransactionR{
Transaction: o,
}
} else {
rel.R.Transaction = o
}
}
return nil
}
// AddTransactionsAttributes adds the given related objects to the existing relationships
// of the transaction, optionally inserting them as new records.
// Appends related to o.R.TransactionsAttributes.
// Sets related.R.Transaction appropriately.
func (o *Transaction) AddTransactionsAttributes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*TransactionsAttribute) error {
var err error
for _, rel := range related {
if insert {
rel.TransactionsID = 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_attributes\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, transactionsAttributePrimaryKeyColumns),
)
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.TransactionsID = o.ID
}
}
if o.R == nil {
o.R = &transactionR{
TransactionsAttributes: related,
}
} else {
o.R.TransactionsAttributes = append(o.R.TransactionsAttributes, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &transactionsAttributeR{
Transaction: o,
}
} else {
rel.R.Transaction = o
}
}
return nil
}
// AddTransactionsHashes adds the given related objects to the existing relationships
// of the transaction, optionally inserting them as new records.
// Appends related to o.R.TransactionsHashes.
// Sets related.R.Transaction appropriately.
func (o *Transaction) AddTransactionsHashes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*TransactionsHash) error {
var err error
for _, rel := range related {
if insert {
rel.TransactionsID = 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_hash\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, transactionsHashPrimaryKeyColumns),
)
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.TransactionsID = o.ID
}
}
if o.R == nil {
o.R = &transactionR{
TransactionsHashes: related,
}
} else {
o.R.TransactionsHashes = append(o.R.TransactionsHashes, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &transactionsHashR{
Transaction: o,
}
} else {
rel.R.Transaction = o
}
}
return nil
}
// Transactions retrieves all the records using an executor.
func Transactions(mods ...qm.QueryMod) transactionQuery {
mods = append(mods, qm.From("\"transactions\""))
q := NewQuery(mods...)
if len(queries.GetSelect(q)) == 0 {
queries.SetSelect(q, []string{"\"transactions\".*"})
}
return transactionQuery{q}
}
// FindTransaction retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindTransaction(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*Transaction, error) {
transactionObj := &Transaction{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"transactions\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, transactionObj)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "model: unable to select from transactions")
}
return transactionObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *Transaction) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("model: no transactions provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(transactionColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
transactionInsertCacheMut.RLock()
cache, cached := transactionInsertCache[key]
transactionInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
transactionAllColumns,
transactionColumnsWithDefault,
transactionColumnsWithoutDefault,
nzDefaults,
)
wl = strmangle.SetComplement(wl, transactionGeneratedColumns)
cache.valueMapping, err = queries.BindMapping(transactionType, transactionMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(transactionType, transactionMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"transactions\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"transactions\" %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 transactions")
}
if !cached {
transactionInsertCacheMut.Lock()
transactionInsertCache[key] = cache
transactionInsertCacheMut.Unlock()
}
return nil
}
// Update uses an executor to update the Transaction.
// 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 *Transaction) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
transactionUpdateCacheMut.RLock()
cache, cached := transactionUpdateCache[key]
transactionUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
transactionAllColumns,
transactionPrimaryKeyColumns,
)
wl = strmangle.SetComplement(wl, transactionGeneratedColumns)
if len(wl) == 0 {
return 0, errors.New("model: unable to update transactions, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, transactionPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(transactionType, transactionMapping, append(wl, transactionPrimaryKeyColumns...))
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 transactions row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by update for transactions")
}
if !cached {
transactionUpdateCacheMut.Lock()
transactionUpdateCache[key] = cache
transactionUpdateCacheMut.Unlock()
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values.
func (q transactionQuery) 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 transactions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected for transactions")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o TransactionSlice) 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)), transactionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, transactionPrimaryKeyColumns, 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 transaction slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected all in update all transaction")
}
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 *Transaction) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("model: no transactions provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(transactionColumnsWithDefault, 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)
transactionUpsertCacheMut.RLock()
cache, cached := transactionUpsertCache[key]
transactionUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
transactionAllColumns,
transactionColumnsWithDefault,
transactionColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
transactionAllColumns,
transactionPrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("model: unable to upsert transactions, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(transactionPrimaryKeyColumns))
copy(conflict, transactionPrimaryKeyColumns)
}
cache.query = buildUpsertQuerySQLite(dialect, "\"transactions\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(transactionType, transactionMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(transactionType, transactionMapping, 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 transactions")
}
if !cached {
transactionUpsertCacheMut.Lock()
transactionUpsertCache[key] = cache
transactionUpsertCacheMut.Unlock()
}
return nil
}
// Delete deletes a single Transaction record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *Transaction) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("model: no Transaction provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), transactionPrimaryKeyMapping)
sql := "DELETE FROM \"transactions\" 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 transactions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by delete for transactions")
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q transactionQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("model: no transactionQuery 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 transactions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for transactions")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o TransactionSlice) 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)), transactionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"transactions\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, transactionPrimaryKeyColumns, 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 transaction slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for transactions")
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *Transaction) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindTransaction(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 *TransactionSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := TransactionSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), transactionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"transactions\".* FROM \"transactions\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, transactionPrimaryKeyColumns, 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 TransactionSlice")
}
*o = slice
return nil
}
// TransactionExists checks if the Transaction row exists.
func TransactionExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"transactions\" 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 transactions exists")
}
return exists, nil
}
// Exists checks if the Transaction row exists.
func (o *Transaction) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
return TransactionExists(ctx, exec, o.ID)
}