Drizzle ORM First impressions - migrations, relations, queries!

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии • 99

  • @andrewsherman4610
    @andrewsherman4610 Год назад +62

    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  Год назад +8

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

    • @AnthonyBullard
      @AnthonyBullard Год назад +1

      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  Год назад +1

      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 Год назад +15

    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  Год назад +3

      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 Год назад +1

      @@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  Год назад +1

      Thank you! I appreciate the follow up

  • @Anton-ih4we
    @Anton-ih4we Год назад +1

    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 😃

  • @mitchelldirt
    @mitchelldirt Год назад +10

    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  Год назад +2

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

  • @nyzss
    @nyzss Год назад +2

    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 Год назад +2

    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.

  • @StartupSpells
    @StartupSpells Год назад +1

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

  • @JohnMcclaned
    @JohnMcclaned Год назад +3

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

    • @mariusespejo
      @mariusespejo  Год назад +1

      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 Год назад +1

      @@mariusespejo do it with Next!

  • @RolandAyala
    @RolandAyala Год назад +2

    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  Год назад +2

      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 Год назад

      @@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  Год назад

      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 Год назад

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

  • @Zippo_1234
    @Zippo_1234 Год назад +1

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

  • @jim0zhan
    @jim0zhan 10 месяцев назад

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

    • @mariusespejo
      @mariusespejo  10 месяцев назад

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

  • @MilindaAbeykoon
    @MilindaAbeykoon Год назад +1

    production ready?

    • @mariusespejo
      @mariusespejo  Год назад +1

      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

  • @rundeks
    @rundeks Год назад +1

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

    • @mariusespejo
      @mariusespejo  Год назад +1

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

  • @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  Год назад +1

      Yeah I can probably cover that!

    • @louislecouturier
      @louislecouturier Год назад

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

  • @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

  • @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  Год назад +1

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

  • @parmetra
    @parmetra Год назад

    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  Год назад +1

      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 Год назад

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

  • @charlesokorobo508
    @charlesokorobo508 4 месяца назад

    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  4 месяца назад

      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

  • @g-luu
    @g-luu Год назад +1

    Amazing, would like to see this in nestjs

  • @jsvrs
    @jsvrs 2 месяца назад

    1 year has passed. Are you still using Drizzle? Why?

    • @mariusespejo
      @mariusespejo  2 месяца назад

      I try to in newer projects, in general the dev experience is just better, and also often performance: orm.drizzle.team/benchmarks

  • @Nobodylihshdheuhdhd
    @Nobodylihshdheuhdhd Год назад

    Kysely vs Kysely,which has more performance?

  • @ruggeddog3103
    @ruggeddog3103 Год назад

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

    • @mariusespejo
      @mariusespejo  Год назад +2

      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

  • @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  Год назад +1

      Interesting thanks I’ll look into that!

  • @tobychidi
    @tobychidi Год назад

    More about Drizzle pls😊

  • @WorkerThreads
    @WorkerThreads 10 месяцев назад

    What it is IDE ?

    • @mariusespejo
      @mariusespejo  10 месяцев назад

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

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

  • @cafesmallhouse1751
    @cafesmallhouse1751 Год назад

    So interesting. Thanks a lot.

  • @kamalkamals
    @kamalkamals 8 месяцев назад

    github link ?

  • @yashkhd1100
    @yashkhd1100 Год назад +4

    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  Год назад +12

      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 Год назад +1

      @@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 Год назад +3

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

  • @googoochu3923
    @googoochu3923 11 месяцев назад

    Source code?

    • @mariusespejo
      @mariusespejo  11 месяцев назад

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

  • @sushantrajbanshi4508
    @sushantrajbanshi4508 Год назад +1

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

    • @mariusespejo
      @mariusespejo  Год назад +2

      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 Год назад +1

      @@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  Год назад +2

      Maybe!

  • @jcen1918
    @jcen1918 Год назад

    Fabulous, thanks

  • @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

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

  • @pythagoran
    @pythagoran Год назад

    ORMs keep you weak

  • @gadgetboyplaysmc
    @gadgetboyplaysmc 7 месяцев назад

    Migrations are kinda bad.

    • @mariusespejo
      @mariusespejo  7 месяцев назад

      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