當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gorp.DbMap類代碼示例

本文整理匯總了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"})
}
開發者ID:renhuiyang,項目名稱:go-shoppingweb-practise,代碼行數:29,代碼來源:users.go

示例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
}
開發者ID:NetaGaming,項目名稱:LeagueLoader,代碼行數:33,代碼來源:games.go

示例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
}
開發者ID:NetaGaming,項目名稱:LeagueLoader,代碼行數:27,代碼來源:summoners.go

示例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)
}
開發者ID:sisteamnik,項目名稱:guseful,代碼行數:7,代碼來源:tags.go

示例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
}
開發者ID:sisteamnik,項目名稱:guseful,代碼行數:7,代碼來源:tags.go

示例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
}
開發者ID:sisteamnik,項目名稱:guseful,代碼行數:34,代碼來源:db.go

示例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
}
開發者ID:DeyV,項目名稱:go-newsagg,代碼行數:7,代碼來源:tagcloud.go

示例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
}
開發者ID:DaleWebb,項目名稱:readraptor,代碼行數:28,代碼來源:article.go

示例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
}
開發者ID:DaleWebb,項目名稱:readraptor,代碼行數:7,代碼來源:article.go

示例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
}
開發者ID:kayac,項目名稱:alphawing,代碼行數:26,代碼來源:util.go

示例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
}
開發者ID:sisteamnik,項目名稱:guseful,代碼行數:7,代碼來源:rate.go

示例12: PrintTable

func PrintTable(dbMap *gorp.DbMap) {
	var users []User

	dbMap.Select(&users, "SELECT * FROM users")

	fmt.Printf("%+v\n", users)
}
開發者ID:GoSteelProgrammers,項目名稱:talk-review-orms,代碼行數:7,代碼來源:crud.go

示例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
}
開發者ID:sisteamnik,項目名稱:guseful,代碼行數:7,代碼來源:rate.go

示例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
}
開發者ID:sisteamnik,項目名稱:guseful,代碼行數:7,代碼來源:db.go

示例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)
}
開發者ID:ukitazume,項目名稱:bunkai,代碼行數:7,代碼來源:server.go


注:本文中的github.com/coopernurse/gorp.DbMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。