@@ -12,27 +12,29 @@ macro_rules! filter {
12
12
}
13
13
}
14
14
15
+ #[ derive( Default ) ]
15
16
pub struct Builder {
16
17
method : Method ,
17
18
url : String ,
19
+ schema : Option < String > ,
18
20
queries : Vec < ( String , String ) > ,
21
+ // TODO: Maybe change to HeaderMap in the future
19
22
headers : Vec < ( String , String ) > ,
20
23
body : Option < String > ,
24
+ is_rpc : bool ,
21
25
}
22
26
23
27
// TODO: Complex filters (not, and, or)
24
- // TODO: Switching schema
25
28
// TODO: Exact, planned, estimated count (HEAD verb)
26
29
// TODO: Response format
27
30
// TODO: Embedded resources
28
31
impl Builder {
29
- pub fn new ( url : & str ) -> Self {
32
+ pub fn new ( url : & str , schema : Option < String > ) -> Self {
30
33
Builder {
31
34
method : Method :: GET ,
32
35
url : url. to_string ( ) ,
33
- queries : Vec :: new ( ) ,
34
- headers : Vec :: new ( ) ,
35
- body : None ,
36
+ schema,
37
+ ..Default :: default ( )
36
38
}
37
39
}
38
40
@@ -96,6 +98,7 @@ impl Builder {
96
98
self . method = Method :: POST ;
97
99
self . headers . push ( (
98
100
"Prefer" . to_string ( ) ,
101
+ // Maybe check if this works as intended...
99
102
"return=representation; resolution=merge-duplicates" . to_string ( ) ,
100
103
) ) ;
101
104
self . body = Some ( body. to_string ( ) ) ;
@@ -127,21 +130,38 @@ impl Builder {
127
130
self
128
131
}
129
132
130
- pub fn in_set ( mut self , column : & str , param : & str ) -> Self {
131
- self . queries
132
- . push ( ( column. to_string ( ) , format ! ( "in.{}" , param) ) ) ;
133
- self
134
- }
135
-
136
133
// It's unfortunate that `in` is a keyword, otherwise it'd belong in the
137
134
// collection of filters below
138
135
filter ! (
139
136
eq, gt, gte, lt, lte, neq, like, ilike, is, fts, plfts, phfts, wfts, cs, cd, ov, sl, sr,
140
137
nxr, nxl, adj, not
141
138
) ;
142
139
140
+ pub fn in_ ( mut self , column : & str , param : & str ) -> Self {
141
+ self . queries
142
+ . push ( ( column. to_string ( ) , format ! ( "in.{}" , param) ) ) ;
143
+ self
144
+ }
145
+
146
+ pub fn rpc ( mut self , params : & str ) -> Self {
147
+ self . method = Method :: POST ;
148
+ self . body = Some ( params. to_string ( ) ) ;
149
+ self . is_rpc = true ;
150
+ self
151
+ }
152
+
143
153
pub async fn execute ( self ) -> Result < Response , Error > {
144
- let mut req = Client :: new ( ) . request ( self . method , & self . url ) ;
154
+ let mut req = Client :: new ( ) . request ( self . method . clone ( ) , & self . url ) ;
155
+ if let Some ( schema) = self . schema {
156
+ // NOTE: Upstream bug: RPC only works with Accept-Profile
157
+ // Will change when upstream is fixed
158
+ let key = if !self . is_rpc || self . method == Method :: GET || self . method == Method :: HEAD {
159
+ "Accept-Profile"
160
+ } else {
161
+ "Content-Profile"
162
+ } ;
163
+ req = req. header ( key, schema) ;
164
+ }
145
165
for ( k, v) in & self . headers {
146
166
req = req. header ( k, v) ;
147
167
}
0 commit comments