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
59 lines (58 loc) • 2.68 kB
TypeScript
import { AxioDB } from "../../../Services/Indexation.operation";
import { ResponseBuilder } from "../../helper/responseBuilder.helper";
import { FastifyRequest } from "fastify";
/**
* Controller class for managing collections in AxioDB.
*
* This class provides methods for creating, retrieving, and managing collections
* within the AxioDB instance. It acts as an interface between the API routes and
* the AxioDB instance.
*/
export default class CollectionController {
private AxioDBInstance;
constructor(AxioDBInstance: AxioDB);
/**
* Creates a new collection in the specified database.
*
* @param request - The Fastify request object containing the collection details in the body
* @returns A ResponseBuilder object containing the status and message of the operation
*
* @throws Will return a conflict response if collection 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 collection creation fails
*/
createCollection(request: FastifyRequest): Promise<ResponseBuilder>;
/**
* Retrieves all collections for a specified database.
*
* @param request - The Fastify request object containing query parameters
* @returns A Promise resolving to a ResponseBuilder object with the response status and data
*
* @remarks
* This method expects a 'databaseName' query parameter in the request.
* It fetches all collections in the specified database and additionally computes
* the file count for each collection path.
*
* @throws Will return a BAD_REQUEST response if databaseName is not provided
* @throws Will return an INTERNAL_SERVER_ERROR response if collection retrieval fails
*/
getCollections(request: FastifyRequest): Promise<ResponseBuilder>;
/**
* Deletes a collection from a specified database.
*
* @param request - The Fastify request object containing the database and collection names in the body.
* @returns A ResponseBuilder object with appropriate status code and message.
*
* @throws Returns a BAD_REQUEST response if the database name or collection name is invalid.
* @throws Returns a NOT_FOUND response if the collection does not exist.
* @throws Returns an INTERNAL_SERVER_ERROR response if the collection deletion fails.
*
* @example
* // Example request body:
* // {
* // "dbName": "myDatabase",
* // "collectionName": "myCollection"
* // }
*/
deleteCollection(request: FastifyRequest): Promise<ResponseBuilder>;
}