Skip to content

Commit a85d508

Browse files
committed
Add some prepare_copy_in docs
1 parent 4863433 commit a85d508

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,29 @@ impl PostgresConnection {
816816
conn.prepare(query, self)
817817
}
818818

819+
/// Creates a new COPY FROM STDIN prepared statement.
820+
///
821+
/// These statements provide a method to efficiently bulk-upload data to
822+
/// the database.
823+
///
824+
/// ## Example
825+
///
826+
/// ```rust,no_run
827+
/// # use postgres::{PostgresConnection, NoSsl};
828+
/// # use postgres::types::ToSql;
829+
/// # let _ = || {
830+
/// # let conn = PostgresConnection::connect("", &NoSsl).unwrap();
831+
/// try!(conn.execute("CREATE TABLE foo (
832+
/// bar INT PRIMARY KEY,
833+
/// baz VARCHAR
834+
/// )", []));
835+
///
836+
/// let stmt = try!(conn.prepare_copy_in("foo", ["bar", "baz"]));
837+
/// let data: &[&[&ToSql]] = &[&[&0i32, &"blah".to_string()],
838+
/// &[&1i32, &None::<String>]];
839+
/// try!(stmt.execute(data.iter().map(|r| r.iter().map(|&e| e))));
840+
/// # Ok(()) };
841+
/// ```
819842
pub fn prepare_copy_in<'a>(&'a self, table: &str, rows: &[&str])
820843
-> PostgresResult<PostgresCopyInStatement<'a>> {
821844
let mut conn = self.conn.borrow_mut();

0 commit comments

Comments
 (0)