Get started
Overview PostgreSQL Manage schema
Overview Column types Indexes & Constraints Migrations Views Schemas Access your data
Query Select Insert Update Delete Filters Joins Magic sql`` operator Performance
Queries Serverless Advanced
Set Operations Transactions Batch Dynamic query building Read Replicas Custom types Goodies Extensions
ESLint Plugin drizzle-zod drizzle-typebox drizzle-valibot According to their official website, Neon database is a multi-cloud fully managed Postgres.
Drizzle ORM natively supports both Neon Serverless
driver with drizzle-orm/neon-serverless
package and postgres
or pg
drivers to access Neon database, as per the Neon nodejs docs.
npm
yarn
pnpm
bun
npm i drizzle-orm @neondatabase/serverless
npm i -D drizzle-kit
yarn add drizzle-orm @neondatabase/serverless
yarn add -D drizzle-kit
pnpm add drizzle-orm @neondatabase/serverless
pnpm add -D drizzle-kit
bun add drizzle-orm @neondatabase/serverless
bun add -D drizzle-kit
With Neon Serverless package [github, blog post] you can access Neon database from serverless environments with no TCP available β like Cloudflare Workers β through websockets.
HTTP
WebSockets
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
neonConfig.fetchConnectionCache = true;
const sql = neon(process.env.DRIZZLE_DATABASE_URL!);
const db = drizzle(sql);
const result = await db.select().from(...);
Below is the example of using Drizzle ORM with Neon Serverless driver in Cloudflare Worker, for extensive example β see here.
import { Pool } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-serverless';
export default {
async fetch(req, env, ctx) {
const pool = new Pool({ connectionString: env.DATABASE_URL });
const db = drizzle(pool)
const result = await db.select().from(...);
ctx.waitUntil(pool.end());
return new Response(now);
}
}
If youβre unsure how to use Neon from a serverfull environments, you should just use PostgresJS driver according to their official nodejs docs β see docs.