From 257c4c86e10bae7e61a0a32d5b5069c3f84f407f Mon Sep 17 00:00:00 2001 From: jkomyno Date: Tue, 14 Nov 2023 09:45:23 +0100 Subject: [PATCH] chore(quaint): rename "*-connector" feature flag to "*-native" --- Cargo.toml | 2 +- quaint/Cargo.toml | 20 ++++++------- quaint/README.md | 8 +++--- quaint/src/connector.rs | 20 ++++--------- quaint/src/connector/mssql.rs | 2 +- quaint/src/connector/mssql/native/mod.rs | 2 +- quaint/src/connector/mysql.rs | 2 +- quaint/src/connector/mysql/native/mod.rs | 2 +- quaint/src/connector/mysql/wasm/common.rs | 12 ++++---- quaint/src/connector/postgres.rs | 2 +- quaint/src/connector/postgres/native/mod.rs | 2 +- quaint/src/connector/postgres/wasm/common.rs | 18 ++++++------ quaint/src/connector/sqlite.rs | 2 +- quaint/src/connector/sqlite/native/mod.rs | 2 +- quaint/src/error.rs | 2 +- quaint/src/pooled/manager.rs | 30 ++++++++++---------- quaint/src/single.rs | 12 ++++---- 17 files changed, 66 insertions(+), 74 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 66f4399ff6db..b32a1a85cf18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,7 @@ features = [ "pooled", "postgresql", "sqlite", - "connectors", + "native", ] [profile.dev.package.backtrace] diff --git a/quaint/Cargo.toml b/quaint/Cargo.toml index abe9fece9746..7c804add2f5e 100644 --- a/quaint/Cargo.toml +++ b/quaint/Cargo.toml @@ -29,21 +29,21 @@ docs = [] # way to access database-specific methods when you need extra control. expose-drivers = [] -connectors = [ - "postgresql-connector", - "mysql-connector", - "mssql-connector", - "sqlite-connector", +native = [ + "postgresql-native", + "mysql-native", + "mssql-native", + "sqlite-native", ] -all = ["connectors", "pooled"] +all = ["native", "pooled"] vendored-openssl = [ "postgres-native-tls/vendored-openssl", "mysql_async/vendored-openssl", ] -postgresql-connector = [ +postgresql-native = [ "postgresql", "native-tls", "tokio-postgres", @@ -57,7 +57,7 @@ postgresql-connector = [ ] postgresql = [] -mssql-connector = [ +mssql-native = [ "mssql", "tiberius", "tokio-util", @@ -66,11 +66,11 @@ mssql-connector = [ ] mssql = [] -mysql-connector = ["mysql", "mysql_async", "tokio/time", "lru-cache"] +mysql-native = ["mysql", "mysql_async", "tokio/time", "lru-cache"] mysql = ["chrono/std"] pooled = ["mobc"] -sqlite-connector = ["sqlite", "rusqlite/bundled", "tokio/sync"] +sqlite-native = ["sqlite", "rusqlite/bundled", "tokio/sync"] sqlite = ["rusqlite"] fmt-sql = ["sqlformat"] diff --git a/quaint/README.md b/quaint/README.md index 3a9b41c65751..03108d9090d3 100644 --- a/quaint/README.md +++ b/quaint/README.md @@ -16,13 +16,13 @@ Quaint is an abstraction over certain SQL databases. It provides: ### Feature flags - `mysql`: Support for MySQL databases. - - On non-WebAssembly targets, choose `mysql-connector` instead. + - On non-WebAssembly targets, choose `mysql-native` instead. - `postgresql`: Support for PostgreSQL databases. - - On non-WebAssembly targets, choose `postgresql-connector` instead. + - On non-WebAssembly targets, choose `postgresql-native` instead. - `sqlite`: Support for SQLite databases. - - On non-WebAssembly targets, choose `sqlite-connector` instead. + - On non-WebAssembly targets, choose `sqlite-native` instead. - `mssql`: Support for Microsoft SQL Server databases. - - On non-WebAssembly targets, choose `mssql-connector` instead. + - On non-WebAssembly targets, choose `mssql-native` instead. - `pooled`: A connection pool in `pooled::Quaint`. - `vendored-openssl`: Statically links against a vendored OpenSSL library on non-Windows or non-Apple platforms. diff --git a/quaint/src/connector.rs b/quaint/src/connector.rs index 0aaa19aa463b..7903d23931c0 100644 --- a/quaint/src/connector.rs +++ b/quaint/src/connector.rs @@ -14,11 +14,7 @@ mod connection_info; pub mod metrics; mod queryable; mod result_set; -#[cfg(any( - feature = "mssql-connector", - feature = "postgresql-connector", - feature = "mysql-connector" -))] +#[cfg(any(feature = "mssql-native", feature = "postgresql-native", feature = "mysql-native"))] mod timeout; mod transaction; mod type_identifier; @@ -27,11 +23,7 @@ pub use self::result_set::*; pub use connection_info::*; pub use queryable::*; pub use transaction::*; -#[cfg(any( - feature = "mssql-connector", - feature = "postgresql-connector", - feature = "mysql-connector" -))] +#[cfg(any(feature = "mssql-native", feature = "postgresql-native", feature = "mysql-native"))] #[allow(unused_imports)] pub(crate) use type_identifier::*; @@ -39,28 +31,28 @@ pub use self::metrics::query; #[cfg(feature = "postgresql")] pub(crate) mod postgres; -#[cfg(feature = "postgresql-connector")] +#[cfg(feature = "postgresql-native")] pub use postgres::native::*; #[cfg(feature = "postgresql")] pub use postgres::wasm::common::*; #[cfg(feature = "mysql")] pub(crate) mod mysql; -#[cfg(feature = "mysql-connector")] +#[cfg(feature = "mysql-native")] pub use mysql::native::*; #[cfg(feature = "mysql")] pub use mysql::wasm::common::*; #[cfg(feature = "sqlite")] pub(crate) mod sqlite; -#[cfg(feature = "sqlite-connector")] +#[cfg(feature = "sqlite-native")] pub use sqlite::native::*; #[cfg(feature = "sqlite")] pub use sqlite::wasm::common::*; #[cfg(feature = "mssql")] pub(crate) mod mssql; -#[cfg(feature = "mssql-connector")] +#[cfg(feature = "mssql-native")] pub use mssql::native::*; #[cfg(feature = "mssql")] pub use mssql::wasm::common::*; diff --git a/quaint/src/connector/mssql.rs b/quaint/src/connector/mssql.rs index ea681bd08d18..c83b5f1f7266 100644 --- a/quaint/src/connector/mssql.rs +++ b/quaint/src/connector/mssql.rs @@ -3,5 +3,5 @@ pub use wasm::common::MssqlUrl; #[cfg(feature = "mssql")] pub(crate) mod wasm; -#[cfg(feature = "mssql-connector")] +#[cfg(feature = "mssql-native")] pub(crate) mod native; diff --git a/quaint/src/connector/mssql/native/mod.rs b/quaint/src/connector/mssql/native/mod.rs index 6a1019c4f594..8458935814b4 100644 --- a/quaint/src/connector/mssql/native/mod.rs +++ b/quaint/src/connector/mssql/native/mod.rs @@ -1,6 +1,6 @@ //! Definitions for the MSSQL connector. //! This module is not compatible with wasm32-* targets. -//! This module is only available with the `mssql-connector` feature. +//! This module is only available with the `mssql-native` feature. mod conversion; mod error; diff --git a/quaint/src/connector/mysql.rs b/quaint/src/connector/mysql.rs index 1794cc738b1e..1e52af6a83a0 100644 --- a/quaint/src/connector/mysql.rs +++ b/quaint/src/connector/mysql.rs @@ -4,5 +4,5 @@ pub use wasm::error::MysqlError; #[cfg(feature = "mysql")] pub(crate) mod wasm; -#[cfg(feature = "mysql-connector")] +#[cfg(feature = "mysql-native")] pub(crate) mod native; diff --git a/quaint/src/connector/mysql/native/mod.rs b/quaint/src/connector/mysql/native/mod.rs index 234f7fb3d74f..e72a2c47a9a1 100644 --- a/quaint/src/connector/mysql/native/mod.rs +++ b/quaint/src/connector/mysql/native/mod.rs @@ -1,6 +1,6 @@ //! Definitions for the MySQL connector. //! This module is not compatible with wasm32-* targets. -//! This module is only available with the `mysql-connector` feature. +//! This module is only available with the `mysql-native` feature. mod conversion; mod error; diff --git a/quaint/src/connector/mysql/wasm/common.rs b/quaint/src/connector/mysql/wasm/common.rs index 58598d6509ac..c17b2224c0ef 100644 --- a/quaint/src/connector/mysql/wasm/common.rs +++ b/quaint/src/connector/mysql/wasm/common.rs @@ -123,7 +123,7 @@ impl MysqlUrl { } fn parse_query_params(url: &Url) -> Result { - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] let mut ssl_opts = { let mut ssl_opts = mysql_async::SslOpts::default(); ssl_opts = ssl_opts.with_danger_accept_invalid_certs(true); @@ -159,7 +159,7 @@ impl MysqlUrl { "sslcert" => { use_ssl = true; - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] { ssl_opts = ssl_opts.with_root_cert_path(Some(Path::new(&*v).to_path_buf())); } @@ -219,7 +219,7 @@ impl MysqlUrl { use_ssl = true; match v.as_ref() { "strict" => { - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] { ssl_opts = ssl_opts.with_danger_accept_invalid_certs(false); } @@ -263,7 +263,7 @@ impl MysqlUrl { // Wrapping this in a block, as attributes on expressions are still experimental // See: https://github.com/rust-lang/rust/issues/15701 - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] { ssl_opts = match identity { Some((Some(path), Some(pw))) => { @@ -279,7 +279,7 @@ impl MysqlUrl { } Ok(MysqlUrlQueryParams { - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] ssl_opts, connection_limit, use_ssl, @@ -313,6 +313,6 @@ pub(crate) struct MysqlUrlQueryParams { pub(crate) prefer_socket: Option, pub(crate) statement_cache_size: usize, - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] pub(crate) ssl_opts: mysql_async::SslOpts, } diff --git a/quaint/src/connector/postgres.rs b/quaint/src/connector/postgres.rs index 0f4da84a7c67..73a8547b8a65 100644 --- a/quaint/src/connector/postgres.rs +++ b/quaint/src/connector/postgres.rs @@ -4,5 +4,5 @@ pub use wasm::error::PostgresError; #[cfg(feature = "postgresql")] pub(crate) mod wasm; -#[cfg(feature = "postgresql-connector")] +#[cfg(feature = "postgresql-native")] pub(crate) mod native; diff --git a/quaint/src/connector/postgres/native/mod.rs b/quaint/src/connector/postgres/native/mod.rs index a6628086aaae..fbb4760ed19f 100644 --- a/quaint/src/connector/postgres/native/mod.rs +++ b/quaint/src/connector/postgres/native/mod.rs @@ -1,6 +1,6 @@ //! Definitions for the Postgres connector. //! This module is not compatible with wasm32-* targets. -//! This module is only available with the `postgresql-connector` feature. +//! This module is only available with the `postgresql-native` feature. mod conversion; mod error; diff --git a/quaint/src/connector/postgres/wasm/common.rs b/quaint/src/connector/postgres/wasm/common.rs index c90826c40548..7b9b3aafabb4 100644 --- a/quaint/src/connector/postgres/wasm/common.rs +++ b/quaint/src/connector/postgres/wasm/common.rs @@ -11,7 +11,7 @@ use url::{Host, Url}; use crate::error::{Error, ErrorKind}; -#[cfg(feature = "postgresql-connector")] +#[cfg(feature = "postgresql-native")] use tokio_postgres::config::{ChannelBinding, SslMode}; #[derive(Clone)] @@ -211,9 +211,9 @@ impl PostgresUrl { } fn parse_query_params(url: &Url) -> Result { - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] let mut ssl_mode = SslMode::Prefer; - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] let mut channel_binding = ChannelBinding::Prefer; let mut connection_limit = None; @@ -240,7 +240,7 @@ impl PostgresUrl { .parse() .map_err(|_| Error::builder(ErrorKind::InvalidConnectionArguments).build())?; } - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] "sslmode" => { match v.as_ref() { "disable" => ssl_mode = SslMode::Disable, @@ -348,7 +348,7 @@ impl PostgresUrl { "application_name" => { application_name = Some(v.to_string()); } - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] "channel_binding" => { match v.as_ref() { "disable" => channel_binding = ChannelBinding::Disable, @@ -390,9 +390,9 @@ impl PostgresUrl { max_idle_connection_lifetime, application_name, options, - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] channel_binding, - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] ssl_mode, }) } @@ -427,10 +427,10 @@ pub(crate) struct PostgresUrlQueryParams { pub(crate) application_name: Option, pub(crate) options: Option, - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] pub(crate) channel_binding: ChannelBinding, - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] pub(crate) ssl_mode: SslMode, } diff --git a/quaint/src/connector/sqlite.rs b/quaint/src/connector/sqlite.rs index 0e699c211878..45611aab9357 100644 --- a/quaint/src/connector/sqlite.rs +++ b/quaint/src/connector/sqlite.rs @@ -3,5 +3,5 @@ pub use wasm::error::SqliteError; #[cfg(feature = "sqlite")] pub(crate) mod wasm; -#[cfg(feature = "sqlite-connector")] +#[cfg(feature = "sqlite-native")] pub(crate) mod native; diff --git a/quaint/src/connector/sqlite/native/mod.rs b/quaint/src/connector/sqlite/native/mod.rs index 66f0e6d840df..bdf5c473fd4d 100644 --- a/quaint/src/connector/sqlite/native/mod.rs +++ b/quaint/src/connector/sqlite/native/mod.rs @@ -1,6 +1,6 @@ //! Definitions for the SQLite connector. //! This module is not compatible with wasm32-* targets. -//! This module is only available with the `sqlite-connector` feature. +//! This module is only available with the `sqlite-native` feature. mod conversion; mod error; diff --git a/quaint/src/error.rs b/quaint/src/error.rs index f6ae3b3ee34a..a77513876726 100644 --- a/quaint/src/error.rs +++ b/quaint/src/error.rs @@ -282,7 +282,7 @@ pub enum ErrorKind { } impl ErrorKind { - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] pub(crate) fn value_out_of_range(msg: impl Into) -> Self { Self::ValueOutOfRange { message: msg.into() } } diff --git a/quaint/src/pooled/manager.rs b/quaint/src/pooled/manager.rs index c31fd44fbcae..73441b7609ba 100644 --- a/quaint/src/pooled/manager.rs +++ b/quaint/src/pooled/manager.rs @@ -1,8 +1,8 @@ -#[cfg(feature = "mssql-connector")] +#[cfg(feature = "mssql-native")] use crate::connector::MssqlUrl; -#[cfg(feature = "mysql-connector")] +#[cfg(feature = "mysql-native")] use crate::connector::MysqlUrl; -#[cfg(feature = "postgresql-connector")] +#[cfg(feature = "postgresql-native")] use crate::connector::PostgresUrl; use crate::{ ast, @@ -97,7 +97,7 @@ impl Manager for QuaintManager { async fn connect(&self) -> crate::Result { let conn = match self { - #[cfg(feature = "sqlite-connector")] + #[cfg(feature = "sqlite-native")] QuaintManager::Sqlite { url, .. } => { use crate::connector::Sqlite; @@ -106,19 +106,19 @@ impl Manager for QuaintManager { Ok(Box::new(conn) as Self::Connection) } - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] QuaintManager::Mysql { url } => { use crate::connector::Mysql; Ok(Box::new(Mysql::new(url.clone()).await?) as Self::Connection) } - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] QuaintManager::Postgres { url } => { use crate::connector::PostgreSql; Ok(Box::new(PostgreSql::new(url.clone()).await?) as Self::Connection) } - #[cfg(feature = "mssql-connector")] + #[cfg(feature = "mssql-native")] QuaintManager::Mssql { url } => { use crate::connector::Mssql; Ok(Box::new(Mssql::new(url.clone()).await?) as Self::Connection) @@ -146,7 +146,7 @@ mod tests { use crate::pooled::Quaint; #[tokio::test] - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] async fn mysql_default_connection_limit() { let conn_string = std::env::var("TEST_MYSQL").expect("TEST_MYSQL connection string not set."); @@ -156,7 +156,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] async fn mysql_custom_connection_limit() { let conn_string = format!( "{}?connection_limit=10", @@ -169,7 +169,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] async fn psql_default_connection_limit() { let conn_string = std::env::var("TEST_PSQL").expect("TEST_PSQL connection string not set."); @@ -179,7 +179,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] async fn psql_custom_connection_limit() { let conn_string = format!( "{}?connection_limit=10", @@ -192,7 +192,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "mssql-connector")] + #[cfg(feature = "mssql-native")] async fn mssql_default_connection_limit() { let conn_string = std::env::var("TEST_MSSQL").expect("TEST_MSSQL connection string not set."); @@ -202,7 +202,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "mssql-connector")] + #[cfg(feature = "mssql-native")] async fn mssql_custom_connection_limit() { let conn_string = format!( "{};connectionLimit=10", @@ -215,7 +215,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "sqlite-connector")] + #[cfg(feature = "sqlite-native")] async fn test_default_connection_limit() { let conn_string = "file:db/test.db".to_string(); let pool = Quaint::builder(&conn_string).unwrap().build(); @@ -224,7 +224,7 @@ mod tests { } #[tokio::test] - #[cfg(feature = "sqlite-connector")] + #[cfg(feature = "sqlite-native")] async fn test_custom_connection_limit() { let conn_string = "file:db/test.db?connection_limit=10".to_string(); let pool = Quaint::builder(&conn_string).unwrap().build(); diff --git a/quaint/src/single.rs b/quaint/src/single.rs index e4e72ab614fa..1a4dbdf52a61 100644 --- a/quaint/src/single.rs +++ b/quaint/src/single.rs @@ -7,7 +7,7 @@ use crate::{ use async_trait::async_trait; use std::{fmt, sync::Arc}; -#[cfg(feature = "sqlite-connector")] +#[cfg(feature = "sqlite-native")] use std::convert::TryFrom; /// The main entry point and an abstraction over a database connection. @@ -129,27 +129,27 @@ impl Quaint { #[allow(unreachable_code)] pub async fn new(url_str: &str) -> crate::Result { let inner = match url_str { - #[cfg(feature = "sqlite-connector")] + #[cfg(feature = "sqlite-native")] s if s.starts_with("file") => { let params = connector::SqliteParams::try_from(s)?; let sqlite = connector::Sqlite::new(¶ms.file_path)?; Arc::new(sqlite) as Arc } - #[cfg(feature = "mysql-connector")] + #[cfg(feature = "mysql-native")] s if s.starts_with("mysql") => { let url = connector::MysqlUrl::new(url::Url::parse(s)?)?; let mysql = connector::Mysql::new(url).await?; Arc::new(mysql) as Arc } - #[cfg(feature = "postgresql-connector")] + #[cfg(feature = "postgresql-native")] s if s.starts_with("postgres") || s.starts_with("postgresql") => { let url = connector::PostgresUrl::new(url::Url::parse(s)?)?; let psql = connector::PostgreSql::new(url).await?; Arc::new(psql) as Arc } - #[cfg(feature = "mssql-connector")] + #[cfg(feature = "mssql-native")] s if s.starts_with("jdbc:sqlserver") | s.starts_with("sqlserver") => { let url = connector::MssqlUrl::new(s)?; let psql = connector::Mssql::new(url).await?; @@ -165,7 +165,7 @@ impl Quaint { Ok(Self { inner, connection_info }) } - #[cfg(feature = "sqlite-connector")] + #[cfg(feature = "sqlite-native")] /// Open a new SQLite database in memory. pub fn new_in_memory() -> crate::Result { use crate::connector::DEFAULT_SQLITE_SCHEMA_NAME;