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


Golang DbMap.Select方法代码示例

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


在下文中一共展示了DbMap.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: insertOrUpdateContact

func insertOrUpdateContact(dbmap *gorp.DbMap, user, contactid, contactname, group string) error {
	var contacts []Contact
	_, err := dbmap.Select(&contacts, "SELECT * FROM contacts WHERE User=? AND ContactId=?", user, contactid)
	if err != nil {
		return err
	}

	if len(contacts) == 0 {
		contact := Contact{
			User:        user,
			ContactId:   contactid,
			ContactName: contactname,
			Group:       group,
		}
		err = dbmap.Insert(&contact)
		if err != nil {
			return err
		}
	} else if len(contacts) == 1 {
		contact := contacts[0]
		contact.ContactName = contactname
		contact.Group = group
		_, err = dbmap.Update(&contact)
		if err != nil {
			return err
		}
	} else {
		return errors.New("You have more than one contacts")
	}
	return nil
}
开发者ID:Narsil,项目名称:smsportal-server,代码行数:31,代码来源:smsserver.go

示例8: Persist

func (jail *Jail) Persist(db *gorp.DbMap) error {
	insert := false

	if len(jail.UUID) == 0 {
		insert = true
		count := 0

		db.Select(&count, "select count(UUID) from Jail where Name = ?", jail.Name)
		if count > 0 {
			return fmt.Errorf("Jail with name %s already exists", jail.Name)
		}
	}

	if err := jail.Validate(); err != nil {
		return err
	}

	if insert {
		db.Insert(jail)
	} else {
		db.Update(jail)
	}

	for _, device := range jail.NetworkDevices {
		device.VmUUID = jail.UUID
		if err := device.Persist(db, jail); err != nil {
			return err
		}
	}

	for _, mount := range jail.Mounts {
		if mount.MountPointID == 0 {
			mount.JailUUID = jail.UUID
			db.Insert(mount)
		} else {
			db.Update(mount)
		}
	}

	for _, option := range jail.Options {
		if option.OptionID == 0 {
			option.JailUUID = jail.UUID
			db.Insert(option)
		} else {
			db.Update(option)
		}
	}

	for _, route := range jail.Routes {
		if route.RouteID == 0 {
			route.VmUUID = jail.UUID
			db.Insert(route)
		} else {
			db.Update(route)
		}
	}

	return nil
}
开发者ID:virtbsd,项目名称:jail,代码行数:59,代码来源:jail.go

示例9: GetComments

func GetComments(db *gorp.DbMap, itemid int64, itemtype string) ([]Comment,
	error) {
	var cs []Comment
	_, err := db.Select(&cs, "select * from Comment where ItemId = ? and"+
		" ItemType = ? and Deleted = 0 order by Id desc",
		itemid, itemtype)
	return cs, err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:8,代码来源:comments.go

示例10: GetGoods

func GetGoods(dbmap *gorp.DbMap) ([]GoodInfo, error) {
	var ginfo []GoodInfo
	_, err := dbmap.Select(&ginfo, "SELECT * FROM GOODS")
	if err != nil {
		glog.V(1).Infof("[DEBUG:] Search goods fail:%v", err)
		return ginfo, err
	}
	return ginfo, nil
}
开发者ID:renhuiyang,项目名称:go-shoppingweb-practise,代码行数:9,代码来源:goods.go

示例11: GetAllNews

func GetAllNews(db *gorp.DbMap, offset, count int64) ([]New, error) {
	n := []New{}
	_, err := db.Select(&n, "select * from New order by Id desc limit ?,?",
		offset, count)
	if err != nil {
		return n, err
	}
	return n, nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:9,代码来源:db.go

示例12: Search

func Search(db *gorp.DbMap, q, itemtype string, offset,
	limit int64) ([]SearchIndex, error) {
	result := []SearchIndex{}
	q = strings.ToLower(q)
	_, err := db.Select(&result, "select * from SearchIndex where Keys like ?"+
		" and Type = ?  group by Type, ItemId order by Weight limit ?,?",
		"%"+q+"%", itemtype, offset, limit)
	return result, err
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:9,代码来源:db.go

示例13: GetItems

func GetItems(db *gorp.DbMap, tagId int64, itemType string) []int64 {
	var r = []int64{}
	_, err := db.Select(&r, "select ItemId from Tags where Id = ? and ItemType = ?",
		tagId, itemType)
	if err != nil {
		fmt.Println(err)
	}
	return r
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:9,代码来源:tags.go

示例14: UnreadArticles

func UnreadArticles(dbmap *gorp.DbMap, readerId int64) (keys []Article, err error) {
	_, err = dbmap.Select(&keys, `
		select articles.*, first_read_at, last_read_at, read_count
		from articles
		  inner join read_receipts on read_receipts.article_id = articles.id
		where (first_read_at is null or articles.updated_at < read_receipts.last_read_at)
		  and read_receipts.reader_id = $1`, readerId)

	return
}
开发者ID:DaleWebb,项目名称:readraptor,代码行数:10,代码来源:read_receipt.go

示例15: GetByUuid

func GetByUuid(db *gorp.DbMap, uuid string) (*User, error) {
	u, err := db.Select(User{}, "select * from User where Uuid = ?", uuid)
	if err != nil {
		return nil, err
	}
	if len(u) == 0 {
		return nil, errors.New("User not found")
	}
	return u[0].(*User), nil
}
开发者ID:sisteamnik,项目名称:guseful,代码行数:10,代码来源:db.go


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