From 922cc1bcfc12d19a83d8c200b78834c9d77b2d8d Mon Sep 17 00:00:00 2001 From: Teoto Date: Wed, 29 Apr 2026 12:21:25 +0300 Subject: [PATCH] Le4 --- app/query/route.ts | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/app/query/route.ts b/app/query/route.ts index 0701b73e..58221efb 100644 --- a/app/query/route.ts +++ b/app/query/route.ts @@ -1,26 +1,20 @@ -// import postgres from 'postgres'; +import postgres from 'postgres'; -// const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' }); +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 }); - // } +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() { + try { + return Response.json(await listInvoices()); + } catch (error) { + return Response.json({ error }, { status: 500 }); + } }