ClickHouse
Install
| npm install @testcontainers/clickhouse --save-dev
|
Examples
These examples use the following libraries:
Choose an image from the container registry and substitute IMAGE
.
Execute a query
1
2
3
4
5
6
7
8
9
10
11
12
13 | await using container = await new ClickHouseContainer(IMAGE).start();
const client = createClient(container.getClientOptions());
const result = await client.query({
query: "SELECT 1 AS value",
format: "JSON",
});
const data = (await result.json()) as ClickHouseQueryResponse<{ value: number }>;
expect(data?.data?.[0]?.value).toBe(1);
await client.close();
|
Connect with URL
| await using container = await new ClickHouseContainer(IMAGE).start();
const client = createClient({
url: container.getConnectionUrl(),
});
|
With credentials
| await using container = await new ClickHouseContainer(IMAGE)
.withUsername("customUsername")
.withPassword("customPassword")
.start();
const client = createClient({
url: container.getHttpUrl(),
username: container.getUsername(),
password: container.getPassword(),
});
|
With database
| const db = "customDatabase";
await using container = await new ClickHouseContainer(IMAGE).withDatabase(db).start();
|