bikeshedder / deadpool

Dead simple pool implementation for rust with async-await
Apache License 2.0
1.08k stars 137 forks source link

Expose API for providing a custom Connect impl and pass through the `runtime` feature #316

Closed shadaj closed 6 months ago

shadaj commented 7 months ago

Currently, deadpool-postgres only offers APIs for creating pools that instantiate their underlying connections based on a tokio_postgres::Config. In some situations (mocking, custom networking), it is useful to provide an alternate connection mechanism. Thankfully, deadpool-postgres already has the Client trait for this so we just need to expose it publicly. As part of this, we also expose the existing ConnectImpl as a public ConfigConnectImpl for code that needs to abstract over a selection of connection strategy.

Our main use case for this is to enable use on WASM, where tokio_postgres is already supported but does not have the tokio-postgres/runtime feature enabled (which enables the APIs for creation based on a database URL). So this PR also adds a runtime feature that maps to the underlying tokio-postgres one for now (defaulting to true to preserve compatibility). It also includes a minor patch to disable the keepalives_idle config on WASM where it is not supported.

shadaj commented 7 months ago

For tests, let me look into adding CI logic to test at least compilation on WASM.

shadaj commented 7 months ago

In theory, the new CI config should test compilation on WASM!

bikeshedder commented 6 months ago

I just removed the runtime feature replacing it by conditional dependencies instead:

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio-postgres = "0.7.9"

[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio-postgres = { version = "0.7.9", default-features = false }

Could you please check if that works for you?

This should be a non breaking release for non-WASM targets now.

shadaj commented 6 months ago

@bikeshedder oh actually I think this doesn't work, due to https://github.com/rust-lang/cargo/issues/1197

In our downstream crates we are seeing the default features pulled in when compiling on WASM.