use crate::{DynamicRecord, GeneratedRecord, IrDocument};
use std::future::Future;
use std::pin::Pin;
pub type OrmFuture<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + 'a>>;
pub trait OrmSession {
type CommandOutput;
type QueryOutput;
type Error;
fn execute_document(self, document: &IrDocument) -> Result<Self::CommandOutput, Self::Error>;
fn query_document(self, document: &IrDocument) -> Result<Self::QueryOutput, Self::Error>;
}
pub trait AsyncOrmSession {
type CommandOutput;
type QueryOutput;
type Error;
fn execute_document_async<'a>(
&'a mut self,
document: &'a IrDocument,
) -> OrmFuture<'a, Self::CommandOutput, Self::Error>;
fn query_document_async<'a>(
&'a mut self,
document: &'a IrDocument,
) -> OrmFuture<'a, Self::QueryOutput, Self::Error>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RecordMutation {
Insert,
Save,
Update,
Delete,
}
pub trait OrmRecordSession {
type Error;
fn mutate_record(
self,
record: &mut DynamicRecord,
mutation: RecordMutation,
) -> Result<(), Self::Error>;
}
pub trait AsyncOrmRecordSession {
type Error;
fn mutate_record_async<'a>(
&'a mut self,
record: &'a mut DynamicRecord,
mutation: RecordMutation,
) -> OrmFuture<'a, (), Self::Error>;
}
pub trait OrmGeneratedRecordSession {
type Error;
fn mutate_generated_record<R: GeneratedRecord>(
self,
record: &mut R,
mutation: RecordMutation,
) -> Result<(), Self::Error>;
}
pub trait OrmGeneratedQuerySession {
type Error;
fn query_generated_records<R: GeneratedRecord + Default>(
self,
document: &IrDocument,
) -> Result<Vec<R>, Self::Error>;
}
pub trait AsyncOrmGeneratedRecordSession {
type Error;
fn mutate_generated_record_async<'a, R: GeneratedRecord + 'a>(
&'a mut self,
record: &'a mut R,
mutation: RecordMutation,
) -> OrmFuture<'a, (), Self::Error>;
}
pub trait AsyncOrmGeneratedQuerySession {
type Error;
fn query_generated_records_async<'a, R: GeneratedRecord + Default + 'a>(
&'a mut self,
document: &'a IrDocument,
) -> OrmFuture<'a, Vec<R>, Self::Error>;
}