Skip to main content

使用 MongoDB 将 Prisma ORM 添加到现有项目后的后续步骤

本节列出了你现在可以从这里采取的一些潜在的后续步骤。请随意探索这些内容或阅读 介绍 页面以获取 Prisma ORM 的高级概述。

¥This section lists a number of potential next steps you can now take from here. Feel free to explore these or read the Introduction page to get a high-level overview of Prisma ORM.

继续探索 Prisma 客户端 API

¥Continue exploring the Prisma Client API

你可以使用 Prisma 客户端 API 发送各种查询。查看 API 参考 并使用本指南中的现有数据库设置来尝试它们。

¥You can send a variety of queries with the Prisma Client API. Check out the API reference and use your existing database setup from this guide to try them out.

提示

你可以使用编辑器的自动补齐功能来了解不同的 API 调用及其所需的参数。通常通过在键盘上敲击 CTRL+SPACE 来调用自动补齐功能。

¥You can use your editor's auto-completion feature to learn about the different API calls and the arguments it takes. Auto-completion is commonly invoked by hitting CTRL+SPACE on your keyboard.

Expand for more Prisma Client API examples

以下是针对你可以使用 Prisma 客户端发送的更多查询的一些建议:

¥Here are a few suggestions for a number of more queries you can send with Prisma Client:

过滤所有包含 "hello"Post 记录

¥Filter all Post records that contain "hello"

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

创建新的 Post 记录并将其连接到现有的 User 记录

¥Create a new Post record and connect it to an existing User record

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 记录

¥Use the fluent relations API to retrieve the Post records of a User by traversing the relations

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

删除 User 条记录

¥Delete a User record

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

使用 Prisma ORM 构建应用

¥Build an app with Prisma ORM

Prisma 博客提供有关 Prisma ORM 的综合教程,请查看我们的最新教程:

¥The Prisma blog features comprehensive tutorials about Prisma ORM, check out our latest ones:

探索 Prisma Studio 中的数据

¥Explore the data in Prisma Studio

Prisma Studio 是数据库中数据的可视化编辑器。在终端中运行 npx prisma studio

¥Prisma Studio is a visual editor for the data in your database. Run npx prisma studio in your terminal.

尝试 Prisma ORM 示例

¥Try a Prisma ORM example

prisma-examples 存储库包含许多可立即运行的示例:

¥The prisma-examples repository contains a number of ready-to-run examples:

演示描述
nextjs全栈简单的 Next.js 应用
nextjs-graphql全栈带有 GraphQL API 的简单 Next.js 应用 (React)
graphql-nexus仅后端基于 @apollo/server 的 GraphQL 服务器
express仅后端使用 Express.JS 的简单 REST API
grpc仅后端简单的 gRPC API