func (o *ContentType) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
InsertG a single record. See Insert for whitelist behavior description.
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 ContentType struct {
	ID          int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
	Name        string      `boil:"name" json:"name" toml:"name" yaml:"name"`
	Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
	R *contentTypeR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L contentTypeL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var ContentTypeColumns = struct {
	ID          string
	Name        string
	Description string
}{
	ID:          "id",
	Name:        "name",
	Description: "description",
}
type contentTypeR struct {
	TypeCollections  CollectionSlice
	TypeContentUnits ContentUnitSlice
}
type contentTypeL struct{}
var (
	contentTypeColumns               = []string{"id", "name", "description"}
	contentTypeColumnsWithoutDefault = []string{"name", "description"}
	contentTypeColumnsWithDefault    = []string{"id"}
	contentTypePrimaryKeyColumns     = []string{"id"}
)
type (
	ContentTypeSlice []*ContentType
	contentTypeQuery struct {
		*queries.Query
	}
)
var (
	contentTypeType                 = reflect.TypeOf(&ContentType{})
	contentTypeMapping              = queries.MakeStructMapping(contentTypeType)
	contentTypePrimaryKeyMapping, _ = queries.BindMapping(contentTypeType, contentTypeMapping, contentTypePrimaryKeyColumns)
	contentTypeInsertCacheMut       sync.RWMutex
	contentTypeInsertCache          = make(map[string]insertCache)
	contentTypeUpdateCacheMut       sync.RWMutex
	contentTypeUpdateCache          = make(map[string]updateCache)
	contentTypeUpsertCacheMut       sync.RWMutex
	contentTypeUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q contentTypeQuery) OneP() *ContentType {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q contentTypeQuery) One() (*ContentType, error) {
	o := &ContentType{}
	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 content_types")
	}
	return o, nil
}
func (q contentTypeQuery) AllP() ContentTypeSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q contentTypeQuery) All() (ContentTypeSlice, error) {
	var o []*ContentType
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to ContentType slice")
	}
	return o, nil
}
func (q contentTypeQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q contentTypeQuery) 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 content_types rows")
	}
	return count, nil
}
func (q contentTypeQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q contentTypeQuery) 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 content_types exists")
	}
	return count > 0, nil
}
func (o *ContentType) TypeCollectionsG(mods ...qm.QueryMod) collectionQuery {
	return o.TypeCollections(boil.GetDB(), mods...)
}
func (o *ContentType) TypeCollections(exec boil.Executor, mods ...qm.QueryMod) collectionQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"collections\".\"type_id\"=?", o.ID),
	)
	query := Collections(exec, queryMods...)
	queries.SetFrom(query.Query, "\"collections\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"collections\".*"})
	}
	return query
}
func (o *ContentType) TypeContentUnitsG(mods ...qm.QueryMod) contentUnitQuery {
	return o.TypeContentUnits(boil.GetDB(), mods...)
}
func (o *ContentType) TypeContentUnits(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"content_units\".\"type_id\"=?", o.ID),
	)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"content_units\".*"})
	}
	return query
}
func (contentTypeL) LoadTypeCollections(e boil.Executor, singular bool, maybeContentType interface{}) error {
	var slice []*ContentType
	var object *ContentType
	count := 1
	if singular {
		object = maybeContentType.(*ContentType)
	} else {
		slice = *maybeContentType.(*[]*ContentType)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &contentTypeR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &contentTypeR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"collections\" where \"type_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")
	}
	defer results.Close()
	var resultSlice []*Collection
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice collections")
	}
	if singular {
		object.R.TypeCollections = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.TypeID {
				local.R.TypeCollections = append(local.R.TypeCollections, foreign)
				break
			}
		}
	}
	return nil
}
func (contentTypeL) LoadTypeContentUnits(e boil.Executor, singular bool, maybeContentType interface{}) error {
	var slice []*ContentType
	var object *ContentType
	count := 1
	if singular {
		object = maybeContentType.(*ContentType)
	} else {
		slice = *maybeContentType.(*[]*ContentType)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &contentTypeR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &contentTypeR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"content_units\" where \"type_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 content_units")
	}
	defer results.Close()
	var resultSlice []*ContentUnit
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice content_units")
	}
	if singular {
		object.R.TypeContentUnits = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.TypeID {
				local.R.TypeContentUnits = append(local.R.TypeContentUnits, foreign)
				break
			}
		}
	}
	return nil
}
func (o *ContentType) AddTypeCollectionsG(insert bool, related ...*Collection) error {
	return o.AddTypeCollections(boil.GetDB(), insert, related...)
}
func (o *ContentType) AddTypeCollectionsP(exec boil.Executor, insert bool, related ...*Collection) {
	if err := o.AddTypeCollections(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) AddTypeCollectionsGP(insert bool, related ...*Collection) {
	if err := o.AddTypeCollections(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) AddTypeCollections(exec boil.Executor, insert bool, related ...*Collection) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.TypeID = 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\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"type_id"}),
				strmangle.WhereClause("\"", "\"", 2, collectionPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, 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")
			}
			rel.TypeID = o.ID
		}
	}
	if o.R == nil {
		o.R = &contentTypeR{
			TypeCollections: related,
		}
	} else {
		o.R.TypeCollections = append(o.R.TypeCollections, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &collectionR{
				Type: o,
			}
		} else {
			rel.R.Type = o
		}
	}
	return nil
}
func (o *ContentType) AddTypeContentUnitsG(insert bool, related ...*ContentUnit) error {
	return o.AddTypeContentUnits(boil.GetDB(), insert, related...)
}
func (o *ContentType) AddTypeContentUnitsP(exec boil.Executor, insert bool, related ...*ContentUnit) {
	if err := o.AddTypeContentUnits(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) AddTypeContentUnitsGP(insert bool, related ...*ContentUnit) {
	if err := o.AddTypeContentUnits(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) AddTypeContentUnits(exec boil.Executor, insert bool, related ...*ContentUnit) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.TypeID = o.ID
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"content_units\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"type_id"}),
				strmangle.WhereClause("\"", "\"", 2, contentUnitPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, 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")
			}
			rel.TypeID = o.ID
		}
	}
	if o.R == nil {
		o.R = &contentTypeR{
			TypeContentUnits: related,
		}
	} else {
		o.R.TypeContentUnits = append(o.R.TypeContentUnits, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &contentUnitR{
				Type: o,
			}
		} else {
			rel.R.Type = o
		}
	}
	return nil
}
func ContentTypesG(mods ...qm.QueryMod) contentTypeQuery {
	return ContentTypes(boil.GetDB(), mods...)
}
func ContentTypes(exec boil.Executor, mods ...qm.QueryMod) contentTypeQuery {
	mods = append(mods, qm.From("\"content_types\""))
	return contentTypeQuery{NewQuery(exec, mods...)}
}
func FindContentTypeG(id int64, selectCols ...string) (*ContentType, error) {
	return FindContentType(boil.GetDB(), id, selectCols...)
}
func FindContentTypeGP(id int64, selectCols ...string) *ContentType {
	retobj, err := FindContentType(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindContentType(exec boil.Executor, id int64, selectCols ...string) (*ContentType, error) {
	contentTypeObj := &ContentType{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"content_types\" where \"id\"=$1", sel,
	)
	q := queries.Raw(exec, query, id)
	err := q.Bind(contentTypeObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from content_types")
	}
	return contentTypeObj, nil
}
func FindContentTypeP(exec boil.Executor, id int64, selectCols ...string) *ContentType {
	retobj, err := FindContentType(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}