From 14345b2622bcaad5075310278ff1e65ab5f84736 Mon Sep 17 00:00:00 2001 From: Dmitry Rashupkin Date: Wed, 29 Apr 2026 15:22:30 +0300 Subject: [PATCH] Save 29042026 --- .gitignore | 3 ++- src/Builder.php | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) 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 ], ); } - }