I ❤️ Drizzle

SQL is amazing but writing a SQL without guardrails is not the best experience. This is what I learned when I started working on a hobby project with my friend. The project was about maintaining a game library and buying and selling games between users. We were using RAWG.IO for the library aspect and used that data to build the marketplace. To put some context during my internship I worked a LOT with CMSes.

We were planning on using NestJs, but then I stumbled upon Strapi. This looked good because it handled a lot of things out of the box and it also had a dashboard view as well and I was happy with everything being hidden away from me. I remember saying to myself "Future me would handle everything :)"

Fast forward a few months later, and I found myself knee-deep in customizing everything. I was learning about the complex ways Strapi managed relations and query builders behind the scenes. That's when I realized that hiding everything is convenient until you have to uncover layers of it just to perform basic tasks.

Switching to TypeOrm

After using Strapi for a while and finding out the V4 version had a lot of the issues I faced in V3 fixed, I was looking into migrating to V4. This meant I would be rewriting a lot, and looking at my old code just made me question a lot of the things I did. This was the perfect opportunity to jump ship, and this time it was NestJS It also helped that I was using Angular for a few projects in my internship and everything in Nest felt familiar. The recommended ORM to use wih Nest is TypeORM. Switching from JS to TS felt like a breath of fresh air. I was happy about the fact that my IDE would yell at me whenever I did something wrong. The biggest annoyance i had with typeorm was that it felt extreamly verbose and i found that i was jumping between files all the time whenever i neeeded to do a small change. After a few more months had passed and COVID came around, my friend and i decided to ditch the entire idea entirely.

Switching to Prisma

While I was using TypeOrm I heard about Prisma and it was the new hot thing**.** At first, the idea of having your entire schema in one file was weird but I soon came to the realization this was great. Separating your business into multiple files throughout your code base in different modules was annoying. Having one schema file allowed me to look at all the entities in one place. Also, the IntelliSense support for the schema file was spot on. Generating migrations was a breeze, and updating your DB was easy as db:push It was all great until it wasn't. It's the same old story as before as your code base grows complexity rises. But this time more than complexity it was editor performance. Whenever you make a change to the schema file, all the types required for the Prisma library get generated, and most of the time whenever I do change it takes quite a while for the editor to pick up the changes and show you which areas need to be updated. This was not a big deal in TypeORM as your entities are defined in TS itself. It was also around this time people found out about issues with how Prisma did relations internally https://codedamn.com/news/product/dont-use-prisma.

Drizzle

This has been the best choice I made in a while. When I heard about drizzle first I thought it was only a query builder like Knex. But then I found out that it also supported relations out of the box as well. I just got a new project and wanted to try it out. I ended up using it with NestJs and it has been more than a year since I made this decision, so far I don't have regrets at the moment. The query builder is very intuitive and ends up looking just like SQL

drizzleClient.insert(posts).values({ name: "Hello, world!", })

Also, relational query building is very simple

drizzleClient.query.posts.findFirst({
    where: (post, { eq }) => eq(post.id, post.id),
});

Migrations are also a no-brainer with drizzle-kit. Unlike other ORMs, drizzle creates migrations as simple SQL snippet files. This allows you to update and modify any changes for migrations.

The only thing I missed was not having built-in hooks to entities.
Overall I ❤️ drizzle