axiodb
Version:
The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor
42 lines (41 loc) • 1.82 kB
TypeScript
export default class Searcher {
private data;
private isUpdated;
private compiledQueries;
constructor(arr: any[], isUpdated?: boolean);
/**
* Pre-compiles query operators for faster matching (regex, $in sets, etc.)
*/
private compileQuery;
/**
* Fast matching using pre-compiled query.
* Note: The item passed here should already be the actual data object to compare against.
* The caller (find method) handles extracting via additionalFiled if needed.
*/
private matchWithCompiled;
/**
* Finds items in the data array that match the given query.
* Uses optimized search strategies based on data size.
* Note: InMemoryCache at the Reader layer already handles query result caching.
*
* @param query - The query object containing conditions to match against items.
* @param additionalFiled - Optional field to extract from each item for matching.
* @param findOne - If true, stops after finding the first match (early exit)
* @param limit - Optional limit for early termination (returns when limit reached)
* @returns {Promise<any[]>} - A promise that resolves to an array of matching items.
*/
find(query: {
[key: string]: any;
}, additionalFiled?: string | number | undefined, findOne?: boolean, limit?: number): Promise<any[]>;
/**
* Matches an item against a query object.
* Supports MongoDB-like operators and logical operators ($or, $and).
*
* @param item - The item to match against the query.
* @param query - The query object containing conditions.
* @returns {boolean} - True if the item matches the query, false otherwise.
*/
static matchesQuery(item: any, query: {
[key: string]: any;
}, isUpdated?: boolean): boolean;
}