-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathShowDatabases.php
More file actions
39 lines (32 loc) · 934 Bytes
/
ShowDatabases.php
File metadata and controls
39 lines (32 loc) · 934 Bytes
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
<?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\Format\JsonEachRow;
use function array_map;
final readonly class ShowDatabases
{
/**
* @return list<string>
*
* @throws ClientExceptionInterface
* @throws ServerError
*/
public static function run(ClickHouseClient $clickHouseClient): array
{
/** @var JsonEachRow<array{name: string}> $format */
$format = new JsonEachRow();
$output = $clickHouseClient->select(
<<<'CLICKHOUSE'
SHOW DATABASES
CLICKHOUSE,
$format,
);
return array_map(
static fn (array $database): string => $database['name'],
$output->data,
);
}
}