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