Supported container runtimes
CockroachDB
登录后可跨设备保存划线和私人笔记登录
CockroachDB
Install
1npm install @testcontainers/cockroachdb --save-devExamples
These examples use the following libraries:
-
1 2npm install pg npm install @types/pg --save-dev
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
14
15
16await using container = await new CockroachDbContainer(image).start();
const client = new Client({
host: container.getHost(),
port: container.getPort(),
database: container.getDatabase(),
user: container.getUsername(),
ssl: false,
});
await client.connect();
const result = await client.query("SELECT 1");
expect(result.rows[0]).toEqual({ "?column?": "1" });
await client.end();Connect with URI
1
2
3
4
5await using container = await new CockroachDbContainer(image).start();
const client = new Client({
connectionString: container.getConnectionUri(),
});With database
1await using container = await new CockroachDbContainer(image).withDatabase("custom_database").start();With username
1await using container = await new CockroachDbContainer(image).withUsername("custom_username").start();评论
登录后参与评论
正在加载评论…
KnowForge