22icon : devicon-plain:cloudflareworkers
33---
44
5- # Cloudflare D1
5+ # Cloudflare
66
7- > Connect DB0 to Cloudflare D1
7+ > Connect DB0 to Cloudflare D1 or PostgreSQL/MySQL using Cloudflare Hyperdrive
8+
9+
10+ ## Cloudflare D1
811
912: read-more { to =" https://developers.cloudflare.com/d1 " }
1013
1114> [ !NOTE]
1215> This connector works within cloudflare workers with D1 enabled.
1316
14- ## Usage
17+ ### Usage
1518
1619Use ` cloudflare-d1 ` connector:
1720
@@ -31,8 +34,110 @@ const db = createDatabase(
3134>
3235> If you are using [ Nitro] ( https://nitro.unjs.io/ ) you don't need to do any extra steps.
3336
34- ## Options
37+ ### Options
3538
36- ### ` bindingName `
39+ #### ` bindingName `
3740
3841Assigned binding name.
42+
43+ ---
44+
45+ ## Hyperdrive PostgreSQL
46+
47+ : read-more { to =" https://developers.cloudflare.com/hyperdrive " }
48+
49+ > [ !NOTE]
50+ > This connector works within Cloudflare Workers with Hyperdrive enabled.
51+
52+ ### Usage
53+
54+ For this connector, you need to install [ ` pg ` ] ( https://www.npmjs.com/package/pg ) dependency:
55+
56+ : pm-install { name =" pg @types/pg " }
57+
58+ Use ` cloudflare-hyperdrive-postgresql ` connector:
59+
60+ ``` js
61+ import { createDatabase } from " db0" ;
62+ import cloudflareHyperdrivePostgresql from " db0/connectors/cloudflare-hyperdrive-postgresql" ;
63+
64+ const db = createDatabase (
65+ cloudflareHyperdrivePostgresql ({
66+ bindingName: " POSTGRESQL" ,
67+ }),
68+ );
69+ ```
70+
71+ ### Options
72+
73+ #### ` bindingName `
74+
75+ Assigned binding name for your Hyperdrive instance.
76+
77+ #### Additional Options
78+
79+ You can also pass PostgreSQL client configuration options (except for ` user ` , ` database ` , ` password ` , ` port ` , ` host ` , and ` connectionString ` which are managed by Hyperdrive):
80+
81+ ``` js
82+ const db = createDatabase (
83+ cloudflareHyperdrivePostgresql ({
84+ bindingName: " HYPERDRIVE" ,
85+ // Additional PostgreSQL options
86+ statement_timeout: 5000 ,
87+ query_timeout: 10000 ,
88+ }),
89+ );
90+ ```
91+
92+ : read-more { title =" node-postgres documentation " to =" https://node-postgres.com/apis/client#new-client " }
93+
94+ ---
95+
96+ ## Hyperdrive MySQL
97+
98+ : read-more { to =" https://developers.cloudflare.com/hyperdrive " }
99+
100+ > [ !NOTE]
101+ > This connector works within Cloudflare Workers with Hyperdrive enabled.
102+
103+ ### Usage
104+
105+ For this connector, you need to install [ ` mysql2 ` ] ( https://www.npmjs.com/package/mysql2 ) dependency:
106+
107+ : pm-install { name =" mysql2 " }
108+
109+ Use ` cloudflare-hyperdrive-mysql ` connector:
110+
111+ ``` js
112+ import { createDatabase } from " db0" ;
113+ import cloudflareHyperdriveMysql from " db0/connectors/cloudflare-hyperdrive-mysql" ;
114+
115+ const db = createDatabase (
116+ cloudflareHyperdriveMysql ({
117+ bindingName: " MYSQL" ,
118+ }),
119+ );
120+ ```
121+
122+ ### Options
123+
124+ #### ` bindingName `
125+
126+ Assigned binding name for your Hyperdrive instance.
127+
128+ ### Additional Options
129+
130+ You can also pass MySQL client configuration options (except for connection/authentication options which are managed by Hyperdrive, and ` disableEval ` which is incompatible in Cloudflare Workers):
131+
132+ ``` js
133+ const db = createDatabase (
134+ cloudflareHyperdriveMysql ({
135+ bindingName: " HYPERDRIVE" ,
136+ // Additional MySQL options
137+ connectTimeout: 10000 ,
138+ queryTimeout: 5000 ,
139+ }),
140+ );
141+ ```
142+
143+ : read-more { to =" https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L82-L329 " }
0 commit comments