bizbaeja / portfolio

포트폴리오
https://portfolio-bizbaeja.vercel.app
0 stars 0 forks source link

prisma settings & planetscale 연동 #4

Open bizbaeja opened 10 months ago

bizbaeja commented 10 months ago

npm i @prisma/client

npm i -D prisma

npx prisma init → prisma폴더와 파일 생김

lib/db.ts생성

import { PrismaClient } from "@prisma/client";

declare global {
    var prisma: PrismaClient | undefined;
}

export const db = globalThis.prisma || new PrismaClient();

if (process.env.NODE_ENV === "production") {
  globalThis.prisma = db;
}

schema.prisma

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
  relationMode = "prisma"
}
model User {
  id             String  @id @default(uuid())
  username       String  @unique
  imageUrl       String  @db.Text
  externalUserId String  @unique
  bio            String? @db.Text
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

플래닛 스케일 참고