コード例 #1
0
ファイル: client_store.go プロジェクト: gourd/kit
// Search a Client by its condition(s)
func (s *ClientStore) Search(
	q store.Query) store.Result {

	return upperio.NewResult(func() (res db.Result, err error) {
		// get collection
		coll, err := s.Coll()
		if err != nil {
			return
		}

		// retrieve entities by given query conditions
		conds := upperio.Conds(q.GetConds())
		if conds == nil {
			res = coll.Find()
		} else {
			res = coll.Find(conds)
		}

		// add sorting information, if any
		res = res.Sort(upperio.Sort(q)...)

		// handle paging
		if q.GetOffset() != 0 {
			res = res.Skip(uint(q.GetOffset()))
		}
		if q.GetLimit() != 0 {
			res = res.Limit(uint(q.GetLimit()))
		}

		return
	})

}
コード例 #2
0
ファイル: sort.go プロジェクト: gourd/kit
// Sort take a store query and returns upperio Sort usable parameter
func Sort(q store.Query) (res []interface{}) {
	ss := q.GetSorts().GetAll()
	res = make([]interface{}, 0, len(ss))
	for _, s := range ss {
		res = append(res, s.String())
	}
	return
}