diff --git a/sqlx-core/src/postgres/connection/mod.rs b/sqlx-core/src/postgres/connection/mod.rs index c911b814fb..69c39a288f 100644 --- a/sqlx-core/src/postgres/connection/mod.rs +++ b/sqlx-core/src/postgres/connection/mod.rs @@ -104,7 +104,7 @@ impl PgConnection { } pub async fn server_version(&mut self) -> Result { - let result = self.fetch_one("SHOW server_version;",).await?; + let result = self.fetch_one("SHOW server_version;").await?; let server_version: String = result.get("server_version"); Ok(server_version) diff --git a/sqlx-core/src/postgres/copy.rs b/sqlx-core/src/postgres/copy.rs index bf728ffcdb..0d8eb46f2d 100644 --- a/sqlx-core/src/postgres/copy.rs +++ b/sqlx-core/src/postgres/copy.rs @@ -8,10 +8,10 @@ use crate::postgres::message::{ use crate::postgres::Postgres; use bytes::{BufMut, Bytes}; use futures_core::stream::BoxStream; +use smallvec::alloc::borrow::Cow; use sqlx_rt::{AsyncRead, AsyncReadExt, AsyncWriteExt}; use std::convert::TryFrom; use std::ops::{Deref, DerefMut}; -use smallvec::alloc::borrow::Cow; impl PgConnection { /// Issue a `COPY FROM STDIN` statement and transition the connection to streaming data @@ -238,13 +238,16 @@ impl> PgCopyIn { )), Err(Error::Database(e)) => { match e.code() { - Some(Cow::Borrowed("57014")) => { // postgres abort received error code - conn.stream.recv_expect(MessageFormat::ReadyForQuery).await?; + Some(Cow::Borrowed("57014")) => { + // postgres abort received error code + conn.stream + .recv_expect(MessageFormat::ReadyForQuery) + .await?; Ok(()) - }, - _ => Err(Error::Database(e)) + } + _ => Err(Error::Database(e)), } - }, + } Err(e) => Err(e), } } @@ -264,7 +267,9 @@ impl> PgCopyIn { .recv_expect(MessageFormat::CommandComplete) .await?; - conn.stream.recv_expect(MessageFormat::ReadyForQuery).await?; + conn.stream + .recv_expect(MessageFormat::ReadyForQuery) + .await?; Ok(cc.rows_affected()) } diff --git a/sqlx-core/src/postgres/message/copy.rs b/sqlx-core/src/postgres/message/copy.rs index 37b286c4a4..58553d431b 100644 --- a/sqlx-core/src/postgres/message/copy.rs +++ b/sqlx-core/src/postgres/message/copy.rs @@ -3,7 +3,6 @@ use crate::io::{BufExt, BufMutExt, Decode, Encode}; use bytes::{Buf, BufMut, Bytes}; use std::ops::Deref; - /// The same structure is sent for both `CopyInResponse` and `CopyOutResponse` pub struct CopyResponse { pub format: i8, diff --git a/tests/postgres/postgres.rs b/tests/postgres/postgres.rs index 7323a9fb91..3d9da2a769 100644 --- a/tests/postgres/postgres.rs +++ b/tests/postgres/postgres.rs @@ -1051,15 +1051,14 @@ async fn it_supports_domain_types_in_composite_domain_types() -> anyhow::Result< .execute(&mut conn) .await; - let result = sqlx::query( - "INSERT INTO heating_bills(month, cost) VALUES($1::winter_year_month, 100);", - ) - .bind(WinterYearMonth { - year: 2021, - month: MonthId(1), - }) - .execute(&mut conn) - .await; + let result = + sqlx::query("INSERT INTO heating_bills(month, cost) VALUES($1::winter_year_month, 100);") + .bind(WinterYearMonth { + year: 2021, + month: MonthId(1), + }) + .execute(&mut conn) + .await; let result = result.unwrap(); assert_eq!(result.rows_affected(), 1); @@ -1070,13 +1069,20 @@ async fn it_supports_domain_types_in_composite_domain_types() -> anyhow::Result< #[sqlx_macros::test] async fn it_can_copy_in() -> anyhow::Result<()> { let mut conn = new::().await?; - conn.execute(r#" + conn.execute( + r#" CREATE TEMPORARY TABLE users (id INTEGER NOT NULL); - "#,).await?; + "#, + ) + .await?; - let mut copy = conn.copy_in_raw(r#" + let mut copy = conn + .copy_in_raw( + r#" COPY users (id) FROM STDIN WITH (FORMAT CSV, HEADER); - "#).await?; + "#, + ) + .await?; copy.send("id\n1\n2\n".as_bytes()).await?; let rows = copy.finish().await?; @@ -1096,13 +1102,20 @@ async fn it_can_copy_in() -> anyhow::Result<()> { #[sqlx_macros::test] async fn it_can_abort_copy_in() -> anyhow::Result<()> { let mut conn = new::().await?; - conn.execute(r#" + conn.execute( + r#" CREATE TEMPORARY TABLE users (id INTEGER NOT NULL); - "#,).await?; + "#, + ) + .await?; - let mut copy = conn.copy_in_raw(r#" + let mut copy = conn + .copy_in_raw( + r#" COPY users (id) FROM STDIN WITH (FORMAT CSV, HEADER); - "#).await?; + "#, + ) + .await?; copy.abort("this is only a test").await?; @@ -1122,9 +1135,13 @@ async fn it_can_copy_out() -> anyhow::Result<()> { let mut conn = new::().await?; { - let mut copy = conn.copy_out_raw(" + let mut copy = conn + .copy_out_raw( + " COPY (SELECT generate_series(1, 2) AS id) TO STDOUT WITH (FORMAT CSV, HEADER); - ").await?; + ", + ) + .await?; assert_eq!(copy.next().await.unwrap().unwrap(), "id\n"); assert_eq!(copy.next().await.unwrap().unwrap(), "1\n");