From b9a0228afaae777fff0a9a83466cfa8688107c3f Mon Sep 17 00:00:00 2001 From: frectonz Date: Thu, 17 Oct 2024 15:14:22 +0300 Subject: [PATCH] feat: add a fetch function for `autocomplete` --- ui/src/api.ts | 11 +++++++++++ ui/src/routes/query.lazy.tsx | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ui/src/api.ts b/ui/src/api.ts index a2bc23f..fafdf58 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -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}/`); @@ -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" }); diff --git a/ui/src/routes/query.lazy.tsx b/ui/src/routes/query.lazy.tsx index 7887eb3..e0fc20e 100644 --- a/ui/src/routes/query.lazy.tsx +++ b/ui/src/routes/query.lazy.tsx @@ -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, @@ -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 ? (