@@ -320,22 +320,7 @@ import map from './map';
320320
321321const 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
381366import map from ' ./map' ;
382367const 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
386403npm install oracledb
0 commit comments