当前位置: 首页>>代码示例>>Golang>>正文


Golang DbMap.Exec方法代码示例

本文整理汇总了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
}
开发者ID:NetaGaming,项目名称:LeagueLoader,代码行数:33,代码来源:games.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:8,代码来源:db.go

示例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")
}
开发者ID:NetaGaming,项目名称:LeagueLoader,代码行数:15,代码来源:leagueloader.go

示例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()
	}()

}
开发者ID:NetaGaming,项目名称:LeagueLoader,代码行数:51,代码来源:summoners.go

示例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()
	}()
}
开发者ID:NetaGaming,项目名称:LeagueLoader,代码行数:43,代码来源:games.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:42,代码来源:rate.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:23,代码来源:db.go

示例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)
}
开发者ID:ukitazume,项目名称:bunkai,代码行数:5,代码来源:server.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:5,代码来源:db.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:5,代码来源:db.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:5,代码来源:db.go

示例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
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:5,代码来源:comments.go


注:本文中的github.com/coopernurse/gorp.DbMap.Exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。