From f358e1fcf94565e3e0337007bff7bd61ff6caa72 Mon Sep 17 00:00:00 2001 From: a5r0n Date: Wed, 21 Jun 2023 18:42:56 +0300 Subject: [PATCH 1/3] fix: use SelectRequestBuilder for rpc call fixes #200 --- postgrest/_async/client.py | 10 +++++----- postgrest/_sync/client.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/postgrest/_async/client.py b/postgrest/_async/client.py index 11f6941d..ffa96630 100644 --- a/postgrest/_async/client.py +++ b/postgrest/_async/client.py @@ -12,7 +12,7 @@ DEFAULT_POSTGREST_CLIENT_TIMEOUT, ) from ..utils import AsyncClient -from .request_builder import AsyncFilterRequestBuilder, AsyncRequestBuilder +from .request_builder import AsyncSelectRequestBuilder, AsyncRequestBuilder class AsyncPostgrestClient(BasePostgrestClient): @@ -76,24 +76,24 @@ def from_table(self, table: str) -> AsyncRequestBuilder: """Alias to :meth:`from_`.""" return self.from_(table) - async def rpc(self, func: str, params: dict) -> AsyncFilterRequestBuilder: + async def rpc(self, func: str, params: dict) -> AsyncSelectRequestBuilder: """Perform a stored procedure call. Args: func: The name of the remote procedure to run. params: The parameters to be passed to the remote procedure. Returns: - :class:`AsyncFilterRequestBuilder` + :class:`AsyncSelectRequestBuilder` Example: .. code-block:: python await client.rpc("foobar", {"arg": "value"}).execute() .. versionchanged:: 0.11.0 - This method now returns a :class:`AsyncFilterRequestBuilder` which allows you to + This method now returns a :class:`AsyncSelectRequestBuilder` which allows you to filter on the RPC's resultset. """ # the params here are params to be sent to the RPC and not the queryparams! - return AsyncFilterRequestBuilder( + return AsyncSelectRequestBuilder( self.session, f"/rpc/{func}", "POST", Headers(), QueryParams(), json=params ) diff --git a/postgrest/_sync/client.py b/postgrest/_sync/client.py index e838e952..c4beb886 100644 --- a/postgrest/_sync/client.py +++ b/postgrest/_sync/client.py @@ -12,7 +12,7 @@ DEFAULT_POSTGREST_CLIENT_TIMEOUT, ) from ..utils import SyncClient -from .request_builder import SyncFilterRequestBuilder, SyncRequestBuilder +from .request_builder import SyncSelectRequestBuilder, SyncRequestBuilder class SyncPostgrestClient(BasePostgrestClient): @@ -76,24 +76,24 @@ def from_table(self, table: str) -> SyncRequestBuilder: """Alias to :meth:`from_`.""" return self.from_(table) - def rpc(self, func: str, params: dict) -> SyncFilterRequestBuilder: + def rpc(self, func: str, params: dict) -> SyncSelectRequestBuilder: """Perform a stored procedure call. Args: func: The name of the remote procedure to run. params: The parameters to be passed to the remote procedure. Returns: - :class:`AsyncFilterRequestBuilder` + :class:`ASyncSelectRequestBuilder` Example: .. code-block:: python await client.rpc("foobar", {"arg": "value"}).execute() .. versionchanged:: 0.11.0 - This method now returns a :class:`AsyncFilterRequestBuilder` which allows you to + This method now returns a :class:`ASyncSelectRequestBuilder` which allows you to filter on the RPC's resultset. """ # the params here are params to be sent to the RPC and not the queryparams! - return SyncFilterRequestBuilder( + return SyncSelectRequestBuilder( self.session, f"/rpc/{func}", "POST", Headers(), QueryParams(), json=params ) From a1077074f3feb1ebc6588e7bd9b8b612e71b061d Mon Sep 17 00:00:00 2001 From: a5r0n Date: Thu, 22 Jun 2023 09:10:45 +0300 Subject: [PATCH 2/3] docs: update RPC section in the readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a43870f..723d5dc3 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,13 @@ await client.from_("countries").delete().eq("name", "Việt Nam").execute() ### General filters ### Stored procedures (RPC) + ```py -await client.rpc("foobar", {"arg1": "value1", "arg2": "value2"}).execute() +query = await client.rpc("foobar", {"arg1": "value1", "arg2": "value2"}) +# for stored procedures that return a result set +await query.execute() +# for stored procedures that return a single object +await query.single().execute() ``` ## DEVELOPMENT From 8fc254a3b432c5cfdd0e96524bbfeca93c1ccb08 Mon Sep 17 00:00:00 2001 From: a5r0n Date: Thu, 22 Jun 2023 10:16:10 +0300 Subject: [PATCH 3/3] fixup! fix: use SelectRequestBuilder for rpc call --- postgrest/_async/client.py | 2 +- postgrest/_sync/client.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/postgrest/_async/client.py b/postgrest/_async/client.py index ffa96630..05433865 100644 --- a/postgrest/_async/client.py +++ b/postgrest/_async/client.py @@ -12,7 +12,7 @@ DEFAULT_POSTGREST_CLIENT_TIMEOUT, ) from ..utils import AsyncClient -from .request_builder import AsyncSelectRequestBuilder, AsyncRequestBuilder +from .request_builder import AsyncRequestBuilder, AsyncSelectRequestBuilder class AsyncPostgrestClient(BasePostgrestClient): diff --git a/postgrest/_sync/client.py b/postgrest/_sync/client.py index c4beb886..9feb210e 100644 --- a/postgrest/_sync/client.py +++ b/postgrest/_sync/client.py @@ -12,7 +12,7 @@ DEFAULT_POSTGREST_CLIENT_TIMEOUT, ) from ..utils import SyncClient -from .request_builder import SyncSelectRequestBuilder, SyncRequestBuilder +from .request_builder import SyncRequestBuilder, SyncSelectRequestBuilder class SyncPostgrestClient(BasePostgrestClient):