@bodil/bdb
    Preparing search index...

    Interface IndexConstructor<Document>

    Constructor functions for creating an index.

    interface IndexConstructor<Document extends object> {
        array: <I extends string, L extends unknown[]>(
            key: I,
        ) => ArrayIndex<Document, I, L>;
        custom: <T, I extends string>(
            key: I,
            orderFn: OrderFn<T>,
        ) => CustomIndex<Document, T, I>;
        key: <I extends string>(key: I) => PrimitiveIndex<Document, I>;
        keys: <I extends string, J extends string>(
            leftKey: I,
            rightKey: J,
        ) => CompoundIndex<Document, I, J>;
        time: <I extends string>(key: I) => CustomIndex<Document, Instant, I>;
    }

    Type Parameters

    • Document extends object

    Properties

    array: <I extends string, L extends unknown[]>(
        key: I,
    ) => ArrayIndex<Document, I, L>

    Create an array index for a property on a document.

    This index works on a property with an array of IndexablePrimitives. It will match documents where the lookup value is a member of the array.

    type Document = { id: string; flags: Array<string> };
    const arrayIndex = index<Document>().array("flags");
    custom: <T, I extends string>(
        key: I,
        orderFn: OrderFn<T>,
    ) => CustomIndex<Document, T, I>

    Create an index with a custom ordering function for a property on a document.

    This works like IndexConstructor.key, except that it takes any value rather than just a primitive, as long as you provide an ordering function for it.

    key: <I extends string>(key: I) => PrimitiveIndex<Document, I>

    Create an index for a single property on a document.

    The type of the property needs to match IndexablePrimitive, ie. it needs to be a string, a number or a bigint. If you need an index for a different value type, use IndexConstructor.custom.

    type Document = { id: string; value: number };
    const index = index<Document>().key("id");
    keys: <I extends string, J extends string>(
        leftKey: I,
        rightKey: J,
    ) => CompoundIndex<Document, I, J>

    Create a compound index for a pair of properties on a document.

    The types of the properties need to match IndexablePrimitive, ie. they need to be strings, numbers or bigints.

    This index matches documents where both properties match the provided pair of values. Partial matches do not count.

    Whemn a compound index is used as a primary index, the unique key is the value pair, not either of the individual values, so you can have multiple documents with either one of the properties having identical values, but only one document matching any one given value pair.

    type Document = { id: string; value: number };
    const compoundIndex = index<Document>().keys("id", "value");
    time: <I extends string>(key: I) => CustomIndex<Document, Instant, I>

    Create an index for a Temporal.Instant property on a document.

    This works exactly like IndexConstructor.key, except that it takes a Temporal.Instant instead of a primitive value.