Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions postgrest_py/_async/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
pre_upsert,
process_response,
)
from postgrest_py.types import ReturnMethod
from postgrest_py.utils import AsyncClient


Expand Down Expand Up @@ -78,13 +79,15 @@ def insert(
json: dict,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
upsert=False,
) -> AsyncQueryRequestBuilder:
method, json = pre_insert(
self.session,
self.path,
json,
count=count,
returning=returning,
upsert=upsert,
)
return AsyncQueryRequestBuilder(self.session, self.path, method, json)
Expand All @@ -94,13 +97,15 @@ def upsert(
json: dict,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
ignore_duplicates=False,
) -> AsyncQueryRequestBuilder:
method, json = pre_upsert(
self.session,
self.path,
json,
count=count,
returning=returning,
ignore_duplicates=ignore_duplicates,
)
return AsyncQueryRequestBuilder(self.session, self.path, method, json)
Expand All @@ -110,10 +115,27 @@ def update(
json: dict,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
) -> AsyncFilterRequestBuilder:
method, json = pre_update(self.session, self.path, json, count=count)
method, json = pre_update(
self.session,
self.path,
json,
count=count,
returning=returning,
)
return AsyncFilterRequestBuilder(self.session, self.path, method, json)

def delete(self, *, count: Optional[CountMethod] = None) -> AsyncFilterRequestBuilder:
method, json = pre_delete(self.session, self.path, count=count)
def delete(
self,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
) -> AsyncFilterRequestBuilder:
method, json = pre_delete(
self.session,
self.path,
count=count,
returning=returning,
)
return AsyncFilterRequestBuilder(self.session, self.path, method, json)
28 changes: 25 additions & 3 deletions postgrest_py/_sync/request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
pre_upsert,
process_response,
)
from postgrest_py.types import ReturnMethod
from postgrest_py.utils import SyncClient


Expand Down Expand Up @@ -78,13 +79,15 @@ def insert(
json: dict,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
upsert=False,
) -> SyncQueryRequestBuilder:
method, json = pre_insert(
self.session,
self.path,
json,
count=count,
returning=returning,
upsert=upsert,
)
return SyncQueryRequestBuilder(self.session, self.path, method, json)
Expand All @@ -94,13 +97,15 @@ def upsert(
json: dict,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
ignore_duplicates=False,
) -> SyncQueryRequestBuilder:
method, json = pre_upsert(
self.session,
self.path,
json,
count=count,
returning=returning,
ignore_duplicates=ignore_duplicates,
)
return SyncQueryRequestBuilder(self.session, self.path, method, json)
Expand All @@ -110,10 +115,27 @@ def update(
json: dict,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
) -> SyncFilterRequestBuilder:
method, json = pre_update(self.session, self.path, json, count=count)
method, json = pre_update(
self.session,
self.path,
json,
count=count,
returning=returning,
)
return SyncFilterRequestBuilder(self.session, self.path, method, json)

def delete(self, *, count: Optional[CountMethod] = None) -> SyncFilterRequestBuilder:
method, json = pre_delete(self.session, self.path, count=count)
def delete(
self,
*,
count: Optional[CountMethod] = None,
returning: ReturnMethod = ReturnMethod.representation,
) -> SyncFilterRequestBuilder:
method, json = pre_delete(
self.session,
self.path,
count=count,
returning=returning,
)
return SyncFilterRequestBuilder(self.session, self.path, method, json)
24 changes: 14 additions & 10 deletions postgrest_py/base_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from httpx import Response

from postgrest_py.constants import CountMethod, Filters, RequestMethod
from postgrest_py.types import CountMethod, Filters, RequestMethod, ReturnMethod
from postgrest_py.utils import (
AsyncClient,
SyncClient,
Expand Down Expand Up @@ -33,10 +33,11 @@ def pre_insert(
path: str,
json: dict,
*,
count: Optional[CountMethod] = None,
upsert=False,
count: Optional[CountMethod],
returning: ReturnMethod,
upsert: bool,
) -> Tuple[RequestMethod, dict]:
prefer_headers = ["return=representation"]
prefer_headers = [f"return={returning}"]
if count:
prefer_headers.append(f"count={count}")
if upsert:
Expand All @@ -50,8 +51,9 @@ def pre_upsert(
path: str,
json: dict,
*,
count: Optional[CountMethod] = None,
ignore_duplicates=False,
count: Optional[CountMethod],
returning: ReturnMethod,
ignore_duplicates: bool,
) -> Tuple[RequestMethod, dict]:
prefer_headers = ["return=representation"]
if count:
Expand All @@ -67,9 +69,10 @@ def pre_update(
path: str,
json: dict,
*,
count: Optional[CountMethod] = None,
count: Optional[CountMethod],
returning: ReturnMethod,
) -> Tuple[RequestMethod, dict]:
prefer_headers = ["return=representation"]
prefer_headers = [f"return={returning}"]
if count:
prefer_headers.append(f"count={count}")
session.headers["prefer"] = ",".join(prefer_headers)
Expand All @@ -80,9 +83,10 @@ def pre_delete(
session: Union[AsyncClient, SyncClient],
path: str,
*,
count: Optional[CountMethod] = None,
count: Optional[CountMethod],
returning: ReturnMethod,
) -> Tuple[RequestMethod, dict]:
prefer_headers = ["return=representation"]
prefer_headers = [f"return={returning}"]
if count:
prefer_headers.append(f"count={count}")
session.headers["prefer"] = ",".join(prefer_headers)
Expand Down
5 changes: 5 additions & 0 deletions postgrest_py/constants.py → postgrest_py/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ class RequestMethod(str, Enum):
PUT = "PUT"
DELETE = "DELETE"
HEAD = "HEAD"


class ReturnMethod(str, Enum):
minimal = "minimal"
representation = "representation"
2 changes: 1 addition & 1 deletion tests/_async/test_request_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from postgrest_py import AsyncRequestBuilder
from postgrest_py.constants import CountMethod
from postgrest_py.types import CountMethod
from postgrest_py.utils import AsyncClient


Expand Down
2 changes: 1 addition & 1 deletion tests/_sync/test_request_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from postgrest_py import SyncRequestBuilder
from postgrest_py.constants import CountMethod
from postgrest_py.types import CountMethod
from postgrest_py.utils import SyncClient


Expand Down