選項
首頁首頁 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 及您的轉接器,然後將轉接器設定傳遞給 Client 建構函式來建立 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 技能有哪些要求?

您需要一個已生成 Client 的 Prisma 專案、受支援的資料庫,以及適當的轉接器。建立 Client 實例和執行查詢時,必須在 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