Skip to main content

将 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" },
{ content: { 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',
author: {
connect: { email: 'alice@prisma.io' },
},
},
})

使用流畅的关系 API 通过遍历关系来检索 UserPost 记录

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

const posts = await prisma.profile
.findUnique({
where: { id: 1 },
})
.user()
.posts()

删除 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 Optimize 获取查询洞察和分析

¥Get query insights and analytics with Prisma Optimize

Prisma 优化 可帮助你生成洞察并提供建议,帮助你加快数据库查询速度。立即试用!

¥Prisma Optimize helps you generate insights and provides recommendations that can help you make your database queries faster. Try it out now!

Optimize 旨在帮助各个技能水平的开发者编写高效的数据库查询,减少数据库负载并提高应用的响应速度。

¥Optimize aims to help developers of all skill levels write efficient database queries, reducing database load and making applications more responsive.

更改数据库架构(例如添加更多表)

¥Change the database schema (e.g. add more tables)

要改进应用,你需要遵循与教程相同的流程:

¥To evolve the app, you need to follow the same flow of the tutorial:

  1. 使用 SQL 手动调整数据库架构

    ¥Manually adjust your database schema using SQL

  2. 重新审视你的数据库

    ¥Re-introspect your database

  3. (可选)重新配置你的 Prisma 客户端 API

    ¥Optionally re-configure your Prisma Client API

  4. 重新生成 Prisma 客户端

    ¥Re-generate Prisma Client

Introspect workflow

尝试 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