func FindCollectionG(id int64, selectCols ...string) (*Collection, error) {
	return FindCollection(boil.GetDB(), id, selectCols...)
}
FindCollectionG retrieves a single record by ID.
package mdbmodels
import (
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"sync"
	"time"
	"github.com/Bnei-Baruch/sqlboiler/boil"
	"github.com/Bnei-Baruch/sqlboiler/queries"
	"github.com/Bnei-Baruch/sqlboiler/queries/qm"
	"github.com/Bnei-Baruch/sqlboiler/strmangle"
	"github.com/pkg/errors"
	"gopkg.in/volatiletech/null.v6"
)
type Collection struct {
	ID         int64     `boil:"id" json:"id" toml:"id" yaml:"id"`
	UID        string    `boil:"uid" json:"uid" toml:"uid" yaml:"uid"`
	TypeID     int64     `boil:"type_id" json:"type_id" toml:"type_id" yaml:"type_id"`
	CreatedAt  time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	Properties null.JSON `boil:"properties" json:"properties,omitempty" toml:"properties" yaml:"properties,omitempty"`
	Secure     int16     `boil:"secure" json:"secure" toml:"secure" yaml:"secure"`
	Published  bool      `boil:"published" json:"published" toml:"published" yaml:"published"`
	R *collectionR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L collectionL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var CollectionColumns = struct {
	ID         string
	UID        string
	TypeID     string
	CreatedAt  string
	Properties string
	Secure     string
	Published  string
}{
	ID:         "id",
	UID:        "uid",
	TypeID:     "type_id",
	CreatedAt:  "created_at",
	Properties: "properties",
	Secure:     "secure",
	Published:  "published",
}
type collectionR struct {
	Type                    *ContentType
	CollectionI18ns         CollectionI18nSlice
	CollectionsContentUnits CollectionsContentUnitSlice
}
type collectionL struct{}
var (
	collectionColumns               = []string{"id", "uid", "type_id", "created_at", "properties", "secure", "published"}
	collectionColumnsWithoutDefault = []string{"uid", "type_id", "properties"}
	collectionColumnsWithDefault    = []string{"id", "created_at", "secure", "published"}
	collectionPrimaryKeyColumns     = []string{"id"}
)
type (
	CollectionSlice []*Collection
	collectionQuery struct {
		*queries.Query
	}
)
var (
	collectionType                 = reflect.TypeOf(&Collection{})
	collectionMapping              = queries.MakeStructMapping(collectionType)
	collectionPrimaryKeyMapping, _ = queries.BindMapping(collectionType, collectionMapping, collectionPrimaryKeyColumns)
	collectionInsertCacheMut       sync.RWMutex
	collectionInsertCache          = make(map[string]insertCache)
	collectionUpdateCacheMut       sync.RWMutex
	collectionUpdateCache          = make(map[string]updateCache)
	collectionUpsertCacheMut       sync.RWMutex
	collectionUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q collectionQuery) OneP() *Collection {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q collectionQuery) One() (*Collection, error) {
	o := &Collection{}
	queries.SetLimit(q.Query, 1)
	err := q.Bind(o)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: failed to execute a one query for collections")
	}
	return o, nil
}
func (q collectionQuery) AllP() CollectionSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q collectionQuery) All() (CollectionSlice, error) {
	var o []*Collection
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to Collection slice")
	}
	return o, nil
}
func (q collectionQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q collectionQuery) Count() (int64, error) {
	var count int64
	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "mdbmodels: failed to count collections rows")
	}
	return count, nil
}
func (q collectionQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q collectionQuery) Exists() (bool, error) {
	var count int64
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)
	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "mdbmodels: failed to check if collections exists")
	}
	return count > 0, nil
}
func (o *Collection) TypeG(mods ...qm.QueryMod) contentTypeQuery {
	return o.Type(boil.GetDB(), mods...)
}
func (o *Collection) Type(exec boil.Executor, mods ...qm.QueryMod) contentTypeQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.TypeID),
	}
	queryMods = append(queryMods, mods...)
	query := ContentTypes(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_types\"")
	return query
}
func (o *Collection) CollectionI18nsG(mods ...qm.QueryMod) collectionI18nQuery {
	return o.CollectionI18ns(boil.GetDB(), mods...)
}
func (o *Collection) CollectionI18ns(exec boil.Executor, mods ...qm.QueryMod) collectionI18nQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"collection_i18n\".\"collection_id\"=?", o.ID),
	)
	query := CollectionI18ns(exec, queryMods...)
	queries.SetFrom(query.Query, "\"collection_i18n\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"collection_i18n\".*"})
	}
	return query
}
func (o *Collection) CollectionsContentUnitsG(mods ...qm.QueryMod) collectionsContentUnitQuery {
	return o.CollectionsContentUnits(boil.GetDB(), mods...)
}
func (o *Collection) CollectionsContentUnits(exec boil.Executor, mods ...qm.QueryMod) collectionsContentUnitQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"collections_content_units\".\"collection_id\"=?", o.ID),
	)
	query := CollectionsContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"collections_content_units\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"collections_content_units\".*"})
	}
	return query
}
func (collectionL) LoadType(e boil.Executor, singular bool, maybeCollection interface{}) error {
	var slice []*Collection
	var object *Collection
	count := 1
	if singular {
		object = maybeCollection.(*Collection)
	} else {
		slice = *maybeCollection.(*[]*Collection)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &collectionR{}
		}
		args[0] = object.TypeID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &collectionR{}
			}
			args[i] = obj.TypeID
		}
	}
	query := fmt.Sprintf(
		"select * from \"content_types\" where \"id\" in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)
	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}
	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load ContentType")
	}
	defer results.Close()
	var resultSlice []*ContentType
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice ContentType")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Type = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.TypeID == foreign.ID {
				local.R.Type = foreign
				break
			}
		}
	}
	return nil
}
func (collectionL) LoadCollectionI18ns(e boil.Executor, singular bool, maybeCollection interface{}) error {
	var slice []*Collection
	var object *Collection
	count := 1
	if singular {
		object = maybeCollection.(*Collection)
	} else {
		slice = *maybeCollection.(*[]*Collection)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &collectionR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &collectionR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"collection_i18n\" where \"collection_id\" in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)
	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}
	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load collection_i18n")
	}
	defer results.Close()
	var resultSlice []*CollectionI18n
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice collection_i18n")
	}
	if singular {
		object.R.CollectionI18ns = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.CollectionID {
				local.R.CollectionI18ns = append(local.R.CollectionI18ns, foreign)
				break
			}
		}
	}
	return nil
}
func (collectionL) LoadCollectionsContentUnits(e boil.Executor, singular bool, maybeCollection interface{}) error {
	var slice []*Collection
	var object *Collection
	count := 1
	if singular {
		object = maybeCollection.(*Collection)
	} else {
		slice = *maybeCollection.(*[]*Collection)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &collectionR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &collectionR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"collections_content_units\" where \"collection_id\" in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)
	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}
	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load collections_content_units")
	}
	defer results.Close()
	var resultSlice []*CollectionsContentUnit
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice collections_content_units")
	}
	if singular {
		object.R.CollectionsContentUnits = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.CollectionID {
				local.R.CollectionsContentUnits = append(local.R.CollectionsContentUnits, foreign)
				break
			}
		}
	}
	return nil
}
func (o *Collection) SetTypeG(insert bool, related *ContentType) error {
	return o.SetType(boil.GetDB(), insert, related)
}
func (o *Collection) SetTypeP(exec boil.Executor, insert bool, related *ContentType) {
	if err := o.SetType(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Collection) SetTypeGP(insert bool, related *ContentType) {
	if err := o.SetType(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Collection) SetType(exec boil.Executor, insert bool, related *ContentType) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}
	updateQuery := fmt.Sprintf(
		"UPDATE \"collections\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"type_id"}),
		strmangle.WhereClause("\"", "\"", 2, collectionPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.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 local table")
	}
	o.TypeID = related.ID
	if o.R == nil {
		o.R = &collectionR{
			Type: related,
		}
	} else {
		o.R.Type = related
	}
	if related.R == nil {
		related.R = &contentTypeR{
			TypeCollections: CollectionSlice{o},
		}
	} else {
		related.R.TypeCollections = append(related.R.TypeCollections, o)
	}
	return nil
}
func (o *Collection) AddCollectionI18nsG(insert bool, related ...*CollectionI18n) error {
	return o.AddCollectionI18ns(boil.GetDB(), insert, related...)
}
func (o *Collection) AddCollectionI18nsP(exec boil.Executor, insert bool, related ...*CollectionI18n) {
	if err := o.AddCollectionI18ns(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Collection) AddCollectionI18nsGP(insert bool, related ...*CollectionI18n) {
	if err := o.AddCollectionI18ns(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Collection) AddCollectionI18ns(exec boil.Executor, insert bool, related ...*CollectionI18n) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.CollectionID = o.ID
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"collection_i18n\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"collection_id"}),
				strmangle.WhereClause("\"", "\"", 2, collectionI18nPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, rel.CollectionID, rel.Language}
			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")
			}
			rel.CollectionID = o.ID
		}
	}
	if o.R == nil {
		o.R = &collectionR{
			CollectionI18ns: related,
		}
	} else {
		o.R.CollectionI18ns = append(o.R.CollectionI18ns, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &collectionI18nR{
				Collection: o,
			}
		} else {
			rel.R.Collection = o
		}
	}
	return nil
}
func (o *Collection) AddCollectionsContentUnitsG(insert bool, related ...*CollectionsContentUnit) error {
	return o.AddCollectionsContentUnits(boil.GetDB(), insert, related...)
}
func (o *Collection) AddCollectionsContentUnitsP(exec boil.Executor, insert bool, related ...*CollectionsContentUnit) {
	if err := o.AddCollectionsContentUnits(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Collection) AddCollectionsContentUnitsGP(insert bool, related ...*CollectionsContentUnit) {
	if err := o.AddCollectionsContentUnits(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Collection) AddCollectionsContentUnits(exec boil.Executor, insert bool, related ...*CollectionsContentUnit) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.CollectionID = o.ID
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"collections_content_units\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"collection_id"}),
				strmangle.WhereClause("\"", "\"", 2, collectionsContentUnitPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, rel.CollectionID, rel.ContentUnitID}
			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")
			}
			rel.CollectionID = o.ID
		}
	}
	if o.R == nil {
		o.R = &collectionR{
			CollectionsContentUnits: related,
		}
	} else {
		o.R.CollectionsContentUnits = append(o.R.CollectionsContentUnits, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &collectionsContentUnitR{
				Collection: o,
			}
		} else {
			rel.R.Collection = o
		}
	}
	return nil
}
func CollectionsG(mods ...qm.QueryMod) collectionQuery {
	return Collections(boil.GetDB(), mods...)
}
func Collections(exec boil.Executor, mods ...qm.QueryMod) collectionQuery {
	mods = append(mods, qm.From("\"collections\""))
	return collectionQuery{NewQuery(exec, mods...)}
}