taitan_orm/
sql_executor_mut.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use crate::result::Result;
use sqlx::Database;
use crate::sql_generic_executor::SqlGenericExecutor;
use taitan_orm_trait::SelectedEntity;

/**
现在sqlx::Executor的实现还是太过简陋,导致无法把不同数据库和事务的连接抽象成一个独立的实体
屏蔽掉ex,让更上层的API层不再感知connection/transaction,
这层抽象让上层实现API接口的实现可以把普通操作和事务操作合并为一份

本模块提供以下接口方法
execute           (stmt, args) -> Result<u64>
execute_plain     (stmt      ) -> Result<u64>

fetch_exists            (stmt, args) -> Result<bool>
fetch_exists_plain      (stmt,     ) -> Result<bool>

fetch_option      (stmt, selection, args) -> Result<Option<SE>>
fetch_option_plain(stmt, selection,     ) -> Result<Option<SE>>
-- fetch_one         (stmt, selection, args) -> Result<SE>
-- fetch_one_plain   (stmt, selection,     ) -> Result<SE>
fetch_all         (stmt, selection, args) -> Result<Vec<SE>>
fetch_all_plain   (stmt, selection,     ) -> Result<Vec<SE>>

fetch_all_full         (stmt, args) -> Result<Vec<SE>>
fetch_all_full_plain   (stmt,     ) -> Result<Vec<SE>>
fetch_one_full         (stmt, args) -> Result<SE>
fetch_one_full_plain   (stmt,     ) -> Result<SE>
fetch_option_full      (stmt, args) -> Result<Option<SE>>
fetch_option_full_plain(stmt,     ) -> Result<Option<SE>>
*/
pub trait SqlExecutorMut: SqlGenericExecutor {

    // type Connection: Connection;
    //
    // async fn get_connection(&mut self) -> Result<PoolConnection<Self::DB>> {
    //     Err(NotImplement("get_connection not implemented".to_string()))
    // }

    // execute           (stmt, args) -> Result<u64>
    async fn execute<'a>(
        &'a mut self,
        stmt: &'a str,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<u64>;

    // execute_plain     (stmt, _   ) -> Result<u64>
    async fn execute_plain<'a>(&'a mut self, stmt: &'a str) -> Result<u64>;


    // fetch_exists            (stmt, args) -> Result<bool>
    async fn fetch_exists<'a>(
        &'a mut self,
        stmt: &'a str,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<bool>;

    async fn fetch_exists_plain<'a, A>(
        &'a mut self,
        stmt: &'a str,
    ) -> Result<bool>;

    async fn fetch_count<'s, 'a>(
        &'a mut self,
        stmt: &'s str,
        args: <Self::DB as sqlx::Database>::Arguments<'a>,
    ) -> crate::Result<u64> where 'a: 's;

    async fn fetch_count_plain<'a>(&'a mut self, stmt: &'a str) -> crate::Result<u64>;


    // fetch_option      (stmt, selection, args) -> Result<Option<SE>>
    async fn fetch_option<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE::Selection,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<Option<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    async fn fetch_option_<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<Option<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    // fetch_option_plain(stmt, selection) -> Result<Option<SE>>
    async fn fetch_option_plain<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE::Selection,
    ) -> Result<Option<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    async fn fetch_option_plain_<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE,
    ) -> Result<Option<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;


    // fetch_all         (stmt, selection, args) -> Result<Vec<SE>>
    async fn fetch_all<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE::Selection,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<Vec<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    async fn fetch_all_<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<Vec<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    // fetch_all_plain   (stmt, selection) -> Result<Vec<SE>>
    async fn fetch_all_plain<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE::Selection,
    ) -> Result<Vec<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    async fn fetch_all_plain_<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        selection: &'a SE,
    ) -> Result<Vec<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;






    // fetch_one_full         (stmt, args) -> Result<SE>
    async fn fetch_one_full<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<SE>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    // fetch_one_full_plain   (stmt, _   ) -> Result<SE>
    async fn fetch_one_full_plain<'a, SE>(&'a mut self, stmt: &'a str) -> Result<SE>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;


    // fetch_option_full      (stmt, args) -> Result<Option<SE>>
    async fn fetch_option_full<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<Option<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    // fetch_option_full_plain(stmt) -> Result<Option<SE>>
    async fn fetch_option_full_plain<'a, SE>(
        &'a mut self,
        stmt: &'a str
    ) -> Result<Option<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;


    // fetch_all_full         (stmt, args) -> Result<Vec<SE>>
    async fn fetch_all_full<'a, SE>(
        &'a mut self,
        stmt: &'a str,
        args: <Self::DB as Database>::Arguments<'a>,
    ) -> Result<Vec<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;


    // fetch_all_full_plain   (stmt) -> Result<Vec<SE>>
    async fn fetch_all_full_plain<'a, SE>(
        &'a mut self,
        stmt: &'a str,
    ) -> Result<Vec<SE>>
    where
        SE: SelectedEntity<Self::DB> + Send + Unpin;

    // fetch_one         (stmt, selection, args) -> Result<SE>
    // fetch_one_plain   (stmt, selection, _   ) -> Result<SE>
}