Skip to content

Commit

Permalink
refactor(core): move fn server_version_num from `trait PgConnection…
Browse files Browse the repository at this point in the history
…Info` to impl

Signed-off-by: Atkins Chang <atkinschang@gmail.com>
  • Loading branch information
AtkinsChang committed Aug 18, 2021
1 parent 207e6db commit c4f9a6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
22 changes: 5 additions & 17 deletions sqlx-core/src/postgres/connection/mod.rs
Expand Up @@ -65,6 +65,11 @@ pub struct PgConnection {
}

impl PgConnection {
/// the version number of the server in `libpq` format
pub fn server_version_num(&self) -> Option<u32> {
self.stream.server_version_num
}

// will return when the connection is ready for another query
async fn wait_until_ready(&mut self) -> Result<(), Error> {
if !self.stream.wbuf.is_empty() {
Expand Down Expand Up @@ -177,20 +182,3 @@ impl Connection for PgConnection {
!self.stream.wbuf.is_empty()
}
}

pub trait PgConnectionInfo {
/// the version number of the server in `libpq` format
fn server_version_num(&self) -> Option<u32>;
}

impl PgConnectionInfo for PgConnection {
fn server_version_num(&self) -> Option<u32> {
self.stream.server_version_num
}
}

impl PgConnectionInfo for crate::pool::PoolConnection<Postgres> {
fn server_version_num(&self) -> Option<u32> {
self.stream.server_version_num
}
}
2 changes: 1 addition & 1 deletion sqlx-core/src/postgres/mod.rs
Expand Up @@ -22,7 +22,7 @@ mod migrate;

pub use arguments::{PgArgumentBuffer, PgArguments};
pub use column::PgColumn;
pub use connection::{PgConnection, PgConnectionInfo};
pub use connection::PgConnection;
pub use database::Postgres;
pub use error::{PgDatabaseError, PgErrorPosition};
pub use listener::{PgListener, PgNotification};
Expand Down
4 changes: 1 addition & 3 deletions tests/postgres/postgres.rs
Expand Up @@ -2,7 +2,7 @@ use futures::TryStreamExt;
use sqlx::postgres::{
PgConnectOptions, PgConnection, PgDatabaseError, PgErrorPosition, PgSeverity,
};
use sqlx::postgres::{PgConnectionInfo, PgPoolOptions, PgRow, Postgres};
use sqlx::postgres::{PgPoolOptions, PgRow, Postgres};
use sqlx::{Column, Connection, Executor, Row, Statement, TypeInfo};
use sqlx_test::{new, setup_if_needed};
use std::env;
Expand Down Expand Up @@ -1096,8 +1096,6 @@ CREATE TABLE heating_bills (

#[sqlx_macros::test]
async fn test_pg_server_num() -> anyhow::Result<()> {
use sqlx::postgres::PgConnectionInfo;

let conn = new::<Postgres>().await?;

assert!(conn.server_version_num().is_some());
Expand Down

0 comments on commit c4f9a6a

Please sign in to comment.