You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In addition to being cumbersome, it is also error-prone, every time I change the query I can easily swap any column of the same time without any compiler error. However, I like how small and succinct cornucopia functions can be and we should keep that.
My idea is the following. This code :
--! example (hello, world) #/* some fancy SQL */
Generate this:
fnexample(hello:&str,world:&i32) -> /* Query or Result */{/* some fancy Rust */}structExampleParams<'a>{hello:&'a str,world:&'a i32}impl<'a>ExampleParams<'a>{fnexample(self) -> /* Query or Result */{example(self.hello,self.world)}}
We could do even crazier things by allowing user naming of params struct.
--! insert (TestParams) #/* some fancy SQL */--! update (TestParams) #/* some fancy SQL */
fninsert(hello:&str,world:&i32) -> /* Query or Result */{/* some fancy Rust */}fnupdate(world:&i32,hello:&str) -> /* Query or Result */{/* some fancy Rust */}structTestParams<'a>{hello:&'a str,world:&'a i32}impl<'a>TestParams<'a>{fninsert(self) -> /* Query or Result */{insert(self.hello,self.world)}fnupdate(self) -> /* Query or Result */{update(self.world,self.hello)}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In one of my projects, I have long queries like this one:
And I need code like this one to pass all arguments:
In addition to being cumbersome, it is also error-prone, every time I change the query I can easily swap any column of the same time without any compiler error. However, I like how small and succinct cornucopia functions can be and we should keep that.
My idea is the following. This code :
Generate this:
We could do even crazier things by allowing user naming of params struct.
Another example:
If we found a trait or create one with a function similar to
params
we could be generic over itBeta Was this translation helpful? Give feedback.
All reactions