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.
1. Introduction to Drizzle
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
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.
3. Drizzle Ecosystem
Drizzle provides a complete set of tools for your database, including Drizzle Studio for UI manipulation, compatibility with various databases, and built-in query runners. Supplementary libraries enhance the Drizzle experience, with extensions for validation and compatibility layers for query builders. Drizzle's ecosystem includes a GraphQL integration and a growing list of community-built tools. Production projects like SST, Payload, T3, and Warp showcase Drizzle's capabilities.
Okay, we've talked about the code Drizzle products, now let's look at its ecosystem. One of the best features of Drizzle is that it aims to provide you a complete set of tools for your database. One of them is Drizzle Studio, a UI tool to view and manipulate the contents of your database. It supports every database that Drizzle supports, which includes cloud providers like CloudFlare D1, Torso, Neon, AWS Aurora, Planetscale, and others. It also comes with a built-in Drizzle and SQL query runners, where you can test and run your queries directly on your database.
While Drizzle Studio is an external tool, we also have a lot of supplementary libraries that enhance your Drizzle experience. We've built extensions for validation libraries like Zot, Valobot, and Typebox. We've implemented compatibility layers for query builders like Nex or Kisely. One of the latest additions in the ecosystem was a GraphQL integration, which you can use to generate a full-fledged GraphQL server from your Drizzle schema in one line. The list keeps growing! Our amazing community is also helping us a lot by constantly building new tools for the Drizzle ecosystem.
One of the questions we are often asked is, when can I start using Drizzle in a production-grade project? Instead of convincing you, I'll let you be the judge of that by showcasing some of the projects that already use Drizzle. SST is a framework for deploying your infrastructure to the cloud. It has a console that uses Drizzle for all the database operations. Payload is a code-first TypeScript CMS that uses Drizzle under the hood and exposes its API to the end-users. T3 is a popular Next.js boilerplate that offers Drizzle as one of the available ORM solutions. Warp is a marketplace that had over 9 million visitors over 3 months, and it's powered by Drizzle. AnswerOverflow, OpenStatus, Unkey, they all use Drizzle. So you've got the idea. Drizzle is already powering lots and lots of production projects.
Comments