Closed
Description
Often, you need to write similar but distinct sqls (eg. all sqls have the same columns but different wheres) based on the inputs, (note all combinations of inputs are known at the development time, so this in theory can be done at compile time), it would reduce code duplication (thus reduce the burden of maintaining and testing), this could be done via code like this:
if condition1() {
sqlx::query!(generate_sql_and_args!(condition1 = true, value)...
} else {
sqlx::query!(generate_sql_and_args!(condition2 = true)...
// generate_sql_and_args!(condition1 = true) would expand to:
// "select col from tab where col = $1", value
// the the first query! becomes:
sqlx::query!("select col from tab where col = $1", value)
}
This (semi-dynamic query) is something that we use quite often, it would be wonderful that this can be expressed in a type safe manner.
Metadata
Metadata
Assignees
Labels
No labels