Drizzle <> Prisma Postgres

This guide assumes familiarity with:
  • 使用 Drizzle 的数据库连接基础
  • Prisma Postgres 无服务器数据库 - 官网
  • Prisma Postgres 直接连接 - 文档
  • Drizzle PostgreSQL 驱动 - 文档

Prisma Postgres 是一个基于 unikernels 构建的无服务器数据库。它拥有大量的免费额度,基于操作的定价 并且没有冷启动。

你可以使用 PostgreSQL 的 node-postgrespostgres.js 驱动进行连接。

Prisma Postgres 也有一个无服务器驱动,将来 Drizzle ORM 会支持它。

第一步 - 安装包

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

第二步 - 初始化驱动并执行查询

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

接下来?