sqlx_exasol_impl/
transaction.rs1use sqlx_core::{sql_str::SqlStr, transaction::TransactionManager};
2
3use crate::{
4 connection::websocket::future::{Commit, Rollback, WebSocketFuture},
5 database::Exasol,
6 error::ExaProtocolError,
7 ExaConnection, SqlxResult,
8};
9
10#[derive(Debug, Clone, Copy)]
12pub struct ExaTransactionManager;
13
14impl TransactionManager for ExaTransactionManager {
15 type Database = Exasol;
16
17 async fn begin(conn: &mut ExaConnection, _: Option<SqlStr>) -> SqlxResult<()> {
18 if conn.attributes().open_transaction() {
20 match conn.ws.pending_rollback.take() {
24 Some(rollback) => rollback.future(&mut conn.ws).await?,
25 None => return Err(ExaProtocolError::TransactionAlreadyOpen)?,
26 }
27 }
28
29 conn.attributes_mut().set_autocommit(false);
33 Ok(())
34 }
35
36 async fn commit(conn: &mut ExaConnection) -> SqlxResult<()> {
37 Commit::default().future(&mut conn.ws).await
38 }
39
40 async fn rollback(conn: &mut ExaConnection) -> SqlxResult<()> {
41 Rollback::default().future(&mut conn.ws).await
42 }
43
44 fn start_rollback(conn: &mut ExaConnection) {
45 conn.ws.pending_rollback = Some(Rollback::default());
46 }
47
48 fn get_transaction_depth(conn: &ExaConnection) -> usize {
49 conn.attributes().open_transaction().into()
50 }
51}