drizzle-cube
Version:
Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.
68 lines (67 loc) • 2.02 kB
TypeScript
import { CubeQuery, CubeResultSet } from '../../types';
/**
* Create a stable query key from a CubeQuery
* The key includes all query parameters to ensure proper caching
*/
export declare function createQueryKey(query: CubeQuery | null): readonly unknown[];
export interface UseCubeLoadQueryOptions {
/**
* Whether to skip the query
* @default false
*/
skip?: boolean;
/**
* Debounce delay in milliseconds
* @default 300
*/
debounceMs?: number;
/**
* Whether to reset result set when query changes
* @default true
*/
resetResultSetOnChange?: boolean;
/**
* Stale time in milliseconds
* @default 60 * 1000 (1 minute)
*/
staleTime?: number;
/**
* Whether to keep previous data while loading new data
* @default true
*/
keepPreviousData?: boolean;
}
export interface UseCubeLoadQueryResult {
/** The result set from the query */
resultSet: CubeResultSet | null;
/** Raw data from the result set */
rawData: unknown[] | null;
/** Whether the query is loading (initial load) */
isLoading: boolean;
/** Whether the query is fetching (includes refetch) */
isFetching: boolean;
/** Whether query is debouncing (waiting for user to stop typing) */
isDebouncing: boolean;
/** Error if the query failed */
error: Error | null;
/** The debounced query that was executed */
debouncedQuery: CubeQuery | null;
/** Whether the current query is valid */
isValidQuery: boolean;
/** Manually refetch the data */
refetch: () => void;
/** Clear the query cache */
clearCache: () => void;
}
/**
* TanStack Query hook for loading cube data with debouncing
*
* Usage:
* ```tsx
* const { resultSet, rawData, isLoading, error } = useCubeLoadQuery(query, {
* debounceMs: 300,
* skip: !isReady
* })
* ```
*/
export declare function useCubeLoadQuery(query: CubeQuery | null, options?: UseCubeLoadQueryOptions): UseCubeLoadQueryResult;