mirror of
https://github.com/michivonah/nextjs.git
synced 2025-12-22 22:16:28 +01:00
22 lines
500 B
TypeScript
22 lines
500 B
TypeScript
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() {
|
|
try {
|
|
return Response.json(await listInvoices());
|
|
} catch (error) {
|
|
return Response.json({ error }, { status: 500 });
|
|
}
|
|
}
|