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
| Postgres.js (**recommended**)|[Postgres.js documentation](https://github.com/porsager/postgres)|`[email protected]`| Supported in both Workers & Pages. |
47
+
| Postgres.js |[Postgres.js documentation](https://github.com/porsager/postgres)|`[email protected]`| Supported in both Workers & Pages. |
48
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. |
// Limit the connections for the Worker request to 5 due to Workers' limits on concurrent external connections
71
+
max: 5,
72
+
// If you are not using array types in your Postgres schema, disable `fetch_types` to avoid an additional round-trip (unnecessary latency)
73
+
fetch_types: false,
74
+
});
70
75
71
76
// Create the Drizzle client with the postgres.js connection
72
77
const db =drizzle(sql);
@@ -82,6 +87,13 @@ export default {
82
87
} satisfiesExportedHandler<Env>;
83
88
```
84
89
90
+
:::note
91
+
92
+
You may use [node-postgres](https://orm.drizzle.team/docs/get-started-postgresql#node-postgres) or [Postgres.js](https://orm.drizzle.team/docs/get-started-postgresql#postgresjs)
93
+
when using Drizzle ORM. Both are supported and compatible.
94
+
95
+
:::
96
+
85
97
### 2.3 Configure Drizzle-Kit for migrations (optional)
86
98
87
99
You can generate and run SQL migrations on your database based on your schema using Drizzle Kit CLI. Refer to [Drizzle ORM docs](https://orm.drizzle.team/docs/get-started/postgresql) for additional guidance.
@@ -95,22 +107,22 @@ You can generate and run SQL migrations on your database based on your schema us
95
107
96
108
2. Create a `drizzle.config.ts` file in the root of your project to configure Drizzle Kit and add the following content:
97
109
98
-
```ts
99
-
import"dotenv/config";
100
-
import { defineConfig } from"drizzle-kit";
101
-
exportdefaultdefineConfig({
102
-
out: "./drizzle",
103
-
schema: "./src/db/schema.ts",
104
-
dialect: "postgresql",
105
-
dbCredentials: {
106
-
url: process.env.DATABASE_URL!,
107
-
},
108
-
});
109
-
```
110
+
```ts
111
+
import"dotenv/config";
112
+
import { defineConfig } from"drizzle-kit";
113
+
exportdefaultdefineConfig({
114
+
out: "./drizzle",
115
+
schema: "./src/db/schema.ts",
116
+
dialect: "postgresql",
117
+
dbCredentials: {
118
+
url: process.env.DATABASE_URL!,
119
+
},
120
+
});
121
+
```
110
122
111
123
3. Generate the migration file for your database according to your schema files and apply the migrations to your database.
0 commit comments