dataflow.db.supabase¶
Supabase database integration for the Haive registry system.
This module provides functionality for connecting to and interacting with a Supabase database instance for storing registry data. It handles connection management, schema mapping, and query execution.
The module uses environment variables for configuration: - SUPABASE_URL: The URL of your Supabase instance - SUPABASE_SERVICE_KEY: Service role API key (preferred for admin operations) - SUPABASE_ANON_KEY: Anonymous API key (fallback)
Typical usage example:
>>> from haive.dataflow.db.supabase import get_supabase_client
>>>
>>> # Get a Supabase client
>>> supabase = get_supabase_client()
>>>
>>> # Query a table
>>> result = supabase.table('registry_items').select('*').execute()
>>> items = result.data
>>> print(f"Found {len(items)} registry items")
Functions¶
|
Return all non-system tables grouped by schema using raw SQL. |
|
Return foreign key relationships between tables using raw SQL. |
|
Get all primary keys per table. |
|
Get all columns, types, and constraints from. |
|
Get a configured Supabase client instance. |
|
Parse a table reference to extract table name and schema. |
|
Remove trailing semicolons and whitespace for safe RPC use. |
|
Get a table reference with appropriate schema handling. |
Module Contents¶
- dataflow.db.supabase.fetch_all_schemas_and_tables(client)¶
Return all non-system tables grouped by schema using raw SQL.
- dataflow.db.supabase.fetch_foreign_key_relations(client)¶
Return foreign key relationships between tables using raw SQL.
- dataflow.db.supabase.fetch_primary_keys(client)¶
Get all primary keys per table.
- dataflow.db.supabase.fetch_table_columns(client)¶
Get all columns, types, and constraints from. information_schema.columns.
- dataflow.db.supabase.get_supabase_client(schema=None)¶
Get a configured Supabase client instance.
Creates and returns a Supabase client configured with the specified schema. The client uses environment variables for connection parameters.
- Parameters:
schema (str | None) – Optional database schema to use. If not specified, defaults to “public” schema.
- Returns:
A configured Supabase client instance.
- Return type:
Client
- Raises:
EnvironmentError – If required environment variables are not set.
Examples
>>> # Get client with default schema >>> client = get_supabase_client() >>> >>> # Get client with specific schema >>> registry_client = get_supabase_client("registry")
- dataflow.db.supabase.parse_table_reference(table_ref)¶
Parse a table reference to extract table name and schema.
This function parses table references in various formats and extracts the table name and schema. It handles: - Simple table names: “items” (uses default schema mapping) - Schema-qualified names: “registry.items” (explicit schema)
- Parameters:
table_ref (str) – Table reference string in one of the supported formats. Examples: “items”, “registry.items”, “models.providers”
- Returns:
- A tuple containing (table_name, schema_name),
where schema_name may be None if not specified and not in DEFAULT_SCHEMA_MAP.
- Return type:
Examples
>>> parse_table_reference("items") ('items', 'registry') # Uses default schema mapping >>> parse_table_reference("registry.items") ('items', 'registry') # Explicit schema >>> parse_table_reference("custom_table") ('custom_table', None) # No mapping found
- dataflow.db.supabase.sanitize_sql(sql)¶
Remove trailing semicolons and whitespace for safe RPC use.
- dataflow.db.supabase.table(client, table_ref, schema_override=None)¶
Get a table reference with appropriate schema handling.