DatabaseConnection
directly from PgPool
(#2348)
* feat(postgres): create `DatabaseConnection` directly from `PgPool` This allows sqlx-based connection pools that were already on-hand to be easily converted into SeaORM types. * Move `From` impls into driver * impls for MySQL and SQLite * CHANGELOG * fmt --------- Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
This commit is contained in:
parent
fb442298dd
commit
8339dbb8df
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
* [sea-orm-macros] Call `EnumIter::get` using fully qualified syntax https://github.com/SeaQL/sea-orm/pull/2321
|
* [sea-orm-macros] Call `EnumIter::get` using fully qualified syntax https://github.com/SeaQL/sea-orm/pull/2321
|
||||||
|
* Construct `DatabaseConnection` directly from `sqlx::PgPool`, `sqlx::SqlitePool` and `sqlx::MySqlPool` https://github.com/SeaQL/sea-orm/pull/2348
|
||||||
|
|
||||||
### Upgrades
|
### Upgrades
|
||||||
|
|
||||||
|
@ -36,6 +36,21 @@ impl std::fmt::Debug for SqlxMySqlPoolConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<MySqlPool> for SqlxMySqlPoolConnection {
|
||||||
|
fn from(pool: MySqlPool) -> Self {
|
||||||
|
SqlxMySqlPoolConnection {
|
||||||
|
pool,
|
||||||
|
metric_callback: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MySqlPool> for DatabaseConnection {
|
||||||
|
fn from(pool: MySqlPool) -> Self {
|
||||||
|
DatabaseConnection::SqlxMySqlPoolConnection(pool.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SqlxMySqlConnector {
|
impl SqlxMySqlConnector {
|
||||||
/// Check if the URI provided corresponds to `mysql://` for a MySQL database
|
/// Check if the URI provided corresponds to `mysql://` for a MySQL database
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
|
@ -36,6 +36,21 @@ impl std::fmt::Debug for SqlxPostgresPoolConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<PgPool> for SqlxPostgresPoolConnection {
|
||||||
|
fn from(pool: PgPool) -> Self {
|
||||||
|
SqlxPostgresPoolConnection {
|
||||||
|
pool,
|
||||||
|
metric_callback: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PgPool> for DatabaseConnection {
|
||||||
|
fn from(pool: PgPool) -> Self {
|
||||||
|
DatabaseConnection::SqlxPostgresPoolConnection(pool.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SqlxPostgresConnector {
|
impl SqlxPostgresConnector {
|
||||||
/// Check if the URI provided corresponds to `postgres://` for a PostgreSQL database
|
/// Check if the URI provided corresponds to `postgres://` for a PostgreSQL database
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
|
@ -37,6 +37,21 @@ impl std::fmt::Debug for SqlxSqlitePoolConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<SqlitePool> for SqlxSqlitePoolConnection {
|
||||||
|
fn from(pool: SqlitePool) -> Self {
|
||||||
|
SqlxSqlitePoolConnection {
|
||||||
|
pool,
|
||||||
|
metric_callback: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SqlitePool> for DatabaseConnection {
|
||||||
|
fn from(pool: SqlitePool) -> Self {
|
||||||
|
DatabaseConnection::SqlxSqlitePoolConnection(pool.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SqlxSqliteConnector {
|
impl SqlxSqliteConnector {
|
||||||
/// Check if the URI provided corresponds to `sqlite:` for a SQLite database
|
/// Check if the URI provided corresponds to `sqlite:` for a SQLite database
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user