本文整理汇总了Golang中github.com/coopernurse/gorp.DbMap类的典型用法代码示例。如果您正苦于以下问题:Golang DbMap类的具体用法?Golang DbMap怎么用?Golang DbMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DbMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostUser
func PostUser(r render.Render, dbmap *gorp.DbMap, res http.ResponseWriter, u User, e binding.Errors) {
if e != nil {
r.JSON(http.StatusBadRequest, map[string]string{"message": e[0].Message})
return
}
//check user exists yet or not?
var count int64
count, err := dbmap.SelectInt("SELECT count(*) FROM CUSTOMER WHERE CUS_TEL=?", u.PhoneNumber)
if err != nil {
glog.V(1).Infof("[DEBUG:] Search customer by tel:%v fail:%v", u.PhoneNumber, err)
r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
return
}
if count > 0 {
glog.V(1).Infof("Customer with tel:%v exists yet", u.PhoneNumber)
r.JSON(http.StatusConflict, map[string]string{"message": "User with same Tel exists"})
return
}
//insert new user info to db;
err = dbmap.Insert(&u)
if err != nil {
glog.V(1).Infof("[DEBUG:] Insert customer %v fail:%v", u, err)
r.JSON(http.StatusConflict, map[string]string{"message": "DB ERROR"})
return
}
r.JSON(200, map[string]string{"message": "SUCCESS"})
}
示例2: 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
}
示例3: getSummoners
// Get list of available summoners
func getSummoners(dbmap *gorp.DbMap) (
<-chan SummonerInfo, <-chan SummonerInfo) {
summonerChan1 := make(chan SummonerInfo)
summonerChan2 := make(chan SummonerInfo)
// select summoners
var summoners []SummonerInfo
_, err := dbmap.Select(
&summoners,
"select id from summoners")
checkErr(err, "Selecting summoner ids failed")
globalWg.Add(1)
go func() {
for _, n := range summoners {
summonerChan1 <- n
summonerChan2 <- n
}
close(summonerChan1)
close(summonerChan2)
globalWg.Done()
}()
return summonerChan1, summonerChan2
}
示例4: SetForItem
func SetForItem(db *gorp.DbMap, tagId, itemId int64, itemType string) error {
t := Tags{}
t.Id = tagId
t.ItemId = itemId
t.ItemType = itemType
return db.Insert(&t)
}
示例5: createTag
func createTag(db *gorp.DbMap, t Tag) (Tag, error) {
var err error
if !tagExist(db, t.Title) {
err = db.Insert(&t)
}
return t, err
}
示例6: CreateOrder
func CreateOrder(db *gorp.DbMap, customer, storeid, deliveryid int64, phone,
address string, products []OrderProduct, price float64) (Order, error) {
t := time.Now().UnixNano()
o := Order{
CustomerId: customer,
StoreId: storeid,
DeliveryId: deliveryid,
Phone: phone,
Price: price,
Address: address,
Created: t,
Updated: t,
}
tx, err := db.Begin()
if err != nil {
return o, err
}
err = tx.Insert(&o)
if err != nil {
tx.Rollback()
return o, err
}
for _, v := range products {
v.OrderId = o.Id
err := tx.Insert(&v)
if err != nil {
tx.Rollback()
return o, err
}
}
tx.Commit()
o.Products = products
return o, err
}
示例7: getAllCats
func getAllCats(dbmap *gorp.DbMap) []interface{} {
tab, err := dbmap.Select(Category{}, "SELECT * FROM Category")
if err != nil {
fmt.Println("Problem z Category InitDb")
}
return tab
}
示例8: AddReadReceipts
func (c *Article) AddReadReceipts(dbmap *gorp.DbMap) {
var delivered []string
_, err := dbmap.Select(&delivered, `
select readers.distinct_id
from articles
inner join read_receipts on read_receipts.article_id = articles.id
inner join readers on read_receipts.reader_id = readers.id
where articles.id = $1
and last_read_at > articles.updated_at`, c.Id)
if err != nil {
panic(err)
}
c.Delivered = delivered
var pending []string
_, err = dbmap.Select(&pending, `
select readers.distinct_id
from articles
inner join read_receipts on read_receipts.article_id = articles.id
inner join readers on read_receipts.reader_id = readers.id
where articles.id = $1
and (last_read_at is null or
last_read_at < articles.updated_at)`, c.Id)
if err != nil {
panic(err)
}
c.Pending = pending
}
示例9: FindArticleWithReadReceipts
func FindArticleWithReadReceipts(dbmap *gorp.DbMap, id int64) (*Article, error) {
var a Article
err := dbmap.SelectOne(&a, "select * from articles where id = $1", id)
a.AddReadReceipts(dbmap)
return &a, err
}
示例10: Transact
func Transact(dbm *gorp.DbMap, f func(gorp.SqlExecutor) error) error {
txn, err := dbm.Begin()
if err != nil {
return err
}
defer func() {
if txn == nil {
return
}
if err := txn.Rollback(); err != nil && err != sql.ErrTxDone {
panic(err)
}
}()
err = f(txn)
if err != nil {
return err
}
err = txn.Commit()
if err != nil && err != sql.ErrTxDone {
return err
}
txn = nil
return nil
}
示例11: GetRateById
func (r Rate) GetRateById(Db *gorp.DbMap, id int64) Rate {
Db.SelectOne(&r, "select * from Rate where Id = ?", id)
if r.Id != 0 {
r.Votes = r.GetVotes(Db)
}
return r
}
示例12: PrintTable
func PrintTable(dbMap *gorp.DbMap) {
var users []User
dbMap.Select(&users, "SELECT * FROM users")
fmt.Printf("%+v\n", users)
}
示例13: GetVotes
func (r Rate) GetVotes(Db *gorp.DbMap) []Vote {
if r.Id == 0 {
return []Vote{}
}
Db.Select(&r.Votes, "select * from Vote where RateId = ?", r.Id)
return r.Votes
}
示例14: GetGeoObjects
func GetGeoObjects(db *gorp.DbMap, tp string, offset, limit int64) ([]GeoObject,
error) {
o := []GeoObject{}
_, err := db.Select(&o, "select * from GeoObject where Type = ? limit ?,?",
tp, offset, limit)
return o, err
}
示例15: UserGet
func UserGet(ren render.Render, params martini.Params, dbmap *gorp.DbMap, s sessions.Session) {
var usr User
log.Println(params)
err := dbmap.SelectOne(&usr, "SELECT * from users WHERE id = $1", s.Get("userId"))
PanicIf(err)
ren.JSON(200, usr)
}