func (o *TwitterUser) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	twitterUserUpdateCacheMut.RLock()
	cache, cached := twitterUserUpdateCache[key]
	twitterUserUpdateCacheMut.RUnlock()
	if !cached {
		wl := strmangle.UpdateColumnSet(
			twitterUserColumns,
			twitterUserPrimaryKeyColumns,
			whitelist,
		)
		if len(wl) == 0 {
			return errors.New("mdbmodels: unable to update twitter_users, could not build whitelist")
		}
		cache.query = fmt.Sprintf("UPDATE \"twitter_users\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, twitterUserPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(twitterUserType, twitterUserMapping, append(wl, twitterUserPrimaryKeyColumns...))
		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 twitter_users row")
	}
	if !cached {
		twitterUserUpdateCacheMut.Lock()
		twitterUserUpdateCache[key] = cache
		twitterUserUpdateCacheMut.Unlock()
	}
	return nil
}
Update uses an executor to update the TwitterUser.
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"
)
type TwitterUser struct {
	ID          int64  `boil:"id" json:"id" toml:"id" yaml:"id"`
	Username    string `boil:"username" json:"username" toml:"username" yaml:"username"`
	AccountID   string `boil:"account_id" json:"account_id" toml:"account_id" yaml:"account_id"`
	DisplayName string `boil:"display_name" json:"display_name" toml:"display_name" yaml:"display_name"`
	R *twitterUserR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L twitterUserL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var TwitterUserColumns = struct {
	ID          string
	Username    string
	AccountID   string
	DisplayName string
}{
	ID:          "id",
	Username:    "username",
	AccountID:   "account_id",
	DisplayName: "display_name",
}
type twitterUserR struct {
	UserTwitterTweets TwitterTweetSlice
}
type twitterUserL struct{}
var (
	twitterUserColumns               = []string{"id", "username", "account_id", "display_name"}
	twitterUserColumnsWithoutDefault = []string{"username", "account_id", "display_name"}
	twitterUserColumnsWithDefault    = []string{"id"}
	twitterUserPrimaryKeyColumns     = []string{"id"}
)
type (
	TwitterUserSlice []*TwitterUser
	twitterUserQuery struct {
		*queries.Query
	}
)
var (
	twitterUserType                 = reflect.TypeOf(&TwitterUser{})
	twitterUserMapping              = queries.MakeStructMapping(twitterUserType)
	twitterUserPrimaryKeyMapping, _ = queries.BindMapping(twitterUserType, twitterUserMapping, twitterUserPrimaryKeyColumns)
	twitterUserInsertCacheMut       sync.RWMutex
	twitterUserInsertCache          = make(map[string]insertCache)
	twitterUserUpdateCacheMut       sync.RWMutex
	twitterUserUpdateCache          = make(map[string]updateCache)
	twitterUserUpsertCacheMut       sync.RWMutex
	twitterUserUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q twitterUserQuery) OneP() *TwitterUser {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q twitterUserQuery) One() (*TwitterUser, error) {
	o := &TwitterUser{}
	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 twitter_users")
	}
	return o, nil
}
func (q twitterUserQuery) AllP() TwitterUserSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q twitterUserQuery) All() (TwitterUserSlice, error) {
	var o []*TwitterUser
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to TwitterUser slice")
	}
	return o, nil
}
func (q twitterUserQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q twitterUserQuery) 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 twitter_users rows")
	}
	return count, nil
}
func (q twitterUserQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q twitterUserQuery) 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 twitter_users exists")
	}
	return count > 0, nil
}
func (o *TwitterUser) UserTwitterTweetsG(mods ...qm.QueryMod) twitterTweetQuery {
	return o.UserTwitterTweets(boil.GetDB(), mods...)
}
func (o *TwitterUser) UserTwitterTweets(exec boil.Executor, mods ...qm.QueryMod) twitterTweetQuery {
	var queryMods []qm.QueryMod
	if len(mods) != 0 {
		queryMods = append(queryMods, mods...)
	}
	queryMods = append(queryMods,
		qm.Where("\"twitter_tweets\".\"user_id\"=?", o.ID),
	)
	query := TwitterTweets(exec, queryMods...)
	queries.SetFrom(query.Query, "\"twitter_tweets\"")
	if len(queries.GetSelect(query.Query)) == 0 {
		queries.SetSelect(query.Query, []string{"\"twitter_tweets\".*"})
	}
	return query
}
func (twitterUserL) LoadUserTwitterTweets(e boil.Executor, singular bool, maybeTwitterUser interface{}) error {
	var slice []*TwitterUser
	var object *TwitterUser
	count := 1
	if singular {
		object = maybeTwitterUser.(*TwitterUser)
	} else {
		slice = *maybeTwitterUser.(*[]*TwitterUser)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &twitterUserR{}
		}
		args[0] = object.ID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &twitterUserR{}
			}
			args[i] = obj.ID
		}
	}
	query := fmt.Sprintf(
		"select * from \"twitter_tweets\" where \"user_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 twitter_tweets")
	}
	defer results.Close()
	var resultSlice []*TwitterTweet
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice twitter_tweets")
	}
	if singular {
		object.R.UserTwitterTweets = resultSlice
		return nil
	}
	for _, foreign := range resultSlice {
		for _, local := range slice {
			if local.ID == foreign.UserID {
				local.R.UserTwitterTweets = append(local.R.UserTwitterTweets, foreign)
				break
			}
		}
	}
	return nil
}
func (o *TwitterUser) AddUserTwitterTweetsG(insert bool, related ...*TwitterTweet) error {
	return o.AddUserTwitterTweets(boil.GetDB(), insert, related...)
}
func (o *TwitterUser) AddUserTwitterTweetsP(exec boil.Executor, insert bool, related ...*TwitterTweet) {
	if err := o.AddUserTwitterTweets(exec, insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TwitterUser) AddUserTwitterTweetsGP(insert bool, related ...*TwitterTweet) {
	if err := o.AddUserTwitterTweets(boil.GetDB(), insert, related...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TwitterUser) AddUserTwitterTweets(exec boil.Executor, insert bool, related ...*TwitterTweet) error {
	var err error
	for _, rel := range related {
		if insert {
			rel.UserID = o.ID
			if err = rel.Insert(exec); err != nil {
				return errors.Wrap(err, "failed to insert into foreign table")
			}
		} else {
			updateQuery := fmt.Sprintf(
				"UPDATE \"twitter_tweets\" SET %s WHERE %s",
				strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}),
				strmangle.WhereClause("\"", "\"", 2, twitterTweetPrimaryKeyColumns),
			)
			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.UserID = o.ID
		}
	}
	if o.R == nil {
		o.R = &twitterUserR{
			UserTwitterTweets: related,
		}
	} else {
		o.R.UserTwitterTweets = append(o.R.UserTwitterTweets, related...)
	}
	for _, rel := range related {
		if rel.R == nil {
			rel.R = &twitterTweetR{
				User: o,
			}
		} else {
			rel.R.User = o
		}
	}
	return nil
}
func TwitterUsersG(mods ...qm.QueryMod) twitterUserQuery {
	return TwitterUsers(boil.GetDB(), mods...)
}
func TwitterUsers(exec boil.Executor, mods ...qm.QueryMod) twitterUserQuery {
	mods = append(mods, qm.From("\"twitter_users\""))
	return twitterUserQuery{NewQuery(exec, mods...)}
}
func FindTwitterUserG(id int64, selectCols ...string) (*TwitterUser, error) {
	return FindTwitterUser(boil.GetDB(), id, selectCols...)
}
func FindTwitterUserGP(id int64, selectCols ...string) *TwitterUser {
	retobj, err := FindTwitterUser(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindTwitterUser(exec boil.Executor, id int64, selectCols ...string) (*TwitterUser, error) {
	twitterUserObj := &TwitterUser{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"twitter_users\" where \"id\"=$1", sel,
	)
	q := queries.Raw(exec, query, id)
	err := q.Bind(twitterUserObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from twitter_users")
	}
	return twitterUserObj, nil
}
func FindTwitterUserP(exec boil.Executor, id int64, selectCols ...string) *TwitterUser {
	retobj, err := FindTwitterUser(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *TwitterUser) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *TwitterUser) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TwitterUser) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TwitterUser) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no twitter_users provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(twitterUserColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	twitterUserInsertCacheMut.RLock()
	cache, cached := twitterUserInsertCache[key]
	twitterUserInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			twitterUserColumns,
			twitterUserColumnsWithDefault,
			twitterUserColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(twitterUserType, twitterUserMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(twitterUserType, twitterUserMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"twitter_users\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"twitter_users\" 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 twitter_users")
	}
	if !cached {
		twitterUserInsertCacheMut.Lock()
		twitterUserInsertCache[key] = cache
		twitterUserInsertCacheMut.Unlock()
	}
	return nil
}
func (o *TwitterUser) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}
func (o *TwitterUser) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *TwitterUser) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}