-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Would sqlx add support for appends a piece of SQL code
at the struct sqlx::Query?
#279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Something I do quite often with SQL databases is to build dynamic WHERE clauses. Typically, some REST api with very liberal filtering options. Often these kinds of queries are hard to precompile. I've used Kotlin string interpolation to build these, something like:
and bind the SQL parameters ( But in this case the "dynamicness" doesn't really change the input and output types of the query. E.g. the SQL queries in applications are often simple "SQL compilers" like this, in my experience. I've always preferred working with pure SQL over DSL-like generators, and I'm currently looking into how to best replicate this pattern in Rust and sqlx. |
We've been debating on the best design for a dynamic query builder but haven't really reached consensus. We definitely have come across a need for it in our own uses of SQLx and ended up hand-rolling something that could serve as a jumping-off point. However, we'd prefer not to add this to I would kind of like to close this issue in favor of one that's specifically for discussing the design of such a query builder. |
Yes, I was not really looking for something directly like "push", but instead exactly as you say, some builder pattern with a way to bind data ergonomically (without a lot of code repetition). It would be interesting to see and maybe contribute to such a discussion! |
closing in favor of #291 |
Like Diesel's query_builder, it's useful when we want to build a conditional
where
sql statement.Detail link: https://docs.diesel.rs/diesel/query_builder/struct.SqlQuery.html#method.sql
The text was updated successfully, but these errors were encountered: