@n8io/baseline-postgres 3.0.0 → 4.0.0

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.
package/README.md CHANGED
@@ -9,7 +9,7 @@ pnpm add @n8io/baseline-postgres
9
9
  ## Exports
10
10
 
11
11
  - `postgresPoolCreate({ databaseUrl, max?, connectTimeoutMs?, vendor? })`: the process's one pool (10 connections, 3 s connect timeout). `vendor` takes pg's own pool settings, such as `ssl` or `idleTimeoutMillis`, and passes them through. The named options win: `vendor` throws on the keys they set, on `host`, `port`, `database`, `user` and `password` (pg lets the URL win, so put them in `databaseUrl`), and on `ssl` when the URL carries an `ssl*` parameter. It is outside the contract: nothing in it is tested here, and moving off pg deletes it.
12
- - `PostgresPool`, `PostgresClient`: the pool and a checked-out connection. Name these in your own signatures, not `pg`'s types. They are pg's own pool and client, because Drizzle's `drizzle({ client })` needs the real ones.
12
+ - `PostgresPool`, `PostgresClient`: the pool and a checked-out connection. `await using` calls the pool's `end()` when its block ends. Name these in your own signatures, not `pg`'s types. They are pg's own pool and client, because Drizzle's `drizzle({ client })` needs the real ones.
13
13
  - `postgresTransactionRun(pgPool, work, { timeoutMs? })`: runs `work(pgClient)` in one transaction; COMMIT on `ok`, ROLLBACK on `err` or a throw. It ends after `timeoutMs` (default 5 s).
14
14
  - `postgresMigrate({ databaseUrl, migrationsFolder, vendor? })`: applies pending Drizzle migrations under an advisory lock, so concurrent starts apply each one once. `vendor` takes pg's settings for its one connection, under the same rules as the pool's.
15
15
  - `postgresIdColumnCreate(prefix)`: a Drizzle `uuid` column that reads and writes `Id<prefix>`.
package/dist/index.d.ts CHANGED
@@ -29,8 +29,11 @@ export declare const postgresMigrate: (options: {
29
29
  /** Settings only pg has, such as `ssl`: the same ones the pool takes. */
30
30
  vendor?: PostgresMigrateVendorOptions;
31
31
  }) => Promise<void>;
32
- /** The process's Postgres connection pool. Close it with `end()`. */
33
- type PostgresPool = pg.Pool;
32
+ /**
33
+ * The process's Postgres connection pool. Close it with `end()`; `await using` calls `end()` when
34
+ * its block ends.
35
+ */
36
+ type PostgresPool = pg.Pool & AsyncDisposable;
34
37
  /** One connection checked out of the pool: what `postgresTransactionRun` hands to its work. */
35
38
  type PostgresClient = pg.PoolClient;
36
39
  /**
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ const postgresPoolCreate = ({ connectTimeoutMs = 3e3, databaseUrl, max = 10, ven
84
84
  pgPool.on("error", (error) => {
85
85
  logger.error({ err: error }, "Postgres idle client error");
86
86
  });
87
- return pgPool;
87
+ return Object.assign(pgPool, { [Symbol.asyncDispose]: () => pgPool.end() });
88
88
  };
89
89
  // src/postgres-transaction-run.ts
90
90
  const clientGuard = (pgClient, isOpen) => new Proxy(pgClient, { get(target, property) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n8io/baseline-postgres",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Postgres pool, Result-aware transactions, migrations and prefixed-id columns on pg and Drizzle.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,8 +27,8 @@
27
27
  "registry": "https://registry.npmjs.org"
28
28
  },
29
29
  "dependencies": {
30
- "@n8io/baseline-id": "^2.0.0",
31
- "@n8io/baseline-logger": "^3.0.0",
30
+ "@n8io/baseline-id": "^3.0.0",
31
+ "@n8io/baseline-logger": "^3.1.0",
32
32
  "@n8io/baseline-result": "^1.1.1"
33
33
  },
34
34
  "peerDependencies": {