Function createComplexQueryEngine

  • This function creates a new function which can be used to implement a Store.query method by evaluating and filtering data available in an iterable, e.g. array.

    Type Parameters

    • T extends Readonly<Record<string, any>>

    Parameters

    Returns ((items: ResultItems<T>) => ResultItems<T>)

    A function which filters, sorts and paginates the given query result.

    import { createComplexQueryEngine } from "store-api/utils";
    import { AsyncStore, ComplexQueryExpression, QueryOptions } from "./api";

    type MyItemType = Record<string, any>;

    class MyStore implements AsyncStore<MyItemType> {
    items: MyItemType[] = [{ a: 1 }, { b: 2 }];
    async query(complexQuery?: ComplexQueryExpression, options?: QueryOptions) {
    // filter, sort, paginate the items array
    return createComplexQueryEngine(complexQuery, options)(this.items);
    }
    }