Supported container runtimes
ClickHouse
登录后可跨设备保存划线和私人笔记登录
ClickHouse
Install
1npm install @testcontainers/clickhouse --save-devExamples
These examples use the following libraries:
-
1npm install @clickhouse/client
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
13await 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
1
2
3
4
5await using container = await new ClickHouseContainer(IMAGE).start();
const client = createClient({
url: container.getConnectionUrl(),
});With credentials
1
2
3
4
5
6
7
8
9
10await 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
1
2const db = "customDatabase";
await using container = await new ClickHouseContainer(IMAGE).withDatabase(db).start();评论
登录后参与评论
正在加载评论…
KnowForge