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.Prisma works out of the box with Bun. First, create a directory and initialize it with
bun init
.
terminal
Then install the Prisma CLI (
prisma
) and Prisma Client (@prisma/client
) as dependencies.
terminal
We’ll use the Prisma CLI with
bunx
to initialize our schema and migration directory. For simplicity we’ll be using an in-memory SQLite database.
terminal
Open
prisma/schema.prisma
and add a simple User
model.
prisma/schema.prisma
Then generate and run initial migration. This will generate a
.sql
migration file in prisma/migrations
, create a new SQLite instance, and execute the migration against the new instance.
terminal
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
We can import the generated client from
@prisma/client
.
Let’s write a simple script to create a new user, then count the number of users in the database.
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 using Bun, we recommend referring to the official Prisma docs as you continue to develop your application.