Connecting to Vercel Postgres

I'm trying to connect to Vercel Postgres like this:
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";

export const db = drizzle(sql, { logger: true });
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";

export const db = drizzle(sql, { logger: true });
But I'm getting this error: n [VercelPostgresError]: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found. It seems like there's no credentials passing here and this sql thing should read the connection string from .env file which you need to pull from Vercel? Am I doing something wrong or is the Vercel + Drizzle ORM mix not supported in dev environment yet?
4 Replies
Andrii Sherman
This error comes from Vercel and not drizzle Seems like you didn’t specify url for vercel Postgres
joostschuur
joostschuur2y ago
Could it be trying to use POSTGRES_URL_NON_POOLING? I know it says POSTGRES_URL. Before I hacked my implementation to use a local DB for local dev, I was successfully using the Vercel Postgres DB locally. I ran vercel env pull .env.development.local and it grabbed a bunch of env secrets.
makaron pelnoziarnisty
Okay, I've just found the solution. I'm using SvelteKit which uses Vite and apparently Vite does not expose .env variables on process.env by default. Here's the solution: https://github.com/vercel/storage/tree/main/packages/postgres#a-note-for-vite-users
GitHub
storage/packages/postgres at main · vercel/storage
Vercel Postgres, KV, Blob, and Edge Config . Contribute to vercel/storage development by creating an account on GitHub.
makaron pelnoziarnisty
I managed to make it work 👍
Want results from more Discord servers?
Add your server