@@ -13,6 +13,11 @@ pub struct StmtCache<DB: Backend, S> {
13
13
cache : HashMap < StatementCacheKey < DB > , S > ,
14
14
}
15
15
16
+ type PrepareFuture < ' a , F , S > = futures:: future:: Either <
17
+ futures:: future:: Ready < QueryResult < ( MaybeCached < ' a , S > , F ) > > ,
18
+ BoxFuture < ' a , QueryResult < ( MaybeCached < ' a , S > , F ) > > ,
19
+ > ;
20
+
16
21
#[ async_trait:: async_trait]
17
22
pub trait PrepareCallback < S , M > {
18
23
async fn prepare (
@@ -38,21 +43,18 @@ impl<S, DB: Backend> StmtCache<DB, S> {
38
43
metadata : & [ DB :: TypeMetadata ] ,
39
44
prepare_fn : F ,
40
45
backend : & DB ,
41
- ) -> futures:: future:: Either <
42
- futures:: future:: Ready < QueryResult < ( MaybeCached < ' a , S > , F ) > > ,
43
- BoxFuture < ' a , QueryResult < ( MaybeCached < ' a , S > , F ) > > ,
44
- >
46
+ ) -> PrepareFuture < ' a , F , S >
45
47
where
46
48
S : Send ,
47
49
DB :: QueryBuilder : Default ,
48
50
DB :: TypeMetadata : Clone + Send + Sync ,
49
51
T : QueryFragment < DB > + QueryId + Send ,
50
- F : PrepareCallback < S , DB :: TypeMetadata > + Send + ' a ,
52
+ F : PrepareCallback < S , DB :: TypeMetadata > + Send + ' a ,
51
53
StatementCacheKey < DB > : Hash + Eq ,
52
54
{
53
55
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
54
56
55
- let cache_key = match StatementCacheKey :: for_source ( & query, & metadata, backend) {
57
+ let cache_key = match StatementCacheKey :: for_source ( & query, metadata, backend) {
56
58
Ok ( key) => key,
57
59
Err ( e) => return futures:: future:: Either :: Left ( futures:: future:: ready ( Err ( e) ) ) ,
58
60
} ;
@@ -80,9 +82,10 @@ impl<S, DB: Backend> StmtCache<DB, S> {
80
82
}
81
83
82
84
match self . cache . entry ( cache_key) {
83
- Occupied ( entry) => futures:: future:: Either :: Left ( futures:: future:: ready ( Ok (
84
- ( MaybeCached :: Cached ( entry. into_mut ( ) ) , prepare_fn)
85
- ) ) ) ,
85
+ Occupied ( entry) => futures:: future:: Either :: Left ( futures:: future:: ready ( Ok ( (
86
+ MaybeCached :: Cached ( entry. into_mut ( ) ) ,
87
+ prepare_fn,
88
+ ) ) ) ) ,
86
89
Vacant ( entry) => {
87
90
let sql = match entry. key ( ) . sql ( & query, backend) {
88
91
Ok ( sql) => sql. into_owned ( ) ,
0 commit comments