#database #sql #postgres #copy

postgres-binary-copy

Support for binary-format COPY query execution with postgres

9 unstable releases (4 breaking)

0.5.0 Jul 23, 2017
0.3.1 Nov 6, 2016
0.2.1 Apr 2, 2016
0.2.0 Jan 4, 2016
0.1.0 Jul 4, 2015

#5 in #copy

Download history 20/week @ 2020-01-24 12/week @ 2020-01-31 32/week @ 2020-02-07 14/week @ 2020-02-14 51/week @ 2020-02-21 38/week @ 2020-02-28 31/week @ 2020-03-06 20/week @ 2020-03-13 31/week @ 2020-03-20 16/week @ 2020-03-27 11/week @ 2020-04-03 69/week @ 2020-04-10 21/week @ 2020-04-17 25/week @ 2020-04-24 9/week @ 2020-05-01 15/week @ 2020-05-08

121 downloads per month
Used in 2 crates (via amadeus-postgres)

MIT license

23KB
503 lines

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();
}

Dependencies

~2.5MB
~69K SLoC