No description
Find a file
2025-11-07 12:20:14 +01:00
examples/all_types Initial commit 2025-11-07 12:16:02 +01:00
src Initial commit 2025-11-07 12:16:02 +01:00
templates Initial commit 2025-11-07 12:16:02 +01:00
turbo-diesel-derive Initial commit 2025-11-07 12:16:02 +01:00
.gitignore Initial commit 2025-11-07 12:16:02 +01:00
Cargo.toml Initial commit 2025-11-07 12:16:02 +01:00
LICENSE Initial commit 2025-11-07 12:16:02 +01:00
README.md Add a note to the readme that noone should use this code yet 2025-11-07 12:20:14 +01:00

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:

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