Drizzle <> Prisma Postgres

This guide assumes familiarity with:

Prisma Postgres๋Š” ์œ ๋‹ˆ์ปค๋„๋กœ ๊ตฌ์ถ•๋œ ์„œ๋ฒ„๋ฆฌ์Šค ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์ž…๋‹ˆ๋‹ค. ๋„‰๋„‰ํ•œ ๋ฌด๋ฃŒ ํ‹ฐ์–ด, ์ž‘์—… ๊ธฐ๋ฐ˜ ๊ฐ€๊ฒฉ ์ฑ…์ • ๋ฐ ์ฝœ๋“œ ์Šคํƒ€ํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

PostgreSQL์šฉ node-postgres ๋˜๋Š” postgres.js ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Prisma Postgres์—๋Š” ํ–ฅํ›„ Drizzle ORM์—์„œ ์ง€์›ํ•  ์„œ๋ฒ„๋ฆฌ์Šค ๋“œ๋ผ์ด๋ฒ„๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

1๋‹จ๊ณ„ - ํŒจํ‚ค์ง€ ์„ค์น˜

node-postgres (pg)
postgres.js
npm
yarn
pnpm
bun
npm i drizzle-orm pg
npm i -D drizzle-kit

2๋‹จ๊ณ„ - ๋“œ๋ผ์ด๋ฒ„ ์ดˆ๊ธฐํ™” ๋ฐ ์ฟผ๋ฆฌ ์‹คํ–‰

node-postgres (pg)
postgres.js
// 'pg' ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค
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 });

const result = await db.execute('select 1');

๋‹ค์Œ ๋‹จ๊ณ„