프로그래밍/NextJS

nextjs prisma 넥스트 프리즈마 세팅

타코코딩 2024. 1. 22. 19:15

프리즈마 세팅

  • mysql 깔려있어야함
  • npm i prisma
  • npx prisma init
  • prisma파일에서 mysql로 변경 .. .env파일에서 mysql로변경/아디/비번/포트번호/워크벤치명

모델생성

model Issue {
  id          Int      @id @default(autoincrement())
  title       String   @db.VarChar(255)
  description String   @db.Text
  status      Status   @default(OPEN)
  createAt    DateTime @default(now())
  updateAt    DateTime @updatedAt
}
enum Status {
  OPEN
  IN_PROGRESS
  CLOSED
}
  • npx prisma format
  • npx prisma migrate dev Create issue model
  • req를 통해 넘어온 데이터 검증 npm i zod
  • prisma/client.ts 복붙
import { PrismaClient } from '@prisma/client'

const prismaClientSingleton = () => {
  return new PrismaClient()
}

declare global {
  var prisma: undefined | ReturnType<typeof prismaClientSingleton>
}

const prisma = globalThis.prisma ?? prismaClientSingleton()

export default prisma

if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma

'프로그래밍 > NextJS' 카테고리의 다른 글

nextauth 넥스트어스 사용하기  (0) 2024.01.22
next Radix 설치 및 사용  (1) 2024.01.22
nextjs nodemailer 연동하기  (0) 2024.01.08
nextjs api폴더 리팩토링  (0) 2024.01.06
nextjs 페이지이동 Link,useRouter  (0) 2024.01.05