1
1
from __future__ import annotations
2
2
3
- from typing import Any , Dict , Union , cast
3
+ from typing import Any , Dict , Optional , Union , cast
4
4
5
5
from deprecation import deprecated
6
6
from httpx import Headers , QueryParams , Timeout
11
11
DEFAULT_POSTGREST_CLIENT_HEADERS ,
12
12
DEFAULT_POSTGREST_CLIENT_TIMEOUT ,
13
13
)
14
+ from ..types import CountMethod
14
15
from ..utils import AsyncClient
15
16
from .request_builder import AsyncRequestBuilder , AsyncRPCFilterRequestBuilder
16
17
@@ -78,12 +79,22 @@ def from_table(self, table: str) -> AsyncRequestBuilder:
78
79
"""Alias to :meth:`from_`."""
79
80
return self .from_ (table )
80
81
81
- def rpc (self , func : str , params : dict ) -> AsyncRPCFilterRequestBuilder [Any ]:
82
+ def rpc (
83
+ self ,
84
+ func : str ,
85
+ params : dict ,
86
+ count : Optional [CountMethod ] = None ,
87
+ head : bool = False ,
88
+ get : bool = False ,
89
+ ) -> AsyncRPCFilterRequestBuilder [Any ]:
82
90
"""Perform a stored procedure call.
83
91
84
92
Args:
85
93
func: The name of the remote procedure to run.
86
94
params: The parameters to be passed to the remote procedure.
95
+ count: The method to use to get the count of rows returned.
96
+ head: When set to `true`, `data` will not be returned. Useful if you only need the count.
97
+ get: When set to `true`, the function will be called with read-only access mode.
87
98
Returns:
88
99
:class:`AsyncRPCFilterRequestBuilder`
89
100
Example:
@@ -97,7 +108,11 @@ def rpc(self, func: str, params: dict) -> AsyncRPCFilterRequestBuilder[Any]:
97
108
This method now returns a :class:`AsyncFilterRequestBuilder` which allows you to
98
109
filter on the RPC's resultset.
99
110
"""
111
+ method = "HEAD" if head else "GET" if get else "POST"
112
+
113
+ headers = Headers ({"Prefer" : f"count={ count } " }) if count else Headers ()
114
+
100
115
# the params here are params to be sent to the RPC and not the queryparams!
101
116
return AsyncRPCFilterRequestBuilder [Any ](
102
- self .session , f"/rpc/{ func } " , "POST" , Headers () , QueryParams (), json = params
117
+ self .session , f"/rpc/{ func } " , method , headers , QueryParams (), json = params
103
118
)
0 commit comments