@@ -5,21 +5,48 @@ pub struct Builder {
5
5
url : String ,
6
6
queries : Vec < ( String , String ) > ,
7
7
headers : Vec < ( String , String ) > ,
8
+ body : Option < String > ,
8
9
}
9
10
10
11
impl Builder {
12
+ // TODO: Schema
11
13
pub fn new ( url : & str ) -> Self {
12
14
Builder {
13
15
method : None ,
14
16
url : url. to_string ( ) ,
15
17
queries : Vec :: new ( ) ,
16
18
headers : Vec :: new ( ) ,
19
+ body : None ,
17
20
}
18
21
}
19
22
20
23
pub fn select ( mut self , column : & str ) -> Self {
21
24
self . method = Some ( Method :: GET ) ;
22
- self . queries . push ( ( "select" . to_string ( ) , column. to_string ( ) ) ) ;
25
+ let column = column. chars ( ) . filter ( |c| !c. is_whitespace ( ) ) . collect ( ) ;
26
+ self . queries . push ( ( "select" . to_string ( ) , column) ) ;
27
+ self
28
+ }
29
+
30
+ // TODO: Write-only tables
31
+ // TODO: UPSERT
32
+ // TODO: URL-encoded payload
33
+ pub fn insert ( mut self , body : & str ) -> Self {
34
+ self . method = Some ( Method :: POST ) ;
35
+ self . headers . push ( ( "Prefer" . to_string ( ) , "return=representation" . to_string ( ) ) ) ;
36
+ self . body = Some ( body. to_string ( ) ) ;
37
+ self
38
+ }
39
+
40
+ pub fn update ( mut self , body : & str ) -> Self {
41
+ self . method = Some ( Method :: PATCH ) ;
42
+ self . headers . push ( ( "Prefer" . to_string ( ) , "return=representation" . to_string ( ) ) ) ;
43
+ self . body = Some ( body. to_string ( ) ) ;
44
+ self
45
+ }
46
+
47
+ pub fn delete ( mut self ) -> Self {
48
+ self . method = Some ( Method :: DELETE ) ;
49
+ self . headers . push ( ( "Prefer" . to_string ( ) , "return=representation" . to_string ( ) ) ) ;
23
50
self
24
51
}
25
52
@@ -32,6 +59,9 @@ impl Builder {
32
59
req = req. header ( k, v) ;
33
60
}
34
61
req = req. query ( & self . queries ) ;
62
+ if let Some ( body) = self . body {
63
+ req = req. body ( body) ;
64
+ }
35
65
36
66
let resp = req. send ( )
37
67
. await ?;
0 commit comments