2 releases
Uses old Rust 2015
0.1.2 | Jun 8, 2018 |
---|---|
0.1.1 | Jan 19, 2018 |
#24 in #rusqlite
8KB
50 lines
Iron Rusqlite Middleware
Middleware for the Iron framework for rust enabling database connections using rusqlite. This library is inspired by the Iron Diesel Middleware.
Adding to Cargo Project
To add this library to your cargo project add the following to your Cargo.toml
.
[dependencies]
iron_rusqlite_middleware = "0.1.1"
Usage
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();
}
License
This library is provided under an MIT license, and is provided WITHOUT WARRENTY.
Dependencies
~25MB
~507K SLoC