© 2026 Hedgehog Software, LLC
npx wrangler pages dev .svelte-kit/cloudflare
npx wrangler pages deploy .svelte-kit/cloudflare --project-name sveltekit-d1 --branch main
src/routes/api/customers/+server.ts
import type { RequestHandler } from '@sveltejs/kit'; export const GET: RequestHandler = async ({request, platform}) => { let log: string[] = [] try { const d1Db = await platform.env.D1_DB log.push("d1 db ok") const stmt = await d1Db.prepare( "SELECT * FROM Customers LIMIT 5" ) log.push("stmt ok") const { results } = await stmt.all(); log.push("results ok") return new Response(JSON.stringify({ status: 200, data: results, log: log })); } catch (e) { return new Response(JSON.stringify({ status: 500, log: log, error: e })); } };
{"status":200,"data":[{"CustomerId":1,"CompanyName":"Alfreds Futterkiste","ContactName":"Maria Anders"},{"CustomerId":4,"CompanyName":"Around the Horn","ContactName":"Thomas Hardy"},{"CustomerId":11,"CompanyName":"Bs Beverages","ContactName":"Victoria Ashworth"},{"CustomerId":13,"CompanyName":"Bs Beverages","ContactName":"Random Name"}],"log":["d1 db ok","stmt ok","results ok"]}
{"status":500,"log":["d1 db ok"],"error":{}}