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

83 lines (82 loc) 3.72 kB
import { AxioDB } from "../../../Services/Indexation.operation"; import { ResponseBuilder } from "../../helper/responseBuilder.helper"; import { FastifyReply, FastifyRequest } from "fastify"; /** * Controller class for managing databases in AxioDB. * * This class provides methods for retrieving database information, * creating new databases, and other database management operations. * It acts as an interface between the API routes and the AxioDB instance. */ export default class DatabaseController { private AxioDBInstance; constructor(AxioDBInstance: AxioDB); /** * Retrieves a list of databases from the AxioDB instance. * * @returns {Promise<ResponseBuilder>} A Promise that resolves to a ResponseBuilder object * containing the list of databases with an OK status code and a success message. * * @example * const response = await databaseController.getDatabases(); * // Returns a ResponseBuilder with status 200 and database list */ getDatabases(): Promise<ResponseBuilder>; /** * Creates a new database with the specified name. * * @param request - The Fastify request object containing the database name in the body * @returns A ResponseBuilder object containing the status and message of the operation * * @throws Will return a conflict response if database already exists * @throws Will return a bad request response if name is missing, not a string, or empty * @throws Will return an internal server error response if database creation fails */ createDatabase(request: FastifyRequest): Promise<ResponseBuilder>; /** * Deletes a database with the specified name. * * @param request - The Fastify request object containing the database name in the body * @returns A ResponseBuilder object with appropriate status code and message * - 200 OK if the database is successfully deleted * - 404 NOT_FOUND if the database does not exist * - 500 INTERNAL_SERVER_ERROR if an error occurs during deletion * * @example * // Example request body * { * "name": "myDatabase" * } */ deleteDatabase(request: FastifyRequest): Promise<ResponseBuilder>; /** * Exports a database as a compressed tar.gz file and sends it as a downloadable attachment. * * @param request - The Fastify request object containing the query parameter 'dbName' * @param reply - The Fastify reply object used to send the response * @returns A stream of the compressed database file or an error response * * @throws Will return an error response if the export process fails * * @remarks * The method creates a temporary tar.gz file of the specified database directory, * streams it to the client as a downloadable file, and then deletes the temporary * file once the stream is closed. */ exportDatabase(request: FastifyRequest, reply: FastifyReply): Promise<never>; /** * Imports a database from an uploaded zip file. * * This method handles the upload of a database file, saves it temporarily, * unzips it to the AxioDB instance path, and cleans up temporary files. * * @param request - The Fastify request object containing the uploaded file * @param reply - The Fastify reply object for sending responses * @returns A response object indicating success or failure of the import operation * @throws Will handle errors related to file operations and return appropriate HTTP responses */ importDatabase(request: FastifyRequest, reply: FastifyReply): Promise<{ message: string; file: string; }>; }