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 diff --git a/postgrest/_async/client.py b/postgrest/_async/client.py index 11f6941d..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 AsyncFilterRequestBuilder, AsyncRequestBuilder +from .request_builder import AsyncRequestBuilder, AsyncSelectRequestBuilder 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..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 SyncFilterRequestBuilder, SyncRequestBuilder +from .request_builder import SyncRequestBuilder, SyncSelectRequestBuilder 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 )