func (o *Person) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	personUpdateCacheMut.RLock()
	cache, cached := personUpdateCache[key]
	personUpdateCacheMut.RUnlock()
	if !cached {
		wl := strmangle.UpdateColumnSet(
			personColumns,
			personPrimaryKeyColumns,
			whitelist,
		)
		if len(wl) == 0 {
			return errors.New("mdbmodels: unable to update persons, could not build whitelist")
		}
		cache.query = fmt.Sprintf("UPDATE \"persons\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, personPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(personType, personMapping, append(wl, personPrimaryKeyColumns...))
		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 persons row")
	}
	if !cached {
		personUpdateCacheMut.Lock()
		personUpdateCache[key] = cache
		personUpdateCacheMut.Unlock()
	}
	return nil
}
Update uses an executor to update the Person.
Whitelist behavior: If a whitelist is provided, only the columns given are updated.
No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
- All columns are inferred to start with
- All primary keys are subtracted from this set
Update does not automatically update the record in case of default values. Use .Reload()
to refresh the records.
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 Person struct {
	ID      int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
	UID     string      `boil:"uid" json:"uid" toml:"uid" yaml:"uid"`
	Pattern null.String `boil:"pattern" json:"pattern,omitempty" toml:"pattern" yaml:"pattern,omitempty"`
	R *personR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L personL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var PersonColumns = struct {
	ID      string
	UID     string
	Pattern string
}{
	ID:      "id",
	UID:     "uid",
	Pattern: "pattern",
}
type personR struct {
	ContentUnitsPersons ContentUnitsPersonSlice
	PersonI18ns         PersonI18nSlice
}
type personL struct{}
var (
	personColumns               = []string{"id", "uid", "pattern"}
	personColumnsWithoutDefault = []string{"uid", "pattern"}
	personColumnsWithDefault    = []string{"id"}
	personPrimaryKeyColumns     = []string{"id"}
)
type (
	PersonSlice []*Person
	personQuery struct {
		*queries.Query
	}
)
var (
	personType                 = reflect.TypeOf(&Person{})
	personMapping              = queries.MakeStructMapping(personType)
	personPrimaryKeyMapping, _ = queries.BindMapping(personType, personMapping, personPrimaryKeyColumns)
	personInsertCacheMut       sync.RWMutex
	personInsertCache          = make(map[string]insertCache)
	personUpdateCacheMut       sync.RWMutex
	personUpdateCache          = make(map[string]updateCache)
	personUpsertCacheMut       sync.RWMutex
	personUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q personQuery) OneP() *Person {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q personQuery) One() (*Person, error) {
	o := &Person{}
	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 persons")
	}
	return o, nil
}
func (q personQuery) AllP() PersonSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q personQuery) All() (PersonSlice, error) {
	var o []*Person
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to Person slice")
	}
	return o, nil
}
func (q personQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q personQuery) 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 persons rows")
	}
	return count, nil
}
func (q personQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q personQuery) 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 persons exists")
	}
	return count > 0, nil
}
func (o *Person) ContentUnitsPersonsG(mods ...qm.QueryMod) contentUnitsPersonQuery {
	return o.ContentUnitsPersons(boil.GetDB(), mods...)
}
func (o *Person) ContentUnitsPersons(exec boil.Executor, mods ...qm.QueryMod) contentUnitsPersonQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"content_units_persons\".\"person_id\"=?", o.ID),
	)
	query := ContentUnitsPersons(exec, queryMods...)
	queries.SetFrom(query.Query, "\"content_units_persons\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"content_units_persons\".*"})
	}
	return query
}
func (o *Person) PersonI18nsG(mods ...qm.QueryMod) personI18nQuery {
	return o.PersonI18ns(boil.GetDB(), mods...)
}
func (o *Person) PersonI18ns(exec boil.Executor, mods ...qm.QueryMod) personI18nQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"person_i18n\".\"person_id\"=?", o.ID),
	)
	query := PersonI18ns(exec, queryMods...)
	queries.SetFrom(query.Query, "\"person_i18n\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"person_i18n\".*"})
	}
	return query
}
func (personL) LoadContentUnitsPersons(e boil.Executor, singular bool, maybePerson interface{}) error {
	var slice []*Person
	var object *Person
	count := 1
	if singular {
		object = maybePerson.(*Person)
	} else {
		slice = *maybePerson.(*[]*Person)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &personR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &personR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"content_units_persons\" where \"person_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_persons")
	}
	defer results.Close()
	var resultSlice []*ContentUnitsPerson
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice content_units_persons")
	}
	if singular {
		object.R.ContentUnitsPersons = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.PersonID {
				local.R.ContentUnitsPersons = append(local.R.ContentUnitsPersons, foreign)
				break
			}
		}
	}
	return nil
}
func (personL) LoadPersonI18ns(e boil.Executor, singular bool, maybePerson interface{}) error {
	var slice []*Person
	var object *Person
	count := 1
	if singular {
		object = maybePerson.(*Person)
	} else {
		slice = *maybePerson.(*[]*Person)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &personR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &personR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"person_i18n\" where \"person_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 person_i18n")
	}
	defer results.Close()
	var resultSlice []*PersonI18n
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice person_i18n")
	}
	if singular {
		object.R.PersonI18ns = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.PersonID {
				local.R.PersonI18ns = append(local.R.PersonI18ns, foreign)
				break
			}
		}
	}
	return nil
}
func (o *Person) AddContentUnitsPersonsG(insert bool, related ...*ContentUnitsPerson) error {
	return o.AddContentUnitsPersons(boil.GetDB(), insert, related...)
}
func (o *Person) AddContentUnitsPersonsP(exec boil.Executor, insert bool, related ...*ContentUnitsPerson) {
	if err := o.AddContentUnitsPersons(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) AddContentUnitsPersonsGP(insert bool, related ...*ContentUnitsPerson) {
	if err := o.AddContentUnitsPersons(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) AddContentUnitsPersons(exec boil.Executor, insert bool, related ...*ContentUnitsPerson) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PersonID = 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_persons\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"person_id"}),
				strmangle.WhereClause("\"", "\"", 2, contentUnitsPersonPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, rel.ContentUnitID, rel.PersonID}
			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.PersonID = o.ID
		}
	}
	if o.R == nil {
		o.R = &personR{
			ContentUnitsPersons: related,
		}
	} else {
		o.R.ContentUnitsPersons = append(o.R.ContentUnitsPersons, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &contentUnitsPersonR{
				Person: o,
			}
		} else {
			rel.R.Person = o
		}
	}
	return nil
}
func (o *Person) AddPersonI18nsG(insert bool, related ...*PersonI18n) error {
	return o.AddPersonI18ns(boil.GetDB(), insert, related...)
}
func (o *Person) AddPersonI18nsP(exec boil.Executor, insert bool, related ...*PersonI18n) {
	if err := o.AddPersonI18ns(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) AddPersonI18nsGP(insert bool, related ...*PersonI18n) {
	if err := o.AddPersonI18ns(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) AddPersonI18ns(exec boil.Executor, insert bool, related ...*PersonI18n) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.PersonID = o.ID
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"person_i18n\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"person_id"}),
				strmangle.WhereClause("\"", "\"", 2, personI18nPrimaryKeyColumns),
			)
			values := []interface{}{o.ID, rel.PersonID, rel.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 foreign table")
			}
			rel.PersonID = o.ID
		}
	}
	if o.R == nil {
		o.R = &personR{
			PersonI18ns: related,
		}
	} else {
		o.R.PersonI18ns = append(o.R.PersonI18ns, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &personI18nR{
				Person: o,
			}
		} else {
			rel.R.Person = o
		}
	}
	return nil
}
func PersonsG(mods ...qm.QueryMod) personQuery {
	return Persons(boil.GetDB(), mods...)
}
func Persons(exec boil.Executor, mods ...qm.QueryMod) personQuery {
	mods = append(mods, qm.From("\"persons\""))
	return personQuery{NewQuery(exec, mods...)}
}
func FindPersonG(id int64, selectCols ...string) (*Person, error) {
	return FindPerson(boil.GetDB(), id, selectCols...)
}
func FindPersonGP(id int64, selectCols ...string) *Person {
	retobj, err := FindPerson(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindPerson(exec boil.Executor, id int64, selectCols ...string) (*Person, error) {
	personObj := &Person{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"persons\" where \"id\"=$1", sel,
	)
	q := queries.Raw(exec, query, id)
	err := q.Bind(personObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from persons")
	}
	return personObj, nil
}
func FindPersonP(exec boil.Executor, id int64, selectCols ...string) *Person {
	retobj, err := FindPerson(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *Person) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *Person) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no persons provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(personColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	personInsertCacheMut.RLock()
	cache, cached := personInsertCache[key]
	personInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			personColumns,
			personColumnsWithDefault,
			personColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(personType, personMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(personType, personMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"persons\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"persons\" 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 persons")
	}
	if !cached {
		personInsertCacheMut.Lock()
		personInsertCache[key] = cache
		personInsertCacheMut.Unlock()
	}
	return nil
}
func (o *Person) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}
func (o *Person) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *Person) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}