diff --git a/Cargo.toml b/Cargo.toml index c42e36de..e6bdafd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ actix-rt = { version = "2.2.0" } maplit = { version = "1" } rust_decimal_macros = { version = "1" } tracing-subscriber = { version = "0.3", features = ["env-filter"] } -sea-orm = { path = ".", features = ["mock", "debug-print", "tests-cfg", "postgres-array"] } +sea-orm = { path = ".", features = ["mock", "debug-print", "tests-cfg", "postgres-array", "sea-orm-internal"] } pretty_assertions = { version = "0.7" } time = { version = "0.3", features = ["macros"] } uuid = { version = "1", features = ["v4"] } @@ -81,6 +81,7 @@ with-bigdecimal = ["bigdecimal", "sea-query/with-bigdecimal", "sea-query-binder? with-uuid = ["uuid", "sea-query/with-uuid", "sea-query-binder?/with-uuid", "sqlx?/uuid"] with-time = ["time", "sea-query/with-time", "sea-query-binder?/with-time", "sqlx?/time"] postgres-array = ["sea-query/postgres-array", "sea-query-binder?/postgres-array", "sea-orm-macros?/postgres-array"] +sea-orm-internal = [] sqlx-dep = [] sqlx-all = ["sqlx-mysql", "sqlx-postgres", "sqlx-sqlite"] sqlx-mysql = ["sqlx-dep", "sea-query-binder/sqlx-mysql", "sqlx/mysql"] diff --git a/src/database/db_connection.rs b/src/database/db_connection.rs index e0839d3c..24196cf3 100644 --- a/src/database/db_connection.rs +++ b/src/database/db_connection.rs @@ -380,6 +380,36 @@ impl DatabaseConnection { } } +#[cfg(feature = "sea-orm-internal")] +impl DatabaseConnection { + /// Get [sqlx::MySqlPool] + #[cfg(feature = "sqlx-mysql")] + pub fn get_mysql_connection_pool(&self) -> &sqlx::MySqlPool { + match self { + DatabaseConnection::SqlxMySqlPoolConnection(conn) => &conn.pool, + _ => panic!("Not MySQL Connection"), + } + } + + /// Get [sqlx::PgPool] + #[cfg(feature = "sqlx-postgres")] + pub fn get_postgres_connection_pool(&self) -> &sqlx::PgPool { + match self { + DatabaseConnection::SqlxPostgresPoolConnection(conn) => &conn.pool, + _ => panic!("Not Postgres Connection"), + } + } + + /// Get [sqlx::SqlitePool] + #[cfg(feature = "sqlx-sqlite")] + pub fn get_sqlite_connection_pool(&self) -> &sqlx::SqlitePool { + match self { + DatabaseConnection::SqlxSqlitePoolConnection(conn) => &conn.pool, + _ => panic!("Not SQLite Connection"), + } + } +} + impl DbBackend { /// Check if the URI is the same as the specified database backend. /// Returns true if they match. diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index 4ee9c737..1d139daf 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -24,7 +24,7 @@ pub struct SqlxMySqlConnector; /// Defines a sqlx MySQL pool #[derive(Clone)] pub struct SqlxMySqlPoolConnection { - pool: MySqlPool, + pub(crate) pool: MySqlPool, metric_callback: Option, } diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index ff4d55ad..2311a504 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -24,7 +24,7 @@ pub struct SqlxPostgresConnector; /// Defines a sqlx PostgreSQL pool #[derive(Clone)] pub struct SqlxPostgresPoolConnection { - pool: PgPool, + pub(crate) pool: PgPool, metric_callback: Option, } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index c0d7e3f0..063b07ab 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -24,7 +24,7 @@ pub struct SqlxSqliteConnector; /// Defines a sqlx SQLite pool #[derive(Clone)] pub struct SqlxSqlitePoolConnection { - pool: SqlitePool, + pub(crate) pool: SqlitePool, metric_callback: Option, }