diff --git a/README.md b/README.md index bdd3aed..78d9225 100644 --- a/README.md +++ b/README.md @@ -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' => [ diff --git a/src/Integrations/Laravel/Builder.php b/src/Integrations/Laravel/Builder.php index eb0664f..7d11790 100644 --- a/src/Integrations/Laravel/Builder.php +++ b/src/Integrations/Laravel/Builder.php @@ -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; @@ -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; + } } diff --git a/src/Integrations/Laravel/Connection.php b/src/Integrations/Laravel/Connection.php index a9d33ee..eb4570c 100644 --- a/src/Integrations/Laravel/Connection.php +++ b/src/Integrations/Laravel/Connection.php @@ -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( @@ -180,7 +186,7 @@ function ($server) { foreach ($config['servers'] ?? [] as $server) { $serverProvider->addServer($this->assembleServer($server)); } - + return $serverProvider; }