import { ReactiveMap } from '@solid-primitives/map'; import { Accessor } from 'solid-js'; import { Collection, CollectionStatus, Context, GetResult, InferResultType, InitialQueryBuilder, LiveQueryCollectionConfig, NonSingleResult, QueryBuilder, SingleResult } from '@tanstack/db'; /** * Create a live query using a query function * @param queryFn - Query function that defines what data to fetch * @returns Accessor that returns data with Suspense support, with state and status information as properties * @example * // Basic query with object syntax * const todosQuery = useLiveQuery((q) => * q.from({ todos: todosCollection }) * .where(({ todos }) => eq(todos.completed, false)) * .select(({ todos }) => ({ id: todos.id, text: todos.text })) * ) * * @example * // With dependencies that trigger re-execution * const todosQuery = useLiveQuery( * (q) => q.from({ todos: todosCollection }) * .where(({ todos }) => gt(todos.priority, minPriority())), * ) * * @example * // Join pattern * const personIssues = useLiveQuery((q) => * q.from({ issues: issueCollection }) * .join({ persons: personCollection }, ({ issues, persons }) => * eq(issues.userId, persons.id) * ) * .select(({ issues, persons }) => ({ * id: issues.id, * title: issues.title, * userName: persons.name * })) * ) * * @example * // Handle loading and error states * const todosQuery = useLiveQuery((q) => * q.from({ todos: todoCollection }) * ) * * return ( * * * Loading... * * * Error: {todosQuery.status} * * * * {(todo) => {todo.text}} * * * * ) * * @example * // Use Suspense boundaries * const todosQuery = useLiveQuery((q) => * q.from({ todos: todoCollection }) * ) * * return ( * Loading...}> * * {(todo) => {todo.text}} * * * ) */ export declare function useLiveQuery(queryFn: (q: InitialQueryBuilder) => QueryBuilder): Accessor> & { /** * @deprecated use function result instead * query.data -> query() */ data: InferResultType; state: ReactiveMap>; collection: Collection, string | number, {}>; status: CollectionStatus; isLoading: boolean; isReady: boolean; isIdle: boolean; isError: boolean; isCleanedUp: boolean; }; export declare function useLiveQuery(queryFn: (q: InitialQueryBuilder) => QueryBuilder | undefined | null): Accessor> & { /** * @deprecated use function result instead * query.data -> query() */ data: InferResultType; state: ReactiveMap>; collection: Collection, string | number, {}> | null; status: CollectionStatus | `disabled`; isLoading: boolean; isReady: boolean; isIdle: boolean; isError: boolean; isCleanedUp: boolean; }; /** * Create a live query using configuration object * @param config - Configuration object with query and options * @returns Accessor that returns data with Suspense support, with state and status information as properties * @example * // Basic config object usage * const todosQuery = useLiveQuery(() => ({ * query: (q) => q.from({ todos: todosCollection }), * gcTime: 60000 * })) * * @example * // With query builder and options * const queryBuilder = new Query() * .from({ persons: collection }) * .where(({ persons }) => gt(persons.age, 30)) * .select(({ persons }) => ({ id: persons.id, name: persons.name })) * * const personsQuery = useLiveQuery(() => ({ query: queryBuilder })) * * @example * // Handle all states uniformly * const itemsQuery = useLiveQuery(() => ({ * query: (q) => q.from({ items: itemCollection }) * })) * * return ( * {itemsQuery().length} items loaded}> * * Loading... * * * Something went wrong * * * Preparing... * * * ) */ export declare function useLiveQuery(config: Accessor>): Accessor> & { /** * @deprecated use function result instead * query.data -> query() */ data: InferResultType; state: ReactiveMap>; collection: Collection, string | number, {}>; status: CollectionStatus; isLoading: boolean; isReady: boolean; isIdle: boolean; isError: boolean; isCleanedUp: boolean; }; /** * Subscribe to an existing live query collection * @param liveQueryCollection - Pre-created live query collection to subscribe to * @returns Accessor that returns data with Suspense support, with state and status information as properties * @example * // Using pre-created live query collection * const myLiveQuery = createLiveQueryCollection((q) => * q.from({ todos: todosCollection }).where(({ todos }) => eq(todos.active, true)) * ) * const todosQuery = useLiveQuery(() => myLiveQuery) * * @example * // Access collection methods directly * const existingQuery = useLiveQuery(() => existingCollection) * * // Use collection for mutations * const handleToggle = (id) => { * existingQuery.collection.update(id, draft => { draft.completed = !draft.completed }) * } * * @example * // Handle states consistently * const sharedQuery = useLiveQuery(() => sharedCollection) * * return ( * {(item) => }}> * * Loading... * * * Error loading data * * * ) */ export declare function useLiveQuery>(liveQueryCollection: Accessor & NonSingleResult>): Accessor> & { /** * @deprecated use function result instead * query.data -> query() */ data: Array; state: ReactiveMap; collection: Collection; status: CollectionStatus; isLoading: boolean; isReady: boolean; isIdle: boolean; isError: boolean; isCleanedUp: boolean; }; export declare function useLiveQuery>(liveQueryCollection: Accessor & SingleResult>): Accessor & { /** * @deprecated use function result instead * query.data -> query() */ data: TResult | undefined; state: ReactiveMap; collection: Collection & SingleResult; status: CollectionStatus; isLoading: boolean; isReady: boolean; isIdle: boolean; isError: boolean; isCleanedUp: boolean; };