Replies: 1 comment 15 replies
-
I'm sorry, but I cannot follow what you exactly want to achieve. It's really hard to follow your question as it mixes quite a lot of stuff. Try to focus on one question at the time and try to provide specific example of the problem you want to solve. Do not try to build a generic example, just use your real code as that usually makes it much easier to follow such questions. |
Beta Was this translation helpful? Give feedback.
15 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just stumbled over a interesting issue and use-case, which I'd like to share and hear your suggestions how to implement it properly.
The table has the following pseudo SQL + Diesel structure:
then I am running that tiny set of funcs doing this:
So what I am doing basically is calculating an new i32 out of a,b,c. It shows it is really dependent on the values a,b and c. Of course, I could write that using filters and select. So calculating based on those values, which however does not return me the "calculated" numbers, which I need in the rest of the test project.
Tiny result table for __get_row_calcfield_numeric (kinda like a truth table just with numeric results)
As far as I know that would really suck hard when implementing it in SQL. Further implementing it three times at different places is probably not A+ level coding.
My first thought was to add a new field to the structure and make it nullable, and update it when the app is updating or pulling the rows. The problem is, this leads to untracked changes to a,b,c and an outdated new field. So this is not a solution for me.
My second thought was to use triggers and procedures, due to SQLite this is not only not feasible, the documentation is also kinda rare in this regard, and I do not want to make a whole research project out of this xD
Another connected approach using SQL if-clauses and virt fields results in something like that:
I do not implement all of it here - just an example.
How could I implement that in diesel.rs without getting headaches ?
My third thought was to add some custom filter to the query to achieve the same I would on DB level. However, after searching a bit and looking into possible places in the docs, I have absolutely no clue how I could implement that. Another issue is: I need the resulting value, does not seem very feasible.
My fear is keeping it like above, so querying all rows of the table and "post-processing" them being kinda resource exhaustive. Although Rust is really fast. If I have 1000 entries and 10 users I would query them all (1000*10*req_amount) and post-process them in the Rust App instead of calculating the entries "on DB level". Though I think there is no other way to achieve it atm.
Ideally I would have an extra virtual field that I could just query to do a "give me all with calcVal = 2" like
just with myjobs.filter(...).select(...) in diesl.rs
In other frameworks we have the possibility to use virtual fields or lets say custom fields, to process and store those specific calculations and apply them in filters e.g.:
This would do the post-processing much easier and at one place using one-time coded funcs. However, this is obviously not the ideal solution either.
Keep in mind it: While could be certainly a business project, as I am pretty sure this is a common use-case when implementing business-logic, this is a playground project - still trying to get used to diesel.rs's workflow.
Any ideas? How would you guys solve this? Has Diesel.rs some utilities or a specific methodology to solve issues like that much easier? I would be wondering if nobody thought about this before, as I have seen that a lot out there.
Beta Was this translation helpful? Give feedback.
All reactions