Skip to content

Commit 891c1e7

Browse files
authored
Merge pull request #5 from supabase/dev/support-all-verbs
Add basic support for all verbs
2 parents e73eb56 + b65b989 commit 891c1e7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/builder.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,48 @@ pub struct Builder {
55
url: String,
66
queries: Vec<(String, String)>,
77
headers: Vec<(String, String)>,
8+
body: Option<String>,
89
}
910

1011
impl Builder {
12+
// TODO: Schema
1113
pub fn new(url: &str) -> Self {
1214
Builder {
1315
method: None,
1416
url: url.to_string(),
1517
queries: Vec::new(),
1618
headers: Vec::new(),
19+
body: None,
1720
}
1821
}
1922

2023
pub fn select(mut self, column: &str) -> Self {
2124
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()));
2350
self
2451
}
2552

@@ -32,6 +59,9 @@ impl Builder {
3259
req = req.header(k, v);
3360
}
3461
req = req.query(&self.queries);
62+
if let Some(body) = self.body {
63+
req = req.body(body);
64+
}
3565

3666
let resp = req.send()
3767
.await?;

0 commit comments

Comments
 (0)