diff --git a/.gitignore b/.gitignore index 116f35f..2e21e39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock -.idea \ No newline at end of file +.idea +.history \ No newline at end of file diff --git a/src/Builder.php b/src/Builder.php index aeb9245..20bdb22 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -78,7 +78,12 @@ class Builder extends BaseBuilder $statement = $this->client->select($query, $bindings); - $this->resolveConnection()->logQuery($query, $bindings, $this->getElapsedTime($start)); + // ✅ Исправление: resolveConnection() отсутствует в этом пакете. + // Обёртка предотвращает падение, если метод когда-нибудь добавят или уберут + if (method_exists($this, 'resolveConnection')) { + $this->resolveConnection()->logQuery($query, $bindings, $this->getElapsedTime($start)); + } + return $statement; } @@ -118,7 +123,33 @@ class Builder extends BaseBuilder return $this; } - + /** + * Добавляет сырое SQL-выражение в SELECT без автоматического экранирования ``. + * Необходимо для агрегатных функций: count(), avg(), uniq(), toStartOfDay() и т.д. + */ + public function selectRaw(string $expression, array $bindings = []): self + { + // Expression сообщает Grammar'у: "не трогай эту строку кавычками" + return $this->select(new Expression($expression)); + } + /** + * Получает первую строку результата как ассоциативный массив или null. + * Аналог Eloquent::first() + */ + public function first(): ?array + { + $rows = $this->limit(1)->getRows(); + return $rows[0] ?? null; + } + /** + * Получает значение одного поля из первой строки. + * Аналог Eloquent::value() + */ + public function value(string $column) + { + $row = $this->select([$column])->first(); + return $row[$column] ?? null; + } /** * Note! This is a heavy operation not designed for frequent use. * @return Statement @@ -231,5 +262,4 @@ class Builder extends BaseBuilder ], ); } - }