Skip to content

Documentation v1.0.0


Documentation / @openassistant/tables / QueryDuckDBComponent

Function: QueryDuckDBComponent()

QueryDuckDBComponent(__namedParameters): Element | null

Defined in: query-table.tsx:168

QueryDuckDBComponent is a component that displays a table of query results from DuckDB. This component is designed to be used with localQuery tool from @openassistant/duckdb.

If you are using localQuery tool with Vercel AI SDK useChat() and streamText() etc., you can use QueryDuckDBComponent to render the results of localQuery tool.

Example with sqlrooms/ai

tsx
import { localQuery, getDuckDB } from '@openassistant/duckdb';
import { QueryDuckDBComponent, QueryDuckDBOutputData } from '@openassistant/tables';
import { createChatStore } from 'sqlrooms/ai';

const SAMPLE_DATASETS = {
  venues: [
    { name: 'Golden Gate Park', city: 'San Francisco', rating: 4.5 },
    { name: "Fisherman's Wharf", city: 'San Francisco', rating: 4.2 },
    { name: 'Alcatraz Island', city: 'San Francisco', rating: 4.7 },
  ],
};

const getValues = async (datasetName: string, variableName: string) => {
  // Get the values of the variable from your dataset
  const dataset = SAMPLE_DATASETS[datasetName as keyof typeof SAMPLE_DATASETS];
  if (!dataset) {
    throw new Error(`Dataset '${datasetName}' not found`);
  }
  return dataset.map((item) => item[variableName as keyof typeof item]);
};

// Create tool with custom context
const localQueryTool = {
  ...localQuery,
  context: { getValues },
  onToolCompleted: (toolCallId: string, additionalData: unknown) => {
    // Handle query completion
  },
  component: (props: QueryDuckDBOutputData) => {
    return (
      <QueryDuckDBComponent
        {...props}
        getDuckDB={getDuckDB}
        getValues={getValues}
      />
    );
  },
};

// Use sqlrooms/ai chat store
const useChatStore = createChatStore({
  ai: {
    getInstructions: () => 'You are a helpful assistant that can answer questions and help with tasks.',
    tools: { localQuery: localQueryTool },
  },
});

Parameters

__namedParameters

QueryDuckDBOutputData & object

Returns

Element | null

Released under the MIT License.