Esempio n. 1
0
File: set.go Progetto: Laller/nocrud
func (s *Set) Find(q map[string]interface{}) ([]map[string]interface{}, error) {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	c := s.db.C(s.coll).Find(q)
	if s.skip != 0 {
		c.Skip(s.skip)
	}
	if s.limit != 0 {
		c.Limit(s.limit)
	}
	if len(s.sort) > 0 {
		c.Sort(s.sort...)
	}
	var res []interface{}
	err := c.All(&res)
	if err != nil {
		return nil, err
	}
	isl := convert.Clean(res).([]interface{})
	ret := []map[string]interface{}{}
	for _, v := range isl {
		ret = append(ret, v.(map[string]interface{}))
	}
	ret = convert.Recurs(ret, toGeneral).([]map[string]interface{})
	return ret, nil
}
Esempio n. 2
0
File: set.go Progetto: Laller/nocrud
func (s *Set) FindOne(q map[string]interface{}) (map[string]interface{}, error) {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	var res interface{}
	err := s.db.C(s.coll).Find(q).One(&res)
	if err != nil {
		return nil, err
	}
	ret := convert.Clean(res).(map[string]interface{})
	return convert.Recurs(ret, toGeneral).(map[string]interface{}), nil
}