From 040ad6c6e5a5431e18184c29258608c26f98cf47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C6=B0=C6=A1ng=20Quang=20M=E1=BA=A1nh?= Date: Sat, 8 Aug 2020 10:04:17 +0700 Subject: [PATCH] Support RPC --- CHANGELOG.md | 1 + README.md | 8 ++++++++ postgrest_py/client.py | 11 +++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bd5953..1c90b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ #### Features - Support basic authentication +- Support stored procedures (RPC) ### v0.1.1 diff --git a/README.md b/README.md index 1dccd19..e18ee3f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@ PostgREST client for Python. This library provides an ORM interface to PostgREST ### Instructions +#### With Poetry + +```sh +$ poetry add git+https://github.com/lqmanh/postgrest_py.git#v0.1.1 +``` + +#### With Pip + ## USAGE ## DOCUMENTATION diff --git a/postgrest_py/client.py b/postgrest_py/client.py index 72275ba..92857c7 100644 --- a/postgrest_py/client.py +++ b/postgrest_py/client.py @@ -1,4 +1,4 @@ -from httpx import AsyncClient +from httpx import AsyncClient, Response from postgrest_py.request_builder import RequestBuilder @@ -22,7 +22,7 @@ async def __aexit__(self, exc_type, exc, tb) -> None: async def aclose(self) -> None: await self.session.aclose() - def auth(self, bearer_token: str, *, username: str = None, password=""): + def auth(self, bearer_token: str, *, username: str = None, password: str = None): """Authenticate the request, with either bearer token or basic authentication.""" if username: @@ -44,3 +44,10 @@ def from_(self, table: str) -> RequestBuilder: """Alias to Self.from_table().""" return self.from_table(table) + + async def rpc(self, func: str, params: dict) -> Response: + """Execute a stored procedure call.""" + + path = f"/rpc/{func}" + r = await self.session.post(path, json=params) + return r