Save
CI Tests / test (push) Has been cancelled

This commit is contained in:
Dmitry Rashupkin
2026-06-23 12:59:49 +03:00
parent 45c30e8980
commit 112b74ee7a
7 changed files with 63 additions and 54 deletions
+1 -1
View File
@@ -120,4 +120,4 @@
## 1.4.0 [2020-12-11] ## 1.4.0 [2020-12-11]
### Features ### Features
1. [#1](https://github.com/glushkovds/phpclickhouse-laravel/pull/1): Ability to retry requests while received not 200 response, maybe due network connectivity problems. 1. [#1](https://github.com/drashupkin/phpclickhouse-laravel/pull/1): Ability to retry requests while received not 200 response, maybe due network connectivity problems.
+2 -2
View File
@@ -1,4 +1,4 @@
![Tests](https://github.com/glushkovds/phpclickhouse-laravel/actions/workflows/test.yml/badge.svg) ![Tests](https://github.com/drashupkin/phpclickhouse-laravel/actions/workflows/test.yml/badge.svg)
# phpClickHouse-laravel # phpClickHouse-laravel
@@ -24,7 +24,7 @@ More: https://github.com/smi2/phpClickHouse#features
**1.** Install via composer **1.** Install via composer
```sh ```sh
$ composer require glushkovds/phpclickhouse-laravel $ composer require drashupkin/phpclickhouse-laravel
``` ```
**2.** Add new connection into your config/database.php: **2.** Add new connection into your config/database.php:
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"name": "glushkovds/phpclickhouse-laravel", "name": "drashupkin/phpclickhouse-laravel",
"description": "Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel", "description": "Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel",
"keywords": [ "keywords": [
"php", "php",
+1 -1
View File
@@ -1,6 +1,6 @@
## Parameter numbering with whereIn ## Parameter numbering with whereIn
The problem is described here: https://github.com/glushkovds/phpclickhouse-laravel/pull/34 The problem is described here: https://github.com/drashupkin/phpclickhouse-laravel/pull/34
The reason for the problem is that for the `DB::table('my-table')` construction The reason for the problem is that for the `DB::table('my-table')` construction
the builder used was not from this library `\PhpClickHouseLaravel\Builder`, the builder used was not from this library `\PhpClickHouseLaravel\Builder`,
+56 -47
View File
@@ -15,7 +15,6 @@ use Tinderbox\ClickhouseBuilder\Query\Expression;
class Builder extends BaseBuilder class Builder extends BaseBuilder
{ {
use WithClient; use WithClient;
use BuilderMethodsFromLaravel; use BuilderMethodsFromLaravel;
@@ -69,6 +68,58 @@ class Builder extends BaseBuilder
return round((microtime(true) - $start) * 1000, 2); return round((microtime(true) - $start) * 1000, 2);
} }
/**
* 🔑 Переопределяем select() для авто-обёртки агрегатных функций в Expression
* Это предотвращает экранирование `` функций типа count(), uniq(), avg()
*/
public function select(...$columns): self
{
// Если передан массив первым аргументом (совместимость со старым вызовом)
if (isset($columns[0]) && is_array($columns[0])) {
$columns = $columns[0];
}
if (is_array($columns)) {
$columns = array_map(function ($col) {
if (is_string($col) && preg_match('/\(|\s+as\s+|\b(count|uniq|avg|sum|min|max|toStartOfDay)\b/i', $col)) {
return new Expression($col);
}
return $col;
}, $columns);
}
return parent::select(...(is_array($columns) ? $columns : [$columns]));
}
/**
* Добавляет сырое SQL-выражение в SELECT без автоматического экранирования ``.
* Необходимо для агрегатных функций: count(), avg(), uniq(), toStartOfDay() и т.д.
*/
public function selectRaw(string $expression, array $bindings = []): self
{
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([new Expression($column)])->first();
return $row ? reset($row) : null;
}
/** /**
* @return Statement * @return Statement
*/ */
@@ -85,7 +136,6 @@ class Builder extends BaseBuilder
$this->resolveConnection()->logQuery($query, $bindings, $this->getElapsedTime($start)); $this->resolveConnection()->logQuery($query, $bindings, $this->getElapsedTime($start));
} }
return $statement; return $statement;
} }
@@ -121,36 +171,9 @@ class Builder extends BaseBuilder
public function setSourcesTable(string $table): self public function setSourcesTable(string $table): self
{ {
$this->tableSources = $table; $this->tableSources = $table;
return $this; 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. * Note! This is a heavy operation not designed for frequent use.
* @return Statement * @return Statement
@@ -190,7 +213,6 @@ public function selectRaw(string $expression, array $bindings = []): self
{ {
$builder = $this->getCountQuery(); $builder = $this->getCountQuery();
$result = $builder->getRows(); $result = $builder->getRows();
return (int) $result[0]['count'] ?? 0; return (int) $result[0]['count'] ?? 0;
} }
@@ -209,16 +231,9 @@ public function selectRaw(string $expression, array $bindings = []): self
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{ {
$page = $page ?: Paginator::resolveCurrentPage($pageName); $page = $page ?: Paginator::resolveCurrentPage($pageName);
$count = (clone $this)->count(); $count = (clone $this)->count();
$perPage = ($perPage instanceof Closure ? $perPage($count) : $perPage) ?: 15;
$perPage = ($perPage instanceof Closure $results = $this->limit($perPage, $perPage * ($page - 1))->getRows();
? $perPage($count)
: $perPage
) ?: 15;
$results = $this->limit($perPage, $perPage * ($page - 1))
->getRows();
return new LengthAwarePaginator( return new LengthAwarePaginator(
$results, $results,
@@ -244,14 +259,8 @@ public function selectRaw(string $expression, array $bindings = []): self
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{ {
$page = $page ?: Paginator::resolveCurrentPage($pageName); $page = $page ?: Paginator::resolveCurrentPage($pageName);
$perPage = $perPage ?: 15; $perPage = $perPage ?: 15;
$results = $this->limit($perPage + 1, ($page - 1) * $perPage)->getRows();
// Next we will set the limit and offset for this query so that when we get the
// results we get the proper section of results. Then, we'll create the full
// paginator instances for these results with the given page and per page.
$results = $this->limit($perPage + 1, ($page - 1) * $perPage)
->getRows();
return new Paginator( return new Paginator(
$results, $results,
+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Installing current library files to empty laravel app # Installing current library files to empty laravel app
cp -r /src/* vendor/glushkovds/phpclickhouse-laravel cp -r /src/* vendor/drashupkin/phpclickhouse-laravel
# Preparing Phpunit # Preparing Phpunit
cp /src/phpunit.xml phpunit.xml cp /src/phpunit.xml phpunit.xml
+1 -1
View File
@@ -1,5 +1,5 @@
FROM bitnami/laravel FROM bitnami/laravel
RUN cd / && composer create-project laravel/laravel app RUN cd / && composer create-project laravel/laravel app
RUN composer require glushkovds/phpclickhouse-laravel RUN composer require drashupkin/phpclickhouse-laravel
WORKDIR "/app" WORKDIR "/app"