diff --git a/sqlx-postgres/src/connection.rs b/sqlx-postgres/src/connection.rs new file mode 100644 index 00000000..263a8a71 --- /dev/null +++ b/sqlx-postgres/src/connection.rs @@ -0,0 +1,87 @@ +use std::fmt::{self, Debug, Formatter}; + +#[cfg(feature = "async")] +use futures_util::future::{BoxFuture, FutureExt, TryFutureExt}; +use sqlx_core::{Close, Connect, Connection, Runtime}; + +use crate::stream::PgStream; +use crate::Postgres; + +/// A single connection (also known as a session) to a +/// PostgreSQL database server. +pub struct PgConnection { + stream: PgStream, + + // process id of this backend + // can be used to send cancel requests + #[allow(dead_code)] + process_id: u32, + + // secret key of this backend + // can be used to send cancel requests + #[allow(dead_code)] + secret_key: u32, +} + +impl Debug for PgConnection +where + Rt: Runtime, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_struct("PgConnection").finish() + } +} + +impl PgConnection { + pub(crate) fn new(stream: NetStream) -> Self { + Self { stream: PgStream::new(stream), process_id: 0, secret_key: 0 } + } +} + +impl Connection for PgConnection { + type Database = Postgres; + + #[cfg(feature = "async")] + fn ping(&mut self) -> BoxFuture<'_, sqlx_core::Result<()>> + where + Rt: sqlx_core::Async, + { + todo!() + } + + #[cfg(feature = "async")] + fn describe<'x, 'e, 'q>( + &'e mut self, + query: &'q str, + ) -> BoxFuture<'x, sqlx_core::Result>> + where + Rt: sqlx_core::Async, + 'e: 'x, + 'q: 'x, + { + todo!() + } +} + +impl Connect for PgConnection { + type Options = PostgresConnectOptions; + + #[cfg(feature = "async")] + fn connect_with(options: &PostgresConnectOptions) -> BoxFuture<'_, sqlx_core::Result> + where + Self: Sized, + Rt: sqlx_core::Async, + { + PgConnection::connect_async(options).boxed() + } +} + +impl Close for PgConnection { + #[cfg(feature = "async")] + fn close(mut self) -> BoxFuture<'static, sqlx_core::Result<()>> + where + Rt: sqlx_core::Async, + { + todo!() + } +} diff --git a/sqlx-postgres/src/lib.rs b/sqlx-postgres/src/lib.rs index 20a831e0..b2448209 100644 --- a/sqlx-postgres/src/lib.rs +++ b/sqlx-postgres/src/lib.rs @@ -26,7 +26,7 @@ use sqlx_core::Arguments; mod stream; mod column; -// mod connection; +mod connection; mod database; // mod error; // mod io;