MikroORM should be on this list. Has all the benefits of an ORM, but lets you easily fall back to a Knex-like query builder when needed. And crucially, it's much better maintained than Sequelize or TypeORM
I watched this video again to remember the differences between certain libraries and ORMs so I made a list: 1. 1:30 pg 2. 3:24 postgres.js 3. 4:11 knex 4. 5:20 kysely 5. 6:13 sequelize 6. 7:11 typeorm 7. 7:55 prisma 8. 8:51 drizzle-orm May this be helpful to someone else as well.
I can understand the Web dev community generally straying away from writing raw SQL, but as an analyst moving to Javascript from having written primarily SQL for the past 6yrs it can be a bit frustrating that the whole ecosystem is based on trying not to do what I'm most comfortable doing - it feels like my mad SQL skills are being somewhat nullified! Great vid Jeff, I haven't seen postgres js before - I will defo be using it.
I'm not an analyst but I used to do a lot of raw sql and still find it easier to me than using ORMs especially for complex queries where (sub-queries, CTE, aggregation with OVER clause and maybe make use of sql variables, procedures, functions and temp tables) is needed. Simply I'm more comfortable with SQL and it's easier for my to translate my ideas directly into what the Database can understand natively. I feel you
Programmers hate being embarrassed. That's why they go to orms. It allows them to ignore the holes in their skill set while being able to goldplate over things for no reason to feel important. 100% ego.
@@matthewrutter8343 Maybe you have a point regarding the skill holes, but maybe it's the other way around as I myself find it very hard to memorize ORM methods, in the same time I can easily do what I want using raw SQL, this caused me some embarrassment in a project I was a member of, so to the others this was a hole in my skills. I'm a programmer with bad memory😎
The two reasons to use an ORM such as Prisma and TypeORM is so you get types for your code and so you don't have to update every single query when you update a column to a table.
@@furycorp I agree. It's more of a "pick your poison" issue with orms vs querybuilders vs sql clients although I would argue the last one is the less scaleable by far
I’m Angular+NestJS developer. For me TypeORM works perfectly. It allows me to model a pretty complex schema, run migrations and provides me with 3 levels of abstraction: high-level Repository pattern, mid-level QueryBuilder and low level raw SQL query. Does the job perfectly so far.
Best ORM is either no ORM or one that auto-generates the access layer based on the structure and types you've already defined in the database. Anything in between is just excess heat and trauma.
Have a lot of projects in production. Some of our codebase accesses MySql, PG and SQLite, so Knex is our definitive tool. Also it handles transactions like a charm.
Snuck in a video in response to the codedam issues with Prisma. Like your approach here - mentioning all pros and cons, going over each option. Great work!
Год назад+4
I'm currently using pg + postrgrator for migrations + sql-ts to generate types from DB. Works like charm. Type checking of sql is done by my IDE (intellij) anyway.
I also like what Supabase did with their new CLI, although not exactly an ORM. It generates typescript types for you based on the tables that you make inside of the dashboard, which you use with the SDK to make safe queries. One of the easiest ways to get a great DX with SQL in my opinion.
I was gonna try typeORM a year ago, but found many articles warning not to use it because it wasn't maintained and had lot of issues. I have tried sequelize, it's great but it needs a lot of setup and it doesn't fully support typescript. I was gonna try Prisma recently, but then someone said that it had issues too with the Rust engine and that there being too much "overhead" and that it was bad for joins. Not to mention that your code would be third party dependant, as Jeff stated. Would really like a video about the underlying structure and flow in ORMs and their tradeoffs, not just about syntax. Appreciate your work :)
Prisma only gives issues with the Rust backend if you plan on deploying it on a lambda function or using serverless in general. And you can still solve all of these issues, it just requires more work and it's not "out of the box".
You should try Kysely. Its all about trying to be 1:1* to compiled SQL (WYSIWYG design principle) and aims at supporting advanced functionality ORMs just don't bother going into or can't.
Absolutely. Plain SQL with prepared statements all the way. ORMs solve one problem while making a giant headache of everything else, other than maybe migrations. I don't know why the most widely adopted approach to a vulnerability was to abstract away the entire language.
If you need advanced postgresql like views, materialized views, PostGIS I would recommend to use pg, choosing the right ORM depends on your project requirements so you must study first what features you will need and do research for the best of your needs
in my opinion they are all good options and I would just look at what saves me the most time and works good with typescript. So I usually go with prisma :) Having said that if you are just a beginner you might wanna go with the orm's that you have to use raw SQL so you know how everything works.
For Postgres PgTyped is an awesome project. You write bare SQL and it typeschecks agains the databse and generates query methods that are comletely typesafe, even with complex joins or recursive queries.
This is how god intended us to use databases. Its so simple, so powerful, such superior performance. It's just amazing how long this approach took to surface, and how little known it is.
My conclusion is that as long as you use raw SQL with the chosen ORM's raw method, you will have control over the performance. However, when you start using their innerJoin built-in methods, you may encounter performance issues. Nonetheless, using raw SQL for complex queries defeats the purpose of using an ORM. This raises the question of which ORM to use that provides a good migration tool and a well-defined schema with types. I believe ORMs are suitable for simple projects, but when it comes to large projects with complex queries and performance optimization requirements, they may not be ideal. Therefore, you will most like be using the ORM for defining schemas and migrations and writing raw SQL for most queries.
You should try a query builder like Kysely instead of going raw SQL in complex queries. We're trying to be 1:1* with compiled SQL and go deeper than ORMs usually do - as long as it can be implemented in a type-safe way.
The first 20 seconds are the most accurate stuff ever. I start with MSSQL and then switched to MongoDB and I was like "Yeah this is the best, I will never go back to sql" yeah but ... years later I'm now working only with MySql and I like it way more then mongo ... Currently using sequelize and the work is so easy to do.
I'm developing a webapp and used MongoDB Atlas for it and Mongoose makes my life easier. But then I realized I'm better off with a relational database because there's a lot of relational data on my backend. I chose Postgres and studied Sequalize and I like how Sequalize is very similar to Mongoose. However, I also came to the conclusion that Supabase will make my project easier to maintain. So I signed for Supabase only to notice that there's no ORM for it. Everything is interfaced through the Supabase API. To manipulate data before they get stored in the database, you would need to write database functions, edge functions and triggers. Creating schemas, constraints, indexes, and RLS policies need to be written in SQL (though some of these can be done through the UI). Supabase was supposed to simplify a lot of stuff, but I'm finding it time-consuming to set up a lot of things. Why can't it be as easy a Sequalize?
@@foreach1 You can only use these ORMs if you have a server-side middle layer between the client and supabase. But obviously if you do that, then why not just use a self-hosted Postgres cluster? We use Supabase for the ability to remove the server-side middle layer. So it's just Supabase and client-side. And you can't really use any ORM for any of these sides. I actually like that approach and I can see it being easier to maintain in the long run. But damn the set up is hard. Migration is hard. Supabase docs are garbage. And Supabase tutorials on RUclips doesn't really cover the very specific database needs/designs that I have. Though I'm pretty sure if I study this more for several more days I can finally get the hang of it.
Out of every ORM I've ever used, my favorite experience was using Ecto [Elixir programming language]. Note that this language, and also ORM, have a pretty steep learning curve, so it can seem obtuse at first. Other ORMs I've used include Django, SQL Alchemy, ActiveRecord, and a couple JavaScript ones.
Hi! I just wanted to add another perspective regarding ORMs. My experience is that they should be considered anti-pattern and I can outline the reasons why: 1. they won't excuse developers from having to understand good database design and proper querying and, most often, introduce N+1 problem through that naivete 2. they encourage direct table access with what amounts to adhoc SQL which ties the hands of database developers when the need arises to reorganize data for scale and performance 3. most relational databases offer things like functions, stored-procs and prepared statements which parameterize queries to solve things like: a. combating sql injection b. providing an access layer tier above base tables which: i. provides API-like access and ii. grants the freedom to re-org base tables as needed iii. simplified access-level authorization Those are the main points (there are others). Whether an ORM is used or not, there is no escape from getting to know your serialization (storage) layer well. You should be using functions or stored-procs as access points to your database regardless. Which then begs the question, why do you even need an ORM?
Sequelize does actually support Typescript if you look through the docs, but it's annoying to set up and mostly scuffed in my experience. It's not an easy drop in.
ORMs are one of those things that aren't worth the trouble in the long run. They can be nice in a quick prototype, but for an app that lives for at least a few years, you'll inevitably start bumping into performance issues or weird ORM behaviour that costs a lot of time to resolve. The first time I encountered an ORM I thought it was magic, but after 15+ years in the business, I no longer find them worth the trouble. Writing raw SQL isn't that hard and as long as you use parameterized statements, much less likely to bite you in the end. Save your future self the headache and start with a low level library.
Typeorm doesn't give full type safety. Even when you pass selective columns in select option for find method, the return type will still be array of entity and not array of those selective columns.
“joist-ts” is an awesome option for graphql + Postgres - has dataloader built in so any graph queries are N+1 safe. Reminds me a lot of ActiveRecord for Rails
0:38 using libraries & ORMs to access SQL to: * get IDE language server completions * migrations * connect to db * handle security * madelling relationships in data
After 15 years of backend development (on the JVM though), I'll take a query builder over an ORM every time. Also: Migrations "down" are usually not worth your time (how to roll back a dropped column or table anyway?)
I've been looking into ORMs as a way of writing better VBA apps. I know, I know, VBA... eww. However, some companies think open source is scary, so Excel is the only tool... blah blah blah... Creating typed objects that represent rows and tables in databases with parameterized crud sql operations saved in a local folder, and a client wrapper object to establish the connection to, query and creation of objects containing data pulled from databases has been some of the most fun I've had in years. All of these modules give different DX, and that's great. However, I think the overreliance of abstractions on abstractions makes the process of learning JS and TS a nightmare for new devs. No one understands the language and instead only understands the framework/module/package and probably only a small fraction of that at that. Rolling my own ORMish thing in a language that doesn't has been a fantastic learning experience and has made connecting to data in my apps a breeze. BTW, I modeled my VBA classes after the generated prismaClient and it's beautiful. Of course implementing a schema hook file and making a VBA_ORM reference library that could do migrations and client generation would be phenomenal, but that's not going to be for some time. Great video as always!
At my dayjob the application teams write raw SQL queries because they can't replace the ancient ORM that came with the framework. Some developer wrote an abstraction library over the database connector that is actually quite nice. You construct a Query object. For example new GetUserById(id); And then do $q->result($db); which yields you the User object you were looking for. Or null.
Prisma internally has large overhead because of all these abstraction layers, a regular SELECT query took over 100 ms while an identical query in TypeORM took 10 ms or so
the first is point is too true, i learnt mysql in school, jumped ship to nosql dbs in college, realised yesterday sql was the solution all along, watching this vid today 🤣🤣
Trust me, you don't want to bother with sequelize if you're using typescript. It just causes so many weird bugs, is not documented as well as it looks at first glance (many options objects are not specified in the api documentation, at least when i last used it), and forget it if you want to write a complicated query.
But TypeORM has a lot of bugs, Prisma is not a good choice for complex app, now we have only MikroORM (which some programmers recommend as a great choice), but I don't see large companies in real life using this ORM. And finally, we have query builders like knex or database drivers to write raw SQL queries.
@@tristan7668 You should try Kysely. It's inspired by Knex, but is type-safe first, immutable, predictable, extensible, and probably more expressive at this point.
Enjoying using Prisma along with Redwood JS at the moment, but the lack of support for PostGIS and spatial types is a bit of a drawback at the moment. Hopefully that support comes soon.
Until you need to do some things dynamically, conditionally or repetitively, and end up maintaining your own query builder. Just use a query builder. :)
@@igalklebanov921 I agree with that. I had some code that involved string concatenations to form an and string for an internal data science application. I began using a query builder right before I left to replace that annoying and unsafe code.
I kinda prefer Knex because it gives me control and everything still looks and feels like SQL. Very transparent in its use. No need to figure out how joins work in an ORM or if it does expensive sub-queries. I'm responsible for optimizing it, and... ChatGPT is also familiar with it.
@@abhinavadarsh7150 and a big pocket once your business grows cause you'll have to foot that bill for those terrible SQL it generates to make all that magic possible!
Well, with Rust and SQLx' Macros you'll get that sweet love from the IDE as well. This amazing library allows your IDE to tell you at edit-time, that your SQL either doesn't match the DB schema or your DTO don't match what you're requesting (i.e. type wise). And I think that's beautiful
I used Prisma for several months and I love it because of its easy interfaces but it had some drawbacks: 1. I had to copy large rust binaries into a image when using docker 2. Also had to generate a prisma client file by running `prisma generate` Totally, it was a MAGIC and similar to how I felt when I was using Rails. I'll try Drizzle.
Been playing with Prima and GORM (Go). The amount of time I’ve spent setting them up and tweaking them instead of just working on my MVP with the few CRUD statements I actually need is…not great. I guess I like the idea cause for some reason I think I need to be able to change my database on a whim.
I'm disappointed by not seeing MikroORM on the list. For me personally it's the best tool with true ORM features in NodeJS. It does not invent anything new in particular and is based on solid, battle tested ORMs from other languages like Hibernate and Doctrine. I migrated a project to MikroORM 2 months ago from Prisma and I'm really glad I did. It makes writing domain-oriented backends pretty fun. I really hope it'll get some more attention soon, especially that it is developed and mantained just by Martin Adamek in his free time, so just imagine how cool it would be if he was supported by more people financially and could give more of his time for this awesome project.
I agree, I wonder why people talk about drizzle so much (ofc it is also another awesome tool, but for different use-cases) when Mikro has been on the market for quite a while and receives great opinions from its users.
@@skyhappy I'm not saying it is better in every aspect. As with every tool that is used, has at least some popularity and is not forgotten there has to be something great about the tool so people use it. It's like saying that JS is bad because ex. in building backends that require the quickest response time possible it sucks. The statement is true in this case, but overall JS has its advantages in other parts of software development and therefore it is one of the most popular languages. But, comming back to ORMs, prisma has great DX, awesome documentation and support. However there are some things I do not like about it: 1. Prisma schema is great for defining DB structure, but in larger projects with many models it becomes cluttered and there is no official support for splitting it up into more files yet 2. Prisma does not allow to map DB tables to domain classes and vice-versa so in order to write domain-oriented code you have to write domain-persistence mappers on your own 3. Prisma does not have a change tracker, so with prisma you always have to explicitly track what has changed and give it to prisma query These are just the most important things I've noticed using Prisma but there are more like transactions, UoW etc. I'll still use Prisma in smaller projects or in those in domain is not complicated, but in other cases I'll stick to MikroORM.
I think the problem with Mikro is that it has a really good DX but while scaling you learn that it is a lot slower than other ORMs/Query Builders. Prisma and TypeORM are not really fast either but at least faster. Knex is okay with own interfaces but a pain to setup but super fast. Drizzle combines the performance of knex while trying to imitate the DX of the best tools in the JS-ecosystem and is I think rightfully in all discussions currently. Disclaimer: We don‘t use it and moved away from sequelize and a test with TypeORM to knex due to performance issues.
The real ORM is the friends we made along the way -- Our Real Mates
Nice sql comment at the end there. Very explanatory.
It's about the vulnerabilities we made along the way
eval(node run test)
And Tables We Dropped
I made friends with ChatGPT along the way
0:20 (S-Q-L), 0:31 (Squeal), 0:52 (Sequel) He pronounced SQL all three different ways so everyone is happy 😂
Or everyone angry
don't tell that to @ThePrimagean, clearly only one of those is truly correct
Squirrel gang
gold
I just wanted to point that out. My brain was like "dafuq am I hearing?!?" 🤣
The timing of this video is impeccable. Been spending the last few days looking into these ORMs
same, and I'm learning towards drizzle
same x2
Same x3
just write SQL
Been using sequelize and typeorm recently
MikroORM should be on this list. Has all the benefits of an ORM, but lets you easily fall back to a Knex-like query builder when needed. And crucially, it's much better maintained than Sequelize or TypeORM
yep, really a shame that mikro orm is not well known, its superb
It’s amazing. Like the best thing ever. The only sad thing is that there’s like one maintainer/creator. The guy is amazing ❤
I agree! And MikroORM works great with MongoDB too.
Definetely agree
Yes, B4nan is a superhero
Breaking world record for most useful information per second of video each time you post someting. Respect, Sir!
This video is so well timed, I was literally transitioning from Firestore to Postgres database with a project just now.
Bro same 😂
what if i tell you that he has all our search data. its not by coincidence
I watched this video again to remember the differences between certain libraries and ORMs so I made a list:
1. 1:30 pg
2. 3:24 postgres.js
3. 4:11 knex
4. 5:20 kysely
5. 6:13 sequelize
6. 7:11 typeorm
7. 7:55 prisma
8. 8:51 drizzle-orm
May this be helpful to someone else as well.
+1, need those youtube chapters
exactly what I was looking for, thx
pg-native should be faster in theory.
MikroORM is awesome and deserve more love. It does what all these ORM do and is battle tested, fast, and well maintained.
I have been looking into MikroORM and confused why it doesn't get much attention and review by the community.
I can understand the Web dev community generally straying away from writing raw SQL, but as an analyst moving to Javascript from having written primarily SQL for the past 6yrs it can be a bit frustrating that the whole ecosystem is based on trying not to do what I'm most comfortable doing - it feels like my mad SQL skills are being somewhat nullified!
Great vid Jeff, I haven't seen postgres js before - I will defo be using it.
I'm not an analyst but I used to do a lot of raw sql and still find it easier to me than using ORMs especially for complex queries where (sub-queries, CTE, aggregation with OVER clause and maybe make use of sql variables, procedures, functions and temp tables) is needed.
Simply I'm more comfortable with SQL and it's easier for my to translate my ideas directly into what the Database can understand natively.
I feel you
You should give Kysely a try. We focus on 1:1* and have CTEs, window functions, etc. But also type-safety and autocompletion.
@@igalklebanov921 Looks nice and intuitive for one with average sql background,
I'll give it a try once I have a chance.
Thanks
Programmers hate being embarrassed. That's why they go to orms. It allows them to ignore the holes in their skill set while being able to goldplate over things for no reason to feel important. 100% ego.
@@matthewrutter8343 Maybe you have a point regarding the skill holes, but maybe it's the other way around as I myself find it very hard to memorize ORM methods, in the same time I can easily do what I want using raw SQL,
this caused me some embarrassment in a project I was a member of, so to the others this was a hole in my skills.
I'm a programmer with bad memory😎
This guy has the most useful content, without wasting any time.
1. 1:30 pg
2. 3:24 postgres.js
3. 4:11 knex
4. 5:20 kysely
5. 6:13 sequelize
6. 7:11 typeorm
7. 7:55 prisma
8. 8:51 drizzle-orm
Hours of research without real outcome and then one video and I know what to choose.
You're my favorite RUclipsr for a reason. 😋
The two reasons to use an ORM such as Prisma and TypeORM is so you get types for your code and so you don't have to update every single query when you update a column to a table.
In my experience with anything beyond a todo list both of those fall apart and have a lot of oversights that are a pain in the ass.
@@furycorp I agree. It's more of a "pick your poison" issue with orms vs querybuilders vs sql clients
although I would argue the last one is the less scaleable by far
prisma is okey for hobby simple projects but will fall out of hands when it gets complex with logic. Also there is no native joins.
prisma won't scale up
TypeORM is the only ORM that actually makes sense because Java uses a similar pattern and Java is Holy.
I’m Angular+NestJS developer. For me TypeORM works perfectly. It allows me to model a pretty complex schema, run migrations and provides me with 3 levels of abstraction: high-level Repository pattern, mid-level QueryBuilder and low level raw SQL query. Does the job perfectly so far.
After experience with most of orms, Objection has the best developer experience with great performance
Have you tried Kysely? koskimas is the author behind both of them. :)
Best ORM is either no ORM or one that auto-generates the access layer based on the structure and types you've already defined in the database. Anything in between is just excess heat and trauma.
Have a lot of projects in production. Some of our codebase accesses MySql, PG and SQLite, so Knex is our definitive tool. Also it handles transactions like a charm.
Great video. I'd enjoy an overview of ORMs in other languages too, such as SqlAlchemy, Entity Framework, etc.
Snuck in a video in response to the codedam issues with Prisma. Like your approach here - mentioning all pros and cons, going over each option. Great work!
I'm currently using pg + postrgrator for migrations + sql-ts to generate types from DB. Works like charm. Type checking of sql is done by my IDE (intellij) anyway.
Rails, Django, Laravel, and Phoenix developers:
Yay!! We don't have to deal with this JavaScript madness.
then they face problems in scaling
@@sushantjain3360 not every project is going to be instagram
@@sushantjain3360 Not something for Phoenix (Elixir). Scalability in the blood of language.
@@sushantjain3360
if you can't scale with phoenix, you won't scale with anything else
I also like what Supabase did with their new CLI, although not exactly an ORM. It generates typescript types for you based on the tables that you make inside of the dashboard, which you use with the SDK to make safe queries. One of the easiest ways to get a great DX with SQL in my opinion.
I was gonna try typeORM a year ago, but found many articles warning not to use it because it wasn't maintained and had lot of issues. I have tried sequelize, it's great but it needs a lot of setup and it doesn't fully support typescript. I was gonna try Prisma recently, but then someone said that it had issues too with the Rust engine and that there being too much "overhead" and that it was bad for joins. Not to mention that your code would be third party dependant, as Jeff stated.
Would really like a video about the underlying structure and flow in ORMs and their tradeoffs, not just about syntax. Appreciate your work :)
Prisma only gives issues with the Rust backend if you plan on deploying it on a lambda function or using serverless in general. And you can still solve all of these issues, it just requires more work and it's not "out of the box".
Typeorm is actively maintained at the moment. There was a year or so where things were stable, but since v0.3 it's been fairly regularly updated.
the only issue with Prisma is when using server less. thats the only problem. if you're not using server less then you're perfectly fine.
I'm back to just SQL..
I prefer writing raw sql queries. Orm tend to make simple things simpler and hard things harder
You should try Kysely. Its all about trying to be 1:1* to compiled SQL (WYSIWYG design principle) and aims at supporting advanced functionality ORMs just don't bother going into or can't.
I agree with you. Also debugging raw queries is much easier as you copy the sql string and execute it manually.
Absolutely. Plain SQL with prepared statements all the way. ORMs solve one problem while making a giant headache of everything else, other than maybe migrations. I don't know why the most widely adopted approach to a vulnerability was to abstract away the entire language.
@@MinibossMakaque I will never fucking understand the insanity of ORM. Literally makes everything worse, a useless abstraction.
Except when you have tons and tons of complex queries and that sometimes occupy and entire file
A video about correct ways to hande migrations for multiple teams would be very handy!
use rails/laravel/django
everyone can do their own migrations & it rarely conflicts
If you need advanced postgresql like views, materialized views, PostGIS
I would recommend to use pg, choosing the right ORM depends on your project requirements so you must study first what features you will need and do research for the best of your needs
Man That Ending !!! Super
in my opinion they are all good options and I would just look at what saves me the most time and works good with typescript.
So I usually go with prisma :)
Having said that if you are just a beginner you might wanna go with the orm's that you have to use raw SQL so you know how everything works.
prisma won't scale up
@@ooogabooga5111 hey what about drizzle
@@ooogabooga5111 How is that so? I use prisma on applications with 3M MAU. Loads pretty fast for everyone
I was less inclined to watch this earlier but, hey man, you rocks. Lots of clear and concise stuff in the video.
lol, the ending was perfect :D well done Mr Fireship
drumroll to commercials, well played mastery.
Absolutely love intro!!!!
For Postgres PgTyped is an awesome project. You write bare SQL and it typeschecks agains the databse and generates query methods that are comletely typesafe, even with complex joins or recursive queries.
This is how god intended us to use databases. Its so simple, so powerful, such superior performance. It's just amazing how long this approach took to surface, and how little known it is.
damn. I just learned about PgTyped, thanks to this comment. it is a gods gift.
My conclusion is that as long as you use raw SQL with the chosen ORM's raw method, you will have control over the performance. However, when you start using their innerJoin built-in methods, you may encounter performance issues. Nonetheless, using raw SQL for complex queries defeats the purpose of using an ORM. This raises the question of which ORM to use that provides a good migration tool and a well-defined schema with types. I believe ORMs are suitable for simple projects, but when it comes to large projects with complex queries and performance optimization requirements, they may not be ideal. Therefore, you will most like be using the ORM for defining schemas and migrations and writing raw SQL for most queries.
You should try a query builder like Kysely instead of going raw SQL in complex queries. We're trying to be 1:1* with compiled SQL and go deeper than ORMs usually do - as long as it can be implemented in a type-safe way.
Love the ending :)
The first 20 seconds are the most accurate stuff ever. I start with MSSQL and then switched to MongoDB and I was like "Yeah this is the best, I will never go back to sql" yeah but ... years later I'm now working only with MySql and I like it way more then mongo ... Currently using sequelize and the work is so easy to do.
Nice to have Eloquent ORM baked right in the Laravel Framework providing all of these and more features out of the box.
I'm developing a webapp and used MongoDB Atlas for it and Mongoose makes my life easier. But then I realized I'm better off with a relational database because there's a lot of relational data on my backend. I chose Postgres and studied Sequalize and I like how Sequalize is very similar to Mongoose. However, I also came to the conclusion that Supabase will make my project easier to maintain. So I signed for Supabase only to notice that there's no ORM for it. Everything is interfaced through the Supabase API. To manipulate data before they get stored in the database, you would need to write database functions, edge functions and triggers. Creating schemas, constraints, indexes, and RLS policies need to be written in SQL (though some of these can be done through the UI). Supabase was supposed to simplify a lot of stuff, but I'm finding it time-consuming to set up a lot of things. Why can't it be as easy a Sequalize?
Supabase is a normal Postgress db. You can use any orm you want with it
@@foreach1 You can only use these ORMs if you have a server-side middle layer between the client and supabase. But obviously if you do that, then why not just use a self-hosted Postgres cluster? We use Supabase for the ability to remove the server-side middle layer. So it's just Supabase and client-side. And you can't really use any ORM for any of these sides. I actually like that approach and I can see it being easier to maintain in the long run. But damn the set up is hard. Migration is hard. Supabase docs are garbage. And Supabase tutorials on RUclips doesn't really cover the very specific database needs/designs that I have. Though I'm pretty sure if I study this more for several more days I can finally get the hang of it.
Out of every ORM I've ever used, my favorite experience was using Ecto [Elixir programming language]. Note that this language, and also ORM, have a pretty steep learning curve, so it can seem obtuse at first. Other ORMs I've used include Django, SQL Alchemy, ActiveRecord, and a couple JavaScript ones.
Quarkus reactive is pretty sweet. But for sheer performance Go and Elixir libraries seem unbeatable.
ok nerd we know that u use 'elixir'
Thank you. Perfect timing, that exactly what i'm looking for.
Awesome video! And amazing that you're giving a free consultation, people should flock for that!
sequelize has been my go to for small project for about 5 years.
When using pg, run your migrations and then use schemats to dynamically generate typescript types from the db itself for great type safety.
Using intellij sql intellisense in the code is way better than every orm can ever been.
🤮
well damn.
ORMs are cancer
Hi! I just wanted to add another perspective regarding ORMs. My experience is that they should be considered anti-pattern and I can outline the reasons why:
1. they won't excuse developers from having to understand good database design and proper querying and, most often, introduce N+1 problem through that naivete
2. they encourage direct table access with what amounts to adhoc SQL which ties the hands of database developers when the need arises to reorganize data for scale and performance
3. most relational databases offer things like functions, stored-procs and prepared statements which parameterize queries to solve things like:
a. combating sql injection
b. providing an access layer tier above base tables which:
i. provides API-like access and
ii. grants the freedom to re-org base tables as needed
iii. simplified access-level authorization
Those are the main points (there are others). Whether an ORM is used or not, there is no escape from getting to know your serialization (storage) layer well. You should be using functions or stored-procs as access points to your database regardless. Which then begs the question, why do you even need an ORM?
The issues that you've mentioned using raw SQL queries can be solved by using SafeQL. Zero abstractions, zero runtime code.
Yes, please. The best ORM is no ORM 🙂👍
@@RasmusSchultz Agreed
No SafeQL for MariaDB? bleh
Hey there fireship, sequelize doesn't support typescript but there's a new sequelize-typescript that does, it would've been nice if you did that.
Sequelize does actually support Typescript if you look through the docs, but it's annoying to set up and mostly scuffed in my experience. It's not an easy drop in.
@@Ke5o it was so scuffed that they need to re-write most of the features when releasing v7
Awesome job Jeff. Thanks for creating such a concise and entertaining video.
ORMs are one of those things that aren't worth the trouble in the long run.
They can be nice in a quick prototype, but for an app that lives for at least a few years, you'll inevitably start bumping into performance issues or weird ORM behaviour that costs a lot of time to resolve.
The first time I encountered an ORM I thought it was magic, but after 15+ years in the business, I no longer find them worth the trouble. Writing raw SQL isn't that hard and as long as you use parameterized statements, much less likely to bite you in the end.
Save your future self the headache and start with a low level library.
Typeorm doesn't give full type safety. Even when you pass selective columns in select option for find method, the return type will still be array of entity and not array of those selective columns.
Drizzle for the next Project.
Love the memes you put in the beginning ! 😂😂😂😂
I found typeorm best, as its provides class based type safety insertion also it has query builder options
“joist-ts” is an awesome option for graphql + Postgres - has dataloader built in so any graph queries are N+1 safe. Reminds me a lot of ActiveRecord for Rails
Long live typesafe query builders (aka Kysley and Drizzle ORM)
yassssssssss
this is gonna be very useful for my typescript api, living and leaning...
prisma is the GOATEST
0:38 using libraries & ORMs to access SQL to:
* get IDE language server completions
* migrations
* connect to db
* handle security
* madelling relationships in data
Thank you for the video, it's very helpful
After 15 years of backend development (on the JVM though), I'll take a query builder over an ORM every time.
Also: Migrations "down" are usually not worth your time (how to roll back a dropped column or table anyway?)
Eloquent is not that bad tbf
Same. I used Spring Data JPA back in the day until I discovered jOOq.
Thank you so much for this was struggling to choose an ORM to use till now
0:30 he said it properly. Squeal. ❤
Alright, now just to figure out how to shove a frickin' matress into my backend so my project won't fail. Thanks for the advice!
Joist is also interesting. It really focusses on great Typescript and lazy loading support while also automatically solving n+1 problems.
@beyondfireship.. lmao
I love the "Data Suppository". :D
being a laravel developer feels like a ghoast or a stranger when you watch these videos
Been using sequelize, and typeorm and typeorm is the most comfortable to me
I've been looking into ORMs as a way of writing better VBA apps. I know, I know, VBA... eww. However, some companies think open source is scary, so Excel is the only tool... blah blah blah...
Creating typed objects that represent rows and tables in databases with parameterized crud sql operations saved in a local folder, and a client wrapper object to establish the connection to, query and creation of objects containing data pulled from databases has been some of the most fun I've had in years.
All of these modules give different DX, and that's great. However, I think the overreliance of abstractions on abstractions makes the process of learning JS and TS a nightmare for new devs. No one understands the language and instead only understands the framework/module/package and probably only a small fraction of that at that.
Rolling my own ORMish thing in a language that doesn't has been a fantastic learning experience and has made connecting to data in my apps a breeze. BTW, I modeled my VBA classes after the generated prismaClient and it's beautiful. Of course implementing a schema hook file and making a VBA_ORM reference library that could do migrations and client generation would be phenomenal, but that's not going to be for some time.
Great video as always!
Prisma for migrations (ddl), Kyseley for interactions (dml)
❤from Kysely.
Thank you man. This is really helpful.
At my dayjob the application teams write raw SQL queries because they can't replace the ancient ORM that came with the framework. Some developer wrote an abstraction library over the database connector that is actually quite nice. You construct a Query object. For example new GetUserById(id); And then do $q->result($db); which yields you the User object you were looking for. Or null.
Prisma internally has large overhead because of all these abstraction layers, a regular SELECT query took over 100 ms while an identical query in TypeORM took 10 ms or so
Jeff And Ozzyman are my most favourite Australians ❤️
I personally love supabase‘s approach best - you have a GUI to create and update tables or columns
the first is point is too true, i learnt mysql in school, jumped ship to nosql dbs in college, realised yesterday sql was the solution all along, watching this vid today 🤣🤣
That snoop dogg line was absolute gold.
Trust me, you don't want to bother with sequelize if you're using typescript. It just causes so many weird bugs, is not documented as well as it looks at first glance (many options objects are not specified in the api documentation, at least when i last used it), and forget it if you want to write a complicated query.
But TypeORM has a lot of bugs, Prisma is not a good choice for complex app, now we have only MikroORM (which some programmers recommend as a great choice), but I don't see large companies in real life using this ORM. And finally, we have query builders like knex or database drivers to write raw SQL queries.
@@tristan7668 You should try Kysely. It's inspired by Knex, but is type-safe first, immutable, predictable, extensible, and probably more expressive at this point.
that clifhanger man, still waiting for the final result :D :D lol
Enjoying using Prisma along with Redwood JS at the moment, but the lack of support for PostGIS and spatial types is a bit of a drawback at the moment. Hopefully that support comes soon.
Prisma has a very good documentation and developer experience. I recommend it over the others. It is very easy to setup and to use.
It looks pretty interesting
It has no sql joins. Horrible
@@md.redwanhossain6288 of course it has support for joins. Rtfm.
prisma so slow
I worked at a company that did everything with raw sql. We had a about 100 tables and it worked great. This is not a typical apparently.
Until you need to do some things dynamically, conditionally or repetitively, and end up maintaining your own query builder. Just use a query builder. :)
@@igalklebanov921 I agree with that. I had some code that involved string concatenations to form an and string for an internal data science application. I began using a query builder right before I left to replace that annoying and unsafe code.
@@igalklebanov921 NextJS 13 exists
TypeORM does the job. Prisma is just not ready for what I need. And that is what is most important.
I can just tell you are a boyscast listener by some of your phrases and I love it.
I kinda prefer Knex because it gives me control and everything still looks and feels like SQL. Very transparent in its use. No need to figure out how joins work in an ORM or if it does expensive sub-queries. I'm responsible for optimizing it, and... ChatGPT is also familiar with it.
You should try Kysely. It's inspired by Knex, but is type-safe first, immutable, predictable, extensible, and probably more expressive at this point.
❤ from Kysely.
Entity framework + LINQ, saves you a ton
Once you started using prisma you never go back ❤
Unless you started having serious performance issues.
@@abhinavadarsh7150 and a big pocket once your business grows cause you'll have to foot that bill for those terrible SQL it generates to make all that magic possible!
Well, with Rust and SQLx' Macros you'll get that sweet love from the IDE as well.
This amazing library allows your IDE to tell you at edit-time, that your SQL either doesn't match the DB schema or your DTO don't match what you're requesting (i.e. type wise).
And I think that's beautiful
I don't see how is it different than kysely. also check zio-sql
I am quite happy with Prisma. They did an amazing job.
Prisma is awesome while you’re not using geometry types 😢 also migrations is still a bit vague
Is the one and only .... that works for you best !
just what i needed
I used Prisma for several months and I love it because of its easy interfaces but it had some drawbacks:
1. I had to copy large rust binaries into a image when using docker
2. Also had to generate a prisma client file by running `prisma generate`
Totally, it was a MAGIC and similar to how I felt when I was using Rails.
I'll try Drizzle.
kysely and drizzle are great.
❤ from Kysely.
"With great abstraction, comes great dependency."
- Uncle Ben
I worked extensively in one of the ORM that’s Eloquent which Laravel uses which is a PHP framework
and there i thought that knex was just a childrens construction toy
Lool man really knows his audience... also was that knex huge security problem patched
Been playing with Prima and GORM (Go). The amount of time I’ve spent setting them up and tweaking them instead of just working on my MVP with the few CRUD statements I actually need is…not great. I guess I like the idea cause for some reason I think I need to be able to change my database on a whim.
I'm disappointed by not seeing MikroORM on the list. For me personally it's the best tool with true ORM features in NodeJS. It does not invent anything new in particular and is based on solid, battle tested ORMs from other languages like Hibernate and Doctrine. I migrated a project to MikroORM 2 months ago from Prisma and I'm really glad I did. It makes writing domain-oriented backends pretty fun. I really hope it'll get some more attention soon, especially that it is developed and mantained just by Martin Adamek in his free time, so just imagine how cool it would be if he was supported by more people financially and could give more of his time for this awesome project.
I agree, I wonder why people talk about drizzle so much (ofc it is also another awesome tool, but for different use-cases) when Mikro has been on the market for quite a while and receives great opinions from its users.
Why is it better than prisma
@@skyhappy I'm not saying it is better in every aspect. As with every tool that is used, has at least some popularity and is not forgotten there has to be something great about the tool so people use it. It's like saying that JS is bad because ex. in building backends that require the quickest response time possible it sucks. The statement is true in this case, but overall JS has its advantages in other parts of software development and therefore it is one of the most popular languages. But, comming back to ORMs, prisma has great DX, awesome documentation and support. However there are some things I do not like about it:
1. Prisma schema is great for defining DB structure, but in larger projects with many models it becomes cluttered and there is no official support for splitting it up into more files yet
2. Prisma does not allow to map DB tables to domain classes and vice-versa so in order to write domain-oriented code you have to write domain-persistence mappers on your own
3. Prisma does not have a change tracker, so with prisma you always have to explicitly track what has changed and give it to prisma query
These are just the most important things I've noticed using Prisma but there are more like transactions, UoW etc. I'll still use Prisma in smaller projects or in those in domain is not complicated, but in other cases I'll stick to MikroORM.
I think the problem with Mikro is that it has a really good DX but while scaling you learn that it is a lot slower than other ORMs/Query Builders. Prisma and TypeORM are not really fast either but at least faster.
Knex is okay with own interfaces but a pain to setup but super fast. Drizzle combines the performance of knex while trying to imitate the DX of the best tools in the JS-ecosystem and is I think rightfully in all discussions currently. Disclaimer: We don‘t use it and moved away from sequelize and a test with TypeORM to knex due to performance issues.
Pls is MikroORM totally free?
DTD lmfao, you are the funniest guy in CS
I don’t recommend using typeorm, as queries get complex doesn’t handle relations well and we have had some issues with the heap memory in production.
Which ones would you recommend and in what order?