Prisma构建数据库的 GraphQL 服务框架

联合创作 · 2023-09-19 18:55

Prisma 是一个快速构建 GraphQL 服务、REST API、数据库服务的后端框架

  • 已支持 MySQL, PostgreSQL, MongoDB 等数据库,其他流行数据库正在开发中

  • 客户端已支持 JavaScript, TypeScript, Flow, Go 等语言

  • 类型安全的数据库访问,包括过滤器、聚合、分页和事务

  • 数据库的实时事件系统以获得有关数据库事件的通知

  • 具有简单SDL语法的声明性数据建模和迁移

Prisma

示例代码:

const { prisma } = require('./generated/prisma-client')

// A `main` function so that we can use async/await
async function main() {
  // Create a new user with a new post
  const newUser = await prisma.createUser({
    name: 'Alice',
    posts: {
      create: { title: 'The data layer for modern apps' }
    }
  })
  console.log(`Created new user: ${newUser.name} (ID: ${newUser.id})`)

  // Read all users from the database and print them to the console
  const allUsers = await prisma.users()
  console.log(allUsers)

  // Read all posts from the database and print them to the console
  const allPosts = await prisma.posts()
  console.log(allPosts)
}

main().catch(e => console.error(e))

 

浏览 1
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报