sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Import sqlx without selecting async runtime & TLS backend

Open oscartbeaumont opened this issue 3 years ago • 3 comments

Assuming it is possible would you be open to adding a feature flag that bypasses the compiler warning here so you can import sqlx in a library without dictating the async runtime and TLS backend for the upstream users of the library. I am building a library and would like to implement a trait on sqlx::types::Jsonand also with a postgres feature sqlx::postgres::types::PgTimeTz sqlx::postgres::types::PgInterval, sqlx::postgres::types::PgRange, sqlx::postgres::types::PgMoney. sqlx::postgres::types::PgTimeTz.

I would be willing to PR, I just want to check if it's something that would be accepted upstream and discuss how it would work.

This may be a weird request but I am working on Specta which is a sub-component of rspc. Specta does type introspection and its main purpose is to convert your Rust types into Typescript. Give the rspc docs on Specta a look for an overview of what it does and how it works.

oscartbeaumont avatar Aug 08 '22 15:08 oscartbeaumont

I happened to run into the same issue today. I wanted to be able to implement Encode and Decode for a library type but I am unable to do so without choosing a runtime, which seems wholly unnecessary.

Cassy343 avatar Aug 09 '22 03:08 Cassy343

Not sure if it completely solves your problem, but it was brought to my attention that upstream crates can depend on sqlx without selecting a runtime, and as long as a downstream crate selects a runtime via a feature flag then the upstream crate will compile successfully as part of the build process. If you need the upstream crate to compile with sqlx for testing then you can enable the feature in a dev-dependency.

Cassy343 avatar Aug 09 '22 13:08 Cassy343

I recently did something like that for another project but it didn't click in my mind that I could use it here. I will try that! Thanks for your help!

oscartbeaumont avatar Aug 10 '22 15:08 oscartbeaumont