Run database queries from runtimes that use HTTP rather than TCP.
Edge or serverless application
Neon · Const
Drizzle integrates with Neon by using Neon's serverless driver as Drizzle's database backend. In serverless applications, create a client with @neondatabase/serverless and pass it to Drizzle's Neon HTTP adapter.
Drizzle connects to Neon through the @neondatabase/serverless driver. For serverless runtimes, create a Neon SQL client from DATABASE_URL, then provide it to Drizzle through drizzle-orm/neon-http; the resulting client exposes Drizzle's typed query API.
const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);| Name | Type | Description |
|---|---|---|
DATABASE_URL | string | Neon database connection string supplied through the DATABASE_URL environment variable. |
A Drizzle database client configured to issue queries through Neon's serverless driver.
drizzle-orm/neon-http when using the serverless HTTP client.DATABASE_URL environment variable before initializing Drizzle.drizzle.import 'dotenv/config';
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);
const result = await db.select().from(users);
console.log(result);Creates a Neon serverless SQL client and passes it to Drizzle's Neon HTTP adapter for a query.
Edge or serverless application
TypeScript application
Application with schema changes
Use neon from @neondatabase/serverless to create a SQL client from DATABASE_URL, then pass that client to drizzle imported from drizzle-orm/neon-http. This gives the application a Drizzle client backed by Neon's HTTP driver.
Follow-up: Which runtime constraint motivates this adapter? Runtimes such as edge functions may not support opening TCP sockets, so the HTTP-based serverless driver is appropriate.
Install drizzle-orm and @neondatabase/serverless; install drizzle-kit separately when migrations are needed. The connection string is supplied through the DATABASE_URL environment variable.
Follow-up: Why keep Drizzle Kit separate? It is the development CLI used for schema and migration workflows, rather than the runtime query client.
The guide presents several driver choices: Neon serverless HTTP, Neon WebSocket, node-postgres, and postgres.js. Select the driver according to the application's runtime and connection requirements.
Follow-up: What is the key alternative for an environment needing WebSockets? Install the WebSocket support and configure Drizzle with the corresponding Neon WebSocket integration.
@neondatabase/serverlessdrizzle-orm/neon-httpdrizzle-kitNeon WebSocket drivernode-postgrespostgres.js