Get a generator for the given query.

@return \Generator
161888
public function cursor()
    {
        if (is_null($this->columns)) {
            $this->columns = ['*'];
        }

        return $this->connection->cursor(
            $this->toSql(), $this->getBindings(), ! $this->useWritePdo
        );
    }
834099
protected function get()
    {
        $a = 0;
        $b = 1;
        $to = $this->getMaxLimit();
        while (0 < $to) {
            yield $a;

            list($a, $b) = [$b, $a + $b];
            --$to;
        }
    }
1221906
public function create(): Query
    {
        $query = static::new()->scope(...$this->getScopes());

        if ($this->repository) {
            return $query->from($this->repository);
        }

        return $query;
    }
1174584
public function getBuilder()
    {
        $builder = new Query\Builder();
        $builder->setVisitors([
            (new Visitors\KeyVisitor($builder))->setKeys($this->keys)->setBaseTable($this->table),
            new Visitors\GroupVisitor($builder),
            new Visitors\EqVisitor($builder),
            new Visitors\NotEqVisitor($builder),
            new Visitors\GtVisitor($builder),
            new Visitors\GteVisitor($builder),
            new Visitors\LtVisitor($builder),
            new Visitors\LteVisitor($builder),
            new Visitors\CtVisitor($builder),
            new Visitors\SwVisitor($builder),
            new Visitors\EwVisitor($builder),
            new Visitors\AndVisitor($builder),
            new Visitors\OrVisitor($builder),
            new Visitors\NotInVisitor($builder),
            new Visitors\InVisitor($builder),
            new Visitors\NullVisitor($builder),
            new Visitors\NotNullVisitor($builder),
        ]);
        $builder->setFunctions([
            new Functions\ConcatFunction(),
            new Functions\SumFunction(),
        ]);

        return $builder;
    }
1312249
public function get()
    {
        // if exists the where or similar things in the query
        // call the from instance
        if (static::$_instance instanceof Builder) {

            $this->source = static::$_instance->get();
        } else {
            // if not call the parent directly
            $this->source = parent::all();
        }

        if (!static::$nested) {
            return $this->source;
        }

        return $this->to(static::$to);
    }
877696
public function createQuery()
    {
        return $this->getParent()->getMandango()->getRepository($this->getDocumentClass())->createQuery(array(
            '_id' => array('$in' => $this->doInitializeSavedData()),
        ));
    }
970161
final public function getQuery()
    {
        if (null === $this->query) {

            $this->query = $this->buildQuery();

            // Apply conditions.
            foreach ($this->conditions as $statement => $value) {
                $this->applyOperator($this->query, $statement, $value);
            }

            $limit = $this->getLimit();

            if (CursorInterface::LIMIT_NONE !== $limit) {
                $this->query->range($this->getOffset(), $limit);
            }
        }

        return $this->query;
    }
481026
public function getQueryBuilder()
    {
        if (!isset($this->queryBuilder)) {
            $this->queryBuilder = $this->getGeneratorConfig()->getConfiguredBuilder($this->getTable(), 'query');
        }

        return $this->queryBuilder;
    }
27702
public function getQuery()
    {

        $strings = $this->string;
        $query = $this->buildQuery($this->getPattern($this->getChieldPattern()), $strings);

        return $query;
    }
358077
protected function getQuery()
    {
        $query = new Query();

        if ($this->valid()) {
            $query->setQuery(new GtNode($this->dataStore->getIdentifier(), $this->key()));
        }

        $query->setLimit(new LimitNode($this->limit));
        $query->setSort(new SortNode([$this->dataStore->getIdentifier() => SortNode::SORT_ASC]));

        return $query;
    }
795074
public function getIterator()
    {
        foreach ($this->rawIterator() as $data) {
            $this->data = $this->persistence->typecastLoadRow($this, $data);
            if ($this->id_field) {
                $this->id = isset($data[$this->id_field]) ? $data[$this->id_field] : null;
            }

            // you can return false in afterLoad hook to prevent to yield this data row
            // use it like this:
            // $model->addHook('afterLoad', function ($m) {
            //     if ($m['date'] < $m->date_from) $m->breakHook(false);
            // })

            // you can also use breakHook() with specific object which will then be returned
            // as a next iterator value

            $ret = $this->hook('afterLoad');

            if ($ret === false) {
                continue;
            }

            if (is_object($ret)) {
                if ($ret->id_field) {
                    yield $ret->id => $ret;
                } else {
                    yield $ret;
                }
            } else {
                if ($this->id_field) {
                    yield $this->id => $this;
                } else {
                    yield $this;
                }
            }
        }

        $this->unload();
    }
590312
public static function query()
    {
        $query = new Query(get_called_class());
        $query->set_searchable_fields(static::get_searchable_fields());
        $query->set_primary_key(static::get_primary_key());

        return $query;
    }
1301758
protected function newBaseQueryBuilder()
    {
        $conn    = $this->getConnection();
        $grammar = $conn->getQueryGrammar();

        if ($grammar instanceof OracleGrammar) {
            return new QueryBuilder($conn, $grammar, $conn->getPostProcessor());
        }

        return new IlluminateQueryBuilder($conn, $grammar, $conn->getPostProcessor());
    }
11786
protected function each(Builder $query, $count = 100): Generator
    {
        $query = $this->exportableQuery($query);

        // enforce order by statement.
        if (empty($query->orders) && empty($query->unionOrders)) {
            $query->orderBy($query->getModel()->getQualifiedKeyName(), 'asc');
        }

        $page = 1;

        do {
            // We'll execute the query for the given page and get the results. If there are
            // no results we can just break and return from here. When there are results
            // we will call the callback with the current chunk of these results here.
            $results = $query->forPage($page, $count)->get();

            $countResults = $results->count();

            if (0 === $countResults) {
                break;
            }

            // On each chunk result set, we will pass them to the callback and then let the
            // developer take care of everything within the callback, which allows us to
            // keep the memory low for spinning through large result sets for working.
            foreach ($results as $index => $item) {
                yield $index = $item;
            }

            unset($results);

            ++$page;
        } while ($countResults === $count);
    }
566543
private function getQuerySelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT q.*, qt.*')
            ->from('ngbm_collection_query', 'q')
            ->innerJoin(
                'q',
                'ngbm_collection_query_translation',
                'qt',
                $query->expr()->andX(
                    $query->expr()->eq('qt.query_id', 'q.id'),
                    $query->expr()->eq('qt.status', 'q.status')
                )
            );

        return $query;
    }
54528
public function getGenerator()
    {
        if (!$this->generator) {
            $this->generator = Factory::create($this->locale);
        }

        return $this->generator;
    }
264761
public function getIterator(): \Generator
    {
        while (!$this->stream->eof()) {
            $item = $this->stream->read($this->chunkSize);
            // @codeCoverageIgnoreStart
            //I don't know how to fabricate this manually, so I can't test it.
            if ($item === '') {
                continue;
            }
            // @codeCoverageIgnoreEnd
            yield $item;
        }
    }