Get SQLx connection pool (#1297)
This commit is contained in:
parent
d80e61ed7e
commit
d332afa99c
@ -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"]
|
||||
|
@ -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.
|
||||
|
@ -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<crate::metric::Callback>,
|
||||
}
|
||||
|
||||
|
@ -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<crate::metric::Callback>,
|
||||
}
|
||||
|
||||
|
@ -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<crate::metric::Callback>,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user