Skip to content

Commit 7529b33

Browse files
committed
chore: add d1 db
1 parent b1afc26 commit 7529b33

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

functions/api/share.js

-15
This file was deleted.

functions/api/share.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export interface Env {
2+
// If you set another name in wrangler.toml as the value for 'binding',
3+
// replace "DB" with the variable name you defined.
4+
DB: D1Database
5+
}
6+
7+
export async function onRequest(context) {
8+
// If you did not use `DB` as your binding name, change it here
9+
const { results } = await context.env.DB.prepare(
10+
'SELECT * FROM Customers WHERE CompanyName = ?',
11+
)
12+
.bind('Bs Beverages')
13+
.all()
14+
15+
return Response.json(results)
16+
// console.log('json', await context.request.json())
17+
18+
// const data = {
19+
// hello: 'world',
20+
// }
21+
22+
// const json = JSON.stringify(data, null, 2)
23+
24+
// return new Response(json, {
25+
// headers: {
26+
// 'content-type': 'application/json;charset=UTF-8',
27+
// },
28+
// })
29+
}

wrangler.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[d1_databases]]
2+
binding = "DB"
3+
database_name = "prod-d1-play"
4+
database_id = "070c90e5-b671-4854-aaa7-b122c535b8c5"

0 commit comments

Comments
 (0)