LaunchPadQuick 🚀
This guide will walk you through the installation and configuration of Prisma ORM in your Next.js 14 SaaS application. You'll learn how to connect Prisma to both Supabase and MongoDB databases, including the necessary schema configurations for each database.
- First, install Prisma and the Prisma client in your project:
1
npm install prisma @prisma/client
- Initialize Prisma in your project by running:
1
npx prisma init
This command creates a prisma directory with a schema.prisma file, and also sets up an initial .env file.
Edit the prisma/schema.prisma file to use PostgreSQL as the provider:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// Example model for Supabase
model User {
id Int @id @default(autoincrement())
name String
email String @unique
}
Install the MongoDB adapter for Prisma:
1
npm install @prisma/adapter-mongodb
Edit the prisma/schema.prisma file to use MongoDB as the provider:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
// Example model for MongoDB
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
email String @unique
}