4 ms·
The reasons you want an ORM or query builder: Reuseability and composeability. In Django for example, you can compose querysets and reuse them in Forms, Admin,
by bayesian_horse 4y ago
The reasons you want an ORM or query builder: Reuseability and composeability. In Django for example, you can compose querysets and reuse them in Forms, Admin, Templates, wherever. You can also generate Forms and Admin out of nothing but the model class.
Most frameworks are way behind Django/Django Rest Framework in that regard. I'm not saying there aren't any others doing something similar, NestJs for example. But I'm not aware on other solutions.
- bitexploder 4y agoYou can achieve this without an ORM, but having composable query bits and abstractable querying to the programming language and not directly SQL is really nice. Objects map fine to relational hierarchies so I am not so worried about design constraint. Rust Diesel can go between pure ORM and a more composable query layer. SQLAlchemy also exposes such functionality when you don’t want to fully embrace ORM, but also don’t want to throw out some reuse and composability.
- megaman821 4y agoIf you have composable query bits, have you just not rolled your own query builder? As you pointed out most ORMs have a query builder layer anyway and usually a raw sql layer too. Why not use an ORM for the easy bits?
- bitexploder 4y agoI would not roll it myself. That was my point about some ORM frameworks offering a middle ground, which is often appealing when adapting to an existing database schema.
- KyeRussell 4y agoAt work, I’ve been using Django exclusively for almost a decade. I’ve just taken note of how much of a funk I’m in and have been branching out, especially in the JS space. I’m amazed at how far ahead Django’s ORM is. Hell, I’m amazed at how far ahead 5-years-ago Django’s ORM is. I’ve been enjoying playing with some of the typed JS ORMs / query builders out there. I’m certainly more skeptical of ORMs than I’ve been in previous years, but if an ORM is what you want, I have an increased appreciation of Django’s execution. I’ve honestly got no idea if DRF is comparatively better than what you can do with other frameworks. I’ve recently come out the other side of some work that’s led me to believe that DRF has some deep rooted design flaws that it’ll never be able to dig itself out of. I’m excited to see how the new generation of API authoring tools shakes this all up. None I’d this is to say that it’s any better anywhere else. I don’t think that things like FastAPI are the sort of like-for-like replacement that I’m interested in.
- bayesian_horse 4y agoI am forced to use dotnet at work after having done Django for a long time. In ASP.NET with CQRS Pattern I need to have about three classes for every endpoint, while with DRF I can get 5 endpoints with about 3 classes including the model and that's about 80-90% of what I'll ever need of a resource. DRF allows you to infer what a sensible API would look like and lets you override pretty much everything on top of that.