Skip to main content

no_mistakes_postgres_sql/statement_facts/isolation/
effect.rs

1use super::{SqlIsolation, SqlIsolationChanges};
2
3/// Effect of a submitted SQL batch on a tracked executor's transaction.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum SqlIsolationEffect {
6    /// Set the isolation of an inherited open transaction.
7    Existing(SqlIsolation),
8    /// The batch leaves an explicit transaction open.
9    Open(Option<SqlIsolation>),
10    /// The batch finishes the transaction.
11    Closed,
12    /// The batch's transaction effects are uncertain.
13    Unknown,
14}
15
16impl SqlIsolationChanges {
17    pub fn after_call_effect(&self) -> Option<SqlIsolationEffect> {
18        if self.unlocated {
19            return Some(SqlIsolationEffect::Unknown);
20        }
21        let (_, last) = self.changes.last()?;
22        if last.ends_call_transaction() {
23            Some(SqlIsolationEffect::Closed)
24        } else if last.has_explicit_transaction() {
25            Some(SqlIsolationEffect::Open(self.effect))
26        } else {
27            self.effect.map(SqlIsolationEffect::Existing)
28        }
29    }
30}