| Crates.io | inline-sql |
| lib.rs | inline-sql |
| version | 0.2.0 |
| created_at | 2024-03-04 16:21:17.83154+00 |
| updated_at | 2024-03-10 18:37:06.523728+00 |
| description | write SQL queries directly in Rust functions |
| homepage | |
| repository | https://github.com/de-vri-es/inline-sql-rs |
| max_upload_size | |
| id | 1162060 |
| size | 42,912 |
Write SQL queries inside Rust functions.
The inline-sql crate lets you annotate a function to directly write an SQL query as the function body.
You can use the function parameters as placeholders in your query,
and the query result will automatically be converted to the return type.
See the documentation of the #[inline_sql] macro for more details and examples.
Currently, only tokio-postgres is supported as backend.
Vec of rows.use inline_sql::inline_sql;
#[inline_sql]
async fn get_pets_by_species(
client: &tokio_postgres::Client,
species: &str,
) -> Result<Vec<Pet>, tokio_postgres::Error> {
query!(SELECT * FROM pets WHERE species = $species)
}
client object.client is obtained in the generated code (for example, from a member of self).