Added the settings clause to the select query builder
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
## 1.18.0 [2023-07-10]
|
||||
|
||||
### Features
|
||||
1. Added the settings clause to the select query builder
|
||||
|
||||
## 1.17.0 [2023-03-24]
|
||||
|
||||
### Features
|
||||
|
||||
@@ -168,6 +168,7 @@ MyTable::insertAssoc([['model_name' => 'model 1', 'some_param' => 1], ['some_par
|
||||
$rows = MyTable::select(['field_one', new RawColumn('sum(field_two)', 'field_two_sum')])
|
||||
->where('created_at', '>', '2020-09-14 12:47:29')
|
||||
->groupBy('field_one')
|
||||
->settings(['max_threads' => 3])
|
||||
->getRows();
|
||||
```
|
||||
|
||||
|
||||
+18
-2
@@ -6,10 +6,8 @@ namespace PhpClickHouseLaravel;
|
||||
|
||||
use ClickHouseDB\Client;
|
||||
use ClickHouseDB\Statement;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use PhpClickHouseLaravel\Exceptions\QueryException;
|
||||
use Tinderbox\ClickhouseBuilder\Query\BaseBuilder;
|
||||
use Tinderbox\ClickhouseBuilder\Query\Grammar;
|
||||
|
||||
class Builder extends BaseBuilder
|
||||
{
|
||||
@@ -20,6 +18,7 @@ class Builder extends BaseBuilder
|
||||
protected $tableSources;
|
||||
/** @var Client */
|
||||
protected $client;
|
||||
protected $settings = [];
|
||||
|
||||
/**
|
||||
* The name of the database connection to use.
|
||||
@@ -34,6 +33,23 @@ class Builder extends BaseBuilder
|
||||
$this->client = $client ?? $this->getThisClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SETTINGS clause for the SELECT statement.
|
||||
* @link https://clickhouse.com/docs/en/sql-reference/statements/select#settings-in-select-query
|
||||
* @param array $settings For example: [max_threads => 3]
|
||||
* @return $this
|
||||
*/
|
||||
public function settings(array $settings): self
|
||||
{
|
||||
$this->settings = $settings;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSettings(): array
|
||||
{
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Statement
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace PhpClickHouseLaravel;
|
||||
|
||||
|
||||
class Grammar extends \Tinderbox\ClickhouseBuilder\Query\Grammar
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->selectComponents[] = 'settings';
|
||||
}
|
||||
|
||||
public function compileSettingsComponent($_, array $settings): string
|
||||
{
|
||||
if (empty($settings)) {
|
||||
return "";
|
||||
}
|
||||
$strAr = [];
|
||||
foreach ($settings as $k => $v) {
|
||||
$strAr[] = is_int($v) ? "$k=$v" : "$k='$v'";
|
||||
}
|
||||
return 'SETTINGS ' . implode(', ', $strAr);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user