Skip to content

Commit 4379b7f

Browse files
committed
Code refactoring
1 parent 57e90da commit 4379b7f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

postgrest_py/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def schema(self, schema: str) -> Client:
3333
return self
3434

3535
def fromTable(self, table: str) -> RequestBuilder:
36-
return RequestBuilder(self.session, table)
36+
return RequestBuilder(self.session, f"/{table}")

postgrest_py/request_builder.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@
22

33

44
class RequestBuilder:
5-
def __init__(self, session: AsyncClient, table: str) -> None:
5+
def __init__(self, session: AsyncClient, path: str) -> None:
66
self.session = session
7-
self.path = f"/{table}"
8-
self.http_method = "GET"
7+
self.path = path
98
self.params = {}
109
self.json = {}
10+
self.http_method = "GET"
1111

1212
def select(self, columns: str) -> RequestBuilder:
13-
self.http_method = "GET"
1413
self.params["select"] = columns
14+
self.http_method = "GET"
15+
return self
1516

1617
def insert(self, json: dict, *, upsert=False) -> RequestBuilder:
17-
self.http_method = "POST"
1818
self.session.headers[
1919
"Prefer"
2020
] = f"return=representation{',resolution=merge-duplicates' if upsert else ''}"
2121
self.json = json
22+
self.http_method = "POST"
23+
return self
2224

2325
def update(self, json: dict) -> RequestBuilder:
24-
self.http_method = "PATCH"
2526
self.session.headers["Prefer"] = "return=representation"
2627
self.json = json
28+
self.http_method = "PATCH"
29+
return self
2730

2831
def delete(self) -> RequestBuilder:
2932
self.http_method = "DELETE"
33+
return self

0 commit comments

Comments
 (0)