跳到主要內容

後續步驟

本節列出您現在可以從此處採取的許多潛在後續步驟。請隨意探索這些步驟,或閱讀簡介頁面,以獲得 Prisma ORM 的高階概述。

繼續探索 Prisma Client API

您可以使用 Prisma Client API 發送各種查詢。查看API 參考文件,並使用本指南中現有的資料庫設定來試用它們。

提示

您可以使用編輯器的自動完成功能來了解不同的 API 呼叫及其接受的參數。通常按下鍵盤上的 CTRL+SPACE 即可調用自動完成功能。

展開以查看更多 Prisma Client API 範例

以下是一些關於您可以使用 Prisma Client 發送更多查詢的建議

篩選所有包含 "hello"Post 記錄

const filteredPosts = await prisma.post.findMany({
where: {
OR: [{ title: { contains: 'hello' } }, { body: { contains: 'hello' } }],
},
})

建立新的 Post 記錄並將其連接到現有的 User 記錄

const post = await prisma.post.create({
data: {
title: 'Join us for Prisma Day 2020',
slug: 'prisma-day-2020',
body: 'A conference on modern application development and databases.',
user: {
connect: { email: 'hello@prisma.com' },
},
},
})

使用流暢關聯 API,透過遍歷關聯來檢索 UserPost 記錄

const user = await prisma.comment
.findUnique({
where: { id: '60ff4e9500acc65700ebf470' },
})
.post()
.user()

刪除 User 記錄

const deletedUser = await prisma.user.delete({
where: { email: 'sarah@prisma.io' },
})

使用 Prisma ORM 建置應用程式

Prisma 部落格提供關於 Prisma ORM 的綜合教學,請查看我們最新的教學

在 Prisma Studio 中探索資料

Prisma Studio 是用於資料庫中資料的可視化編輯器。在您的終端機中執行 npx prisma studio

試用 Prisma ORM 範例

prisma-examples 儲存庫包含許多可立即執行的範例

示範堆疊描述
nextjs全端簡單的 Next.js 應用程式
nextjs-graphql全端簡單的 Next.js 應用程式 (React) 與 GraphQL API
graphql-nexus僅後端基於 @apollo/server 的 GraphQL 伺服器
express僅後端使用 Express.JS 的簡單 REST API
grpc僅後端簡單 gRPC API