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")

Attributes¶

Functions¶

fetch_all_schemas_and_tables(→ list[dict])

Return all non-system tables grouped by schema using raw SQL.

fetch_foreign_key_relations(→ list[dict])

Return foreign key relationships between tables using raw SQL.

fetch_primary_keys(→ list[dict])

Get all primary keys per table.

fetch_table_columns(→ list[dict])

Get all columns, types, and constraints from.

get_supabase_client(→ supabase.Client)

Get a configured Supabase client instance.

parse_table_reference(→ tuple[str, str | None])

Parse a table reference to extract table name and schema.

sanitize_sql(→ str)

Remove trailing semicolons and whitespace for safe RPC use.

table(→ Any)

Get a table reference with appropriate schema handling.

Module Contents¶

dataflow.db.supabase.fetch_all_schemas_and_tables(client: supabase.Client) list[dict]¶

Return all non-system tables grouped by schema using raw SQL.

dataflow.db.supabase.fetch_foreign_key_relations(client: supabase.Client) list[dict]¶

Return foreign key relationships between tables using raw SQL.

dataflow.db.supabase.fetch_primary_keys(client: supabase.Client) list[dict]¶

Get all primary keys per table.

dataflow.db.supabase.fetch_table_columns(client: supabase.Client) list[dict]¶

Get all columns, types, and constraints from. information_schema.columns.

dataflow.db.supabase.get_supabase_client(schema: str | None = None) supabase.Client¶

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 – 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: str) tuple[str, str | None]¶

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 – 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:

Tuple[str, Optional[str]]

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: str) str¶

Remove trailing semicolons and whitespace for safe RPC use.

dataflow.db.supabase.table(client: supabase.Client, table_ref: str, schema_override: str | None = None) Any¶

Get a table reference with appropriate schema handling.

Parameters:
  • client – Supabase client

  • table_ref – Table reference (can include schema)

  • schema_override – Optional schema to override detected schema

Returns:

Table reference for queries

dataflow.db.supabase.DEFAULT_SCHEMA_MAP¶
dataflow.db.supabase.SUPABASE_KEY¶
dataflow.db.supabase.SUPABASE_URL¶