elif_orm/transactions/
isolation.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum IsolationLevel {
8 ReadUncommitted,
10 ReadCommitted,
12 RepeatableRead,
14 Serializable,
16}
17
18impl IsolationLevel {
19 pub fn as_sql(&self) -> &'static str {
21 match self {
22 IsolationLevel::ReadUncommitted => "READ UNCOMMITTED",
23 IsolationLevel::ReadCommitted => "READ COMMITTED",
24 IsolationLevel::RepeatableRead => "REPEATABLE READ",
25 IsolationLevel::Serializable => "SERIALIZABLE",
26 }
27 }
28
29 pub fn default_for_dialect(dialect: &crate::backends::SqlDialect) -> Self {
31 match dialect {
32 crate::backends::SqlDialect::PostgreSQL => IsolationLevel::ReadCommitted,
33 crate::backends::SqlDialect::MySQL => IsolationLevel::RepeatableRead,
34 crate::backends::SqlDialect::SQLite => IsolationLevel::Serializable,
35 }
36 }
37
38 pub fn is_supported_by(&self, dialect: &crate::backends::SqlDialect) -> bool {
40 match dialect {
41 crate::backends::SqlDialect::PostgreSQL => true, crate::backends::SqlDialect::MySQL => {
43 matches!(
44 self,
45 IsolationLevel::ReadUncommitted
46 | IsolationLevel::ReadCommitted
47 | IsolationLevel::RepeatableRead
48 | IsolationLevel::Serializable
49 )
50 }
51 crate::backends::SqlDialect::SQLite => {
52 matches!(self, IsolationLevel::Serializable)
54 }
55 }
56 }
57}