#[non_exhaustive]pub enum Isolation {
ReadUncommitted,
ReadCommitted,
RepeatableRead,
Serializable,
}Expand description
The isolation level a transaction opens at, on Postgres, MySQL and MariaDB.
A table names one (TableSpec::isolation), and the dialect’s
begin opens the table’s transactions at it. A database that runs a level
as a stronger one does not keep it, so its dialect refuses it: Postgres refuses
ReadUncommitted.
§Examples
use ruststream_sqlx_dialect::{
Dialect, Isolation, Opening, Opens, Statement, StatementError, TableSpec, level,
};
/// SQL Server, a database without a built-in dialect.
#[derive(Debug)]
pub struct Mssql;
impl Dialect for Mssql {
fn name(&self) -> &'static str {
"mssql"
}
fn begin(&self, opening: Opening) -> Result<Option<&'static str>, StatementError> {
match opening {
Opening::Default | Opening::Isolation(Isolation::ReadCommitted) => Ok(Some(
"SET TRANSACTION ISOLATION LEVEL READ COMMITTED; BEGIN TRANSACTION",
)),
Opening::Isolation(Isolation::RepeatableRead) => Ok(Some(
"SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN TRANSACTION",
)),
// A refusal names the opening the table declares.
other => Err(StatementError::UnsupportedOpening {
dialect: self.name(),
opening: other.name(),
}),
}
}
}
// A table at one of these levels mounts on `Mssql`.
impl Opens<level::ReadCommitted> for Mssql {}
impl Opens<level::RepeatableRead> for Mssql {}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
ReadUncommitted
A read may see what other transactions wrote and have not committed.
ReadCommitted
Each statement sees what was committed before it began.
RepeatableRead
Every statement sees what was committed before the transaction’s first one.
Serializable
Transactions take effect as if they ran one after another.
Implementations§
Source§impl Isolation
impl Isolation
Sourcepub const fn sql(self) -> &'static str
pub const fn sql(self) -> &'static str
The level as SQL names it: READ COMMITTED.
§Examples
use ruststream_sqlx_dialect::{Dialect, Isolation, Opening, Postgres};
// A dialect's test: each level it serves opens a transaction at that level.
for level in [Isolation::ReadCommitted, Isolation::RepeatableRead, Isolation::Serializable] {
let begin = Postgres.begin(Opening::Isolation(level))?;
assert_eq!(begin, Some(format!("BEGIN ISOLATION LEVEL {}", level.sql())).as_deref());
}Trait Implementations§
impl Copy for Isolation
impl Eq for Isolation
impl StructuralPartialEq for Isolation
Auto Trait Implementations§
impl Freeze for Isolation
impl RefUnwindSafe for Isolation
impl Send for Isolation
impl Sync for Isolation
impl Unpin for Isolation
impl UnsafeUnpin for Isolation
impl UnwindSafe for Isolation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more