From adfb623ea8ab4fa1d8233b38abb86cfecd0ce740 Mon Sep 17 00:00:00 2001 From: Joel Lee Date: Fri, 29 Jan 2021 11:28:31 +0800 Subject: [PATCH] Add rpc function --- supabase_py/client.py | 49 +++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/supabase_py/client.py b/supabase_py/client.py index 5fdc440b..4867b58c 100644 --- a/supabase_py/client.py +++ b/supabase_py/client.py @@ -1,21 +1,29 @@ +from postgrest_py import PostgrestClient + class SupabaseClient(): def __init__(self, supabaseUrl: str, supabaseKey: str): if not supabaseUrl or not supabaseKey: raise("supabaseUrl is required") + SETTINGS = {} self.restUrl = f"{supabaseUrl}/rest/v1" self.realtimeUrl = f"{supabaseUrl}/realtime/v1".replace('http', 'ws') self.authUrl = f"{supabaseUrl}/auth/v1" - - - def some_other_stuff(self): - pass + # TODO: Allow user to pass in schema. This is hardcoded + self.schema = 'public' + self.supabaseUrl = supabaseUrl + self.supabaseKey = supabaseKey + # self.auth = self._initSupabaseAuthClient(SETTINGS) def auth(self): pass - def rpc(self): + def rpc(self, fn, params): + """ + Performs a stored procedure call. + """ + rest = self._initPostgrestClient() + return rest.rpc(fn, params) - pass def removeSubscription(self): pass @@ -26,17 +34,36 @@ def _closeSubscription(self, subscription): def getSubscriptions(self): pass - def _initSupabaseAuthClient(self): + def _initRealtimeClient(self): pass + # return RealtimeClient(self.realtimeUrl, { + # params: { apiKey: self.supabaseKey} + # }) - def _initSupabaseAuthClient(self): + def _initSupabaseAuthClient(self, autoRefreshToken, persistSession, + detectSessionInUrl,localStorage): pass + # return SupabaseAuthClient({ + # self.authUrl, + # "headers": { + # "Authorization": f"Bearer {self.supabaseKey}", + # "apiKey": f"{self.supabaseKey}", + # autoRefreshToken, + # persistSession, + # detectSessionInUrl, + # localStorage + # } + # }) - def _initPostgRESTClient(self): - pass + def _initPostgrestClient(self): + return PostgrestClient(self.restUrl) def _getAuthHeaders(self): - pass + headers = {} + # authBearer = self.auth.session().token if self.auth.session().token else self.supabaseKey + headers['apiKey'] = self.supabaseKey + headers['Authorization'] = f"Bearer {self.supabaseKey}" + return headers def _closeChannel(self): pass