Open
Description
What is the documentation issue?
The error comes from the fetchRevenue() function located in the app/lib/data.ts file.
export async function fetchRevenue() {
try {
// Artificially delay a response for demo purposes.
// Don't do this in production :)
// console.log('Fetching revenue data...');
// await new Promise((resolve) => setTimeout(resolve, 3000));
const data = await sql<Revenue>`SELECT * FROM revenue`;
//console.log('Data fetch completed after 3 seconds.');
return data.rows;
} catch (error) {
console.error('Database Error:', error);
throw new Error('Failed to fetch revenue data.');
}
}
For the solution, I wanted to use the command we used in the database test before.
import { db } from "@vercel/postgres";
const client = await db.connect();
async function listInvoices() {
const data = await client.sql`
SELECT invoices.amount, customers.name
FROM invoices
JOIN customers ON invoices.customer_id = customers.id
WHERE invoices.amount = 666;
`;
return data.rows;
}
export async function GET() {
try {
return Response.json(await listInvoices());
} catch (error) {
return Response.json({ error }, { status: 500 });
}
}
And with my novice coding knowledge I wrote this and ran the graph but I didn't understand why the library(import { sql } from '@vercel/postgres';
) wasn't working
import { db } from "@vercel/postgres";
const testr = await db.connect();
export async function fetchRevenue() {
try {
const data = await testr.sql<Revenue>`
SELECT * FROM revenue
`;
return data.rows;
} catch (error) {
console.error('database error', error);
throw new Error('revenue datasını çekemedi')
}
}
Is there any context that might help us understand?
I think I'm missing something