UNPKG

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

90 lines (89 loc) 3.98 kB
import Database from "./Database/database.operation"; import { ErrorInterface, SuccessInterface } from "../config/Interfaces/Helper/response.helper.interface"; import { AxioDBOptions } from "../config/Interfaces/Operation/Indexation.operation.interface"; /** * Class representing the AxioDB database. * @param {AxioDBOptions} options - Configuration options for AxioDB * @param {boolean} options.GUI - Enable/disable HTTP GUI server (port 27018). Defaults to false. * @param {string} options.RootName - Custom name for the database root folder. Defaults to "AxioDB". * @param {string} options.CustomPath - Custom path for database storage. Defaults to current directory. * @param {boolean} options.TCP - Enable/disable TCP server (port 27019). Defaults to false. * @returns {AxioDB} - Returns the instance of AxioDB. * @example * const db = new AxioDB({ GUI: true, RootName: "MyDB", CustomPath: "./data" }); */ export declare class AxioDB { private readonly RootName; private currentPATH; private fileManager; private folderManager; private Converter; private ResponseHelper; private static _instance; private DatabaseMap; private GUI; private TCP; constructor(options?: AxioDBOptions); /** * Initializes the root directory for the AxioDB. * * This method sets the `currentPATH` to include the `RootName` and checks if the AxioDB folder exists. * If the folder does not exist, it attempts to create it. If the creation fails, an error is thrown. * * @throws {Error} If the AxioDB folder cannot be created. * @returns {Promise<void>} A promise that resolves when the initialization is complete. */ private initializeRoot; /** * Gets the current path of the indexation operation. * @returns {string} The current path. */ get GetPath(): string; /** * Creates a new database folder and updates the metadata file. * @param DBName - The name of the database to create. * @returns The newly created database object. */ createDB(DBName: string): Promise<Database>; /** * Retrieves information about the databases in the current directory. * * This method performs the following operations: * 1. Lists all directories (databases) in the current path. * 2. Calculates the total size of the current directory. * 3. Checks if the data from both operations is returned. * 4. Logs the number of databases. * 5. Constructs an object containing the total size, total number of databases, and the list of databases. * 6. Sends a success response with the constructed object. * * @returns {Promise<SuccessInterface | undefined>} A promise that resolves when the database information is successfully retrieved and the response is sent. */ getInstanceInfo(): Promise<SuccessInterface | undefined>; /** * Checks if a database with the given name exists * * @param DBName - The name of the database to check for existence * @returns A Promise that resolves to a boolean indicating whether the database exists * * @example * ```typescript * const exists = await indexation.isDatabaseExists('myDatabase'); * if (exists) { * console.log('Database exists'); * } * ``` */ isDatabaseExists(DBName: string): Promise<boolean>; /** * Deletes a database from the current directory. * * This method performs the following operations: * 1. Checks if the database exists. * 2. Deletes the database if it exists. * 3. Sends a success response if the database is deleted. * * @param {string} DBName - The name of the database to delete. * @returns {Promise<SuccessInterface>} A promise that resolves when the database is successfully deleted and the response is sent. */ deleteDatabase(DBName: string): Promise<SuccessInterface | ErrorInterface | undefined>; }