Skip to content

Commit 17760d0

Browse files
Move server_version_num from trait to impl (#1384)
* refactor(core): move `fn server_version_num` from `trait PgConnectionInfo` to impl Signed-off-by: Atkins Chang <[email protected]> * fix rebase issues Co-authored-by: Austin Bonander <[email protected]>
1 parent 17fde44 commit 17760d0

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlx-core/src/postgres/connection/mod.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ pub struct PgConnection {
6767
}
6868

6969
impl PgConnection {
70+
/// the version number of the server in `libpq` format
71+
pub fn server_version_num(&self) -> Option<u32> {
72+
self.stream.server_version_num
73+
}
74+
7075
// will return when the connection is ready for another query
7176
pub(in crate::postgres) async fn wait_until_ready(&mut self) -> Result<(), Error> {
7277
if !self.stream.wbuf.is_empty() {
@@ -187,20 +192,3 @@ impl Connection for PgConnection {
187192
!self.stream.wbuf.is_empty()
188193
}
189194
}
190-
191-
pub trait PgConnectionInfo {
192-
/// the version number of the server in `libpq` format
193-
fn server_version_num(&self) -> Option<u32>;
194-
}
195-
196-
impl PgConnectionInfo for PgConnection {
197-
fn server_version_num(&self) -> Option<u32> {
198-
self.stream.server_version_num
199-
}
200-
}
201-
202-
impl PgConnectionInfo for crate::pool::PoolConnection<Postgres> {
203-
fn server_version_num(&self) -> Option<u32> {
204-
self.stream.server_version_num
205-
}
206-
}

sqlx-core/src/postgres/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod migrate;
2727
pub use advisory_lock::{PgAdvisoryLock, PgAdvisoryLockGuard, PgAdvisoryLockKey};
2828
pub use arguments::{PgArgumentBuffer, PgArguments};
2929
pub use column::PgColumn;
30-
pub use connection::{PgConnection, PgConnectionInfo};
30+
pub use connection::PgConnection;
3131
pub use copy::PgCopyIn;
3232
pub use database::Postgres;
3333
pub use error::{PgDatabaseError, PgErrorPosition};

tests/postgres/postgres.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use futures::{StreamExt, TryStreamExt};
22
use sqlx::postgres::types::Oid;
33
use sqlx::postgres::{
4-
PgAdvisoryLock, PgConnectOptions, PgConnection, PgConnectionInfo, PgDatabaseError,
5-
PgErrorPosition, PgListener, PgPoolOptions, PgRow, PgSeverity, Postgres,
4+
PgAdvisoryLock, PgConnectOptions, PgConnection, PgDatabaseError, PgErrorPosition, PgListener,
5+
PgPoolOptions, PgRow, PgSeverity, Postgres,
66
};
77
use sqlx::{Column, Connection, Executor, Row, Statement, TypeInfo};
88
use sqlx_test::{new, pool, setup_if_needed};
@@ -1202,8 +1202,6 @@ VALUES
12021202

12031203
#[sqlx_macros::test]
12041204
async fn test_pg_server_num() -> anyhow::Result<()> {
1205-
use sqlx::postgres::PgConnectionInfo;
1206-
12071205
let conn = new::<Postgres>().await?;
12081206

12091207
assert!(conn.server_version_num().is_some());

0 commit comments

Comments
 (0)