Note — At the moment Prisma needs Node.js to be installed to run certain generation code. Make
sure Node.js is installed in the environment where you’re running
bunx prisma commands.1
Create a new project
First, create a directory and initialize it with
bun init.terminal
2
Install Prisma dependencies
Then install the Prisma CLI (
prisma), Prisma Client (@prisma/client), and the accelerate extension as dependencies.terminal
3
Initialize Prisma with PostgreSQL
We’ll use the Prisma CLI with This creates a basic schema. We need to update it to use the new Rust-free client with Bun optimization. Open
prisma/schema.prisma
bunx to initialize our schema and migration directory. We’ll be using PostgreSQL as our database.terminal
prisma/schema.prisma and modify the generator block, then add a simple User model.4
Configure database connection
Set up your Postgres database URL in the
.env file..env
5
Create and run database migration
Then generate and run initial migration.This will generate a
.sql migration file in prisma/migrations, and execute the migration against your Postgres database.terminal
6
Generate Prisma Client
As indicated in the output, Prisma re-generates our Prisma client whenever we execute a new migration. The client provides a fully typed API for reading and writing from our database. You can manually re-generate the client with the Prisma CLI.
terminal
7
Initialize Prisma Client with Accelerate
Now we need to create a Prisma client instance. Create a new file
prisma/db.ts
prisma/db.ts to initialize the PrismaClient with the Postgres adapter.8
Create a test script
Let’s write a simple script to create a new user, then count the number of users in the database.
index.ts
9
Run and test the application
Let’s run this script with
bun run. Each time we run it, a new user is created.terminal
terminal
terminal
That’s it! Now that you’ve set up Prisma Postgres using Bun, we recommend referring to the official Prisma Postgres docs as you continue to develop your application.