func (o *Block) InsertGP(columns boil.Columns) {
	if err := o.Insert(boil.GetDB(), columns); err != nil {
		panic(boil.WrapErr(err))
	}
}
InsertGP a single record, and panics on error. See Insert for whitelist
behavior description.
package model
import (
	"database/sql"
	"fmt"
	"reflect"
	"strconv"
	"strings"
	"sync"
	"time"
	"github.com/pkg/errors"
	"github.com/volatiletech/null"
	"github.com/volatiletech/sqlboiler/boil"
	"github.com/volatiletech/sqlboiler/queries"
	"github.com/volatiletech/sqlboiler/queries/qm"
	"github.com/volatiletech/sqlboiler/queries/qmhelper"
	"github.com/volatiletech/sqlboiler/strmangle"
)
type Block struct {
	ID                    uint64      `boil:"id" json:"id" toml:"id" yaml:"id"`
	Bits                  string      `boil:"bits" json:"bits" toml:"bits" yaml:"bits"`
	Chainwork             string      `boil:"chainwork" json:"chainwork" toml:"chainwork" yaml:"chainwork"`
	Confirmations         uint        `boil:"confirmations" json:"confirmations" toml:"confirmations" yaml:"confirmations"`
	Difficulty            float64     `boil:"difficulty" json:"difficulty" toml:"difficulty" yaml:"difficulty"`
	Hash                  string      `boil:"hash" json:"hash" toml:"hash" yaml:"hash"`
	Height                uint64      `boil:"height" json:"height" toml:"height" yaml:"height"`
	MerkleRoot            string      `boil:"merkle_root" json:"merkle_root" toml:"merkle_root" yaml:"merkle_root"`
	NameClaimRoot         string      `boil:"name_claim_root" json:"name_claim_root" toml:"name_claim_root" yaml:"name_claim_root"`
	Nonce                 uint64      `boil:"nonce" json:"nonce" toml:"nonce" yaml:"nonce"`
	PreviousBlockHash     null.String `boil:"previous_block_hash" json:"previous_block_hash,omitempty" toml:"previous_block_hash" yaml:"previous_block_hash,omitempty"`
	NextBlockHash         null.String `boil:"next_block_hash" json:"next_block_hash,omitempty" toml:"next_block_hash" yaml:"next_block_hash,omitempty"`
	BlockSize             uint64      `boil:"block_size" json:"block_size" toml:"block_size" yaml:"block_size"`
	BlockTime             uint64      `boil:"block_time" json:"block_time" toml:"block_time" yaml:"block_time"`
	Version               uint64      `boil:"version" json:"version" toml:"version" yaml:"version"`
	VersionHex            string      `boil:"version_hex" json:"version_hex" toml:"version_hex" yaml:"version_hex"`
	TransactionHashes     null.String `boil:"transaction_hashes" json:"transaction_hashes,omitempty" toml:"transaction_hashes" yaml:"transaction_hashes,omitempty"`
	TransactionsProcessed bool        `boil:"transactions_processed" json:"transactions_processed" toml:"transactions_processed" yaml:"transactions_processed"`
	CreatedAt             time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	ModifiedAt            time.Time   `boil:"modified_at" json:"modified_at" toml:"modified_at" yaml:"modified_at"`
	R *blockR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L blockL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var BlockColumns = struct {
	ID                    string
	Bits                  string
	Chainwork             string
	Confirmations         string
	Difficulty            string
	Hash                  string
	Height                string
	MerkleRoot            string
	NameClaimRoot         string
	Nonce                 string
	PreviousBlockHash     string
	NextBlockHash         string
	BlockSize             string
	BlockTime             string
	Version               string
	VersionHex            string
	TransactionHashes     string
	TransactionsProcessed string
	CreatedAt             string
	ModifiedAt            string
}{
	ID:                    "id",
	Bits:                  "bits",
	Chainwork:             "chainwork",
	Confirmations:         "confirmations",
	Difficulty:            "difficulty",
	Hash:                  "hash",
	Height:                "height",
	MerkleRoot:            "merkle_root",
	NameClaimRoot:         "name_claim_root",
	Nonce:                 "nonce",
	PreviousBlockHash:     "previous_block_hash",
	NextBlockHash:         "next_block_hash",
	BlockSize:             "block_size",
	BlockTime:             "block_time",
	Version:               "version",
	VersionHex:            "version_hex",
	TransactionHashes:     "transaction_hashes",
	TransactionsProcessed: "transactions_processed",
	CreatedAt:             "created_at",
	ModifiedAt:            "modified_at",
}
var BlockWhere = struct {
	ID                    whereHelperuint64
	Bits                  whereHelperstring
	Chainwork             whereHelperstring
	Confirmations         whereHelperuint
	Difficulty            whereHelperfloat64
	Hash                  whereHelperstring
	Height                whereHelperuint64
	MerkleRoot            whereHelperstring
	NameClaimRoot         whereHelperstring
	Nonce                 whereHelperuint64
	PreviousBlockHash     whereHelpernull_String
	NextBlockHash         whereHelpernull_String
	BlockSize             whereHelperuint64
	BlockTime             whereHelperuint64
	Version               whereHelperuint64
	VersionHex            whereHelperstring
	TransactionHashes     whereHelpernull_String
	TransactionsProcessed whereHelperbool
	CreatedAt             whereHelpertime_Time
	ModifiedAt            whereHelpertime_Time
}{
	ID:                    whereHelperuint64{field: "`block`.`id`"},
	Bits:                  whereHelperstring{field: "`block`.`bits`"},
	Chainwork:             whereHelperstring{field: "`block`.`chainwork`"},
	Confirmations:         whereHelperuint{field: "`block`.`confirmations`"},
	Difficulty:            whereHelperfloat64{field: "`block`.`difficulty`"},
	Hash:                  whereHelperstring{field: "`block`.`hash`"},
	Height:                whereHelperuint64{field: "`block`.`height`"},
	MerkleRoot:            whereHelperstring{field: "`block`.`merkle_root`"},
	NameClaimRoot:         whereHelperstring{field: "`block`.`name_claim_root`"},
	Nonce:                 whereHelperuint64{field: "`block`.`nonce`"},
	PreviousBlockHash:     whereHelpernull_String{field: "`block`.`previous_block_hash`"},
	NextBlockHash:         whereHelpernull_String{field: "`block`.`next_block_hash`"},
	BlockSize:             whereHelperuint64{field: "`block`.`block_size`"},
	BlockTime:             whereHelperuint64{field: "`block`.`block_time`"},
	Version:               whereHelperuint64{field: "`block`.`version`"},
	VersionHex:            whereHelperstring{field: "`block`.`version_hex`"},
	TransactionHashes:     whereHelpernull_String{field: "`block`.`transaction_hashes`"},
	TransactionsProcessed: whereHelperbool{field: "`block`.`transactions_processed`"},
	CreatedAt:             whereHelpertime_Time{field: "`block`.`created_at`"},
	ModifiedAt:            whereHelpertime_Time{field: "`block`.`modified_at`"},
}
var BlockRels = struct {
	BlockHashTransactions string
}{
	BlockHashTransactions: "BlockHashTransactions",
}
type blockR struct {
	BlockHashTransactions TransactionSlice
}
func (*blockR) NewStruct() *blockR {
	return &blockR{}
}
type blockL struct{}
var (
	blockAllColumns            = []string{"id", "bits", "chainwork", "confirmations", "difficulty", "hash", "height", "merkle_root", "name_claim_root", "nonce", "previous_block_hash", "next_block_hash", "block_size", "block_time", "version", "version_hex", "transaction_hashes", "transactions_processed", "created_at", "modified_at"}
	blockColumnsWithoutDefault = []string{"bits", "chainwork", "confirmations", "difficulty", "hash", "height", "merkle_root", "name_claim_root", "nonce", "previous_block_hash", "next_block_hash", "block_size", "block_time", "version", "version_hex", "transaction_hashes"}
	blockColumnsWithDefault    = []string{"id", "transactions_processed", "created_at", "modified_at"}
	blockPrimaryKeyColumns     = []string{"id"}
)
type (
	BlockSlice []*Block
	blockQuery struct {
		*queries.Query
	}
)
var (
	blockType                 = reflect.TypeOf(&Block{})
	blockMapping              = queries.MakeStructMapping(blockType)
	blockPrimaryKeyMapping, _ = queries.BindMapping(blockType, blockMapping, blockPrimaryKeyColumns)
	blockInsertCacheMut       sync.RWMutex
	blockInsertCache          = make(map[string]insertCache)
	blockUpdateCacheMut       sync.RWMutex
	blockUpdateCache          = make(map[string]updateCache)
	blockUpsertCacheMut       sync.RWMutex
	blockUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = qmhelper.Where
)
func (q blockQuery) OneG() (*Block, error) {
	return q.One(boil.GetDB())
}
func (q blockQuery) OneGP() *Block {
	o, err := q.One(boil.GetDB())
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q blockQuery) OneP(exec boil.Executor) *Block {
	o, err := q.One(exec)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q blockQuery) One(exec boil.Executor) (*Block, error) {
	o := &Block{}
	queries.SetLimit(q.Query, 1)
	err := q.Bind(nil, exec, o)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "model: failed to execute a one query for block")
	}
	return o, nil
}
func (q blockQuery) AllG() (BlockSlice, error) {
	return q.All(boil.GetDB())
}
func (q blockQuery) AllGP() BlockSlice {
	o, err := q.All(boil.GetDB())
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q blockQuery) AllP(exec boil.Executor) BlockSlice {
	o, err := q.All(exec)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q blockQuery) All(exec boil.Executor) (BlockSlice, error) {
	var o []*Block
	err := q.Bind(nil, exec, &o)
	if err != nil {
		return nil, errors.Wrap(err, "model: failed to assign all query results to Block slice")
	}
	return o, nil
}
func (q blockQuery) CountG() (int64, error) {
	return q.Count(boil.GetDB())
}
func (q blockQuery) CountGP() int64 {
	c, err := q.Count(boil.GetDB())
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q blockQuery) CountP(exec boil.Executor) int64 {
	c, err := q.Count(exec)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q blockQuery) Count(exec boil.Executor) (int64, error) {
	var count int64
	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	err := q.Query.QueryRow(exec).Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "model: failed to count block rows")
	}
	return count, nil
}
func (q blockQuery) ExistsG() (bool, error) {
	return q.Exists(boil.GetDB())
}
func (q blockQuery) ExistsGP() bool {
	e, err := q.Exists(boil.GetDB())
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q blockQuery) ExistsP(exec boil.Executor) bool {
	e, err := q.Exists(exec)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q blockQuery) Exists(exec boil.Executor) (bool, error) {
	var count int64
	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)
	err := q.Query.QueryRow(exec).Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "model: failed to check if block exists")
	}
	return count > 0, nil
}
func (o *Block) BlockHashTransactions(mods ...qm.QueryMod) transactionQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("`transaction`.`block_hash_id`=?", o.Hash),
	)
	query := Transactions(queryMods...)
	queries.SetFrom(query.Query, "`transaction`")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"`transaction`.*"})
	}
	return query
}
func (blockL) LoadBlockHashTransactions(e boil.Executor, singular bool, maybeBlock interface{}, mods queries.Applicator) error {
	var slice []*Block
	var object *Block
	if singular {
		object = maybeBlock.(*Block)
	} else {
		slice = *maybeBlock.(*[]*Block)
	}
	args := make([]interface{}, 0, 1)
	if singular {
		if object.R == nil {
			object.R = &blockR{}
		}
		args = append(args, object.Hash)
	} else {
	Outer:
		for _, obj := range slice {
			if obj.R == nil {
				obj.R = &blockR{}
			}
			for _, a := range args {
				if queries.Equal(a, obj.Hash) {
					continue Outer
				}
			}
			args = append(args, obj.Hash)
		}
	}
	if len(args) == 0 {
		return nil
	}
	query := NewQuery(qm.From(`transaction`), qm.WhereIn(`block_hash_id in ?`, args...))
	if mods != nil {
		mods.Apply(query)
	}
	results, err := query.Query(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 in eager load on transaction")
	}
	if err = results.Err(); err != nil {
		return errors.Wrap(err, "error occurred during iteration of eager loaded relations for transaction")
	}
	if singular {
		object.R.BlockHashTransactions = resultSlice
		for _, foreign := range resultSlice {
			if foreign.R == nil {
				foreign.R = &transactionR{}
			}
			foreign.R.BlockHash = object
		}
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if queries.Equal(local.Hash, foreign.BlockHashID) {
				local.R.BlockHashTransactions = append(local.R.BlockHashTransactions, foreign)
				if foreign.R == nil {
					foreign.R = &transactionR{}
				}
				foreign.R.BlockHash = local
				break
			}
		}
	}
	return nil
}
func (o *Block) AddBlockHashTransactionsG(insert bool, related ...*Transaction) error {
	return o.AddBlockHashTransactions(boil.GetDB(), insert, related...)
}
func (o *Block) AddBlockHashTransactionsP(exec boil.Executor, insert bool, related ...*Transaction) {
	if err := o.AddBlockHashTransactions(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Block) AddBlockHashTransactionsGP(insert bool, related ...*Transaction) {
	if err := o.AddBlockHashTransactions(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Block) AddBlockHashTransactions(exec boil.Executor, insert bool, related ...*Transaction) error {
	var err error
	for _, rel := range related {
		if insert {
			queries.Assign(&rel.BlockHashID, o.Hash)
			if err = rel.Insert(exec, boil.Infer()); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE `transaction` SET %s WHERE %s",
				strmangle.SetParamNames("`", "`", 0, []string{"block_hash_id"}),
				strmangle.WhereClause("`", "`", 0, transactionPrimaryKeyColumns),
			)
			values := []interface{}{o.Hash, rel.ID}
			if boil.DebugMode {
				fmt.Fprintln(boil.DebugWriter, updateQuery)
				fmt.Fprintln(boil.DebugWriter, values)
			}
			if _, err = exec.Exec(updateQuery, values...); err != nil {
				return errors.Wrap(err, "failed to update foreign table")
			}
			queries.Assign(&rel.BlockHashID, o.Hash)
		}
	}
	if o.R == nil {
		o.R = &blockR{
			BlockHashTransactions: related,
		}
	} else {
		o.R.BlockHashTransactions = append(o.R.BlockHashTransactions, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &transactionR{
				BlockHash: o,
			}
		} else {
			rel.R.BlockHash = o
		}
	}
	return nil
}
func (o *Block) SetBlockHashTransactionsG(insert bool, related ...*Transaction) error {
	return o.SetBlockHashTransactions(boil.GetDB(), insert, related...)
}
func (o *Block) SetBlockHashTransactionsP(exec boil.Executor, insert bool, related ...*Transaction) {
	if err := o.SetBlockHashTransactions(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Block) SetBlockHashTransactionsGP(insert bool, related ...*Transaction) {
	if err := o.SetBlockHashTransactions(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Block) SetBlockHashTransactions(exec boil.Executor, insert bool, related ...*Transaction) error {
	query := "update `transaction` set `block_hash_id` = null where `block_hash_id` = ?"
	values := []interface{}{o.Hash}
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, query)
		fmt.Fprintln(boil.DebugWriter, values)
	}
	_, err := exec.Exec(query, values...)
	if err != nil {
		return errors.Wrap(err, "failed to remove relationships before set")
	}
	if o.R != nil {
		for _, rel := range o.R.BlockHashTransactions {
			queries.SetScanner(&rel.BlockHashID, nil)
			if rel.R == nil {
				continue
			}
			rel.R.BlockHash = nil
		}
		o.R.BlockHashTransactions = nil
	}
	return o.AddBlockHashTransactions(exec, insert, related...)
}
func (o *Block) RemoveBlockHashTransactionsG(related ...*Transaction) error {
	return o.RemoveBlockHashTransactions(boil.GetDB(), related...)
}
func (o *Block) RemoveBlockHashTransactionsP(exec boil.Executor, related ...*Transaction) {
	if err := o.RemoveBlockHashTransactions(exec, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Block) RemoveBlockHashTransactionsGP(related ...*Transaction) {
	if err := o.RemoveBlockHashTransactions(boil.GetDB(), related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Block) RemoveBlockHashTransactions(exec boil.Executor, related ...*Transaction) error {
	var err error
	for _, rel := range related {
		queries.SetScanner(&rel.BlockHashID, nil)
		if rel.R != nil {
			rel.R.BlockHash = nil
		}
		if err = rel.Update(exec, boil.Whitelist("block_hash_id")); err != nil {
			return err
		}
	}
	if o.R == nil {
		return nil
	}
	for _, rel := range related {
		for i, ri := range o.R.BlockHashTransactions {
			if rel != ri {
				continue
			}
			ln := len(o.R.BlockHashTransactions)
			if ln > 1 && i < ln-1 {
				o.R.BlockHashTransactions[i] = o.R.BlockHashTransactions[ln-1]
			}
			o.R.BlockHashTransactions = o.R.BlockHashTransactions[:ln-1]
			break
		}
	}
	return nil
}
func Blocks(mods ...qm.QueryMod) blockQuery {
	mods = append(mods, qm.From("`block`"))
	return blockQuery{NewQuery(mods...)}
}
func FindBlockG(iD uint64, selectCols ...string) (*Block, error) {
	return FindBlock(boil.GetDB(), iD, selectCols...)
}
func FindBlockP(exec boil.Executor, iD uint64, selectCols ...string) *Block {
	retobj, err := FindBlock(exec, iD, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindBlockGP(iD uint64, selectCols ...string) *Block {
	retobj, err := FindBlock(boil.GetDB(), iD, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindBlock(exec boil.Executor, iD uint64, selectCols ...string) (*Block, error) {
	blockObj := &Block{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from `block` where `id`=?", sel,
	)
	q := queries.Raw(query, iD)
	err := q.Bind(nil, exec, blockObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "model: unable to select from block")
	}
	return blockObj, nil
}
func (o *Block) InsertG(columns boil.Columns) error {
	return o.Insert(boil.GetDB(), columns)
}
func (o *Block) InsertP(exec boil.Executor, columns boil.Columns) {
	if err := o.Insert(exec, columns); err != nil {
		panic(boil.WrapErr(err))
	}
}