UNPKG

axiodb

Version:

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

68 lines (67 loc) 3.04 kB
import { ErrorInterface, SuccessInterface } from "../../config/Interfaces/Helper/response.helper.interface"; import Reader from "../CRUD Operation/Reader.operation"; import DeleteOperation from "../CRUD Operation/Delete.operation"; import UpdateOperation from "../CRUD Operation/Update.operation"; import Aggregation from "../Aggregation/Aggregation.Operation"; import { CryptoHelper } from "../../Helper/Crypto.helper"; /** * Represents a collection inside a database. */ export default class Collection { private readonly name; private readonly path; private readonly updatedAt; private schema; private readonly isEncrypted; private readonly cryptoInstance?; private Converter; private Insertion; private isSchemaNeeded; private readonly encryptionKey; constructor(name: string, path: string, isSchemaNeeded: boolean, schema?: object | any, isEncrypted?: boolean, cryptoInstance?: CryptoHelper, encryptionKey?: string); /** * Get Numbers of Documents in the Collection * @returns {Promise<number>} - A promise that resolves with the number of documents in the collection. * @throws {Error} - Throws an error if the collection is empty or if there is an issue with the query. */ totalDocuments(): Promise<SuccessInterface | ErrorInterface>; /** * Inserts a document into the collection. * @param {object} data - The data to be inserted. * @returns {Promise<any>} - A promise that resolves with the response of the insertion operation. */ insert(data: object | any): Promise<SuccessInterface | ErrorInterface | undefined>; /** * Reads a document from the collection. * @param {object} query - The query to be executed * @returns {Reader} - An instance of the Reader class. */ query(query: object | any): Reader; /** * Initiates an aggregation operation on the collection with the provided pipeline steps. * @param {object[]} PipelineQuerySteps - The pipeline steps to be executed. * @returns {Aggregation} - An instance of the Aggregation class. * @throws {Error} Throws an error if the pipeline steps are empty. * @example * ```typescript * // Aggregate the collection to get the total count of documents * collection.aggregate([{$match: {}}, ${group: {_id: null, count: {$sum: 1}}}]).exec(); * ``` */ aggregate(PipelineQuerySteps: object[]): Aggregation; /** * Initiates a delete operation on the collection with the provided query. * * @param query - The query object that specifies which documents to delete. * @returns A DeleteOperation instance that can be executed to perform the deletion. * @throws {Error} Throws an error if the query is empty. * * @example * ```typescript * // Delete all documents where age is greater than 30 * collection.delete({ age: { $gt: 30 } }); * ``` */ delete(query: object | any): DeleteOperation; update(query: object | any): UpdateOperation; }