Exemple #1
0
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
}
Exemple #2
0
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
}
Exemple #3
0
func (s *Set) UpdateAll(q map[string]interface{}, updQuery map[string]interface{}) (int, error) {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	updQuery = convert.Recurs(updQuery, fromGeneral).(map[string]interface{})
	chi, err := s.db.C(s.coll).UpdateAll(q, updQuery)
	return chi.Updated, err
}
Exemple #4
0
func (s *Set) Update(q map[string]interface{}, updQuery map[string]interface{}) error {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	updQuery = convert.Recurs(updQuery, fromGeneral).(map[string]interface{})
	return s.db.C(s.coll).Update(q, updQuery)
}
Exemple #5
0
func (s *Set) Insert(d map[string]interface{}) error {
	d = convert.Recurs(d, fromGeneral).(map[string]interface{})
	return s.db.C(s.coll).Insert(d)
}
Exemple #6
0
func (s *Set) Count(q map[string]interface{}) (int, error) {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	return s.db.C(s.coll).Find(q).Count()
}
Exemple #7
0
func (s *Set) RemoveAll(q map[string]interface{}) (int, error) {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	chi, err := s.db.C(s.coll).RemoveAll(q)
	return chi.Removed, err
}
Exemple #8
0
func (s *Set) Remove(q map[string]interface{}) error {
	q = convert.Recurs(q, fromGeneral).(map[string]interface{})
	return s.db.C(s.coll).Remove(q)
}