launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.41k stars 1.28k forks source link

any_kind() not available #3155

Open prabirshrestha opened 7 months ago

prabirshrestha commented 7 months ago

Bug Description

any_kind() is not available in Pool<Any> in v0.7.

Minimal Reproduction

A small code snippet or a link to a Github repo or Gist, with instructions on reproducing the bug.

[dependencies]
sqlx = { version = "0.7.4", features = ["any", "sqlite", "postgres", "mysql"] }
tokio = { version = "1.36.0", features = ["full"] }
use sqlx::{Any, Pool};

#[tokio::main]
async fn main() {
    let pool: Pool<Any> = Pool::connect("sqlite::memory:").await.unwrap();
    let kind = pool.any_kind();
}

Error:

error[E0599]: no method named `any_kind` found for struct `Pool` in the current scope
 --> src/main.rs:6:21
  |
6 |     let kind = pool.any_kind();
  |                     ^^^^^^^^ method not found in `Pool<Any>`

For more information about this error, try `rustc --explain E0599`.

Info

0Killian commented 4 months ago

I have the same issue, found out that the compilation of any_kind() is gated behind some features in sqlx_core (sqlx-core/src/pool/mod.rs):

#[cfg(all(
    any(
        feature = "postgres",
        feature = "mysql",
        feature = "mssql",
        feature = "sqlite"
    ),
    feature = "any"
))]
impl Pool<Any> {
    /// Returns the database driver currently in-use by this `Pool`.
    ///
    /// Determined by the connection URL.
    pub fn any_kind(&self) -> AnyKind {
        self.0
            .connect_options
            .read()
            .expect("write-lock holder panicked")
            .kind()
    }
}

Turns out that the features postgres, mysql, mssql and sqlite have been removed during refactoring (#2039), as well as the kind() method on AnyConnectOptions.

Adding these features back in the sqlx_core crate and implementing the missing kind() method on AnyConnectOptions brings back any_kind(), though I don't know if it's the intended way to do it here (perhaps we could remove these feature flags alltogether?)