---
id: 'drizzle'
title: 'Connect to Postgres with Drizzle'
description: 'Install Drizzle ORM, define your tables as TypeScript models, and connect to your Supabase Postgres database through the connection pooler with Postgres.js.'
breadcrumb: 'ORM Quickstarts'
hideToc: true
---
## Connecting with Drizzle
[Drizzle ORM](https://github.com/drizzle-team/drizzle-orm) is a TypeScript ORM for SQL databases designed with maximum type safety in mind. You can use their ORM to connect to your database.
If you plan on solely using Drizzle instead of the Supabase Data API (PostgREST), you can turn off the latter in the [API Settings](/dashboard/project/_/settings/api).
Install Drizzle and related dependencies.
```shell
npm i drizzle-orm postgres
npm i -D drizzle-kit
```
Create a `schema.ts` file and define your models.
```ts schema.ts
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
export const users = pgTable('users', {
id: serial('id').primaryKey(),
fullName: text('full_name'),
phone: varchar('phone', { length: 256 }),
});
```
Connect to your database using the connection pooler.
From the project [**Connect** panel](/dashboard/project/_?showConnect=true&connectTab=direct&method=transaction), copy the **Transaction pooler** URI and save it as the `DATABASE_URL` environment variable. Replace the password placeholder with your database password.
In a local Edge Function, the `db.ts` sample swaps the `supabase_db_` host for `db`, which Postgres.js can resolve. See [Reach the local Supabase services](/docs/guides/functions/development-environment#reach-the-local-supabase-services).
```ts db.ts
import 'dotenv/config'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
const databaseUrl = process.env.DATABASE_URL
if (!databaseUrl) throw new Error('DATABASE_URL is not set')
let connectionString = databaseUrl
if (connectionString.includes('postgres:postgres@supabase_db_')) {
const url = new URL(connectionString)
url.hostname = url.hostname.split('_')[1]
connectionString = url.href
}
// Disable prepared statements, which the transaction pooler doesn't support
export const client = postgres(connectionString, { prepare: false })
export const db = drizzle(client)
```
## Related resources
- [Build a TanStack and Drizzle app with Postgres Database](/kb/guides/setup-drizzle-with-postgres-and-tanstack-start)