Co-authored by
Drizzle is a brilliant, type-safe ORM growing quickly in popularity. If you want to switch to Drizzle, you have two options:
- Keep Prisma and add the Drizzle API to the Prisma client. Drizzle have a great guide on how to do this.
- Go all-in and switch to Drizzle.
1. Swap out the required dependencies in @repo/database
Uninstall the existing dependencies…
Terminal
Terminal
2. Update the database connection code
Delete everything in@repo/database/index.ts
and replace it with the following:
packages/database/index.ts
3. Create a drizzle.config.ts
file
Next we’ll create a Drizzle configuration file, used by Drizzle Kit and contains all the information about your database connection, migration folder and schema files. Create a drizzle.config.ts
file in the packages/database
directory with the following contents:
packages/database/drizzle.config.ts
4. Generate the schema file
Drizzle uses a schema file to define your database tables. Rather than create one from scratch, we can generate it from the existing database. In thepackages/database
folder, run the following command to generate the schema file:
schema.ts
file containing the table definitions and some other files.
5. Update your queries
Now you can update your queries to use the Drizzle ORM. For example, here’s how we can update thepage
query in app/(authenticated)/page.tsx
:
apps/app/app/(authenticated)/page.tsx
6. Remove Prisma Studio
You can also delete the now unused Prisma Studio app located atapps/studio
:
Terminal
7. Update the migration script in the root package.json
Change the migration script in the root package.json
from Prisma to Drizzle. Update the migrate
script to use Drizzle commands: