Skip to content

Commit

Permalink
feat: add a fetch function for autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Oct 17, 2024
1 parent bab013d commit b9a0228
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ const metadata = z.object({
can_shutdown: z.boolean(),
});

const autocomplete = z.object({
tables: z
.object({
columns: z.string().array(),
table_name: z.string(),
})
.array(),
});

const $fetch = createZodFetcher();

export const fetchOverview = () => $fetch(overview, `${BASE_URL}/`);
Expand All @@ -86,6 +95,8 @@ export const fetchQuery = (value: string) =>
body: JSON.stringify({ query: value }),
});
export const fetchMetadata = () => $fetch(metadata, `${BASE_URL}/metadata`);
export const fetchAutocomplete = () =>
$fetch(autocomplete, `${BASE_URL}/autocomplete`);

export const sendShutdown = () =>
fetch(`${BASE_URL}/shutdown`, { method: "POST" });
9 changes: 8 additions & 1 deletion ui/src/routes/query.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { createFileRoute } from "@tanstack/react-router";

import { cn } from "@/lib/utils";
import { fetchQuery } from "@/api";
import { fetchAutocomplete, fetchQuery } from "@/api";
import {
useQueries,
QueriesProvider,
Expand Down Expand Up @@ -177,6 +177,13 @@ function Query({ sql, onChange, onSave, onDelete, onUpdate }: QueryProps) {
retry: false,
});

const { data: autocompleteData } = useQuery({
queryKey: ["autocomplete"],
queryFn: () => fetchAutocomplete(),
});

console.log(autocompleteData);

const grid = !data ? (
!autoExecute && code && error ? (
<Card>
Expand Down

0 comments on commit b9a0228

Please sign in to comment.