Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move server_version_num from trait to impl #1384

Merged
merged 3 commits into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 5 additions & 17 deletions sqlx-core/src/postgres/connection/mod.rs
Expand Up @@ -67,6 +67,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
pub(in crate::postgres) async fn wait_until_ready(&mut self) -> Result<(), Error> {
if !self.stream.wbuf.is_empty() {
Expand Down Expand Up @@ -187,20 +192,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 @@ -27,7 +27,7 @@ mod migrate;
pub use advisory_lock::{PgAdvisoryLock, PgAdvisoryLockGuard, PgAdvisoryLockKey};
pub use arguments::{PgArgumentBuffer, PgArguments};
pub use column::PgColumn;
pub use connection::{PgConnection, PgConnectionInfo};
pub use connection::PgConnection;
pub use copy::PgCopyIn;
pub use database::Postgres;
pub use error::{PgDatabaseError, PgErrorPosition};
Expand Down
6 changes: 2 additions & 4 deletions tests/postgres/postgres.rs
@@ -1,8 +1,8 @@
use futures::{StreamExt, TryStreamExt};
use sqlx::postgres::types::Oid;
use sqlx::postgres::{
PgAdvisoryLock, PgConnectOptions, PgConnection, PgConnectionInfo, PgDatabaseError,
PgErrorPosition, PgListener, PgPoolOptions, PgRow, PgSeverity, Postgres,
PgAdvisoryLock, PgConnectOptions, PgConnection, PgDatabaseError, PgErrorPosition, PgListener,
PgPoolOptions, PgRow, PgSeverity, Postgres,
};
use sqlx::{Column, Connection, Executor, Row, Statement, TypeInfo};
use sqlx_test::{new, pool, setup_if_needed};
Expand Down Expand Up @@ -1202,8 +1202,6 @@ VALUES

#[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