next-learn
next-learn copied to clipboard
Chapter 7 - fetching data from the DB Error: Failed to fetch revenue data.
Solved by replacing:
import { sql } from '@vercel/postgres';
.
.
.
await sql< Revenue >
with
import { db } from '@vercel/postgres';
const client = await db.connect();
.
.
.
await client.sql< Revenue >
Solved this by replacing:
import { sql } from '@vercel/postgres'; await sql< Revenue >
with
import { db } from '@vercel/postgres'; const client = await db.connect(); await client.sql< Revenue >
This solution doesn't work for me.
My solution is replacing:
const data = await sql<Revenue>`SELECT * FROM revenue`;
with
const data = await sql.query<Revenue>('SELECT * FROM revenue');
Same problem, both solutions work for me.
Do these solutions work for neon and supabase or is there another?
You can switch to postgres which is an agnostic library which works with any Postgres database! We will likely update that here.
Do these solutions work for neon and supabase or is there another?
liuxiaohui's solution worked for me, using supabase
Solved this by replacing: import { sql } from '@vercel/postgres'; await sql< Revenue > with import { db } from '@vercel/postgres'; const client = await db.connect(); await client.sql< Revenue >
This solution doesn't work for me.
My solution is replacing:
const data = await sql<Revenue>`SELECT * FROM revenue`;with
const data = await sql.query<Revenue>('SELECT * FROM revenue');
perfect!
This worked just perfect https://github.com/vercel/next-learn/issues/943#issuecomment-2565387462
Glad to hear these solutions worked for you all!
TL;DR use 'NEON' DB instead of supabase or soemthing.
My case was solved without changed the code.
I installed "supabase" and it was the cause of problem. I deleted the supaabase db and installed neon and it wroks. Try this.
deepseek-r1 solved this for me :)
### **Diagnosis & Solution Summary**
The current `@vercel/[email protected]` is designed for integration with **Neon Serverless PostgreSQL**.
However, your error message indicates the use of a **Supabase host (`api.pooler.supabase.com`)**, meaning the **connection string is pointing to Supabase instead of Neon**, which is the core issue.
---
### 1. **Root Cause**
- **Mismatch Between Library and Connection Target**
- `@vercel/[email protected]` is built for **Neon**, but your environment variable (`DATABASE_URL`) is using a **Supabase connection string**.
- Result: The library attempts to connect to Supabase using the Neon driver (`@neondatabase/serverless`) → DNS error occurs.
---
### 2. **Solution**
#### (1) **Full Migration to Neon** [Recommended]
- **Use Vercel Postgres + Neon**
1. Create a **Neon Database** via the Vercel Dashboard and connect it.
2. Apply the auto-generated **Neon connection string** to your `.env` file:
```env
DATABASE_URL="postgres://user:pass@neon-host:5432/db?sslmode=require"
```
3. Continue using the `sql` helper in your code:
```ts
import { sql } from '@vercel/postgres';
await sql`...`;
```