Skip to main content

Module level

Module level 

Source
Expand description

The isolation levels and SQLite modes as types: a table names one, and its dialect opens it where it implements Opens for it.

A table that names a level carries it twice: as one of these types, which the bound on its dialect checks when the service compiles, and as the Opening in its description, which Dialect::begin turns into a statement.

§Examples

A dialect implements Opens for each level its begin opens:

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",
            )),
            other => Err(StatementError::UnsupportedOpening {
                dialect: self.name(),
                opening: other.name(),
            }),
        }
    }
}

// A table at `read_committed` or `repeatable_read` mounts on `Mssql`.
impl Opens<level::ReadCommitted> for Mssql {}
impl Opens<level::RepeatableRead> for Mssql {}

Structs§

Deferred
Mode::Deferred as a type, for the bound Opens sets.
Exclusive
Mode::Exclusive as a type, for the bound Opens sets.
Immediate
Mode::Immediate as a type, for the bound Opens sets.
ReadCommitted
Isolation::ReadCommitted as a type, for the bound Opens sets.
ReadUncommitted
Isolation::ReadUncommitted as a type, for the bound Opens sets.
RepeatableRead
Isolation::RepeatableRead as a type, for the bound Opens sets.
Serializable
Isolation::Serializable as a type, for the bound Opens sets.