Skip to content

Commit

Permalink
remove sql editor
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis committed Aug 8, 2024
1 parent 9056681 commit 9c8b15b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 61 deletions.
12 changes: 2 additions & 10 deletions packages/explorer/src/app/(home)/DataExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"use client";

import { useSearchParams } from "next/navigation";
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { SQLEditor } from "./SQLEditor";
import { TableSelector } from "./TableSelector";
import { TablesViewer } from "./TablesViewer";

export function DataExplorer() {
const searchParams = useSearchParams();
const [query, setQuery] = useState<string | undefined>();
const { data: tables, isLoading: tablesLoading } = useQuery({
const { data: tables } = useQuery({
queryKey: ["tables"],
queryFn: async () => {
const response = await fetch("/api/tables");
Expand All @@ -25,12 +22,7 @@ export function DataExplorer() {
return (
<>
<TableSelector value={selectedTable} options={tables} />
<SQLEditor
table={selectedTable}
tablesLoading={tablesLoading}
setQuery={setQuery}
/>
<TablesViewer table={selectedTable} query={query} />
<TablesViewer table={selectedTable} />
</>
);
}
44 changes: 0 additions & 44 deletions packages/explorer/src/app/(home)/SQLEditor.tsx

This file was deleted.

9 changes: 4 additions & 5 deletions packages/explorer/src/app/(home)/TablesViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ import { bufferToBigInt } from "./utils/bufferToBigInt";

type Props = {
table: string | undefined;
query: string | undefined;
};

export function TablesViewer({ table: selectedTable, query }: Props) {
export function TablesViewer({ table: selectedTable }: Props) {
const [sorting, setSorting] = useState<SortingState>([]);
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
Expand Down Expand Up @@ -66,9 +65,9 @@ export function TablesViewer({ table: selectedTable, query }: Props) {
});

const { data: rows } = useQuery({
queryKey: ["rows", { query }],
queryKey: ["rows", { table: selectedTable }],
queryFn: async () => {
const response = await fetch(`/api/rows?query=${query}`);
const response = await fetch(`/api/rows?table=${selectedTable}`);
return response.json();
},
select: (data) => {
Expand All @@ -83,7 +82,7 @@ export function TablesViewer({ table: selectedTable, query }: Props) {
);
});
},
enabled: Boolean(selectedTable) && Boolean(query),
enabled: Boolean(selectedTable),
refetchInterval: 1000,
});

Expand Down
6 changes: 4 additions & 2 deletions packages/explorer/src/app/api/rows/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ function convertKeysToCamelCase(rows: RowsResponse): Row[] {
export async function GET(request: Request) {
const db = getDatabase();
const { searchParams } = new URL(request.url);
const query = searchParams.get("query");
const rows = db?.prepare(query || "").all() as RowsResponse;
const table = searchParams.get("table");
const rows = db
?.prepare(`SELECT * FROM '${table}' LIMIT 30`)
.all() as RowsResponse;

return Response.json({ rows: convertKeysToCamelCase(rows) });
}

0 comments on commit 9c8b15b

Please sign in to comment.