// 增删改查操作的统一方法
// count操作resultPtr类型为*int
// list操作resultPtr类型为*map[string][]string
// find操作resultPtr类型为*map[string]interface{}
// insert操作resultPtr类型为*[]string，允许为nil(不接收id列表)
// update操作resultPtr为nil
// remove操作resultPtr为nil
776098
func Mgo(resultPtr interface{}, operate string, option map[string]interface{}) error {
	o := getOperator(operate)
	if o == nil {
		return errors.New("the db-operate " + operate + " does not exist!")
	}

	v := reflect.ValueOf(o).Elem()
	for key, val := range option {
		value := v.FieldByName(key)
		if value == (reflect.Value{}) || !value.CanSet() {
			continue
		}
		value.Set(reflect.ValueOf(val))
	}

	return o.Exec(resultPtr)
}
121806
func (kv *KV) Count() (i int) {
	rows, err := kv.db.Query(
		fmt.Sprintf("SELECT COUNT(*) FROM %s LIMIT 1", string(kv.table)),
	)
	if err != nil {
		return
	}
	defer rows.Close()
	if rows.Next() {
		err = rows.Scan(&i)
	}
	return
}
1157938
func (session *Session) queryStr(sqlStr string, paramStr ...interface{}) (result []map[string]string, err error) {
	rows, err := session.queryRows(sqlStr, paramStr...)
	if err != nil {
		return nil, err
	}
	result, err = rows2Strings(rows)
	rows.Close()
	return
}
389560
func (kv *KV) Count() (i int) {
	kv.db.View(func(tx *buntdb.Tx) error {
		err := tx.Ascend("", func(key, value string) bool {
			i++
			return true
		})
		return err
	})
	return
}
1119703
func (session *Session) Count(bean interface{}) (int64, error) {
	defer session.resetStatement()
	if session.IsAutoClose {
		defer session.Close()
	}

	var sqlStr string
	var args []interface{}
	if session.Statement.RawSQL == "" {
		sqlStr, args = session.Statement.genCountSQL(bean)
	} else {
		sqlStr = session.Statement.RawSQL
		args = session.Statement.RawParams
	}

	session.queryPreprocess(&sqlStr, args...)

	var err error
	var total int64
	if session.IsAutoCommit {
		err = session.DB().QueryRow(sqlStr, args...).Scan(&total)
	} else {
		err = session.Tx.QueryRow(sqlStr, args...).Scan(&total)
	}
	if err != nil {
		return 0, err
	}

	return total, nil
}
1159493
func (d DB) Count(item interface{}) (int,error) {
	object := strings.Split(reflect.TypeOf(item).String(),".")
	Collection := object[len(object) - 1]
	collection := d.MoDb.C(Collection)
	return collection.Find(nil).Count()
}
344010
func NewMapStringInterfacePtr(val map[string]interface{}) *map[string]interface{} {
	ptrValue := new(map[string]interface{})
	*ptrValue = map[string]interface{}{}
	for key, value := range val {
		(*ptrValue)[key] = value
	}
	return ptrValue
}
310675
func (mongo *MongoDB) Count() int {
	c, _ := mongo.Collection.Count()
	return c
}
1275987
func Slice(slicePtr interface{}, less func(i, j int) bool) {
	v := reflect.ValueOf(slicePtr).Elem()
	if v.Len() <= 1 {
		return
	}
	sort.Slice(v.Interface(), less)

	i := 0
	for j := 1; j < v.Len(); j++ {
		if !less(i, j) {
			continue
		}
		i++
		v.Index(i).Set(v.Index(j))
	}
	i++
	v.SetLen(i)
}
338342
func (self *Operation) Count() (int64, error) {
	var result int64
	// params := Params{Params: []interface{}{self.Key}}
	params := []interface{}{self.Key}
	if err := self.Call("operation.count", params, &result); err != nil {
		return -1, err
	}
	return result, nil
}
1312766
func (r *GormRepository) List(ctx context.Context, start *int, limit *int) ([]Space, int, error) {
	defer goa.MeasureSince([]string{"goa", "db", "space", "list"}, time.Now())
	result, count, err := r.listSpaceFromDB(ctx, nil, nil, start, limit)
	if err != nil {
		return nil, 0, errs.WithStack(err)
	}
	return result, count, nil
}
245389
func (m *metadataTracker) countsPtr(dev protocol.DeviceID, flags uint32) *Counts {
	// must be called with the mutex held

	key := metaKey{dev, flags}
	idx, ok := m.indexes[key]
	if !ok {
		idx = len(m.counts.Counts)
		m.counts.Counts = append(m.counts.Counts, Counts{DeviceID: dev[:], LocalFlags: flags})
		m.indexes[key] = idx
	}
	return &m.counts.Counts[idx]
}
241360
func (s *Sublist) Count() uint32 {
	s.RLock()
	defer s.RUnlock()
	return s.count
}
151943
func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error) {
	if session.isAutoClose {
		defer session.Close()
	}

	session.autoResetStatement = false
	err := session.find(rowsSlicePtr, condiBean...)
	if err != nil {
		return 0, err
	}

	sliceValue := reflect.Indirect(reflect.ValueOf(rowsSlicePtr))
	if sliceValue.Kind() != reflect.Slice && sliceValue.Kind() != reflect.Map {
		return 0, errors.New("needs a pointer to a slice or a map")
	}

	sliceElementType := sliceValue.Type().Elem()
	if sliceElementType.Kind() == reflect.Ptr {
		sliceElementType = sliceElementType.Elem()
	}
	session.autoResetStatement = true

	if session.statement.selectStr != "" {
		session.statement.selectStr = ""
	}
	if session.statement.OrderStr != "" {
		session.statement.OrderStr = ""
	}

	return session.Count(reflect.New(sliceElementType).Interface())
}
835384
func (db *Database) Count(value *uint8) error {
	key, _ := primaryKey(db.models[0])
	if key != "" {
		db = db.Select("count(" + handleIdentifier(key) + ")")
	} else {
		db = db.Select("count(*)")
	}
	return db.Scan(value)
}
1355352
func (p *queryPlan) limit() {
	if p.stm.IsLimitSet() {
		tracer.Trace(p.tracer, func() []string {
			return []string{"Limit results to " + strconv.Itoa(int(p.stm.Limit()))}
		})
		p.tbl.Limit(p.stm.Limit())
	}
}
971388
func CastToMapStringInterfacePtr(value interface{}) (*map[string]interface{}, bool) {
	casted, ok := CastToMapStringInterface(value)
	if !ok {
		return nil, false
	}
	return pointers.NewMapStringInterfacePtr(casted), true
}