Refer to the relevant sections for the API documentation.
TypeScript support
D1 Worker Bindings API is fully-typed via the @cloudflare/workers-types package, and also supports generic types ↗ as part of its TypeScript API. A generic type allows you to provide an optional type parameter so that a function understands the type of the data it is handling.
For example, providing an OrderRow type as a type parameter to D1PreparedStatement::run will return a typed Array<OrderRow> object instead of the default Record<string, unknown> type:
API playground
The D1 Worker Binding API playground is an index.js file where you can test each of the documented Worker Binding APIs for D1. The file builds from the end-state of the Get started code.
You can use this alongside the API documentation to better understand how each API works.
Follow the steps to setup your API playground.
1. Complete the Get started tutorial
Complete the Get started tutorial. Ensure you use JavaScript instead of TypeScript.
2. Modify the content of index.js
Replace the contents of your index.js file with the code below to view the effect of each API.
index.js
3. Deploy the Worker
Navigate to your tutorial directory you created by following step 1.
Run npx wrangler dev.
Open a browser at the specified address.
4. Test the APIs
Change the URL to test the various D1 Worker Binding APIs.
Was this helpful?
What did you like?
What went wrong?
Thank you for helping improve Cloudflare's documentation!