Created
January 15, 2023 18:28
-
-
Save tostu/7fd2a4c50ba2e47cd93fc772626195aa to your computer and use it in GitHub Desktop.
Cloudflare pages d1 database query endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { RequestHandler } from '@sveltejs/kit'; | |
| export const GET = (async ({ platform }) => { | |
| const ps = platform.env.db.prepare('SELECT * from test'); | |
| const data = await ps.first(); | |
| return new Response(data) | |
| }) satisfies RequestHandler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // See https://kit.svelte.dev/docs/types#app | |
| // for information about these interfaces | |
| // and what to do when importing types | |
| /// <reference types="@sveltejs/kit" /> | |
| /// <reference types="@sveltejs/adapter-cloudflare" /> | |
| declare global { | |
| namespace App { | |
| // interface Error {} | |
| // interface Locals {} | |
| // interface PageData {} | |
| // interface Platform {} | |
| interface Platform { | |
| env?: { | |
| db: D1Database; | |
| }; | |
| context: { | |
| waitUntil(promise: Promise<any>): void; | |
| }; | |
| caches: CacheStorage & { default: Cache } | |
| } | |
| } | |
| } | |
| export {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment