deadpool icon indicating copy to clipboard operation
deadpool copied to clipboard

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

Open shadaj opened this issue 4 months ago • 2 comments

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 avatar Apr 15 '24 02:04 shadaj

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

shadaj avatar Apr 20 '24 01:04 shadaj

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

shadaj avatar Apr 20 '24 02:04 shadaj

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.

bikeshedder avatar May 04 '24 10:05 bikeshedder

@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.

shadaj avatar May 05 '24 18:05 shadaj