Next.js Discord

Discord Forum

Running Vercel Postgres locally for development, pooled connection string

Unanswered
Bonga shad posted this in #help-forum
Open in Discord
Bonga shadOP
I'm trying out PostgreSQL from Vercel and want to run Postgres also locally for development purposes.
As ORM I'm using Kysely.
Running locally results in the following message though:

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.


How can I get a pooled connection string for my local Postgres?
I also tried createClient() but not sure how to use it.

Any help is appreciated.

3 Replies

Bonga shadOP
Now I'm doing this:
import { createKysely } from '@vercel/postgres-kysely';
import { Kysely, PostgresDialect } from 'kysely';
import { Pool } from 'pg';

import { Database } from './types';

function createLocalKysely<DB>() {
  const pool = new Pool({
    database: process.env.POSTGRES_DATABASE,
    host: process.env.POSTGRES_HOST,
    user: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_PASSWORD,
    port: process.env.POSTGRES_PORT
      ? Number.parseInt(process.env.POSTGRES_PORT)
      : 5432,
  });

  const dialect = new PostgresDialect({
    pool,
  });

  return new Kysely<DB>({
    dialect,
  });
}

export const db =
  process.env.NODE_ENV === 'development'
    ? createLocalKysely<Database>()
    : createKysely<Database>();
Any simpler approaches?