Trait iron_postgres_middleware::PostgresReqExt [] [src]

pub trait PostgresReqExt {
    fn db_conn(&self) -> PooledConnection<PostgresConnectionManager>;
}

Adds a method to requests to get a database connection.

Example

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

  Ok(Response::with((status::Ok, resp_str)))
}

Required Methods

fn db_conn(&self) -> PooledConnection<PostgresConnectionManager>

Returns a pooled connection to the postgresql database. The connection is returned to the pool when the pooled connection is dropped.

Panics if a PostgresMiddleware has not been registered with Iron, or if retrieving a connection to the database times out.

Implementors