-
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from SeaQL/transaction
Transaction Support
- Loading branch information
Showing
26 changed files
with
648 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::{pin::Pin, future::Future}; | ||
use crate::{DatabaseTransaction, DbBackend, DbErr, ExecResult, QueryResult, Statement, TransactionError}; | ||
|
||
#[async_trait::async_trait] | ||
pub trait ConnectionTrait: Sync { | ||
fn get_database_backend(&self) -> DbBackend; | ||
|
||
async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr>; | ||
|
||
async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr>; | ||
|
||
async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr>; | ||
|
||
/// Execute the function inside a transaction. | ||
/// If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed. | ||
async fn transaction<F, T, E>(&self, callback: F) -> Result<T, TransactionError<E>> | ||
where | ||
F: for<'c> FnOnce(&'c DatabaseTransaction<'_>) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'c>> + Send + Sync, | ||
T: Send, | ||
E: std::error::Error + Send; | ||
|
||
fn is_mock_connection(&self) -> bool { | ||
false | ||
} | ||
} |
Oops, something went wrong.