// SelectMany projects each element of a collection to a Query, iterates and
// flattens the resulting collection into one collection.
973743
func (q Query) SelectMany(selector func(interface{}) Query) Query {
	return Query{
		Iterate: func() Iterator {
			outernext := q.Iterate()
			var inner interface{}
			var innernext Iterator

			return func() (item interface{}, ok bool) {
				for !ok {
					if inner == nil {
						inner, ok = outernext()
						if !ok {
							return
						}

						innernext = selector(inner).Iterate()
					}

					item, ok = innernext()
					if !ok {
						inner = nil
					}
				}

				return
			}
		},
	}
}
1257611
func (m *DbMap) SelectOne(dest interface{}, query string, args ...interface{}) error {
	return hookedget(m, m, dest, query, args...)
}
209333
func (adapter *SQLiteAdapter) SelectRowQuery(tableName, fields, indexValue string) string {
	return Cleanf("SELECT %s FROM %s WHERE %s = '%s';", fields, adapter.SecureName(tableName), types.SQLColumnLabelHeight, indexValue)
}
843513
func marshalMany(models []interface{}) (*ManyPayload, error) {
	payload := &ManyPayload{
		Data: []*Node{},
	}
	included := map[string]*Node{}

	for _, model := range models {
		node, err := visitModelNode(model, &included, true)
		if err != nil {
			return nil, err
		}
		payload.Data = append(payload.Data, node)
	}
	payload.Included = nodeMapValues(&included)

	return payload, nil
}
24127
func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
	return SelectContext(ctx, db, dest, query, args...)
}
1075968
func (l *Loader) LoadMany(originalContext context.Context, keys Keys) ThunkMany {
	ctx, finish := l.tracer.TraceLoadMany(originalContext, keys)

	var (
		length = len(keys)
		data   = make([]interface{}, length)
		errors = make([]error, length)
		c      = make(chan *ResultMany, 1)
		wg     sync.WaitGroup
	)

	resolve := func(ctx context.Context, i int) {
		defer wg.Done()
		thunk := l.Load(ctx, keys[i])
		result, err := thunk()
		data[i] = result
		errors[i] = err
	}

	wg.Add(length)
	for i := range keys {
		go resolve(ctx, i)
	}

	go func() {
		wg.Wait()

		// errs is nil unless there exists a non-nil error.
		// This prevents dataloader from returning a slice of all-nil errors.
		var errs []error
		for _, e := range errors {
			if e != nil {
				errs = errors
				break
			}
		}

		c <- &ResultMany{Data: data, Error: errs}
		close(c)
	}()

	var result struct {
		mu    sync.RWMutex
		value *ResultMany
	}

	thunkMany := func() ([]interface{}, []error) {
		result.mu.RLock()
		resultNotSet := result.value == nil
		result.mu.RUnlock()

		if resultNotSet {
			result.mu.Lock()
			if v, ok := <-c; ok {
				result.value = v
			}
			result.mu.Unlock()
		}
		result.mu.RLock()
		defer result.mu.RUnlock()
		return result.value.Data, result.value.Error
	}

	defer finish(thunkMany)
	return thunkMany
}
393044
func (s *EventsService) Select(r RRSetKey, query string) ([]EventInfoDTO, error) {
	// TODO: Sane Configuration for timeouts / retries
	maxerrs := 5
	waittime := 5 * time.Second

	// init accumulators
	pis := []EventInfoDTO{}
	offset := 0
	errcnt := 0

	for {
		reqEvents, ri, res, err := s.SelectWithOffset(r, query, offset)
		if err != nil {
			if res != nil && res.StatusCode >= 500 {
				errcnt = errcnt + 1
				if errcnt < maxerrs {
					time.Sleep(waittime)
					continue
				}
			}
			return pis, err
		}

		log.Printf("ResultInfo: %+v\n", ri)
		for _, pi := range reqEvents {
			pis = append(pis, pi)
		}
		if ri.ReturnedCount+ri.Offset >= ri.TotalCount {
			return pis, nil
		}
		offset = ri.ReturnedCount + ri.Offset
		continue
	}
}
325868
func (ri *manyRunIterator16) nextMany(hs uint32, buf []uint32) int {
	n := 0
	if !ri.hasNext() {
		return n
	}
	// start and end are inclusive
	for n < len(buf) {
		if ri.curIndex == -1 || int(ri.rc.iv[ri.curIndex].length-ri.curPosInIndex) <= 0 {
			ri.curPosInIndex = 0
			ri.curIndex++
			if ri.curIndex == int64(len(ri.rc.iv)) {
				break
			}
			buf[n] = uint32(ri.rc.iv[ri.curIndex].start) | hs
			if ri.curIndex != 0 {
				ri.curSeq++
			}
			n++
			// not strictly necessarily due to len(buf)-n min check, but saves some work
			continue
		}
		// add as many as you can from this seq
		moreVals := minOfInt(int(ri.rc.iv[ri.curIndex].length-ri.curPosInIndex), len(buf)-n)

		base := uint32(ri.rc.iv[ri.curIndex].start+ri.curPosInIndex+1) | hs

		// allows BCE
		buf2 := buf[n : n+moreVals]
		for i := range buf2 {
			buf2[i] = base + uint32(i)
		}

		// update values
		ri.curPosInIndex += uint16(moreVals) //moreVals always fits in uint16
		ri.curSeq += int64(moreVals)
		n += moreVals
	}
	return n
}
920273
func (q Query) SelectManyBy(selector func(interface{}) Query,
	resultSelector func(interface{}, interface{}) interface{}) Query {

	return Query{
		Iterate: func() Iterator {
			outernext := q.Iterate()
			var outer interface{}
			var innernext Iterator

			return func() (item interface{}, ok bool) {
				for !ok {
					if outer == nil {
						outer, ok = outernext()
						if !ok {
							return
						}

						innernext = selector(outer).Iterate()
					}

					item, ok = innernext()
					if !ok {
						outer = nil
					}
				}

				item = resultSelector(item, outer)
				return
			}
		},
	}
}
175467
func (_m *Client) GetMany(uids []string, options groveclient.GetManyOptions) (*groveclient.GetManyOutput, error) {
	ret := _m.Called(uids, options)

	var r0 *groveclient.GetManyOutput
	if rf, ok := ret.Get(0).(func([]string, groveclient.GetManyOptions) *groveclient.GetManyOutput); ok {
		r0 = rf(uids, options)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*groveclient.GetManyOutput)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func([]string, groveclient.GetManyOptions) error); ok {
		r1 = rf(uids, options)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
10149
func (s *userService) GetAll() []datamodels.User {
	return s.repo.SelectMany(func(_ datamodels.User) bool {
		return true
	}, -1)
}
1227904
func (api *DatabaseAPI) FilterBy(key string, value interface{}) *DatabaseAPI {
	api.filterBy(key, value, false)
	return api
}
1276724
func (s *TasksService) Select(query string) ([]Task, error) {
	// TODO: Sane Configuration for timeouts / retries
	maxerrs := 5
	waittime := 5 * time.Second

	// init accumulators
	dtos := []Task{}
	offset := 0
	errcnt := 0

	for {
		reqDtos, ri, res, err := s.SelectWithOffset(query, offset)
		if err != nil {
			if res != nil && res.StatusCode >= 500 {
				errcnt = errcnt + 1
				if errcnt < maxerrs {
					time.Sleep(waittime)
					continue
				}
			}
			return dtos, err
		}

		log.Printf("[DEBUG] ResultInfo: %+v\n", ri)
		for _, d := range reqDtos {
			dtos = append(dtos, d)
		}
		if ri.ReturnedCount+ri.Offset >= ri.TotalCount {
			return dtos, nil
		}
		offset = ri.ReturnedCount + ri.Offset
		continue
	}
}
810458
func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
	return Query{
		Iterate: func() Iterator {
			next := q.Iterate()
			set := make(map[interface{}]bool)

			return func() (item interface{}, ok bool) {
				for item, ok = next(); ok; item, ok = next() {
					s := selector(item)
					if _, has := set[s]; !has {
						set[s] = true
						return
					}
				}

				return
			}
		},
	}
}
641091
func (c *CollaboratorsController) AddMany(ctx *app.AddManyCollaboratorsContext) error {
	return proxy.RouteHTTP(ctx, c.config.GetAuthShortServiceHostName())
}
1301047
func (NoopTracer) TraceLoadMany(ctx context.Context, keys Keys) (context.Context, TraceLoadManyFinishFunc) {
	return ctx, func(ThunkMany) {}
}
1043926
func (q *Query) Select(values ...interface{}) error {
	if q.stickyErr != nil {
		return q.stickyErr
	}

	model, err := q.newModel(values...)
	if err != nil {
		return err
	}

	q, err = model.BeforeSelectQuery(q.ctx, q.db, q)
	if err != nil {
		return err
	}

	res, err := q.query(model, newSelectQuery(q))
	if err != nil {
		return err
	}

	if res.RowsReturned() > 0 {
		if q.model != nil {
			if err := q.selectJoins(q.model.GetJoins()); err != nil {
				return err
			}
		}
		if err := model.AfterSelect(q.ctx, q.db); err != nil {
			return err
		}
	}

	return nil
}