From a304161b287f8b4bd053fcfede1966b4c548581b Mon Sep 17 00:00:00 2001 From: Akira Hayakawa Date: Sat, 13 Nov 2021 07:15:15 +0900 Subject: [PATCH] Copy API improvement (#1536) (#1537) * expose PgCopyIn * downgrade Pool copy_in_raw/out_row to take &self --- sqlx-core/src/postgres/copy.rs | 10 ++-------- sqlx-core/src/postgres/mod.rs | 1 + 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/sqlx-core/src/postgres/copy.rs b/sqlx-core/src/postgres/copy.rs index 18771e3e..babdecca 100644 --- a/sqlx-core/src/postgres/copy.rs +++ b/sqlx-core/src/postgres/copy.rs @@ -75,10 +75,7 @@ impl Pool { /// ### 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>> { + pub async fn copy_in_raw(&self, statement: &str) -> Result>> { PgCopyIn::begin(self.acquire().await?, statement).await } @@ -101,10 +98,7 @@ impl Pool { /// /// 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>> { + pub async fn copy_out_raw(&self, statement: &str) -> Result>> { pg_begin_copy_out(self.acquire().await?, statement).await } } diff --git a/sqlx-core/src/postgres/mod.rs b/sqlx-core/src/postgres/mod.rs index ae71a18d..cac6c004 100644 --- a/sqlx-core/src/postgres/mod.rs +++ b/sqlx-core/src/postgres/mod.rs @@ -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};