diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc index c5b2959..3d3f34e 100644 Binary files a/__pycache__/__init__.cpython-312.pyc and b/__pycache__/__init__.cpython-312.pyc differ diff --git a/__pycache__/_service.cpython-312.pyc b/__pycache__/_service.cpython-312.pyc index 33f699d..2d335b4 100644 Binary files a/__pycache__/_service.cpython-312.pyc and b/__pycache__/_service.cpython-312.pyc differ diff --git a/__pycache__/auth.cpython-312.pyc b/__pycache__/auth.cpython-312.pyc index 332c60d..89eea73 100644 Binary files a/__pycache__/auth.cpython-312.pyc and b/__pycache__/auth.cpython-312.pyc differ diff --git a/__pycache__/client.cpython-312.pyc b/__pycache__/client.cpython-312.pyc index 1696081..7d31bc3 100644 Binary files a/__pycache__/client.cpython-312.pyc and b/__pycache__/client.cpython-312.pyc differ diff --git a/__pycache__/database.cpython-312.pyc b/__pycache__/database.cpython-312.pyc index 8ae04a7..68afaad 100644 Binary files a/__pycache__/database.cpython-312.pyc and b/__pycache__/database.cpython-312.pyc differ diff --git a/__pycache__/edge_functions.cpython-312.pyc b/__pycache__/edge_functions.cpython-312.pyc index a9199e2..855e4c1 100644 Binary files a/__pycache__/edge_functions.cpython-312.pyc and b/__pycache__/edge_functions.cpython-312.pyc differ diff --git a/__pycache__/init.cpython-312.pyc b/__pycache__/init.cpython-312.pyc index 542e1b7..ea3bfd6 100644 Binary files a/__pycache__/init.cpython-312.pyc and b/__pycache__/init.cpython-312.pyc differ diff --git a/__pycache__/realtime.cpython-312.pyc b/__pycache__/realtime.cpython-312.pyc index d9e1a81..e707fec 100644 Binary files a/__pycache__/realtime.cpython-312.pyc and b/__pycache__/realtime.cpython-312.pyc differ diff --git a/__pycache__/storage.cpython-312.pyc b/__pycache__/storage.cpython-312.pyc index 85536ed..1133f41 100644 Binary files a/__pycache__/storage.cpython-312.pyc and b/__pycache__/storage.cpython-312.pyc differ diff --git a/client.py b/client.py index 3c71409..5116e43 100644 --- a/client.py +++ b/client.py @@ -84,6 +84,18 @@ def get_raw_client(self): supabase.Client instance """ return self._raw_client + + def table(self, table_name: str): + """ + Delegate table access to the raw client for compatibility. + + Args: + table_name: Name of the table + + Returns: + Table query builder from raw client + """ + return self._raw_client.table(table_name) # Create a singleton instance supabase = SupabaseClient() diff --git a/database.py b/database.py index bfe9d47..fbf46e1 100644 --- a/database.py +++ b/database.py @@ -2,6 +2,8 @@ from ._service import SupabaseService +from ._service import SupabaseService + class SupabaseDatabaseService(SupabaseService): """ Service for interacting with Supabase Database (PostgreSQL) API. @@ -17,7 +19,8 @@ def fetch_data(self, filters: Optional[Dict[str, Any]] = None, order: Optional[str] = None, limit: Optional[int] = None, - offset: Optional[int] = None) -> List[Dict[str, Any]]: + offset: Optional[int] = None, + is_admin: bool = False) -> List[Dict[str, Any]]: """ Fetch data from a table with optional filtering, ordering, and pagination. @@ -56,6 +59,7 @@ def fetch_data(self, method="GET", endpoint=endpoint, auth_token=auth_token, + is_admin=is_admin, params=params, headers={"Prefer": "return=representation"} ) @@ -64,7 +68,8 @@ def insert_data(self, table: str, data: Union[Dict[str, Any], List[Dict[str, Any]]], auth_token: Optional[str] = None, - upsert: bool = False) -> List[Dict[str, Any]]: + upsert: bool = False, + is_admin: bool = False) -> List[Dict[str, Any]]: """ Insert data into a table. @@ -73,6 +78,7 @@ def insert_data(self, data: Data to insert (single record or list of records) auth_token: Optional JWT token for authenticated requests upsert: Whether to upsert (update on conflict) + is_admin: Whether to use service role key (bypasses RLS) Returns: Inserted data @@ -87,6 +93,7 @@ def insert_data(self, method="POST", endpoint=endpoint, auth_token=auth_token, + is_admin=is_admin, data=data, headers=headers ) @@ -95,7 +102,8 @@ def update_data(self, table: str, data: Dict[str, Any], filters: Dict[str, Any], - auth_token: Optional[str] = None) -> List[Dict[str, Any]]: + auth_token: Optional[str] = None, + is_admin: bool = False) -> List[Dict[str, Any]]: """ Update data in a table. @@ -120,6 +128,7 @@ def update_data(self, method="PATCH", endpoint=endpoint, auth_token=auth_token, + is_admin=is_admin, # Pass the is_admin parameter to use service role key data=data, params=params, headers={"Prefer": "return=representation"} @@ -128,7 +137,8 @@ def update_data(self, def upsert_data(self, table: str, data: Union[Dict[str, Any], List[Dict[str, Any]]], - auth_token: Optional[str] = None) -> List[Dict[str, Any]]: + auth_token: Optional[str] = None, + is_admin: bool = False) -> List[Dict[str, Any]]: """ Upsert data in a table (insert or update). @@ -140,12 +150,13 @@ def upsert_data(self, Returns: Upserted data """ - return self.insert_data(table, data, auth_token, upsert=True) + return self.insert_data(table, data, auth_token, upsert=True, is_admin=is_admin) def delete_data(self, table: str, filters: Dict[str, Any], - auth_token: Optional[str] = None) -> List[Dict[str, Any]]: + auth_token: Optional[str] = None, + is_admin: bool = False) -> List[Dict[str, Any]]: """ Delete data from a table. @@ -169,6 +180,7 @@ def delete_data(self, method="DELETE", endpoint=endpoint, auth_token=auth_token, + is_admin=is_admin, # Pass the is_admin parameter to use service role key params=params, headers={"Prefer": "return=representation"} ) diff --git a/init.py b/init.py index 862a284..d9e10cf 100644 --- a/init.py +++ b/init.py @@ -53,10 +53,12 @@ def initialize_supabase() -> Client: # Check for required environment variables supabase_url = os.getenv("SUPABASE_URL") - # Use service role key for backend operations to bypass RLS - supabase_key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") or os.getenv("SUPABASE_ANON_KEY") - - print(f"Supabase URL: {supabase_url}") # Added print statement to show the URL + # Determine which key to use: prefer service role key for admin operations + service_role_key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") + if service_role_key: + supabase_key = service_role_key + else: + supabase_key = os.getenv("SUPABASE_ANON_KEY") if not supabase_url: error_msg = "SUPABASE_URL is not set in environment variables"