desktop/backend/model/note_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"
)
// NoteTransaction is an object representing the database table.
type NoteTransaction struct {
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
NoteID int64 `boil:"note_id" json:"note_id" toml:"note_id" yaml:"note_id"`
TransactionsID int64 `boil:"transactions_id" json:"transactions_id" toml:"transactions_id" yaml:"transactions_id"`
R *noteTransactionR `boil:"-" json:"-" toml:"-" yaml:"-"`
L noteTransactionL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var NoteTransactionColumns = struct {
ID string
NoteID string
TransactionsID string
}{
ID: "id",
NoteID: "note_id",
TransactionsID: "transactions_id",
}
var NoteTransactionTableColumns = struct {
ID string
NoteID string
TransactionsID string
}{
ID: "note_transactions.id",
NoteID: "note_transactions.note_id",
TransactionsID: "note_transactions.transactions_id",
}
// Generated where
var NoteTransactionWhere = struct {
ID whereHelperint64
NoteID whereHelperint64
TransactionsID whereHelperint64
}{
ID: whereHelperint64{field: "\"note_transactions\".\"id\""},
NoteID: whereHelperint64{field: "\"note_transactions\".\"note_id\""},
TransactionsID: whereHelperint64{field: "\"note_transactions\".\"transactions_id\""},
}
// NoteTransactionRels is where relationship names are stored.
var NoteTransactionRels = struct {
Transaction string
Note string
}{
Transaction: "Transaction",
Note: "Note",
}
// noteTransactionR is where relationships are stored.
type noteTransactionR struct {
Transaction *Transaction `boil:"Transaction" json:"Transaction" toml:"Transaction" yaml:"Transaction"`
Note *Note `boil:"Note" json:"Note" toml:"Note" yaml:"Note"`
}
// NewStruct creates a new relationship struct
func (*noteTransactionR) NewStruct() *noteTransactionR {
return ¬eTransactionR{}
}
func (r *noteTransactionR) GetTransaction() *Transaction {
if r == nil {
return nil
}
return r.Transaction
}
func (r *noteTransactionR) GetNote() *Note {
if r == nil {
return nil
}
return r.Note
}
// noteTransactionL is where Load methods for each relationship are stored.
type noteTransactionL struct{}
var (
noteTransactionAllColumns = []string{"id", "note_id", "transactions_id"}
noteTransactionColumnsWithoutDefault = []string{"note_id", "transactions_id"}
noteTransactionColumnsWithDefault = []string{"id"}
noteTransactionPrimaryKeyColumns = []string{"id"}
noteTransactionGeneratedColumns = []string{"id"}
)
type (
// NoteTransactionSlice is an alias for a slice of pointers to NoteTransaction.
// This should almost always be used instead of []NoteTransaction.
NoteTransactionSlice []*NoteTransaction
noteTransactionQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
noteTransactionType = reflect.TypeOf(&NoteTransaction{})
noteTransactionMapping = queries.MakeStructMapping(noteTransactionType)
noteTransactionPrimaryKeyMapping, _ = queries.BindMapping(noteTransactionType, noteTransactionMapping, noteTransactionPrimaryKeyColumns)
noteTransactionInsertCacheMut sync.RWMutex
noteTransactionInsertCache = make(map[string]insertCache)
noteTransactionUpdateCacheMut sync.RWMutex
noteTransactionUpdateCache = make(map[string]updateCache)
noteTransactionUpsertCacheMut sync.RWMutex
noteTransactionUpsertCache = 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 noteTransaction record from the query.
func (q noteTransactionQuery) One(ctx context.Context, exec boil.ContextExecutor) (*NoteTransaction, error) {
o := &NoteTransaction{}
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 note_transactions")
}
return o, nil
}
// All returns all NoteTransaction records from the query.
func (q noteTransactionQuery) All(ctx context.Context, exec boil.ContextExecutor) (NoteTransactionSlice, error) {
var o []*NoteTransaction
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "model: failed to assign all query results to NoteTransaction slice")
}
return o, nil
}
// Count returns the count of all NoteTransaction records in the query.
func (q noteTransactionQuery) 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 note_transactions rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q noteTransactionQuery) 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 note_transactions exists")
}
return count > 0, nil
}
// Transaction pointed to by the foreign key.
func (o *NoteTransaction) Transaction(mods ...qm.QueryMod) transactionQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.TransactionsID),
}
queryMods = append(queryMods, mods...)
return Transactions(queryMods...)
}
// Note pointed to by the foreign key.
func (o *NoteTransaction) Note(mods ...qm.QueryMod) noteQuery {
queryMods := []qm.QueryMod{
qm.Where("\"id\" = ?", o.NoteID),
}
queryMods = append(queryMods, mods...)
return Notes(queryMods...)
}
// LoadTransaction allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (noteTransactionL) LoadTransaction(ctx context.Context, e boil.ContextExecutor, singular bool, maybeNoteTransaction interface{}, mods queries.Applicator) error {
var slice []*NoteTransaction
var object *NoteTransaction
if singular {
var ok bool
object, ok = maybeNoteTransaction.(*NoteTransaction)
if !ok {
object = new(NoteTransaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeNoteTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeNoteTransaction))
}
}
} else {
s, ok := maybeNoteTransaction.(*[]*NoteTransaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeNoteTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeNoteTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = ¬eTransactionR{}
}
args = append(args, object.TransactionsID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = ¬eTransactionR{}
}
for _, a := range args {
if a == obj.TransactionsID {
continue Outer
}
}
args = append(args, obj.TransactionsID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`transactions`),
qm.WhereIn(`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 Transaction")
}
var resultSlice []*Transaction
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Transaction")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for transactions")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for transactions")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Transaction = foreign
if foreign.R == nil {
foreign.R = &transactionR{}
}
foreign.R.NoteTransactions = append(foreign.R.NoteTransactions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.TransactionsID == foreign.ID {
local.R.Transaction = foreign
if foreign.R == nil {
foreign.R = &transactionR{}
}
foreign.R.NoteTransactions = append(foreign.R.NoteTransactions, local)
break
}
}
}
return nil
}
// LoadNote allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (noteTransactionL) LoadNote(ctx context.Context, e boil.ContextExecutor, singular bool, maybeNoteTransaction interface{}, mods queries.Applicator) error {
var slice []*NoteTransaction
var object *NoteTransaction
if singular {
var ok bool
object, ok = maybeNoteTransaction.(*NoteTransaction)
if !ok {
object = new(NoteTransaction)
ok = queries.SetFromEmbeddedStruct(&object, &maybeNoteTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeNoteTransaction))
}
}
} else {
s, ok := maybeNoteTransaction.(*[]*NoteTransaction)
if ok {
slice = *s
} else {
ok = queries.SetFromEmbeddedStruct(&slice, maybeNoteTransaction)
if !ok {
return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeNoteTransaction))
}
}
}
args := make([]interface{}, 0, 1)
if singular {
if object.R == nil {
object.R = ¬eTransactionR{}
}
args = append(args, object.NoteID)
} else {
Outer:
for _, obj := range slice {
if obj.R == nil {
obj.R = ¬eTransactionR{}
}
for _, a := range args {
if a == obj.NoteID {
continue Outer
}
}
args = append(args, obj.NoteID)
}
}
if len(args) == 0 {
return nil
}
query := NewQuery(
qm.From(`note`),
qm.WhereIn(`note.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")
}
var resultSlice []*Note
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice Note")
}
if err = results.Close(); err != nil {
return errors.Wrap(err, "failed to close results of eager load for note")
}
if err = results.Err(); err != nil {
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for note")
}
if len(resultSlice) == 0 {
return nil
}
if singular {
foreign := resultSlice[0]
object.R.Note = foreign
if foreign.R == nil {
foreign.R = ¬eR{}
}
foreign.R.NoteTransactions = append(foreign.R.NoteTransactions, object)
return nil
}
for _, local := range slice {
for _, foreign := range resultSlice {
if local.NoteID == foreign.ID {
local.R.Note = foreign
if foreign.R == nil {
foreign.R = ¬eR{}
}
foreign.R.NoteTransactions = append(foreign.R.NoteTransactions, local)
break
}
}
}
return nil
}
// SetTransaction of the noteTransaction to the related item.
// Sets o.R.Transaction to related.
// Adds o to related.R.NoteTransactions.
func (o *NoteTransaction) SetTransaction(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Transaction) 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 \"note_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"transactions_id"}),
strmangle.WhereClause("\"", "\"", 0, noteTransactionPrimaryKeyColumns),
)
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.TransactionsID = related.ID
if o.R == nil {
o.R = ¬eTransactionR{
Transaction: related,
}
} else {
o.R.Transaction = related
}
if related.R == nil {
related.R = &transactionR{
NoteTransactions: NoteTransactionSlice{o},
}
} else {
related.R.NoteTransactions = append(related.R.NoteTransactions, o)
}
return nil
}
// SetNote of the noteTransaction to the related item.
// Sets o.R.Note to related.
// Adds o to related.R.NoteTransactions.
func (o *NoteTransaction) SetNote(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Note) 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 \"note_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, []string{"note_id"}),
strmangle.WhereClause("\"", "\"", 0, noteTransactionPrimaryKeyColumns),
)
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.NoteID = related.ID
if o.R == nil {
o.R = ¬eTransactionR{
Note: related,
}
} else {
o.R.Note = related
}
if related.R == nil {
related.R = ¬eR{
NoteTransactions: NoteTransactionSlice{o},
}
} else {
related.R.NoteTransactions = append(related.R.NoteTransactions, o)
}
return nil
}
// NoteTransactions retrieves all the records using an executor.
func NoteTransactions(mods ...qm.QueryMod) noteTransactionQuery {
mods = append(mods, qm.From("\"note_transactions\""))
q := NewQuery(mods...)
if len(queries.GetSelect(q)) == 0 {
queries.SetSelect(q, []string{"\"note_transactions\".*"})
}
return noteTransactionQuery{q}
}
// FindNoteTransaction retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindNoteTransaction(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*NoteTransaction, error) {
noteTransactionObj := &NoteTransaction{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from \"note_transactions\" where \"id\"=?", sel,
)
q := queries.Raw(query, iD)
err := q.Bind(ctx, exec, noteTransactionObj)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "model: unable to select from note_transactions")
}
return noteTransactionObj, nil
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *NoteTransaction) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("model: no note_transactions provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(noteTransactionColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
noteTransactionInsertCacheMut.RLock()
cache, cached := noteTransactionInsertCache[key]
noteTransactionInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
noteTransactionAllColumns,
noteTransactionColumnsWithDefault,
noteTransactionColumnsWithoutDefault,
nzDefaults,
)
wl = strmangle.SetComplement(wl, noteTransactionGeneratedColumns)
cache.valueMapping, err = queries.BindMapping(noteTransactionType, noteTransactionMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(noteTransactionType, noteTransactionMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"note_transactions\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"note_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 note_transactions")
}
if !cached {
noteTransactionInsertCacheMut.Lock()
noteTransactionInsertCache[key] = cache
noteTransactionInsertCacheMut.Unlock()
}
return nil
}
// Update uses an executor to update the NoteTransaction.
// 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 *NoteTransaction) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
var err error
key := makeCacheKey(columns, nil)
noteTransactionUpdateCacheMut.RLock()
cache, cached := noteTransactionUpdateCache[key]
noteTransactionUpdateCacheMut.RUnlock()
if !cached {
wl := columns.UpdateColumnSet(
noteTransactionAllColumns,
noteTransactionPrimaryKeyColumns,
)
wl = strmangle.SetComplement(wl, noteTransactionGeneratedColumns)
if len(wl) == 0 {
return 0, errors.New("model: unable to update note_transactions, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE \"note_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, wl),
strmangle.WhereClause("\"", "\"", 0, noteTransactionPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(noteTransactionType, noteTransactionMapping, append(wl, noteTransactionPrimaryKeyColumns...))
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 note_transactions row")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by update for note_transactions")
}
if !cached {
noteTransactionUpdateCacheMut.Lock()
noteTransactionUpdateCache[key] = cache
noteTransactionUpdateCacheMut.Unlock()
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values.
func (q noteTransactionQuery) 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 note_transactions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected for note_transactions")
}
return rowsAff, nil
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o NoteTransactionSlice) 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)), noteTransactionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE \"note_transactions\" SET %s WHERE %s",
strmangle.SetParamNames("\"", "\"", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, noteTransactionPrimaryKeyColumns, 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 noteTransaction slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: unable to retrieve rows affected all in update all noteTransaction")
}
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 *NoteTransaction) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("model: no note_transactions provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(noteTransactionColumnsWithDefault, 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)
noteTransactionUpsertCacheMut.RLock()
cache, cached := noteTransactionUpsertCache[key]
noteTransactionUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
noteTransactionAllColumns,
noteTransactionColumnsWithDefault,
noteTransactionColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
noteTransactionAllColumns,
noteTransactionPrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("model: unable to upsert note_transactions, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(noteTransactionPrimaryKeyColumns))
copy(conflict, noteTransactionPrimaryKeyColumns)
}
cache.query = buildUpsertQuerySQLite(dialect, "\"note_transactions\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(noteTransactionType, noteTransactionMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(noteTransactionType, noteTransactionMapping, 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 note_transactions")
}
if !cached {
noteTransactionUpsertCacheMut.Lock()
noteTransactionUpsertCache[key] = cache
noteTransactionUpsertCacheMut.Unlock()
}
return nil
}
// Delete deletes a single NoteTransaction record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *NoteTransaction) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if o == nil {
return 0, errors.New("model: no NoteTransaction provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), noteTransactionPrimaryKeyMapping)
sql := "DELETE FROM \"note_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 note_transactions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by delete for note_transactions")
}
return rowsAff, nil
}
// DeleteAll deletes all matching rows.
func (q noteTransactionQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
if q.Query == nil {
return 0, errors.New("model: no noteTransactionQuery 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 note_transactions")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for note_transactions")
}
return rowsAff, nil
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o NoteTransactionSlice) 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)), noteTransactionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM \"note_transactions\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, noteTransactionPrimaryKeyColumns, 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 noteTransaction slice")
}
rowsAff, err := result.RowsAffected()
if err != nil {
return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for note_transactions")
}
return rowsAff, nil
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *NoteTransaction) Reload(ctx context.Context, exec boil.ContextExecutor) error {
ret, err := FindNoteTransaction(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 *NoteTransactionSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
if o == nil || len(*o) == 0 {
return nil
}
slice := NoteTransactionSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), noteTransactionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT \"note_transactions\".* FROM \"note_transactions\" WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, noteTransactionPrimaryKeyColumns, 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 NoteTransactionSlice")
}
*o = slice
return nil
}
// NoteTransactionExists checks if the NoteTransaction row exists.
func NoteTransactionExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
var exists bool
sql := "select exists(select 1 from \"note_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 note_transactions exists")
}
return exists, nil
}
// Exists checks if the NoteTransaction row exists.
func (o *NoteTransaction) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
return NoteTransactionExists(ctx, exec, o.ID)
}