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.Install Prisma dependencies
Then install the Prisma CLI (
prisma), Prisma Client (@prisma/client), and the accelerate extension as dependencies.terminal
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.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
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
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.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
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.