Skip to content

Instantly share code, notes, and snippets.

@tostu
Created January 15, 2023 18:28
Show Gist options
  • Select an option

  • Save tostu/7fd2a4c50ba2e47cd93fc772626195aa to your computer and use it in GitHub Desktop.

Select an option

Save tostu/7fd2a4c50ba2e47cd93fc772626195aa to your computer and use it in GitHub Desktop.
Cloudflare pages d1 database query endpoint
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;
// 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