@@ -9,7 +9,7 @@ pub struct Builder {
9
9
}
10
10
11
11
impl Builder {
12
- // TODO: Schema
12
+ // TODO: Switching schema
13
13
pub fn new ( url : & str ) -> Self {
14
14
Builder {
15
15
method : None ,
@@ -28,8 +28,8 @@ impl Builder {
28
28
}
29
29
30
30
// TODO: Write-only tables
31
- // TODO: UPSERT
32
31
// TODO: URL-encoded payload
32
+ // TODO: Allow specifying columns
33
33
pub fn insert ( mut self , body : & str ) -> Self {
34
34
self . method = Some ( Method :: POST ) ;
35
35
self . headers
@@ -38,6 +38,33 @@ impl Builder {
38
38
self
39
39
}
40
40
41
+ pub fn insert_csv ( mut self , body : & str ) -> Self {
42
+ self . headers
43
+ . push ( ( "Content-Type" . to_string ( ) , "text/csv" . to_string ( ) ) ) ;
44
+ self . insert ( body)
45
+ }
46
+
47
+ // TODO: Allow Prefer: resolution=ignore-duplicates
48
+ // TODO: on_conflict (make UPSERT work on UNIQUE columns)
49
+ pub fn upsert ( mut self , body : & str ) -> Self {
50
+ self . method = Some ( Method :: POST ) ;
51
+ self . headers
52
+ . push ( ( "Prefer" . to_string ( ) ,
53
+ "return=representation; resolution=merge-duplicates" . to_string ( ) ) ) ;
54
+ self . body = Some ( body. to_string ( ) ) ;
55
+ self
56
+ }
57
+
58
+ pub fn single_upsert ( mut self , primary_column : & str , key : & str , body : & str ) -> Self {
59
+ self . method = Some ( Method :: PUT ) ;
60
+ self . headers
61
+ . push ( ( "Prefer" . to_string ( ) , "return=representation" . to_string ( ) ) ) ;
62
+ self . queries . push ( ( primary_column. to_string ( ) ,
63
+ format ! ( "eq.{}" , key) ) ) ;
64
+ self . body = Some ( body. to_string ( ) ) ;
65
+ self
66
+ }
67
+
41
68
pub fn update ( mut self , body : & str ) -> Self {
42
69
self . method = Some ( Method :: PATCH ) ;
43
70
self . headers
0 commit comments