use crate::{Dialect, RelError, Row, Value};
use std::future::Future;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Isolation {
#[default]
ReadCommitted,
RepeatableRead,
Serializable,
}
pub trait RelationalBackend: Send + Sync {
type Tx<'a>: RelationalTx + 'a
where
Self: 'a;
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;
}
pub trait RelationalTx: Send {
fn execute(
&mut self,
sql: &str,
params: &[Value],
) -> impl Future<Output = Result<u64, RelError>> + Send;
fn query(
&mut self,
sql: &str,
params: &[Value],
) -> impl Future<Output = Result<Vec<Row>, RelError>> + Send;
fn commit(self) -> impl Future<Output = Result<(), RelError>> + Send;
fn rollback(self) -> impl Future<Output = Result<(), RelError>> + Send;
}