5 ms·
I LOVE Prisma. I’ve used Django, SQLAlchemy, Sequelize, Knex, and TypeORM in the past. all had rough edges that continually frustrated me or didn’t provide the
by dickfickling 5y ago
I LOVE Prisma. I’ve used Django, SQLAlchemy, Sequelize, Knex, and TypeORM in the past. all had rough edges that continually frustrated me or didn’t provide the functionality i needed.
Prisma is different. It’s absolutely got rough edges, but the extremely strong type safety makes Sequelize look like a joke. The query engine itself, written in rust, combines and optimizes queries inside every tick of the event loop so GraphQL N+1 issues are a thing of the past.
Also, the team and community behind it are amazing! I never thought having an active dev community behind an ORM would be important, but as the author of Sequelize-Typescript was forced to abandon it late last year and the author of TypeORM was also pretty much absent, Prisma was a breath of fresh air. I REALLY hope they can find a way to build a sustainable business out of it. Support packages, feature development contracts, something to keep them financially incentivized to keep making it better.
Happy to answer any questions about my experience using it if anyone has any.
- brap 5y ago> GraphQL N+1 issues are a thing of the past. Huh, care to explain this one? I’m using Prisma with Apollo Server without doing anything fancy in my resolvers. I just assumed I’m getting N+1 issues but didn’t bother to optimize yet.
- dickfickling 5y agoin short the separate engine process allows them to combine every findX call you make during one tick of the event loop into a single SQL query, following the dataloader pattern, so you don’t have to implement it yourself. i’m sure @nikolasburk can shed some more light if you’re interested.
- eurasiantiger 5y agoI have a feeling that does not work at all in non-trivial scenarios, e.g. if both composite keys and date range matching are required to resolve a reference.
- sbarre 5y agoCould you test this and get back to us with the results?
- sorenbs 5y agoThere are pretty extensive docs on how Prisma optimises n+1 queries: https://www.prisma.io/docs/guides/performance-and-optimization/query-optimization-performance#n1-in-other-contexts https://www.prisma.io/docs/guides/performance-and-optimizati...
- eurasiantiger 5y agoThe examples are still for a trivial case of joining one thing to many things. What about joining one thing to many things that join to many things that join to one thing that joins to many things that join to many things that join to many things?
- Sujan 5y agoNo need to test really - indeed more complicated cases are not covered by this yet. But happy to look at any Github issues with reproduction of cases that are not working, but could or should work to make your life better.
- brap 5y agoVery interesting, thank you. Is there a way for me to monitor what Prisma is doing in my use case?
- dickfickling 5y agousing `new PrismaClient({ log: ["query"] });` it'll log all the actual sql queries it's running, so you'll be able to see if queries are being combined
- brap 5y agoAwesome, thanks! Turns out Prisma wasn’t optimizing my queries, I think it has to do with me not using the sub query API and instead querying tables seperately (e.g posts.findMany({ where: { owner: user } }))
- Sujan 5y agoPleeeeeease open an issue if you have a simple reproduction for this. That will make sure we will make sure this _does_ work (sooner or later, not committing to a timeline here on HN of course :p).
- tehlike 5y agoIf it's optimizing with figuring the calls in a single tick out, one can probably still optimize further by using db specific features, like postgres supports json_agg which let's you not only break n+1 in a way, but also prevents cartesian product explosion with joins
- hnjobaccount 5y agoFor the interested, here's an article that explains how the dataloader manages to pull this off https://www.mikealche.com/software-development/advanced-promises-in-javascript-building-a-simple-dataloader https://www.mikealche.com/software-development/advanced-prom...
- m007850 5y agoThis isn't true. Prisma currently only supports batching of findUnique queries: https://www.prisma.io/docs/guides/performance-and-optimization/query-optimization-performance#solving-n1-in-graphql-with-findunique-and-prismas-dataloader https://www.prisma.io/docs/guides/performance-and-optimizati... There's an issue open for findMany as well, but it hasn't moved in over a year: https://github.com/prisma/prisma/issues/1477 https://github.com/prisma/prisma/issues/1477
- Apofis 5y agoIs 933 open issues a warning sign? Seems excessive.
- eurasiantiger 5y ago> GraphQL N+1 issues are a thing of the past. This one I will believe when I see it. It would be a general solution to cache invalidation.
- mixedCase 5y agoYou can disable caching if that's a problem for your application. But the idea is that DataLoader simply holds onto promises that requested an entity, and fires them all in batches according to a scheduler function. In Node.js, the default is to use scheduler magic (relies on how the event loop works).
- hnjobaccount 5y agoHere's a small article that explains how the dataloader pattern works under the hood https://www.mikealche.com/software-development/advanced-promises-in-javascript-building-a-simple-dataloader https://www.mikealche.com/software-development/advanced-prom...
- mirthflat83 5y agoPrisma 2 is a delight to use. Gave it a try after typeorm-model-generator’s author suggested using something else than TypeORM. Prisma blows other JS/TS ORM libraries out of the water. It integrates so well with VS Code
- ragnese 5y agoTo be fair, Sequelize makes itself look like a joke. I normally wouldn't call out an individual library to shit on, because I understand that a lot of work has gone into it. But I used it for years and it was always buggy. Sometimes options wouldn't work correctly because the authors liked to do that clever JavaScript thing where they write `foo = optional_thing || default_value` even for BOOLEAN options. I always had issues with it not being able to truncate/drop tables correctly that had foreign keys (it didn't attempt to order them intelligently), some of the options weren't compatible with each other even though they were orthogonal (I'm thinking about the snake_casing options and the created_at/updated_at column features), etc, etc. It just... didn't actually work. Over many versions. I think I used it from late 3.x somewhere through 5.x. Maybe it's awesome now, but I doubt it.
- Capaj 5y agoNo it's not. Even if they fixed all the bugs which I doubt the API design is bad.
- ThalesX 5y ago> I normally wouldn't call out an individual library to shit on, because I understand that a lot of work has gone into it. I don't think I've ever called out on a library, or not felt truly thankful that it was there to help me. But Sequelize... man... When I first got into Node, and got Sequelize, after working for years with .NET, Entity Framework, NHibernate and the likes, it just felt like horrible-everything. I've forced myself to use it in some projects, because node is cheap, and I kept thinking that I'm missing something. Some brilliance behind the questionable... everything. No. I can't even bring myself to think about that design mess. Sorry for the rant, Sequelize makes me feel insecure, and little, in the chaos of the Universe.
- ragnese 5y agoSame. Honestly, I only have not-nice things to say about Node, JavaScript, and its ecosystem, so I should probably just shut up. But I was like you- I picked up Node because we had an existing project in it. It only used libraries that had the most "stars" or whatever on NPM and they were all pretty deficient (and some were shockingly slow). But none were so frustrating as Sequelize.
- bnt 5y agoLaravel has Eloquent and it’s an absolute delight to use. I’ve used Rails and Django, and I always felt as if I was fighting the ORM, where as with Eloquent everything just seems natural.
- joshmanders 5y agoI am a former PHP developer, absolutely loved Laravel and adored Eloquent as the ideal ORM. I switched to Node/JavaScript in 2015 and have been chasing a good ORM since, nothing could ever compare with Eloquent in Nodeland, I all but gave up and started building my own, in TypeScript to match Eloquent as much as possible. Then Nikolas Burk reached out to me and did his absolute best to convert me, but I was stuck in my ways, it HAD to behave like Eloquent, or it was not good enough and that DSL layer? No thanks, I don't like it. Started writing code for my own ORM when I was like "What the heck am I doing? this gets me nowhere" And messaged Nikolas back saying I was dropping everything and planned to give Prisma a real solid try. I'm so glad I did. I LOVE it now. I consider it a part of my GOAT stack.
- nikolasburk 5y ago:heart:
- nesarkvechnep 5y agoYou haven't mentioned the best query builder I've ever used - Elixir's Ecto. I encourage to give both Elixir and Ecto a try as they're worth learning.
- midrus 5y agoHaving used in the past both Django and Rails ORMs, I totally agree with this. Prisma is awesome, it's been the best experience I've ever had so far with SQL databases.
- wdb 5y agoI wish Prisma had built-in Opentelemetry support for tracing and metrics. They have a whole blog article about why monitoring is important but don't seem come with it: https://www.prisma.io/blog/monitoring-best-practices-monitor5g08d0b https://www.prisma.io/blog/monitoring-best-practices-monitor...
- wdb 5y agoIt's unclear what's the pros are of Prisma compared to TypeORM. I do find it confusing I always thought Prisma was GraphQL related.
- nikolasburk 5y ago> I do find it confusing I always thought Prisma was GraphQL related. This is a common misconception that stems from our history as a company and being early contributors to the GraphQL ecosystem. With the move to Prisma 2 however, there is no native GraphQL layer in Prisma any more. I've talked about this extensively in a recent livestream on Youtube [1] if you want to learn more :) There's also this article "How Prisma and GraphQL fit together" [2] that explains the historic dimensions of this if you're interested. > It's unclear what's the pros are of Prisma compared to TypeORM. I guess you could argue that one benefit is the superior type-safety Prisma provides [3]. Other folks have also called out that they prefer way how data is modeled with Prisma (via the Prisma schema), the migration system as well as the active maintenance, regular releases, the active community, the support and thorough documentation of Prisma. Ultimately it'll come down to your personal preference though which one is the more appropriate for your project :) [1] https://www.youtube.com/watch?v=hMWMPpy4ta4&list=PLz8Iz-Fnk_eTpvd49Sa77NiF8Uqq5Iykx&ab_channel=JasonLengstorf https://www.youtube.com/watch?v=hMWMPpy4ta4&list=PLz8Iz-Fnk_... [2] https://www.prisma.io/blog/prisma-and-graphql-mfl5y2r7t49c https://www.prisma.io/blog/prisma-and-graphql-mfl5y2r7t49c [3] https://www.prisma.io/docs/concepts/more/comparisons/prisma-and-typeorm#type-safety https://www.prisma.io/docs/concepts/more/comparisons/prisma-...
- jcrben 5y agoI skipped Prisma when I discovered that you were supposed to toss your schema in a single file. There's some ways to get around this but amazed that this is the official way