Skip to content

Commit

Permalink
Possibility to get query statistics from the connection throught buil…
Browse files Browse the repository at this point in the history
…der, possibility to specify server configuration without servers option in config
  • Loading branch information
evsign committed Oct 31, 2019
1 parent 4e28241 commit 53a9462
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,23 @@ Connection configures via `config/database.php`.

Example with alone server:

```php
'connections' => [
'clickhouse' => [
'driver' => 'clickhouse',
'host' => 'ch-00.domain.com',
'port' => '',
'database' => '',
'username' => '',
'password' => '',
'options' => [
'timeout' => 10,
'protocol' => 'https'
]
]
]
```
or
```php
'connections' => [
'clickhouse' => [
Expand Down
23 changes: 23 additions & 0 deletions src/Integrations/Laravel/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Traits\Macroable;
use Tinderbox\Clickhouse\Common\Format;
use Tinderbox\Clickhouse\Query;
use Tinderbox\Clickhouse\Query\QueryStatistic;
use Tinderbox\ClickhouseBuilder\Query\BaseBuilder;
use Tinderbox\ClickhouseBuilder\Query\Grammar;

Expand Down Expand Up @@ -177,4 +178,26 @@ public function delete()
{
return $this->connection->delete($this->grammar->compileDelete($this));
}

/**
* Get last query statistics from the connection.
*
* @throws \Tinderbox\ClickhouseBuilder\Exceptions\BuilderException
*
* @return QueryStatistic
*/
public function getLastQueryStatistics() : QueryStatistic
{
return $this->getConnection()->getLastQueryStatistic();
}

/**
* Get connection.
*
* @return Connection
*/
public function getConnection() : Connection
{
return $this->connection;
}
}
8 changes: 7 additions & 1 deletion src/Integrations/Laravel/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ protected function createTransport(array $options) : TransportInterface
protected function assembleServerProvider(array $config)
{
$serverProvider = new ServerProvider();

if (empty($config['clusters'] ?? []) && empty($config['servers'] ?? [])) {
$serverProvider->addServer($this->assembleServer($config));

return $serverProvider;
}

foreach ($config['clusters'] ?? [] as $clusterName => $servers) {
$cluster = new Cluster(
Expand All @@ -180,7 +186,7 @@ function ($server) {
foreach ($config['servers'] ?? [] as $server) {
$serverProvider->addServer($this->assembleServer($server));
}

return $serverProvider;
}

Expand Down

0 comments on commit 53a9462

Please sign in to comment.