UNPKG

axiodb

Version:

A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern application. Supports schemas, encryption, and advanced query capabilities.

91 lines (90 loc) 3.63 kB
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface"; /** * Class representing a read operation. */ export default class Reader { private readonly collectionName; private readonly path; private readonly Converter; private readonly baseQuery; private limit; private skip; private sort; private isEncrypted; private encryptionKey; private cryptoInstance?; private totalCount; private FindOneStatus; private project; private readonly ResponseHelper; private AllData; /** * Creates an instance of Read. * @param {string} collectionName - The name of the collection. * @param {string} path - The data to be read. * @param {object} baseQuery - The base query to be used. * @param {boolean} isEncrypted - The encryption status. * @param {string} encryptionKey - The encryption key. */ constructor(collectionName: string, path: string, baseQuery: object | any, isEncrypted?: boolean, encryptionKey?: string); /** * Reads the data from a file. * @returns {Promise<any>} A promise that resolves with the response of the read operation. */ exec(): Promise<SuccessInterface | ErrorInterface>; /** * set limit to the query * @param {number} limit - The limit to be set. * @returns {Reader} - An instance of the Reader class. */ Limit(limit: number): Reader; /** * to be skipped to the query * @param {number} skip - The skip to be set. * @returns {Reader} - An instance of the Reader class. */ Skip(skip: number): Reader; /** * to be sorted to the query * @param {object} sort - The sort to be set. * @returns {Reader} - An instance of the Reader class. */ Sort(sort: object | any): Reader; /** * Sets whether to include the total count of matching documents in the result. * * @param count - Boolean flag indicating whether to include the total count * @returns The Reader instance for method chaining */ setCount(count: boolean): Reader; findOne(status?: boolean): Reader; setProject(project: object | any): Reader; /** * 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; /** * Applies skip and limit to the provided data array. * * This method checks if both `limit` and `skip` are defined. If they are, * it slices the `FinalData` array according to the `skip` and `limit` values * and returns the sliced data. If either `limit` or `skip` is not defined, * it returns the original `FinalData` array. * * @param {any[]} FinalData - The array of data to apply skip and limit to. * @returns {Promise<SuccessInterface | ErrorInterface>} - A promise that resolves to a success interface containing the sliced data or the original data. */ private ApplySkipAndLimit; private ApplyProjection; }