prisma-client-api by prisma/skills
npx skills add https://github.com/prisma/skills --skill prisma-client-apiPrisma Client 的完整 API 参考。此技能提供关于 Prisma ORM 7.x 的模型查询、过滤、关联和客户端方法的指导。
在以下情况下参考此技能:
| 优先级 | 类别 | 影响 | 前缀 |
|---|---|---|---|
| 1 | 客户端构造 | 高 | constructor |
| 2 | 模型查询 | 关键 | model-queries |
| 3 | 查询形状 | 高 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
query-options| 4 | 过滤 | 高 | filters |
| 5 | 关联 | 高 | relations |
| 6 | 事务 | 关键 | transactions |
| 7 | 原生 SQL | 关键 | raw-queries |
| 8 | 客户端方法 | 中 | client-methods |
constructor - PrismaClient 设置和适配器连接model-queries - CRUD 操作和批量操作query-options - select、include、omit、排序、分页filters - 标量和逻辑过滤运算符relations - 关联读取和嵌套写入transactions - 数组和交互式事务模式raw-queries - $queryRaw 和 $executeRaw 安全性client-methods - 生命周期和扩展方法import { PrismaClient } from '../generated/client'
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL
})
const prisma = new PrismaClient({ adapter })
| 方法 | 描述 |
|---|---|
findUnique() | 通过唯一字段查找一条记录 |
findUniqueOrThrow() | 查找一条记录或抛出错误 |
findFirst() | 查找第一条匹配的记录 |
findFirstOrThrow() | 查找第一条记录或抛出错误 |
findMany() | 查找多条记录 |
create() | 创建新记录 |
createMany() | 创建多条记录 |
createManyAndReturn() | 创建多条记录并返回它们 |
update() | 更新一条记录 |
updateMany() | 更新多条记录 |
updateManyAndReturn() | 更新多条记录并返回它们 |
upsert() | 更新或创建记录 |
delete() | 删除一条记录 |
deleteMany() | 删除多条记录 |
count() | 统计匹配的记录数 |
aggregate() | 聚合值(求和、平均值等) |
groupBy() | 分组和聚合 |
| 选项 | 描述 |
|---|---|
where | 过滤条件 |
select | 要包含的字段 |
include | 要加载的关联关系 |
omit | 要排除的字段 |
orderBy | 排序顺序 |
take | 限制结果数量 |
skip | 跳过结果(分页) |
cursor | 基于游标的分页 |
distinct | 仅唯一值 |
| 方法 | 描述 |
|---|---|
$connect() | 显式连接到数据库 |
$disconnect() | 断开与数据库的连接 |
$transaction() | 执行事务 |
$queryRaw() | 执行原生 SQL 查询 |
$executeRaw() | 执行原生 SQL 命令 |
$on() | 订阅事件 |
$extends() | 添加扩展 |
// 通过唯一字段查找
const user = await prisma.user.findUnique({
where: { email: 'alice@prisma.io' }
})
// 使用过滤器查找
const users = await prisma.user.findMany({
where: { role: 'ADMIN' },
orderBy: { createdAt: 'desc' },
take: 10
})
const user = await prisma.user.create({
data: {
email: 'alice@prisma.io',
name: 'Alice',
posts: {
create: { title: 'Hello World' }
}
},
include: { posts: true }
})
const user = await prisma.user.update({
where: { id: 1 },
data: { name: 'Alice Smith' }
})
await prisma.user.delete({
where: { id: 1 }
})
const [user, post] = await prisma.$transaction([
prisma.user.create({ data: { email: 'alice@prisma.io' } }),
prisma.post.create({ data: { title: 'Hello', authorId: 1 } })
])
详细的 API 文档:
references/constructor.md - PrismaClient 构造函数选项
references/model-queries.md - CRUD 操作
references/query-options.md - select, include, omit, where, orderBy
references/filters.md - 过滤条件和运算符
references/relations.md - 关联查询和嵌套操作
references/transactions.md - 事务 API
references/raw-queries.md - $queryRaw, $executeRaw
references/client-methods.md - $connect, $disconnect, $on, $extends
| 运算符 | 描述 |
|---|---|
equals | 精确匹配 |
not | 不等于 |
in | 在数组中 |
notIn | 不在数组中 |
lt, lte | 小于 |
gt, gte | 大于 |
contains | 字符串包含 |
startsWith | 字符串以...开始 |
endsWith | 字符串以...结束 |
mode | 大小写敏感度 |
| 运算符 | 描述 |
|---|---|
some | 至少有一条关联记录匹配 |
every | 所有关联记录都匹配 |
none | 没有关联记录匹配 |
is | 关联记录匹配(一对一) |
isNot | 关联记录不匹配 |
从上表中选择类别,然后打开对应的参考文件以获取实现细节和示例。
每周安装量
2.7K
仓库
GitHub 星标数
26
首次出现
2026年2月4日
安全审计
安装于
github-copilot2.4K
cursor2.3K
opencode2.2K
codex2.2K
gemini-cli2.1K
amp2.0K
Complete API reference for Prisma Client. This skill provides guidance on model queries, filtering, relations, and client methods for Prisma ORM 7.x.
Reference this skill when:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Client Construction | HIGH | constructor |
| 2 | Model Queries | CRITICAL | model-queries |
| 3 | Query Shape | HIGH | query-options |
| 4 | Filtering | HIGH | filters |
| 5 | Relations | HIGH | relations |
| 6 | Transactions | CRITICAL | transactions |
| 7 | Raw SQL | CRITICAL | raw-queries |
| 8 | Client Methods | MEDIUM | client-methods |
constructor - PrismaClient setup and adapter wiringmodel-queries - CRUD operations and bulk operationsquery-options - select, include, omit, sort, paginationfilters - scalar and logical filter operatorsrelations - relation reads and nested writestransactions - array and interactive transaction patternsimport { PrismaClient } from '../generated/client'
import { PrismaPg } from '@prisma/adapter-pg'
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL
})
const prisma = new PrismaClient({ adapter })
| Method | Description |
|---|---|
findUnique() | Find one record by unique field |
findUniqueOrThrow() | Find one or throw error |
findFirst() | Find first matching record |
findFirstOrThrow() | Find first or throw error |
findMany() | Find multiple records |
create() | Create a new record |
| Option | Description |
|---|---|
where | Filter conditions |
select | Fields to include |
include | Relations to load |
omit | Fields to exclude |
orderBy | Sort order |
take | Limit results |
| Method | Description |
|---|---|
$connect() | Explicitly connect to database |
$disconnect() | Disconnect from database |
$transaction() | Execute transaction |
$queryRaw() | Execute raw SQL query |
$executeRaw() | Execute raw SQL command |
$on() | Subscribe to events |
// Find by unique field
const user = await prisma.user.findUnique({
where: { email: 'alice@prisma.io' }
})
// Find with filter
const users = await prisma.user.findMany({
where: { role: 'ADMIN' },
orderBy: { createdAt: 'desc' },
take: 10
})
const user = await prisma.user.create({
data: {
email: 'alice@prisma.io',
name: 'Alice',
posts: {
create: { title: 'Hello World' }
}
},
include: { posts: true }
})
const user = await prisma.user.update({
where: { id: 1 },
data: { name: 'Alice Smith' }
})
await prisma.user.delete({
where: { id: 1 }
})
const [user, post] = await prisma.$transaction([
prisma.user.create({ data: { email: 'alice@prisma.io' } }),
prisma.post.create({ data: { title: 'Hello', authorId: 1 } })
])
Detailed API documentation:
references/constructor.md - PrismaClient constructor options
references/model-queries.md - CRUD operations
references/query-options.md - select, include, omit, where, orderBy
references/filters.md - Filter conditions and operators
references/relations.md - Relation queries and nested operations
references/transactions.md - Transaction API
references/raw-queries.md - $queryRaw, $executeRaw
references/client-methods.md - $connect, $disconnect, $on, $extends
| Operator | Description |
|---|---|
equals | Exact match |
not | Not equal |
in | In array |
notIn | Not in array |
lt, lte | Less than |
gt, |
| Operator | Description |
|---|---|
some | At least one related record matches |
every | All related records match |
none | No related records match |
is | Related record matches (1-to-1) |
isNot | Related record doesn't match |
Pick the category from the table above, then open the matching reference file for implementation details and examples.
Weekly Installs
2.7K
Repository
GitHub Stars
26
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot2.4K
cursor2.3K
opencode2.2K
codex2.2K
gemini-cli2.1K
amp2.0K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
raw-queries - $queryRaw and $executeRaw safetyclient-methods - lifecycle and extension methodscreateMany() | Create multiple records |
createManyAndReturn() | Create multiple and return them |
update() | Update one record |
updateMany() | Update multiple records |
updateManyAndReturn() | Update multiple and return them |
upsert() | Update or create record |
delete() | Delete one record |
deleteMany() | Delete multiple records |
count() | Count matching records |
aggregate() | Aggregate values (sum, avg, etc.) |
groupBy() | Group and aggregate |
skip| Skip results (pagination) |
cursor | Cursor-based pagination |
distinct | Unique values only |
$extends() | Add extensions |
gte| Greater than |
contains | String contains |
startsWith | String starts with |
endsWith | String ends with |
mode | Case sensitivity |