$ npm install prisma --save-dev
$ npx prisma init
DATABASE_URL="heroku postgresql db link"
model Post {
id Int @default(autoincrement()) @id
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
$ npx prisma db push
$ npx prisma studio
Before you can access your database from Next.js using Prisma, you first need to install Prisma Client in your app
$ npm install @prisma/client
Because Prisma Client is tailored to your own schema, you need to update it every time your Prisma schema file is changing by running the following command
$ npx prisma generate
$ mkdir lib && touch lib/prisma.ts
// lib/prisma.ts
import { PrismaClient } from '@prisma/client'
let prisma: PrismaClient
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!global.prisma) {
global.prisma = new PrismaClient()
}
prisma = global.prisma
}
export default prisma