Drizzle ORM in 100 Seconds

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
drizzle om a lightweight set of tools that makes type safe object relational mapping with your favorite relational database fun again most apps in the real world rely on databases like MySQL postgressql and SQL light to store their critical user data but working with raw SQL can be painful and even life-threatening when you screw up over the decades hundreds of libraries have been built to abstract away SQL code to hide its complexity inside your favorite objectoriented programming language this technique is called object relational mapping it's great and null but can often bring unnecessary performance overhead and cause leaky abstractions because the developers have no idea how their underlying SQL code actually works drizzle is an omm that takes the opposite approach it provides an API and typescript that closely matches the native underly SQL code this gives you the benefits of type safety and intellisense without all the crazy abstractions but how is that possible when every database is different instead of trying to jam everything into a single API drizzle provides dedicated adapters for each one of them along with dedicated tools for popular Cloud hosts like RDS and neon but if this code looks too raw and uncensored for you it also provides an optional Prisma likee query API that keeps your data fetching and join code concise and readable in addition it provides an optional CLI for handling database migrations called drizzle kit but the cherry on top is drizzle Studio A guey you can run locally to manage your data to get started you'll first need a relational database I'm going with neon my go-to pick for a postgress database and the sponsor of today's video neon is awesome because it's easy to use there's a generous free tier and it even has a fast serverless driver with a drizzle adapter you don't even need to install postgress locally just create a new database on the dashboard both drizzle and neon are designed to run on any JavaScript runtime like node.js bun and Dino as well as Edge run times like cloudflare workers now install drizzle and your database driver then connect to the database in your typescript code we could start making queries now but we don't have any data yet first we need a schema create a schema file then Define tables with the PG table function each table table has a name followed by columns defined in this JavaScript object columns are given constraints with JavaScript functions that match their SQL equivalents once a table is defined we can reference it in other tables to create relationships with foreign keys and optionally we can use the relations function to simplify relational queries and Joints now let's convert this typescript code into postgressql by running the drizzle kit generate command that creates a directory with our migration files which we can then apply to Neon with this migrate function and now we can use drizzle SQL like a to insert data into the database and because the schema is strongly typed it's impossible to write incorrect queries in addition because we also created a relation in our schema we can use the query API to fetch records based on one to one one to many or many to many relationships this has been drizzle in 100 seconds shout out to Neon for making this video possible and check out their drizzle tutorial to learn more thanks for watching and I will see you in the next one
Info
Channel: Fireship
Views: 446,407
Rating: undefined out of 5
Keywords: webdev, app development, lesson, tutorial
Id: i_mAHOhpBSA
Channel Id: undefined
Length: 2min 54sec (174 seconds)
Published: Thu Feb 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.