DatabaseConnection impl Sync, Send and Clone

This commit is contained in:
Billy Chan 2021-09-15 12:27:32 +08:00 committed by Chris Tsang
parent 27807f3f6c
commit 3093cd2035
4 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,7 @@
use crate::{error::*, ExecResult, QueryResult, Statement, StatementBuilder};
use sea_query::{MysqlQueryBuilder, PostgresQueryBuilder, QueryBuilder, SqliteQueryBuilder};
#[cfg_attr(not(feature = "mock"), derive(Clone))]
pub enum DatabaseConnection {
#[cfg(feature = "sqlx-mysql")]
SqlxMySqlPoolConnection(crate::SqlxMySqlPoolConnection),
@ -143,3 +144,15 @@ impl DbBackend {
}
}
}
#[cfg(test)]
mod tests {
use crate::DatabaseConnection;
#[test]
fn assert_database_connection_traits() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<DatabaseConnection>();
}
}

View File

@ -13,7 +13,7 @@ use super::sqlx_common::*;
#[derive(Debug)]
pub struct SqlxMySqlConnector;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct SqlxMySqlPoolConnection {
pool: MySqlPool,
}

View File

@ -13,7 +13,7 @@ use super::sqlx_common::*;
#[derive(Debug)]
pub struct SqlxPostgresConnector;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct SqlxPostgresPoolConnection {
pool: PgPool,
}

View File

@ -13,7 +13,7 @@ use super::sqlx_common::*;
#[derive(Debug)]
pub struct SqlxSqliteConnector;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct SqlxSqlitePoolConnection {
pool: SqlitePool,
}