1use crate::{DynamicRecord, GeneratedRecord, IrDocument};
2use std::future::Future;
3use std::pin::Pin;
4
5pub type OrmFuture<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + 'a>>;
7
8pub trait OrmSession {
14 type CommandOutput;
15 type QueryOutput;
16 type Error;
17
18 fn execute_document(self, document: &IrDocument) -> Result<Self::CommandOutput, Self::Error>;
19 fn query_document(self, document: &IrDocument) -> Result<Self::QueryOutput, Self::Error>;
20}
21
22pub trait AsyncOrmSession {
28 type CommandOutput;
29 type QueryOutput;
30 type Error;
31
32 fn execute_document_async<'a>(
33 &'a mut self,
34 document: &'a IrDocument,
35 ) -> OrmFuture<'a, Self::CommandOutput, Self::Error>;
36
37 fn query_document_async<'a>(
38 &'a mut self,
39 document: &'a IrDocument,
40 ) -> OrmFuture<'a, Self::QueryOutput, Self::Error>;
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44pub enum RecordMutation {
45 Insert,
46 Save,
47 Update,
48 Delete,
49}
50
51pub trait OrmRecordSession {
53 type Error;
54
55 fn mutate_record(
56 self,
57 record: &mut DynamicRecord,
58 mutation: RecordMutation,
59 ) -> Result<(), Self::Error>;
60}
61
62pub trait AsyncOrmRecordSession {
63 type Error;
64
65 fn mutate_record_async<'a>(
66 &'a mut self,
67 record: &'a mut DynamicRecord,
68 mutation: RecordMutation,
69 ) -> OrmFuture<'a, (), Self::Error>;
70}
71
72pub trait OrmGeneratedRecordSession {
74 type Error;
75
76 fn mutate_generated_record<R: GeneratedRecord>(
77 self,
78 record: &mut R,
79 mutation: RecordMutation,
80 ) -> Result<(), Self::Error>;
81}
82
83pub trait OrmGeneratedQuerySession {
84 type Error;
85
86 fn query_generated_records<R: GeneratedRecord + Default>(
87 self,
88 document: &IrDocument,
89 ) -> Result<Vec<R>, Self::Error>;
90}
91
92pub trait AsyncOrmGeneratedRecordSession {
95 type Error;
96
97 fn mutate_generated_record_async<'a, R: GeneratedRecord + 'a>(
98 &'a mut self,
99 record: &'a mut R,
100 mutation: RecordMutation,
101 ) -> OrmFuture<'a, (), Self::Error>;
102}
103
104pub trait AsyncOrmGeneratedQuerySession {
105 type Error;
106
107 fn query_generated_records_async<'a, R: GeneratedRecord + Default + 'a>(
108 &'a mut self,
109 document: &'a IrDocument,
110 ) -> OrmFuture<'a, Vec<R>, Self::Error>;
111}