Prepares and returns Doctrine's QueryBuilder

@param ColumnCollection        $columns
@param DataSetRequestInterface $request

@return QueryBuilder
166947
public function getQueryBuilder(ColumnCollection $columns, DataSetRequestInterface $request): QueryBuilder
    {
        $this->conditions = $this->getConditions($request);
        
        $this->queryBuilder->select($columns->getSelectClause());
        $this->queryBuilder->addOrderBy($this->getOrderByExpression($request, $columns));
        $this->queryBuilder->setFirstResult($request->getOffset());
        $this->setColumnConditions($columns);
        
        if ($request->getLimit() > 0) {
            $this->queryBuilder->setMaxResults($request->getLimit());
        }
        
        return $this->queryBuilder;
    }
1174381
public function toDynamoDbQuery(
        $columns = [],
        $limit = DynamoDbQueryBuilder::MAX_LIMIT
    ) {
        $this->applyScopes();

        $this->resetExpressions();

        $op = 'Scan';
        $queryBuilder = DynamoDb::table($this->model->getTable());

        if (! empty($this->wheres)) {
            $analyzer = $this->getConditionAnalyzer();

            if ($keyConditions = $analyzer->keyConditions()) {
                $op = 'Query';
                $queryBuilder->setKeyConditionExpression($this->keyConditionExpression->parse($keyConditions));
            }

            if ($filterConditions = $analyzer->filterConditions()) {
                $queryBuilder->setFilterExpression($this->filterExpression->parse($filterConditions));
            }

            if ($index = $analyzer->index()) {
                $queryBuilder->setIndexName($index->name);
            }
        }

        if ($this->index) {
            // If user specifies the index manually, respect that
            $queryBuilder->setIndexName($this->index);
        }

        if ($limit !== static::MAX_LIMIT) {
            $queryBuilder->setLimit($limit);
        }

        if (!empty($columns)) {
            // Either we try to get the count or specific columns
            if ($columns == ['count(*)']) {
                $queryBuilder->setSelect('COUNT');
            } else {
                $queryBuilder->setProjectionExpression($this->projectionExpression->parse($columns));
            }
        }

        if (!empty($this->lastEvaluatedKey)) {
            $queryBuilder->setExclusiveStartKey($this->lastEvaluatedKey);
        }

        $queryBuilder
            ->setExpressionAttributeNames($this->expressionAttributeNames->all())
            ->setExpressionAttributeValues($this->expressionAttributeValues->all());

        $raw = new RawDynamoDbQuery($op, $queryBuilder->prepare($this->client)->query);

        if ($this->decorator) {
            call_user_func($this->decorator, $raw);
        }

        return $raw;
    }
408495
protected function getFromQuery(ServerRequestInterface $request)
    {
        $params = array_intersect_key($request->getQueryParams(), array_flip($this->getQueryKeys()));
        $regex  = '~^\/?' . $this->getRegEx() . '\b~';

        foreach ($params as $key => $value) {
            if ( preg_match($regex, $value, $matches) ) {
                if (isset($matches['language'])) {
                    return $matches['language'];
                } else {
                    throw new RuntimeException('The regular expression pattern is missing a named subpattern "language".');
                }
            }
        }
    }
292676
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        if ($parentQuery->getQuery()->from == $query->getQuery()->from) {
            return $this->getRelationExistenceQueryForSelfRelation($query, $parentQuery, $columns);
        }

        $this->performJoin($query);

        return $query->select($columns)->whereColumn(
            $this->getQualifiedForeignKeyName(), '=', $this->getQualifiedSecondOwnerKeyName()
        );
    }
538884
public function columns($columns)
	{
		if (is_null($this->columns))
		{
			$this->columns = new Query\QueryElement('()', $columns);
		}
		else
		{
			$this->columns->append($columns);
		}

		return $this;
	}
1334878
public function toQuery( Query $query, array $columns = [], $alias = '' ) {

		foreach( $this->criteria as $column => $criteria ) {

			if( !$column = $this->getColumnName($columns, $column, $alias) )
				continue;

			foreach( $criteria as $operator => $value ) {
				$query->where($column, $operator, $value);
			}

		}

		foreach( $this->getOrder() as $column => $ascending ) {
			$column = $this->getColumnName($columns, $column, $alias);
			if( !$column )
				continue;
			$query->orderBy($column, $ascending);
		}

		if( $this->offset )
			$query->offset($this->offset);

		if( $this->limit )
			$query->limit($this->limit);

		return $query;

	}
309224
public function Columns($columns = ''): QueryBuilder
    {
        if (empty($columns)) {
            return $this;
        }
        
        if (! is_array($columns)) {
            $this->fields = explode(',', $columns);
        }
        
        $this->fields = array_map('trim', $this->fields);
        
        return $this;
    }
455148
public function fetchColumn(QueryBuilder $builder, string $modelClass, string $columnName): iterable
    {
        $statement = $builder->execute();
        $statement->setFetchMode(PDOConnection::FETCH_ASSOC);

        if ($this->isFetchTyped() === true) {
            $platform = $builder->getConnection()->getDatabasePlatform();
            $typeName = $this->getModelSchemas()->getAttributeTypes($modelClass)[$columnName];
            $type     = Type::getType($typeName);
            while (($attributes = $statement->fetch()) !== false) {
                $value     = $attributes[$columnName];
                $converted = $type->convertToPHPValue($value, $platform);

                yield $converted;
            }
        } else {
            while (($attributes = $statement->fetch()) !== false) {
                $value = $attributes[$columnName];

                yield $value;
            }
        }

        $this->clearFetchParameters();
    }
192299
public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*'])
    {
        if ($parentQuery->getQuery()->from === $query->getQuery()->from) {
            return $this->getRelationExistenceQueryForSelfJoin($query, $parentQuery, $columns);
        }

        $this->performJoin($query);

        return parent::getRelationExistenceQuery($query, $parentQuery, $columns);
    }
734014
protected function runPaginationCountQuery($columns = ['*'])
    {
        return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
            ->cloneWithoutBindings(['select', 'order'])
            ->setAggregate('count', $this->withoutSelectAliases($columns))
            ->get()->all();
    }
889081
public function scopeSearch(Builder $query, ?string $keyword, ?array $columns = null): Builder
    {
        return $this->setupWildcardQueryFilter($query, $keyword ?? '', $columns ?? $this->getSearchableColumns());
    }
543553
public function get($columns = array('*'))
    {
        $models = $this->getModels($columns);

        if (count($models) > 0) {
            $models = $this->eagerLoadRelations($models);
        }

        return $this->model->newCollection($models);
    }
1211031
private function compileCollection(array $columnConfiguration)
    {
        $searchFunc = null;
        if ($this->queryConfiguration->isGlobalSearch()) {
            $searchFunc = $this->defaultGlobalSearchFunction;
        }

        $this->transformCollectionData($columnConfiguration, $searchFunc);
        $this->removeEmptyRowsFromCollection();
    }
414791
protected function select($columns=[])
    {
        $query = $this->model->newQuery()->getQuery();
        if ($columns) {
            $query->select($columns);
        }
        return $query;
    }
424656
public function findOrFail($id, $columns = ['*'])
    {
        $this->newQuery();

        if ($result = $this->query->find($id, $columns)) {
            return $result;
        }

        throw (new ModelNotFoundException)->setModel($this->model);
    }
849415
public function find($id, $columns = ['*'])
    {
        $this->newQuery();

        return $this->query->find($id, $columns);
    }
187456
public function setQueriedColumns($queriedColumns)
    {
        return $this->alterDataQuery(function (DataQuery $query) use ($queriedColumns) {
            $query->setQueriedColumns($queriedColumns);
        });
    }