@@ -15,6 +15,7 @@ Naming used here is the same as in ClickHouse docs.
1515- Works with any HTTP Client implementation ([ PSR-18 compliant] ( https://www.php-fig.org/psr/psr-18/ ) )
1616- All [ ClickHouse Formats] ( https://clickhouse.yandex/docs/en/interfaces/formats/ ) support
1717- Logging ([ PSR-3 compliant] ( https://www.php-fig.org/psr/psr-3/ ) )
18+ - SQL Factory for [ parameters "binding"] ( #parameters-binding )
1819- [ Native query parameters] ( #native-query-parameters ) support
1920
2021## Contents
@@ -231,10 +232,7 @@ If not provided they're not passed either:
231232
232233# ## Select
233234
234- # # Native Query Parameters
235-
236- > [!TIP]
237- > [Official docs](https://clickhouse.com/docs/en/interfaces/http#cli-queries-with-parameters)
235+ # # Parameters "binding"
238236
239237` ` ` php
240238<?php
@@ -245,11 +243,35 @@ use SimPod\ClickHouseClient\Sql\ValueFormatter;
245243$sqlFactory = new SqlFactory(new ValueFormatter());
246244
247245$sql = $sqlFactory->createWithParameters(
246+ 'SELECT :param',
247+ ['param' => 'value']
248+ );
249+ ` ` `
250+ This produces `SELECT 'value'` and it can be passed to `ClickHouseClient::select()`.
251+
252+ Supported types are :
253+ - scalars
254+ - DateTimeImmutable (`\DateTime` is not supported because `ValueFormatter` might modify its timezone so it's not considered safe)
255+ - [Expression](#expression)
256+ - objects implementing `__toString()`
257+
258+ # # Native Query Parameters
259+
260+ > [!TIP]
261+ > [Official docs](https://clickhouse.com/docs/en/interfaces/http#cli-queries-with-parameters)
262+
263+ ` ` ` php
264+ <?php
265+
266+ use SimPod\C lickHouseClient\C lient\P srClickHouseClient;
267+
268+ $client = new PsrClickHouseClient(...);
269+
270+ $output = $client->selectWithParams(
248271 'SELECT {p1:String}',
249272 ['param' => 'value']
250273);
251274` ` `
252- This produces `SELECT 'value'` in ClickHouse and it can be passed to `ClickHouseClient::select()`.
253275
254276All types are supported (except `AggregateFunction`, `SimpleAggregateFunction` and `Nothing` by design).
255277You can also pass `DateTimeInterface` into `Date*` types or native array into `Array`, `Tuple`, `Native` and `Geo` types
0 commit comments