Example #1
0
File: set.go Project: 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
}
Example #2
0
File: set.go Project: 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
}
Example #3
0
File: set.go Project: Laller/nocrud
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
}
Example #4
0
File: set.go Project: Laller/nocrud
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)
}
Example #5
0
File: set.go Project: Laller/nocrud
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)
}
Example #6
0
File: set.go Project: Laller/nocrud
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()
}
Example #7
0
File: set.go Project: Laller/nocrud
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
}
Example #8
0
File: set.go Project: Laller/nocrud
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)
}