diff --git a/CHANGELOG.md b/CHANGELOG.md index 3974654..c8ec3aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Add WASM support + ## [0.12.0] - 2024-05-04 - Add `Send` to `Manager::Type` and `Manager::Error` associated types diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index 5105f4f..08bf657 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Add WASM support +- Expose API for providing a custom `Connect` implementation. + ## [0.13.1] - 2024-05-04 - Update `deadpool` dependency to version `0.12` diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index c651a9b..247d39b 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -14,8 +14,7 @@ readme = "README.md" all-features = true [features] -default = ["runtime", "rt_tokio_1"] -runtime = ["tokio-postgres/runtime"] +default = ["rt_tokio_1"] rt_tokio_1 = ["deadpool/rt_tokio_1"] rt_async-std_1 = ["deadpool/rt_async-std_1"] serde = ["deadpool/serde", "dep:serde"] @@ -28,11 +27,14 @@ serde = { package = "serde", version = "1.0", features = [ "derive", ], optional = true } tokio = { version = "1.29", features = ["rt"] } -tokio-postgres = { version = "0.7.9", default-features = false } tracing = "0.1.37" +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +tokio-postgres = "0.7.9" + [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2", features = ["js"] } +tokio-postgres = { version = "0.7.9", default-features = false } [dev-dependencies] config = { version = "0.14", features = ["json"] } diff --git a/postgres/src/config.rs b/postgres/src/config.rs index 1506eab..477dfd4 100644 --- a/postgres/src/config.rs +++ b/postgres/src/config.rs @@ -7,11 +7,11 @@ use tokio_postgres::config::{ SslMode as PgSslMode, TargetSessionAttrs as PgTargetSessionAttrs, }; -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] use super::Pool; -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] use crate::{CreatePoolError, PoolBuilder, Runtime}; -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] use tokio_postgres::{ tls::{MakeTlsConnect, TlsConnect}, Socket, @@ -151,7 +151,7 @@ impl Config { Self::default() } - #[cfg(feature = "runtime")] + #[cfg(not(target_arch = "wasm32"))] /// Creates a new [`Pool`] using this [`Config`]. /// /// # Errors @@ -171,7 +171,7 @@ impl Config { builder.build().map_err(CreatePoolError::Build) } - #[cfg(feature = "runtime")] + #[cfg(not(target_arch = "wasm32"))] /// Creates a new [`PoolBuilder`] using this [`Config`]. /// /// # Errors diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs index e01c4cc..56c36e5 100644 --- a/postgres/src/lib.rs +++ b/postgres/src/lib.rs @@ -37,7 +37,7 @@ use std::{ }; use deadpool::managed; -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] use tokio::spawn; use tokio::task::JoinHandle; use tokio_postgres::{ @@ -45,7 +45,7 @@ use tokio_postgres::{ Transaction as PgTransaction, TransactionBuilder as PgTransactionBuilder, }; -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] use tokio_postgres::{ tls::{MakeTlsConnect, TlsConnect}, Socket, @@ -89,7 +89,7 @@ pub struct Manager { } impl Manager { - #[cfg(feature = "runtime")] + #[cfg(not(target_arch = "wasm32"))] /// Creates a new [`Manager`] using the given [`tokio_postgres::Config`] and /// `tls` connector. pub fn new(pg_config: tokio_postgres::Config, tls: T) -> Self @@ -102,7 +102,7 @@ impl Manager { Self::from_config(pg_config, tls, ManagerConfig::default()) } - #[cfg(feature = "runtime")] + #[cfg(not(target_arch = "wasm32"))] /// Create a new [`Manager`] using the given [`tokio_postgres::Config`], and /// `tls` connector and [`ManagerConfig`]. pub fn from_config(pg_config: tokio_postgres::Config, tls: T, config: ManagerConfig) -> Self @@ -188,7 +188,7 @@ pub trait Connect: Sync + Send { ) -> BoxFuture<'_, Result<(PgClient, JoinHandle<()>), Error>>; } -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] /// Provides an implementation of [`Connect`] that establishes the connection /// using the `tokio_postgres` configuration itself. #[derive(Debug)] @@ -203,7 +203,7 @@ where pub tls: T, } -#[cfg(feature = "runtime")] +#[cfg(not(target_arch = "wasm32"))] impl Connect for ConfigConnectImpl where T: MakeTlsConnect + Clone + Sync + Send + 'static,