Skip to content

Commit

Permalink
Remove runtime feature keeping the WASM support intact
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder committed May 4, 2024
1 parent 776b59f commit 99087b7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions postgres/CHANGELOG.md
Expand Up @@ -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`
Expand Down
8 changes: 5 additions & 3 deletions postgres/Cargo.toml
Expand Up @@ -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"]
Expand All @@ -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"] }
Expand Down
10 changes: 5 additions & 5 deletions postgres/src/config.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl Config {
Self::default()
}

#[cfg(feature = "runtime")]
#[cfg(not(target_arch = "wasm32"))]
/// Creates a new [`Pool`] using this [`Config`].
///
/// # Errors
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions postgres/src/lib.rs
Expand Up @@ -37,15 +37,15 @@ use std::{
};

use deadpool::managed;
#[cfg(feature = "runtime")]
#[cfg(not(target_arch = "wasm32"))]
use tokio::spawn;
use tokio::task::JoinHandle;
use tokio_postgres::{
types::Type, Client as PgClient, Config as PgConfig, Error, IsolationLevel, Statement,
Transaction as PgTransaction, TransactionBuilder as PgTransactionBuilder,
};

#[cfg(feature = "runtime")]
#[cfg(not(target_arch = "wasm32"))]
use tokio_postgres::{
tls::{MakeTlsConnect, TlsConnect},
Socket,
Expand Down Expand Up @@ -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<T>(pg_config: tokio_postgres::Config, tls: T) -> Self
Expand All @@ -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<T>(pg_config: tokio_postgres::Config, tls: T, config: ManagerConfig) -> Self
Expand Down Expand Up @@ -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)]
Expand All @@ -203,7 +203,7 @@ where
pub tls: T,
}

#[cfg(feature = "runtime")]
#[cfg(not(target_arch = "wasm32"))]
impl<T> Connect for ConfigConnectImpl<T>
where
T: MakeTlsConnect<Socket> + Clone + Sync + Send + 'static,
Expand Down

0 comments on commit 99087b7

Please sign in to comment.