Crates.io | iron_rusqlite_middleware |
lib.rs | iron_rusqlite_middleware |
version | 0.1.2 |
source | src |
created_at | 2018-01-19 04:48:04.820526 |
updated_at | 2018-06-08 12:52:06.662283 |
description | Iron middleware for the rusqlite SQLite library. |
homepage | |
repository | https://gitlab.com/kmidkiff/iron-rusqlite-middleware |
max_upload_size | |
id | 47370 |
size | 8,532 |
Middleware for the Iron framework for rust enabling database connections using rusqlite. This library is inspired by the Iron Diesel Middleware.
To add this library to your cargo project add the following to your Cargo.toml
.
[dependencies]
iron_rusqlite_middleware = "0.1.1"
The following example showcases the major components needed for using this library in your Iron project.
// Include Iron crate with any needed "use" statements
// Include the middleware's crate
extern crate iron_rusqlite_middleware;
use iron_rusqlite_middleware::{RusqliteMiddleware, RusqliteRequestExtension};
fn handler(req: &mut Request) -> IronResult<Response> {
// The SQLite database connection is added into the Request object through the extension
let conn = req.database_connection();
// Do your request
Ok(Response::with((status::Ok, "Done."))
}
fn main() {
// Initialize the middleware
let rusqlite_middleware = RusqliteMiddleware::new("example.db").unwrap();
// Create the Iron chain of middlewares
let mut chain = Chain::new(handler);
// Add in the middleware as before
chain.link_before(rusqlite_middleware);
// Start your Iron webserver
let addr = "127.0.0.1:3000";
println!("-- Running webserver on {}", addr);
Iron::new(chain).http(addr).unwrap();
}
This library is provided under an MIT license, and is provided WITHOUT WARRENTY.