Skip to content

Cloudflare d1 #114

Answered by lroal
thunderbug1 asked this question in Q&A
Nov 8, 2024 · 3 comments · 9 replies
Discussion options

You must be logged in to vote

Cloudflare is now supported from v.4.5.0
📄 wrangler.toml

name = "d1-tutorial"
main = "src/index.ts"
compatibility_date = "2025-02-04"

# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
[[d1_databases]]
binding = "DB"
database_name = "<your-name-for-the-database>"
database_id = "<your-guid-for-the-database>"

📄 src/index.ts

import map from './map';

export interface Env {
  // Must match the binding name in wrangler.toml  
  DB: D1Database;
}

export default {
  async fetch(request, env): Promise<Response> {
    const db = map.d1(env.DB);
    const customers = await db.customer.getAll(

Replies: 3 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@lroal
Comment options

@lroal
Comment options

@thunderbug1
Comment options

@lroal
Comment options

lroal Dec 9, 2024
Maintainer

@thunderbug1
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by lroal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants