https://github.com/bluemoon/tide-diesel
Tide middleware for Diesel pooled connections & transactions
https://github.com/bluemoon/tide-diesel
diesel rust tide
Last synced: 9 months ago
JSON representation
Tide middleware for Diesel pooled connections & transactions
- Host: GitHub
- URL: https://github.com/bluemoon/tide-diesel
- Owner: bluemoon
- Created: 2022-02-07T15:32:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-15T01:08:29.000Z (over 4 years ago)
- Last Synced: 2025-04-23T05:13:34.342Z (about 1 year ago)
- Topics: diesel, rust, tide
- Language: Rust
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tide-diesel
[Tide][] middleware for [Diesel][] pooled connections & transactions.
----
A [Tide][] middleware which holds a pool of Diesel database connections, and automatically hands
each [tide::Request][] a connection, which may transparently be either a database transaction,
or a direct pooled database connection.
When using this, use the `DieselRequestExt` extenstion trait to get the connection.
## Examples
### Basic
```rust
#[async_std::main]
async fn main() -> anyhow::Result<()> {
use tide_diesel::DieselRequestExt;
let mut app = tide::new();
app.with(DieselMiddleware::new("postgres://localhost/a_database").await?);
app.at("/").post(|req: tide::Request<()>| async move {
let mut pg_conn = req.pg_conn().await;
Ok("")
});
Ok(())
}
```
## License
Licensed under the [BlueOak Model License 1.0.0](LICENSE.md) — _[Contributions via DCO 1.1](contributing.md#developers-certificate-of-origin)_
[tide::Request]: https://docs.rs/tide/0.15.0/tide/struct.Request.html
[Diesel]: https://github.com/diesel-rs/diesel
[Tide]: https://github.com/http-rs/tide