Creates a new request message for the given query

@param Query $query
@return self
490873
public static function createRequestForQuery(Query $query)
    {
        $request = new Message();
        $request->header->set('id', self::generateId());
        $request->header->set('rd', 1);
        $request->questions[] = (array) $query;
        $request->prepare();

        return $request;
    }
854486
public function withQuery($query)
    {
        if (!is_string($query) && !method_exists($query, '__toString')) {
            throw new InvalidArgumentException('Uri query must be a string');
        }
        $query = ltrim((string)$query, '?');
        $clone = clone $this;
        $clone->query = Validator::checkQuery($query);

        return $clone;
    }
258264
public function merge(Query $query): Query
    {
        foreach ($query->getCriteria() as $criterion) {
            $criterion->attach($this);
        }

        return $this->attach($query);
    }
328071
public function boostingQuery($query, $boost = 1) {
		if(empty($this->data['boostingQueries'])) {
			$this->data['boostingQueries'] = array();
		}
		$newBoosting = array(
			'patternQuery' => $query,
			'boost' => $boost
		);
		$this->data['boostingQueries'][] = $newBoosting;
		return $this;
	}
1338232
public function count(Query $query)
    {
        $options = $query->getOptions();

        $cmd['count'] = $options['table'];
        $cmd['query'] = $this->parseWhere($query, $options['where']);

        foreach (['hint', 'limit', 'maxTimeMS', 'skip'] as $option) {
            if (isset($options[$option])) {
                $cmd[$option] = $options[$option];
            }
        }

        $command = new Command($cmd);
        $this->log('cmd', 'count', $cmd);

        return $command;
    }
181544
public function delete(Query $query)
    {
        $options = $query->getOptions();
        $where   = $this->parseWhere($query, $options['where']);

        $bulk = new BulkWrite;

        if (1 == $options['limit']) {
            $deleteOptions = ['limit' => 1];
        } else {
            $deleteOptions = ['limit' => 0];
        }

        $bulk->delete($where, $deleteOptions);

        $this->log('remove', $where, $deleteOptions);

        return $bulk;
    }
1218879
protected function createRequest(Question $question): Message
    {
        $request = $this->messageFactory->create(MessageTypes::QUERY);
        $request->getQuestionRecords()->add($question);
        $request->isRecursionDesired(true);

        $request->setID($this->createId());

        return $request;
    }
600717
public function run(Query $query)
    {
        return $this->getDisconnectRetry()->run(function () use ($query) {
            $statement = $this->prepare($query);
            $query->getValueBinder()->attachTo($statement);
            $statement->execute();

            return $statement;
        });
    }
1216840
protected function setKeysForSaveQuery(Query $query)
    {
        $query->where($this->morphType, $this->morphClass);

        return parent::setKeysForSaveQuery($query);
    }
443198
function setQuery($query)
    {
        if ($query !== null) {
            $q = $this->getQuery();
            $q->with($q::parseWith($query));
        }

        return $this;
    }
684772
public function createSavedSearch($query)
	{
		// Set the API path
		$path = '/saved_searches/create.json';

		// Set POST request data
		$data['query'] = rawurlencode($query);

		// Send the request.
		return $this->sendRequest($path, 'POST', $data);
	}
648741
protected function createSub($query)
    {
        // If the given query is a Closure, we will execute it while passing in a new
        // query instance to the Closure. This will give the developer a chance to
        // format and work with the query before we cast it to a raw SQL string.
        if ($query instanceof Closure) {
            $callback = $query;

            $callback($query = $this->forSubQuery());
        }

        return $this->parseSub($query);
    }
737314
protected function cloneQuery(Query $query)
    {
        $aclAppliedQuery = clone $query;
        $params = $query->getParameters();
        /* @var $param Parameter */
        foreach ($params as $param) {
            $aclAppliedQuery->setParameter($param->getName(), $param->getValue(), $param->getType());
        }

        return $aclAppliedQuery;
    }
357104
public function union(SelectQuery $query): self
    {
        $this->union[] = ['', $query->build(false)];

        return $this;
    }
1365993
public function createInstanceByQueryString($query)
    {
        switch ($this->rdfHelpers->getQueryType($query)) {
            case 'askQuery':
                return new AskQueryImpl($query, $this->rdfHelpers);

            case 'constructQuery':
                return new ConstructQueryImpl($query, $this->rdfHelpers);

            case 'describeQuery':
                return new DescribeQueryImpl($query, $this->rdfHelpers);

            case 'graphQuery':
                return new GraphQueryImpl($query, $this->rdfHelpers);

            case 'selectQuery':
                return new SelectQueryImpl($query, $this->rdfHelpers);

            case 'updateQuery':
                return new UpdateQueryImpl($query, $this->rdfHelpers);

            default:
                throw new \Exception('Unknown query type: '.$query);
        }
    }
213978
public function withQuery(array $query = [])
    {
        // Set Query in class.
        $this->query = collect($this->query)->merge($query)->all();

        return $this;
    }
1109973
public function prepareQuery(Query $query)
    {
        $parameters = new Parameters($this->driver);

        if ($this->pdo === null)
            $this->connect();

        $sql = $this->driver->toSQL($parameters, $query);

        $statement = $this->prepare($sql);
        $parameters->bindParameters($statement);
        return $statement;
    }