File size: 662 Bytes
c001a4d
62d0c8c
 
c001a4d
62d0c8c
c001a4d
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
import streamlit as st


def get_connection():
    """Supabase Postgres connection.

    - On Hugging Face: set a Space Secret named SUPABASE_DB_URL (a full SQLAlchemy URL,
      e.g. postgresql+psycopg2://USER:PASSWORD@HOST:5432/postgres). It is read here as an
      environment variable, so the password never lives in the repo.
    - Locally: if SUPABASE_DB_URL is not set, this falls back to the [connections.supabase]
      block in .streamlit/secrets.toml (gitignored).
    """
    url = os.environ.get("SUPABASE_DB_URL")
    if url:
        return st.connection("supabase", type="sql", url=url)
    return st.connection("supabase", type="sql")