use std::future::Future;
use std::pin::Pin;
use crate::error::PipelineError;
pub(crate) type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum TransactionType {
Read,
Write,
Schema,
}
#[derive(Debug, Clone)]
pub(crate) enum QueryResultKind {
Ok,
Rows(Vec<serde_json::Value>),
Documents(Vec<serde_json::Value>),
}
pub(crate) trait TransactionOps: Send {
fn query(&mut self, typeql: &str) -> BoxFuture<'_, Result<QueryResultKind, PipelineError>>;
fn commit(&mut self) -> BoxFuture<'_, Result<(), PipelineError>>;
}
pub(crate) trait DriverBackend: Send + Sync {
fn open_transaction(
&self,
database: &str,
tx_type: TransactionType,
) -> BoxFuture<'_, Result<Box<dyn TransactionOps>, PipelineError>>;
fn database_exists(&self, database: &str) -> BoxFuture<'_, Result<bool, PipelineError>>;
fn create_database(&self, database: &str) -> BoxFuture<'_, Result<(), PipelineError>>;
fn delete_database(&self, database: &str) -> BoxFuture<'_, Result<(), PipelineError>>;
fn is_open(&self) -> bool;
}