Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/_service.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/auth.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/client.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/database.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/edge_functions.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/init.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/realtime.cpython-312.pyc
Binary file not shown.
Binary file modified __pycache__/storage.cpython-312.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
24 changes: 18 additions & 6 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from ._service import SupabaseService

from ._service import SupabaseService

class SupabaseDatabaseService(SupabaseService):
"""
Service for interacting with Supabase Database (PostgreSQL) API.
Expand All @@ -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.

Expand Down Expand Up @@ -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"}
)
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -87,6 +93,7 @@ def insert_data(self,
method="POST",
endpoint=endpoint,
auth_token=auth_token,
is_admin=is_admin,
data=data,
headers=headers
)
Expand All @@ -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.

Expand All @@ -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"}
Expand All @@ -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).

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

Expand All @@ -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"}
)
Expand Down
10 changes: 6 additions & 4 deletions init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down