feat: add Greenplum 7 compatibility and AI SQL generation
Greenplum 7 (PG12-based) compatibility: - Auto-detect GP via version() string, store DbFlavor per connection - connect returns ConnectResult with version + flavor - Fix pg_total_relation_size to use c.oid (universal, safer on both PG/GP) - Branch is_identity column query for GP (lacks the column) - Branch list_sessions wait_event fields for GP - Exclude gp_toolkit schema in schema listing, completion, lookup, AI context - Smart StatusBar version display: GP shows "GP 7.0.0 (PG 12.4)" - Fix connection list spinner showing on all cards during connect AI SQL generation (Ollama): - Add AI settings, model selection, and generate_sql command - Frontend AI panel with prompt input and SQL output Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ import { useCompletionSchema } from "@/hooks/use-completion-schema";
|
||||
import { useConnections } from "@/hooks/use-connections";
|
||||
import { useAppStore } from "@/stores/app-store";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Play, Loader2, Lock, BarChart3, Download, AlignLeft, Bookmark, Table2, Braces } from "lucide-react";
|
||||
import { Play, Loader2, Lock, BarChart3, Download, AlignLeft, Bookmark, Table2, Braces, Sparkles } from "lucide-react";
|
||||
import { format as formatSql } from "sql-formatter";
|
||||
import { SaveQueryDialog } from "@/components/saved-queries/SaveQueryDialog";
|
||||
import {
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { exportCsv, exportJson } from "@/lib/tauri";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import { toast } from "sonner";
|
||||
import { AiBar } from "@/components/ai/AiBar";
|
||||
import type { QueryResult, ExplainResult } from "@/types";
|
||||
|
||||
interface Props {
|
||||
@@ -51,6 +52,7 @@ export function WorkspacePanel({
|
||||
const [resultView, setResultView] = useState<"results" | "explain">("results");
|
||||
const [resultViewMode, setResultViewMode] = useState<"table" | "json">("table");
|
||||
const [saveDialogOpen, setSaveDialogOpen] = useState(false);
|
||||
const [aiBarOpen, setAiBarOpen] = useState(false);
|
||||
|
||||
const queryMutation = useQueryExecution();
|
||||
const addHistoryMutation = useAddHistory();
|
||||
@@ -245,6 +247,16 @@ export function WorkspacePanel({
|
||||
<Bookmark className="h-3 w-3" />
|
||||
Save
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant={aiBarOpen ? "secondary" : "ghost"}
|
||||
className="h-6 gap-1 text-xs"
|
||||
onClick={() => setAiBarOpen(!aiBarOpen)}
|
||||
title="AI SQL Generator"
|
||||
>
|
||||
<Sparkles className="h-3 w-3" />
|
||||
AI
|
||||
</Button>
|
||||
{result && result.columns.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -277,7 +289,18 @@ export function WorkspacePanel({
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{aiBarOpen && (
|
||||
<AiBar
|
||||
connectionId={connectionId}
|
||||
onSqlGenerated={(sql) => {
|
||||
setSqlValue(sql);
|
||||
onSqlChange?.(sql);
|
||||
}}
|
||||
onClose={() => setAiBarOpen(false)}
|
||||
onExecute={handleExecute}
|
||||
/>
|
||||
)}
|
||||
<div className="min-h-0 flex-1">
|
||||
<SqlEditor
|
||||
value={sqlValue}
|
||||
onChange={handleChange}
|
||||
@@ -290,70 +313,74 @@ export function WorkspacePanel({
|
||||
</ResizablePanel>
|
||||
<ResizableHandle withHandle />
|
||||
<ResizablePanel id="results" defaultSize="60%" minSize="15%">
|
||||
{(explainData || result || error) && (
|
||||
<div className="flex items-center border-b text-xs">
|
||||
<button
|
||||
className={`px-3 py-1 font-medium ${
|
||||
resultView === "results"
|
||||
? "bg-background text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => setResultView("results")}
|
||||
>
|
||||
Results
|
||||
</button>
|
||||
{explainData && (
|
||||
<div className="flex h-full flex-col overflow-hidden">
|
||||
{(explainData || result || error) && (
|
||||
<div className="flex shrink-0 items-center border-b text-xs">
|
||||
<button
|
||||
className={`px-3 py-1 font-medium ${
|
||||
resultView === "explain"
|
||||
resultView === "results"
|
||||
? "bg-background text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => setResultView("explain")}
|
||||
onClick={() => setResultView("results")}
|
||||
>
|
||||
Explain
|
||||
Results
|
||||
</button>
|
||||
)}
|
||||
{resultView === "results" && result && result.columns.length > 0 && (
|
||||
<div className="ml-auto mr-2 flex items-center rounded-md border">
|
||||
{explainData && (
|
||||
<button
|
||||
className={`flex items-center gap-1 px-2 py-0.5 font-medium ${
|
||||
resultViewMode === "table"
|
||||
? "bg-muted text-foreground"
|
||||
className={`px-3 py-1 font-medium ${
|
||||
resultView === "explain"
|
||||
? "bg-background text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => setResultViewMode("table")}
|
||||
title="Table view"
|
||||
onClick={() => setResultView("explain")}
|
||||
>
|
||||
<Table2 className="h-3 w-3" />
|
||||
Table
|
||||
Explain
|
||||
</button>
|
||||
<button
|
||||
className={`flex items-center gap-1 px-2 py-0.5 font-medium ${
|
||||
resultViewMode === "json"
|
||||
? "bg-muted text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => setResultViewMode("json")}
|
||||
title="JSON view"
|
||||
>
|
||||
<Braces className="h-3 w-3" />
|
||||
JSON
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{resultView === "results" && result && result.columns.length > 0 && (
|
||||
<div className="ml-auto mr-2 flex items-center rounded-md border">
|
||||
<button
|
||||
className={`flex items-center gap-1 px-2 py-0.5 font-medium ${
|
||||
resultViewMode === "table"
|
||||
? "bg-muted text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => setResultViewMode("table")}
|
||||
title="Table view"
|
||||
>
|
||||
<Table2 className="h-3 w-3" />
|
||||
Table
|
||||
</button>
|
||||
<button
|
||||
className={`flex items-center gap-1 px-2 py-0.5 font-medium ${
|
||||
resultViewMode === "json"
|
||||
? "bg-muted text-foreground"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
onClick={() => setResultViewMode("json")}
|
||||
title="JSON view"
|
||||
>
|
||||
<Braces className="h-3 w-3" />
|
||||
JSON
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="min-h-0 flex-1">
|
||||
{resultView === "explain" && explainData ? (
|
||||
<ExplainView data={explainData} />
|
||||
) : (
|
||||
<ResultsPanel
|
||||
result={result}
|
||||
error={error}
|
||||
isLoading={queryMutation.isPending && resultView === "results"}
|
||||
viewMode={resultViewMode}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{resultView === "explain" && explainData ? (
|
||||
<ExplainView data={explainData} />
|
||||
) : (
|
||||
<ResultsPanel
|
||||
result={result}
|
||||
error={error}
|
||||
isLoading={queryMutation.isPending && resultView === "results"}
|
||||
viewMode={resultViewMode}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
</ResizablePanelGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user