VibORM

Neon HTTP

Serverless PostgreSQL driver for Neon

Installation

pnpm add @neondatabase/serverless

Configuration

import { createClient } from "viborm/drivers/neon-http";

const client = createClient({
  databaseUrl: process.env.DATABASE_URL,
  schema,
});

Options

OptionTypeDescription
databaseUrlstringPostgreSQL connection URL
options.fetchOptionsRequestInitCustom fetch options
options.arrayModebooleanReturn rows as arrays
options.fullResultsbooleanReturn full result metadata
pgvectorbooleanEnable pgvector support
postgisbooleanEnable PostGIS support

With pgvector

import { createClient } from "viborm/drivers/neon-http";

const client = createClient({
  databaseUrl: process.env.DATABASE_URL,
  pgvector: true,
  schema,
});

Serverless Usage

Neon HTTP is optimized for serverless/edge environments:

// Vercel Edge, Cloudflare Workers, etc.
export default async function handler(request: Request) {
  const client = createClient({
    databaseUrl: process.env.DATABASE_URL,
    schema,
  });

  const users = await client.user.findMany();
  return Response.json(users);
}

Transactions & Batching

Neon HTTP does not support traditional dynamic transactions (each HTTP request is a separate connection), but VibORM provides full support for batch mode using Neon's transaction() function.

Use the array API for atomic operations - VibORM uses Neon's transaction() function under the hood:

// Atomic execution using Neon's transaction() function
const [user, post] = await client.$transaction([
  client.user.create({ data: { name: "Alice", email: "alice@example.com" } }),
  client.post.create({ data: { title: "Hello", authorId: "preset-id" } }),
]);

Dynamic Transactions

Dynamic transactions (callback API) will execute sequentially with a warning:

// Warning: Operations execute without isolation on Neon HTTP
await client.$transaction(async (tx) => {
  const user = await tx.user.create({ data: { name: "Alice" } });
  await tx.post.create({ data: { title: "Hello", authorId: user.id } });
});

For Neon HTTP, prefer batch mode ($transaction([...])) over callback mode when operations are independent. Batch mode provides atomicity through Neon's transaction() function.

Migrations

Migrations run atomically on Neon HTTP using the transaction() function - all statements succeed or none are applied.

Capabilities

FeatureSupport
Dynamic transactionsSequential with warning
Batch modeFull (transaction() function)
Migration atomicityFull

Limitations

  • No transaction isolation - Other connections may see intermediate state
  • No read-your-writes in batch - Operations must be independent
  • HTTP-based: slightly higher latency than traditional connections
  • Best suited for serverless environments with simple queries
  • For full transaction support, use @neondatabase/serverless Pool with WebSockets

On this page