diff --git a/sqlx/src/postgres/blocking.rs b/sqlx/src/postgres/blocking.rs deleted file mode 100644 index 217280ea..00000000 --- a/sqlx/src/postgres/blocking.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod connection; -mod options; diff --git a/sqlx/src/postgres/blocking/connection.rs b/sqlx/src/postgres/blocking/connection.rs deleted file mode 100644 index 3d95032b..00000000 --- a/sqlx/src/postgres/blocking/connection.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::blocking::{Close, Connect, Connection, Runtime}; -use crate::postgres::connection::PostgresConnection; -use crate::{Blocking, Result}; - -impl PostgresConnection { - /// Open a new database connection. - /// - /// For detailed information, refer to the async version of - /// this: [`connect`](#method.connect). - /// - /// Implemented with [`Connect::connect`]. - #[inline] - pub fn connect(url: &str) -> Result { - sqlx_postgres::PostgresConnection::::connect(url).map(Self) - } - - /// Checks if a connection to the database is still valid. - /// - /// For detailed information, refer to the async version of - /// this: [`ping`](#method.ping). - /// - /// Implemented with [`Connection::ping`]. - #[inline] - pub fn ping(&mut self) -> Result<()> { - self.0.ping() - } - - /// Explicitly close this database connection. - /// - /// For detailed information, refer to the async version of - /// this: [`close`](#method.close). - /// - /// Implemented with [`Close::close`]. - #[inline] - pub fn close(self) -> Result<()> { - self.0.close() - } -} - -impl Close for PostgresConnection { - #[inline] - fn close(self) -> Result<()> { - self.0.close() - } -} - -impl Connect for PostgresConnection { - #[inline] - fn connect(url: &str) -> Result { - sqlx_postgres::PostgresConnection::::connect(url).map(Self) - } -} - -impl Connection for PostgresConnection { - #[inline] - fn ping(&mut self) -> Result<()> { - self.0.ping() - } -} diff --git a/sqlx/src/postgres/blocking/options.rs b/sqlx/src/postgres/blocking/options.rs deleted file mode 100644 index 42ebfc6c..00000000 --- a/sqlx/src/postgres/blocking/options.rs +++ /dev/null @@ -1,28 +0,0 @@ -use crate::blocking::{ConnectOptions, Runtime}; -use crate::postgres::{PostgresConnectOptions, PostgresConnection}; -use crate::{Blocking, Result}; - -impl PostgresConnectOptions { - /// Open a new database connection with the configured connection options. - /// - /// For detailed information, refer to the async version of - /// this: [`connect`](#method.connect). - /// - /// Implemented with [`ConnectOptions::connect`]. - #[inline] - pub fn connect(&self) -> Result> { - as ConnectOptions>::connect(&self.0) - .map(PostgresConnection::) - } -} - -impl ConnectOptions for PostgresConnectOptions { - #[inline] - fn connect(&self) -> Result - where - Self::Connection: Sized, - { - as ConnectOptions>::connect(&self.0) - .map(PostgresConnection::) - } -} diff --git a/sqlx/src/postgres/connection.rs b/sqlx/src/postgres/connection.rs deleted file mode 100644 index c3b67b27..00000000 --- a/sqlx/src/postgres/connection.rs +++ /dev/null @@ -1,93 +0,0 @@ -use std::fmt::{self, Debug, Formatter}; - -#[cfg(feature = "async")] -use futures_util::future::{BoxFuture, FutureExt}; - -use super::{Postgres, PostgresConnectOptions}; -#[cfg(feature = "async")] -use crate::{Async, Result}; -use crate::{Close, Connect, Connection, DefaultRuntime, Runtime}; - -/// A single connection (also known as a session) to a MySQL database server. -#[allow(clippy::module_name_repetitions)] -pub struct PostgresConnection( - pub(super) sqlx_postgres::PostgresConnection, -); - -#[cfg(feature = "async")] -impl PostgresConnection { - /// Open a new database connection. - /// - /// A value of [`PostgresConnectOptions`] is parsed from the provided - /// connection `url`. - /// - /// ```text - /// postgres://[[user[:password]@]host][/database][?properties] - /// ``` - /// - /// Implemented with [`Connect::connect`][crate::Connect::connect]. - pub async fn connect(url: &str) -> Result { - sqlx_postgres::PostgresConnection::::connect(url).await.map(Self) - } - - /// Checks if a connection to the database is still valid. - /// - /// Implemented with [`Connection::ping`][crate::Connection::ping]. - pub async fn ping(&mut self) -> Result<()> { - self.0.ping().await - } - - /// Explicitly close this database connection. - /// - /// This method is **not required** for safe and consistent operation. However, it is - /// recommended to call it instead of letting a connection `drop` as MySQL - /// will be faster at cleaning up resources. - /// - /// Implemented with [`Close::close`][crate::Close::close]. - pub async fn close(self) -> Result<()> { - self.0.close().await - } -} - -impl Debug for PostgresConnection { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.0) - } -} - -impl Close for PostgresConnection { - #[cfg(feature = "async")] - #[inline] - fn close(self) -> BoxFuture<'static, Result<()>> - where - Rt: Async, - { - self.close().boxed() - } -} - -impl Connect for PostgresConnection { - type Options = PostgresConnectOptions; - - #[cfg(feature = "async")] - #[inline] - fn connect(url: &str) -> BoxFuture<'_, Result> - where - Rt: Async, - { - Self::connect(url).boxed() - } -} - -impl Connection for PostgresConnection { - type Database = Postgres; - - #[cfg(feature = "async")] - #[inline] - fn ping(&mut self) -> BoxFuture<'_, Result<()>> - where - Rt: Async, - { - self.ping().boxed() - } -} diff --git a/sqlx/src/postgres/database.rs b/sqlx/src/postgres/database.rs deleted file mode 100644 index c2a974d8..00000000 --- a/sqlx/src/postgres/database.rs +++ /dev/null @@ -1,15 +0,0 @@ -use sqlx_core::HasOutput; - -use super::PostgresConnection; -use crate::{Database, Runtime}; - -#[derive(Debug)] -pub struct Postgres; - -impl Database for Postgres { - type Connection = PostgresConnection; -} - -impl<'x> HasOutput<'x> for Postgres { - type Output = &'x mut Vec; -} diff --git a/sqlx/src/postgres/options.rs b/sqlx/src/postgres/options.rs deleted file mode 100644 index dd4e4a88..00000000 --- a/sqlx/src/postgres/options.rs +++ /dev/null @@ -1,95 +0,0 @@ -use std::fmt::{self, Debug, Formatter}; -use std::str::FromStr; - -#[cfg(feature = "async")] -use futures_util::future::{BoxFuture, FutureExt}; - -use crate::postgres::PostgresConnection; -#[cfg(feature = "async")] -use crate::Async; -use crate::{ConnectOptions, DefaultRuntime, Error, Result, Runtime}; - -mod builder; -mod getters; - -/// Options which can be used to configure how a MySQL connection is opened. -#[allow(clippy::module_name_repetitions)] -pub struct PostgresConnectOptions( - pub(super) sqlx_postgres::PostgresConnectOptions, -); - -impl PostgresConnectOptions { - /// Creates a default set of connection options. - /// - /// Implemented with [`Default`](#impl-Default). - #[inline] - pub fn new() -> Self { - Self::default() - } - - /// Parses connection options from a connection URL. - /// - /// ```text - /// postgres://[[user[:password]@]host][/database][?properties] - /// ``` - /// - /// Implemented with [`FromStr`](#impl-FromStr). - /// - #[inline] - pub fn parse(url: &str) -> Result { - Ok(Self(url.parse()?)) - } -} - -#[cfg(feature = "async")] -impl PostgresConnectOptions { - /// Open a new database connection with the configured connection options. - /// - /// Implemented with [`ConnectOptions::connect`]. - #[inline] - pub async fn connect(&self) -> Result> { - as ConnectOptions>::connect(&self.0) - .await - .map(PostgresConnection) - } -} - -impl ConnectOptions for PostgresConnectOptions { - type Connection = PostgresConnection; - - #[cfg(feature = "async")] - #[inline] - fn connect(&self) -> BoxFuture<'_, Result> - where - Self::Connection: Sized, - Rt: Async, - { - self.connect().boxed() - } -} - -impl Debug for PostgresConnectOptions { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.0) - } -} - -impl Default for PostgresConnectOptions { - fn default() -> Self { - Self(sqlx_postgres::PostgresConnectOptions::::default()) - } -} - -impl Clone for PostgresConnectOptions { - fn clone(&self) -> Self { - Self(self.0.clone()) - } -} - -impl FromStr for PostgresConnectOptions { - type Err = Error; - - fn from_str(url: &str) -> Result { - Ok(Self(url.parse()?)) - } -} diff --git a/sqlx/src/postgres/options/builder.rs b/sqlx/src/postgres/options/builder.rs deleted file mode 100644 index d1630601..00000000 --- a/sqlx/src/postgres/options/builder.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::path::Path; - -use super::PostgresConnectOptions; -use crate::Runtime; - -impl PostgresConnectOptions { - /// Sets the hostname of the database server. - /// - /// If the hostname begins with a slash (`/`), it is interpreted as the absolute path - /// to a Unix domain socket file instead of a hostname of a server. - /// - /// Defaults to `localhost`. - /// - #[inline] - pub fn host(&mut self, host: impl AsRef) -> &mut Self { - self.0.host(host); - self - } - - /// Sets the path of the Unix domain socket to connect to. - /// - /// Overrides [`host()`](#method.host) and [`port()`](#method.port). - /// - #[inline] - pub fn socket(&mut self, socket: impl AsRef) -> &mut Self { - self.0.socket(socket); - self - } - - /// Sets the TCP port number of the database server. - /// - /// Defaults to `3306`. - /// - #[inline] - pub fn port(&mut self, port: u16) -> &mut Self { - self.0.port(port); - self - } - - /// Sets the username to be used for authentication. - // FIXME: Specify what happens when you do NOT set this - pub fn username(&mut self, username: impl AsRef) -> &mut Self { - self.0.username(username); - self - } - - /// Sets the password to be used for authentication. - #[inline] - pub fn password(&mut self, password: impl AsRef) -> &mut Self { - self.0.password(password); - self - } - - /// Sets the default database for the connection. - #[inline] - pub fn database(&mut self, database: impl AsRef) -> &mut Self { - self.0.database(database); - self - } - - /// Sets the character set for the connection. - #[inline] - pub fn charset(&mut self, charset: impl AsRef) -> &mut Self { - self.0.charset(charset); - self - } - - /// Sets the timezone for the connection. - #[inline] - pub fn timezone(&mut self, timezone: impl AsRef) -> &mut Self { - self.0.timezone(timezone); - self - } -} diff --git a/sqlx/src/postgres/options/getters.rs b/sqlx/src/postgres/options/getters.rs deleted file mode 100644 index ea63beb3..00000000 --- a/sqlx/src/postgres/options/getters.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::path::Path; - -use super::PostgresConnectOptions; -use crate::Runtime; - -impl PostgresConnectOptions { - /// Returns the hostname of the database server. - #[must_use] - #[inline] - pub fn get_host(&self) -> &str { - self.0.get_host() - } - - /// Returns the TCP port number of the database server. - #[must_use] - #[inline] - pub fn get_port(&self) -> u16 { - self.0.get_port() - } - - /// Returns the path to the Unix domain socket, if one is configured. - #[must_use] - #[inline] - pub fn get_socket(&self) -> Option<&Path> { - self.0.get_socket() - } - - /// Returns the default database name. - #[must_use] - #[inline] - pub fn get_database(&self) -> Option<&str> { - self.0.get_database() - } - - /// Returns the username to be used for authentication. - #[must_use] - #[inline] - pub fn get_username(&self) -> Option<&str> { - self.0.get_username() - } - - /// Returns the password to be used for authentication. - #[must_use] - #[inline] - pub fn get_password(&self) -> Option<&str> { - self.0.get_password() - } - - /// Returns the character set for the connection. - #[must_use] - #[inline] - pub fn get_charset(&self) -> &str { - self.0.get_charset() - } - - /// Returns the timezone for the connection. - #[must_use] - #[inline] - pub fn get_timezone(&self) -> &str { - self.0.get_timezone() - } -}