Prisma’s dynamically loaded subcommands, such as
prisma dev, require npm to be installed alongside Bun. The commands
used in this guide (prisma init, prisma migrate, and prisma generate) are built into the CLI. Generated code
works with Bun using the prisma-client generator.1
Create a new project
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 LibSQL adapter as dependencies.terminal
3
Initialize Prisma with SQLite
Use the Prisma CLI with This creates a basic schema. Open
bunx to initialize the schema and migration directory. This guide uses a local SQLite database file; prisma init writes its connection string, DATABASE_URL="file:./dev.db", to .env.terminal
prisma/schema.prisma, update the generator block to use the Rust-free client with the bun runtime, and add a User model.prisma/schema.prisma
4
Create and run database migration
Generate and run the initial migration. This writes a
.sql migration file to prisma/migrations, creates a new SQLite database, and runs the migration against it. Bun does not load .env automatically when it runs a CLI with --bun, and the prisma.config.ts generated by prisma init reads DATABASE_URL from the environment, so pass --env-file=.env explicitly.terminal
5
Generate Prisma Client
prisma migrate dev does not generate the Prisma client, so generate it with the Prisma CLI. The client provides a fully typed API for reading and writing to your database.terminal
6
Initialize Prisma Client with LibSQL
Create a new file
prisma/db.ts that initializes the PrismaClient with the LibSQL adapter.prisma/db.ts
7
Create a test script
Write a script that creates a new user, then counts the users in the database.
index.ts
8
Run and test the application
Run the script with
bun run. Each run creates a new user.terminal
terminal
terminal
Prisma is now set up with Bun. See the Prisma docs as you build out your application.