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.

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.

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.

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

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 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.

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
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
Rome, a Modern Toolchain!
JSNation 2023JSNation 2023
31 min
Rome, a Modern Toolchain!
Top Content
Rome is a toolchain built in Rust that aims to replace multiple tools and provide high-quality diagnostics for code maintenance. It simplifies tool interactions by performing all operations once, generating a shared structure for all tools. Rome offers a customizable format experience with a stable formatter and a linter with over 150 rules. It integrates with VCS and VLSP, supports error-resilient parsing, and has exciting plans for the future, including the ability to create JavaScript plugins. Rome aims to be a top-notch toolchain and welcomes community input to improve its work.
Improving Developer Happiness with AI
React Summit 2023React Summit 2023
29 min
Improving Developer Happiness with AI
Watch video: Improving Developer Happiness with AI
GitHub Copilot is an auto-completion tool that provides suggestions based on context. Research has shown that developers using Copilot feel less frustrated, spend less time searching externally, and experience less mental effort on repetitive tasks. Copilot can generate code for various tasks, including adding modals, testing, and refactoring. It is a useful tool for improving productivity and saving time, especially for junior developers and those working in unfamiliar domains. Security concerns have been addressed with optional data sharing and different versions for individuals and businesses.
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
Static analysis in JavaScript involves analyzing source code without executing it, producing metrics, problems, or warnings. Data flow analysis aims to determine the values of data in a program. Rule implementation in JavaScript can be straightforward or require extensive consideration of various cases and parameters. JavaScript's dynamic nature and uncertainty make static analysis challenging, but it can greatly improve code quality.
Automate the Browser With Workers Browser Rendering API
JSNation 2024JSNation 2024
20 min
Automate the Browser With Workers Browser Rendering API
The Talk discusses browser automation using the Worker's Browser Rendering API, which allows tasks like navigating websites, taking screenshots, and creating PDFs. Cloudflare integrated Puppeteer with their workers to automate browser tasks, and their browser rendering API combines remote browser isolation with Puppeteer. Use cases for the API include taking screenshots, generating PDFs, automating web applications, and gathering performance metrics. The Talk also covers extending sessions and performance metrics using Durable Objects. Thank you for attending!
Conquering Complexity: Refactoring JavaScript Projects
JSNation 2024JSNation 2024
21 min
Conquering Complexity: Refactoring JavaScript Projects
Today's Talk explores the complexity in code and its impact. It discusses different methods of measuring complexity, such as cyclomatic complexity and cognitive complexity. The importance of understanding and conquering complexity is emphasized, with a demo showcasing complexity in a codebase. The Talk also delves into the need for change and the role of refactoring in dealing with complexity. Tips and techniques for refactoring are shared, including the use of language features and tools to simplify code. Overall, the Talk provides insights into managing and reducing complexity in software development.

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).