ta_data_mas 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/apps/api/.prettierrc +4 -0
- package/apps/api/README.md +98 -0
- package/apps/api/drizzle/0000_right_drax.sql +87 -0
- package/apps/api/drizzle/meta/0000_snapshot.json +588 -0
- package/apps/api/drizzle/meta/_journal.json +13 -0
- package/apps/api/drizzle.config.ts +12 -0
- package/apps/api/eslint.config.mjs +35 -0
- package/apps/api/nest-cli.json +8 -0
- package/apps/api/package.json +99 -0
- package/apps/api/src/app.controller.spec.ts +25 -0
- package/apps/api/src/app.controller.ts +9 -0
- package/apps/api/src/app.module.ts +37 -0
- package/apps/api/src/app.service.ts +8 -0
- package/apps/api/src/auth/auth.controller.ts +113 -0
- package/apps/api/src/auth/auth.module.ts +15 -0
- package/apps/api/src/auth/auth.service.ts +309 -0
- package/apps/api/src/auth/decorators/current-user-decorator.ts +10 -0
- package/apps/api/src/auth/decorators/require-org-role-decorator.ts +7 -0
- package/apps/api/src/auth/dto/login.dto.ts +10 -0
- package/apps/api/src/auth/dto/register.dto.ts +14 -0
- package/apps/api/src/auth/guards/jwt-auth-guard.ts +40 -0
- package/apps/api/src/auth/guards/org-role.guards.ts +60 -0
- package/apps/api/src/db/db.module.ts +9 -0
- package/apps/api/src/db/drizzle.service.ts +16 -0
- package/apps/api/src/db/schema/index.ts +6 -0
- package/apps/api/src/db/schema/organizations.ts +30 -0
- package/apps/api/src/db/schema/projects.ts +26 -0
- package/apps/api/src/db/schema/query-history.ts +16 -0
- package/apps/api/src/db/schema/storage-buckets.ts +17 -0
- package/apps/api/src/db/schema/storage-objects.ts +18 -0
- package/apps/api/src/db/schema/users.ts +14 -0
- package/apps/api/src/main.ts +51 -0
- package/apps/api/src/members/dto/invite-member-dto.ts +6 -0
- package/apps/api/src/members/dto/update-role.dto.ts +8 -0
- package/apps/api/src/members/invite.service.ts +147 -0
- package/apps/api/src/members/members.controller.ts +56 -0
- package/apps/api/src/members/members.module.ts +13 -0
- package/apps/api/src/members/members.service.ts +85 -0
- package/apps/api/src/orgs/dto/create-org.dto.ts +8 -0
- package/apps/api/src/orgs/orgs.controller.ts +27 -0
- package/apps/api/src/orgs/orgs.module.ts +12 -0
- package/apps/api/src/orgs/orgs.service.ts +86 -0
- package/apps/api/src/project-api/project-api.controller.ts +95 -0
- package/apps/api/src/project-api/project-api.module.ts +12 -0
- package/apps/api/src/project-api/project-api.service.ts +196 -0
- package/apps/api/src/project-api/project-key.guard.ts +45 -0
- package/apps/api/src/project-api/query-parser.ts +129 -0
- package/apps/api/src/project-auth/dto/magic-link.dto.ts +7 -0
- package/apps/api/src/project-auth/dto/signin.dto.ts +10 -0
- package/apps/api/src/project-auth/dto/signup.dto.ts +11 -0
- package/apps/api/src/project-auth/project-auth-dashboard.controller.ts +35 -0
- package/apps/api/src/project-auth/project-auth.controller.ts +111 -0
- package/apps/api/src/project-auth/project-auth.module.ts +13 -0
- package/apps/api/src/project-auth/project-auth.service.ts +440 -0
- package/apps/api/src/projects/dto/create-project.dto.ts +9 -0
- package/apps/api/src/projects/projects.controller.ts +34 -0
- package/apps/api/src/projects/projects.module.ts +12 -0
- package/apps/api/src/projects/projects.service.ts +136 -0
- package/apps/api/src/realtime/realtime-socket.type.ts +14 -0
- package/apps/api/src/realtime/realtime.controller.ts +63 -0
- package/apps/api/src/realtime/realtime.gateway.ts +150 -0
- package/apps/api/src/realtime/realtime.module.ts +14 -0
- package/apps/api/src/realtime/realtime.service.ts +101 -0
- package/apps/api/src/realtime/trigger.service.ts +95 -0
- package/apps/api/src/sql-editor/dto/execute-query.dto.ts +7 -0
- package/apps/api/src/sql-editor/sql-editor.controller.ts +28 -0
- package/apps/api/src/sql-editor/sql-editor.module.ts +12 -0
- package/apps/api/src/sql-editor/sql-editor.service.ts +154 -0
- package/apps/api/src/storage/project-storage.controller.ts +140 -0
- package/apps/api/src/storage/storage.controller.ts +118 -0
- package/apps/api/src/storage/storage.module.ts +15 -0
- package/apps/api/src/storage/storage.service.ts +191 -0
- package/apps/api/src/storage/uploadthing.ts +23 -0
- package/apps/api/src/table-editor/dto/alter-table.dto.ts +15 -0
- package/apps/api/src/table-editor/dto/create-table.dto.ts +54 -0
- package/apps/api/src/table-editor/table-editor.controller.ts +117 -0
- package/apps/api/src/table-editor/table-editor.module.ts +12 -0
- package/apps/api/src/table-editor/table-editor.service.ts +366 -0
- package/apps/api/test/app.e2e-spec.ts +29 -0
- package/apps/api/test/jest-e2e.json +9 -0
- package/apps/api/tsconfig.build.json +4 -0
- package/apps/api/tsconfig.json +25 -0
- package/apps/web/.env.example +12 -0
- package/apps/web/AGENTS.md +9 -0
- package/apps/web/CLAUDE.md +1 -0
- package/apps/web/README.md +36 -0
- package/apps/web/components.json +25 -0
- package/apps/web/eslint.config.mjs +18 -0
- package/apps/web/next.config.ts +11 -0
- package/apps/web/package.json +48 -0
- package/apps/web/postcss.config.mjs +7 -0
- package/apps/web/public/file.svg +1 -0
- package/apps/web/public/globe.svg +1 -0
- package/apps/web/public/logo.svg +4 -0
- package/apps/web/public/next.svg +1 -0
- package/apps/web/public/vercel.svg +1 -0
- package/apps/web/public/window.svg +1 -0
- package/apps/web/src/app/(dashboard)/layout.tsx +33 -0
- package/apps/web/src/app/(dashboard)/organizations/(list)/layout.tsx +7 -0
- package/apps/web/src/app/(dashboard)/organizations/(list)/new/page.tsx +26 -0
- package/apps/web/src/app/(dashboard)/organizations/(list)/page.tsx +44 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/api/page.tsx +13 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/layout.tsx +19 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/page.tsx +10 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/providers/page.tsx +19 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/url-configuration/page.tsx +24 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/auth/users/page.tsx +13 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/database/page.tsx +29 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/realtime/page.tsx +28 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/sql/page.tsx +21 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/[projectSlug]/storage/page.tsx +28 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/layout.tsx +20 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/projects/page.tsx +62 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/settings/members/page.tsx +28 -0
- package/apps/web/src/app/(dashboard)/organizations/[slug]/settings/page.tsx +10 -0
- package/apps/web/src/app/(dashboard)/settings/page.tsx +12 -0
- package/apps/web/src/app/dashboard/page.tsx +14 -0
- package/apps/web/src/app/favicon.ico +0 -0
- package/apps/web/src/app/globals.css +115 -0
- package/apps/web/src/app/layout.tsx +36 -0
- package/apps/web/src/app/login/page.tsx +199 -0
- package/apps/web/src/app/page.tsx +100 -0
- package/apps/web/src/app/register/page.tsx +218 -0
- package/apps/web/src/components/app-sidebar.tsx +301 -0
- package/apps/web/src/components/navbar.tsx +63 -0
- package/apps/web/src/components/topNav.tsx +68 -0
- package/apps/web/src/components/ui/avatar.tsx +112 -0
- package/apps/web/src/components/ui/badge.tsx +48 -0
- package/apps/web/src/components/ui/button.tsx +66 -0
- package/apps/web/src/components/ui/card.tsx +102 -0
- package/apps/web/src/components/ui/checkbox.tsx +32 -0
- package/apps/web/src/components/ui/dialog.tsx +168 -0
- package/apps/web/src/components/ui/dropdown-menu.tsx +269 -0
- package/apps/web/src/components/ui/field.tsx +238 -0
- package/apps/web/src/components/ui/input.tsx +19 -0
- package/apps/web/src/components/ui/label.tsx +24 -0
- package/apps/web/src/components/ui/resizable.tsx +50 -0
- package/apps/web/src/components/ui/scroll-area.tsx +55 -0
- package/apps/web/src/components/ui/select.tsx +192 -0
- package/apps/web/src/components/ui/separator.tsx +28 -0
- package/apps/web/src/components/ui/sheet.tsx +147 -0
- package/apps/web/src/components/ui/sidebar.tsx +703 -0
- package/apps/web/src/components/ui/skeleton.tsx +13 -0
- package/apps/web/src/components/ui/switch.tsx +33 -0
- package/apps/web/src/components/ui/table.tsx +116 -0
- package/apps/web/src/components/ui/tooltip.tsx +57 -0
- package/apps/web/src/features/api-docs/api-docs-client.tsx +227 -0
- package/apps/web/src/features/api-docs/api-docs-helpers.server.ts +86 -0
- package/apps/web/src/features/auth/action.ts +67 -0
- package/apps/web/src/features/auth/client.schema.ts +13 -0
- package/apps/web/src/features/auth/constants.ts +6 -0
- package/apps/web/src/features/auth/cookies.ts +86 -0
- package/apps/web/src/features/auth/server.schema.ts +11 -0
- package/apps/web/src/features/auth/sign-out.ts +17 -0
- package/apps/web/src/features/members/action.ts +66 -0
- package/apps/web/src/features/members/client.schema.ts +11 -0
- package/apps/web/src/features/members/constants.ts +8 -0
- package/apps/web/src/features/members/members-client.tsx +198 -0
- package/apps/web/src/features/members/members-helpers.server.ts +21 -0
- package/apps/web/src/features/members/server.schema.ts +19 -0
- package/apps/web/src/features/organization/action.ts +45 -0
- package/apps/web/src/features/organization/client.schema.ts +5 -0
- package/apps/web/src/features/organization/constants.tsx +3 -0
- package/apps/web/src/features/organization/create-org-form.tsx +66 -0
- package/apps/web/src/features/organization/organization-helpers.server.ts +35 -0
- package/apps/web/src/features/organization/server.schema.ts +10 -0
- package/apps/web/src/features/project-auth/project-auth-action.ts +78 -0
- package/apps/web/src/features/project-auth/project-auth-client.schema.ts +18 -0
- package/apps/web/src/features/project-auth/project-auth-constants.ts +8 -0
- package/apps/web/src/features/project-auth/project-auth-helpers.server.ts +39 -0
- package/apps/web/src/features/project-auth/project-auth-providers.tsx +222 -0
- package/apps/web/src/features/project-auth/project-auth-server.schema.ts +22 -0
- package/apps/web/src/features/project-auth/project-auth-shell.tsx +106 -0
- package/apps/web/src/features/project-auth/project-auth-url-config.tsx +151 -0
- package/apps/web/src/features/project-auth/project-auth-users.tsx +138 -0
- package/apps/web/src/features/projects/action.ts +46 -0
- package/apps/web/src/features/projects/client.schema.ts +9 -0
- package/apps/web/src/features/projects/constants.ts +6 -0
- package/apps/web/src/features/projects/create-project-modal.tsx +117 -0
- package/apps/web/src/features/projects/project-helpers.server.ts +38 -0
- package/apps/web/src/features/projects/server.schema.ts +10 -0
- package/apps/web/src/features/realtime/realtime-client.tsx +294 -0
- package/apps/web/src/features/realtime/realtime-helpers.server.ts +40 -0
- package/apps/web/src/features/sql-editor/sql-editor-client.tsx +324 -0
- package/apps/web/src/features/sql-editor/sql-editor-helpers.server.ts +22 -0
- package/apps/web/src/features/storage/storage-client.tsx +500 -0
- package/apps/web/src/features/storage/storage-helpers.server.ts +36 -0
- package/apps/web/src/features/table-editor/action.ts +97 -0
- package/apps/web/src/features/table-editor/add-column-dialog.tsx +184 -0
- package/apps/web/src/features/table-editor/client.schema.ts +36 -0
- package/apps/web/src/features/table-editor/create-table-drawer.tsx +542 -0
- package/apps/web/src/features/table-editor/server.schema.ts +41 -0
- package/apps/web/src/features/table-editor/table-editor-client.tsx +737 -0
- package/apps/web/src/features/table-editor/table-editor-helpers.server.ts +39 -0
- package/apps/web/src/hooks/use-mobile.ts +19 -0
- package/apps/web/src/lib/axios.ts +8 -0
- package/apps/web/src/lib/utils.ts +6 -0
- package/apps/web/src/proxy.ts +72 -0
- package/apps/web/src/server-utils/utils.ts +10 -0
- package/apps/web/tsconfig.json +34 -0
- package/package.json +22 -0
- package/packages/apiDatabase-js/package.json +39 -0
- package/packages/apiDatabase-js/src/auth/index.ts +121 -0
- package/packages/apiDatabase-js/src/client.ts +25 -0
- package/packages/apiDatabase-js/src/db/index.ts +15 -0
- package/packages/apiDatabase-js/src/db/query-builder.ts +194 -0
- package/packages/apiDatabase-js/src/index.ts +16 -0
- package/packages/apiDatabase-js/src/realtime/index.ts +84 -0
- package/packages/apiDatabase-js/src/storage/index.ts +130 -0
- package/packages/apiDatabase-js/tsconfig.json +13 -0
- package/packages/apiDatabase-js/tsdown.config.ts +20 -0
- package/packages/constants/package.json +6 -0
- package/packages/constants/src/index.ts +76 -0
- package/packages/tsconfig.json +13 -0
- package/packages/tsdown.config.ts +20 -0
- package/packages/types/package.json +6 -0
- package/packages/types/src/index.ts +254 -0
- package/pnpm-workspace.yaml +10 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useRef, useCallback } from "react";
|
|
4
|
+
import dynamic from "next/dynamic";
|
|
5
|
+
import type { OnMount } from "@monaco-editor/react";
|
|
6
|
+
import {
|
|
7
|
+
ResizablePanelGroup,
|
|
8
|
+
ResizablePanel,
|
|
9
|
+
ResizableHandle,
|
|
10
|
+
} from "@/components/ui/resizable";
|
|
11
|
+
import { Button } from "@/components/ui/button";
|
|
12
|
+
import {
|
|
13
|
+
Table,
|
|
14
|
+
TableBody,
|
|
15
|
+
TableCell,
|
|
16
|
+
TableHead,
|
|
17
|
+
TableHeader,
|
|
18
|
+
TableRow,
|
|
19
|
+
} from "@/components/ui/table";
|
|
20
|
+
import { Play, Clock, History, X } from "lucide-react";
|
|
21
|
+
import type { QueryResult, QueryHistoryItem } from "@apiDatabase/types";
|
|
22
|
+
|
|
23
|
+
const MonacoEditor = dynamic(() => import("@monaco-editor/react"), {
|
|
24
|
+
ssr: false,
|
|
25
|
+
loading: () => (
|
|
26
|
+
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">
|
|
27
|
+
Loading editor...
|
|
28
|
+
</div>
|
|
29
|
+
),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function formatCellValue(value: unknown): string {
|
|
33
|
+
if (value === null || value === undefined) return "";
|
|
34
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SqlEditorClientProps {
|
|
39
|
+
orgSlug: string;
|
|
40
|
+
projectSlug: string;
|
|
41
|
+
initialHistory: QueryHistoryItem[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function SqlEditorClient({
|
|
45
|
+
orgSlug,
|
|
46
|
+
projectSlug,
|
|
47
|
+
initialHistory,
|
|
48
|
+
}: SqlEditorClientProps) {
|
|
49
|
+
const [sql, setSql] = useState("SELECT * FROM users LIMIT 10;");
|
|
50
|
+
const [result, setResult] = useState<QueryResult | null>(null);
|
|
51
|
+
const [error, setError] = useState<string | null>(null);
|
|
52
|
+
const [loading, setLoading] = useState(false);
|
|
53
|
+
const [history, setHistory] = useState<QueryHistoryItem[]>(initialHistory);
|
|
54
|
+
const [showHistory, setShowHistory] = useState(false);
|
|
55
|
+
const editorRef = useRef<Parameters<OnMount>[0] | null>(null);
|
|
56
|
+
|
|
57
|
+
const runQuery = useCallback(
|
|
58
|
+
async (queryToRun?: string) => {
|
|
59
|
+
const query = queryToRun ?? sql;
|
|
60
|
+
if (!query.trim()) return;
|
|
61
|
+
|
|
62
|
+
setLoading(true);
|
|
63
|
+
setError(null);
|
|
64
|
+
setResult(null);
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(
|
|
68
|
+
`${process.env.NEXT_PUBLIC_API_URL}/orgs/${orgSlug}/projects/${projectSlug}/sql`,
|
|
69
|
+
{
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: { "Content-Type": "application/json" },
|
|
72
|
+
credentials: "include",
|
|
73
|
+
body: JSON.stringify({ sql: query }),
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const data = (await res.json()) as QueryResult | { message: string };
|
|
78
|
+
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
setError((data as { message: string }).message ?? "Query failed");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const queryResult = data as QueryResult;
|
|
85
|
+
setResult(queryResult);
|
|
86
|
+
|
|
87
|
+
setHistory((prev) => [
|
|
88
|
+
{
|
|
89
|
+
id: crypto.randomUUID(),
|
|
90
|
+
projectId: projectSlug,
|
|
91
|
+
sql: query,
|
|
92
|
+
executionTimeMs: queryResult.executionTimeMs,
|
|
93
|
+
rowCount: queryResult.rowCount,
|
|
94
|
+
createdAt: new Date().toISOString(),
|
|
95
|
+
},
|
|
96
|
+
...prev,
|
|
97
|
+
]);
|
|
98
|
+
} catch {
|
|
99
|
+
setError("Failed to connect to the server");
|
|
100
|
+
} finally {
|
|
101
|
+
setLoading(false);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
[sql, orgSlug, projectSlug],
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const handleEditorMount: OnMount = (editorInstance) => {
|
|
108
|
+
editorRef.current = editorInstance;
|
|
109
|
+
|
|
110
|
+
editorInstance.addCommand(2048 | 3, () => void runQuery());
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div className="relative flex h-full min-h-0 w-full min-w-0 overflow-hidden">
|
|
115
|
+
<ResizablePanelGroup
|
|
116
|
+
orientation="vertical"
|
|
117
|
+
className="h-full min-h-0 min-w-0 flex-1"
|
|
118
|
+
>
|
|
119
|
+
<ResizablePanel defaultSize={45} minSize={20} className="min-h-0">
|
|
120
|
+
<div className="flex h-full min-h-0 flex-col">
|
|
121
|
+
<div className="flex shrink-0 items-center justify-between border-b border-border bg-background px-4 py-2">
|
|
122
|
+
<span className="text-sm font-medium">SQL Editor</span>
|
|
123
|
+
<div className="flex items-center gap-2">
|
|
124
|
+
<Button
|
|
125
|
+
variant="ghost"
|
|
126
|
+
size="sm"
|
|
127
|
+
onClick={() => setShowHistory((v) => !v)}
|
|
128
|
+
className="gap-1.5"
|
|
129
|
+
>
|
|
130
|
+
<History size={14} />
|
|
131
|
+
History
|
|
132
|
+
</Button>
|
|
133
|
+
<Button
|
|
134
|
+
size="sm"
|
|
135
|
+
onClick={() => void runQuery()}
|
|
136
|
+
disabled={loading}
|
|
137
|
+
className="gap-1.5"
|
|
138
|
+
>
|
|
139
|
+
<Play size={12} />
|
|
140
|
+
{loading ? "Running..." : "Run"}
|
|
141
|
+
<span className="ml-1 text-xs opacity-60">⌘↵</span>
|
|
142
|
+
</Button>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
<div className="relative min-h-0 flex-1 overflow-hidden">
|
|
147
|
+
<MonacoEditor
|
|
148
|
+
height="100%"
|
|
149
|
+
language="sql"
|
|
150
|
+
value={sql}
|
|
151
|
+
onChange={(v) => setSql(v ?? "")}
|
|
152
|
+
onMount={handleEditorMount}
|
|
153
|
+
theme="vs"
|
|
154
|
+
className="absolute inset-0"
|
|
155
|
+
options={{
|
|
156
|
+
minimap: { enabled: false },
|
|
157
|
+
fontSize: 13,
|
|
158
|
+
fontFamily: "var(--font-mono)",
|
|
159
|
+
lineNumbers: "on",
|
|
160
|
+
scrollBeyondLastLine: false,
|
|
161
|
+
automaticLayout: true,
|
|
162
|
+
padding: { top: 12, bottom: 12 },
|
|
163
|
+
wordWrap: "on",
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
</ResizablePanel>
|
|
169
|
+
|
|
170
|
+
<ResizableHandle />
|
|
171
|
+
|
|
172
|
+
<ResizablePanel defaultSize={55} minSize={20} className="min-h-0">
|
|
173
|
+
<div className="flex h-full min-h-0 min-w-0 flex-col overflow-hidden bg-background">
|
|
174
|
+
{result && (
|
|
175
|
+
<div className="flex shrink-0 items-center gap-3 border-b border-border px-4 py-2 text-xs text-muted-foreground">
|
|
176
|
+
<span>
|
|
177
|
+
{result.command &&
|
|
178
|
+
result.rows.length === 0 &&
|
|
179
|
+
result.command !== "SELECT"
|
|
180
|
+
? `${result.rowCount} ${result.rowCount === 1 ? "row" : "rows"} affected`
|
|
181
|
+
: `${result.rowCount} ${result.rowCount === 1 ? "row" : "rows"}`}
|
|
182
|
+
</span>
|
|
183
|
+
<span>·</span>
|
|
184
|
+
<span className="flex items-center gap-1">
|
|
185
|
+
<Clock size={10} />
|
|
186
|
+
{result.executionTimeMs}ms
|
|
187
|
+
</span>
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
190
|
+
|
|
191
|
+
{error && (
|
|
192
|
+
<div className="shrink-0 border-b border-destructive/20 bg-destructive/10 px-4 py-3">
|
|
193
|
+
<p className="break-all font-mono text-xs text-destructive">
|
|
194
|
+
{error}
|
|
195
|
+
</p>
|
|
196
|
+
</div>
|
|
197
|
+
)}
|
|
198
|
+
|
|
199
|
+
{!result && !error && (
|
|
200
|
+
<div className="flex flex-1 flex-col items-center justify-center text-center">
|
|
201
|
+
<p className="text-sm text-muted-foreground">
|
|
202
|
+
Run a query to see results
|
|
203
|
+
</p>
|
|
204
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
205
|
+
Press{" "}
|
|
206
|
+
<kbd className="rounded border border-border px-1 py-0.5 font-mono text-xs">
|
|
207
|
+
⌘↵
|
|
208
|
+
</kbd>{" "}
|
|
209
|
+
to run
|
|
210
|
+
</p>
|
|
211
|
+
</div>
|
|
212
|
+
)}
|
|
213
|
+
|
|
214
|
+
{result && result.rows.length === 0 && (
|
|
215
|
+
<div className="flex flex-1 items-center justify-center">
|
|
216
|
+
<p className="text-sm text-muted-foreground">
|
|
217
|
+
Query returned 0 rows
|
|
218
|
+
</p>
|
|
219
|
+
</div>
|
|
220
|
+
)}
|
|
221
|
+
|
|
222
|
+
{result && result.rows.length > 0 && (
|
|
223
|
+
<div className="min-h-0 min-w-0 flex-1 overflow-auto">
|
|
224
|
+
<Table className="w-full table-fixed">
|
|
225
|
+
<TableHeader className="sticky top-0 z-10 bg-background">
|
|
226
|
+
<TableRow>
|
|
227
|
+
{result.columns.map((col) => (
|
|
228
|
+
<TableHead
|
|
229
|
+
key={col}
|
|
230
|
+
className="max-w-0 border-r border-border text-xs"
|
|
231
|
+
>
|
|
232
|
+
<span className="block truncate" title={col}>
|
|
233
|
+
{col}
|
|
234
|
+
</span>
|
|
235
|
+
</TableHead>
|
|
236
|
+
))}
|
|
237
|
+
</TableRow>
|
|
238
|
+
</TableHeader>
|
|
239
|
+
<TableBody>
|
|
240
|
+
{result.rows.map((row, i) => (
|
|
241
|
+
<TableRow key={i}>
|
|
242
|
+
{result.columns.map((col) => {
|
|
243
|
+
const value = formatCellValue(row[col]);
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<TableCell
|
|
247
|
+
key={col}
|
|
248
|
+
className="max-w-0 border-r border-border py-1.5 font-mono text-xs align-top"
|
|
249
|
+
title={value}
|
|
250
|
+
>
|
|
251
|
+
{row[col] === null ? (
|
|
252
|
+
<span className="italic text-muted-foreground">
|
|
253
|
+
NULL
|
|
254
|
+
</span>
|
|
255
|
+
) : (
|
|
256
|
+
<span className="block truncate">{value}</span>
|
|
257
|
+
)}
|
|
258
|
+
</TableCell>
|
|
259
|
+
);
|
|
260
|
+
})}
|
|
261
|
+
</TableRow>
|
|
262
|
+
))}
|
|
263
|
+
</TableBody>
|
|
264
|
+
</Table>
|
|
265
|
+
</div>
|
|
266
|
+
)}
|
|
267
|
+
</div>
|
|
268
|
+
</ResizablePanel>
|
|
269
|
+
</ResizablePanelGroup>
|
|
270
|
+
|
|
271
|
+
{showHistory && (
|
|
272
|
+
<div className="absolute inset-y-0 right-0 z-20 flex h-full w-80 flex-col border-l border-border bg-background shadow-lg">
|
|
273
|
+
<div className="flex shrink-0 items-center justify-between border-b border-border px-4 py-3">
|
|
274
|
+
<span className="text-sm font-medium">Query History</span>
|
|
275
|
+
<Button
|
|
276
|
+
variant="ghost"
|
|
277
|
+
size="icon"
|
|
278
|
+
className="h-6 w-6"
|
|
279
|
+
onClick={() => setShowHistory(false)}
|
|
280
|
+
>
|
|
281
|
+
<X size={12} />
|
|
282
|
+
</Button>
|
|
283
|
+
</div>
|
|
284
|
+
<div className="min-h-0 flex-1 overflow-auto">
|
|
285
|
+
{history.length === 0 ? (
|
|
286
|
+
<p className="py-8 text-center text-xs text-muted-foreground">
|
|
287
|
+
No queries yet
|
|
288
|
+
</p>
|
|
289
|
+
) : (
|
|
290
|
+
<div className="divide-y divide-border">
|
|
291
|
+
{history.map((item) => (
|
|
292
|
+
<button
|
|
293
|
+
key={item.id}
|
|
294
|
+
className="w-full px-4 py-3 text-left transition-colors hover:bg-accent"
|
|
295
|
+
onClick={() => {
|
|
296
|
+
setSql(item.sql);
|
|
297
|
+
setShowHistory(false);
|
|
298
|
+
}}
|
|
299
|
+
>
|
|
300
|
+
<p
|
|
301
|
+
className="line-clamp-3 font-mono text-xs text-foreground"
|
|
302
|
+
title={item.sql}
|
|
303
|
+
>
|
|
304
|
+
{item.sql}
|
|
305
|
+
</p>
|
|
306
|
+
<div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs text-muted-foreground">
|
|
307
|
+
<span>{item.rowCount} rows</span>
|
|
308
|
+
<span>·</span>
|
|
309
|
+
<span>{item.executionTimeMs}ms</span>
|
|
310
|
+
<span>·</span>
|
|
311
|
+
<span>
|
|
312
|
+
{new Date(item.createdAt).toLocaleTimeString()}
|
|
313
|
+
</span>
|
|
314
|
+
</div>
|
|
315
|
+
</button>
|
|
316
|
+
))}
|
|
317
|
+
</div>
|
|
318
|
+
)}
|
|
319
|
+
</div>
|
|
320
|
+
</div>
|
|
321
|
+
)}
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { redirect } from "next/navigation";
|
|
2
|
+
import apiClient from "@/lib/axios";
|
|
3
|
+
import { retrieveTokenFromCookie } from "@/server-utils/utils";
|
|
4
|
+
import { COOKIE_KEYS } from "@apiDatabase/constants";
|
|
5
|
+
import type { QueryHistoryItem } from "@apiDatabase/types";
|
|
6
|
+
|
|
7
|
+
export async function retrieveSqlHistoryFromApi(
|
|
8
|
+
orgSlug: string,
|
|
9
|
+
projectSlug: string,
|
|
10
|
+
): Promise<QueryHistoryItem[]> {
|
|
11
|
+
const token = await retrieveTokenFromCookie();
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const { data } = await apiClient.get<QueryHistoryItem[]>(
|
|
15
|
+
`/orgs/${orgSlug}/projects/${projectSlug}/sql/history`,
|
|
16
|
+
{ headers: { Cookie: `${COOKIE_KEYS.ACCESS_TOKEN}=${token}` } },
|
|
17
|
+
);
|
|
18
|
+
return data;
|
|
19
|
+
} catch {
|
|
20
|
+
redirect(`/organizations/${orgSlug}/projects`);
|
|
21
|
+
}
|
|
22
|
+
}
|