Skip to content

Commit 1f04cd4

Browse files
thomasgauvindeadlypants1973
authored andcommitted
thomasgauvin: fix db docs to adjust for no default nodejs_compat in c3 (#19395)
1 parent 7d6843f commit 1f04cd4

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

src/content/docs/hyperdrive/configuration/connect-to-postgres.mdx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,24 @@ Refer to the [Examples documentation](/hyperdrive/examples/) for step-by-step gu
5252

5353
Hyperdrive uses Workers [TCP socket support](/workers/runtime-apis/tcp-sockets/#connect) to support TCP connections to databases. The following table lists the supported database drivers and the minimum version that works with Hyperdrive:
5454

55-
| Driver | Documentation | Minimum Version Required | Notes |
56-
| ----------------------------- | ---------------------------------------------------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
57-
| Postgres.js (**recommended**) | [Postgres.js documentation](https://github.com/porsager/postgres) | `[email protected]` | Supported in both Workers & Pages. |
58-
| 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. |
59-
| Drizzle | [Drizzle documentation](https://orm.drizzle.team/) | `0.26.2`^ | |
60-
| Kysely | [Kysely documentation](https://kysely.dev/) | `0.26.3`^ | |
61-
| [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. |
55+
| Driver | Documentation | Minimum Version Required | Notes |
56+
| ---------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
57+
| Postgres.js (**recommended**) | [Postgres.js documentation](https://github.com/porsager/postgres) | `[email protected]` | Supported in both Workers & Pages. |
58+
| 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. |
59+
| Drizzle | [Drizzle documentation](https://orm.drizzle.team/) | `0.26.2`^ | |
60+
| Kysely | [Kysely documentation](https://kysely.dev/) | `0.26.3`^ | |
61+
| [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. |
6262

6363
^ _The marked libraries use `node-postgres` as a dependency._
6464

6565
Other drivers and ORMs not listed may also be supported: this list is not exhaustive.
6666

67+
### Database drivers and Node.js compatibility
68+
69+
[Node.js compatibility](/workers/runtime-apis/nodejs/) is required for database drivers, including Postgres.js, and needs to be configured for your Workers project.
70+
71+
<Render file="nodejs_compat" product="workers" />
72+
6773
## Supported TLS (SSL) modes
6874

6975
Hyperdrive supports the following [PostgreSQL TLS (SSL)](https://www.postgresql.org/docs/current/libpq-ssl.html) connection modes when connecting to your origin database:

src/content/docs/hyperdrive/get-started.mdx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,11 @@ This will create a new `hyperdrive-tutorial` directory. Your new `hyperdrive-tut
7474
- A `"Hello World"` [Worker](/workers/get-started/guide/#3-write-code) at `src/index.ts`.
7575
- A [`wrangler.toml`](/workers/wrangler/configuration/) configuration file. `wrangler.toml` is how your `hyperdrive-tutorial` Worker will connect to Hyperdrive.
7676

77-
:::note
78-
79-
Note that the `wrangler.toml` file contains the following option:
80-
81-
import { WranglerConfig } from "~/components";
82-
83-
<WranglerConfig>
77+
### Enable Node.js compatibility
8478

85-
```toml title="wrangler.toml"
86-
compatibility_flags = [ "nodejs_compat" ]
87-
```
88-
89-
</WranglerConfig>
79+
[Node.js compatibility](/workers/runtime-apis/nodejs/) is required for database drivers, including Postgres.js, and needs to be configured for your Workers project.
9080

91-
This enables the Node.js compatibility mode which is required for database drivers, including Postgres.js.
92-
93-
:::
81+
<Render file="nodejs_compat" product="workers" />
9482

9583
## 3. Connect Hyperdrive to a database
9684

src/content/docs/workers/tutorials/postgres/index.mdx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ languages:
1313
- SQL
1414
---
1515

16-
import { Render, PackageManagers } from "~/components";
16+
import { Render, PackageManagers, WranglerConfig } from "~/components";
1717

1818
In this tutorial, you will learn how to create a Cloudflare Workers application and connect it to a PostgreSQL database using [TCP Sockets](/workers/runtime-apis/tcp-sockets/) and [Hyperdrive](/hyperdrive/). The Workers application you create in this tutorial will interact with a product database inside of PostgreSQL.
1919

@@ -58,17 +58,9 @@ cd postgres-tutorial
5858

5959
### Enable Node.js compatibility
6060

61-
<Render file="nodejs-compat-howto" />
61+
[Node.js compatibility](/workers/runtime-apis/nodejs/) is required for database drivers, including Postgres.js, and needs to be configured for your Workers project.
6262

63-
import { WranglerConfig } from "~/components";
64-
65-
<WranglerConfig>
66-
67-
```toml title="wrangler.toml"
68-
compatibility_flags = ["nodejs_compat_v2"]
69-
```
70-
71-
</WranglerConfig>
63+
<Render file="nodejs_compat" product="workers" />
7264

7365
## 2. Add the PostgreSQL connection library
7466

@@ -112,8 +104,6 @@ npx wrangler secret put DB_URL
112104

113105
Set your `DB_URL` secret locally in a `.dev.vars` file as documented in [Local Development with Secrets](/workers/configuration/secrets/).
114106

115-
116-
117107
<WranglerConfig>
118108

119109
```toml
@@ -126,8 +116,6 @@ DB_URL="<ENTER YOUR POSTGRESQL CONNECTION STRING>"
126116

127117
Configure each database parameter as an [environment variable](/workers/configuration/environment-variables/) via the [Cloudflare dashboard](/workers/configuration/environment-variables/#add-environment-variables-via-the-dashboard) or in your `wrangler.toml` file. Refer to an example of a`wrangler.toml` file configuration:
128118

129-
130-
131119
<WranglerConfig>
132120

133121
```toml
@@ -329,8 +317,6 @@ You can also use explicit parameters by following the [wrangler documentation fo
329317

330318
This command outputs the Hyperdrive configuration `id` that will be used for your Hyperdrive [binding](/workers/runtime-apis/bindings/). Set up your binding by specifying the `id` in the `wrangler.toml` file.
331319

332-
333-
334320
<WranglerConfig>
335321

336322
```toml {7-9}

0 commit comments

Comments
 (0)