docudb
Version:
Document-based NoSQL database for NodeJS
107 lines • 3.54 kB
TypeScript
/**
* Query Module (MQL - DocuDB Query Language)
* Implements a simple and powerful query language for filtering documents
*/
import { QueryCriteria, SortOptions, SelectFields, DocumentStructure, Query as QueryInterface, Document } from '../types/index.js';
declare class Query implements QueryInterface {
/** Query criteria */
criteria: QueryCriteria;
/** Sort options */
sortOptions: SortOptions | null;
/** Limit value */
limitValue: number | null;
/** Skip value */
skipValue: number;
/** Fields to select */
selectFields: SelectFields | null;
/**
* Creates a new query for filtering documents
* @param criteria - Search criteria using MongoDB-like query syntax
*/
constructor(criteria?: QueryCriteria);
/**
* Evaluates if a document matches the query criteria
* @param doc - Document to evaluate
* @returns true if the document matches the criteria
*/
matches(doc: DocumentStructure): boolean;
/**
* Sorts results by specified fields
* @param sortBy - Fields and sort direction (1 ascending, -1 descending)
* @returns Current instance for chaining
*/
sort(sortBy: SortOptions): Query;
/**
* Limits the number of results
* @param n - Maximum number of results
* @returns Current instance for chaining
*/
limit(n: number): Query;
/**
* Skips a number of results
* @param n - Number of results to skip
* @returns Current instance for chaining
*/
skip(n: number): Query;
/**
* Selects specific fields to include in the results
* @param fields - Fields to include
* @returns Current instance for chaining
*/
select(fields: SelectFields): Query;
/**
* Applies the query to a collection of documents
* @param documents - Documents to filter
* @returns Documents that match the criteria
*/
execute(documents: DocumentStructure[]): Document[];
/**
* Recursively evaluates query criteria
* @param {Object} doc - Document to evaluate
* @param {QueryCriteria} criteria - Query criteria
* @returns {boolean} - true if the document matches the criteria
* @private
*/
private _evaluateCriteria;
/**
* Evaluates a specific operator
* @param {string} operator - Operator to evaluate
* @param {*} docValue - Document value
* @param {*} criteriaValue - Criteria value
* @returns {boolean} - true if the operator condition is met
* @private
*/
private _evaluateOperator;
/**
* Compares two values to determine if they are equal
* @param {*} a - First value
* @param {*} b - Second value
* @returns {boolean} - true if values are equal
* @private
*/
private _equals;
/**
* Gets a nested value from an object using dot notation
* @param {Object} obj - Object to get value from
* @param {string} path - Path to value using dot notation
* @returns {*} - Found value or undefined
* @private
*/
private _getNestedValue;
/**
* Applies sorting to results
* @param {Array} results - Results to sort
* @returns {Array} - Sorted results
* @private
*/
private _applySorting;
/**
* Applies field projection to results
* @param {Array} results - Results to project
* @returns {Array} - Results with projection applied
* @private
*/
private _applyProjection;
}
export default Query;
//# sourceMappingURL=query.d.ts.map