Skip to content

Commit 2f5f4e1

Browse files
committed
change ClickHouseConnection constructor for usage driverOptions
1 parent 0e34000 commit 2f5f4e1

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ $connectionParams = [
2525
'password' => '',
2626
'dbname' => 'default',
2727
'driverClass' => 'FOD\DBALClickHouse\Driver',
28-
'wrapperClass' => 'FOD\DBALClickHouse\Connection'
28+
'wrapperClass' => 'FOD\DBALClickHouse\Connection',
29+
'driverOptions' => [
30+
'extremes' => false,
31+
'readonly' => true,
32+
'max_execution_time' => 30,
33+
'enable_http_compression' => 0,
34+
'https' => false,
35+
],
2936
];
3037
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, new \Doctrine\DBAL\Configuration());
3138
```

src/ClickHouseConnection.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOD\DBALClickHouse;
1313

14-
use Doctrine\DBAL\ConnectionException;
1514
use ClickHouseDB\Client as Smi2CHClient;
1615
use Doctrine\DBAL\ParameterType;
1716
use Doctrine\DBAL\Platforms\AbstractPlatform;
@@ -36,27 +35,25 @@ class ClickHouseConnection implements \Doctrine\DBAL\Driver\Connection
3635
/**
3736
* Connection constructor
3837
*
38+
* @param array $params
3939
* @param string $username The username to use when connecting.
4040
* @param string $password The password to use when connecting.
41-
* @param string $host
42-
* @param int $port
43-
* @param string $database
4441
* @param AbstractPlatform $platform
4542
*/
4643
public function __construct(
47-
$username = 'default',
48-
$password = '',
49-
$host = 'localhost',
50-
$port = 8123,
51-
$database = 'default',
44+
array $params,
45+
$username,
46+
$password,
5247
AbstractPlatform $platform
5348
) {
5449
$this->smi2CHClient = new Smi2CHClient([
55-
'host' => $host,
56-
'port' => $port,
50+
'host' => $params['host'] ?? 'localhost',
51+
'port' => $params['port'] ?? 8123,
5752
'username' => $username,
5853
'password' => $password,
59-
'settings' => ['database' => $database]
54+
'settings' => array_merge([
55+
'database' => $params['dbname'] ?? 'default',
56+
], $params['driverOptions'] ?? []),
6057
]);
6158

6259
$this->platform = $platform;

src/Driver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public function connect(array $params, $user = null, $password = null, array $dr
5151
throw new ClickHouseException('Connection parameter `dbname` is required');
5252
}
5353

54-
return new ClickHouseConnection($user, $password, $params['host'], $params['port'], $params['dbname'],
55-
$this->getDatabasePlatform());
54+
return new ClickHouseConnection($params, $user, $password, $this->getDatabasePlatform());
5655
}
5756

5857
/**

tests/CreateConnectionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public static function createConnection($params = null)
4848
'dbname' => phpunit_ch_dbname,
4949
'driverClass' => phpunit_ch_driver_class,
5050
'wrapperClass' => phpunit_ch_wrapper_class,
51+
'driverOptions' => [
52+
'extremes' => false,
53+
'readonly' => true,
54+
'max_execution_time' => 30,
55+
'enable_http_compression' => 0,
56+
'https' => false
57+
],
5158
];
5259
}
5360
return \Doctrine\DBAL\DriverManager::getConnection($params, new \Doctrine\DBAL\Configuration());

0 commit comments

Comments
 (0)