Skip to content

Commit f7574c2

Browse files
committed
cloudflare docs
1 parent fa1c2cc commit f7574c2

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

README.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,7 @@ import map from './map';
320320

321321
const db = map.http('http://localhost:3000/orange');
322322
```
323-
__Cloudflare D1__
324-
<sub>📄 wrangler.toml</sub>
325-
```toml
326-
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
327-
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
328-
[[d1_databases]]
329-
binding = "DB"
330-
database_name = "<your-name-for-the-database>"
331-
database_id = "<your-guid-for-the-database>"
332-
```
333323

334-
```javascript
335-
import map from './map';
336-
// Must match the binding name in wrangler.toml
337-
const db = map.d1(env.DB);
338-
```
339324
__MySQL__
340325
```bash
341326
$ npm install mysql2
@@ -381,6 +366,38 @@ With schema
381366
import map from './map';
382367
const db = map.postgres('postgres://postgres:postgres@postgres/postgres?search_path=custom');
383368
```
369+
__Cloudflare D1__
370+
<sub>📄 wrangler.toml</sub>
371+
```toml
372+
name = "d1-tutorial"
373+
main = "src/index.ts"
374+
compatibility_date = "2025-02-04"
375+
376+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
377+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
378+
[[d1_databases]]
379+
binding = "DB"
380+
database_name = "<your-name-for-the-database>"
381+
database_id = "<your-guid-for-the-database>"
382+
```
383+
384+
<sub>📄 scr/index.ts</sub>
385+
```javascript
386+
import map from './map';
387+
388+
export interface Env {
389+
// Must match the binding name in wrangler.toml
390+
DB: D1Database;
391+
}
392+
393+
export default {
394+
async fetch(request, env): Promise<Response> {
395+
const db = map.d1(env.DB);
396+
const customers = await db.customer.getAll();
397+
return Response.json(customers);
398+
},
399+
} satisfies ExportedHandler<Env>;
400+
```
384401
__Oracle__
385402
```bash
386403
npm install oracledb

0 commit comments

Comments
 (0)