Skip to content

Commit

Permalink
Support RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
lqmanh committed Aug 8, 2020
1 parent 1e8166d commit 040ad6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
#### Features

- Support basic authentication
- Support stored procedures (RPC)

### v0.1.1

Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions postgrest_py/client.py
@@ -1,4 +1,4 @@
from httpx import AsyncClient
from httpx import AsyncClient, Response

from postgrest_py.request_builder import RequestBuilder

Expand All @@ -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:
Expand All @@ -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

0 comments on commit 040ad6c

Please sign in to comment.