postgres-binary-copy

Crates.iopostgres-binary-copy
lib.rspostgres-binary-copy
version0.5.0
sourcesrc
created_at2015-07-04 23:46:20.172039
updated_at2017-07-23 22:21:28.801605
descriptionSupport for binary-format COPY query execution with postgres
homepage
repositoryhttps://github.com/sfackler/rust-postgres-binary-copy
max_upload_size
id2534
size24,587
cargo publish (github:servo:cargo-publish)

documentation

https://docs.rs/postgres-binary-copy/0.5.0/postgres_binary_copy

README

postgres-binary-copy

CircleCI Latest Version

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

Documentation

Example

extern crate postgres;
extern crate postgres_binary_copy;

use postgres::{Connection, TlsMode};
use postgres::types::{Type, ToSql};
use postgres_binary_copy::BinaryCopyReader;

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 = &[Type::Int4, Type::Varchar];
    let data: Vec<Box<ToSql>> = vec![Box::new(1i32), Box::new("hello"),
                                     Box::new(2i32), Box::new("world")];
    let data = data.iter().map(|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();
}
Commit count: 58

cargo fmt