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
36 lines (35 loc) • 1.74 kB
TypeScript
import { IndexManager } from "./Index.service";
export default class InsertIndex extends IndexManager {
private indexCache;
constructor(path: string);
/**
* Inserts a document identifier into one or more index files as defined by the global index meta.
*
* OPTIMIZED: Uses in-memory index cache for fast reads and atomic dual-write (memory + disk).
*
* The method:
* 1. Calls `this.findMatchingIndexMeta(document)` to determine which index files should be updated.
* 2. For each matched index entry:
* - Gets current index data from memory cache (or loads from disk if not cached)
* - Appends `${document.documentId}${General.DBMS_File_EXT}` to `indexEntries`
* - Updates both memory cache and disk atomically via indexCache.updateIndex()
*
* @param document - Object representing the document to index. Must contain a `documentId` property (string | number).
* @returns A Promise that resolves to:
* - `true` if the last index file write operation returned a success status,
* - `false` if the global index meta could not be read, no matching index meta entries were found, or the final write returned a falsy status.
*
* @throws Propagates any exceptions thrown by file reads/writes or conversion (e.g., IO or parse/serialize errors).
*
* @remarks
* - Updates both memory cache and disk atomically
* - Thread-safe via index cache locking mechanism
* - Falls back to disk read on cache miss (cold start recovery)
*
* @example
* // document must include documentId:
* // { documentId: "abc123", ... }
* const success = await indexService.InsertToIndex({ documentId: "abc123" });
*/
InsertToIndex(document: any): Promise<boolean>;
}