Next.js parse data-type from PostgreSQL

110 Views Asked by At

I'm new to Next.js and I am currently following the official tutorial. To spice it up, I decided to run PostgreSQL locally instead of using the @vercel/postgres SDK used in the tutorial. In the tutorial, they use the sql function of the SDK, which I have replaced by pool.query() from the node-postgres client. For most queries, this works fine and I am able to communicate with my local PostgreSQL database. However, I am having trouble adapting this code:

const data = await sql<Revenue>`SELECT * FROM revenue`;

What is it doing? From my understanding, <Revenue> is a type passed with the sql function, which I suppose is used to parse the data returned by @vercel/postgres.

How could I adapt my code to parse the <Revenue> data-type using node-postgres? Here is my current code:

const data = await pool.query(`SELECT * FROM revenue`);

For reference, here is the code I am trying to adapt (line 24 in data.ts). The <Revenue> type is defined in definitions.ts and the database content is in placeholder-data.js

Thank you for your help!

0

There are 0 best solutions below