Skip to content

Commit 52ebb6d

Browse files
authored
feat: undeprecate ValueFormatter (#249)
1 parent 5036edb commit 52ebb6d

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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\ClickHouseClient\Client\PsrClickHouseClient;
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

254276
All types are supported (except `AggregateFunction`, `SimpleAggregateFunction` and `Nothing` by design).
255277
You can also pass `DateTimeInterface` into `Date*` types or native array into `Array`, `Tuple`, `Native` and `Geo` types

src/Sql/ValueFormatter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
use function preg_match;
2323
use function sprintf;
2424

25-
/**
26-
* @internal
27-
* @deprecated
28-
*/
25+
/** @internal */
2926
final class ValueFormatter
3027
{
3128
public function __construct(private DateTimeZone|null $dateTimeZone = null)

0 commit comments

Comments
 (0)