What’s the Deal With Drizzle ORM?

Rate this content
Bookmark

There's already plenty of ORMs in the JS world, so why build another one? In this talk we'll figure out why Drizzle is different from other solutions in the market, why do we consider it a "day 1000 ORM" and how does it feel to be a headless ORM with a head. We'll also delve into the Drizzle ecosystem and look at solutions that will greatly enhance your drizzling™ experience.

This talk has been presented at JSNation 2024, check out the latest edition of this JavaScript Conference.

FAQ

Drizzle is a TypeScript overrun designed to leverage SQL knowledge while using TypeScript end-to-end. It features both SQL-like CRUD API and a relational API for complex relational data.

Drizzle allows you to write SQL in TypeScript, manage your database schema, and supports prepared statements for peak performance. It is fully written in TypeScript and offers tools like DrizzleKit and Drizzle Studio.

Drizzle comes with a CLI tool called DrizzleKit that can generate migrations based on schema changes. It calculates the differences and generates SQL migration, making it easier to manage your database schema.

Drizzle tries to stay a thin wrapper around SQL to minimize overhead. While SQL is already fast, Drizzle supports prepared statements to reduce overhead even further, achieving peak performance.

Yes, Drizzle is already powering several production-grade projects like SST, Payload, T3, Warp, AnswerOverflow, OpenStatus, and Unkey.

Drizzle Studio is a UI tool for viewing and manipulating the contents of your database. It supports every database compatible with Drizzle and includes built-in query runners for testing and running SQL queries.

Drizzle has not yet reached its v1 release, which means the API is still being polished and may change. However, the team is close to achieving their ideal API, so fewer changes are expected before the v1 release.

The Drizzle ecosystem includes tools like Drizzle Studio for viewing and manipulating database contents, DrizzleKit for schema management, and supplementary libraries for validation and query building. It also has a GraphQL integration.

Future plans for Drizzle include supporting more SQL dialects, achieving a v1 release, and open-sourcing DrizzleKit. There are also plans to expand the Drizzle ecosystem with more tools and libraries.

Drizzle's relational API is designed for querying complex relational data, like one-to-many relations, in a convenient format. It transforms relational queries into a single SQL statement, resulting in one roundtrip to the database.

Dan Kochetov
Dan Kochetov
8 min
17 Jun, 2024

Comments

Sign in or register to post your comment.
  • Dan Kochetov
    Dan Kochetov
    Drizzle Team
    It's not a priority for the team - there are no noticeable issues with runtime performance at the moment that would justify spending time on it.
  • Sean Kelly
    Sean Kelly
    Munster Bovine
    Hey Dan, why not take advantage of workers?
  • Dan Kochetov
    Dan Kochetov
    Drizzle Team
    Sean, Drizzle doesn't utilize multi-threading on its own, since Node.js is single-threaded by default.

Video Summary and Transcription

Drizzle is a TypeScript ORM that leverages SQL knowledge, is fast and has its own ecosystem. It manages database schema and supports prepared statements for peak performance. Drizzle provides a complete set of tools, including Drizzle Studio and query runners. The ecosystem includes GraphQL integration and community-built tools.
Available in Español: ¿Qué hay con Drizzle ORM?

1. Introduction to Drizzle

Short description:

Drizzle is a TypeScript overrun that leverages your SQL knowledge, uses TypeScript end to end, and has both SQL-like CRUD API and a relational API. It works with all major databases and cloud providers, is fast, and has its own ecosystem. Everything you write with Drizzle is in TypeScript, no additional language required. If you know SQL, you know Drizzle. It manages your database schema for you.

Hi, I'm Dan, I'm a co-founder of Drizzle team. And today I'm going to talk about Drizzle overrun. So what's Drizzle? It's basically like a small rain. It's some sort of weather condition, right? And by complete chance, it's also a TypeScript overrun. So let's talk about that one. We were bypassed in 2007 and then again in 2008, and then we lost to Eloquent even before we existed. So as you can see, it's been a rough journey, but anyway, what is Drizzle for real this time?

As I said, Drizzle is a TypeScript overrun which has several unique features compared to other overruns. First of all, it leverages your SQL knowledge rather than obstructing it away from you. It also uses TypeScript end to end, so you'll only need to write TypeScript code and nothing else. It has both SQL-like CRUD API and a relational API for complex relational data. It works with all major databases and cloud providers. It's quite fast compared to just running raw SQL. And it has its own ecosystem, which includes a migration management tool, a data viewer and a lot more. So let's dive in.

Drizzle is fully written in TypeScript. It was designed with TypeScript in mind and it leverages it to its fullest. Everything you write with Drizzle, from schema to queries, is rewritten in TypeScript. There's no additional language you need to learn first. There's no compilation step on every code change. Everything is dynamic and familiar. You might have noticed that the table definition on the previous slide looks quite similar to SQL. And that's actually on purpose. The whole philosophy of Drizzle is, if you know SQL, you know Drizzle. All the query APIs closely resemble their SQL counterparts. So you don't even need to learn a new API. You just write SQL as you're used to, just in TypeScript. And the result is always predictable. You don't need to guess which query will be run on the database. It's exactly what you've written, and the result is always fully type safe. Drizzle not only allows you to write SQL in TypeScript, it can also manage your database schema for you.

2. DrizzleKit and Performance

Short description:

Drizzle comes with a CLI tool called DrizzleKit that generates migrations based on schema changes. It recognizes common cases like renaming columns. Drizzle is a thin wrapper around SQL, minimizing overhead. It supports prepared statements for peak performance. The relational API allows convenient querying of complex relational data, providing simple yet powerful syntax and maintaining optimal performance.

It comes with a CLI tool called DrizzleKit, which, among other things, can generate the migrations for you based on the schema changes. All you need to do is run DrizzleKit generate, and it will calculate the differences you've made to the schema and generate a SQL migration. It's also smart enough to recognize some common cases like renaming a column, for example.

Now, is Drizzle fast? Well, not exactly. You see, the thing is, SQL is already quite fast on its own. So all that we have to do is not to slow it down. Drizzle tries to stay a thin wrapper around SQL, and it does as little things as possible besides just running the query. So its overhead compared to running SQL is minimal. We've always been building Drizzle with performance in mind. So it also has support for prepared statements, something that we didn't really see implemented in other ORMs to our sprites. With prepared statements, you can make the overhead even lower to truly achieve peak performance.

Now, let's talk about the relational API for a bit. Its primary purpose is to query complex relational data, like one-to-many relations, for example, in a convenient format. So in this example, you can certainly get the same data using basic SQL queries with joins and then aggregate it in code to get the same result. But that might not be as convenient to write. With relational queries, on the other hand, you have simple yet powerful syntax to query your relational data without much hassle. So now you have multiple opportunities. You can have full control over your queries to execute the exact SQL statements you need, and you can easily obtain relational data of any complexity without compromising the performance. This is because every relational query, no matter how big, is always transformed into a single SQL statement, which results in exactly one roundtrip to the database.