Cloudflare 中文文档
D1
编辑这个页面
跳转官方原文档
Set theme to dark (⇧+D)

Query D1 from Hono

Query D1 from the Hono web framework

Hono is a fast web framework for building API-first applications, and it includes first-class support for both Workers and Pages.

When using Workers:

If you are using Pages Functions:

  1. Bind a D1 database to your Pages Function.
  2. Pass the --d1 BINDING_NAME=DATABASE_ID flag to wrangler dev when developing locally. BINDING_NAME should match what call in your code, and DATABASE_ID should match the database_id defined in your wrangler.toml: for example, --d1 DB=xxxx-xxxx-xxxx-xxxx-xxxx.
  3. Refer to the Hono guide for Cloudflare Pages.

The following examples show how to access a D1 database bound to DB from both a Workers script and a Pages Function: