Skip to content

Commit ba296aa

Browse files
CockroachDB
1 parent e13c942 commit ba296aa

File tree

7 files changed

+50
-28
lines changed

7 files changed

+50
-28
lines changed

docs/modules/azurite.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ Choose an image from [Docker Hub](https://hub.docker.com/r/microsoft/azure-stora
4444
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:createAndInsertOnTable
4545
<!--/codeinclude-->
4646

47-
### Custom credentials
47+
### In memory persistence
4848

4949
<!--codeinclude-->
50-
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:customCredentials
50+
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:inMemoryPersistence
5151
<!--/codeinclude-->
5252

53-
### Custom ports
53+
### With credentials
5454

5555
<!--codeinclude-->
56-
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:customPorts
56+
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:customCredentials
5757
<!--/codeinclude-->
5858

59-
### In memory persistence
59+
### With ports
6060

6161
<!--codeinclude-->
62-
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:inMemoryPersistence
62+
[](../../packages/modules/azurite/src/azurite-container.test.ts) inside_block:customPorts
6363
<!--/codeinclude-->

docs/modules/cassandra.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Choose an image from [Docker Hub](https://hub.docker.com/_/cassandra) and substi
2424
[](../../packages/modules/cassandra/src/cassandra-container.test.ts) inside_block:connectWithDefaultCredentials
2525
<!--/codeinclude-->
2626

27-
### Custom credentials
27+
### With credentials
2828

2929
<!--codeinclude-->
3030
[](../../packages/modules/cassandra/src/cassandra-container.test.ts) inside_block:connectWithCustomCredentials
3131
<!--/codeinclude-->
3232

33-
### Custom datacenter / rack
33+
### With datacenter/rack
3434

3535
<!--codeinclude-->
3636
[](../../packages/modules/cassandra/src/cassandra-container.test.ts) inside_block:customDataCenterAndRack

docs/modules/chromadb.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ Choose an image from [Docker Hub](https://hub.docker.com/r/chromadb/chroma) and
4444

4545
<!--codeinclude-->
4646
[](../../packages/modules/chromadb/src/chromadb-container.test.ts) inside_block:chromaAuth
47-
<!--/codeinclude-->_
47+
<!--/codeinclude-->

docs/modules/clickhouse.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ Choose an image from [Docker Hub](https://hub.docker.com/r/clickhouse/clickhouse
3030
[](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:connectWithUrl
3131
<!--/codeinclude-->
3232

33-
### Connect with credentials
33+
### With credentials
3434

3535
<!--codeinclude-->
3636
[](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:connectWithUsernameAndPassword
3737
<!--/codeinclude-->
3838

39-
### Set database
39+
### With database
4040

4141
<!--codeinclude-->
4242
[](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:setDatabase

docs/modules/cockroachdb.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# CockroachDB Module
2-
3-
[CockroachDB](https://github.com/cockroachdb/cockroach) is a cloud-native, postgresql compatible, distributed SQL database designed to build, scale, and manage modern, data-intensive applications.
4-
1+
# CockroachDB
52

63
## Install
74

@@ -11,18 +8,40 @@ npm install @testcontainers/cockroachdb --save-dev
118

129
## Examples
1310

11+
These examples use the following libraries:
12+
13+
- [pg](https://www.npmjs.com/package/pg)
14+
15+
npm install pg
16+
17+
- [@types/pg](https://www.npmjs.com/package/@types/pg)
18+
19+
npm install @types/pg
20+
21+
---
22+
23+
Choose an image from [Docker Hub](https://hub.docker.com/r/cockroachdb/cockroach) and substitute `IMAGE`.
24+
25+
### Execute a query
26+
1427
<!--codeinclude-->
15-
[Connect and execute query:](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:connect
28+
[](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:cockroachConnect
1629
<!--/codeinclude-->
1730

31+
### Connect with URI
32+
1833
<!--codeinclude-->
19-
[Connect and execute query using URI:](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:uriConnect
34+
[](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:uriConnect
2035
<!--/codeinclude-->
2136

37+
### With database
38+
2239
<!--codeinclude-->
23-
[Set database:](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:setDatabase
40+
[](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:setDatabase
2441
<!--/codeinclude-->
2542

43+
### With username
44+
2645
<!--codeinclude-->
27-
[Set username:](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:setUsername
46+
[](../../packages/modules/cockroachdb/src/cockroachdb-container.test.ts) inside_block:setUsername
2847
<!--/codeinclude-->

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ nav:
6060
- Cassandra: modules/cassandra.md
6161
- ChromaDB: modules/chromadb.md
6262
- ClickHouse: modules/clickhouse.md
63+
- CockroachDB: modules/cockroachdb.md
6364
- CosmosDB: modules/cosmosdb.md
6465
- Couchbase: modules/couchbase.md
65-
- CockroachDB: modules/cockroachdb.md
6666
- Elasticsearch: modules/elasticsearch.md
6767
- Etcd: modules/etcd.md
6868
- GCloud: modules/gcloud.md

packages/modules/cockroachdb/src/cockroachdb-container.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { CockroachDbContainer } from "./cockroachdb-container";
55
const IMAGE = getImage(__dirname);
66

77
describe("CockroachDbContainer", { timeout: 180_000 }, () => {
8-
// connect {
98
it("should connect and return a query result", async () => {
9+
// cockroachConnect {
1010
await using container = await new CockroachDbContainer(IMAGE).start();
1111

1212
const client = new Client({
@@ -23,62 +23,65 @@ describe("CockroachDbContainer", { timeout: 180_000 }, () => {
2323
expect(result.rows[0]).toEqual({ "?column?": "1" });
2424

2525
await client.end();
26+
// }
2627
});
27-
// }
2828

29-
// uriConnect {
3029
it("should work with database URI", async () => {
30+
// uriConnect {
3131
await using container = await new CockroachDbContainer(IMAGE).start();
3232

3333
const client = new Client({
3434
connectionString: container.getConnectionUri(),
3535
});
36+
// }
37+
3638
await client.connect();
3739

3840
const result = await client.query("SELECT 1");
3941
expect(result.rows[0]).toEqual({ "?column?": "1" });
4042

4143
await client.end();
4244
});
43-
// }
4445

45-
// setDatabase {
4646
it("should set database", async () => {
47+
// setDatabase {
4748
await using container = await new CockroachDbContainer(IMAGE).withDatabase("custom_database").start();
49+
// }
4850

4951
const client = new Client({
5052
host: container.getHost(),
5153
port: container.getPort(),
5254
database: container.getDatabase(),
5355
user: container.getUsername(),
5456
});
57+
5558
await client.connect();
5659

5760
const result = await client.query("SELECT current_database()");
5861
expect(result.rows[0]).toEqual({ current_database: "custom_database" });
5962

6063
await client.end();
6164
});
62-
// }
6365

64-
// setUsername {
6566
it("should set username", async () => {
67+
// setUsername {
6668
await using container = await new CockroachDbContainer(IMAGE).withUsername("custom_username").start();
69+
// }
6770

6871
const client = new Client({
6972
host: container.getHost(),
7073
port: container.getPort(),
7174
database: container.getDatabase(),
7275
user: container.getUsername(),
7376
});
77+
7478
await client.connect();
7579

7680
const result = await client.query("SELECT current_user");
7781
expect(result.rows[0]).toEqual({ current_user: "custom_username" });
7882

7983
await client.end();
8084
});
81-
// }
8285

8386
it("should work with restarted container", async () => {
8487
await using container = await new CockroachDbContainer(IMAGE).start();

0 commit comments

Comments
 (0)