feat: add supabase db

This commit is contained in:
qixinbo
2026-03-21 20:28:02 +08:00
parent cf19c9c12f
commit 7da0d9677e
6 changed files with 76 additions and 5 deletions
+3
View File
@@ -133,4 +133,7 @@ def test_datasource_connection(
else: else:
raise HTTPException(status_code=400, detail="Connection failed") raise HTTPException(status_code=400, detail="Connection failed")
except Exception as e: except Exception as e:
import traceback
import sys
print(f"Datasource Test Error: {str(e)}\n{traceback.format_exc()}", file=sys.stderr)
raise HTTPException(status_code=400, detail=f"Connection failed: {str(e)}") raise HTTPException(status_code=400, detail=f"Connection failed: {str(e)}")
+11 -3
View File
@@ -13,9 +13,17 @@ def _get_cached_connector(ds_type: str, config_json: str):
config = json.loads(config_json) config = json.loads(config_json)
if ds_type in ["postgres", "postgresql", "supabase"]: if ds_type in ["postgres", "postgresql", "supabase"]:
# Supabase is just postgres db_url = config.get("connection_string")
db_url = config.get("connection_string") or \ if not db_url:
f"postgresql://{config.get('user')}:{config.get('password')}@{config.get('host')}:{config.get('port', 5432)}/{config.get('database')}" default_port = 6543 if ds_type == "supabase" else 5432
port = config.get("port") or default_port
db_url = f"postgresql://{config.get('user')}:{config.get('password')}@{config.get('host')}:{port}/{config.get('database')}"
if ds_type == "supabase" and "?" not in db_url:
db_url += "?sslmode=require"
elif ds_type == "supabase" and "sslmode=" not in db_url:
db_url += "&sslmode=require"
return PostgresConnector(db_url=db_url) return PostgresConnector(db_url=db_url)
elif ds_type == "sqlite": elif ds_type == "sqlite":
+1 -1
View File
@@ -69,6 +69,6 @@ class PostgresConnector:
return True return True
except Exception as e: except Exception as e:
print(f"PostgreSQL Connection Error: {e}") print(f"PostgreSQL Connection Error: {e}")
return False raise e
postgres_connector = PostgresConnector() postgres_connector = PostgresConnector()
Binary file not shown.
+60 -1
View File
@@ -93,9 +93,68 @@ export function DataSourceForm({ initialData, onSubmit, onTest, onCancel }: Data
const renderConfigFields = () => { const renderConfigFields = () => {
switch (type) { switch (type) {
case "supabase":
return (
<div className="space-y-4">
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<label className="text-sm font-medium">Host</label>
<Input
value={config.host || ""}
onChange={e => handleConfigChange("host", e.target.value)}
placeholder="aws-0-[region].pooler.supabase.com"
/>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Port</label>
<Input
type="number"
value={config.port || 6543}
onChange={e => handleConfigChange("port", parseInt(e.target.value))}
placeholder="6543"
/>
</div>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Database</label>
<Input
value={config.database || "postgres"}
onChange={e => handleConfigChange("database", e.target.value)}
placeholder="postgres"
/>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Username</label>
<Input
value={config.user || ""}
onChange={e => handleConfigChange("user", e.target.value)}
placeholder="postgres.[project-ref]"
/>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Password</label>
<Input
type="password"
value={config.password || ""}
onChange={e => handleConfigChange("password", e.target.value)}
placeholder="••••••"
/>
</div>
<div className="text-xs text-zinc-500 pt-2">
使 Supabase Connection String (URI):
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Connection String</label>
<Input
value={config.connection_string || ""}
onChange={e => handleConfigChange("connection_string", e.target.value)}
placeholder="postgresql://postgres.[project-ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres?sslmode=require"
/>
</div>
</div>
);
case "postgres": case "postgres":
case "postgresql": case "postgresql":
case "supabase":
case "mysql": case "mysql":
case "sqlserver": case "sqlserver":
case "oracle": case "oracle":
+1
View File
@@ -12,6 +12,7 @@ const SOURCE_TYPES = [
{ id: "csv", name: "CSV Upload", icon: <FileText className="h-6 w-6 text-green-600" /> }, { id: "csv", name: "CSV Upload", icon: <FileText className="h-6 w-6 text-green-600" /> },
{ id: "bigquery", name: "BigQuery", icon: <Database className="h-6 w-6 text-blue-500" /> }, { id: "bigquery", name: "BigQuery", icon: <Database className="h-6 w-6 text-blue-500" /> },
{ id: "postgres", name: "PostgreSQL", icon: <Database className="h-6 w-6 text-indigo-600" /> }, { id: "postgres", name: "PostgreSQL", icon: <Database className="h-6 w-6 text-indigo-600" /> },
{ id: "supabase", name: "Supabase", icon: <Database className="h-6 w-6 text-emerald-500" /> },
{ id: "mysql", name: "MySQL", icon: <Database className="h-6 w-6 text-cyan-600" /> }, { id: "mysql", name: "MySQL", icon: <Database className="h-6 w-6 text-cyan-600" /> },
{ id: "oracle", name: "Oracle", icon: <Database className="h-6 w-6 text-red-600" /> }, { id: "oracle", name: "Oracle", icon: <Database className="h-6 w-6 text-red-600" /> },
{ id: "sqlserver", name: "SQL Server", icon: <Database className="h-6 w-6 text-red-500" /> }, { id: "sqlserver", name: "SQL Server", icon: <Database className="h-6 w-6 text-red-500" /> },