export default defineEventHandler((event) => {
const db = event.context.DB
console.log('context ',db); // undefined
console.log('event.context',event.context) // object returned, no DB
var posts: Post[];
posts = [
{ id: 1, title: 'Post 1', body: 'This is the body of post 1' },
{ id: 2, title: 'Post 2', body: 'This is the body of post 2' },
{ id: 3, title: 'Post 3', body: 'This is the body of post 3' },
]
return posts; // I see the posts returned status code 200
})[[d1_databases]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "demo"
database_id = "[guid]"
preview_database_id = "DB""pages:dev": "wrangler pages dev --compatibility-date=2024-02-08 --proxy 3000 --d1=demo -- npm run dev",
"pages:deploy": "npm run build && wrangler pages deploy ./dist"export default defineEventHandler((event) => {
const db = event.context.DB
console.log('context ',db); // undefined
console.log('event.context',event.context) // object returned, no DB
var posts: Post[];
posts = [
{ id: 1, title: 'Post 1', body: 'This is the body of post 1' },
{ id: 2, title: 'Post 2', body: 'This is the body of post 2' },
{ id: 3, title: 'Post 3', body: 'This is the body of post 3' },
]
return posts; // I see the posts returned status code 200
})[[d1_databases]]
binding = "DB" # i.e. available in your Worker on env.DB
database_name = "demo"
database_id = "[guid]"
preview_database_id = "DB""pages:dev": "wrangler pages dev --compatibility-date=2024-02-08 --proxy 3000 --d1=demo -- npm run dev",
"pages:deploy": "npm run build && wrangler pages deploy ./dist"