func (o SourceI18nSlice) DeleteAllGP() {
	if err := o.DeleteAllG(); err != nil {
		panic(boil.WrapErr(err))
	}
}
DeleteAllGP deletes all rows in the slice, and 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 SourceI18n struct {
	SourceID    int64       `boil:"source_id" json:"source_id" toml:"source_id" yaml:"source_id"`
	Language    string      `boil:"language" json:"language" toml:"language" yaml:"language"`
	Name        null.String `boil:"name" json:"name,omitempty" toml:"name" yaml:"name,omitempty"`
	Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"`
	CreatedAt   time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	R *sourceI18nR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L sourceI18nL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var SourceI18nColumns = struct {
	SourceID    string
	Language    string
	Name        string
	Description string
	CreatedAt   string
}{
	SourceID:    "source_id",
	Language:    "language",
	Name:        "name",
	Description: "description",
	CreatedAt:   "created_at",
}
type sourceI18nR struct {
	Source *Source
}
type sourceI18nL struct{}
var (
	sourceI18nColumns               = []string{"source_id", "language", "name", "description", "created_at"}
	sourceI18nColumnsWithoutDefault = []string{"source_id", "language", "name", "description"}
	sourceI18nColumnsWithDefault    = []string{"created_at"}
	sourceI18nPrimaryKeyColumns     = []string{"source_id", "language"}
)
type (
	SourceI18nSlice []*SourceI18n
	sourceI18nQuery struct {
		*queries.Query
	}
)
var (
	sourceI18nType                 = reflect.TypeOf(&SourceI18n{})
	sourceI18nMapping              = queries.MakeStructMapping(sourceI18nType)
	sourceI18nPrimaryKeyMapping, _ = queries.BindMapping(sourceI18nType, sourceI18nMapping, sourceI18nPrimaryKeyColumns)
	sourceI18nInsertCacheMut       sync.RWMutex
	sourceI18nInsertCache          = make(map[string]insertCache)
	sourceI18nUpdateCacheMut       sync.RWMutex
	sourceI18nUpdateCache          = make(map[string]updateCache)
	sourceI18nUpsertCacheMut       sync.RWMutex
	sourceI18nUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q sourceI18nQuery) OneP() *SourceI18n {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q sourceI18nQuery) One() (*SourceI18n, error) {
	o := &SourceI18n{}
	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_i18n")
	}
	return o, nil
}
func (q sourceI18nQuery) AllP() SourceI18nSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q sourceI18nQuery) All() (SourceI18nSlice, error) {
	var o []*SourceI18n
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to SourceI18n slice")
	}
	return o, nil
}
func (q sourceI18nQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q sourceI18nQuery) 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_i18n rows")
	}
	return count, nil
}
func (q sourceI18nQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q sourceI18nQuery) 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_i18n exists")
	}
	return count > 0, nil
}
func (o *SourceI18n) SourceG(mods ...qm.QueryMod) sourceQuery {
	return o.Source(boil.GetDB(), mods...)
}
func (o *SourceI18n) Source(exec boil.Executor, mods ...qm.QueryMod) sourceQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.SourceID),
	}
	queryMods = append(queryMods, mods...)
	query := Sources(exec, queryMods...)
	queries.SetFrom(query.Query, "\"sources\"")
	return query
}  
func (sourceI18nL) LoadSource(e boil.Executor, singular bool, maybeSourceI18n interface{}) error {
	var slice []*SourceI18n
	var object *SourceI18n
	count := 1
	if singular {
		object = maybeSourceI18n.(*SourceI18n)
	} else {
		slice = *maybeSourceI18n.(*[]*SourceI18n)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &sourceI18nR{}
		}
		args[0] = object.SourceID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &sourceI18nR{}
			}
			args[i] = obj.SourceID
		}
	}
	query := fmt.Sprintf(
		"select * from \"sources\" 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 Source")
	}
	defer results.Close()
	var resultSlice []*Source
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Source")
	}
	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 *SourceI18n) SetSourceG(insert bool, related *Source) error {
	return o.SetSource(boil.GetDB(), insert, related)
}
func (o *SourceI18n) SetSourceP(exec boil.Executor, insert bool, related *Source) {
	if err := o.SetSource(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) SetSourceGP(insert bool, related *Source) {
	if err := o.SetSource(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) SetSource(exec boil.Executor, insert bool, related *Source) 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 \"source_i18n\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"source_id"}),
		strmangle.WhereClause("\"", "\"", 2, sourceI18nPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.SourceID, o.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 local table")
	}
	o.SourceID = related.ID
	if o.R == nil {
		o.R = &sourceI18nR{
			Source: related,
		}
	} else {
		o.R.Source = related
	}
	if related.R == nil {
		related.R = &sourceR{
			SourceI18ns: SourceI18nSlice{o},
		}
	} else {
		related.R.SourceI18ns = append(related.R.SourceI18ns, o)
	}
	return nil
}
func SourceI18nsG(mods ...qm.QueryMod) sourceI18nQuery {
	return SourceI18ns(boil.GetDB(), mods...)
}
func SourceI18ns(exec boil.Executor, mods ...qm.QueryMod) sourceI18nQuery {
	mods = append(mods, qm.From("\"source_i18n\""))
	return sourceI18nQuery{NewQuery(exec, mods...)}
}
func FindSourceI18nG(sourceID int64, language string, selectCols ...string) (*SourceI18n, error) {
	return FindSourceI18n(boil.GetDB(), sourceID, language, selectCols...)
}
func FindSourceI18nGP(sourceID int64, language string, selectCols ...string) *SourceI18n {
	retobj, err := FindSourceI18n(boil.GetDB(), sourceID, language, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindSourceI18n(exec boil.Executor, sourceID int64, language string, selectCols ...string) (*SourceI18n, error) {
	sourceI18nObj := &SourceI18n{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"source_i18n\" where \"source_id\"=$1 AND \"language\"=$2", sel,
	)
	q := queries.Raw(exec, query, sourceID, language)
	err := q.Bind(sourceI18nObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from source_i18n")
	}
	return sourceI18nObj, nil
}
func FindSourceI18nP(exec boil.Executor, sourceID int64, language string, selectCols ...string) *SourceI18n {
	retobj, err := FindSourceI18n(exec, sourceID, language, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *SourceI18n) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *SourceI18n) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no source_i18n provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(sourceI18nColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	sourceI18nInsertCacheMut.RLock()
	cache, cached := sourceI18nInsertCache[key]
	sourceI18nInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			sourceI18nColumns,
			sourceI18nColumnsWithDefault,
			sourceI18nColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(sourceI18nType, sourceI18nMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(sourceI18nType, sourceI18nMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"source_i18n\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"source_i18n\" 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_i18n")
	}
	if !cached {
		sourceI18nInsertCacheMut.Lock()
		sourceI18nInsertCache[key] = cache
		sourceI18nInsertCacheMut.Unlock()
	}
	return nil
}
func (o *SourceI18n) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}
func (o *SourceI18n) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	sourceI18nUpdateCacheMut.RLock()
	cache, cached := sourceI18nUpdateCache[key]
	sourceI18nUpdateCacheMut.RUnlock()
	if !cached {
		wl := strmangle.UpdateColumnSet(
			sourceI18nColumns,
			sourceI18nPrimaryKeyColumns,
			whitelist,
		)
		if len(wl) == 0 {
			return errors.New("mdbmodels: unable to update source_i18n, could not build whitelist")
		}
		cache.query = fmt.Sprintf("UPDATE \"source_i18n\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, sourceI18nPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(sourceI18nType, sourceI18nMapping, append(wl, sourceI18nPrimaryKeyColumns...))
		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_i18n row")
	}
	if !cached {
		sourceI18nUpdateCacheMut.Lock()
		sourceI18nUpdateCache[key] = cache
		sourceI18nUpdateCacheMut.Unlock()
	}
	return nil
}
func (q sourceI18nQuery) UpdateAllP(cols M) {
	if err := q.UpdateAll(cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (q sourceI18nQuery) 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_i18n")
	}
	return nil
}
func (o SourceI18nSlice) UpdateAllG(cols M) error {
	return o.UpdateAll(boil.GetDB(), cols)
}
func (o SourceI18nSlice) UpdateAllGP(cols M) {
	if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o SourceI18nSlice) UpdateAllP(exec boil.Executor, cols M) {
	if err := o.UpdateAll(exec, cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o SourceI18nSlice) 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)), sourceI18nPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}
	sql := fmt.Sprintf("UPDATE \"source_i18n\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, sourceI18nPrimaryKeyColumns, 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 sourceI18n slice")
	}
	return nil
}
func (o *SourceI18n) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...)
}
func (o *SourceI18n) 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 *SourceI18n) 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 *SourceI18n) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no source_i18n provided for upsert")
	}
	nzDefaults := queries.NonZeroDefaultSet(sourceI18nColumnsWithDefault, 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)
	sourceI18nUpsertCacheMut.RLock()
	cache, cached := sourceI18nUpsertCache[key]
	sourceI18nUpsertCacheMut.RUnlock()
	var err error
	if !cached {
		insert, ret := strmangle.InsertColumnSet(
			sourceI18nColumns,
			sourceI18nColumnsWithDefault,
			sourceI18nColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		update := strmangle.UpdateColumnSet(
			sourceI18nColumns,
			sourceI18nPrimaryKeyColumns,
			updateColumns,
		)
		if len(update) == 0 {
			return errors.New("mdbmodels: unable to upsert source_i18n, could not build update column list")
		}
		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(sourceI18nPrimaryKeyColumns))
			copy(conflict, sourceI18nPrimaryKeyColumns)
		}
		cache.query = queries.BuildUpsertQueryPostgres(dialect, "\"source_i18n\"", updateOnConflict, ret, update, conflict, insert)
		cache.valueMapping, err = queries.BindMapping(sourceI18nType, sourceI18nMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(sourceI18nType, sourceI18nMapping, 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_i18n")
	}
	if !cached {
		sourceI18nUpsertCacheMut.Lock()
		sourceI18nUpsertCache[key] = cache
		sourceI18nUpsertCacheMut.Unlock()
	}
	return nil
}
func (o *SourceI18n) DeleteP(exec boil.Executor) {
	if err := o.Delete(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) DeleteG() error {
	if o == nil {
		return errors.New("mdbmodels: no SourceI18n provided for deletion")
	}
	return o.Delete(boil.GetDB())
}
func (o *SourceI18n) DeleteGP() {
	if err := o.DeleteG(); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *SourceI18n) Delete(exec boil.Executor) error {
	if o == nil {
		return errors.New("mdbmodels: no SourceI18n provided for delete")
	}
	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), sourceI18nPrimaryKeyMapping)
	sql := "DELETE FROM \"source_i18n\" WHERE \"source_id\"=$1 AND \"language\"=$2"
	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 delete from source_i18n")
	}
	return nil
}
func (q sourceI18nQuery) DeleteAllP() {
	if err := q.DeleteAll(); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (q sourceI18nQuery) DeleteAll() error {
	if q.Query == nil {
		return errors.New("mdbmodels: no sourceI18nQuery provided for delete all")
	}
	queries.SetDelete(q.Query)
	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to delete all from source_i18n")
	}
	return nil
}