Skip to content

Commit d6a5df9

Browse files
authored
feat: add schema method to the client (#809)
1 parent 8468c2e commit d6a5df9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

supabase/_async/client.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def __init__(
7474
self.auth_url = f"{supabase_url}/auth/v1"
7575
self.storage_url = f"{supabase_url}/storage/v1"
7676
self.functions_url = f"{supabase_url}/functions/v1"
77-
self.schema = options.schema
7877

7978
# Instantiate clients.
8079
self.auth = self._init_supabase_auth_client(
@@ -110,6 +109,19 @@ def table(self, table_name: str) -> AsyncRequestBuilder:
110109
"""
111110
return self.from_(table_name)
112111

112+
def schema(self, schema: str) -> AsyncPostgrestClient:
113+
"""Select a schema to query or perform an function (rpc) call.
114+
115+
The schema needs to be on the list of exposed schemas inside Supabase.
116+
"""
117+
self._postgrest = self._init_postgrest_client(
118+
rest_url=self.rest_url,
119+
headers=self.options.headers,
120+
schema=schema,
121+
timeout=self.options.postgrest_client_timeout,
122+
)
123+
return self._postgrest
124+
113125
def from_(self, table_name: str) -> AsyncRequestBuilder:
114126
"""Perform a table operation.
115127

supabase/_sync/client.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def __init__(
7474
self.auth_url = f"{supabase_url}/auth/v1"
7575
self.storage_url = f"{supabase_url}/storage/v1"
7676
self.functions_url = f"{supabase_url}/functions/v1"
77-
self.schema = options.schema
7877

7978
# Instantiate clients.
8079
self.auth = self._init_supabase_auth_client(
@@ -110,6 +109,19 @@ def table(self, table_name: str) -> SyncRequestBuilder:
110109
"""
111110
return self.from_(table_name)
112111

112+
def schema(self, schema: str) -> SyncPostgrestClient:
113+
"""Select a schema to query or perform an function (rpc) call.
114+
115+
The schema needs to be on the list of exposed schemas inside Supabase.
116+
"""
117+
self._postgrest = self._init_postgrest_client(
118+
rest_url=self.rest_url,
119+
headers=self.options.headers,
120+
schema=schema,
121+
timeout=self.options.postgrest_client_timeout,
122+
)
123+
return self._postgrest
124+
113125
def from_(self, table_name: str) -> SyncRequestBuilder:
114126
"""Perform a table operation.
115127

0 commit comments

Comments
 (0)