Prisma構(gòu)建數(shù)據(jù)庫的 GraphQL 服務(wù)框架
Prisma 是一個快速構(gòu)建 GraphQL 服務(wù)、REST API、數(shù)據(jù)庫服務(wù)的后端框架
-
已支持 MySQL, PostgreSQL, MongoDB 等數(shù)據(jù)庫,其他流行數(shù)據(jù)庫正在開發(fā)中
-
客戶端已支持 JavaScript, TypeScript, Flow, Go 等語言
-
類型安全的數(shù)據(jù)庫訪問,包括過濾器、聚合、分頁和事務(wù)
-
數(shù)據(jù)庫的實時事件系統(tǒng)以獲得有關(guān)數(shù)據(jù)庫事件的通知
-
具有簡單SDL語法的聲明性數(shù)據(jù)建模和遷移
示例代碼:
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))
評論
圖片
表情
