-
Notifications
You must be signed in to change notification settings - Fork 73
Description
NOTE FROM MAINTAINERS
The way to use @vercel/postgres locally is documented here: https://vercel.com/docs/storage/vercel-postgres/local-development
I thought I could use Vercel Postgres with a local DB for offline development with a custom connection string that points to a local DB...
import { createPool, sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';
export const db = drizzle(
process.env.NODE_ENV === 'production'
? sql
: createPool({
connectionString: process.env.POSTGRES_URL,
}),
{ logger: true }
);
...but this doesn't work:
[VercelPostgresError]: VercelPostgresError - 'invalid_connection_string': This connection string is meant to be used with a direct connection. Make sure to use a pooled connection string or try `createClient()` instead.
The initial issue seems to be that the error is triggered if you don't provide a pooled URL, and that check is hardcoded for the presence of -pooler.
in the connection string, due to the URLs Vercel uses:
export function isPooledConnectionString(connectionString: string): boolean {
return connectionString.includes('-pooler.');
}
If I try and bypass this with a local URL like 'postgresql://jschuur:@localhost:5432/learnchineseclub?foo=-pooler.'
then I get a new error:
The database host is 'localhost', which is the default host when none is set. If that's intentional, please ignore this warning. If not, perhaps an environment variable has not been set, or has not been passed to the library?
- error uncaughtException: Error: connect ECONNREFUSED ::1:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
digest: undefined
}
Is it currently possible to do local development without using a cloud hosted Vercel Postgres DB in both locations this way? Considering the 1 database limit on the free tier (and low other limits), this makes development rather difficult.