@dads-framework/postgres 0.1.0 → 0.2.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 +24 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @dads-framework/postgres — the Postgres pool and Drizzle handle
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Open and close Postgres connections in application wiring so database adapters
|
|
4
|
+
can share one pool. This package owns the pool and the Drizzle instance (`createPostgresConnection`),
|
|
4
5
|
plus pool lifecycle/teardown, and the adapter helpers `isUniqueViolation` and
|
|
5
6
|
`loadPageAndTotal`/`sqlOffsetForPage`. Domain code never imports `drizzle-orm`
|
|
6
7
|
directly — it talks to the per-domain `<entity>-reader`/`<entity>-writer`
|
|
@@ -40,17 +41,38 @@ needs the `databaseMigrations` named input instead.
|
|
|
40
41
|
|
|
41
42
|
## Try it
|
|
42
43
|
|
|
44
|
+
In a Node.js 22+ project, install the package.
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npm install @dads-framework/postgres
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Set `DATABASE_URL` to the connection string for a running PostgreSQL database.
|
|
51
|
+
|
|
52
|
+
Save this as `example.mts` and run `node --experimental-strip-types example.mts`.
|
|
53
|
+
|
|
54
|
+
<!-- dads:check-example -->
|
|
55
|
+
|
|
43
56
|
```ts
|
|
44
57
|
import { connectPostgresClient } from "@dads-framework/postgres";
|
|
45
58
|
|
|
59
|
+
const databaseUrl = process.env["DATABASE_URL"];
|
|
60
|
+
if (!databaseUrl) throw new Error("Set DATABASE_URL");
|
|
61
|
+
|
|
46
62
|
const client = await connectPostgresClient(databaseUrl);
|
|
47
63
|
try {
|
|
48
|
-
await client.query("SELECT 1");
|
|
64
|
+
const result = await client.query<{ answer: number }>("SELECT 1 AS answer");
|
|
65
|
+
console.log(result.rows[0]?.answer);
|
|
49
66
|
} finally {
|
|
50
67
|
await client.end();
|
|
51
68
|
}
|
|
52
69
|
```
|
|
53
70
|
|
|
71
|
+
The script prints `1` and closes the connection.
|
|
72
|
+
|
|
73
|
+
In the generated app, `assembly/services.ts` opens the shared application
|
|
74
|
+
connection and closes it when the provider stops. [Starter service wiring](../../../apps/kit-workbench/assembly/services.ts)
|
|
75
|
+
|
|
54
76
|
## What it refuses to do
|
|
55
77
|
|
|
56
78
|
This package manages database connections. Applications provide connection configuration and own schema migrations.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dads-framework/postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"README.md"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@dads-framework/audit-actor": "0.
|
|
53
|
-
"@dads-framework/request-work": "0.
|
|
52
|
+
"@dads-framework/audit-actor": "0.2.0",
|
|
53
|
+
"@dads-framework/request-work": "0.2.0",
|
|
54
54
|
"drizzle-orm": "^0.45.2",
|
|
55
55
|
"pg": "^8.21.0"
|
|
56
56
|
},
|