mirror of
https://github.com/vercel/next-learn.git
synced 2026-06-11 09:51:47 +00:00
fixed missing query files (#992)
This commit is contained in:
26
dashboard/final-example/app/query/route.ts
Normal file
26
dashboard/final-example/app/query/route.ts
Normal file
@@ -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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
26
dashboard/starter-example/app/query/route.ts
Normal file
26
dashboard/starter-example/app/query/route.ts
Normal file
@@ -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 });
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user