pgsql-test 2.0.5 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +61 -16
  2. package/package.json +28 -3
package/README.md CHANGED
@@ -16,7 +16,6 @@
16
16
  </a>
17
17
  </p>
18
18
 
19
-
20
19
  `pgsql-test` gives you instant, isolated PostgreSQL databases for each test — with automatic transaction rollbacks, context switching, and clean seeding. Forget flaky tests and brittle environments. Write real SQL. Get real coverage. Stay fast.
21
20
 
22
21
  ## Install
@@ -52,6 +51,7 @@ Part of the [LaunchQL](https://github.com/launchql) ecosystem, `pgsql-test` is b
52
51
  6. [Usage Examples](#usage-examples)
53
52
  * [Basic Setup](#-basic-setup)
54
53
  * [Role-Based Context](#-role-based-context)
54
+ * [Seeding System](#-seeding-system)
55
55
  * [SQL File Seeding](#-sql-file-seeding)
56
56
  * [Programmatic Seeding](#-programmatic-seeding)
57
57
  * [CSV Seeding](#️-csv-seeding)
@@ -79,6 +79,16 @@ afterAll(() => teardown());
79
79
 
80
80
  ## `getConnections()` Overview
81
81
 
82
+ ```ts
83
+ import { getConnections } from 'pgsql-test';
84
+
85
+ // Complete object destructuring
86
+ const { pg, db, admin, teardown, manager } = await getConnections();
87
+
88
+ // Most common pattern
89
+ const { db, teardown } = await getConnections();
90
+ ```
91
+
82
92
  The `getConnections()` helper sets up a fresh PostgreSQL test database and returns a structured object with:
83
93
 
84
94
  * `pg`: a `PgTestClient` connected as the root or superuser — useful for administrative setup or introspection
@@ -97,6 +107,19 @@ The `PgTestClient` returned by `getConnections()` is a fully-featured wrapper ar
97
107
 
98
108
  ## `PgTestClient` API Overview
99
109
 
110
+ ```ts
111
+ let pg: PgTestClient;
112
+ let teardown: () => Promise<void>;
113
+
114
+ beforeAll(async () => {
115
+ ({ pg, teardown } = await getConnections());
116
+ });
117
+
118
+ beforeEach(() => pg.beforeEach());
119
+ afterEach(() => pg.afterEach());
120
+ afterAll(() => teardown());
121
+ ```
122
+
100
123
  The `PgTestClient` returned by `getConnections()` wraps a `pg.Client` and provides convenient helpers for query execution, test isolation, and context switching.
101
124
 
102
125
  ### Common Methods
@@ -201,6 +224,27 @@ This approach enables testing various access patterns:
201
224
 
202
225
  > **Note:** While this interface helps simulate RBAC for testing, your production server should manage user/role claims via secure authentication tokens, typically by setting values like `current_setting('jwt.claims.user_id')` through proper authentication middleware.
203
226
 
227
+ ### 🌱 Seeding System
228
+
229
+ The second argument to `getConnections()` is an optional array of `SeedAdapter` objects:
230
+
231
+ ```ts
232
+ const { db, teardown } = await getConnections(getConnectionOptions, seedAdapters);
233
+ ```
234
+
235
+ This array lets you fully customize how your test database is seeded. You can compose multiple strategies:
236
+
237
+ * [`seed.sqlfile()`](#-sql-file-seeding) – Execute raw `.sql` files from disk
238
+ * [`seed.fn()`](#-programmatic-seeding) – Run JavaScript/TypeScript logic to programmatically insert data
239
+ * [`seed.csv()`](#️-csv-seeding) – Load tabular data from CSV files
240
+ * [`seed.json()`](#️-json-seeding) – Use in-memory objects as seed data
241
+ * [`seed.sqitch()`](#️-sqitch-seeding) – Deploy a Sqitch-compatible migration project
242
+ * [`seed.launchql()`](#-launchql-seeding) – Apply a LaunchQL module using `deployFast()` (compatible with sqitch)
243
+
244
+ > ✨ **Default Behavior:** If no `SeedAdapter[]` is passed, LaunchQL seeding is assumed. This makes `pgsql-test` zero-config for LaunchQL-based projects.
245
+
246
+ This composable system allows you to mix-and-match data setup strategies for flexible, realistic, and fast database tests.
247
+
204
248
  ### 🔌 SQL File Seeding
205
249
 
206
250
  Use `.sql` files to set up your database state before tests:
@@ -368,19 +412,28 @@ beforeAll(async () => {
368
412
  seed.sqitch(cwd)
369
413
  ]));
370
414
  });
371
-
372
- it('runs a schema query', async () => {
373
- const res = await db.query('SELECT COUNT(*) FROM myapp.users');
374
- expect(+res.rows[0].count).toBeGreaterThanOrEqual(0);
375
- });
376
415
  ```
377
416
 
378
417
  This works for any Sqitch-compatible module, now accelerated by LaunchQL's deployment tooling.
379
418
 
380
419
  ## 🚀 LaunchQL Seeding
381
420
 
382
- For LaunchQL modules with precompiled `sqitch.plan`, use `seed.launchql(cwd)` to apply a schema quickly with `deployFast()`:
383
- For maximum performance with precompiled LaunchQL modules, use `seed.launchql(cwd)` to apply a schema at lightning speed with our TypeScript-powered `deployFast()`:
421
+ If your project uses LaunchQL modules with a precompiled `sqitch.plan`, you can use `pgsql-test` with **zero configuration**. Just call `getConnections()` — and it *just works*:
422
+
423
+ ```ts
424
+ import { getConnections } from 'pgsql-test';
425
+
426
+ let db, teardown;
427
+
428
+ beforeAll(async () => {
429
+ ({ db, teardown } = await getConnections()); // 🚀 LaunchQL deployFast() is used automatically - up to 10x faster than traditional Sqitch!
430
+ });
431
+ ```
432
+
433
+ This works out of the box because `pgsql-test` uses the high-speed `deployFast()` function by default, applying any compiled LaunchQL schema located in the current working directory (`process.cwd()`).
434
+
435
+ If you want to specify a custom path to your LaunchQL module, use `seed.launchql()` explicitly:
436
+
384
437
 
385
438
  ```ts
386
439
  import path from 'path';
@@ -393,16 +446,8 @@ beforeAll(async () => {
393
446
  seed.launchql(cwd) // uses deployFast() - up to 10x faster than traditional Sqitch!
394
447
  ]));
395
448
  });
396
-
397
- it('creates user records', async () => {
398
- await db.query(`INSERT INTO myapp.users (username, email) VALUES ('testuser', 'test@example.com')`);
399
- const res = await db.query(`SELECT COUNT(*) FROM myapp.users`);
400
- expect(+res.rows[0].count).toBeGreaterThan(0);
401
- });
402
449
  ```
403
450
 
404
- This is the fastest way to bring up a ready-to-query schema from a compiled LaunchQL module - perfect for both development and CI environments.
405
-
406
451
  ## Why LaunchQL's Approach?
407
452
 
408
453
  LaunchQL provides the best of both worlds:
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "pgsql-test",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
- "description": "PostgreSQL Testing in TypeScript",
5
+ "description": "pgsql-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests — giving developers realistic test coverage without external state pollution",
6
6
  "main": "index.js",
7
7
  "module": "esm/index.js",
8
8
  "types": "index.d.ts",
@@ -19,6 +19,31 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/launchql/launchql/issues"
21
21
  },
22
+ "keywords": [
23
+ "postgres",
24
+ "postgresql",
25
+ "testing",
26
+ "integration-tests",
27
+ "database-testing",
28
+ "pg",
29
+ "rls",
30
+ "role-based-access",
31
+ "test-database",
32
+ "test-runner",
33
+ "jest",
34
+ "mocha",
35
+ "sqitch",
36
+ "launchql",
37
+ "typeorm",
38
+ "knex",
39
+ "seed",
40
+ "fixtures",
41
+ "transactions",
42
+ "rollback",
43
+ "node-postgres",
44
+ "pg-pool",
45
+ "pg-client"
46
+ ],
22
47
  "scripts": {
23
48
  "copy": "copyfiles -f ../../LICENSE README.md package.json dist",
24
49
  "clean": "rimraf dist/**",
@@ -42,5 +67,5 @@
42
67
  "pg": "^8.16.0",
43
68
  "pg-copy-streams": "^6.0.6"
44
69
  },
45
- "gitHead": "5697261a8f6e252d38b02b806272a19c5cd7a578"
70
+ "gitHead": "9b9c34caa3b8f21c9996f23495013cfe88612672"
46
71
  }