选项
首页首页 Skill 网页开发 prisma-client-api

prisma-client-api

prisma/skills prisma/skills

Prisma Client API 参考文档,涵盖模型查询、过滤器、运算符和客户端方法。在编写数据库查询、使用 CRUD 操作、过滤数据或配置 Prisma Client 时可参考本文档。 触发器适用于“prisma query”、“findMany”、“create”、“update”、“delete”和“$transaction”。

...展开全部
58
更新时间 2026-06-29

关于prisma-client-api

prisma-client-api 技能为使用 Prisma Client 与数据库交互提供了全面的参考指南。它简化了在 Prisma 项目中构建查询、执行 CRUD 操作、应用过滤器、管理关系以及处理事务的流程。 通过提供关于客户端实例化、模型查询、查询选项以及原始 SQL 执行的详细指导,该技能可帮助开发人员在处理关系型数据库时减少错误并提高效率。它对于确保查询结构正确,以及安全有效地处理嵌套写入和事务等高级操作尤为有用。

本技能涵盖广泛的功能,包括 findUnique、findMany、create、update、delete、upsert 等模型查询方法,以及 count、aggregate 和 groupBy 等聚合函数。它还为查询选项提供了全面支持,允许开发人员进行过滤、选择、包含、排除、排序、分页以及强制使用唯一值。 此外,还涵盖了 Prisma Client 用于生命周期管理、事件订阅、原始 SQL 执行以及客户端扩展的方法。该技能确保原始 SQL 查询的安全执行,并提供有关使用数组式和交互式事务的指导,以维护数据完整性。

目标用户包括使用 JavaScript 或 TypeScript 且需要通过 Prisma 高效与数据库交互的后端开发人员、数据库管理员和全栈工程师。 典型用例包括构建 Web 应用程序、API 和微服务,其中精确的数据检索、操作和聚合至关重要。该技能还适用于需要在生产环境中实现复杂关系逻辑或执行批处理操作时,寻求一致查询模式和最佳实践标准参考的团队。

常见问题

如何使用自定义适配器实例化 Prisma Client?

您可以通过导入 PrismaClient 和您的适配器,然后将适配器配置传递给客户端构造函数来实例化 Prisma Client,具体操作如提供的 TypeScript 示例所示。

Prisma Client 支持哪些数据库操作?

Prisma Client 支持完整的 CRUD 操作,包括 findUnique、findMany、create、createMany、update、updateMany、upsert、delete 和 deleteMany。它还支持聚合和分组方法。

Prisma Client 能否处理事务?

是的,Prisma Client 通过 $transaction 方法同时支持基于数组和交互式的事务,允许在单个事务内安全地执行多个查询。

是否支持原始 SQL,使用是否安全?

Prisma Client 提供了 $queryRaw 和 $executeRaw 方法来执行原始 SQL 查询。使用这些方法时应格外谨慎,以避免 SQL 注入;文档中提供了安全使用的指导。

使用此 Prisma Client API 技能有哪些要求?

您需要一个已生成客户端的 Prisma 项目、一个受支持的数据库以及一个合适的适配器。客户端实例化和查询执行需要 TypeScript 或 JavaScript 环境。

在 GitHub 上查看

Prisma Client API Reference

Complete API reference for Prisma Client. This skill provides guidance on model queries, filtering, relations, and client methods for current Prisma projects.

When to Apply

Reference this skill when:

  • Writing database queries with Prisma Client
  • Performing CRUD operations (create, read, update, delete)
  • Filtering and sorting data
  • Working with relations
  • Using transactions
  • Configuring client options

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Client ConstructionHIGHconstructor
2Model QueriesCRITICALmodel-queries
3Query ShapeHIGHquery-options
4FilteringHIGHfilters
5RelationsHIGHrelations
6TransactionsCRITICALtransactions
7Raw SQLCRITICALraw-queries
8Client MethodsMEDIUMclient-methods

Quick Reference

  • constructor - PrismaClient setup, adapter wiring, logging, and SQL commenter plugins
  • model-queries - CRUD operations and bulk operations
  • query-options - select, include, omit, sort, pagination
  • filters - scalar and logical filter operators
  • relations - relation reads and nested writes
  • transactions - array and interactive transaction patterns
  • raw-queries - $queryRaw and $executeRaw safety
  • client-methods - lifecycle methods, extensions, and satisfies patterns for prisma-client

Client Instantiation

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 })

Model Query Methods

MethodDescription
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
createMany()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

Query Options

OptionDescription
whereFilter conditions
selectFields to include
includeRelations to load
omitFields to exclude
orderBySort order
takeLimit results
skipSkip results (pagination)
cursorCursor-based pagination
distinctUnique values only

Client Methods

MethodDescription
$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
$extends()Add extensions

Quick Examples

Find records

// Find by unique fieldconst user = await prisma.user.findUnique({  where: { email: '[email protected]' }})// Find with filterconst users = await prisma.user.findMany({  where: { role: 'ADMIN' },  orderBy: { createdAt: 'desc' },  take: 10})

Create records

const user = await prisma.user.create({  data: {    email: '[email protected]',    name: 'Alice',    posts: {      create: { title: 'Hello World' }    }  },  include: { posts: true }})

Update records

const user = await prisma.user.update({  where: { id: 1 },  data: { name: 'Alice Smith' }})

Delete records

await prisma.user.delete({  where: { id: 1 }})

Transactions

const [user, post] = await prisma.$transaction([  prisma.user.create({ data: { email: '[email protected]' } }),  prisma.post.create({ data: { title: 'Hello', authorId: 1 } })])

Rule Files

Detailed API documentation:

references/constructor.md        - PrismaClient constructor optionsreferences/model-queries.md      - CRUD operationsreferences/query-options.md      - select, include, omit, where, orderByreferences/filters.md            - Filter conditions and operatorsreferences/relations.md          - Relation queries and nested operationsreferences/transactions.md       - Transaction APIreferences/raw-queries.md        - $queryRaw, $executeRawreferences/client-methods.md     - $connect, $disconnect, $on, $extends

Filter Operators

OperatorDescription
equalsExact match
notNot equal
inIn array
notInNot in array
lt, lteLess than
gt, gteGreater than
containsString contains
startsWithString starts with
endsWithString ends with
modeCase sensitivity

Relation Filters

OperatorDescription
someAt least one related record matches
everyAll related records match
noneNo related records match
isRelated record matches (1-to-1)
isNotRelated record doesn't match

Resources

  • Prisma Client API Reference
  • CRUD Operations
  • Filtering and Sorting

How to Use

Pick the category from the table above, then open the matching reference file for implementation details and examples.

安装 prisma-client-api

下载技能文件并将其解压到 .claude/skills/ 目录中。

下载ZIP

克隆仓库并复制技能文件到您的项目中。

git clone https://github.com/prisma/skills/blob/main/prisma-client-api/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ 目录下,Claude 会自动检测并使用该技能
仓库 prisma/skills

相关技能

github-code-search
更新时间 2026-06-29
drizzle-orm
更新时间 2026-06-29
clickhouse-io
更新时间 2026-06-29
coding-standards
更新时间 2026-06-29
OR