Drizzle <> PostgreSQL
Drizzle은 node-postgres와 postgres.js 드라이버를 사용한 PostgreSQL 연결을 네이티브로 지원합니다.
두 드라이버를 사용하고 Drizzle ORM과 통합하면서 발견한 node-postgres와 postgres.js 간의 몇 가지 차이점이 있습니다. 예를 들어:
node-postgres에서는pg-native를 설치하여node-postgres와 Drizzle의 속도를 약 10% 향상시킬 수 있습니다.node-postgres는 전역 패치 없이 쿼리별로 타입 파서를 제공할 수 있습니다. 자세한 내용은 타입 문서를 참조하세요.postgres.js는 기본적으로 prepared statements를 사용하므로 이를 비활성화해야 할 수 있습니다. 이는 AWS 환경 등에서 잠재적인 문제가 될 수 있으므로 유의하시기 바랍니다.- 추가로 기여하고 싶은 내용이 있다면 여기에서 PR을 환영합니다
node-postgres
Step 1 - 패키지 설치
npm
yarn
pnpm
bun
npm i drizzle-orm pg
npm i -D drizzle-kit @types/pg
Step 2 - 드라이버 초기화 및 쿼리 실행
node-postgres
node-postgres with config
// Make sure to install the 'pg' package
import { drizzle } from 'drizzle-orm/node-postgres';
const db = drizzle(process.env.DATABASE_URL);
const result = await db.execute('select 1');기존 드라이버를 제공해야 하는 경우:
// Make sure to install the 'pg' package
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');postgres.js
Step 1 - 패키지 설치
npm
yarn
pnpm
bun
npm i drizzle-orm postgres
npm i -D drizzle-kit
Step 2 - 드라이버 초기화 및 쿼리 실행
postgres.js
postgres.js with config
import { drizzle } from 'drizzle-orm/postgres-js';
const db = drizzle(process.env.DATABASE_URL);
const result = await db.execute('select 1');기존 드라이버를 제공해야 하는 경우:
// Make sure to install the 'postgres' package
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
const queryClient = postgres(process.env.DATABASE_URL);
const db = drizzle({ client: queryClient });
const result = await db.execute('select 1');