sqlx_conditional_queries_layering
This library provides a macro for handling query templates in conjunction with the sqlx_conditional_queries library. It simplifies the creation of SQL queries with conditional parameters.
Basic Example
let keehee =
.choose
.cloned
.unwrap_or_default;
create_conditional_query_as!;
This will generate an keehee_query macro.
Using the generated query
keehee_query is a template. You can use it to do an sqlx query:
keehee_query!
.fetch_one
.await;
We can further extend the template with aditional variables using the macro supply_sql_variables_to_query_as.
supply_sql_variables_to_query_as!;
In this example we create some_query, which is another macro that have the same template variables as keehee_query with the addition of #name.
It does not stop here though!
We can merge two queries into one through:
merge_sql_query_as!;
This will merge all the template variables of a and b into a single argsception query!
Note
This macro relies on other macros from sqlx_conditional_queries.
Dependencies
You need to enable the macro_metavar_expr feature to use this library:
You will also need to add the following dependencies to Cargo.toml: sqlx_conditional_queries, paste.
You can do so easily, through:
cargo add sqlx_conditional_queries
cargo add paste