在 React Server Components 中使用 Prisma 查询来自 MySQL、PostgreSQL、SQL Server、CockroachDB 和 MongoDB 数据库的数据——这是一款更出色的 JavaScript 和 TypeScript ORM。
// Creating a new recordawait prisma.user.create({firstName: “Alice”,email: “alice@prisma.io”})
id firstName email1 Bobby bobby@tables.io2 Nilufar nilu@email.com3 Jürgen jums@dums.edu4 Alice alice@prisma.io
React 是一个流行的 JavaScript 库,用于构建用户界面。它用于构建在 Web 浏览器中运行的前端应用程序。借助 React Server Components,React 组件现在也可以在服务器上渲染。React Server Components 可以完全访问服务器端功能,例如文件系统和数据库。这就是 Prisma ORM 的用武之地:Prisma ORM 是 React 开发者在 React Server Components 中查询数据库的最佳方式。
您还可以使用我们的其他工具来增强 Prisma ORM 的使用体验
• Prisma Accelerate 是一种全局数据库缓存和可扩展连接池,可加速您的数据库查询。
• Prisma Pulse 使您能够以类型安全的方式构建反应式实时应用程序。Pulse 是实现 GraphQL 订阅或实时查询的完美伴侣。
React Server Components 在服务器上渲染,这意味着它们可以使用 @prisma/client
直接与数据库通信,以实现安全高效的数据库访问。
Prisma 提供了一个开发者友好的 API,用于构建数据库查询。在底层,它生成所需的查询并将其发送到数据库。
1export default function NoteList({searchText}) {2 // Query all notes in the database containing the searchText in the title3 const notes = await prisma.note.findMany({4 where: {5 title: {6 contains: searchText,7 },8 },9 });1011 // Display notes in React component12 return notes.length > 0 ? (13 <ul className="notes-list">14 {notes.map((note) => (15 <li key={note.id}>16 <SidebarNote note={note} />17 </li>18 ))}19 </ul>20 ) : (21 <div className="notes-empty">22 {searchText23 ? `Couldn't find any notes titled "${searchText}".`24 : 'No notes created yet!'}{' '}25 </div>26 );27}
React Server Components 在服务器上渲染,这意味着它们可以使用 @prisma/client
直接与数据库通信,以实现安全高效的数据库访问。
Prisma 提供了一个开发者友好的 API,用于构建数据库查询。在底层,它生成所需的查询并将其发送到数据库。
1export default function NoteList({searchText}) {2 // Query all notes in the database containing the searchText in the title3 const notes = await prisma.note.findMany({4 where: {5 title: {6 contains: searchText,7 },8 },9 });1011 // Display notes in React component12 return notes.length > 0 ? (13 <ul className="notes-list">14 {notes.map((note) => (15 <li key={note.id}>16 <SidebarNote note={note} />17 </li>18 ))}19 </ul>20 ) : (21 <div className="notes-empty">22 {searchText23 ? `Couldn't find any notes titled "${searchText}".`24 : 'No notes created yet!'}{' '}25 </div>26 );27}
Prisma 通过简洁直观的 API 使数据库查询变得轻松,方便您读取和写入数据。
在 React Server Components 中查询数据库可显著提高应用程序的性能。
Prisma 的声明式建模语言简洁明了,让您可以直观地描述数据库模式。
将 Prisma 与 React 配对使用可确保您的应用程序从数据库到前端都具有一致的类型。
Prisma 为您提供数据库查询的自动完成、出色的开发者体验和完全的类型安全。
React 和 Prisma 都有活跃的社区,您可以在其中找到支持、有趣的活动和很棒的人。
本指南全面介绍了如何使用 React(通过 Next.js)、Prisma 和 PostgreSQL 构建可用于生产环境的全栈应用程序。它包括通过 NextAuth.js 进行身份验证以及通过 Vercel 进行部署。
RedwoodJS 是一个全栈应用程序框架。它基于 React、GraphQL 和 Prisma 构建,使用您喜爱的组件和开发工作流程,但具有简单的约定和辅助工具,使您的体验更加出色。
我们有多个渠道供您与社区成员以及 Prisma 团队互动。