Skip to main content

无 Rust 引擎

v6.7.0 开始,你可以在 PostgreSQL、SQLite、D1、PlanetScale 和 MS SQL Server 数据库上使用无需 Rust 引擎 二进制文件的 Prisma ORM。

¥As of v6.7.0, you can use Prisma ORM without Rust engine binaries on PostgreSQL, SQLite, D1, PlanetScale & MS SQL Server databases.

本页概述了如何使用此版本的 Prisma ORM。

¥This page gives an overview of how to use this version of Prisma ORM.

不带 Rust 引擎的 Prisma ORM

¥Prisma ORM without Rust engines

如果你使用不带 Rust 引擎的 Prisma ORM,主要技术差异如下:

¥The main technical differences if you're using Prisma ORM without a Rust engine are:

  • generator 块上没有 binaryTargetsengineType 字段

    ¥no binaryTargets and engineType fields on the generator block

  • 没有使用生成的 Prisma 客户端下载到目录中的查询引擎二进制文件

    ¥no query engine binary that's downloaded into the directory with your generated Prisma Client

  • 数据库连接管理需要使用 驱动适配器

    ¥required usage of driver adapters for database connection management

用法

¥Usage

先决条件

¥Prerequisites

  • Prisma ORM v6.7.0(或更高版本)

    ¥Prisma ORM v6.7.0 (or later)

1. 设置功能标志

¥ Set feature flags

使用新架构需要设置 driverAdaptersqueryCompiler 功能标志:

¥Usage of the new architecture requires the driverAdapters and queryCompiler feature flags to be set:

schema.prisma
generator client {
provider = "prisma-client-js" // or `prisma-client`
previewFeatures = ["queryCompiler", "driverAdapters"]
output = "../generated/prisma"
}

2. 重新生成 Prisma 客户端

¥ Re-generate Prisma Client

要使功能标志生效,你需要重新生成 Prisma 客户端:

¥To make the feature flags take effect, you need re-generate Prisma Client:

npx prisma generate

3. 安装驱动程序适配器

¥ Install the driver adapter

根据你使用的数据库,你需要安装不同的驱动程序适配器库:

¥Depending on the database you use, you need to install a different driver adapter library:

npm install @prisma/adapter-pg

4. 实例化 Prisma 客户端

¥ Instantiate Prisma Client

最后,你需要实例化 Prisma 客户端,你可以使用驱动程序适配器和你正在使用的数据库实例的连接 URL 来完成此操作。

¥Finally, you need to instantiate Prisma Client which you can do using the driver adapter and the connection URL for the database instance you're using.

import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from './generated/prisma'

const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter })

5. 查询数据库

¥ Query your database

如果你已完成前面的步骤,则可以像使用 Prisma Client 一样查询数据库。无需进行其他更改。

¥If you went through the previous steps, you can query your database as you're used to with Prisma Client. No other changes are needed.