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 crate::{error::*, ExecResult, QueryResult, Statement, StatementBuilder};
use sea_query::{MysqlQueryBuilder, PostgresQueryBuilder, QueryBuilder, SqliteQueryBuilder}; use sea_query::{MysqlQueryBuilder, PostgresQueryBuilder, QueryBuilder, SqliteQueryBuilder};
#[cfg_attr(not(feature = "mock"), derive(Clone))]
pub enum DatabaseConnection { pub enum DatabaseConnection {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
SqlxMySqlPoolConnection(crate::SqlxMySqlPoolConnection), 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)] #[derive(Debug)]
pub struct SqlxMySqlConnector; pub struct SqlxMySqlConnector;
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct SqlxMySqlPoolConnection { pub struct SqlxMySqlPoolConnection {
pool: MySqlPool, pool: MySqlPool,
} }

View File

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

View File

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