Drizzle ORM
Drizzle ORM is a TypeScript ORM. In this guide, you'll learn how to connect Drizzle ORM to Prisma Postgres.
- Node.js version 16 or higher
- TypeScript version 5.0 or higher
Create a new directory for your project and initialize it with npm:
mkdir drizzle-quickstart
cd drizzle-quickstart
bun initmkdir drizzle-quickstart
cd drizzle-quickstart
pnpm initmkdir drizzle-quickstart
cd drizzle-quickstart
yarn initmkdir drizzle-quickstart
cd drizzle-quickstart
npm initInstall TypeScript and initialize it:
bun add --dev typescriptpnpm add --save-dev typescriptyarn add --dev typescriptnpm install --save-dev typescriptbunx tsc --initpnpm tsc --inityarn tsc --initnpx tsc --initIn your package.json, set the type to module:
{
// ...
"type": "module"
// ...
}Create a Prisma Postgres database with the create-db CLI tool:
bunx create-dbpnpm dlx create-dbyarn dlx create-dbnpx create-dbThen the CLI tool should output:
┌ 🚀 Creating a Prisma Postgres database
│
│ Provisioning a temporary database in us-east-1...
│
│ It will be automatically deleted in 24 hours, but you can claim it.
│
◇ Database created successfully!
│
│
● Database Connection
│
│
│ Connection String:
│
│ postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require
│
│
◆ Claim Your Database
│
│ Keep your database for free:
│
│ https://create-db.prisma.io/claim?CLAIM_CODE
│
│ Database will be deleted on 11/18/2025, 1:55:39 AM if not claimed.
│
└Create a .env file and add the connection string from the output:
DATABASE_URL="postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require"The database created is temporary and will be deleted in 24 hours unless claimed. Claiming moves the database into your Prisma Data Platform account. Visit the claim URL from the output to keep your database.
Install Drizzle ORM and the PostgreSQL driver:
bun add drizzle-orm pg dotenvpnpm add drizzle-orm pg dotenvyarn add drizzle-orm pg dotenvnpm install drizzle-orm pg dotenvbun add --dev drizzle-kit @types/pg tsxpnpm add --save-dev drizzle-kit @types/pg tsxyarn add --dev drizzle-kit @types/pg tsxnpm install --save-dev drizzle-kit @types/pg tsxPackage breakdown:
drizzle-orm: The lightweight TypeScript ORMpg: PostgreSQL driver for Node.jsdotenv: Loads environment variables from.envfiledrizzle-kit: CLI tool for migrations and schema management@types/pg: TypeScript type definitions for the pg drivertsx: TypeScript execution engine for running.tsfiles directly
Create a src/script.ts file:
import "dotenv/config";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
const db = drizzle({ client: pool });
async function main() {
const result = await db.execute("select 1");
console.log("Query result:", result);
}
main()
.then(async () => {
await pool.end();
console.log("Connection closed");
})
.catch(async (error) => {
console.error("Error:", error);
await pool.end();
process.exit(1);
});Run the script:
bunx tsx src/script.tspnpm dlx tsx src/script.tsyarn dlx tsx src/script.tsnpx tsx src/script.tsYou should receive output similar to:
Query result: Result {
command: 'SELECT',
rowCount: 1,
oid: null,
rows: [ { '?column?': 1 } ],
fields: [
Field {
name: '?column?',
tableID: 0,
columnID: 0,
dataTypeID: 23,
dataTypeSize: 4,
dataTypeModifier: -1,
format: 'text'
}
],
_parsers: [ [Function: parseInteger] ],
_types: { getTypeParser: [Function: getTypeParser] },
RowCtor: null,
rowAsArray: false,
_prebuiltEmptyResultObject: { '?column?': null }
}
Connection closedDrizzle ORM is now connected to Prisma Postgres. For schemas, migrations, and queries, see the Drizzle ORM documentation.