forked from launchbadge/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.rs
More file actions
35 lines (26 loc) · 1008 Bytes
/
transaction.rs
File metadata and controls
35 lines (26 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::future::Future;
use sqlx_core::transaction::TransactionManager;
use sqlx_core::{error::Error, sql_str::SqlStr};
use crate::{Sqlite, SqliteConnection};
/// Implementation of [`TransactionManager`] for SQLite.
pub struct SqliteTransactionManager;
impl TransactionManager for SqliteTransactionManager {
type Database = Sqlite;
async fn begin(conn: &mut SqliteConnection, statement: Option<SqlStr>) -> Result<(), Error> {
conn.worker.begin(statement).await
}
fn commit(conn: &mut SqliteConnection) -> impl Future<Output = Result<(), Error>> + Send + '_ {
conn.worker.commit()
}
fn rollback(
conn: &mut SqliteConnection,
) -> impl Future<Output = Result<(), Error>> + Send + '_ {
conn.worker.rollback()
}
fn start_rollback(conn: &mut SqliteConnection) {
conn.worker.start_rollback().ok();
}
fn get_transaction_depth(conn: &SqliteConnection) -> usize {
conn.worker.shared.get_transaction_depth()
}
}