CockroachDB
Install
| npm install @testcontainers/cockroachdb --save-dev
|
Examples
These examples use the following libraries:
- pg
| npm 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
16 | await 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
| await using container = await new CockroachDbContainer(IMAGE).start();
const client = new Client({
connectionString: container.getConnectionUri(),
});
|
With database
| await using container = await new CockroachDbContainer(IMAGE).withDatabase("custom_database").start();
|
With username
| await using container = await new CockroachDbContainer(IMAGE).withUsername("custom_username").start();
|