diff --git a/CHANGELOG.md b/CHANGELOG.md index d900d09f..567c2d9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Enhancements * [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 diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index df986263..e1c593b0 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -36,6 +36,21 @@ impl std::fmt::Debug for SqlxMySqlPoolConnection { } } +impl From for SqlxMySqlPoolConnection { + fn from(pool: MySqlPool) -> Self { + SqlxMySqlPoolConnection { + pool, + metric_callback: None, + } + } +} + +impl From for DatabaseConnection { + fn from(pool: MySqlPool) -> Self { + DatabaseConnection::SqlxMySqlPoolConnection(pool.into()) + } +} + impl SqlxMySqlConnector { /// Check if the URI provided corresponds to `mysql://` for a MySQL database pub fn accepts(string: &str) -> bool { diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index 6e424a34..ceb855f2 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -36,6 +36,21 @@ impl std::fmt::Debug for SqlxPostgresPoolConnection { } } +impl From for SqlxPostgresPoolConnection { + fn from(pool: PgPool) -> Self { + SqlxPostgresPoolConnection { + pool, + metric_callback: None, + } + } +} + +impl From for DatabaseConnection { + fn from(pool: PgPool) -> Self { + DatabaseConnection::SqlxPostgresPoolConnection(pool.into()) + } +} + impl SqlxPostgresConnector { /// Check if the URI provided corresponds to `postgres://` for a PostgreSQL database pub fn accepts(string: &str) -> bool { diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 3d5465aa..4d343027 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -37,6 +37,21 @@ impl std::fmt::Debug for SqlxSqlitePoolConnection { } } +impl From for SqlxSqlitePoolConnection { + fn from(pool: SqlitePool) -> Self { + SqlxSqlitePoolConnection { + pool, + metric_callback: None, + } + } +} + +impl From for DatabaseConnection { + fn from(pool: SqlitePool) -> Self { + DatabaseConnection::SqlxSqlitePoolConnection(pool.into()) + } +} + impl SqlxSqliteConnector { /// Check if the URI provided corresponds to `sqlite:` for a SQLite database pub fn accepts(string: &str) -> bool {