Repository: launchbadge/sqlx
File: sqlx-macros-core/src/database/impls.rs (Rust)

Code before:

            // This can't be a provided method because the `static` can't reference `Self`.
            static CACHE: CachingDescribeBlocking<$database> = CachingDescribeBlocking::new();

            CACHE.describe(query, database_url)
        }
    };
    ($database:path, $describe:path) => {
        fn describe_blocking(
            query: &str,
            database_url: &str,
        ) -> sqlx_core::Result<sqlx_core::describe::Describe<Self>> {
            $describe(query, database_url)
        }
    };
}

// The paths below will also be emitted from the macros, so they need to match the final facade.
mod sqlx {
    #[cfg(feature = "mysql")]
    pub use sqlx_mysql as mysql;

    #[cfg(feature = "postgres")]
    pub use sqlx_postgres as postgres;

    #[cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))]
    pub use sqlx_sqlite as sqlite;
}

// NOTE: type mappings have been moved to `src/type_checking.rs` in their respective driver crates.
#[cfg(feature = "mysql")]
impl_database_ext! {
    sqlx::mysql::MySql,
    row: sqlx::mysql::MySqlRow,
}

#[cfg(feature = "postgres")]
impl_database_ext! {
    sqlx::postgres::Postgres,
    row: sqlx::postgres::PgRow,
}

#[cfg(any(feature = "sqlite", feature = "sqlite-unbundled"))]
impl_database_ext! {
    sqlx::sqlite::Sqlite,
    row: sqlx::sqlite::SqliteRow,
    // Since proc-macros don't benefit from async, we can make a describe call directly
    // which also ensures that the database is closed afterwards, regardless of errors.
    describe-blocking: sqlx_sqlite::describe_blocking,
}


Review comment (suggestion):
To avoid having to do this everywhere, both these features could enable a feature like `_sqllite` or `_sqlite-base`. We use the underscore prefix to indicate a feature that's not meant for direct use.

Code after:

            // This can't be a provided method because the `static` can't reference `Self`.
            static CACHE: CachingDescribeBlocking<$database> = CachingDescribeBlocking::new();

            CACHE.describe(query, database_url)
        }
    };
    ($database:path, $describe:path) => {
        fn describe_blocking(
            query: &str,
            database_url: &str,
        ) -> sqlx_core::Result<sqlx_core::describe::Describe<Self>> {
            $describe(query, database_url)
        }
    };
}

// The paths below will also be emitted from the macros, so they need to match the final facade.
mod sqlx {
    #[cfg(feature = "mysql")]
    pub use sqlx_mysql as mysql;

    #[cfg(feature = "postgres")]
    pub use sqlx_postgres as postgres;

    #[cfg(feature = "_sqlite")]
    pub use sqlx_sqlite as sqlite;
}

// NOTE: type mappings have been moved to `src/type_checking.rs` in their respective driver crates.
#[cfg(feature = "mysql")]
impl_database_ext! {
    sqlx::mysql::MySql,
    row: sqlx::mysql::MySqlRow,
}

#[cfg(feature = "postgres")]
impl_database_ext! {
    sqlx::postgres::Postgres,
    row: sqlx::postgres::PgRow,
}

#[cfg(feature = "_sqlite")]
impl_database_ext! {
    sqlx::sqlite::Sqlite,
    row: sqlx::sqlite::SqliteRow,
    // Since proc-macros don't benefit from async, we can make a describe call directly
    // which also ensures that the database is closed afterwards, regardless of errors.
    describe-blocking: sqlx_sqlite::describe_blocking,
}