• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang gorp.DbMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/coopernurse/gorp.DbMap的典型用法代码示例。如果您正苦于以下问题:Golang DbMap类的具体用法?Golang DbMap怎么用?Golang DbMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DbMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: NewForStruct

func NewForStruct(dbmap *gorp.DbMap, i interface{}) (*builder, error) {
	table := dbmap.GetTable(i)
	if table == nil {
		return nil, TableNotDefined
	}
	return New(table.TableName), nil
}
开发者ID:rf-,项目名称:gologs,代码行数:7,代码来源:builder.go


示例17: NewPassword

func (u *User) NewPassword(db *gorp.DbMap, password string) error {
	u.HashedPassword, _ = bcrypt.GenerateFromPassword(
		[]byte(password), bcrypt.DefaultCost)
	u.Updated = time.Now().UnixNano()
	_, err := db.Update(u)
	return err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:7,代码来源:db.go


示例18: AddImages

func (n New) AddImages(db *gorp.DbMap, iids []int64) error {
	n.GetImages(db)
	for _, v := range n.Images {
		for _, j := range iids {
			if v == j {
				return errors.New("Image already taken")
			}
		}
	}
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	for _, v := range iids {
		NewImage := NewImages{
			NewId:   n.Id,
			ImageId: v,
		}
		err := tx.Insert(&NewImage)
		if err != nil {
			tx.Rollback()
			return err
		}
	}
	tx.Commit()
	return nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:27,代码来源:db.go


示例19: SignUp

func (u *User) SignUp(db *gorp.DbMap, s SmsSender, firstname, lastname, phone,
	password string) error {
	u.FirstName = firstname
	u.LastName = lastname
	u.Phone = phone
	u.HashedPassword, _ = bcrypt.GenerateFromPassword(
		[]byte(password), bcrypt.DefaultCost)

	_, err := db.Update(u)
	if err != nil {
		return err
	}

	conf, err := generateConfirmation(db, u.Id)
	if err != nil {
		return err
	}

	message := fmt.Sprintf("You code %d. Session %d.", conf.Code, conf.Id)

	err = s.Send(phone, message)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:27,代码来源:db.go


示例20: Query

// Query generates a Query for a target model.  The target that is
// passed in must be a pointer to a struct, and will be used as a
// reference for query construction.
func Query(m *gorp.DbMap, exec gorp.SqlExecutor, target interface{}) interfaces.Query {
	// Handle non-standard dialects
	switch src := m.Dialect.(type) {
	case gorp.MySQLDialect:
		m.Dialect = dialects.MySQLDialect{src}
	case gorp.SqliteDialect:
		m.Dialect = dialects.SqliteDialect{src}
	default:
	}
	plan := &QueryPlan{
		dbMap:    m,
		executor: exec,
	}

	targetVal := reflect.ValueOf(target)
	if targetVal.Kind() != reflect.Ptr || targetVal.Elem().Kind() != reflect.Struct {
		plan.Errors = append(plan.Errors, errors.New("A query target must be a pointer to struct"))
	}
	targetTable, err := plan.mapTable(targetVal)
	if err != nil {
		plan.Errors = append(plan.Errors, err)
		return plan
	}
	plan.target = targetVal
	plan.table = targetTable
	return plan
}
开发者ID:nelsam,项目名称:gorp_queries,代码行数:30,代码来源:query_plans.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gorp.SqlExecutor类代码示例发布时间:2022-05-23
下一篇:
Golang qbs.Qbs类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap