Crate postgres_binary_copy [] [src]

Support for binary-format COPY query execution with rust-postgres.

Example

extern crate postgres;
extern crate postgres_binary_copy;
extern crate streaming_iterator;

use postgres::{Connection, TlsMode};
use postgres::types::{ToSql, INT4, VARCHAR};
use postgres_binary_copy::BinaryCopyReader;
use streaming_iterator::StreamingIterator;

fn main() {
    let conn = Connection::connect("postgres://postgres@localhost",
                                   TlsMode::None).unwrap();

    conn.execute("CREATE TABLE foo (id INT PRIMARY KEY, bar VARCHAR)", &[])
        .unwrap();

    let types = &[INT4, VARCHAR];
    let data: Vec<Box<ToSql>> = vec![Box::new(1i32), Box::new("hello"),
                                     Box::new(2i32), Box::new("world")];
    let data = streaming_iterator::convert(data.into_iter()).map_ref(|v| &**v);
    let mut reader = BinaryCopyReader::new(types, data);

    let stmt = conn.prepare("COPY foo (id, bar) FROM STDIN (FORMAT binary)").unwrap();
    stmt.copy_in(&[], &mut reader).unwrap();
}

Structs

BinaryCopyReader

A ReadWithInfo implementation that generates binary-formatted output for use with COPY ... FROM STDIN (FORMAT binary) statements.

BinaryCopyWriter

A ReadWithInfo implementation that processes binary-formatted input for use with COPY ... TO STDOUT (FORMAT binary) statements.

Traits

WriteValue

A trait for types that can receive values from a BinaryCopyWriter.