1use sqlx::Database;
2
3use crate::{C3p0Error, DataType, NewRecord, Record, WithData};
4
5pub trait Tx {
7 type DB: Database;
8
9 fn create_table_if_not_exists<DATA: WithData>(
11 &mut self,
12 ) -> impl Future<Output = Result<(), C3p0Error>>;
13
14 fn drop_table_if_exists<DATA: WithData>(
16 &mut self,
17 cascade: bool,
18 ) -> impl Future<Output = Result<(), C3p0Error>>;
19
20 fn count_all<DATA: WithData>(&mut self) -> impl Future<Output = Result<u64, C3p0Error>>;
22
23 fn exists_by_id<DATA: WithData>(
25 &mut self,
26 id: u64,
27 ) -> impl Future<Output = Result<bool, C3p0Error>>;
28
29 fn fetch_all<DATA: DataType>(
31 &mut self,
32 ) -> impl Future<Output = Result<Vec<Record<DATA>>, C3p0Error>>;
33
34 fn fetch_one_optional_by_id<DATA: DataType>(
36 &mut self,
37 id: u64,
38 ) -> impl Future<Output = Result<Option<Record<DATA>>, C3p0Error>>;
39
40 fn fetch_one_by_id<DATA: DataType>(
42 &mut self,
43 id: u64,
44 ) -> impl Future<Output = Result<Record<DATA>, C3p0Error>>;
45
46 fn delete<DATA: DataType>(
48 &mut self,
49 record: Record<DATA>,
50 ) -> impl Future<Output = Result<Record<DATA>, C3p0Error>>;
51
52 fn delete_all<DATA: WithData>(&mut self) -> impl Future<Output = Result<u64, C3p0Error>>;
54
55 fn delete_by_id<DATA: WithData>(
57 &mut self,
58 id: u64,
59 ) -> impl Future<Output = Result<u64, C3p0Error>>;
60
61 fn update<DATA: DataType>(
65 &mut self,
66 record: Record<DATA>,
67 ) -> impl Future<Output = Result<Record<DATA>, C3p0Error>>;
68
69 fn save<DATA: DataType>(
71 &mut self,
72 record: NewRecord<DATA>,
73 ) -> impl Future<Output = Result<Record<DATA>, C3p0Error>>;
74}