数据库特性矩阵
本页概述了 Prisma ORM 支持的数据库提供的功能。此外,它还解释了如何在 Prisma ORM 中使用这些功能,并提供更多文档的指针。
¥This page gives an overview of the features which are provided by the databases that Prisma ORM supports. Additionally, it explains how each of these features can be used in Prisma ORM with pointers to further documentation.
关系型数据库特点
¥Relational database features
本节介绍 Prisma ORM 当前支持的关系数据库上存在哪些数据库功能。Prisma 架构列指示如何在 Prisma 架构 中表示特定功能以及其文档的链接。请注意,数据库功能可以在 Prisma Client 中使用,即使它们可能尚未在 Prisma 架构中表示。
¥This section describes which database features exist on the relational databases that are currently supported by Prisma ORM. The Prisma schema column indicates how a certain feature can be represented in the Prisma schema and links to its documentation. Note that database features can be used in Prisma Client even though they might not yet be representable in the Prisma schema.
这些功能仅适用于关系数据库。支持 NoSQL 数据库(如 MongoDB)的功能可以 如下所示。
¥These features are only for relational databases. Supported features for NoSQL databases, like MongoDB, can be found below.
约束条件
¥Constraints
约束 | 支持的 | Prisma 架构 | Prisma 客户端 | Prisma 迁移 |
---|---|---|---|---|
PRIMARY KEY | ✔️ | @id 和 @@id | ✔️ | ✔️ |
FOREIGN KEY | ✔️ | 关系字段 | ✔️ | ✔️ |
UNIQUE | ✔️ | @unique 和 @@unique | ✔️ | ✔️ |
CHECK | ✔️ | 还没有 | ✔️ | 还没有 |
NOT NULL | ✔️ | ? | ✔️ | ✔️ |
DEFAULT | ✔️ | @default | ✔️ | ✔️ |
- 在 Microsoft SQL Server 中使用
UNIQUE
约束时需要注意的事项 † 仅在 版本 8 及更高版本 中的 MySQL 中受支持。¥* Caveats apply when using the
UNIQUE
constraint with Microsoft SQL Server † Only supported in MySQL in version 8 and higher.
引用操作(外键引用的删除和更新行为)
¥Referential Actions (Delete and Update behaviors for foreign key references)
删除行为 | 支持的 | Prisma 架构 | Prisma 客户端 | Prisma 迁移 |
---|---|---|---|---|
CASCADE | ✔️ | ✔️ | ✔️ | ✔️ |
RESTRICT | ✔️ | ✔️ | ✔️ | ✔️ |
NO ACTION | ✔️ | ✔️ | ✔️ | ✔️ |
SET DEFAULT | ✔️ | ✔️ | ✔️ | ✔️ |
SET NULL | ✔️ | ✔️ | ✔️ | ✔️ |
RESTRICT
在 Microsoft SQL Server 中不受支持。¥*
RESTRICT
is not supported in Microsoft SQL Server.
索引
¥Indexes
索引 | 支持的 | Prisma 架构 | Prisma 客户端 | Prisma 迁移 |
---|---|---|---|---|
UNIQUE | ✔️ | @unique 和 @@unique | ✔️ | ✔️ |
USING | 仅限 PostgreSQL | type | ✔️ | ✔️ |
WHERE | ✔️ | 还没有 | ✔️ | 还没有 |
(expression) | ✔️ | 还没有 | ✔️ | 还没有 |
INCLUDE | 仅限 PostgreSQL 和 Microsoft SQL Server | 还没有 | ✔️ | 还没有 |
通过 USING
指定的算法:
¥Algorithm specified via USING
:
索引类型(算法) | 支持的 | Prisma 架构 | Prisma 客户端 | Prisma 迁移 |
---|---|---|---|---|
B 树 | ✔️ | ✔️ | ✔️ | 还没有 |
哈希值 | ✔️ | ✔️ | ✔️ | 还没有 |
要旨 | ✔️ | ✔️ | ✔️ | 还没有 |
杜松子酒 | ✔️ | ✔️ | ✔️ | 还没有 |
布林 | ✔️ | ✔️ | ✔️ | 还没有 |
SP-GiST | ✔️ | ✔️ | ✔️ | 还没有 |
-
- 不支持 MySQL 和 SQLite
¥* Not supported for MySQL and SQLite
-
† 仅在 Prisma ORM 版本
4.0.0
及更高版本中与 PostgreSQL 连接器一起使用。¥† Available with the PostgreSQL connector only in Prisma ORM versions
4.0.0
and later.
杂项
¥Misc
特性 | 支持的 | Prisma 架构 | Prisma 客户端 | Prisma 迁移 |
---|---|---|---|---|
自动递增 ID | ✔️ | autoincrement() | ✔️ | ✔️ |
数组 | 仅限 PostgreSQL | [] | ✔️ | ✔️ |
枚举 | ✔️ † | enum | ✔️ | ✔️ |
原生数据库类型 | ✔️ | ✔️ | ✔️ | 还没有 |
SQL 视图 | ✔️ | 还没有 | 还没有 | 还没有 |
JSON 支持 | ✔️ | ✔️ | ✔️ | ✔️ |
模糊/短语全文搜索 | ✔️ | 还没有 | 还没有 | 还没有 |
表继承 | 仅限 PostgreSQL 和 Microsoft SQL Server | 还没有 | ✔️ | 还没有 |
授权和用户管理 | ✔️ | 还没有 | 还没有 | 还没有 |
-
- 不受 Microsoft SQL Server 支持
¥* Not supported by Microsoft SQL Server
-
† 从 Prisma ORM 6.2.0 开始,SQLite 支持 JSON 和枚举类型。
¥† JSON and Enum types are supported in SQLite as of Prisma ORM 6.2.0.
-
‡ SQLite 不支持
¥‡ Not supported by SQLite
NoSQL 数据库特性
¥NoSQL database features
本节介绍 Prisma ORM 当前支持的 NoSQL 数据库上存在哪些数据库功能。
¥This section describes which database features exist on the NoSQL databases that are currently supported by Prisma ORM.
MongoDB
下表列出了常见的 MongoDB 功能并描述了 Prisma ORM 提供的支持级别:
¥The following table lists common MongoDB features and describes the level of support offered by Prisma ORM:
特性 | 由 Prisma ORM 支持 | 注意 |
---|---|---|
嵌入文档 | ✔️ | |
事务 | ✔️ | |
索引 | ✔️ 有警告 | 仅当索引引用的字段至少包含一些数据时,才能对索引进行内省。 |
自动递增 ID | 不 | |
化合物 ID | 不 | MongoDB 不支持复合 ID (@@id ) |
生成 ObjectId | ✔️ | 看:为 MongoDB 定义 ID |
数组 | ✔️ | |
枚举 | ✔️ | 在 Prisma ORM 级别实现 |
原生数据库类型 | ✔️ | 看:字段映射参考 |
JSON 支持 | ✔️ | 尚不支持高级 Json 字段过滤。 |
数据库引用 | 不 | |
改变流 | 不 | |
直接访问聚合管道 | 不 |