#Running Vercel Postgres locally for development, pooled connection string

4 messages · Page 1 of 1 (latest)

candid island
#

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.

ocean forgeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
candid island
#

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>();