From sqlx pool

This commit is contained in:
Chris Tsang 2021-06-11 15:48:26 +08:00
parent 9beca86617
commit 398e1f0913

View File

@ -22,9 +22,9 @@ impl Connector for SqlxMySqlConnector {
}
async fn connect(string: &str) -> Result<DatabaseConnection, ConnectionErr> {
if let Ok(conn) = MySqlPool::connect(string).await {
if let Ok(pool) = MySqlPool::connect(string).await {
Ok(DatabaseConnection::SqlxMySqlPoolConnection(
SqlxMySqlPoolConnection { pool: conn },
SqlxMySqlPoolConnection { pool },
))
} else {
Err(ConnectionErr)
@ -32,6 +32,14 @@ impl Connector for SqlxMySqlConnector {
}
}
impl SqlxMySqlConnector {
pub fn from_sqlx_mysql_pool(pool: MySqlPool) -> DatabaseConnection {
DatabaseConnection::SqlxMySqlPoolConnection(
SqlxMySqlPoolConnection { pool },
)
}
}
#[async_trait]
impl Connection for &SqlxMySqlPoolConnection {
async fn execute(&self, stmt: Statement) -> Result<ExecResult, ExecErr> {