No description
| examples/all_types | ||
| src | ||
| templates | ||
| turbo-diesel-derive | ||
| .gitignore | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
TurboDiesel
TurboDiesel is a Diesel extension to integrate Diesel effortless with various Rust WebFrameworks. It builds on top of existing frameworks and allows you to customise every component to your needs.
Caution
This code is very experimental, not to use
It currently supports the following frameworks:
It provides a derive to effortless generates routes for:
- get all items for the entity as JSON
- get a single item for an entity as JSON
- create/update an entity via JSON
- Get all items as HTML table
- Get a single item as HTML
- Create/Update an entity via HTML forms
- Delete an entity
Example:
#[derive(
diesel::Queryable,
diesel::Selectable,
Debug,
turbo_diesel::TurboDiesel,
diesel::Identifiable,
serde::Serialize,
)]
#[diesel(table_name = users)]
struct User {
#[turbo_diesel(skip_insert)]
#[turbo_diesel(skip_changeset)]
id: i32,
name: String,
}
#[derive(Clone)]
struct State {
pool: deadpool_diesel::sqlite::Pool,
templates: minijinja::Environment<'static>,
}
impl turbo_diesel::StateExtractor for State {
type ConnectionPool = deadpool_diesel::sqlite::Pool;
fn get_pool(&self) -> &Self::ConnectionPool {
&self.pool
}
fn get_template_pool(&self) -> &dyn Templates {
&self.templates
}
}
// in your main function
let state = State::new();
let router = Router::new().register_all::<User>().with_state(state);
let listener = tokio::net::TcpListener::bind("127.0.0.1:8000")
.await?;
axum::serve(listener, router).await?;
You can then access the mounted route via http://localhost:8000/user.html. Alternative JSON routes:
- GET http://localhost:8000/user to get a list of JSON objects
- POST http://localhost:8000/user to create a new user from a JSON object
- GET http://localhost:8000/user/{id} to get a specific user as JSON object
- PUT http://localhost:8000/user/{id} to update a specific user from a JSON object
- DELETE http://localhost:8000/user/{id} to delete a specific user
There is a complete example in the example directory. You can execute it via cargo run in the corresponding directory.
LICENSE
The code is licensed under MPL 2.0