axiodb
Version:
A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern application. Supports schemas, encryption, and advanced query capabilities.
58 lines (57 loc) • 2.64 kB
TypeScript
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface";
/**
* Class that performs aggregation operations on data.
*
* This class allows for MongoDB-like aggregation pipeline operations on collection data.
* It supports various stages including $match, $group, $sort, $project, $limit, $skip,
* $unwind, and $addFields.
*
* The class can handle both encrypted and non-encrypted data collections.
*/
export default class Aggregation {
private AllData;
private readonly Pipeline;
private path;
private readonly collectionName;
private readonly ResponseHelper;
private isEncrypted;
private encryptionKey?;
private cryptoInstance?;
private readonly Converter;
constructor(collectionName: string, path: string, Pipeline: object[] | any, isEncrypted?: boolean, encryptionKey?: string);
/**
* Executes the aggregation pipeline on the data.
*
* This method processes the aggregation pipeline stages in sequence:
* - $match: Filters documents based on specified conditions
* - $group: Groups documents by specified fields and applies aggregation operations
* - $sort: Sorts documents based on specified fields and order
* - $project: Reshapes documents by including specified fields
* - $limit: Limits the number of documents in the result
* - $skip: Skips a specified number of documents
* - $unwind: Deconstructs an array field from input documents
* - $addFields: Adds new fields to documents
*
* The method first validates if the pipeline is an array, loads all buffer data,
* and then processes each stage of the pipeline sequentially.
*
* @throws {Error} If the pipeline is not an array
* @returns {Array<any>} The result of the aggregation pipeline
*/
exec(): Promise<SuccessInterface | ErrorInterface>;
/**
* Loads all buffer raw data from the specified directory.
*
* This method performs the following steps:
* 1. Checks if the directory is locked.
* 2. If the directory is not locked, it lists all files in the directory.
* 3. Reads each file and decrypts the data if encryption is enabled.
* 4. Stores the decrypted data in the `AllData` array.
* 5. If the directory is locked, it unlocks the directory, reads the files, and then locks the directory again.
*
* @returns {Promise<SuccessInterface | ErrorInterface>} A promise that resolves to a success or error response.
*
* @throws {Error} Throws an error if any operation fails.
*/
private LoadAllBufferRawData;
}