Neon HTTP connection with existing neon driver
To connect using an existing neon driver instance: import { neon } from '@neondatabase/serverless'; import { drizzle } from 'drizzle-orm/neon-http'; const sql = neon(process.env.DATABASE_URL!); const db = drizzle({ client: sql });
Neon WebSockets driver for interactive transactions
The neon-websockets driver provides WebSocket-based connectivity and is a fully compatible drop-in replacement for the pg driver. If you need session or interactive transaction support, use the WebSocket-based neon-serverless driver.
Neon WebSockets connection without existing driver
To connect to Neon using WebSockets without providing an existing driver, import drizzle from 'drizzle-orm/neon-serverless', then instantiate with the DATABASE_URL environment variable: const db = drizzle(process.env.DATABASE_URL);
Install Drizzle with Neon serverless package
To use Drizzle with Neon, install drizzle-orm and @neondatabase/serverless packages, along with drizzle-kit as a dev dependency.
Neon WebSockets connection with existing pool in browser
To connect using an existing Pool instance in browser environments: import { Pool } from '@neondatabase/serverless'; import { drizzle } from 'drizzle-orm/neon-serverless'; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const db = drizzle({ client: pool });
Neon WebSockets configuration in Node.js
To use WebSockets in Node.js where the WebSocket global is not defined, install the 'ws' and 'bufferutil' packages, then configure: import { Pool, neonConfig } from '@neondatabase/serverless'; import { drizzle } from 'drizzle-orm/neon-serverless'; import ws from 'ws'; neonConfig.webSocketConstructor = ws; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); const db = drizzle({ client: pool });
Use postgres.js driver with Neon in serverful environments
To use Neon from a serverful environment, you can use the postgres.js driver. Install drizzle-orm and postgres packages, then import from 'drizzle-orm/postgres-js'.
postgres.js connection without existing driver
To connect to Neon using postgres.js without providing an existing driver, import drizzle from 'drizzle-orm/postgres-js', then instantiate with the DATABASE_URL environment variable: const db = drizzle(process.env.DATABASE_URL);
Neon HTTP driver for serverless environments
Drizzle has native support for Neon connections with the neon-http driver, which uses the neon-serverless driver under the hood. With neon-http, you can access a Neon database from serverless environments over HTTP. Querying over HTTP is faster for single, non-interactive transactions.
Netlify Database zero config connection
import { drizzle } from 'drizzle-orm/netlify-db';
// Connection string is set automatically by the platform
const db = drizzle();
const result = await db.execute('select 1');
Netlify Database dual runtime contexts
Netlify Database runs application code in two different contexts: serverless functions which use HTTP-based queries and have no persistent connections, and server mode which uses persistent connections via node-postgres.
Install packages for Netlify Database
To use Drizzle with Netlify Database, install drizzle-orm@rc, @netlify/database, and drizzle-kit@rc as a dev dependency.
Netlify Database native support in Drizzle
Drizzle has native support for Netlify Database connections that intelligently selects the optimal underlying Postgres driver based on the runtime environment.
Netlify Database connection string config
import { drizzle } from 'drizzle-orm/netlify-db';
const db = drizzle(process.env.DATABASE_URL);
const result = await db.execute('select 1');
Netlify Database explicit client config
import { drizzle } from 'drizzle-orm/netlify-db';
// Explicit client — consumer controls the driver
const db = drizzle({ client: netlifyDbClient });
const result = await db.execute('select 1');
PostgreSQL drivers and providers supported by Drizzle ORM
Drizzle ORM supports the following PostgreSQL drivers and providers: PostgreSQL (node-postgres), PlanetScale Postgres, Neon, Vercel Postgres, Prisma Postgres, Supabase, Xata, PGLite, Nile, Bun SQL, Effect Postgres, Netlify Database, AWS Data API Postgres, and Drizzle HTTP proxy.
Nile virtual tenant databases overview
Nile provides virtual tenant databases. When you set a tenant context, Nile directs queries to the virtual database for that tenant, and all queries apply only to that tenant's data.
Nile is PostgreSQL re-engineered for multi-tenant apps
Nile is a PostgreSQL database platform designed specifically for multi-tenant applications. It works with Drizzle through any of Drizzle's PostgreSQL drivers.
Nile packages to install with node-postgres
Install drizzle-orm@rc, pg, and drizzle-kit@rc to use Drizzle with Nile using the node-postgres driver.
Basic Nile connection with node-postgres
To initialize Drizzle with Nile using the node-postgres driver, import drizzle from 'drizzle-orm/node-postgres' and pass the NILEDB_URL environment variable or a Pool instance.
Nile connection with existing Pool instance
You can provide your own node-postgres Pool instance to Drizzle's drizzle function with a client property.
Set Nile tenant context with SQL command
To set the tenant context in Nile, execute the SQL command 'set local nile.tenant_id' with the tenant ID within a transaction.
Wrapper function for Nile tenant queries
A tenantDB wrapper function takes a tenant ID and a callback, wraps the callback in a Drizzle transaction, and executes 'set local nile.tenant_id' before running the query so all queries within the callback only access that tenant's data.
Using AsyncLocalStorage for Nile tenant context
You can use Node.js AsyncLocalStorage to store the tenant ID and avoid passing it explicitly to each query. Create an AsyncLocalStorage instance and use middleware to populate it with the tenant ID from the request.
AsyncLocalStorage setup for Nile tenant context
Import AsyncLocalStorage from 'async_hooks' and create an instance to store the tenant context. The tenantDB wrapper retrieves the tenant ID from AsyncLocalStorage and sets it in the transaction.
Middleware to populate Nile tenant context
In a web framework, use middleware to extract the tenant ID from the request (path parameters or headers) and store it in AsyncLocalStorage using the run method.
PGlite can run as ephemeral in-memory or with persistence
PGlite can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun) or indexedDB (Browser).
PGlite is a WASM Postgres build for browsers and Node.js
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 2.6mb gzipped. Unlike previous 'Postgres in the browser' projects, PGlite does not use a Linux virtual machine—it is simply Postgres in WASM.
Initialize Drizzle with an existing PGlite client instance
To use an existing PGlite driver instance, import PGlite from '@electric-sql/pglite' and drizzle from 'drizzle-orm/pglite', create a PGlite client, then pass it to drizzle: const client = new PGlite(); const db = drizzle({ client });
Initialize Drizzle with PGlite using native configuration
To create a PGlite database with native PGlite configuration options, import drizzle from 'drizzle-orm/pglite' and pass an object with a connection property containing PGlite configuration: const db = drizzle({ connection: { dataDir: 'path-to-dir' } });
Initialize Drizzle with PGlite for file system persistence
To create a PGlite database with file system persistence in Node.js or Bun, import drizzle from 'drizzle-orm/pglite' and call drizzle with a path string: const db = drizzle('path-to-dir');
Initialize Drizzle with PGlite for in-memory database
To create an in-memory PGlite database with Drizzle, import drizzle from 'drizzle-orm/pglite' and call drizzle() with no arguments: const db = drizzle();
Install Drizzle with PGlite driver
Install drizzle-orm@rc and @electric-sql/pglite as dependencies, and drizzle-kit@rc as a development dependency.
Prisma Postgres serverless driver future support
Prisma Postgres has a serverless driver that will be supported with Drizzle ORM in the future but is not currently supported.
Prisma Postgres serverless database overview
Prisma Postgres is a serverless database built on unikernels. It features a large free tier, operation-based pricing, and has no cold starts.
Prisma Postgres supported drivers
You can connect to Prisma Postgres using either the node-postgres (pg) or postgres.js drivers for PostgreSQL.
Connect to Prisma Postgres with postgres.js
To connect to Prisma Postgres using postgres.js, install drizzle-orm@rc and postgres, then initialize the connection: import { drizzle } from 'drizzle-orm/postgres-js'; import postgres from 'postgres'; const queryClient = postgres(process.env.DATABASE_URL); const db = drizzle({ client: queryClient }); const result = await db.execute('select 1');
Drizzle postgres-js driver initialization with Supabase
Initialize Drizzle with the postgres-js driver for Supabase by importing from 'drizzle-orm/postgres-js', then call drizzle(process.env.DATABASE_URL) or pass an existing postgres client to drizzle({ client }).
Supabase + Drizzle installation
To use Drizzle with Supabase, install drizzle-orm@rc, postgres, and drizzle-kit@rc as a dev dependency using npm.
Supabase definition
Supabase is an open source Firebase alternative for building secure and performant Postgres backends with minimal configuration.
Supabase connection types for different environments
Use the Connection Pooler for serverless environments and the Direct Connection for long-running servers when connecting to Supabase.
Supabase Transaction pool mode requires prepare: false
When using Supabase connection pooling with Transaction pool mode enabled, prepared statements are not supported. Disable prepare by passing { prepare: false } to the postgres client initialization: postgres(process.env.DATABASE_URL, { prepare: false }).
Vercel Postgres setup requires drizzle-orm and @vercel/postgres packages
To use Vercel Postgres with Drizzle, install drizzle-orm and @vercel/postgres as dependencies, and drizzle-kit as a development dependency.
Drizzle supports Vercel Postgres with postgres or pg drivers
Drizzle ORM supports accessing Vercel Postgres through the postgres or pg drivers using a postgresql:// connection string.
Initialize Vercel Postgres driver without arguments
To initialize the Vercel Postgres driver in Drizzle without providing an existing driver, import drizzle from drizzle-orm/vercel-postgres and call drizzle() with no arguments. Example: import { drizzle } from 'drizzle-orm/vercel-postgres'; const db = drizzle();
Initialize Vercel Postgres driver with existing @vercel/postgres client
To initialize the Vercel Postgres driver with an existing @vercel/postgres client, pass the client object in the options. Example: import { sql } from '@vercel/postgres'; import { drizzle } from 'drizzle-orm/vercel-postgres'; const db = drizzle({ client: sql });
Vercel Postgres is a serverless SQL database
Vercel Postgres is a serverless SQL database designed to integrate with Vercel Functions.
@vercel/postgres works in serverless environments without TCP
The @vercel/postgres package can be used to access Vercel Postgres from serverless environments that do not have TCP available, such as Cloudflare Workers, by connecting through websockets.
Vercel Postgres can be accessed from serverful environments
From serverful environments, Vercel Postgres can be accessed either with the @vercel/postgres package or directly through a postgresql:// connection string using postgres or pg drivers.
Drizzle supports Vercel Postgres with @vercel/postgres driver
Drizzle ORM natively supports the @vercel/postgres serverless driver through the drizzle-orm/vercel-postgres package.
Xata connection with existing postgres-js client
When using an existing postgres-js client with Xata, create the client with postgres(process.env.DATABASE_URL), then pass it to drizzle in an object: import postgres from 'postgres'; const client = postgres(process.env.DATABASE_URL); const db = drizzle({ client }); const allUsers = await db.select().from(...);
Xata PostgreSQL platform overview
Xata is a PostgreSQL database platform designed to help developers operate and scale databases. It provides features including instant copy-on-write database branches, zero-downtime schema changes, data anonymization, AI-powered performance monitoring, and BYOC (Bring Your Own Cloud).
Connect to Xata with postgres-js driver
To connect to Xata using Drizzle with the postgres-js driver, import drizzle from 'drizzle-orm/postgres-js', pass process.env.DATABASE_URL to drizzle(), and execute queries. Example: import { drizzle } from 'drizzle-orm/postgres-js'; const db = drizzle(process.env.DATABASE_URL); const allUsers = await db.select().from(...);
Xata Drizzle packages to install
Install drizzle-orm@rc and postgres as dependencies, and drizzle-kit@rc as a dev dependency for Xata integration with Drizzle.
drizzle.config.ts minimal configuration
A minimal drizzle-kit configuration file requires three properties: dialect set to "postgresql", schema pointing to the schema file or folder path, and out defining the output folder for migrations. The configuration is exported from defineConfig function imported from drizzle-kit.
dialect configuration option
The dialect option specifies the database type being used. For PostgreSQL, set dialect to "postgresql". This is a required option with no default value. It is used by commands: generate, push, pull, studio, migrate, up, and export.
schema configuration option
The schema option accepts a glob-based path as a string or array of strings pointing to drizzle schema file(s) or folder(s) containing schema files. Type is string or string[]. It has no default value and is used by commands: generate, push, export, and studio.
out configuration option
The out option defines the output folder for SQL migration files, JSON schema snapshots, and schema.ts files generated from drizzle-kit pull command. Type is string or string[]. Default value is "drizzle". It is used by commands: generate, pull, migrate, check, and up.
driver configuration option
The driver option explicitly specifies which database driver to use. Drizzle Kit automatically picks available drivers based on dialect, but some vendor-specific databases require different connection parameters. Accepted values are "aws-data-api" and "pglite". It has no default value and is used by commands: push, migrate, pull, and studio.
PGLite driver configuration
When using driver: "pglite" with PostgreSQL, dbCredentials requires a url property that can be either ":memory:" for in-memory database or a folder path string like "./database/" for persistent database storage.