本文整理汇总了Golang中github.com/coopernurse/gorp.DbMap.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang DbMap.Exec方法的具体用法?Golang DbMap.Exec怎么用?Golang DbMap.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coopernurse/gorp.DbMap
的用法示例。
在下文中一共展示了DbMap.Exec方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateGameInfo
// Updates the common game information
func updateGameInfo(games <-chan GameInfo, db *gorp.DbMap) <-chan GameInfo {
// TODO: Use insert/update query instead
var gameInfoQuery string = `
INSERT IGNORE INTO game_info
(id, mode, type, subType, mapId, date)
VALUES
(?, ?, ?, ?, ?, FROM_UNIXTIME(?))`
out := make(chan GameInfo)
globalWg.Add(1)
go func() {
for gi := range games {
_, infoErr := db.Exec(
gameInfoQuery,
gi.Game.GameID,
gi.Game.GameMode,
gi.Game.GameType,
gi.Game.SubType,
gi.Game.MapID,
gi.Game.CreateDate/1000)
checkErr(infoErr, "Unable to insert new game info")
out <- gi
}
close(out)
globalWg.Done()
}()
return out
}
示例2: AdminSetPublished
func AdminSetPublished(db *gorp.DbMap, id int64, published bool) error {
p := 0
if published {
p = 1
}
_, err := db.Exec("update New set Published = ? where Id =?", p, id)
return err
}
示例3: saveLoadReport
// Saves runttime report to db
func saveLoadReport(StartTime string, EndTime string, Records int, dbmap *gorp.DbMap) {
var reportQuery string = `INSERT INTO runtimes
(startTime, endTime, records)
VALUES
(?,?,?)`
_, err := dbmap.Exec(reportQuery,
StartTime,
EndTime,
Records)
checkErr(err, "Could not report to database")
fmt.Println("Reported")
}
示例4: updateSummoners
// Updates summoner name and level
func updateSummoners(summoners <-chan SummonerInfo, dbmap *gorp.DbMap) {
// we'll keep all the summoners details in here
var SummonersGoRiot map[int64]goriot.Summoner = make(map[int64]goriot.Summoner)
// Get summoner data from Riot in batches of
// forty and then combine them
go func() {
globalWg.Add(1)
var selectQueries []string
for s := range summoners {
// get riot data
riotData, err := goriot.SummonerByID(goriot.NA, s.ID)
checkErr(err, "Could not load summoners from Riot")
// add to larger structure
for k, v := range riotData {
SummonersGoRiot[k] = v
}
}
// Build a slice of select queries that will be UNIONd
// together to help reduce DB calls
for _, summoner := range SummonersGoRiot {
selectQueries = append(
selectQueries,
fmt.Sprintf(
"SELECT %d id, %d level, '%s' name",
summoner.ID,
summoner.SummonerLevel,
summoner.Name))
}
// build final update query
var updateQuery string = fmt.Sprintf(
`UPDATE summoners s INNER JOIN (
%s
) r USING(id)
SET s.level = r.level, s.name = r.name, s.last_update = UTC_TIMESTAMP();`,
strings.Join(selectQueries, " UNION "))
// run query and check for errors
_, err := dbmap.Exec(updateQuery)
checkErr(err, "Summoner update failed")
globalWg.Done()
}()
}
示例5: updateSummonerGames
// Updates a summoners specific game information
func updateSummonerGames(
gameStats <-chan GameInfo,
db *gorp.DbMap) {
// save summoner_game
// TODO: Use insert/update query instead
var summonerGameQuery string = `
INSERT IGNORE INTO summoner_games
(summonerId,
gameId,
championId,
spellOne,
spellTwo,
minionsKilled,
numDeaths,
assists,
championsKilled,
won)
VALUES
(?,?,?,?,?,?,?,?,?,?)`
globalWg.Add(1)
go func() {
for gs := range gameStats {
_, sgErr := db.Exec(
summonerGameQuery,
gs.SummonerID,
gs.Game.GameID,
gs.Game.ChampionID,
gs.Game.Spell1,
gs.Game.Spell2,
gs.Game.Statistics.MinionsKilled,
gs.Game.Statistics.NumDeaths,
gs.Game.Statistics.Assists,
gs.Game.Statistics.ChampionsKilled,
gs.Game.Statistics.Win)
checkErr(sgErr, "Could not save summoner game info")
}
globalWg.Done()
}()
}
示例6: Vote
func (r Rate) Vote(Db *gorp.DbMap, v string, u int64) (Rate, error) {
var el int64
if r.Id == 0 {
return Rate{}, errors.New("Rate not found")
}
r = r.GetRate(Db, r.ItemType, r.ItemId)
id, err := Db.SelectInt("select RateId from Vote where RateId = ? and"+
" UserId = ?", r.Id, u)
if err != nil {
return Rate{}, err
}
if id != 0 {
return Rate{}, errors.New("You have already voted")
}
switch v {
case "a":
el = -1
r.Against++
Db.Exec("update Rate set Against = Against+1 where Id = ?", r)
break
case "b":
el = 1
r.Behind++
Db.Exec("update Rate set Behind = Behind+1 where Id = ?", r)
break
default:
return Rate{}, errors.New("Vote election undefined")
}
r.Rate = WilsonSum(r.Behind-r.Against, r.Against+r.Behind)
vote := Vote{
RateId: r.Id,
Value: el,
UserId: u,
}
Db.Update(&r)
Db.Insert(&vote)
return r, nil
}
示例7: BasketAdd
func BasketAdd(db *gorp.DbMap, userid, storeid, productid, count int64) error {
t := time.Now().UnixNano()
b := StoreBasket{
UserId: userid,
StoreId: storeid,
ProductId: productid,
Count: count,
Created: t,
Updated: t,
}
res, err := db.Exec("update StoreBasket set Count = Count + ?, Updated = ?"+
" where UserId = ? and StoreId=? and ProductId=?",
count, t, userid, storeid, productid)
if err != nil {
return err
}
if num, err := res.RowsAffected(); err == nil && num == 0 {
err := db.Insert(&b)
return err
}
return err
}
示例8: SentenceDelete
func SentenceDelete(ren render.Render, params martini.Params, dbmap *gorp.DbMap) {
_, err := dbmap.Exec("DELETE FROM sentences WHERE id= $1", params["id"])
PanicIf(err)
ren.JSON(200, nil)
}
示例9: AdminSetDeleted
func AdminSetDeleted(db *gorp.DbMap, id int64) error {
_, err := db.Exec("update New set Deleted = ? where Id = ?",
time.Now().UnixNano(), id)
return err
}
示例10: BasketClean
func BasketClean(db *gorp.DbMap, userid, storeid int64) error {
_, err := db.Exec("delete from StoreBasket where UserId = ? and "+
"StoreId = ?", userid, storeid)
return err
}
示例11: BasketRemove
func BasketRemove(db *gorp.DbMap, userid, storeid, productid int64) error {
_, err := db.Exec("delete from StoreBasket where UserId = ? and "+
"StoreId = ? and ProductId=?", userid, storeid, productid)
return err
}
示例12: DeleteComment
func DeleteComment(db *gorp.DbMap, commentId int64) error {
_, err := db.Exec("update Comment set Deleted = ? where Id = ?",
time.Now().UnixNano(), commentId)
return err
}