Struct r2d2_postgres::PostgresConnectionManager [] [src]

pub struct PostgresConnectionManager {
    // some fields omitted
}

An r2d2::ConnectionManager for postgres::Connections.

Example

#![allow(unstable)]
extern crate r2d2;
extern crate r2d2_postgres;
extern crate postgres;

use std::sync::Arc;
use std::default::Default;
use std::thread;
use postgres::SslMode;
use r2d2_postgres::PostgresConnectionManager;

fn main() {
    let config = Default::default();
    let manager = PostgresConnectionManager::new("postgres://postgres@localhost",
                                                 SslMode::None).unwrap();
    let error_handler = Box::new(r2d2::LoggingErrorHandler);
    let pool = Arc::new(r2d2::Pool::new(config, manager, error_handler).unwrap());

    for i in 0..10i32 {
        let pool = pool.clone();
        thread::spawn(move || {
            let conn = pool.get().unwrap();
            conn.execute("INSERT INTO foo (bar) VALUES ($1)", &[&i]).unwrap();
        });
    }
}

Methods

impl PostgresConnectionManager
[src]

fn new<T: IntoConnectParams>(params: T, ssl_mode: SslMode) -> Result<PostgresConnectionManagerConnectError>

Creates a new PostgresConnectionManager.

See postgres::Connection::connect for a description of the parameter types.

Trait Implementations

impl Debug for PostgresConnectionManager
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl ConnectionManager for PostgresConnectionManager
[src]

type Connection = Connection

The connection type this manager deals with.

type Error = Error

The error type returned by Connections.

fn connect(&self) -> Result<ConnectionError>

Attempts to create a new connection.

fn is_valid(&self, conn: &mut Connection) -> Result<()Error>

Determines if the connection is still connected to the database. Read more

fn has_broken(&self, conn: &mut Connection) -> bool

Quickly determines if the connection is no longer usable. Read more