Drizzle <> Xata

This guide assumes familiarity with:

Xata is a PostgreSQL database platform designed to help developers operate and scale databases with enhanced productivity and performance. Xata provides features like instant copy-on-write database branches, zero-downtime schema changes, data anonymization, AI-powered performance monitoring, and BYOC.

Checkout official Xata + Drizzle docs.

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i drizzle-orm postgres
npm i -D drizzle-kit

Step 2 - Initialize the driver and make a query

index.ts
import { drizzle } from 'drizzle-orm/postgres-js'

const db = drizzle(process.env.DATABASE_URL);

const allUsers = await db.select().from(...);

If you need to provide your existing driver:

index.ts
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

const client = postgres(process.env.DATABASE_URL)
const db = drizzle({ client });

const allUsers = await db.select().from(...);

What’s next?