Skip to content

Commit d2b545f

Browse files
loks0nclaude
andcommitted
feat(clickhouse): accept any PSR-18 client in adapter constructor
Widen the ClickHouse adapter's $client parameter from the concrete Utopia\Client to the PSR-18 ClientInterface. The adapter only ever calls sendRequest() on the transport, so the narrower type was unnecessary and blocked passing a Utopia\Client\Pool — which is a ClientInterface but not a Utopia\Client — to share a bounded set of connections across concurrent coroutine callers (the default single-handle cURL client is not coroutine-safe when the adapter is shared). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7a280f8 commit d2b545f

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"minimum-stability": "stable",
2020
"require": {
2121
"php": ">=8.4",
22+
"psr/http-client": "^1.0",
2223
"utopia-php/client": "^0.1|^0.2",
2324
"utopia-php/database": "5.*|6.0.*",
2425
"utopia-php/query": "0.1.*"

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Usage/Adapter/ClickHouse.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use DateTime;
66
use DateTimeZone;
77
use Exception;
8+
use Psr\Http\Client\ClientInterface;
89
use Throwable;
910
use Utopia\Client;
1011
use Utopia\Client\Adapter\Curl\Client as CurlAdapter;
@@ -93,7 +94,7 @@ class ClickHouse extends SQL
9394
/** @var bool Whether to use HTTPS for ClickHouse HTTP interface */
9495
private bool $secure = false;
9596

96-
private Client $client;
97+
private ClientInterface $client;
9798

9899
private RequestFactory $requestFactory;
99100

@@ -148,17 +149,19 @@ class ClickHouse extends SQL
148149
* @param string $password ClickHouse password (default: '')
149150
* @param int $port ClickHouse HTTP port (default: 8123)
150151
* @param bool $secure Whether to use HTTPS (default: false)
151-
* @param Client|null $client HTTP transport. Defaults to a cURL client
152-
* with persistent connection reuse. Inject your own to control timeouts,
153-
* TLS, or retries — e.g. wrap an adapter in `Utopia\Client\Decorator\Retry`.
152+
* @param ClientInterface|null $client PSR-18 HTTP transport. Defaults to a
153+
* cURL client with persistent connection reuse. Inject your own to control
154+
* timeouts, TLS, or retries — e.g. wrap an adapter in
155+
* `Utopia\Client\Decorator\Retry`, or pass a `Utopia\Client\Pool` to share a
156+
* bounded set of connections across concurrent (coroutine) callers.
154157
*/
155158
public function __construct(
156159
string $host,
157160
string $username = 'default',
158161
string $password = '',
159162
int $port = self::DEFAULT_PORT,
160163
bool $secure = false,
161-
?Client $client = null
164+
?ClientInterface $client = null
162165
) {
163166
$this->validateHost($host);
164167
$this->validatePort($port);

0 commit comments

Comments
 (0)