You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| node-postgres - `pg` (recommended) |[node-postgres - `pg` documentation](https://node-postgres.com/)|`[email protected]`|`8.11.4` introduced a bug with URL parsing and will not work. `8.11.5` fixes this. Requires `compatibility_flags = ["nodejs_compat"]` and `compatibility_date = "2024-09-23"` - refer to [Node.js compatibility](/workers/runtime-apis/nodejs). Requires wrangler `3.78.7` or later. |
47
48
| Postgres.js |[Postgres.js documentation](https://github.com/porsager/postgres)|`[email protected]`| Supported in both Workers & Pages. |
48
-
| node-postgres - `pg`|[node-postgres - `pg` documentation](https://node-postgres.com/)|`[email protected]`|`8.11.4` introduced a bug with URL parsing and will not work. `8.11.5` fixes this. Requires `compatibility_flags = ["nodejs_compat"]` and `compatibility_date = "2024-09-23"` - refer to [Node.js compatibility](/workers/runtime-apis/nodejs). Requires wrangler `3.78.7` or later. |
|[rust-postgres](https://github.com/sfackler/rust-postgres)|[rust-postgres documentation](https://docs.rs/postgres/latest/postgres/)|`v0.19.8`| Use the [`query_typed`](https://docs.rs/postgres/latest/postgres/struct.Client.html#method.query_typed) method for best performance. |
@@ -68,18 +68,18 @@ The following examples show you how to:
68
68
2. Pass the Hyperdrive connection string and connect to the database.
69
69
3. Query your database via Hyperdrive.
70
70
71
-
### Postgres.js
72
-
73
-
The following Workers code shows you how to use [Postgres.js](https://github.com/porsager/postgres) with Hyperdrive.
Copy file name to clipboardExpand all lines: src/content/docs/hyperdrive/get-started.mdx
+20-19Lines changed: 20 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,11 +182,15 @@ Once you have created a Hyperdrive configuration and bound it to your Worker, yo
182
182
<Tabs>
183
183
<TabItemlabel="PostgreSQL">
184
184
185
-
To connect to your database, you will need a database driver which allows you to authenticate and query your database. For this tutorial, you will use [Postgres.js](https://github.com/porsager/postgres), one of the most widely used PostgreSQL drivers.
185
+
To connect to your database, you will need a database driver which allows you to authenticate and query your database. For this tutorial, you will use [node-postgres (pg)](https://node-postgres.com/), one of the most widely used PostgreSQL drivers.
186
186
187
-
To install `postgres`, ensure you are in the `hyperdrive-tutorial` directory. Open your terminal and run the following command:
187
+
To install `pg`, ensure you are in the `hyperdrive-tutorial` directory. Open your terminal and run the following command:
188
188
189
-
<PackageManagerspkg="postgres"comment="This should install v3.4.5 or later" />
189
+
<PackageManagerspkg="pg"comment="This should install v8.13.0 or later" />
190
+
191
+
If you are using TypeScript, you should also install the type definitions for `pg`:
192
+
193
+
<PackageManagerspkg="@types/pg"devcomment="This should install v8.13.0 or later" />
190
194
191
195
With the driver installed, you can now create a Worker script that queries your database.
192
196
@@ -217,8 +221,8 @@ The `index.ts` file is where you configure your Worker's interactions with Hyper
217
221
Populate your `index.ts` file with the following code:
218
222
219
223
```typescript
220
-
//Postgres.js 3.4.5 or later is recommended
221
-
importpostgresfrom"postgres";
224
+
//pg 8.13.0 or later is recommended
225
+
import{ Client } from"pg";
222
226
223
227
exportinterfaceEnv {
224
228
// If you set another name in the Wrangler config file as the value for 'binding',
0 commit comments