1+ use crate :: iter:: Iter ;
2+ #[ cfg( feature = "runtime" ) ]
3+ use crate :: Config ;
4+ use crate :: { CopyInWriter , CopyOutReader , Statement , ToStatement , Transaction } ;
15use fallible_iterator:: FallibleIterator ;
26use futures:: executor;
3- use std:: io:: { BufRead , Read } ;
47use tokio_postgres:: tls:: { MakeTlsConnect , TlsConnect } ;
58use tokio_postgres:: types:: { ToSql , Type } ;
69#[ cfg( feature = "runtime" ) ]
710use tokio_postgres:: Socket ;
811use tokio_postgres:: { Error , Row , SimpleQueryMessage } ;
912
10- use crate :: copy_in_stream:: CopyInStream ;
11- use crate :: copy_out_reader:: CopyOutReader ;
12- use crate :: iter:: Iter ;
13- #[ cfg( feature = "runtime" ) ]
14- use crate :: Config ;
15- use crate :: { Statement , ToStatement , Transaction } ;
16-
1713/// A synchronous PostgreSQL client.
1814///
1915/// This is a lightweight wrapper over the asynchronous tokio_postgres `Client`.
@@ -264,29 +260,33 @@ impl Client {
264260 /// The `query` argument can either be a `Statement`, or a raw query string. The data in the provided reader is
265261 /// passed along to the server verbatim; it is the caller's responsibility to ensure it uses the proper format.
266262 ///
263+ /// The copy *must* be explicitly completed via the `finish` method. If it is not, the copy will be aborted.
264+ ///
267265 /// # Examples
268266 ///
269267 /// ```no_run
270268 /// use postgres::{Client, NoTls};
269+ /// use std::io::Write;
271270 ///
272- /// # fn main() -> Result<(), postgres:: Error> {
271+ /// # fn main() -> Result<(), Box<dyn std::error:: Error> > {
273272 /// let mut client = Client::connect("host=localhost user=postgres", NoTls)?;
274273 ///
275- /// client.copy_in("COPY people FROM stdin", &[], &mut "1\tjohn\n2\tjane\n".as_bytes())?;
274+ /// let mut writer = client.copy_in("COPY people FROM stdin", &[])?;
275+ /// writer.write_all(b"1\tjohn\n2\tjane\n")?;
276+ /// writer.finish()?;
276277 /// # Ok(())
277278 /// # }
278279 /// ```
279- pub fn copy_in < T , R > (
280+ pub fn copy_in < T > (
280281 & mut self ,
281282 query : & T ,
282283 params : & [ & ( dyn ToSql + Sync ) ] ,
283- reader : R ,
284- ) -> Result < u64 , Error >
284+ ) -> Result < CopyInWriter < ' _ > , Error >
285285 where
286286 T : ?Sized + ToStatement ,
287- R : Read + Unpin ,
288287 {
289- executor:: block_on ( self . 0 . copy_in ( query, params, CopyInStream ( reader) ) )
288+ let sink = executor:: block_on ( self . 0 . copy_in ( query, params) ) ?;
289+ Ok ( CopyInWriter :: new ( sink) )
290290 }
291291
292292 /// Executes a `COPY TO STDOUT` statement, returning a reader of the resulting data.
@@ -312,7 +312,7 @@ impl Client {
312312 & mut self ,
313313 query : & T ,
314314 params : & [ & ( dyn ToSql + Sync ) ] ,
315- ) -> Result < impl BufRead , Error >
315+ ) -> Result < CopyOutReader < ' _ > , Error >
316316 where
317317 T : ?Sized + ToStatement ,
318318 {
0 commit comments