3
3
//! - The `client()` method is not available.
4
4
//! - The `prepare_cached()` and `prepare_typed_cached()` are
5
5
//! added.
6
- use std:: future:: Future ;
7
-
8
6
use tokio_postgres:: types:: { BorrowToSql , ToSql , Type } ;
9
7
use tokio_postgres:: RowStream ;
10
8
use tokio_postgres:: { Error , Row , Statement , ToStatement } ;
11
9
10
+ use async_trait:: async_trait;
11
+
12
12
use crate :: { Client , ClientWrapper , Transaction } ;
13
13
14
14
mod private {
@@ -18,96 +18,78 @@ mod private {
18
18
/// A trait allowing abstraction over connections and transactions.
19
19
///
20
20
/// This trait is "sealed", and cannot be implemented outside of this crate.
21
+ #[ async_trait]
21
22
pub trait GenericClient : Sync + private:: Sealed {
22
23
/// Like `Client::execute`.
23
- fn execute < T > (
24
- & self ,
25
- query : & T ,
26
- params : & [ & ( dyn ToSql + Sync ) ] ,
27
- ) -> impl Future < Output = Result < u64 , Error > > + Send
24
+ async fn execute < T > ( & self , query : & T , params : & [ & ( dyn ToSql + Sync ) ] ) -> Result < u64 , Error >
28
25
where
29
26
T : ?Sized + ToStatement + Sync + Send ;
30
27
31
28
/// Like `Client::execute_raw`.
32
- fn execute_raw < P , I , T > (
33
- & self ,
34
- statement : & T ,
35
- params : I ,
36
- ) -> impl Future < Output = Result < u64 , Error > > + Send
29
+ async fn execute_raw < P , I , T > ( & self , statement : & T , params : I ) -> Result < u64 , Error >
37
30
where
38
31
T : ?Sized + ToStatement + Sync + Send ,
39
32
P : BorrowToSql ,
40
33
I : IntoIterator < Item = P > + Sync + Send ,
41
34
I :: IntoIter : ExactSizeIterator ;
42
35
43
36
/// Like `Client::query`.
44
- fn query < T > (
45
- & self ,
46
- query : & T ,
47
- params : & [ & ( dyn ToSql + Sync ) ] ,
48
- ) -> impl Future < Output = Result < Vec < Row > , Error > > + Send
37
+ async fn query < T > ( & self , query : & T , params : & [ & ( dyn ToSql + Sync ) ] ) -> Result < Vec < Row > , Error >
49
38
where
50
39
T : ?Sized + ToStatement + Sync + Send ;
51
40
52
41
/// Like `Client::query_one`.
53
- fn query_one < T > (
42
+ async fn query_one < T > (
54
43
& self ,
55
44
statement : & T ,
56
45
params : & [ & ( dyn ToSql + Sync ) ] ,
57
- ) -> impl Future < Output = Result < Row , Error > > + Send
46
+ ) -> Result < Row , Error >
58
47
where
59
48
T : ?Sized + ToStatement + Sync + Send ;
60
49
61
50
/// Like `Client::query_opt`.
62
- fn query_opt < T > (
51
+ async fn query_opt < T > (
63
52
& self ,
64
53
statement : & T ,
65
54
params : & [ & ( dyn ToSql + Sync ) ] ,
66
- ) -> impl Future < Output = Result < Option < Row > , Error > > + Send
55
+ ) -> Result < Option < Row > , Error >
67
56
where
68
57
T : ?Sized + ToStatement + Sync + Send ;
69
58
70
59
/// Like `Client::query_raw`.
71
- fn query_raw < T , P , I > (
72
- & self ,
73
- statement : & T ,
74
- params : I ,
75
- ) -> impl Future < Output = Result < RowStream , Error > > + Send
60
+ async fn query_raw < T , P , I > ( & self , statement : & T , params : I ) -> Result < RowStream , Error >
76
61
where
77
62
T : ?Sized + ToStatement + Sync + Send ,
78
63
P : BorrowToSql ,
79
64
I : IntoIterator < Item = P > + Sync + Send ,
80
65
I :: IntoIter : ExactSizeIterator ;
81
66
82
67
/// Like `Client::prepare`.
83
- fn prepare ( & self , query : & str ) -> impl Future < Output = Result < Statement , Error > > + Send ;
68
+ async fn prepare ( & self , query : & str ) -> Result < Statement , Error > ;
84
69
85
70
/// Like `Client::prepare_typed`.
86
- fn prepare_typed (
71
+ async fn prepare_typed (
87
72
& self ,
88
73
query : & str ,
89
74
parameter_types : & [ Type ] ,
90
- ) -> impl Future < Output = Result < Statement , Error > > + Send ;
75
+ ) -> Result < Statement , Error > ;
91
76
92
77
/// Like [`Client::prepare_cached`].
93
- fn prepare_cached ( & self , query : & str ) -> impl Future < Output = Result < Statement , Error > > + Send ;
78
+ async fn prepare_cached ( & self , query : & str ) -> Result < Statement , Error > ;
94
79
95
80
/// Like [`Client::prepare_typed_cached`]
96
- fn prepare_typed_cached (
97
- & self ,
98
- query : & str ,
99
- types : & [ Type ] ,
100
- ) -> impl Future < Output = Result < Statement , Error > > + Send ;
81
+ async fn prepare_typed_cached ( & self , query : & str , types : & [ Type ] ) -> Result < Statement , Error > ;
101
82
102
83
/// Like `Client::transaction`.
103
- fn transaction ( & mut self ) -> impl Future < Output = Result < Transaction < ' _ > , Error > > + Send ;
84
+ async fn transaction ( & mut self ) -> Result < Transaction < ' _ > , Error > ;
104
85
105
86
/// Like `Client::batch_execute`.
106
- fn batch_execute ( & self , query : & str ) -> impl Future < Output = Result < ( ) , Error > > + Send ;
87
+ async fn batch_execute ( & self , query : & str ) -> Result < ( ) , Error > ;
107
88
}
108
89
109
90
impl private:: Sealed for Client { }
110
91
92
+ #[ async_trait]
111
93
impl GenericClient for Client {
112
94
async fn execute < T > ( & self , query : & T , params : & [ & ( dyn ToSql + Sync ) ] ) -> Result < u64 , Error >
113
95
where
@@ -196,6 +178,7 @@ impl GenericClient for Client {
196
178
197
179
impl private:: Sealed for Transaction < ' _ > { }
198
180
181
+ #[ async_trait]
199
182
#[ allow( clippy:: needless_lifetimes) ]
200
183
impl GenericClient for Transaction < ' _ > {
201
184
async fn execute < T > ( & self , query : & T , params : & [ & ( dyn ToSql + Sync ) ] ) -> Result < u64 , Error >
0 commit comments