bun add drizzle-orm@rc postgresbun add -D drizzle-kit@rc
第二步:初始化驱动并执行查询
node-postgres (pg)
postgres.js
// Make sure to install the 'pg' packageimport { 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 'postgres' packageimport { drizzle } from 'drizzle-orm/postgres-js';const db = drizzle(process.env.DATABASE_URL);const result = await db.execute('select 1');
如果需要传入已有驱动:
node-postgres (pg)
postgres.js
// Make sure to install the 'pg' packageimport { 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');
// Make sure to install the 'postgres' packageimport { 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');
# Runtime: pooled, transaction modeDATABASE_URL="postgresql://admin:<password>@db-<hash>.<region>.appwrite.center:6432/<database>?sslmode=require"# Migrations & introspection: direct connection to the engineDIRECT_URL="postgresql://admin:<password>@db-<hash>.<region>.appwrite.center:5432/<database>?sslmode=require"