How can I switch mindsets from ORMs or query builders to projects like this? #268
Replies: 1 comment
-
|
SQL is indeed anti-modular and non composable in a sense, which sucks. Generating strings with string interpolation might not be the best approach, and in any case it's not supported by Cornucopia. However, SQL has some modularity in that it allows you to factor out common parts of queries into their own functions (and define those functions as part of your migrations). In special you could have functions that returns some condition that is put at an where clause, like this --! my_query(param)
SELECT *
FROM player
WHERE something(onething, otherthing, :param)And then, you define the function What SQL doesn't have is a way to dispatch over multiple queries (building queries with string concatenation inside procedural function is terrible and doesn't count). So you really need to define all those functions and do dispatch on Rust side. Which is unfortunate. Really the library should help with this. Note: while this project is inactive (last commit 2 years ago), development is continued on a fork, Clorinde. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm really fascinated by this idea you had to generate Rust code from sql files. Great!
What I can't understand after years of using "Query builders" and ORMs is how to get the same queries I'm getting using this pattern:
this creates a big and complex and dynamic CTE (Common Table Expressions) query like this:
How can I switch from
sqlx::QueryBuildertoclorinde?I can't always know in advance which filters I'll need.
Beta Was this translation helpful? Give feedback.
All reactions