4 ms·
when you write code to build a query in an ORM in an interpreted language like Ruby or Python, does it typically go out of its way to actually build the query o
by adamrezich 3y ago
when you write code to build a query in an ORM in an interpreted language like Ruby or Python, does it typically go out of its way to actually build the query once? or does the query get "re-built" (or cached?) every time you call the function that contains your query-building code?
I've been wondering about this and other things while working on my own mini-ORM thing for SQLite—I have it so queries are built once, at compile-time, type-checked, and stored in read-only memory in the executable. but I'm going down the route of having the user manually write SQL for everything that isn't super basic, instead of making a sort of mini-DSL for query-building. so far it's been going great but there's a lot of prior art in this space, and while I've used both Rails and Django before, forever ago, I've been kind of going into this all blindly (and so far it's been going great!).
- cjblomqvist 3y agoProbably different for different ORMs. I know EF Core (C# /.NET) does it/cache queries (for performance reasons).
- deleted 3y ago[deleted]
- gndk 3y agoIn the PHP world, especially when using Symfony, Doctrine ORM is very popular (inspired by Hibernate). It has all kinds of caches, including the query cache that you mentioned: https://www.doctrine-project.org/projects/doctrine-orm/en/2.15/reference/caching.html#query-cache https://www.doctrine-project.org/projects/doctrine-orm/en/2....
- clintonb 3y agoWhy bother caching queries that are pretty quick to generate? Most caching around ORMs focuses on caching the results of the query since they require more resources to generate.
- adamrezich 3y agowell if you're using an interpreted language without any sort of build step then I suppose that's all you can do, but if your backend is written in a compiled language with compile-time execution functionality, then it seems useful to do stuff like this then, instead of at run-time, likely multiple times per request—that's a lot of unnecessarily repeated string-building, without any benefit for doing so!