func (o *ContentType) UpsertGP(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) {
	if err := o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
UpsertGP attempts an insert, and does an update or ignore on conflict. Panics on error.
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
}
func (o *ContentType) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *ContentType) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no content_types provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(contentTypeColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	contentTypeInsertCacheMut.RLock()
	cache, cached := contentTypeInsertCache[key]
	contentTypeInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			contentTypeColumns,
			contentTypeColumnsWithDefault,
			contentTypeColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(contentTypeType, contentTypeMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(contentTypeType, contentTypeMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"content_types\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"content_types\" DEFAULT VALUES"
		}
		var queryOutput, queryReturning string
		if len(cache.retMapping) != 0 {
			queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
		}
	}
	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	} else {
		_, err = exec.Exec(cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to insert into content_types")
	}
	if !cached {
		contentTypeInsertCacheMut.Lock()
		contentTypeInsertCache[key] = cache
		contentTypeInsertCacheMut.Unlock()
	}
	return nil
}
func (o *ContentType) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}
func (o *ContentType) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentType) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	contentTypeUpdateCacheMut.RLock()
	cache, cached := contentTypeUpdateCache[key]
	contentTypeUpdateCacheMut.RUnlock()
	if !cached {
		wl := strmangle.UpdateColumnSet(
			contentTypeColumns,
			contentTypePrimaryKeyColumns,
			whitelist,
		)
		if len(wl) == 0 {
			return errors.New("mdbmodels: unable to update content_types, could not build whitelist")
		}
		cache.query = fmt.Sprintf("UPDATE \"content_types\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, contentTypePrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(contentTypeType, contentTypeMapping, append(wl, contentTypePrimaryKeyColumns...))
		if err != nil {
			return err
		}
	}
	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, values)
	}
	_, err = exec.Exec(cache.query, values...)
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to update content_types row")
	}
	if !cached {
		contentTypeUpdateCacheMut.Lock()
		contentTypeUpdateCache[key] = cache
		contentTypeUpdateCacheMut.Unlock()
	}
	return nil
}
func (q contentTypeQuery) UpdateAllP(cols M) {
	if err := q.UpdateAll(cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (q contentTypeQuery) UpdateAll(cols M) error {
	queries.SetUpdate(q.Query, cols)
	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to update all for content_types")
	}
	return nil
}
func (o ContentTypeSlice) UpdateAllG(cols M) error {
	return o.UpdateAll(boil.GetDB(), cols)
}
func (o ContentTypeSlice) UpdateAllGP(cols M) {
	if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o ContentTypeSlice) UpdateAllP(exec boil.Executor, cols M) {
	if err := o.UpdateAll(exec, cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o ContentTypeSlice) UpdateAll(exec boil.Executor, cols M) error {
	ln := int64(len(o))
	if ln == 0 {
		return nil
	}
	if len(cols) == 0 {
		return errors.New("mdbmodels: 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++
	}
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), contentTypePrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}
	sql := fmt.Sprintf("UPDATE \"content_types\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, contentTypePrimaryKeyColumns, len(o)))
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}
	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to update all in contentType slice")
	}
	return nil
}
func (o *ContentType) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...)
}