Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatabaseConnection directly from PgPool #2348

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/driver/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ 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 {
/// Check if the URI provided corresponds to `mysql://` for a MySQL database
pub fn accepts(string: &str) -> bool {
Expand Down
12 changes: 12 additions & 0 deletions src/driver/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ 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 {
/// Check if the URI provided corresponds to `postgres://` for a PostgreSQL database
pub fn accepts(string: &str) -> bool {
Expand Down
12 changes: 12 additions & 0 deletions src/driver/sqlx_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ 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 {
/// Check if the URI provided corresponds to `sqlite:` for a SQLite database
pub fn accepts(string: &str) -> bool {
Expand Down
Loading