func (o *ContentUnitDerivation) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no content_unit_derivations provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(contentUnitDerivationColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	contentUnitDerivationInsertCacheMut.RLock()
	cache, cached := contentUnitDerivationInsertCache[key]
	contentUnitDerivationInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			contentUnitDerivationColumns,
			contentUnitDerivationColumnsWithDefault,
			contentUnitDerivationColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(contentUnitDerivationType, contentUnitDerivationMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(contentUnitDerivationType, contentUnitDerivationMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"content_unit_derivations\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"content_unit_derivations\" 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_unit_derivations")
	}
	if !cached {
		contentUnitDerivationInsertCacheMut.Lock()
		contentUnitDerivationInsertCache[key] = cache
		contentUnitDerivationInsertCacheMut.Unlock()
	}
	return nil
}
Insert a single record using an executor.
Whitelist behavior: If a whitelist is provided, only those columns supplied are inserted
No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
- All columns without a default value are included (i.e. name, age)
- All columns with a default, but non-zero are included (i.e. health = 75)
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"
)
type ContentUnitDerivation struct {
	SourceID  int64  `boil:"source_id" json:"source_id" toml:"source_id" yaml:"source_id"`
	DerivedID int64  `boil:"derived_id" json:"derived_id" toml:"derived_id" yaml:"derived_id"`
	Name      string `boil:"name" json:"name" toml:"name" yaml:"name"`
	R *contentUnitDerivationR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L contentUnitDerivationL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var ContentUnitDerivationColumns = struct {
	SourceID  string
	DerivedID string
	Name      string
}{
	SourceID:  "source_id",
	DerivedID: "derived_id",
	Name:      "name",
}
type contentUnitDerivationR struct {
	Derived *ContentUnit
	Source  *ContentUnit
}
type contentUnitDerivationL struct{}
var (
	contentUnitDerivationColumns               = []string{"source_id", "derived_id", "name"}
	contentUnitDerivationColumnsWithoutDefault = []string{"source_id", "derived_id", "name"}
	contentUnitDerivationColumnsWithDefault    = []string{}
	contentUnitDerivationPrimaryKeyColumns     = []string{"source_id", "derived_id"}
)
type (
	ContentUnitDerivationSlice []*ContentUnitDerivation
	contentUnitDerivationQuery struct {
		*queries.Query
	}
)
var (
	contentUnitDerivationType                 = reflect.TypeOf(&ContentUnitDerivation{})
	contentUnitDerivationMapping              = queries.MakeStructMapping(contentUnitDerivationType)
	contentUnitDerivationPrimaryKeyMapping, _ = queries.BindMapping(contentUnitDerivationType, contentUnitDerivationMapping, contentUnitDerivationPrimaryKeyColumns)
	contentUnitDerivationInsertCacheMut       sync.RWMutex
	contentUnitDerivationInsertCache          = make(map[string]insertCache)
	contentUnitDerivationUpdateCacheMut       sync.RWMutex
	contentUnitDerivationUpdateCache          = make(map[string]updateCache)
	contentUnitDerivationUpsertCacheMut       sync.RWMutex
	contentUnitDerivationUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q contentUnitDerivationQuery) OneP() *ContentUnitDerivation {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q contentUnitDerivationQuery) One() (*ContentUnitDerivation, error) {
	o := &ContentUnitDerivation{}
	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_unit_derivations")
	}
	return o, nil
}
func (q contentUnitDerivationQuery) AllP() ContentUnitDerivationSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q contentUnitDerivationQuery) All() (ContentUnitDerivationSlice, error) {
	var o []*ContentUnitDerivation
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to ContentUnitDerivation slice")
	}
	return o, nil
}
func (q contentUnitDerivationQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q contentUnitDerivationQuery) 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_unit_derivations rows")
	}
	return count, nil
}
func (q contentUnitDerivationQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q contentUnitDerivationQuery) 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_unit_derivations exists")
	}
	return count > 0, nil
}
func (o *ContentUnitDerivation) DerivedG(mods ...qm.QueryMod) contentUnitQuery {
	return o.Derived(boil.GetDB(), mods...)
}
func (o *ContentUnitDerivation) Derived(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.DerivedID),
	}
	queryMods = append(queryMods, mods...)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	return query
}
func (o *ContentUnitDerivation) SourceG(mods ...qm.QueryMod) contentUnitQuery {
	return o.Source(boil.GetDB(), mods...)
}
func (o *ContentUnitDerivation) Source(exec boil.Executor, mods ...qm.QueryMod) contentUnitQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.SourceID),
	}
	queryMods = append(queryMods, mods...)
	query := ContentUnits(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units\"")
	return query
}  
func (contentUnitDerivationL) LoadDerived(e boil.Executor, singular bool, maybeContentUnitDerivation interface{}) error {
	var slice []*ContentUnitDerivation
	var object *ContentUnitDerivation
	count := 1
	if singular {
		object = maybeContentUnitDerivation.(*ContentUnitDerivation)
	} else {
		slice = *maybeContentUnitDerivation.(*[]*ContentUnitDerivation)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &contentUnitDerivationR{}
		}
		args[0] = object.DerivedID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &contentUnitDerivationR{}
			}
			args[i] = obj.DerivedID
		}
	}
	query := fmt.Sprintf(
		"select * from \"content_units\" 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 ContentUnit")
	}
	defer results.Close()
	var resultSlice []*ContentUnit
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice ContentUnit")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Derived = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.DerivedID == foreign.ID {
				local.R.Derived = foreign
				break
			}
		}
	}
	return nil
}
func (contentUnitDerivationL) LoadSource(e boil.Executor, singular bool, maybeContentUnitDerivation interface{}) error {
	var slice []*ContentUnitDerivation
	var object *ContentUnitDerivation
	count := 1
	if singular {
		object = maybeContentUnitDerivation.(*ContentUnitDerivation)
	} else {
		slice = *maybeContentUnitDerivation.(*[]*ContentUnitDerivation)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &contentUnitDerivationR{}
		}
		args[0] = object.SourceID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &contentUnitDerivationR{}
			}
			args[i] = obj.SourceID
		}
	}
	query := fmt.Sprintf(
		"select * from \"content_units\" 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 ContentUnit")
	}
	defer results.Close()
	var resultSlice []*ContentUnit
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice ContentUnit")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Source = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.SourceID == foreign.ID {
				local.R.Source = foreign
				break
			}
		}
	}
	return nil
}
func (o *ContentUnitDerivation) SetDerivedG(insert bool, related *ContentUnit) error {
	return o.SetDerived(boil.GetDB(), insert, related)
}
func (o *ContentUnitDerivation) SetDerivedP(exec boil.Executor, insert bool, related *ContentUnit) {
	if err := o.SetDerived(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) SetDerivedGP(insert bool, related *ContentUnit) {
	if err := o.SetDerived(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) SetDerived(exec boil.Executor, insert bool, related *ContentUnit) 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 \"content_unit_derivations\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"derived_id"}),
		strmangle.WhereClause("\"", "\"", 2, contentUnitDerivationPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.SourceID, o.DerivedID}
	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.DerivedID = related.ID
	if o.R == nil {
		o.R = &contentUnitDerivationR{
			Derived: related,
		}
	} else {
		o.R.Derived = related
	}
	if related.R == nil {
		related.R = &contentUnitR{
			DerivedContentUnitDerivations: ContentUnitDerivationSlice{o},
		}
	} else {
		related.R.DerivedContentUnitDerivations = append(related.R.DerivedContentUnitDerivations, o)
	}
	return nil
}
func (o *ContentUnitDerivation) SetSourceG(insert bool, related *ContentUnit) error {
	return o.SetSource(boil.GetDB(), insert, related)
}
func (o *ContentUnitDerivation) SetSourceP(exec boil.Executor, insert bool, related *ContentUnit) {
	if err := o.SetSource(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) SetSourceGP(insert bool, related *ContentUnit) {
	if err := o.SetSource(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) SetSource(exec boil.Executor, insert bool, related *ContentUnit) 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 \"content_unit_derivations\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"source_id"}),
		strmangle.WhereClause("\"", "\"", 2, contentUnitDerivationPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.SourceID, o.DerivedID}
	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.SourceID = related.ID
	if o.R == nil {
		o.R = &contentUnitDerivationR{
			Source: related,
		}
	} else {
		o.R.Source = related
	}
	if related.R == nil {
		related.R = &contentUnitR{
			SourceContentUnitDerivations: ContentUnitDerivationSlice{o},
		}
	} else {
		related.R.SourceContentUnitDerivations = append(related.R.SourceContentUnitDerivations, o)
	}
	return nil
}
func ContentUnitDerivationsG(mods ...qm.QueryMod) contentUnitDerivationQuery {
	return ContentUnitDerivations(boil.GetDB(), mods...)
}
func ContentUnitDerivations(exec boil.Executor, mods ...qm.QueryMod) contentUnitDerivationQuery {
	mods = append(mods, qm.From("\"content_unit_derivations\""))
	return contentUnitDerivationQuery{NewQuery(exec, mods...)}
}
func FindContentUnitDerivationG(sourceID int64, derivedID int64, selectCols ...string) (*ContentUnitDerivation, error) {
	return FindContentUnitDerivation(boil.GetDB(), sourceID, derivedID, selectCols...)
}
func FindContentUnitDerivationGP(sourceID int64, derivedID int64, selectCols ...string) *ContentUnitDerivation {
	retobj, err := FindContentUnitDerivation(boil.GetDB(), sourceID, derivedID, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindContentUnitDerivation(exec boil.Executor, sourceID int64, derivedID int64, selectCols ...string) (*ContentUnitDerivation, error) {
	contentUnitDerivationObj := &ContentUnitDerivation{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"content_unit_derivations\" where \"source_id\"=$1 AND \"derived_id\"=$2", sel,
	)
	q := queries.Raw(exec, query, sourceID, derivedID)
	err := q.Bind(contentUnitDerivationObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from content_unit_derivations")
	}
	return contentUnitDerivationObj, nil
}
func FindContentUnitDerivationP(exec boil.Executor, sourceID int64, derivedID int64, selectCols ...string) *ContentUnitDerivation {
	retobj, err := FindContentUnitDerivation(exec, sourceID, derivedID, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *ContentUnitDerivation) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *ContentUnitDerivation) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *ContentUnitDerivation) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}