Can't connect to PostgreSQL db
Unanswered
Barbary Lion posted this in #help-forum
Barbary LionOP
Hi everyone. I try connect to PostgreSQL db but i get this error: "Error: Error connecting to database: fetch failed"
It occures in my data.ts file
My .env file
My package.json file
There is interesting moment that Prisma can connect to my PostgreSQL db and create table with data. But when i try to do the same with help @vercel/postgres it always fails. Why?
It occures in my data.ts file
import { sql } from '@vercel/postgres';
import { unstable_noStore as noStore } from 'next/cache';
export async function fetchAllProducts() {
noStore();
const data = await sql`SELECT * FROM product`;
return data.rows;
}My .env file
POSTGRES_URL="postgresql://postgres:password@localhost:5432/postgres"
POSTGRES_URL_NON_POOLING="postgresql://postgres:password@localhost:5432/postgres"
POSTGRES_PRISMA_URL="postgresql://postgres:password@localhost:5432/postgres"
POSTGRES_USER="postgres"
POSTGRES_HOST="localhost"
POSTGRES_PASSWORD="password"
POSTGRES_DATABASE="postgres"My package.json file
{
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@prisma/client": "^5.6.0",
"@vercel/postgres": "^0.5.1",
"next": "14.0.3",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.0.1",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"postcss": "^8",
"prisma": "^5.6.0",
"tailwindcss": "^3.3.0",
"typescript": "^5"
}
}There is interesting moment that Prisma can connect to my PostgreSQL db and create table with data. But when i try to do the same with help @vercel/postgres it always fails. Why?