Copy API improvement (#1536) (#1537)

* expose PgCopyIn

* downgrade Pool<Posgres> copy_in_raw/out_row to take &self
This commit is contained in:
Akira Hayakawa 2021-11-13 07:15:15 +09:00 committed by GitHub
parent c8db803dca
commit a304161b28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View file

@ -75,10 +75,7 @@ impl Pool<Postgres> {
/// ### Note
/// [PgCopyIn::finish] or [PgCopyIn::abort] *must* be called when finished or the connection
/// will return an error the next time it is used.
pub async fn copy_in_raw(
&mut self,
statement: &str,
) -> Result<PgCopyIn<PoolConnection<Postgres>>> {
pub async fn copy_in_raw(&self, statement: &str) -> Result<PgCopyIn<PoolConnection<Postgres>>> {
PgCopyIn::begin(self.acquire().await?, statement).await
}
@ -101,10 +98,7 @@ impl Pool<Postgres> {
///
/// Command examples and accepted formats for `COPY` data are shown here:
/// https://www.postgresql.org/docs/current/sql-copy.html
pub async fn copy_out_raw(
&mut self,
statement: &str,
) -> Result<BoxStream<'static, Result<Bytes>>> {
pub async fn copy_out_raw(&self, statement: &str) -> Result<BoxStream<'static, Result<Bytes>>> {
pg_begin_copy_out(self.acquire().await?, statement).await
}
}

View file

@ -26,6 +26,7 @@ mod migrate;
pub use arguments::{PgArgumentBuffer, PgArguments};
pub use column::PgColumn;
pub use connection::{PgConnection, PgConnectionInfo};
pub use copy::PgCopyIn;
pub use database::Postgres;
pub use error::{PgDatabaseError, PgErrorPosition};
pub use listener::{PgListener, PgNotification};