// WithQueryFullCount is used to configure whether the query returns the full count of results
// before the last LIMIT statement
320136
func WithQueryFullCount(parent context.Context, value ...bool) context.Context {
	v := true
	if len(value) > 0 {
		v = value[0]
	}
	return context.WithValue(contextOrBackground(parent), keyQueryOptFullCount, v)
}
100823
func (s *CountService) Query(query Query) *CountService {
	s.query = query
	return s
}
283819
func (builder *SecondaryIndexQueryCommandBuilder) WithMaxResults(maxResults uint32) *SecondaryIndexQueryCommandBuilder {
	builder.protobuf.MaxResults = &maxResults
	return builder
}
396242
func (b *UpdateBuilder) Limit(count interface{}) *UpdateBuilder {
	if b.Update.Limit == nil {
		b.Update.Limit = &Limit{}
	}
	b.Update.Limit.Rowcount = makeValExpr(count)
	return b
}
39634
func WithMaxResults(maxResults int) userSearchF {
	return func(s userSearch) userSearch {
		s = append(s, userSearchParam{name: "maxResults", value: fmt.Sprintf("%d", maxResults)})
		return s
	}
}
143778
func (builder *TsQueryCommandBuilder) WithQuery(query string) *TsQueryCommandBuilder {
	builder.protobuf.Query = &riak_ts.TsInterpolation{Base: []byte(query)}
	return builder
}
247104
func (q Query) SingleWith(predicate func(interface{}) bool) (r interface{}) {
	next := q.Iterate()
	found := false

	for item, ok := next(); ok; item, ok = next() {
		if predicate(item) {
			if found {
				return nil
			}

			found = true
			r = item
		}
	}

	return
}
636728
func (builder *SearchCommandBuilder) WithQuery(query string) *SearchCommandBuilder {
	builder.protobuf.Q = []byte(query)
	return builder
}
1250643
func (builder *SearchCommandBuilder) WithFilterQuery(filterQuery string) *SearchCommandBuilder {
	builder.protobuf.Filter = []byte(filterQuery)
	return builder
}
208176
func (db *DB) CountPendingScans() (count int64, err error) {
	err = db.QueryRow(`SELECT COUNT(*) FROM scans
				  WHERE completion_perc = 0
				  AND attempts < 3 AND ack = false`).Scan(&count)
	return
}
1340008
func (_m *DBClient) IntervalsWithLimit(limit int) ([]models.Interval, error) {
	ret := _m.Called(limit)

	var r0 []models.Interval
	if rf, ok := ret.Get(0).(func(int) []models.Interval); ok {
		r0 = rf(limit)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.Interval)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(int) error); ok {
		r1 = rf(limit)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
232405
func (q *Query) SelectAndCount(values ...interface{}) (count int, firstErr error) {
	if q.stickyErr != nil {
		return 0, q.stickyErr
	}

	var wg sync.WaitGroup
	var mu sync.Mutex

	if q.limit >= 0 {
		wg.Add(1)
		go func() {
			defer wg.Done()
			err := q.Select(values...)
			if err != nil {
				mu.Lock()
				if firstErr == nil {
					firstErr = err
				}
				mu.Unlock()
			}
		}()
	}

	wg.Add(1)
	go func() {
		defer wg.Done()
		var err error
		count, err = q.Count()
		if err != nil {
			mu.Lock()
			if firstErr == nil {
				firstErr = err
			}
			mu.Unlock()
		}
	}()

	wg.Wait()
	return count, firstErr
}
671088
func countFunc(q query, t iterator) interface{} {
	var count = 0
	test := predicate(q)
	switch typ := q.Evaluate(t).(type) {
	case query:
		for node := typ.Select(t); node != nil; node = typ.Select(t) {
			if test(node) {
				count++
			}
		}
	}
	return float64(count)
}
735747
func (db *DB) ZLexCount(key []byte, min []byte, max []byte, rangeType uint8) (int64, error) {
	if min == nil {
		min = db.zEncodeStartSetKey(key)
	} else {
		min = db.zEncodeSetKey(key, min)
	}
	if max == nil {
		max = db.zEncodeStopSetKey(key)
	} else {
		max = db.zEncodeSetKey(key, max)
	}

	it := db.bucket.RangeIterator(min, max, rangeType)
	defer it.Close()

	var n int64
	for ; it.Valid(); it.Next() {
		n++
	}

	return n, nil
}
298008
func (q Query) LastWith(predicate func(interface{}) bool) (r interface{}) {
	next := q.Iterate()

	for item, ok := next(); ok; item, ok = next() {
		if predicate(item) {
			r = item
		}
	}

	return
}
683945
func (c *CandleService) HistoryWithQuery(
	symbol string,
	resolution bitfinex.CandleResolution,
	start bitfinex.Mts,
	end bitfinex.Mts,
	limit bitfinex.QueryLimit,
	sort bitfinex.SortOrder,
	) (*bitfinex.CandleSnapshot, error) {

		if symbol == "" {
		return nil, fmt.Errorf("symbol cannot be empty")
	}

	segments := []string{ "trade", string(resolution), symbol }

	req := NewRequestWithMethod(path.Join("candles", strings.Join(segments,":"), "HIST"), "GET")
	req.Params = make(url.Values)

	//req.Params.Add("end", strconv.FormatInt(start, 10))
	//req.Params.Add("end", strconv.FormatInt(start, 10))
	req.Params.Add("end", string(end))
	req.Params.Add("start", string(start))
	req.Params.Add("limit", string(limit))
	req.Params.Add("sort", string(sort))

	raw, err := c.Request(req)

	if err != nil {
		return nil, err
	}

	data := make([][]float64, 0, len(raw))
	for _, ifacearr := range raw {
		if arr, ok := ifacearr.([]interface{}); ok {
			sub := make([]float64, 0, len(arr))
			for _, iface := range arr {
				if flt, ok := iface.(float64); ok {
					sub = append(sub, flt)
				}
			}
			data = append(data, sub)
		}
	}

	cs, err := bitfinex.NewCandleSnapshotFromRaw(symbol, resolution, data)

	if err != nil {
		return nil, err
	}

	return cs, nil
}
1016860
func WithQuerySatelliteSyncWait(parent context.Context, value time.Duration) context.Context {
	return context.WithValue(contextOrBackground(parent), keyQueryOptSatSyncWait, value)
}