/
germanubis
/
sqlx
ΠΠ±Π·ΠΎΡ
ΠΠΎΠΊΡΠΌΠ΅Π½ΡΠ°ΡΠΈΡ
ΠΠΎΠΉΡΠΈ
/
germanubis
/
sqlx
ΠΠΎΠ΄
ΠΠ°ΠΏΡΠΎΡΡ
0
ΠΠ°Π΄Π°ΡΠΈ
ΠΠΈΠΊΠΈ
ΠΠ°ΠΊΠ΅ΡΡ
0
Π Π΅Π»ΠΈΠ·Ρ
0
ΠΠ½Π°Π»ΠΈΡΠΈΠΊΠ°
ΠΠ΅Π·ΠΎΠΏΠ°ΡΠ½ΠΎΡΡΡ
v0.7.2
sqlx-postgres/src/transaction.rs
60 ΡΡΡΠΎΠΊ
2 KB
Austin Bonander
Break drivers out into separate crates, clean up some technical debt (#2039)
22 ΡΠ΅Π² 2023, 00:25
22 ΡΠ΅Π² 2023, 00:25
b5312c3
ΠΠΎΠ΄
ΠΠ²ΡΠΎΡΡΡΠ²ΠΎ
Π ΡΡΠΌ ΠΊΠΎΠ΄?
use futures_core::future::BoxFuture; use crate::error::Error; use crate::executor::Executor; use crate::{PgConnection, Postgres}; pub(crate) use sqlx_core::transaction::*; /// Implementation of [`TransactionManager`] for PostgreSQL. pub struct PgTransactionManager; impl TransactionManager for PgTransactionManager { type Database = Postgres; fn begin(conn: &mut PgConnection) -> BoxFuture<'_, Result<(), Error>> { Box::pin(async move { conn.execute(&*begin_ansi_transaction_sql(conn.transaction_depth)) .await?; conn.transaction_depth += 1; Ok(()) }) } fn commit(conn: &mut PgConnection) -> BoxFuture<'_, Result<(), Error>> { Box::pin(async move { if conn.transaction_depth > 0 { conn.execute(&*commit_ansi_transaction_sql(conn.transaction_depth)) .await?; conn.transaction_depth -= 1; } Ok(()) }) } fn rollback(conn: &mut PgConnection) -> BoxFuture<'_, Result<(), Error>> { Box::pin(async move { if conn.transaction_depth > 0 { conn.execute(&*rollback_ansi_transaction_sql(conn.transaction_depth)) .await?; conn.transaction_depth -= 1; } Ok(()) }) } fn start_rollback(conn: &mut PgConnection) { if conn.transaction_depth > 0 { conn.queue_simple_query(&rollback_ansi_transaction_sql(conn.transaction_depth)); conn.transaction_depth -= 1; } } }