Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Montana Low committed Jul 27, 2021
1 parent 5e99cc2 commit 37bca39
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion sqlx-core/src/postgres/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl PgConnection {
}

pub async fn server_version(&mut self) -> Result<String, Error> {
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)
Expand Down
19 changes: 12 additions & 7 deletions sqlx-core/src/postgres/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -238,13 +238,16 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
)),
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),
}
}
Expand All @@ -264,7 +267,9 @@ impl<C: DerefMut<Target = PgConnection>> PgCopyIn<C> {
.recv_expect(MessageFormat::CommandComplete)
.await?;

conn.stream.recv_expect(MessageFormat::ReadyForQuery).await?;
conn.stream
.recv_expect(MessageFormat::ReadyForQuery)
.await?;

Ok(cc.rows_affected())
}
Expand Down
1 change: 0 additions & 1 deletion sqlx-core/src/postgres/message/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
55 changes: 36 additions & 19 deletions tests/postgres/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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::<Postgres>().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?;
Expand All @@ -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::<Postgres>().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?;

Expand All @@ -1122,9 +1135,13 @@ async fn it_can_copy_out() -> anyhow::Result<()> {
let mut conn = new::<Postgres>().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");
Expand Down

0 comments on commit 37bca39

Please sign in to comment.