Skip to content

wolbodo/iron-postgres-middleware

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iron-postgres-middleware

An attempt to create postgres middleware for the Iron web framework

Usage

Cargo.toml

[dependencies.iron-postgres-middleware]
git = "https://github.com/martinsp/iron-postgres-middleware.git"

Import

extern crate iron_postgres_middleware as pg_middleware;
use pg_middleware::{PostgresMiddleware, PostgresReqExt};

Middleware

fn main() {
  let mut router = Router::new();
  router.get("/", handler);

  let mut c = Chain::new(router);

  let pg_middleware = PostgresMiddleware::new("postgres://user@localhost/db_name").unwrap();
  c.link_before(pg_middleware);

  Iron::new(c).http("localhost:3000").unwrap();
}

fn handler(req: &mut Request) -> IronResult<Response> {
  let con = req.db_conn();
  con.execute("INSERT INTO foo (bar) VALUES ($1)", &[&1i32]).unwrap();
  Ok(Response::new().set(status::Ok).set("Success"))
}

About

A postgres middleware for Iron web framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%