Prisma는 오픈소스 ORM 프로젝트로 아래와 같은 하위 항목들로 구성됨
Prisma는 지원하는 모든 노드, 타입스크립트 애플리케이션에서 사용 가능
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
npm install @prisma/client
prisma generate
실행import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const allUsers = await prisma.user.findMany()
const allUsers = await prisma.user.findMany({
include: { posts: true },
})
const filteredPosts = await prisma.post.findMany({
where: {
OR: [
{ title: { contains: 'prisma' } },
{ content: { contains: 'prisma' } },
],
},
})
const user = await prisma.user.create({
data: {
name: 'Alice',
email: 'alice@prisma.io',
posts: {
create: { title: 'Join us for Prisma Day 2020' },
},
},
})
const post = await prisma.post.update({
where: { id: 42 },
data: { published: true },
})