Skip to content

Commit 5e65ebf

Browse files
committed
trying to get postgrest working
1 parent d20cb3c commit 5e65ebf

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Diff for: pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ license = "MIT"
99
python = "^3.7.1"
1010
postgrest-py = "0.4.0"
1111
realtime-py="^0.1.2"
12-
realtime-py="^0.1.0"
1312
gotrue="0.2.0"
1413
pytest="6.2.2"
1514

Diff for: supabase_py/client.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def __init__(
6060
# )
6161
self.realtime = None
6262
self.postgrest: PostgrestClient = self._init_postgrest_client(
63-
rest_url=self.rest_url
63+
rest_url=self.rest_url,
64+
supabase_key=supabase_key,
6465
)
6566

6667
def table(self, table_name: str) -> SupabaseQueryBuilder:
@@ -161,9 +162,11 @@ def _init_supabase_auth_client(
161162
)
162163

163164
@staticmethod
164-
def _init_postgrest_client(rest_url: str) -> PostgrestClient:
165+
def _init_postgrest_client(rest_url: str, supabase_key: str) -> PostgrestClient:
165166
"""Private helper for creating an instance of the Postgrest client."""
166-
return PostgrestClient(rest_url)
167+
client = PostgrestClient(rest_url)
168+
client.auth(token=supabase_key)
169+
return client
167170

168171
def _get_auth_headers(self) -> Dict[str, str]:
169172
"""Helper method to get auth headers."""

Diff for: supabase_py/lib/query_builder.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from httpx import AsyncClient
12
from postgrest_py.client import PostgrestClient
3+
24
from .realtime_client import SupabaseRealtimeClient
35

46

@@ -23,7 +25,15 @@ def __init__(self, url, headers, schema, realtime, table):
2325
-------
2426
None
2527
"""
26-
super().__init__(url)
28+
super().__init__(base_url=url)
29+
headers = {
30+
"Accept": "application/json",
31+
"Content-Type": "application/json",
32+
"Accept-Profile": schema,
33+
"Content-Profile": schema,
34+
**headers,
35+
}
36+
self.session = AsyncClient(base_url=url, headers=headers)
2737
# self._subscription = SupabaseRealtimeClient(realtime, schema, table)
2838
# self._realtime = realtime
2939

Diff for: tests/test_client.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def test_client_auth():
5656
_assert_authenticated_user(user)
5757

5858

59-
def test_client_select():
59+
@pytest.mark.asyncio
60+
async def test_client_select():
6061
"""Ensure we can select data from a table."""
6162
from supabase_py import create_client, Client
6263

@@ -65,7 +66,8 @@ def test_client_select():
6566
supabase: Client = create_client(url, key)
6667
# TODO(fedden): Add this set back in (and expand on it) when postgrest and
6768
# realtime libs are working.
69+
query = supabase.table("countries").select("*")
6870
import ipdb
6971

7072
ipdb.set_trace()
71-
data = supabase.table("countries").select("*")
73+
data = await query.execute()

0 commit comments

Comments
 (0)