summary history files

desktop/backend/model/account_match.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"
)

// AccountMatch is an object representing the database table.
type AccountMatch struct {
	ID                   int64  `boil:"id" json:"id" toml:"id" yaml:"id"`
	Name                 string `boil:"name" json:"name" toml:"name" yaml:"name"`
	SourceAccountID      int64  `boil:"source_account_id" json:"source_account_id" toml:"source_account_id" yaml:"source_account_id"`
	DestinationAccountID int64  `boil:"destination_account_id" json:"destination_account_id" toml:"destination_account_id" yaml:"destination_account_id"`

	R *accountMatchR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L accountMatchL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

var AccountMatchColumns = struct {
	ID                   string
	Name                 string
	SourceAccountID      string
	DestinationAccountID string
}{
	ID:                   "id",
	Name:                 "name",
	SourceAccountID:      "source_account_id",
	DestinationAccountID: "destination_account_id",
}

var AccountMatchTableColumns = struct {
	ID                   string
	Name                 string
	SourceAccountID      string
	DestinationAccountID string
}{
	ID:                   "account_match.id",
	Name:                 "account_match.name",
	SourceAccountID:      "account_match.source_account_id",
	DestinationAccountID: "account_match.destination_account_id",
}

// Generated where

var AccountMatchWhere = struct {
	ID                   whereHelperint64
	Name                 whereHelperstring
	SourceAccountID      whereHelperint64
	DestinationAccountID whereHelperint64
}{
	ID:                   whereHelperint64{field: "\"account_match\".\"id\""},
	Name:                 whereHelperstring{field: "\"account_match\".\"name\""},
	SourceAccountID:      whereHelperint64{field: "\"account_match\".\"source_account_id\""},
	DestinationAccountID: whereHelperint64{field: "\"account_match\".\"destination_account_id\""},
}

// AccountMatchRels is where relationship names are stored.
var AccountMatchRels = struct {
	DestinationAccount     string
	SourceAccount          string
	AccountMatchAttributes string
	AccountMatchRegexes    string
}{
	DestinationAccount:     "DestinationAccount",
	SourceAccount:          "SourceAccount",
	AccountMatchAttributes: "AccountMatchAttributes",
	AccountMatchRegexes:    "AccountMatchRegexes",
}

// accountMatchR is where relationships are stored.
type accountMatchR struct {
	DestinationAccount     *Account                   `boil:"DestinationAccount" json:"DestinationAccount" toml:"DestinationAccount" yaml:"DestinationAccount"`
	SourceAccount          *Account                   `boil:"SourceAccount" json:"SourceAccount" toml:"SourceAccount" yaml:"SourceAccount"`
	AccountMatchAttributes AccountMatchAttributeSlice `boil:"AccountMatchAttributes" json:"AccountMatchAttributes" toml:"AccountMatchAttributes" yaml:"AccountMatchAttributes"`
	AccountMatchRegexes    AccountMatchRegexSlice     `boil:"AccountMatchRegexes" json:"AccountMatchRegexes" toml:"AccountMatchRegexes" yaml:"AccountMatchRegexes"`
}

// NewStruct creates a new relationship struct
func (*accountMatchR) NewStruct() *accountMatchR {
	return &accountMatchR{}
}

func (r *accountMatchR) GetDestinationAccount() *Account {
	if r == nil {
		return nil
	}
	return r.DestinationAccount
}

func (r *accountMatchR) GetSourceAccount() *Account {
	if r == nil {
		return nil
	}
	return r.SourceAccount
}

func (r *accountMatchR) GetAccountMatchAttributes() AccountMatchAttributeSlice {
	if r == nil {
		return nil
	}
	return r.AccountMatchAttributes
}

func (r *accountMatchR) GetAccountMatchRegexes() AccountMatchRegexSlice {
	if r == nil {
		return nil
	}
	return r.AccountMatchRegexes
}

// accountMatchL is where Load methods for each relationship are stored.
type accountMatchL struct{}

var (
	accountMatchAllColumns            = []string{"id", "name", "source_account_id", "destination_account_id"}
	accountMatchColumnsWithoutDefault = []string{"name", "source_account_id", "destination_account_id"}
	accountMatchColumnsWithDefault    = []string{"id"}
	accountMatchPrimaryKeyColumns     = []string{"id"}
	accountMatchGeneratedColumns      = []string{"id"}
)

type (
	// AccountMatchSlice is an alias for a slice of pointers to AccountMatch.
	// This should almost always be used instead of []AccountMatch.
	AccountMatchSlice []*AccountMatch

	accountMatchQuery struct {
		*queries.Query
	}
)

// Cache for insert, update and upsert
var (
	accountMatchType                 = reflect.TypeOf(&AccountMatch{})
	accountMatchMapping              = queries.MakeStructMapping(accountMatchType)
	accountMatchPrimaryKeyMapping, _ = queries.BindMapping(accountMatchType, accountMatchMapping, accountMatchPrimaryKeyColumns)
	accountMatchInsertCacheMut       sync.RWMutex
	accountMatchInsertCache          = make(map[string]insertCache)
	accountMatchUpdateCacheMut       sync.RWMutex
	accountMatchUpdateCache          = make(map[string]updateCache)
	accountMatchUpsertCacheMut       sync.RWMutex
	accountMatchUpsertCache          = 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 accountMatch record from the query.
func (q accountMatchQuery) One(ctx context.Context, exec boil.ContextExecutor) (*AccountMatch, error) {
	o := &AccountMatch{}

	queries.SetLimit(q.Query, 1)

	err := q.Bind(ctx, exec, o)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "model: failed to execute a one query for account_match")
	}

	return o, nil
}

// All returns all AccountMatch records from the query.
func (q accountMatchQuery) All(ctx context.Context, exec boil.ContextExecutor) (AccountMatchSlice, error) {
	var o []*AccountMatch

	err := q.Bind(ctx, exec, &o)
	if err != nil {
		return nil, errors.Wrap(err, "model: failed to assign all query results to AccountMatch slice")
	}

	return o, nil
}

// Count returns the count of all AccountMatch records in the query.
func (q accountMatchQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)

	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "model: failed to count account_match rows")
	}

	return count, nil
}

// Exists checks if the row exists in the table.
func (q accountMatchQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
	var count int64

	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)

	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "model: failed to check if account_match exists")
	}

	return count > 0, nil
}

// DestinationAccount pointed to by the foreign key.
func (o *AccountMatch) DestinationAccount(mods ...qm.QueryMod) accountQuery {
	queryMods := []qm.QueryMod{
		qm.Where("\"id\" = ?", o.DestinationAccountID),
	}

	queryMods = append(queryMods, mods...)

	return Accounts(queryMods...)
}

// SourceAccount pointed to by the foreign key.
func (o *AccountMatch) SourceAccount(mods ...qm.QueryMod) accountQuery {
	queryMods := []qm.QueryMod{
		qm.Where("\"id\" = ?", o.SourceAccountID),
	}

	queryMods = append(queryMods, mods...)

	return Accounts(queryMods...)
}

// AccountMatchAttributes retrieves all the account_match_attribute's AccountMatchAttributes with an executor.
func (o *AccountMatch) AccountMatchAttributes(mods ...qm.QueryMod) accountMatchAttributeQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}

	queryMods = append(queryMods,
		qm.Where("\"account_match_attributes\".\"account_match_id\"=?", o.ID),
	)

	return AccountMatchAttributes(queryMods...)
}

// AccountMatchRegexes retrieves all the account_match_regex's AccountMatchRegexes with an executor.
func (o *AccountMatch) AccountMatchRegexes(mods ...qm.QueryMod) accountMatchRegexQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}

	queryMods = append(queryMods,
		qm.Where("\"account_match_regex\".\"account_match_id\"=?", o.ID),
	)

	return AccountMatchRegexes(queryMods...)
}

// LoadDestinationAccount allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (accountMatchL) LoadDestinationAccount(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccountMatch interface{}, mods queries.Applicator) error {
	var slice []*AccountMatch
	var object *AccountMatch

	if singular {
		var ok bool
		object, ok = maybeAccountMatch.(*AccountMatch)
		if !ok {
			object = new(AccountMatch)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccountMatch))
			}
		}
	} else {
		s, ok := maybeAccountMatch.(*[]*AccountMatch)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccountMatch))
			}
		}
	}

	args := make([]interface{}, 0, 1)
	if singular {
		if object.R == nil {
			object.R = &accountMatchR{}
		}
		args = append(args, object.DestinationAccountID)

	} else {
	Outer:
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &accountMatchR{}
			}

			for _, a := range args {
				if a == obj.DestinationAccountID {
					continue Outer
				}
			}

			args = append(args, obj.DestinationAccountID)

		}
	}

	if len(args) == 0 {
		return nil
	}

	query := NewQuery(
		qm.From(`account`),
		qm.WhereIn(`account.id in ?`, args...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load Account")
	}

	var resultSlice []*Account
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Account")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results of eager load for account")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for account")
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		foreign := resultSlice[0]
		object.R.DestinationAccount = foreign
		if foreign.R == nil {
			foreign.R = &accountR{}
		}
		foreign.R.DestinationAccountAccountMatches = append(foreign.R.DestinationAccountAccountMatches, object)
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.DestinationAccountID == foreign.ID {
				local.R.DestinationAccount = foreign
				if foreign.R == nil {
					foreign.R = &accountR{}
				}
				foreign.R.DestinationAccountAccountMatches = append(foreign.R.DestinationAccountAccountMatches, local)
				break
			}
		}
	}

	return nil
}

// LoadSourceAccount allows an eager lookup of values, cached into the
// loaded structs of the objects. This is for an N-1 relationship.
func (accountMatchL) LoadSourceAccount(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccountMatch interface{}, mods queries.Applicator) error {
	var slice []*AccountMatch
	var object *AccountMatch

	if singular {
		var ok bool
		object, ok = maybeAccountMatch.(*AccountMatch)
		if !ok {
			object = new(AccountMatch)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccountMatch))
			}
		}
	} else {
		s, ok := maybeAccountMatch.(*[]*AccountMatch)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccountMatch))
			}
		}
	}

	args := make([]interface{}, 0, 1)
	if singular {
		if object.R == nil {
			object.R = &accountMatchR{}
		}
		args = append(args, object.SourceAccountID)

	} else {
	Outer:
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &accountMatchR{}
			}

			for _, a := range args {
				if a == obj.SourceAccountID {
					continue Outer
				}
			}

			args = append(args, obj.SourceAccountID)

		}
	}

	if len(args) == 0 {
		return nil
	}

	query := NewQuery(
		qm.From(`account`),
		qm.WhereIn(`account.id in ?`, args...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load Account")
	}

	var resultSlice []*Account
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Account")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results of eager load for account")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for account")
	}

	if len(resultSlice) == 0 {
		return nil
	}

	if singular {
		foreign := resultSlice[0]
		object.R.SourceAccount = foreign
		if foreign.R == nil {
			foreign.R = &accountR{}
		}
		foreign.R.SourceAccountAccountMatches = append(foreign.R.SourceAccountAccountMatches, object)
		return nil
	}

	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.SourceAccountID == foreign.ID {
				local.R.SourceAccount = foreign
				if foreign.R == nil {
					foreign.R = &accountR{}
				}
				foreign.R.SourceAccountAccountMatches = append(foreign.R.SourceAccountAccountMatches, local)
				break
			}
		}
	}

	return nil
}

// LoadAccountMatchAttributes 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 (accountMatchL) LoadAccountMatchAttributes(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccountMatch interface{}, mods queries.Applicator) error {
	var slice []*AccountMatch
	var object *AccountMatch

	if singular {
		var ok bool
		object, ok = maybeAccountMatch.(*AccountMatch)
		if !ok {
			object = new(AccountMatch)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccountMatch))
			}
		}
	} else {
		s, ok := maybeAccountMatch.(*[]*AccountMatch)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccountMatch))
			}
		}
	}

	args := make([]interface{}, 0, 1)
	if singular {
		if object.R == nil {
			object.R = &accountMatchR{}
		}
		args = append(args, object.ID)
	} else {
	Outer:
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &accountMatchR{}
			}

			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(`account_match_attributes`),
		qm.WhereIn(`account_match_attributes.account_match_id in ?`, args...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load account_match_attributes")
	}

	var resultSlice []*AccountMatchAttribute
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice account_match_attributes")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results in eager load on account_match_attributes")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for account_match_attributes")
	}

	if singular {
		object.R.AccountMatchAttributes = resultSlice
		for _, foreign := range resultSlice {
			if foreign.R == nil {
				foreign.R = &accountMatchAttributeR{}
			}
			foreign.R.AccountMatch = object
		}
		return nil
	}

	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.AccountMatchID {
				local.R.AccountMatchAttributes = append(local.R.AccountMatchAttributes, foreign)
				if foreign.R == nil {
					foreign.R = &accountMatchAttributeR{}
				}
				foreign.R.AccountMatch = local
				break
			}
		}
	}

	return nil
}

// LoadAccountMatchRegexes 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 (accountMatchL) LoadAccountMatchRegexes(ctx context.Context, e boil.ContextExecutor, singular bool, maybeAccountMatch interface{}, mods queries.Applicator) error {
	var slice []*AccountMatch
	var object *AccountMatch

	if singular {
		var ok bool
		object, ok = maybeAccountMatch.(*AccountMatch)
		if !ok {
			object = new(AccountMatch)
			ok = queries.SetFromEmbeddedStruct(&object, &maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeAccountMatch))
			}
		}
	} else {
		s, ok := maybeAccountMatch.(*[]*AccountMatch)
		if ok {
			slice = *s
		} else {
			ok = queries.SetFromEmbeddedStruct(&slice, maybeAccountMatch)
			if !ok {
				return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeAccountMatch))
			}
		}
	}

	args := make([]interface{}, 0, 1)
	if singular {
		if object.R == nil {
			object.R = &accountMatchR{}
		}
		args = append(args, object.ID)
	} else {
	Outer:
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &accountMatchR{}
			}

			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(`account_match_regex`),
		qm.WhereIn(`account_match_regex.account_match_id in ?`, args...),
	)
	if mods != nil {
		mods.Apply(query)
	}

	results, err := query.QueryContext(ctx, e)
	if err != nil {
		return errors.Wrap(err, "failed to eager load account_match_regex")
	}

	var resultSlice []*AccountMatchRegex
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice account_match_regex")
	}

	if err = results.Close(); err != nil {
		return errors.Wrap(err, "failed to close results in eager load on account_match_regex")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for account_match_regex")
	}

	if singular {
		object.R.AccountMatchRegexes = resultSlice
		for _, foreign := range resultSlice {
			if foreign.R == nil {
				foreign.R = &accountMatchRegexR{}
			}
			foreign.R.AccountMatch = object
		}
		return nil
	}

	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.AccountMatchID {
				local.R.AccountMatchRegexes = append(local.R.AccountMatchRegexes, foreign)
				if foreign.R == nil {
					foreign.R = &accountMatchRegexR{}
				}
				foreign.R.AccountMatch = local
				break
			}
		}
	}

	return nil
}

// SetDestinationAccount of the accountMatch to the related item.
// Sets o.R.DestinationAccount to related.
// Adds o to related.R.DestinationAccountAccountMatches.
func (o *AccountMatch) SetDestinationAccount(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Account) error {
	var err error
	if insert {
		if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE \"account_match\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 0, []string{"destination_account_id"}),
		strmangle.WhereClause("\"", "\"", 0, accountMatchPrimaryKeyColumns),
	)
	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.DestinationAccountID = related.ID
	if o.R == nil {
		o.R = &accountMatchR{
			DestinationAccount: related,
		}
	} else {
		o.R.DestinationAccount = related
	}

	if related.R == nil {
		related.R = &accountR{
			DestinationAccountAccountMatches: AccountMatchSlice{o},
		}
	} else {
		related.R.DestinationAccountAccountMatches = append(related.R.DestinationAccountAccountMatches, o)
	}

	return nil
}

// SetSourceAccount of the accountMatch to the related item.
// Sets o.R.SourceAccount to related.
// Adds o to related.R.SourceAccountAccountMatches.
func (o *AccountMatch) SetSourceAccount(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Account) error {
	var err error
	if insert {
		if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}

	updateQuery := fmt.Sprintf(
		"UPDATE \"account_match\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 0, []string{"source_account_id"}),
		strmangle.WhereClause("\"", "\"", 0, accountMatchPrimaryKeyColumns),
	)
	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.SourceAccountID = related.ID
	if o.R == nil {
		o.R = &accountMatchR{
			SourceAccount: related,
		}
	} else {
		o.R.SourceAccount = related
	}

	if related.R == nil {
		related.R = &accountR{
			SourceAccountAccountMatches: AccountMatchSlice{o},
		}
	} else {
		related.R.SourceAccountAccountMatches = append(related.R.SourceAccountAccountMatches, o)
	}

	return nil
}

// AddAccountMatchAttributes adds the given related objects to the existing relationships
// of the account_match, optionally inserting them as new records.
// Appends related to o.R.AccountMatchAttributes.
// Sets related.R.AccountMatch appropriately.
func (o *AccountMatch) AddAccountMatchAttributes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AccountMatchAttribute) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.AccountMatchID = 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 \"account_match_attributes\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 0, []string{"account_match_id"}),
				strmangle.WhereClause("\"", "\"", 0, accountMatchAttributePrimaryKeyColumns),
			)
			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.AccountMatchID = o.ID
		}
	}

	if o.R == nil {
		o.R = &accountMatchR{
			AccountMatchAttributes: related,
		}
	} else {
		o.R.AccountMatchAttributes = append(o.R.AccountMatchAttributes, related...)
	}

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &accountMatchAttributeR{
				AccountMatch: o,
			}
		} else {
			rel.R.AccountMatch = o
		}
	}
	return nil
}

// AddAccountMatchRegexes adds the given related objects to the existing relationships
// of the account_match, optionally inserting them as new records.
// Appends related to o.R.AccountMatchRegexes.
// Sets related.R.AccountMatch appropriately.
func (o *AccountMatch) AddAccountMatchRegexes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*AccountMatchRegex) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.AccountMatchID = 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 \"account_match_regex\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 0, []string{"account_match_id"}),
				strmangle.WhereClause("\"", "\"", 0, accountMatchRegexPrimaryKeyColumns),
			)
			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.AccountMatchID = o.ID
		}
	}

	if o.R == nil {
		o.R = &accountMatchR{
			AccountMatchRegexes: related,
		}
	} else {
		o.R.AccountMatchRegexes = append(o.R.AccountMatchRegexes, related...)
	}

	for _, rel := range related {
		if rel.R == nil {
			rel.R = &accountMatchRegexR{
				AccountMatch: o,
			}
		} else {
			rel.R.AccountMatch = o
		}
	}
	return nil
}

// AccountMatches retrieves all the records using an executor.
func AccountMatches(mods ...qm.QueryMod) accountMatchQuery {
	mods = append(mods, qm.From("\"account_match\""))
	q := NewQuery(mods...)
	if len(queries.GetSelect(q)) == 0 {
		queries.SetSelect(q, []string{"\"account_match\".*"})
	}

	return accountMatchQuery{q}
}

// FindAccountMatch retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindAccountMatch(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*AccountMatch, error) {
	accountMatchObj := &AccountMatch{}

	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"account_match\" where \"id\"=?", sel,
	)

	q := queries.Raw(query, iD)

	err := q.Bind(ctx, exec, accountMatchObj)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "model: unable to select from account_match")
	}

	return accountMatchObj, nil
}

// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *AccountMatch) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("model: no account_match provided for insertion")
	}

	var err error

	nzDefaults := queries.NonZeroDefaultSet(accountMatchColumnsWithDefault, o)

	key := makeCacheKey(columns, nzDefaults)
	accountMatchInsertCacheMut.RLock()
	cache, cached := accountMatchInsertCache[key]
	accountMatchInsertCacheMut.RUnlock()

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			accountMatchAllColumns,
			accountMatchColumnsWithDefault,
			accountMatchColumnsWithoutDefault,
			nzDefaults,
		)
		wl = strmangle.SetComplement(wl, accountMatchGeneratedColumns)

		cache.valueMapping, err = queries.BindMapping(accountMatchType, accountMatchMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(accountMatchType, accountMatchMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"account_match\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"account_match\" %sDEFAULT VALUES%s"
		}

		var queryOutput, queryReturning string

		if len(cache.retMapping) != 0 {
			queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
		}

		cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, vals)
	}

	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}

	if err != nil {
		return errors.Wrap(err, "model: unable to insert into account_match")
	}

	if !cached {
		accountMatchInsertCacheMut.Lock()
		accountMatchInsertCache[key] = cache
		accountMatchInsertCacheMut.Unlock()
	}

	return nil
}

// Update uses an executor to update the AccountMatch.
// 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 *AccountMatch) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
	var err error
	key := makeCacheKey(columns, nil)
	accountMatchUpdateCacheMut.RLock()
	cache, cached := accountMatchUpdateCache[key]
	accountMatchUpdateCacheMut.RUnlock()

	if !cached {
		wl := columns.UpdateColumnSet(
			accountMatchAllColumns,
			accountMatchPrimaryKeyColumns,
		)
		wl = strmangle.SetComplement(wl, accountMatchGeneratedColumns)

		if len(wl) == 0 {
			return 0, errors.New("model: unable to update account_match, could not build whitelist")
		}

		cache.query = fmt.Sprintf("UPDATE \"account_match\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 0, wl),
			strmangle.WhereClause("\"", "\"", 0, accountMatchPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(accountMatchType, accountMatchMapping, append(wl, accountMatchPrimaryKeyColumns...))
		if err != nil {
			return 0, err
		}
	}

	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, values)
	}
	var result sql.Result
	result, err = exec.ExecContext(ctx, cache.query, values...)
	if err != nil {
		return 0, errors.Wrap(err, "model: unable to update account_match row")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "model: failed to get rows affected by update for account_match")
	}

	if !cached {
		accountMatchUpdateCacheMut.Lock()
		accountMatchUpdateCache[key] = cache
		accountMatchUpdateCacheMut.Unlock()
	}

	return rowsAff, nil
}

// UpdateAll updates all rows with the specified column values.
func (q accountMatchQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
	queries.SetUpdate(q.Query, cols)

	result, err := q.Query.ExecContext(ctx, exec)
	if err != nil {
		return 0, errors.Wrap(err, "model: unable to update all for account_match")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "model: unable to retrieve rows affected for account_match")
	}

	return rowsAff, nil
}

// UpdateAll updates all rows with the specified column values, using an executor.
func (o AccountMatchSlice) 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)), accountMatchPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := fmt.Sprintf("UPDATE \"account_match\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 0, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, accountMatchPrimaryKeyColumns, 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 accountMatch slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "model: unable to retrieve rows affected all in update all accountMatch")
	}
	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 *AccountMatch) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
	if o == nil {
		return errors.New("model: no account_match provided for upsert")
	}

	nzDefaults := queries.NonZeroDefaultSet(accountMatchColumnsWithDefault, 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)

	accountMatchUpsertCacheMut.RLock()
	cache, cached := accountMatchUpsertCache[key]
	accountMatchUpsertCacheMut.RUnlock()

	var err error

	if !cached {
		insert, ret := insertColumns.InsertColumnSet(
			accountMatchAllColumns,
			accountMatchColumnsWithDefault,
			accountMatchColumnsWithoutDefault,
			nzDefaults,
		)
		update := updateColumns.UpdateColumnSet(
			accountMatchAllColumns,
			accountMatchPrimaryKeyColumns,
		)

		if updateOnConflict && len(update) == 0 {
			return errors.New("model: unable to upsert account_match, could not build update column list")
		}

		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(accountMatchPrimaryKeyColumns))
			copy(conflict, accountMatchPrimaryKeyColumns)
		}
		cache.query = buildUpsertQuerySQLite(dialect, "\"account_match\"", updateOnConflict, ret, update, conflict, insert)

		cache.valueMapping, err = queries.BindMapping(accountMatchType, accountMatchMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(accountMatchType, accountMatchMapping, ret)
			if err != nil {
				return err
			}
		}
	}

	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	var returns []interface{}
	if len(cache.retMapping) != 0 {
		returns = queries.PtrsFromMapping(value, cache.retMapping)
	}

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, cache.query)
		fmt.Fprintln(writer, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
		if errors.Is(err, sql.ErrNoRows) {
			err = nil // Postgres doesn't return anything when there's no update
		}
	} else {
		_, err = exec.ExecContext(ctx, cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "model: unable to upsert account_match")
	}

	if !cached {
		accountMatchUpsertCacheMut.Lock()
		accountMatchUpsertCache[key] = cache
		accountMatchUpsertCacheMut.Unlock()
	}

	return nil
}

// Delete deletes a single AccountMatch record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *AccountMatch) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if o == nil {
		return 0, errors.New("model: no AccountMatch provided for delete")
	}

	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), accountMatchPrimaryKeyMapping)
	sql := "DELETE FROM \"account_match\" WHERE \"id\"=?"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, args...)
	}
	result, err := exec.ExecContext(ctx, sql, args...)
	if err != nil {
		return 0, errors.Wrap(err, "model: unable to delete from account_match")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "model: failed to get rows affected by delete for account_match")
	}

	return rowsAff, nil
}

// DeleteAll deletes all matching rows.
func (q accountMatchQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
	if q.Query == nil {
		return 0, errors.New("model: no accountMatchQuery provided for delete all")
	}

	queries.SetDelete(q.Query)

	result, err := q.Query.ExecContext(ctx, exec)
	if err != nil {
		return 0, errors.Wrap(err, "model: unable to delete all from account_match")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for account_match")
	}

	return rowsAff, nil
}

// DeleteAll deletes all rows in the slice, using an executor.
func (o AccountMatchSlice) 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)), accountMatchPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "DELETE FROM \"account_match\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, accountMatchPrimaryKeyColumns, 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 accountMatch slice")
	}

	rowsAff, err := result.RowsAffected()
	if err != nil {
		return 0, errors.Wrap(err, "model: failed to get rows affected by deleteall for account_match")
	}

	return rowsAff, nil
}

// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *AccountMatch) Reload(ctx context.Context, exec boil.ContextExecutor) error {
	ret, err := FindAccountMatch(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 *AccountMatchSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
	if o == nil || len(*o) == 0 {
		return nil
	}

	slice := AccountMatchSlice{}
	var args []interface{}
	for _, obj := range *o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), accountMatchPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}

	sql := "SELECT \"account_match\".* FROM \"account_match\" WHERE " +
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, accountMatchPrimaryKeyColumns, 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 AccountMatchSlice")
	}

	*o = slice

	return nil
}

// AccountMatchExists checks if the AccountMatch row exists.
func AccountMatchExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
	var exists bool
	sql := "select exists(select 1 from \"account_match\" where \"id\"=? limit 1)"

	if boil.IsDebug(ctx) {
		writer := boil.DebugWriterFrom(ctx)
		fmt.Fprintln(writer, sql)
		fmt.Fprintln(writer, iD)
	}
	row := exec.QueryRowContext(ctx, sql, iD)

	err := row.Scan(&exists)
	if err != nil {
		return false, errors.Wrap(err, "model: unable to check if account_match exists")
	}

	return exists, nil
}

// Exists checks if the AccountMatch row exists.
func (o *AccountMatch) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
	return AccountMatchExists(ctx, exec, o.ID)
}