27 | throw new Error(‘Failed to fetch revenue data.’);
// Database has all tables and sample data. RLS is disabled.
// Googled and found similar errors but not this one. :=(
// Thanks for you time and interest.
First, let’s check the implementation of the fetchRevenue function. It should be located in the @/app/lib/data.ts file. Can you please confirm that the function looks similar to this?
export async function fetchRevenue() {
try {
// SQL query to fetch revenue data
const data = await sql<Revenue>`SELECT * FROM revenue`;
return data.rows;
} catch (error) {
console.error('Database Error:', error);
throw new Error('Failed to fetch revenue data.');
}
}
If this is correct, the error you’re seeing suggests that there’s an issue with the database connection or the SQL query execution. Here are a few things we can check:
Database Connection: is it correctly set up in your environment variables?
SQL Query: Make sure the ‘revenue’ table exists in your database and has the correct structure.
Error Handling: Let’s modify the error handling to get more information about what’s going wrong.
Hello!
I have the same problem while going through the tutorial.
I compared two approaches:
Using @vercel/postgres (attached a screenshot)
Using postgres (attached a screenshot)
In the first case, that is, when using @vercel/postgres, an error 500 is issued (attached a screenshot)
In the second case, that is, when using postgres, data is retrieved from the database without problems (attached a screenshot)
That is, the problem is really on the side of @vercel/postgres, and not on the side of the database.
Please help me figure out this problem.
I would like to use import { sql } from ‘@vercel/postgres’;.
And does @vercel/postgres really allow you to protect the site from SQL injections? If so, then I would really, really like you to help with the problem described above.