Crates.io | toql_rocket |
lib.rs | toql_rocket |
version | 0.3.0 |
source | src |
created_at | 2019-05-15 17:37:39.85256 |
updated_at | 2021-10-20 13:53:53.595762 |
description | Rocket integration for Toql |
homepage | |
repository | https://github.com/roy-ganz/toql_rocket |
max_upload_size | |
id | 134539 |
size | 10,925 |
This crate adds:
Add this to your Cargo.toml
:
[dependencies]
toql_rocket = "0.3"
Then enjoy some simplifications in your rocket handlers:
use toql_rocket::prelude::{ToqlQUery, Counted};
#[get("/?<toql_query..>")]
pub async fn query(
cache: &State<Cache>,
mut conn: Connection<TodoDb>,
toql_query: ToqlQuery, //<!-- Get URL parameters with default values
) -> Result<Counted<Json<Vec<Todo>, MyError>>>
{
let mut toql = MySqlAsync::from(&mut *conn, &*cache);
let (query, page) = toql_query.parse::<Todo>()?; //<!-- Parse into typesafe query
let r = toql.load_page(query, page).await?;
Ok(Counted(Json(r.0), r.1)) //<!-- Put page count information into headers
}
Check out the full featured REST server based on Rocket, Toql and MySQL.
Toql Rocket is distributed under the terms of both the MIT license and the Apache License (Version 2.0).