-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParts.php
More file actions
55 lines (47 loc) · 1.46 KB
/
Parts.php
File metadata and controls
55 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace SimPod\ClickHouseClient\Snippet;
use Psr\Http\Client\ClientExceptionInterface;
use SimPod\ClickHouseClient\Client\ClickHouseClient;
use SimPod\ClickHouseClient\Exception\ServerError;
use SimPod\ClickHouseClient\Exception\UnsupportedParamType;
use SimPod\ClickHouseClient\Exception\UnsupportedParamValue;
use SimPod\ClickHouseClient\Format\JsonEachRow;
use function sprintf;
final readonly class Parts
{
/**
* @return array<array<string, mixed>>
*
* @throws ClientExceptionInterface
* @throws ServerError
* @throws UnsupportedParamType
* @throws UnsupportedParamValue
*/
public static function run(
ClickHouseClient $clickHouseClient,
string $database,
string $table,
bool|null $active = null,
): array {
$whereActiveClause = $active === null ? '' : sprintf(' AND active = %d', $active);
/** @var JsonEachRow<array<string, mixed>> $format */
$format = new JsonEachRow();
$output = $clickHouseClient->selectWithParams(
<<<CLICKHOUSE
SELECT *
FROM system.parts
WHERE
database = :database
AND table = :table $whereActiveClause
ORDER BY max_date
CLICKHOUSE,
[
'database' => $database,
'table' => $table,
],
$format,
);
return $output->data;
}
}