Skip to content

Instantly share code, notes, and snippets.

@aloha1003
Created March 2, 2018 09:43
Show Gist options
  • Save aloha1003/b510485b91bf328b7b39e1c548e58a77 to your computer and use it in GitHub Desktop.
Save aloha1003/b510485b91bf328b7b39e1c548e58a77 to your computer and use it in GitHub Desktop.
Question
package controllers
import (
"my-project/app/models"
"database/sql"
)
type Bonus struct {
App
}
func (c Bonus) getCanDrawTimes() revel.Result {
connstring := "root:pass@tcp([0.0.0.0]:3306)/mydb"
db, err := sql.Open("mysql", connstring)
if err != nil {
revel.INFO.Println("DB Error", err)
}
data := models.BonusMission(db).One()
return c.RenderJSON(data)
}
// Code generated by SQLBoiler (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"bytes"
"database/sql"
"fmt"
"reflect"
"strings"
"sync"
"time"
"github.com/pkg/errors"
"github.com/volatiletech/sqlboiler/boil"
"github.com/volatiletech/sqlboiler/queries"
"github.com/volatiletech/sqlboiler/queries/qm"
"github.com/volatiletech/sqlboiler/strmangle"
"gopkg.in/volatiletech/null.v6"
)
// BonusMission is an object representing the database table.
type BonusMission struct {
ID uint `boil:"id" json:"id" toml:"id" yaml:"id"`
MissionName null.String `boil:"mission_name" json:"mission_name,omitempty" toml:"mission_name" yaml:"mission_name,omitempty"`
Status null.Int8 `boil:"status" json:"status,omitempty" toml:"status" yaml:"status,omitempty"`
MissionDesc null.String `boil:"mission_desc" json:"mission_desc,omitempty" toml:"mission_desc" yaml:"mission_desc,omitempty"`
StartTime null.Time `boil:"start_time" json:"start_time,omitempty" toml:"start_time" yaml:"start_time,omitempty"`
EndTime null.Time `boil:"end_time" json:"end_time,omitempty" toml:"end_time" yaml:"end_time,omitempty"`
FinishCount null.String `boil:"finish_count" json:"finish_count,omitempty" toml:"finish_count" yaml:"finish_count,omitempty"`
MissionTarget null.String `boil:"mission_target" json:"mission_target,omitempty" toml:"mission_target" yaml:"mission_target,omitempty"`
RetryNum null.Int8 `boil:"retry_num" json:"retry_num,omitempty" toml:"retry_num" yaml:"retry_num,omitempty"`
RetryNumExtraBonusRule string `boil:"retry_num_extra_bonus_rule" json:"retry_num_extra_bonus_rule" toml:"retry_num_extra_bonus_rule" yaml:"retry_num_extra_bonus_rule"`
RetryInternvalType null.Uint8 `boil:"retry_internval_type" json:"retry_internval_type,omitempty" toml:"retry_internval_type" yaml:"retry_internval_type,omitempty"`
RetryInternval null.Uint `boil:"retry_internval" json:"retry_internval,omitempty" toml:"retry_internval" yaml:"retry_internval,omitempty"`
Type null.String `boil:"type" json:"type,omitempty" toml:"type" yaml:"type,omitempty"`
UpdatedTime null.Int `boil:"updated_time" json:"updated_time,omitempty" toml:"updated_time" yaml:"updated_time,omitempty"`
R *bonusMissionR `boil:"-" json:"-" toml:"-" yaml:"-"`
L bonusMissionL `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var BonusMissionColumns = struct {
ID string
MissionName string
Status string
MissionDesc string
StartTime string
EndTime string
FinishCount string
MissionTarget string
RetryNum string
RetryNumExtraBonusRule string
RetryInternvalType string
RetryInternval string
Type string
UpdatedTime string
}{
ID: "id",
MissionName: "mission_name",
Status: "status",
MissionDesc: "mission_desc",
StartTime: "start_time",
EndTime: "end_time",
FinishCount: "finish_count",
MissionTarget: "mission_target",
RetryNum: "retry_num",
RetryNumExtraBonusRule: "retry_num_extra_bonus_rule",
RetryInternvalType: "retry_internval_type",
RetryInternval: "retry_internval",
Type: "type",
UpdatedTime: "updated_time",
}
// bonusMissionR is where relationships are stored.
type bonusMissionR struct {
BonusRewardItems BonusRewardItemSlice
}
// bonusMissionL is where Load methods for each relationship are stored.
type bonusMissionL struct{}
var (
bonusMissionColumns = []string{"id", "mission_name", "status", "mission_desc", "start_time", "end_time", "finish_count", "mission_target", "retry_num", "retry_num_extra_bonus_rule", "retry_internval_type", "retry_internval", "type", "updated_time"}
bonusMissionColumnsWithoutDefault = []string{"mission_name", "status", "mission_desc", "start_time", "end_time", "finish_count", "mission_target", "retry_num", "retry_internval_type", "retry_internval", "type", "updated_time"}
bonusMissionColumnsWithDefault = []string{"id", "retry_num_extra_bonus_rule"}
bonusMissionPrimaryKeyColumns = []string{"id"}
)
type (
// BonusMissionSlice is an alias for a slice of pointers to BonusMission.
// This should generally be used opposed to []BonusMission.
BonusMissionSlice []*BonusMission
bonusMissionQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
bonusMissionType = reflect.TypeOf(&BonusMission{})
bonusMissionMapping = queries.MakeStructMapping(bonusMissionType)
bonusMissionPrimaryKeyMapping, _ = queries.BindMapping(bonusMissionType, bonusMissionMapping, bonusMissionPrimaryKeyColumns)
bonusMissionInsertCacheMut sync.RWMutex
bonusMissionInsertCache = make(map[string]insertCache)
bonusMissionUpdateCacheMut sync.RWMutex
bonusMissionUpdateCache = make(map[string]updateCache)
bonusMissionUpsertCacheMut sync.RWMutex
bonusMissionUpsertCache = make(map[string]insertCache)
)
var (
// Force time package dependency for automated UpdatedAt/CreatedAt.
_ = time.Second
// Force bytes in case of primary key column that uses []byte (for relationship compares)
_ = bytes.MinRead
)
// OneP returns a single bonusMission record from the query, and panics on error.
func (q bonusMissionQuery) OneP() *BonusMission {
o, err := q.One()
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// One returns a single bonusMission record from the query.
func (q bonusMissionQuery) One() (*BonusMission, error) {
o := &BonusMission{}
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, "models: failed to execute a one query for bonus_mission")
}
return o, nil
}
// AllP returns all BonusMission records from the query, and panics on error.
func (q bonusMissionQuery) AllP() BonusMissionSlice {
o, err := q.All()
if err != nil {
panic(boil.WrapErr(err))
}
return o
}
// All returns all BonusMission records from the query.
func (q bonusMissionQuery) All() (BonusMissionSlice, error) {
var o []*BonusMission
err := q.Bind(&o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to BonusMission slice")
}
return o, nil
}
// CountP returns the count of all BonusMission records in the query, and panics on error.
func (q bonusMissionQuery) CountP() int64 {
c, err := q.Count()
if err != nil {
panic(boil.WrapErr(err))
}
return c
}
// Count returns the count of all BonusMission records in the query.
func (q bonusMissionQuery) 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, "models: failed to count bonus_mission rows")
}
return count, nil
}
// Exists checks if the row exists in the table, and panics on error.
func (q bonusMissionQuery) ExistsP() bool {
e, err := q.Exists()
if err != nil {
panic(boil.WrapErr(err))
}
return e
}
// Exists checks if the row exists in the table.
func (q bonusMissionQuery) 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, "models: failed to check if bonus_mission exists")
}
return count > 0, nil
}
// BonusRewardItemsG retrieves all the bonus_reward_item's bonus reward item.
func (o *BonusMission) BonusRewardItemsG(mods ...qm.QueryMod) bonusRewardItemQuery {
return o.BonusRewardItems(boil.GetDB(), mods...)
}
// BonusRewardItems retrieves all the bonus_reward_item's bonus reward item with an executor.
func (o *BonusMission) BonusRewardItems(exec boil.Executor, mods ...qm.QueryMod) bonusRewardItemQuery {
var queryMods []qm.QueryMod
if len(mods) != 0 {
queryMods = append(queryMods, mods...)
}
queryMods = append(queryMods,
qm.Where("`bonus_reward_item`.`bonus_mission_id`=?", o.ID),
)
query := BonusRewardItems(exec, queryMods...)
queries.SetFrom(query.Query, "`bonus_reward_item`")
if len(queries.GetSelect(query.Query)) == 0 {
queries.SetSelect(query.Query, []string{"`bonus_reward_item`.*"})
}
return query
}
// LoadBonusRewardItems allows an eager lookup of values, cached into the
// loaded structs of the objects.
func (bonusMissionL) LoadBonusRewardItems(e boil.Executor, singular bool, maybeBonusMission interface{}) error {
var slice []*BonusMission
var object *BonusMission
count := 1
if singular {
object = maybeBonusMission.(*BonusMission)
} else {
slice = *maybeBonusMission.(*[]*BonusMission)
count = len(slice)
}
args := make([]interface{}, count)
if singular {
if object.R == nil {
object.R = &bonusMissionR{}
}
args[0] = object.ID
} else {
for i, obj := range slice {
if obj.R == nil {
obj.R = &bonusMissionR{}
}
args[i] = obj.ID
}
}
query := fmt.Sprintf(
"select * from `bonus_reward_item` where `bonus_mission_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 bonus_reward_item")
}
defer results.Close()
var resultSlice []*BonusRewardItem
if err = queries.Bind(results, &resultSlice); err != nil {
return errors.Wrap(err, "failed to bind eager loaded slice bonus_reward_item")
}
if singular {
object.R.BonusRewardItems = resultSlice
return nil
}
for _, foreign := range resultSlice {
for _, local := range slice {
if local.ID == foreign.BonusMissionID {
local.R.BonusRewardItems = append(local.R.BonusRewardItems, foreign)
break
}
}
}
return nil
}
// AddBonusRewardItemsG adds the given related objects to the existing relationships
// of the bonus_mission, optionally inserting them as new records.
// Appends related to o.R.BonusRewardItems.
// Sets related.R.BonusMission appropriately.
// Uses the global database handle.
func (o *BonusMission) AddBonusRewardItemsG(insert bool, related ...*BonusRewardItem) error {
return o.AddBonusRewardItems(boil.GetDB(), insert, related...)
}
// AddBonusRewardItemsP adds the given related objects to the existing relationships
// of the bonus_mission, optionally inserting them as new records.
// Appends related to o.R.BonusRewardItems.
// Sets related.R.BonusMission appropriately.
// Panics on error.
func (o *BonusMission) AddBonusRewardItemsP(exec boil.Executor, insert bool, related ...*BonusRewardItem) {
if err := o.AddBonusRewardItems(exec, insert, related...); err != nil {
panic(boil.WrapErr(err))
}
}
// AddBonusRewardItemsGP adds the given related objects to the existing relationships
// of the bonus_mission, optionally inserting them as new records.
// Appends related to o.R.BonusRewardItems.
// Sets related.R.BonusMission appropriately.
// Uses the global database handle and panics on error.
func (o *BonusMission) AddBonusRewardItemsGP(insert bool, related ...*BonusRewardItem) {
if err := o.AddBonusRewardItems(boil.GetDB(), insert, related...); err != nil {
panic(boil.WrapErr(err))
}
}
// AddBonusRewardItems adds the given related objects to the existing relationships
// of the bonus_mission, optionally inserting them as new records.
// Appends related to o.R.BonusRewardItems.
// Sets related.R.BonusMission appropriately.
func (o *BonusMission) AddBonusRewardItems(exec boil.Executor, insert bool, related ...*BonusRewardItem) error {
var err error
for _, rel := range related {
if insert {
rel.BonusMissionID = o.ID
if err = rel.Insert(exec); err != nil {
return errors.Wrap(err, "failed to insert into foreign table")
}
} else {
updateQuery := fmt.Sprintf(
"UPDATE `bonus_reward_item` SET %s WHERE %s",
strmangle.SetParamNames("`", "`", 0, []string{"bonus_mission_id"}),
strmangle.WhereClause("`", "`", 0, bonusRewardItemPrimaryKeyColumns),
)
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.BonusMissionID = o.ID
}
}
if o.R == nil {
o.R = &bonusMissionR{
BonusRewardItems: related,
}
} else {
o.R.BonusRewardItems = append(o.R.BonusRewardItems, related...)
}
for _, rel := range related {
if rel.R == nil {
rel.R = &bonusRewardItemR{
BonusMission: o,
}
} else {
rel.R.BonusMission = o
}
}
return nil
}
// BonusMissionsG retrieves all records.
func BonusMissionsG(mods ...qm.QueryMod) bonusMissionQuery {
return BonusMissions(boil.GetDB(), mods...)
}
// BonusMissions retrieves all the records using an executor.
func BonusMissions(exec boil.Executor, mods ...qm.QueryMod) bonusMissionQuery {
mods = append(mods, qm.From("`bonus_mission`"))
return bonusMissionQuery{NewQuery(exec, mods...)}
}
// FindBonusMissionG retrieves a single record by ID.
func FindBonusMissionG(id uint, selectCols ...string) (*BonusMission, error) {
return FindBonusMission(boil.GetDB(), id, selectCols...)
}
// FindBonusMissionGP retrieves a single record by ID, and panics on error.
func FindBonusMissionGP(id uint, selectCols ...string) *BonusMission {
retobj, err := FindBonusMission(boil.GetDB(), id, selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return retobj
}
// FindBonusMission retrieves a single record by ID with an executor.
// If selectCols is empty Find will return all columns.
func FindBonusMission(exec boil.Executor, id uint, selectCols ...string) (*BonusMission, error) {
bonusMissionObj := &BonusMission{}
sel := "*"
if len(selectCols) > 0 {
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
}
query := fmt.Sprintf(
"select %s from `bonus_mission` where `id`=?", sel,
)
q := queries.Raw(exec, query, id)
err := q.Bind(bonusMissionObj)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: unable to select from bonus_mission")
}
return bonusMissionObj, nil
}
// FindBonusMissionP retrieves a single record by ID with an executor, and panics on error.
func FindBonusMissionP(exec boil.Executor, id uint, selectCols ...string) *BonusMission {
retobj, err := FindBonusMission(exec, id, selectCols...)
if err != nil {
panic(boil.WrapErr(err))
}
return retobj
}
// InsertG a single record. See Insert for whitelist behavior description.
func (o *BonusMission) InsertG(whitelist ...string) error {
return o.Insert(boil.GetDB(), whitelist...)
}
// InsertGP a single record, and panics on error. See Insert for whitelist
// behavior description.
func (o *BonusMission) InsertGP(whitelist ...string) {
if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// InsertP a single record using an executor, and panics on error. See Insert
// for whitelist behavior description.
func (o *BonusMission) InsertP(exec boil.Executor, whitelist ...string) {
if err := o.Insert(exec, whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// Insert a single record using an executor.
// Whitelist behavior: If a whitelist is provided, only those columns supplied are inserted
// No whitelist behavior: Without a whitelist, columns are inferred by the following rules:
// - All columns without a default value are included (i.e. name, age)
// - All columns with a default, but non-zero are included (i.e. health = 75)
func (o *BonusMission) Insert(exec boil.Executor, whitelist ...string) error {
if o == nil {
return errors.New("models: no bonus_mission provided for insertion")
}
var err error
nzDefaults := queries.NonZeroDefaultSet(bonusMissionColumnsWithDefault, o)
key := makeCacheKey(whitelist, nzDefaults)
bonusMissionInsertCacheMut.RLock()
cache, cached := bonusMissionInsertCache[key]
bonusMissionInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := strmangle.InsertColumnSet(
bonusMissionColumns,
bonusMissionColumnsWithDefault,
bonusMissionColumnsWithoutDefault,
nzDefaults,
whitelist,
)
cache.valueMapping, err = queries.BindMapping(bonusMissionType, bonusMissionMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(bonusMissionType, bonusMissionMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO `bonus_mission` (`%s`) %%sVALUES (%s)%%s", strings.Join(wl, "`,`"), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO `bonus_mission` () VALUES ()"
}
var queryOutput, queryReturning string
if len(cache.retMapping) != 0 {
cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `bonus_mission` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, bonusMissionPrimaryKeyColumns))
}
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)
}
result, err := exec.Exec(cache.query, vals...)
if err != nil {
return errors.Wrap(err, "models: unable to insert into bonus_mission")
}
var lastID int64
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
lastID, err = result.LastInsertId()
if err != nil {
return ErrSyncFail
}
o.ID = uint(lastID)
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == bonusMissionMapping["ID"] {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.ID,
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)
}
err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
if err != nil {
return errors.Wrap(err, "models: unable to populate default values for bonus_mission")
}
CacheNoHooks:
if !cached {
bonusMissionInsertCacheMut.Lock()
bonusMissionInsertCache[key] = cache
bonusMissionInsertCacheMut.Unlock()
}
return nil
}
// UpdateG a single BonusMission record. See Update for
// whitelist behavior description.
func (o *BonusMission) UpdateG(whitelist ...string) error {
return o.Update(boil.GetDB(), whitelist...)
}
// UpdateGP a single BonusMission record.
// UpdateGP takes a whitelist of column names that should be updated.
// Panics on error. See Update for whitelist behavior description.
func (o *BonusMission) UpdateGP(whitelist ...string) {
if err := o.Update(boil.GetDB(), whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateP uses an executor to update the BonusMission, and panics on error.
// See Update for whitelist behavior description.
func (o *BonusMission) UpdateP(exec boil.Executor, whitelist ...string) {
err := o.Update(exec, whitelist...)
if err != nil {
panic(boil.WrapErr(err))
}
}
// Update uses an executor to update the BonusMission.
// 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.
func (o *BonusMission) Update(exec boil.Executor, whitelist ...string) error {
var err error
key := makeCacheKey(whitelist, nil)
bonusMissionUpdateCacheMut.RLock()
cache, cached := bonusMissionUpdateCache[key]
bonusMissionUpdateCacheMut.RUnlock()
if !cached {
wl := strmangle.UpdateColumnSet(
bonusMissionColumns,
bonusMissionPrimaryKeyColumns,
whitelist,
)
if len(wl) == 0 {
return errors.New("models: unable to update bonus_mission, could not build whitelist")
}
cache.query = fmt.Sprintf("UPDATE `bonus_mission` SET %s WHERE %s",
strmangle.SetParamNames("`", "`", 0, wl),
strmangle.WhereClause("`", "`", 0, bonusMissionPrimaryKeyColumns),
)
cache.valueMapping, err = queries.BindMapping(bonusMissionType, bonusMissionMapping, append(wl, bonusMissionPrimaryKeyColumns...))
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, "models: unable to update bonus_mission row")
}
if !cached {
bonusMissionUpdateCacheMut.Lock()
bonusMissionUpdateCache[key] = cache
bonusMissionUpdateCacheMut.Unlock()
}
return nil
}
// UpdateAllP updates all rows with matching column names, and panics on error.
func (q bonusMissionQuery) UpdateAllP(cols M) {
if err := q.UpdateAll(cols); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateAll updates all rows with the specified column values.
func (q bonusMissionQuery) UpdateAll(cols M) error {
queries.SetUpdate(q.Query, cols)
_, err := q.Query.Exec()
if err != nil {
return errors.Wrap(err, "models: unable to update all for bonus_mission")
}
return nil
}
// UpdateAllG updates all rows with the specified column values.
func (o BonusMissionSlice) UpdateAllG(cols M) error {
return o.UpdateAll(boil.GetDB(), cols)
}
// UpdateAllGP updates all rows with the specified column values, and panics on error.
func (o BonusMissionSlice) UpdateAllGP(cols M) {
if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateAllP updates all rows with the specified column values, and panics on error.
func (o BonusMissionSlice) UpdateAllP(exec boil.Executor, cols M) {
if err := o.UpdateAll(exec, cols); err != nil {
panic(boil.WrapErr(err))
}
}
// UpdateAll updates all rows with the specified column values, using an executor.
func (o BonusMissionSlice) UpdateAll(exec boil.Executor, cols M) error {
ln := int64(len(o))
if ln == 0 {
return nil
}
if len(cols) == 0 {
return errors.New("models: 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++
}
// Append all of the primary key values for each column
for _, obj := range o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), bonusMissionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := fmt.Sprintf("UPDATE `bonus_mission` SET %s WHERE %s",
strmangle.SetParamNames("`", "`", 0, colNames),
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, bonusMissionPrimaryKeyColumns, 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, "models: unable to update all in bonusMission slice")
}
return nil
}
// UpsertG attempts an insert, and does an update or ignore on conflict.
func (o *BonusMission) UpsertG(updateColumns []string, whitelist ...string) error {
return o.Upsert(boil.GetDB(), updateColumns, whitelist...)
}
// UpsertGP attempts an insert, and does an update or ignore on conflict. Panics on error.
func (o *BonusMission) UpsertGP(updateColumns []string, whitelist ...string) {
if err := o.Upsert(boil.GetDB(), updateColumns, whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// UpsertP attempts an insert using an executor, and does an update or ignore on conflict.
// UpsertP panics on error.
func (o *BonusMission) UpsertP(exec boil.Executor, updateColumns []string, whitelist ...string) {
if err := o.Upsert(exec, updateColumns, whitelist...); err != nil {
panic(boil.WrapErr(err))
}
}
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
func (o *BonusMission) Upsert(exec boil.Executor, updateColumns []string, whitelist ...string) error {
if o == nil {
return errors.New("models: no bonus_mission provided for upsert")
}
nzDefaults := queries.NonZeroDefaultSet(bonusMissionColumnsWithDefault, o)
// Build cache key in-line uglily - mysql vs postgres problems
buf := strmangle.GetBuffer()
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)
bonusMissionUpsertCacheMut.RLock()
cache, cached := bonusMissionUpsertCache[key]
bonusMissionUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := strmangle.InsertColumnSet(
bonusMissionColumns,
bonusMissionColumnsWithDefault,
bonusMissionColumnsWithoutDefault,
nzDefaults,
whitelist,
)
update := strmangle.UpdateColumnSet(
bonusMissionColumns,
bonusMissionPrimaryKeyColumns,
updateColumns,
)
if len(update) == 0 {
return errors.New("models: unable to upsert bonus_mission, could not build update column list")
}
cache.query = queries.BuildUpsertQueryMySQL(dialect, "bonus_mission", update, insert)
cache.retQuery = fmt.Sprintf(
"SELECT %s FROM `bonus_mission` WHERE `id`=?",
strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
)
cache.valueMapping, err = queries.BindMapping(bonusMissionType, bonusMissionMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(bonusMissionType, bonusMissionMapping, 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)
}
result, err := exec.Exec(cache.query, vals...)
if err != nil {
return errors.Wrap(err, "models: unable to upsert for bonus_mission")
}
var lastID int64
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
goto CacheNoHooks
}
lastID, err = result.LastInsertId()
if err != nil {
return ErrSyncFail
}
o.ID = uint(lastID)
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == bonusMissionMapping["ID"] {
goto CacheNoHooks
}
identifierCols = []interface{}{
o.ID,
}
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)
}
err = exec.QueryRow(cache.retQuery, identifierCols...).Scan(returns...)
if err != nil {
return errors.Wrap(err, "models: unable to populate default values for bonus_mission")
}
CacheNoHooks:
if !cached {
bonusMissionUpsertCacheMut.Lock()
bonusMissionUpsertCache[key] = cache
bonusMissionUpsertCacheMut.Unlock()
}
return nil
}
// DeleteP deletes a single BonusMission record with an executor.
// DeleteP will match against the primary key column to find the record to delete.
// Panics on error.
func (o *BonusMission) DeleteP(exec boil.Executor) {
if err := o.Delete(exec); err != nil {
panic(boil.WrapErr(err))
}
}
// DeleteG deletes a single BonusMission record.
// DeleteG will match against the primary key column to find the record to delete.
func (o *BonusMission) DeleteG() error {
if o == nil {
return errors.New("models: no BonusMission provided for deletion")
}
return o.Delete(boil.GetDB())
}
// DeleteGP deletes a single BonusMission record.
// DeleteGP will match against the primary key column to find the record to delete.
// Panics on error.
func (o *BonusMission) DeleteGP() {
if err := o.DeleteG(); err != nil {
panic(boil.WrapErr(err))
}
}
// Delete deletes a single BonusMission record with an executor.
// Delete will match against the primary key column to find the record to delete.
func (o *BonusMission) Delete(exec boil.Executor) error {
if o == nil {
return errors.New("models: no BonusMission provided for delete")
}
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), bonusMissionPrimaryKeyMapping)
sql := "DELETE FROM `bonus_mission` WHERE `id`=?"
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, "models: unable to delete from bonus_mission")
}
return nil
}
// DeleteAllP deletes all rows, and panics on error.
func (q bonusMissionQuery) DeleteAllP() {
if err := q.DeleteAll(); err != nil {
panic(boil.WrapErr(err))
}
}
// DeleteAll deletes all matching rows.
func (q bonusMissionQuery) DeleteAll() error {
if q.Query == nil {
return errors.New("models: no bonusMissionQuery provided for delete all")
}
queries.SetDelete(q.Query)
_, err := q.Query.Exec()
if err != nil {
return errors.Wrap(err, "models: unable to delete all from bonus_mission")
}
return nil
}
// DeleteAllGP deletes all rows in the slice, and panics on error.
func (o BonusMissionSlice) DeleteAllGP() {
if err := o.DeleteAllG(); err != nil {
panic(boil.WrapErr(err))
}
}
// DeleteAllG deletes all rows in the slice.
func (o BonusMissionSlice) DeleteAllG() error {
if o == nil {
return errors.New("models: no BonusMission slice provided for delete all")
}
return o.DeleteAll(boil.GetDB())
}
// DeleteAllP deletes all rows in the slice, using an executor, and panics on error.
func (o BonusMissionSlice) DeleteAllP(exec boil.Executor) {
if err := o.DeleteAll(exec); err != nil {
panic(boil.WrapErr(err))
}
}
// DeleteAll deletes all rows in the slice, using an executor.
func (o BonusMissionSlice) DeleteAll(exec boil.Executor) error {
if o == nil {
return errors.New("models: no BonusMission slice provided for delete all")
}
if len(o) == 0 {
return nil
}
var args []interface{}
for _, obj := range o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), bonusMissionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "DELETE FROM `bonus_mission` WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, bonusMissionPrimaryKeyColumns, 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, "models: unable to delete all from bonusMission slice")
}
return nil
}
// ReloadGP refetches the object from the database and panics on error.
func (o *BonusMission) ReloadGP() {
if err := o.ReloadG(); err != nil {
panic(boil.WrapErr(err))
}
}
// ReloadP refetches the object from the database with an executor. Panics on error.
func (o *BonusMission) ReloadP(exec boil.Executor) {
if err := o.Reload(exec); err != nil {
panic(boil.WrapErr(err))
}
}
// ReloadG refetches the object from the database using the primary keys.
func (o *BonusMission) ReloadG() error {
if o == nil {
return errors.New("models: no BonusMission provided for reload")
}
return o.Reload(boil.GetDB())
}
// Reload refetches the object from the database
// using the primary keys with an executor.
func (o *BonusMission) Reload(exec boil.Executor) error {
ret, err := FindBonusMission(exec, o.ID)
if err != nil {
return err
}
*o = *ret
return nil
}
// ReloadAllGP refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
// Panics on error.
func (o *BonusMissionSlice) ReloadAllGP() {
if err := o.ReloadAllG(); err != nil {
panic(boil.WrapErr(err))
}
}
// ReloadAllP refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
// Panics on error.
func (o *BonusMissionSlice) ReloadAllP(exec boil.Executor) {
if err := o.ReloadAll(exec); err != nil {
panic(boil.WrapErr(err))
}
}
// ReloadAllG refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *BonusMissionSlice) ReloadAllG() error {
if o == nil {
return errors.New("models: empty BonusMissionSlice provided for reload all")
}
return o.ReloadAll(boil.GetDB())
}
// ReloadAll refetches every row with matching primary key column values
// and overwrites the original object slice with the newly updated slice.
func (o *BonusMissionSlice) ReloadAll(exec boil.Executor) error {
if o == nil || len(*o) == 0 {
return nil
}
bonusMissions := BonusMissionSlice{}
var args []interface{}
for _, obj := range *o {
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), bonusMissionPrimaryKeyMapping)
args = append(args, pkeyArgs...)
}
sql := "SELECT `bonus_mission`.* FROM `bonus_mission` WHERE " +
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, bonusMissionPrimaryKeyColumns, len(*o))
q := queries.Raw(exec, sql, args...)
err := q.Bind(&bonusMissions)
if err != nil {
return errors.Wrap(err, "models: unable to reload all in BonusMissionSlice")
}
*o = bonusMissions
return nil
}
// BonusMissionExists checks if the BonusMission row exists.
func BonusMissionExists(exec boil.Executor, id uint) (bool, error) {
var exists bool
sql := "select exists(select 1 from `bonus_mission` where `id`=? limit 1)"
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, sql)
fmt.Fprintln(boil.DebugWriter, id)
}
row := exec.QueryRow(sql, id)
err := row.Scan(&exists)
if err != nil {
return false, errors.Wrap(err, "models: unable to check if bonus_mission exists")
}
return exists, nil
}
// BonusMissionExistsG checks if the BonusMission row exists.
func BonusMissionExistsG(id uint) (bool, error) {
return BonusMissionExists(boil.GetDB(), id)
}
// BonusMissionExistsGP checks if the BonusMission row exists. Panics on error.
func BonusMissionExistsGP(id uint) bool {
e, err := BonusMissionExists(boil.GetDB(), id)
if err != nil {
panic(boil.WrapErr(err))
}
return e
}
// BonusMissionExistsP checks if the BonusMission row exists. Panics on error.
func BonusMissionExistsP(exec boil.Executor, id uint) bool {
e, err := BonusMissionExists(exec, id)
if err != nil {
panic(boil.WrapErr(err))
}
return e
}
func Test(test string) string {
return test
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment