Replies: 1 comment 1 reply
-
|
Thanks for writing this proposal. I can see why such a derive would look like a good extension, but I fear that it's not as easy as that. Different users will have widely different requirements on how exactly that derive is supposed to work. You want to be able to specify the operator as part of the attribute, while others likely want to have the operator flexible as well. Technically that's likely still all solvable but comes with a lot of complexity. Given that I would prefer to see some out of tree experimentation in a third party crate first. If that crate is reasonable popular we can still talk about merging it back to diesel itself.
I don't think that's something you would need to care that much about. Allocations are an order of magnitude cheaper than network IO, so this will be all only noise compared to the actual query runtime due to the need to perform network IO for most of the backends. The only exception there is the SQLite backend. There allocations can matter, but only in hot inner loops, so even there this is still likely irrelevant. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Backend
PostgreSQL, MySQL, SQLite
What do you want to add to diesel?
Recently, the fantastic HasQuery was added to diesel, which improves query ergonomics a lot. I've been thinking about a "sibling" trait (potentially called
AsFilter) that could be used like so:Implementation notes
Here's something I already use in my own code, which could probably be turned into a derive macro with some work (above code omitted):
Additional details
My only concern is performance. I tried to dig into how diesel handles boxed queries to see if it's reboxing the query the way my
AsFiltertrait does, but I couldn't really tell. If the current way (query.into_boxed) is the same in number of heap allocations as myAsFilter, then it should be fine. There's also a possibility for optimization if the filter structure has no optional fields - then, only one box is necessary (or we split this into two traits -AsFilterandAsBoxedFilter).Anyways, if anyone has thoughts as to whether it's a worthwhile pursuit, I'm happy to hear them!
Checklist
Beta Was this translation helpful? Give feedback.
All reactions