No video

Drizzle ORM First impressions - migrations, relations, queries!

In this video we take a quick look at the drizzle ORM to see if it's good enough to replace other options like prisma, typeorm, and Kysely. We'll create a simple application to test out creating migrations, running introspection, creating queries, and using relations. If you're looking for an orm for database queries that has very good typescript support but doesn't try to over abstract, you need check this one out!

Пікірлер: 97

  • @andrewsherman4610
    @andrewsherman4610 Жыл бұрын

    Thank you very much, from the Drizzle Team, for the great video! You pointed out a few bugs that we will fix, so we truly appreciate your help in spotting them. We also appreciate you trying out Drizzle and showcasing all of that

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Great to see the drizzle team in the comments! Thanks for stopping by!

  • @AnthonyBullard

    @AnthonyBullard

    Жыл бұрын

    He hit a lot of the speed bumps I encountered. The relations function feels very clunky coming from Prisma (but now that I know the rules, I'll take it for the perf improvements). In the meantime, can we try to make run() on a SQLite insert not return `any`? 😉. I lost a lot of time trying to figure out how to get my full table row back out. There is returning, run, get, all. And the docs aren't great, especially in LSP

  • @owenwexler7214

    @owenwexler7214

    Жыл бұрын

    @@AnthonyBullard the lack of a UNIQUE constraint is a big glaring thing missing but a. I'm sure that's a high-priority addition coming soon, b. it's easy to get around right now by implementing the schema in a SQL client outside of Drizzle and only using Drizzle to read the schema and do other CRUD operations.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Support for unique constraints was added recently github.com/drizzle-team/drizzle-orm/releases/tag/0.27.2

  • @owenwexler7214

    @owenwexler7214

    Жыл бұрын

    @@mariusespejo Thank you! We appreciate you. I used to be really anti-ORM but Drizzle looks to be the only ORM I would consider using.

  • @bloberenober
    @bloberenober Жыл бұрын

    Awesome video! You covered the core API of Drizzle very well and concisely. A couple of notes: 1. ".returning()" is only required for insert/update/delete queries because it's actually how you'd write it in SQL. 2. I agree that having to specify the reverse side of a relation is not intuitive and furthermore is not covered in the docs, might improve either the API, the docs or both in the next releases. 2. The result type issue in the relational query is a bug, thanks for pointing it out! Will try to fix it shortly 🙂

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Ah! That makes so much sense now haha, TIL “returning” clause. To be honest I’ve mostly used MySQL at work which I think doesn’t have that, good callout. Anyways, thank you! great work so far!

  • @bloberenober

    @bloberenober

    Жыл бұрын

    @@mariusespejo a quick update: the types issue was happening because you typed your db variable manually, and it's missing a schema generic. It should've been "PostgresJsDatabase", or, better, just remove the type and let TS infer it for you. Nonetheless, I'm working on improving the feedback from the API for such cases, so that it's clear what's wrong.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Thank you! I appreciate the follow up

  • @mitchelldirt
    @mitchelldirt Жыл бұрын

    I recently tried out Drizzle, having only tried out prisma prior and I really enjoyed it! I love that you can write the queries the sameish way you would with raw SQL. The Zod extension is great too!

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Ah I missed that there are extensions, I’ll check that out!

  • @Anton-ih4we
    @Anton-ih4we Жыл бұрын

    Omg I just watched the video and haven't noticed it was a 30 min video. You were going through all of this so fluently. Thank you very much, I've learned a lot 😃

  • @nyzss
    @nyzss Жыл бұрын

    thank you, I have been using drizzle for my latest (hobby) project and I found it incredible. i'm glad its finally getting so much recognition lately.

  • @sully-kg
    @sully-kg Жыл бұрын

    Thanks for the video, got stuck for a few hours because I'm blind to docs (missed the { schema } generic while migrating my db.ts from the old format to relational queries) and this cleared it right up.

  • @drpwnage23
    @drpwnage2310 ай бұрын

    Thanks for making this video, I think I will be using Drizzle for my next project

  • @RolandAyala
    @RolandAyala10 ай бұрын

    I've used Drizzle and Kysely, and prefer both the Prisma (by far), and Kysely is my favorite of the two, and suggest you give it a try. For me, I find Kysely easier to use, esp. compared to the inferred relations that need to be declared for Drizzle. With Kysely, just use the nested array and object helpers, and there's no additional setup needed, and no bifurcating the api between select and query. Kysely just feels like the right balance to me. ymmv.

  • @mariusespejo

    @mariusespejo

    10 ай бұрын

    I did make an impressions vid for kysely as well if you’re curious. They’re both good, but the drizzle query builder api to me is more intuitive, definitely a preference thing

  • @RolandAyala

    @RolandAyala

    10 ай бұрын

    @@mariusespejo Agree, the Drizzle queries are simpler *once* you set them up, but, I find it more effort to build the drizzle relations than to just query straight-up using kysely, and prefer letters flexibility, but agree it comes doesn't to personal pref.

  • @mariusespejo

    @mariusespejo

    10 ай бұрын

    Relation api is optional though, you can just as easily do manual join and use your own utilities on top of it. With that said I really don’t think it’s even fair to compare the two. One is clearly trying to be an ORM, like a full fledged alternative to prisma. The other is just trying to bring a type-safe query builder

  • @RolandAyala

    @RolandAyala

    10 ай бұрын

    @@mariusespejo Very true. Drizzle is developing into more of an ORM with its new(ish) query interface, and appropriately so I suppose given its name (drizzle-orm). It's been awhile, but I'll check again if something like jsonArrayFrom & jsonObjectFrom are avail for drizzle (there was unofficial sample several months back), but, frankly, I just overall prefer the ergonomics of Kelsey (personal pref). The only reason I waiver sometimes is because I use drizzle-kit for defining my schema, handling pushes, migrations, etc., and infer back out the interfaces for Kysely to use via drizzle-zod, so kinda makes sense for me to be all in on drizzle, but, like I said, just much prefer the ergonomics of kysely. I also left Prisma because wanting to get away from using ORMs.

  • @charlesokorobo508
    @charlesokorobo50813 күн бұрын

    Dear Marius, I am trying to use Drizzle ORM, but many things are not clear to me: I want to create 4 Database Tables: a.) Users Table: a table that will have normal user information. Then there will be 3 additional tables which records and stores a user's interaction on the website. These are: b.) Posts Table: a table with a One-to-Many Relationship -- where a user will have many Posts, many Comments, many Likes, many Thumbs Down, many Friends, many Groups, and many Pages, stored into this table. c.) Purchases Table: a table which is a One-to-Many Relationship Table -- where a user will have many transactions listed to their name. This table only keeps stock and inventory of all the Purchases that a user makes on my website. d.) Points Table: a table which stores all the many Points, many Awards, and many Badges that a user will earn on the website. QUESTION 1 In creating a Schema, I'm I going to create One(1) Schema per Table? -- in which case I will have 4 different Schemas? Or Is it one(1) Schema I will use to declare all the structure of the 4 Tables? 2.) How do I create a Schema that will take note of all these four(4) Tables, and is able to link them to work together? This is a big problem for me, and I am hoping that you can guide me on this, because I didn't see how to do it in the Documentation, and I've spent 8 days on it without hope on what to do exactly. Regards.

  • @mariusespejo

    @mariusespejo

    11 күн бұрын

    How you organize your tables within schemas is not really something specific to drizzle, it’s based on how you want to separate your data. Generally in most cases tables that are related to each other should be in the same schema, so in your case here 1 schema with 4 tables. You should understand how to create/manage schema in SQL and it will make more sense how to also do the same in drizzle. You can find drizzle examples for assigning a set of tables to a schema here: orm.drizzle.team/docs/schemas

  • @rundeks
    @rundeks Жыл бұрын

    Drizzle creates a drizzle schema and that is where it tracks the migrations ran on the db.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    I see, will check for that next time I use it, thanks!

  • @StartupSpells
    @StartupSpells Жыл бұрын

    whats the theme & file icons on the sidebar? love it.

  • @jim0zhan
    @jim0zhan6 ай бұрын

    Thanks for the great sharing! May I know what type of font you are using also? It's lovely 😊

  • @mariusespejo

    @mariusespejo

    5 ай бұрын

    On vs code I used Cascadia Mono it’s free!

  • @JohnMcclaned
    @JohnMcclaned Жыл бұрын

    Can you please make a video using the ts-rest library? It looks awesome but there is no content on it! Thanks :)

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    It actually is on my todo list, I was thinking of doing an end-to-end type safety with Nest or Next! I’ll try to bump it up in the list, thanks for the reminder 😄

  • @JohnMcclaned

    @JohnMcclaned

    Жыл бұрын

    @@mariusespejo I'd love to see a Next / ts-rest video! I'm starting a project soon with this and it would be awesome to be able to get up to speed with a video :)

  • @lutfiikbalmajid

    @lutfiikbalmajid

    Жыл бұрын

    @@mariusespejo do it with Next!

  • @g-luu
    @g-luu Жыл бұрын

    Amazing, would like to see this in nestjs

  • @peter-novak-m
    @peter-novak-m Жыл бұрын

    Thanks for the video, I am curious about Drizzle as an Prisma alternative and keen to learn more. Have you considered using it together with the T3 stack?

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Well prisma is technically part of the t3 stack I think, although I don’t see any reason why you couldn’t swap it out for drizzle. But it’s still fairly young and you’re going to find bugs or missing features, if you prefer stability I’d suggest waiting a couple months

  • @parmetra
    @parmetra9 ай бұрын

    Thanks for your video! Could you tell me if you recommend using Drizzle instead of Prisma? Or maybe there is a third option?

  • @mariusespejo

    @mariusespejo

    9 ай бұрын

    Honestly depends on the use case. Prisma has great dev ux, is fairly stable and is pretty good for most cases, while drizzle might outperform it in some situations, but it’s still new and has some missing features. Prisma also tries to work at a higher abstraction, getting farther away from sql, while drizzle tries to get their query builder as close to sql-like as possible. So it depends on your personal preference.

  • @parmetra

    @parmetra

    9 ай бұрын

    @@mariusespejo Thank you very much for your detailed answer! Then I'll settle on Drizzle. I like to write pure SQL queries. I would like to make an API, but as I understand it, it is necessary to use some kind of ORM. Then let it be Drizzle.

  • @Szarlus
    @Szarlus Жыл бұрын

    Hi, thanks for the vid! On the environment file and editing to blur, I love a vsc plugin called cloak, which hides the env file env values for me, so I don't expose it accidentally when screen sharing or stuff 😜

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Interesting thanks I’ll look into that!

  • @louislecouturier
    @louislecouturier Жыл бұрын

    Hey Marius ! Thanks a lot for this demo ! Are you planning to make a video about using Drizzle ORM in NestJS ?

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Yeah I can probably cover that!

  • @louislecouturier

    @louislecouturier

    Жыл бұрын

    @@mariusespejo that would be great help ! ☺️ thanks mate !

  • @tobychidi
    @tobychidi Жыл бұрын

    More about Drizzle pls😊

  • @cafesmallhouse1751
    @cafesmallhouse1751 Жыл бұрын

    So interesting. Thanks a lot.

  • @ruggeddog3103
    @ruggeddog3103 Жыл бұрын

    i'm using prisma, haven't ran into any problems so far, am i better off with it? Y/N

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Engineering decisions are not that black and white. “Better” depends on context. Prisma for the most part is still a great solution as long as you’re not hindered by its performance in some situations. It all depends on the rest of your infrastructure. If you don’t already know if or why you should switch, you probably shouldn’t.

  • @ruggeddog3103

    @ruggeddog3103

    Жыл бұрын

    @@mariusespejo thanks man really appreciate it

  • @jcen1918
    @jcen1918 Жыл бұрын

    Fabulous, thanks

  • @fieryninja2374
    @fieryninja2374 Жыл бұрын

    I am really bad at reading docs so can someone help me make something unique? I have no sql knowledge but I know a bit of prisma and I want to make the email in my user table unique.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    You’re looking for unique constraints. I highly suggest taking the time to learn SQL so you have a clear understanding of what tools like prisma are ultimately doing for you.

  • @MilindaAbeykoon
    @MilindaAbeykoon Жыл бұрын

    production ready?

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    The query builder seems good enough for most use cases, but the relations api and drizzle-kit as a whole seems fairly new. I suggest looking at the docs to see if it fits your current needs

  • @Nobodylihshdheuhdhd
    @Nobodylihshdheuhdhd10 ай бұрын

    Kysely vs Kysely,which has more performance?

  • @mariusespejo

    @mariusespejo

    10 ай бұрын

    Huh

  • @ComisarioLobo
    @ComisarioLobo Жыл бұрын

    Hi Marius, thanks for this great resource. Do you mind sharing how you get JSON responses from your console logs to appear formatted nicely and with colors in your terminal?

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    I didn’t really setup anything special for that. I’m using oh-my-zsh with the syntax highlighting plugin. I don’t think there is any formatting involved there though, I believe that’s default behavior of console.log

  • @ComisarioLobo

    @ComisarioLobo

    Жыл бұрын

    @@mariusespejo thanks for your quick response, unfortunately for me that setup only shows white text in the terminal when console logging. What's the VSCode theme that you are using?

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Like I said I’m using oh-my-zsh with the syntax highlighting plugin, which is for coloring. it has nothing to do with vs code’s theme. You can also install themes for oh-my-zsh, I think I’m using Power10k theme, it’s fairly popular. But still theme has nothing to do with syntax highlighting from my understanding , you first need to enable that before it can be themed. I could be wrong.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Also the whole point of the syntax highlighting plugin is to colorize syntax so that tells me you don’t have it installed correctly. You might also need to set vs code to use that specific terminal that you configured

  • @ComisarioLobo

    @ComisarioLobo

    Жыл бұрын

    @@mariusespejo I have oh-my-zsh installed with syntax highlighting plugin and it is working as expected, if I type echo $'Hello World', I do see the colors and when I disable it everything is white. However, even with that plugin correctly setup I only see my json objects printed in white in my terminal. So, I'll install the Power10k theme of zsh to see if that makes the trick. About the VSCode theme, I know it is a separate thing but I like the one you are using and I would like to try it Thanks again for you help =)

  • @yashkhd1100
    @yashkhd1100 Жыл бұрын

    It's quite odd that in 2023 Node devs are yet to settle for an ORM that works well. I'm experienced backend dev with lot of experience in enterprise apps with traditional languages like C# and Java. ORM thing on both platforms are solved from more than 10 years. They work as expected with rock solid stability. Recently I have been seeing around front end and node eco system. The thing that surprises me most are how cracky node environment can be with tons and tons of package dependency and Node JS version issues. The promise of node environment is to get things done quickly than traditional environments like Java and C#. However, it turns out you spent more time dealing with basic gotchas of NodeJS than working on your application.

  • @LtdJorge

    @LtdJorge

    Жыл бұрын

    Java is 28 years old and C# is 23, tho

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    I think you’re reading into it wrong. It’s not that there isn’t an ORM that works well in fact there are a lot of Node ORMs that work great. But it doesn’t mean that a large ecosystem wont try to keep improving things. Each new evolution in the web space (intro of TS, serverless, edge, etc.) often requires an evolution of the solutions. Your mentality is like saying: “we’ve got cars figured out ages ago, let’s stop trying to make new cars!” A good engineer understands that change can and will happen, it’s up to you to decide if the tradeoffs are worth it for you.

  • @yashkhd1100

    @yashkhd1100

    Жыл бұрын

    @@LtdJorge yeah agree but the purpose of new environments/languages is to provide all that is already present and provide lot of value on the top of it. Otherwise it just doesn't make any sense. When a Car company launches a new car people expects it has all goodies available from a Car 20 years old and lot more on the top of it. I have nothing against Node this is just rational observation.

  • @yashkhd1100

    @yashkhd1100

    Жыл бұрын

    @@mariusespejo First thing first your content is really high quality. I have seen your lot of videos in past and they are very informative. Regarding overall Node JS thing...in my opinion the purpose of new environments/languages is to provide all that is already present and provide lot of value on the top of it. Otherwise it just doesn't make any sense. When a Car company launches a new car people expects it has all goodies available from a Car 20 years old and lot more on the top of it. I have nothing against Node this is just rational observation.

  • @oscarljimenez5717

    @oscarljimenez5717

    Жыл бұрын

    @@yashkhd1100 yeah, but that's your point of view. You wanna a language that have everything already when you use it, but your using Java or C# that have almost 30 years old (so your point of view make sense), Node only 14 years the last month. Also the experience with Nodejs have to think a lot of stuff that neither Java or C# need to worry, things like TS, Serverless, Edge, etc, so like Marius said, tools always need improvement. Even Cars need improvement too. In Node, we the community are the factory, so we build out own cars and then use it.

  • @user-bp8hd6kr3d
    @user-bp8hd6kr3d6 ай бұрын

    What it is IDE ?

  • @mariusespejo

    @mariusespejo

    6 ай бұрын

    Not sure I understand the question, are you asking what editor I’m using?

  • @kamalkamals
    @kamalkamals3 ай бұрын

    github link ?

  • @googoochu3923
    @googoochu39237 ай бұрын

    Source code?

  • @mariusespejo

    @mariusespejo

    7 ай бұрын

    It’s just an overview not really a project to clone. I recommend trying it out in your own project with your own database.

  • @jamesdenmark1396
    @jamesdenmark1396 Жыл бұрын

    In most, if not all, cases for small projects, you don't need a relational database; you can use MongoDB. :) Many people don't realize this until they start using MongoDB.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    We having noSQL vs SQL debate now? Lol.

  • @lutfiikbalmajid

    @lutfiikbalmajid

    Жыл бұрын

    It's even not in the context.

  • @satyak1337
    @satyak1337 Жыл бұрын

    I got seen 4 advertisement in first 20 mins ..

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Sorry about that, youtube auto places ads for me

  • @TerryZeng
    @TerryZeng Жыл бұрын

    Another new ORM? tired...

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Whatever you’re using is probably still good

  • @gadgetboyplaysmc
    @gadgetboyplaysmc3 ай бұрын

    Migrations are kinda bad.

  • @mariusespejo

    @mariusespejo

    2 ай бұрын

    What issues did you run into? I do agree when I was testing it before, quite a bit of stuff were not supported. Haven’t had a chance to try recently though

  • @pythagoran
    @pythagoran10 ай бұрын

    ORMs keep you weak

  • @mariusespejo

    @mariusespejo

    10 ай бұрын

    Ah not enough protein?

  • @pythagoran

    @pythagoran

    10 ай бұрын

    @@mariusespejo too much sugar

  • @sushantrajbanshi4508
    @sushantrajbanshi4508 Жыл бұрын

    Have you tried *mikro-orm* ? Heard lot of good things about it.

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    I have not. I have heard good things as well. However I have had to use typeorm a lot for work and they are very similar at quick glance so I never saw a good enough reason to switch

  • @sushantrajbanshi4508

    @sushantrajbanshi4508

    Жыл бұрын

    @@mariusespejo Yeah, my friends say `mikro-orm` is what `typeorm` should've been at first place. Do try to explore it and maybe make a video on it, if possible ?

  • @mariusespejo

    @mariusespejo

    Жыл бұрын

    Maybe!