func (o *TagI18n) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
InsertG a single record. See Insert for whitelist behavior description.
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 TagI18n struct {
	TagID            int64       `boil:"tag_id" json:"tag_id" toml:"tag_id" yaml:"tag_id"`
	Language         string      `boil:"language" json:"language" toml:"language" yaml:"language"`
	OriginalLanguage null.String `boil:"original_language" json:"original_language,omitempty" toml:"original_language" yaml:"original_language,omitempty"`
	Label            null.String `boil:"label" json:"label,omitempty" toml:"label" yaml:"label,omitempty"`
	UserID           null.Int64  `boil:"user_id" json:"user_id,omitempty" toml:"user_id" yaml:"user_id,omitempty"`
	CreatedAt        time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	R *tagI18nR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L tagI18nL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var TagI18nColumns = struct {
	TagID            string
	Language         string
	OriginalLanguage string
	Label            string
	UserID           string
	CreatedAt        string
}{
	TagID:            "tag_id",
	Language:         "language",
	OriginalLanguage: "original_language",
	Label:            "label",
	UserID:           "user_id",
	CreatedAt:        "created_at",
}
type tagI18nR struct {
	Tag  *Tag
	User *User
}
type tagI18nL struct{}
var (
	tagI18nColumns               = []string{"tag_id", "language", "original_language", "label", "user_id", "created_at"}
	tagI18nColumnsWithoutDefault = []string{"tag_id", "language", "original_language", "label", "user_id"}
	tagI18nColumnsWithDefault    = []string{"created_at"}
	tagI18nPrimaryKeyColumns     = []string{"tag_id", "language"}
)
type (
	TagI18nSlice []*TagI18n
	tagI18nQuery struct {
		*queries.Query
	}
)
var (
	tagI18nType                 = reflect.TypeOf(&TagI18n{})
	tagI18nMapping              = queries.MakeStructMapping(tagI18nType)
	tagI18nPrimaryKeyMapping, _ = queries.BindMapping(tagI18nType, tagI18nMapping, tagI18nPrimaryKeyColumns)
	tagI18nInsertCacheMut       sync.RWMutex
	tagI18nInsertCache          = make(map[string]insertCache)
	tagI18nUpdateCacheMut       sync.RWMutex
	tagI18nUpdateCache          = make(map[string]updateCache)
	tagI18nUpsertCacheMut       sync.RWMutex
	tagI18nUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q tagI18nQuery) OneP() *TagI18n {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q tagI18nQuery) One() (*TagI18n, error) {
	o := &TagI18n{}
	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 tag_i18n")
	}
	return o, nil
}
func (q tagI18nQuery) AllP() TagI18nSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q tagI18nQuery) All() (TagI18nSlice, error) {
	var o []*TagI18n
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to TagI18n slice")
	}
	return o, nil
}
func (q tagI18nQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q tagI18nQuery) 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 tag_i18n rows")
	}
	return count, nil
}
func (q tagI18nQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q tagI18nQuery) 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 tag_i18n exists")
	}
	return count > 0, nil
}
func (o *TagI18n) TagG(mods ...qm.QueryMod) tagQuery {
	return o.Tag(boil.GetDB(), mods...)
}
func (o *TagI18n) Tag(exec boil.Executor, mods ...qm.QueryMod) tagQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.TagID),
	}
	queryMods = append(queryMods, mods...)
	query := Tags(exec, queryMods...)
	queries.SetFrom(query.Query, "\"tags\"")
	return query
}
func (o *TagI18n) UserG(mods ...qm.QueryMod) userQuery {
	return o.User(boil.GetDB(), mods...)
}
func (o *TagI18n) User(exec boil.Executor, mods ...qm.QueryMod) userQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.UserID),
	}
	queryMods = append(queryMods, mods...)
	query := Users(exec, queryMods...)
	queries.SetFrom(query.Query, "\"users\"")
	return query
}  
func (tagI18nL) LoadTag(e boil.Executor, singular bool, maybeTagI18n interface{}) error {
	var slice []*TagI18n
	var object *TagI18n
	count := 1
	if singular {
		object = maybeTagI18n.(*TagI18n)
	} else {
		slice = *maybeTagI18n.(*[]*TagI18n)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &tagI18nR{}
		}
		args[0] = object.TagID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &tagI18nR{}
			}
			args[i] = obj.TagID
		}
	}
	query := fmt.Sprintf(
		"select * from \"tags\" 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 Tag")
	}
	defer results.Close()
	var resultSlice []*Tag
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Tag")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Tag = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.TagID == foreign.ID {
				local.R.Tag = foreign
				break
			}
		}
	}
	return nil
}
func (tagI18nL) LoadUser(e boil.Executor, singular bool, maybeTagI18n interface{}) error {
	var slice []*TagI18n
	var object *TagI18n
	count := 1
	if singular {
		object = maybeTagI18n.(*TagI18n)
	} else {
		slice = *maybeTagI18n.(*[]*TagI18n)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &tagI18nR{}
		}
		args[0] = object.UserID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &tagI18nR{}
			}
			args[i] = obj.UserID
		}
	}
	query := fmt.Sprintf(
		"select * from \"users\" 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 User")
	}
	defer results.Close()
	var resultSlice []*User
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice User")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.User = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.UserID.Int64 == foreign.ID {
				local.R.User = foreign
				break
			}
		}
	}
	return nil
}
func (o *TagI18n) SetTagG(insert bool, related *Tag) error {
	return o.SetTag(boil.GetDB(), insert, related)
}
func (o *TagI18n) SetTagP(exec boil.Executor, insert bool, related *Tag) {
	if err := o.SetTag(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TagI18n) SetTagGP(insert bool, related *Tag) {
	if err := o.SetTag(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TagI18n) SetTag(exec boil.Executor, insert bool, related *Tag) 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 \"tag_i18n\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"tag_id"}),
		strmangle.WhereClause("\"", "\"", 2, tagI18nPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.TagID, 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.TagID = related.ID
	if o.R == nil {
		o.R = &tagI18nR{
			Tag: related,
		}
	} else {
		o.R.Tag = related
	}
	if related.R == nil {
		related.R = &tagR{
			TagI18ns: TagI18nSlice{o},
		}
	} else {
		related.R.TagI18ns = append(related.R.TagI18ns, o)
	}
	return nil
}
func (o *TagI18n) SetUserG(insert bool, related *User) error {
	return o.SetUser(boil.GetDB(), insert, related)
}
func (o *TagI18n) SetUserP(exec boil.Executor, insert bool, related *User) {
	if err := o.SetUser(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TagI18n) SetUserGP(insert bool, related *User) {
	if err := o.SetUser(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TagI18n) SetUser(exec boil.Executor, insert bool, related *User) 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 \"tag_i18n\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
		strmangle.WhereClause("\"", "\"", 2, tagI18nPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.TagID, 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.UserID.Int64 = related.ID
	o.UserID.Valid = true
	if o.R == nil {
		o.R = &tagI18nR{
			User: related,
		}
	} else {
		o.R.User = related
	}
	if related.R == nil {
		related.R = &userR{
			TagI18ns: TagI18nSlice{o},
		}
	} else {
		related.R.TagI18ns = append(related.R.TagI18ns, o)
	}
	return nil
}
func (o *TagI18n) RemoveUserG(related *User) error {
	return o.RemoveUser(boil.GetDB(), related)
}
func (o *TagI18n) RemoveUserP(exec boil.Executor, related *User) {
	if err := o.RemoveUser(exec, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TagI18n) RemoveUserGP(related *User) {
	if err := o.RemoveUser(boil.GetDB(), related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TagI18n) RemoveUser(exec boil.Executor, related *User) error {
	var err error
	o.UserID.Valid = false
	if err = o.Update(exec, "user_id"); err != nil {
		o.UserID.Valid = true
		return errors.Wrap(err, "failed to update local table")
	}
	o.R.User = nil
	if related == nil || related.R == nil {
		return nil
	}
	for i, ri := range related.R.TagI18ns {
		if o.UserID.Int64 != ri.UserID.Int64 {
			continue
		}
		ln := len(related.R.TagI18ns)
		if ln > 1 && i < ln-1 {
			related.R.TagI18ns[i] = related.R.TagI18ns[ln-1]
		}
		related.R.TagI18ns = related.R.TagI18ns[:ln-1]
		break
	}
	return nil
}
func TagI18nsG(mods ...qm.QueryMod) tagI18nQuery {
	return TagI18ns(boil.GetDB(), mods...)
}
func TagI18ns(exec boil.Executor, mods ...qm.QueryMod) tagI18nQuery {
	mods = append(mods, qm.From("\"tag_i18n\""))
	return tagI18nQuery{NewQuery(exec, mods...)}
}
func FindTagI18nG(tagID int64, language string, selectCols ...string) (*TagI18n, error) {
	return FindTagI18n(boil.GetDB(), tagID, language, selectCols...)
}
func FindTagI18nGP(tagID int64, language string, selectCols ...string) *TagI18n {
	retobj, err := FindTagI18n(boil.GetDB(), tagID, language, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindTagI18n(exec boil.Executor, tagID int64, language string, selectCols ...string) (*TagI18n, error) {
	tagI18nObj := &TagI18n{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"tag_i18n\" where \"tag_id\"=$1 AND \"language\"=$2", sel,
	)
	q := queries.Raw(exec, query, tagID, language)
	err := q.Bind(tagI18nObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from tag_i18n")
	}
	return tagI18nObj, nil
}
func FindTagI18nP(exec boil.Executor, tagID int64, language string, selectCols ...string) *TagI18n {
	retobj, err := FindTagI18n(exec, tagID, language, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}