mirror of
https://github.com/michivonah/nextjs.git
synced 2025-12-22 22:16:28 +01:00
setup db connection + implement data fetching on dashboard + add skeleton + docs
This commit is contained in:
parent
aea677e6f7
commit
00c39d3416
11 changed files with 259 additions and 67 deletions
|
|
@ -1,26 +1,22 @@
|
|||
// 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;
|
||||
// `;
|
||||
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;
|
||||
// }
|
||||
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 });
|
||||
// }
|
||||
try {
|
||||
return Response.json(await listInvoices());
|
||||
} catch (error) {
|
||||
return Response.json({ error }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue