Skip to main content

RelationalBackend

Trait RelationalBackend 

Source
pub trait RelationalBackend: Send + Sync {
    type Tx<'a>: RelationalTx + 'a
       where Self: 'a;

    // Required methods
    fn backend(&self) -> &str;
    fn version(&self) -> &str;
    fn dialect(&self) -> Dialect;
    fn execute(
        &self,
        sql: &str,
        params: &[Value],
    ) -> impl Future<Output = Result<u64, RelError>> + Send;
    fn query(
        &self,
        sql: &str,
        params: &[Value],
    ) -> impl Future<Output = Result<Vec<Row>, RelError>> + Send;
    fn begin(
        &self,
        isolation: Isolation,
    ) -> impl Future<Output = Result<Self::Tx<'_>, RelError>> + Send;

    // Provided methods
    fn call_bound(&self) -> Option<Duration> { ... }
    fn with_lock_held<'a>(
        &'a self,
        lock_sql: &'a str,
        at_most: Duration,
        during: Pin<Box<dyn Future<Output = ()> + Send + 'a>>,
    ) -> impl Future<Output = Result<(), RelError>> + Send { ... }
}
Expand description

A relational database, as small as it can be.

Statements are written in the backend’s own Dialect; parameters are positional and written as that dialect writes them ($1 for PostgreSQL). Nothing here translates SQL.

Required Associated Types§

Source

type Tx<'a>: RelationalTx + 'a where Self: 'a

A transaction on this backend. Dropping it without commit rolls it back.

Required Methods§

Source

fn backend(&self) -> &str

The backend’s name as it appears in matrix rows (postgres).

Source

fn version(&self) -> &str

The server version string as it appears in matrix rows (16.15).

Source

fn dialect(&self) -> Dialect

The dialect statements must be written in.

Source

fn execute( &self, sql: &str, params: &[Value], ) -> impl Future<Output = Result<u64, RelError>> + Send

Run a statement that returns no rows; the result is the number of rows affected.

Source

fn query( &self, sql: &str, params: &[Value], ) -> impl Future<Output = Result<Vec<Row>, RelError>> + Send

Run a statement and return its rows.

Source

fn begin( &self, isolation: Isolation, ) -> impl Future<Output = Result<Self::Tx<'_>, RelError>> + Send

Begin a transaction at (at least) isolation.

Provided Methods§

Source

fn call_bound(&self) -> Option<Duration>

The per-call timeout this backend enforces, if one is configured; None (the default) means a call waits as long as the server does. Every call that takes longer returns RelError::Timeout.

Source

fn with_lock_held<'a>( &'a self, lock_sql: &'a str, at_most: Duration, during: Pin<Box<dyn Future<Output = ()> + Send + 'a>>, ) -> impl Future<Output = Result<(), RelError>> + Send

Test support for kv.bounded_call: take lock_sql (a statement that locks a row) in a transaction of its own, drive during while that lock is held, then roll back. during is dropped, unfinished, after at_most, so a broken bound cannot hang the test. A backend that enforces no bound returns RelError::Unsupported.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R: RelationalBackend> RelationalBackend for Defective<'_, R>

Source§

type Tx<'a> = DefectiveTx<'a, R> where Self: 'a