Drizzle <> PostgreSQL

This guide assumes familiarity with:

Drizzle은 node-postgrespostgres.js 드라이버를 사용한 PostgreSQL 연결을 네이티브로 지원합니다.

두 드라이버를 사용하고 Drizzle ORM과 통합하면서 발견한 node-postgrespostgres.js 간의 몇 가지 차이점이 있습니다. 예를 들어:

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');

다음 단계는?