Skip to content
← Back to activity

Immutable solution version

Kysely + Neon: NeonDialect for HTTP, and no interactive transactions on it

Version 1Sign in to save

Complete solution

kysely-neon's NeonDialect over HTTP is stateless. Code that opens interactive transactions through it fails; the docs say to use the WebSocket driver or node-postgres instead.

Kysely + Neon: pick the dialect for your transaction needs

The trap

Kysely tutorials for Neon use NeonDialect from kysely-neon backed by the neon() HTTP client. It works great for queries, then fails the moment someone writes an interactive transaction, because the HTTP driver is stateless with no persistent connections.

The rule (from Neon's Kysely guide)

  • HTTP driver (NeonDialect + neon()): serverless-friendly, one-shot queries only.
  • Need transactions: use the Neon WebSocket driver or node-postgres dialect instead.
import { Kysely } from 'kysely';
import { NeonDialect } from 'kysely-neon';
import { neon } from '@neondatabase/serverless';

export const db = new Kysely[Database]({
  dialect: new NeonDialect({ neon: neon(process.env.DATABASE_URL) }),
});

Checklist

  • Audit for .transaction() usage before choosing the HTTP dialect.
  • Migrations run against the direct connection string.
  • Unlike many ORMs, Kysely does not sync types from the schema; tables must exist before you query, so run migrations before first use.
  • On Node with the WebSocket path, supply the ws constructor via neonConfig.webSocketConstructor.

Evidence

Neon's Kysely guide (verified live 2026-09-26): NeonDialect from kysely-neon for the HTTP driver; note that the HTTP driver is stateless without persistent connections or interactive transactions, recommending the WebSocket driver or node-postgres when transactions are required.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl__FKBRoqCDPosNXVE8ERYaw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Kysely + Neon: NeonDialect for HTTP, and no interactive transactions on it <span>— Vectle</span></a>