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.

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.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
Rome, a Modern Toolchain!
JSNation 2023JSNation 2023
31 min
Rome, a Modern Toolchain!
Top Content
Modern JavaScript projects come in many shapes: websites, web applications, desktop apps, mobile apps, and more. For most of them, the common denominator is the technical debt that comes from settings up tools: bundlers, testing suite, code analysis, documentation, etc. I want to present you Rome, a toolchain that aims to be a all-in-one toolchain for the web, with one single tool you can maintain the health of all your projects!
Improving Developer Happiness with AI
React Summit 2023React Summit 2023
29 min
Improving Developer Happiness with AI
GitHub Copilot is an AI pair programmer that can help you write code faster and spend less time writing repetitive code.This session will cover some interesting use cases for Copilot that could shine a light on its possibilities. This ranges from prompting Copilot to suggest a function based on a comment, learning how to use a new framework, tackling a security or accessibility bug, better documenting your code, translating  code from one language to another, etc.Agenda:
Introduction to CoPilot
- What is Copilot
- How can you use it
- How it can help you write code faster
- Copilot Labs experimental features I will pick examples from the React ecosystem and show how we can fix Security Vulnerabilities and Accessibility issues in some components.
Static Analysis in JavaScript: What’s Easy and What’s Hard
JSNation 2023JSNation 2023
23 min
Static Analysis in JavaScript: What’s Easy and What’s Hard
We are all using static analysis tools like ESLint every day to ensure the better quality of our code. How does it work, and what is tricky about JavaScript, making writing a proper rule often not trivial?
How I Automated Code Changes for 100 Repositories: Getting Started With Codemods
React Day Berlin 2022React Day Berlin 2022
28 min
How I Automated Code Changes for 100 Repositories: Getting Started With Codemods
Three Ways to Automate Your Browser, and Why We Are Adding a Fourth: WebDriver BiDi
JSNation 2023JSNation 2023
19 min
Three Ways to Automate Your Browser, and Why We Are Adding a Fourth: WebDriver BiDi
A journey through overwhelming ways to automate browsers. Join Michael on a journey to see what happens behind the scenes of "await page.goto('https://example.com');" et. al. See what pros and cons each of the three ways of browser automation have.
Understand why we are adding a fourth - WebDriver BiDi.

Workshops on related topic

Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
JSNation 2023JSNation 2023
44 min
Solve 100% Of Your Errors: How to Root Cause Issues Faster With Session Replay
WorkshopFree
Ryan Albrecht
Ryan Albrecht
You know that annoying bug? The one that doesn’t show up locally? And no matter how many times you try to recreate the environment you can’t reproduce it? You’ve gone through the breadcrumbs, read through the stack trace, and are now playing detective to piece together support tickets to make sure it’s real.
Join Sentry developer Ryan Albrecht in this talk to learn how developers can use Session Replay - a tool that provides video-like reproductions of user interactions - to identify, reproduce, and resolve errors and performance issues faster (without rolling your head on your keyboard).