Drizzle <> Prisma Postgres

This guide assumes familiarity with:
  • Drizzle 数据库 连接基础

  • Prisma Postgres 无服务器数据库 - website

  • Prisma Postgres 直连 - docs

  • Drizzle PostgreSQL 驱动程序 - docs

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

你可以使用 PostgreSQL 的 node-postgrespostgres.js 驱动程序连接到它。

Prisma Postgres 也有一个 无服务器驱动程序,未来 Drizzle ORM 将支持该功能。

步骤 1 - 安装软件包

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

步骤 2 - 初始化驱动程序并进行查询

node-postgres (pg)
postgres.js
// 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');

下一步是什么?