iron_rusqlite_middleware

Crates.ioiron_rusqlite_middleware
lib.rsiron_rusqlite_middleware
version0.1.2
sourcesrc
created_at2018-01-19 04:48:04.820526
updated_at2018-06-08 12:52:06.662283
descriptionIron middleware for the rusqlite SQLite library.
homepage
repositoryhttps://gitlab.com/kmidkiff/iron-rusqlite-middleware
max_upload_size
id47370
size8,532
Kevin Midkiff (KevinMidkiff)

documentation

README

Iron Rusqlite Middleware

Build Status iron_rusqlite_middleware’s current version badge

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.

Commit count: 18

cargo fmt