From b9c5ac3ed643ac818cb5fc85cfb82c8d6ca51958 Mon Sep 17 00:00:00 2001 From: zviedris Date: Thu, 30 Jan 2025 04:41:04 +0200 Subject: [PATCH] fixed missing query files (#992) --- dashboard/final-example/app/query/route.ts | 26 ++++++++++++++++++++ dashboard/starter-example/app/query/route.ts | 26 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 dashboard/final-example/app/query/route.ts create mode 100644 dashboard/starter-example/app/query/route.ts diff --git a/dashboard/final-example/app/query/route.ts b/dashboard/final-example/app/query/route.ts new file mode 100644 index 0000000..453f3bf --- /dev/null +++ b/dashboard/final-example/app/query/route.ts @@ -0,0 +1,26 @@ +import postgres from 'postgres'; + +const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' }); + +async function listInvoices() { + const data = await sql` + SELECT invoices.amount, customers.name + FROM invoices + JOIN customers ON invoices.customer_id = customers.id + WHERE invoices.amount = 666; + `; + + return data; +} + +export async function GET() { + // return Response.json({ + // message: + // 'Uncomment this file and remove this line. You can delete this file when you are finished.', + // }); + try { + return Response.json(await listInvoices()); + } catch (error) { + return Response.json({ error }, { status: 500 }); + } +} diff --git a/dashboard/starter-example/app/query/route.ts b/dashboard/starter-example/app/query/route.ts new file mode 100644 index 0000000..0701b73 --- /dev/null +++ b/dashboard/starter-example/app/query/route.ts @@ -0,0 +1,26 @@ +// import postgres from 'postgres'; + +// const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' }); + +// async function listInvoices() { +// const data = await sql` +// SELECT invoices.amount, customers.name +// FROM invoices +// JOIN customers ON invoices.customer_id = customers.id +// WHERE invoices.amount = 666; +// `; + +// return data; +// } + +export async function GET() { + return Response.json({ + message: + 'Uncomment this file and remove this line. You can delete this file when you are finished.', + }); + // try { + // return Response.json(await listInvoices()); + // } catch (error) { + // return Response.json({ error }, { status: 500 }); + // } +}