Determines the reason why request was rejected.

@param Query $query

@return \Closure
761321
protected function parseReason(Query $query)
    {
        return function ($reason) use ($query) {
            if ($reason instanceof RequestException) {
                $response = $reason->getResponse();

                if (is_null($response)) {
                    throw TransportException::connectionError($query->getServer(), $reason->getMessage());
                } else {
                    throw TransportException::serverReturnedError($reason, $query);
                }
            }

            throw $reason;
        };
    }
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);
    }
1230867
public function lookup(Query $query)
    {
        $id = $this->serializeQueryToIdentity($query);

        $expiredAt = $this->expiredAt;

        return $this->cache
            ->get($id)
            ->then(function ($value) use ($query, $expiredAt) {
                // cache 0.5+ resolves with null on cache miss, return explicit cache miss here
                if ($value === null) {
                    return Promise\reject();
                }

                /* @var $recordBag RecordBag */
                $recordBag = unserialize($value);

                // reject this cache hit if the query was started before the time we expired the cache?
                // todo: this is a legacy left over, this value is never actually set, so this never applies.
                // todo: this should probably validate the cache time instead.
                if (null !== $expiredAt && $expiredAt <= $query->currentTime) {
                    return Promise\reject();
                }

                return $recordBag->all();
            });
    }
386494
protected function deleteRecord(Query $query): bool
	{
		return (bool) $query->where($this->primaryKey, '=', $this->columns[$this->primaryKey])->delete();
	}
514626
public function setQuery(Query $query)
    {
        $this->query = $query;
        $this->clonedQuery = clone $query;

        return $this;
    }
1291066
public function search($query)
    {
        try {
            $request = $this->client->createRequest($query);
            $response = $this->executeRequest($request);
            $this->hasSearched = true;
            $this->responseCache = $response;
        } catch (HttpException $e) {
            $this->handleErrorResponses($e);
        }
        return $response;
    }
794927
function query(string $query): \React\Promise\PromiseInterface {
        if($this->goingAway) {
            return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
        }
        
        $connection = $this->getOptimalConnection();
        
        return $connection->query($this, $query)->then(null, function (\Throwable $error) use (&$connection) {
            $this->checkinConnection($connection);
            throw $error;
        });
    }
649091
public function scopeRequestOrder($query, Request $request)
    {
        if ($request->has('orderBy')) {
            $direction = ($request->has('orderDir')) ? $request->input('orderDir') : 'desc';
            $query->orderBy($request->input('orderBy'), $direction);
        }

        return $query;
    }
23785
public function apply(Query $query) : Query
    {
        return $query->where(
            (new QueryExpression())->gt(
                $this->field,
                $this->value,
                $query->getTypeMap()->type($this->field)
            )
        );
    }
62533
public function unprepared($query)
    {
        $start = $this->getLogTime();

        try {

            $result = $this->wpdb->query($query);

            if ($result === false || $this->wpdb->last_error) {
                throw new QueryException($query, [], new \Exception($this->wpdb->last_error));
            }

            return $result;

        } catch (QueryException $e) {
            throw $e;
        } finally {
            $this->logQuery($query, [], $this->getElapsedTime($start));
        }

    }
689381
protected function formatQuery(Query $query)
    {
        // handle numeric where, from 2 to ['id'=>2]
        if (!$query->formatted() && $where = $query->get('where')) {
            $table = static::getFirstTable($query['table']);
            $atable  = static::getFirstTableAlias($query['table']);
            $model  = static::getQueryModel();
            $pk     = isset($model['primary_key']) ? $model['primary_key'] : null;
            $spk    = $atable . '.' . $pk;
            foreach ($where as $k=>$v) {
                if (is_numeric($k)) {
                    if (is_numeric($v)) {
                        if (!$pk) {
                            throw new Exception('pk is not set:' . $table);
                        }
                        $where[$k] = [$spk => $v];
                    } elseif (is_array($v)) {
                        foreach ($v as $k2=>$v2) {
                            if (is_numeric($k2) && is_numeric($v2)) {
                                if (!$pk) {
                                    throw new Exception('pk is not set:' . $table);
                                }
                                $where[$k][$k2] = [$spk => $v2];
                            }
                        }
                    }
                }
            }
            
            $query->setRaw('where', $where);
        }
        
        return $query;
    }
335676
protected function attempt(Closure $run, $query='')
    {
        try {
            return $run();
        } catch (Exception $e) {
            throw $this->convertException($e, $query);
        }
    }
1216840
protected function setKeysForSaveQuery(Query $query)
    {
        $query->where($this->morphType, $this->morphClass);

        return parent::setKeysForSaveQuery($query);
    }
1153380
public function execute(Query $query)
    {
        $handler = $this->resolveHandler($query);

        return $handler->handle($query);
    }
601876
protected function queryDriver($query)
    {
        $this->logger->debug($query);
        $result = $this->mysqli()->query($query);
        if (false === $result) {
            $this->logger->info("-- Query fail with SQL: $query");
            $this->logger->error("FAIL: $query\nLast message:" . $this->getLastMessage());
        }
        return $result;
    }
1156928
private function doSettlementSearch($query)
    {
        $search = ClassValidator::getInstance('Eway\Rapid\Model\SettlementSearch', $query);
        return $this->getHttpService()->getSettlementSearch($search->toArray());
    }
166207
public function handle(Query $query)
    {
        $handler = $this->locator->findHandler($query);

        if (!is_callable($handler)) {
            throw HandlerNotFoundException::notFound($query);
        }

        return call_user_func($handler, $query);
    }