mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-09-28 21:42:06 +00:00
PgConnection: use more obvious/safer query for ping()
This commit is contained in:
parent
a0d1106f90
commit
e3dbd58bf2
@ -117,7 +117,8 @@ impl Connection for PgConnection {
|
||||
}
|
||||
|
||||
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
|
||||
self.execute("SELECT 1").map_ok(|_| ()).boxed()
|
||||
// By sending a comment we avoid an error if the connection was in the middle of a rowset
|
||||
self.execute("/* SQLx ping */").map_ok(|_| ()).boxed()
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use futures::TryStreamExt;
|
||||
use sqlx::postgres::PgRow;
|
||||
use sqlx::{postgres::Postgres, Executor, Row};
|
||||
use sqlx::{postgres::Postgres, Connection, Executor, Row};
|
||||
use sqlx_core::postgres::{PgDatabaseError, PgErrorPosition, PgSeverity};
|
||||
use sqlx_test::new;
|
||||
|
||||
@ -18,6 +18,15 @@ async fn it_connects() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_pings() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Postgres>().await?;
|
||||
|
||||
conn.ping().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn it_maths() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Postgres>().await?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user