func (o *SourceType) DeleteGP() {
	if err := o.DeleteG(); err != nil {
		panic(boil.WrapErr(err))
	}
}
DeleteGP deletes a single SourceType record.
DeleteGP will match against the primary key column to find the record to delete.
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"
)
type SourceType struct {
	ID   int64  `boil:"id" json:"id" toml:"id" yaml:"id"`
	Name string `boil:"name" json:"name" toml:"name" yaml:"name"`
	R *sourceTypeR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L sourceTypeL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var SourceTypeColumns = struct {
	ID   string
	Name string
}{
	ID:   "id",
	Name: "name",
}
type sourceTypeR struct {
	TypeSources SourceSlice
}
type sourceTypeL struct{}
var (
	sourceTypeColumns               = []string{"id", "name"}
	sourceTypeColumnsWithoutDefault = []string{"name"}
	sourceTypeColumnsWithDefault    = []string{"id"}
	sourceTypePrimaryKeyColumns     = []string{"id"}
)
type (
	SourceTypeSlice []*SourceType
	sourceTypeQuery struct {
		*queries.Query
	}
)
var (
	sourceTypeType                 = reflect.TypeOf(&SourceType{})
	sourceTypeMapping              = queries.MakeStructMapping(sourceTypeType)
	sourceTypePrimaryKeyMapping, _ = queries.BindMapping(sourceTypeType, sourceTypeMapping, sourceTypePrimaryKeyColumns)
	sourceTypeInsertCacheMut       sync.RWMutex
	sourceTypeInsertCache          = make(map[string]insertCache)
	sourceTypeUpdateCacheMut       sync.RWMutex
	sourceTypeUpdateCache          = make(map[string]updateCache)
	sourceTypeUpsertCacheMut       sync.RWMutex
	sourceTypeUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q sourceTypeQuery) OneP() *SourceType {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q sourceTypeQuery) One() (*SourceType, error) {
	o := &SourceType{}
	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 source_types")
	}
	return o, nil
}
func (q sourceTypeQuery) AllP() SourceTypeSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q sourceTypeQuery) All() (SourceTypeSlice, error) {
	var o []*SourceType
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to SourceType slice")
	}
	return o, nil
}
func (q sourceTypeQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q sourceTypeQuery) 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 source_types rows")
	}
	return count, nil
}
func (q sourceTypeQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q sourceTypeQuery) 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 source_types exists")
	}
	return count > 0, nil
}
func (o *SourceType) TypeSourcesG(mods ...qm.QueryMod) sourceQuery {
	return o.TypeSources(boil.GetDB(), mods...)
}
func (o *SourceType) TypeSources(exec boil.Executor, mods ...qm.QueryMod) sourceQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"sources\".\"type_id\"=?", o.ID),
	)
	query := Sources(exec, queryMods...)
	queries.SetFrom(query.Query, "\"sources\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"sources\".*"})
	}
	return query
}
func (sourceTypeL) LoadTypeSources(e boil.Executor, singular bool, maybeSourceType interface{}) error {
	var slice []*SourceType
	var object *SourceType
	count := 1
	if singular {
		object = maybeSourceType.(*SourceType)
	} else {
		slice = *maybeSourceType.(*[]*SourceType)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceTypeR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceTypeR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"sources\" 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 sources")
	}
	defer results.Close()
	var resultSlice []*Source
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice sources")
	}
	if singular {
		object.R.TypeSources = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.TypeID {
				local.R.TypeSources = append(local.R.TypeSources, foreign)
				break
			}
		}
	}
	return nil
}
func (o *SourceType) AddTypeSourcesG(insert bool, related ...*Source) error {
	return o.AddTypeSources(boil.GetDB(), insert, related...)
}
func (o *SourceType) AddTypeSourcesP(exec boil.Executor, insert bool, related ...*Source) {
	if err := o.AddTypeSources(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) AddTypeSourcesGP(insert bool, related ...*Source) {
	if err := o.AddTypeSources(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) AddTypeSources(exec boil.Executor, insert bool, related ...*Source) 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 \"sources\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"type_id"}),
				strmangle.WhereClause("\"", "\"", 2, sourcePrimaryKeyColumns),
			)
			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 = &sourceTypeR{
			TypeSources: related,
		}
	} else {
		o.R.TypeSources = append(o.R.TypeSources, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &sourceR{
				Type: o,
			}
		} else {
			rel.R.Type = o
		}
	}
	return nil
}
func SourceTypesG(mods ...qm.QueryMod) sourceTypeQuery {
	return SourceTypes(boil.GetDB(), mods...)
}
func SourceTypes(exec boil.Executor, mods ...qm.QueryMod) sourceTypeQuery {
	mods = append(mods, qm.From("\"source_types\""))
	return sourceTypeQuery{NewQuery(exec, mods...)}
}
func FindSourceTypeG(id int64, selectCols ...string) (*SourceType, error) {
	return FindSourceType(boil.GetDB(), id, selectCols...)
}
func FindSourceTypeGP(id int64, selectCols ...string) *SourceType {
	retobj, err := FindSourceType(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindSourceType(exec boil.Executor, id int64, selectCols ...string) (*SourceType, error) {
	sourceTypeObj := &SourceType{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"source_types\" where \"id\"=$1", sel,
	)
	q := queries.Raw(exec, query, id)
	err := q.Bind(sourceTypeObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from source_types")
	}
	return sourceTypeObj, nil
}
func FindSourceTypeP(exec boil.Executor, id int64, selectCols ...string) *SourceType {
	retobj, err := FindSourceType(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *SourceType) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *SourceType) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no source_types provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(sourceTypeColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	sourceTypeInsertCacheMut.RLock()
	cache, cached := sourceTypeInsertCache[key]
	sourceTypeInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			sourceTypeColumns,
			sourceTypeColumnsWithDefault,
			sourceTypeColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(sourceTypeType, sourceTypeMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(sourceTypeType, sourceTypeMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"source_types\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"source_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 source_types")
	}
	if !cached {
		sourceTypeInsertCacheMut.Lock()
		sourceTypeInsertCache[key] = cache
		sourceTypeInsertCacheMut.Unlock()
	}
	return nil
}
func (o *SourceType) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}
func (o *SourceType) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	sourceTypeUpdateCacheMut.RLock()
	cache, cached := sourceTypeUpdateCache[key]
	sourceTypeUpdateCacheMut.RUnlock()
	if !cached {
		wl := strmangle.UpdateColumnSet(
			sourceTypeColumns,
			sourceTypePrimaryKeyColumns,
			whitelist,
		)
		if len(wl) == 0 {
			return errors.New("mdbmodels: unable to update source_types, could not build whitelist")
		}
		cache.query = fmt.Sprintf("UPDATE \"source_types\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, sourceTypePrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(sourceTypeType, sourceTypeMapping, append(wl, sourceTypePrimaryKeyColumns...))
		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 source_types row")
	}
	if !cached {
		sourceTypeUpdateCacheMut.Lock()
		sourceTypeUpdateCache[key] = cache
		sourceTypeUpdateCacheMut.Unlock()
	}
	return nil
}
func (q sourceTypeQuery) UpdateAllP(cols M) {
	if err := q.UpdateAll(cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (q sourceTypeQuery) 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 source_types")
	}
	return nil
}
func (o SourceTypeSlice) UpdateAllG(cols M) error {
	return o.UpdateAll(boil.GetDB(), cols)
}
func (o SourceTypeSlice) UpdateAllGP(cols M) {
	if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o SourceTypeSlice) UpdateAllP(exec boil.Executor, cols M) {
	if err := o.UpdateAll(exec, cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o SourceTypeSlice) 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)), sourceTypePrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}
	sql := fmt.Sprintf("UPDATE \"source_types\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, sourceTypePrimaryKeyColumns, 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 sourceType slice")
	}
	return nil
}
func (o *SourceType) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...)
}
func (o *SourceType) 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))
	}
}
func (o *SourceType) UpsertP(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) {
	if err := o.Upsert(exec, updateOnConflict, conflictColumns, updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no source_types provided for upsert")
	}
	nzDefaults := queries.NonZeroDefaultSet(sourceTypeColumnsWithDefault, o)
	buf := strmangle.GetBuffer()
	if updateOnConflict {
		buf.WriteByte('t')
	} else {
		buf.WriteByte('f')
	}
	buf.WriteByte('.')
	for _, c := range conflictColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range updateColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range whitelist {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range nzDefaults {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)
	sourceTypeUpsertCacheMut.RLock()
	cache, cached := sourceTypeUpsertCache[key]
	sourceTypeUpsertCacheMut.RUnlock()
	var err error
	if !cached {
		insert, ret := strmangle.InsertColumnSet(
			sourceTypeColumns,
			sourceTypeColumnsWithDefault,
			sourceTypeColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		update := strmangle.UpdateColumnSet(
			sourceTypeColumns,
			sourceTypePrimaryKeyColumns,
			updateColumns,
		)
		if len(update) == 0 {
			return errors.New("mdbmodels: unable to upsert source_types, could not build update column list")
		}
		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(sourceTypePrimaryKeyColumns))
			copy(conflict, sourceTypePrimaryKeyColumns)
		}
		cache.query = queries.BuildUpsertQueryPostgres(dialect, "\"source_types\"", updateOnConflict, ret, update, conflict, insert)
		cache.valueMapping, err = queries.BindMapping(sourceTypeType, sourceTypeMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(sourceTypeType, sourceTypeMapping, ret)
			if err != nil {
				return err
			}
		}
	}
	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	var returns []interface{}
	if len(cache.retMapping) != 0 {
		returns = queries.PtrsFromMapping(value, cache.retMapping)
	}
	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(returns...)
		if err == sql.ErrNoRows {
			err = nil  
		}
	} else {
		_, err = exec.Exec(cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to upsert source_types")
	}
	if !cached {
		sourceTypeUpsertCacheMut.Lock()
		sourceTypeUpsertCache[key] = cache
		sourceTypeUpsertCacheMut.Unlock()
	}
	return nil
}
func (o *SourceType) DeleteP(exec boil.Executor) {
	if err := o.Delete(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceType) DeleteG() error {
	if o == nil {
		return errors.New("mdbmodels: no SourceType provided for deletion")
	}
	return o.Delete(boil.GetDB())
}