Fireship · @fireship

Drizzle ORM in 100 Seconds

Uploaded February 29, 2024 · Length 2:54

Drizzle ORM in 100 Seconds

Summary

Drizzle ORM explained: a lightweight, type-safe object relational mapping for databases like MySQL, PostgreSQL, and SQL Light.

  • drizzle orm
  • object relational mapping
  • typescript database
  • sql light
  • postgressql

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    drizzle om a lightweight set of tools

  2. 0:02

    that makes type safe object relational

  3. 0:04

    mapping with your favorite relational

  4. 0:06

    database fun again most apps in the real

  5. 0:08

    world rely on databases like MySQL

  6. 0:11

    postgressql and SQL light to store their

  7. 0:13

    critical user data but working with raw

  8. 0:15

    SQL can be painful and even

  9. 0:17

    life-threatening when you screw up over

  10. 0:19

    the decades hundreds of libraries have

  11. 0:20

    been built to abstract away SQL code to

  12. 0:23

    hide its complexity inside your favorite

  13. 0:25

    objectoriented programming language this

  14. 0:27

    technique is called object relational

  15. 0:29

    mapping it's great and null but can

  16. 0:31

    often bring unnecessary performance

  17. 0:32

    overhead and cause leaky abstractions

  18. 0:35

    because the developers have no idea how

  19. 0:36

    their underlying SQL code actually works

  20. 0:39

    drizzle is an omm that takes the

  21. 0:41

    opposite approach it provides an API and

  22. 0:42

    typescript that closely matches the

  23. 0:44

    native underly SQL code this gives you

  24. 0:47

    the benefits of type safety and

  25. 0:48

    intellisense without all the crazy

  26. 0:50

    abstractions but how is that possible

  27. 0:52

    when every database is different instead

  28. 0:54

    of trying to jam everything into a

  29. 0:55

    single API drizzle provides dedicated

  30. 0:57

    adapters for each one of them along with

  31. 0:59

    dedicated tools for popular Cloud hosts

  32. 1:01

    like RDS and neon but if this code looks

  33. 1:04

    too raw and uncensored for you it also

  34. 1:06

    provides an optional Prisma likee query

  35. 1:08

    API that keeps your data fetching and

  36. 1:10

    join code concise and readable in

  37. 1:12

    addition it provides an optional CLI for

  38. 1:14

    handling database migrations called

  39. 1:16

    drizzle kit but the cherry on top is

  40. 1:18

    drizzle Studio A guey you can run

  41. 1:20

    locally to manage your data to get

  42. 1:21

    started you'll first need a relational

  43. 1:23

    database I'm going with neon my go-to

  44. 1:25

    pick for a postgress database and the

  45. 1:27

    sponsor of today's video neon is awesome

  46. 1:29

    because it's easy to use there's a

  47. 1:31

    generous free tier and it even has a

  48. 1:33

    fast serverless driver with a drizzle

  49. 1:35

    adapter you don't even need to install

  50. 1:36

    postgress locally just create a new

  51. 1:38

    database on the dashboard both drizzle

  52. 1:40

    and neon are designed to run on any

  53. 1:42

    JavaScript runtime like node.js bun and

  54. 1:44

    Dino as well as Edge run times like

  55. 1:46

    cloudflare workers now install drizzle

  56. 1:48

    and your database driver then connect to

  57. 1:50

    the database in your typescript code we

  58. 1:52

    could start making queries now but we

  59. 1:53

    don't have any data yet first we need a

  60. 1:55

    schema create a schema file then Define

  61. 1:57

    tables with the PG table function each

  62. 1:59

    table table has a name followed by