UNPKG

adonis-odm

Version:

A comprehensive MongoDB ODM for AdonisJS with Lucid-style API, type-safe relationships, embedded documents, and transaction support

244 lines 8.79 kB
import type { BaseModel } from '../base_model/base_model.js'; /** * Extract the instance type from a model class */ type ModelInstance<T extends typeof BaseModel> = InstanceType<T>; /** * Advanced query builder for embedded documents with full type safety * * Supports: * - Complex filtering and searching * - Pagination for large datasets * - Multiple sorting criteria * - Performance optimizations * - Aggregation operations * - All methods from ModelQueryBuilder for consistency */ export declare class EmbeddedQueryBuilder<T extends typeof BaseModel> { private items; private filters; private orFilters; private sortOptions; private limitValue?; private skipValue?; private selectFields?; private searchTerm?; private searchFields?; constructor(items: Array<ModelInstance<T>>); /** * Filter embedded documents by field value with type safety */ where<K extends keyof ModelInstance<T>>(field: K, operator: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in' | '==' | '<>', value: ModelInstance<T>[K]): this; where<K extends keyof ModelInstance<T>>(field: K, value: ModelInstance<T>[K]): this; /** * Alias for where method */ andWhere<K extends keyof ModelInstance<T>>(field: K, operator: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in' | '==' | '<>', value: ModelInstance<T>[K]): this; andWhere<K extends keyof ModelInstance<T>>(field: K, value: ModelInstance<T>[K]): this; /** * Add an OR where condition */ orWhere<K extends keyof ModelInstance<T>>(field: K, operator: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in' | '==' | '<>', value: ModelInstance<T>[K]): this; orWhere<K extends keyof ModelInstance<T>>(field: K, value: ModelInstance<T>[K]): this; /** * Add a where not condition */ whereNot<K extends keyof ModelInstance<T>>(field: K, operator: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in' | '==' | '<>', value: ModelInstance<T>[K]): this; whereNot<K extends keyof ModelInstance<T>>(field: K, value: ModelInstance<T>[K]): this; /** * Alias for whereNot method */ andWhereNot<K extends keyof ModelInstance<T>>(field: K, operator: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in' | any, value?: ModelInstance<T>[K]): this; andWhereNot<K extends keyof ModelInstance<T>>(field: K, value: ModelInstance<T>[K]): this; /** * Add an OR where not condition */ orWhereNot<K extends keyof ModelInstance<T>>(field: K, operator: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in' | any, value?: ModelInstance<T>[K]): this; orWhereNot<K extends keyof ModelInstance<T>>(field: K, value: ModelInstance<T>[K]): this; /** * Add a where like condition (case-sensitive) */ whereLike<K extends keyof ModelInstance<T>>(field: K, value: string): this; /** * Add a where ilike condition (case-insensitive) */ whereILike<K extends keyof ModelInstance<T>>(field: K, value: string): this; /** * Add a where in condition */ whereIn<K extends keyof ModelInstance<T>>(field: K, values: ModelInstance<T>[K][]): this; /** * Add an OR where in condition */ orWhereIn<K extends keyof ModelInstance<T>>(field: K, values: ModelInstance<T>[K][]): this; /** * Add a where not in condition */ whereNotIn<K extends keyof ModelInstance<T>>(field: K, values: ModelInstance<T>[K][]): this; /** * Add an OR where not in condition */ orWhereNotIn<K extends keyof ModelInstance<T>>(field: K, values: ModelInstance<T>[K][]): this; /** * Add a where between condition */ whereBetween<K extends keyof ModelInstance<T>>(field: K, range: [ModelInstance<T>[K], ModelInstance<T>[K]]): this; /** * Add an OR where between condition */ orWhereBetween<K extends keyof ModelInstance<T>>(field: K, range: [ModelInstance<T>[K], ModelInstance<T>[K]]): this; /** * Add a where not between condition */ whereNotBetween<K extends keyof ModelInstance<T>>(field: K, range: [ModelInstance<T>[K], ModelInstance<T>[K]]): this; /** * Add an OR where not between condition */ orWhereNotBetween<K extends keyof ModelInstance<T>>(field: K, range: [ModelInstance<T>[K], ModelInstance<T>[K]]): this; /** * Filter embedded documents where field is not null */ whereNotNull<K extends keyof ModelInstance<T>>(field: K): this; /** * Add an OR where not null condition */ orWhereNotNull<K extends keyof ModelInstance<T>>(field: K): this; /** * Filter embedded documents where field is null */ whereNull<K extends keyof ModelInstance<T>>(field: K): this; /** * Add an OR where null condition */ orWhereNull<K extends keyof ModelInstance<T>>(field: K): this; /** * Add a where exists condition */ whereExists<K extends keyof ModelInstance<T>>(field: K): this; /** * Add an OR where exists condition */ orWhereExists<K extends keyof ModelInstance<T>>(field: K): this; /** * Add a where not exists condition */ whereNotExists<K extends keyof ModelInstance<T>>(field: K): this; /** * Add an OR where not exists condition */ orWhereNotExists<K extends keyof ModelInstance<T>>(field: K): this; /** * Sort embedded documents with type safety */ orderBy<K extends keyof ModelInstance<T>>(field: K, direction?: 'asc' | 'desc'): this; /** * Limit the number of results */ limit(count: number): this; /** * Skip a number of results */ skip(count: number): this; /** * Alias for skip - for pagination compatibility */ offset(count: number): this; /** * Set pagination using page and perPage */ forPage(page: number, perPage: number): this; /** * Select specific fields to return (for performance with large objects) */ select(...fields: Array<keyof ModelInstance<T>>): this; /** * Search across multiple fields with a single term */ search(term: string, fields?: Array<keyof ModelInstance<T>>): this; /** * Add multiple where conditions with AND logic */ whereAll(conditions: Array<{ field: keyof ModelInstance<T>; operator: '=' | '==' | '!=' | '<>' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in'; value: any; }>): this; /** * Add multiple where conditions with OR logic */ whereAny(conditions: Array<{ field: keyof ModelInstance<T>; operator: '=' | '==' | '!=' | '<>' | '>' | '>=' | '<' | '<=' | 'like' | 'in' | 'not in'; value: any; }>): this; /** * Filter by date range */ whereDateBetween<K extends keyof ModelInstance<T>>(field: K, startDate: Date | string, endDate: Date | string): this; /** * Filter by array contains */ whereArrayContains<K extends keyof ModelInstance<T>>(field: K, value: any): this; /** * Filter by regex pattern */ whereRegex<K extends keyof ModelInstance<T>>(field: K, pattern: RegExp | string, flags?: string): this; /** * Execute the query and return filtered results */ get(): Array<ModelInstance<T>>; /** * Get the first result */ first(): ModelInstance<T> | null; /** * Get the count of results */ count(): number; /** * Check if any results exist */ exists(): boolean; /** * Get paginated results with metadata */ paginate(page: number, perPage: number): { data: Array<ModelInstance<T>>; pagination: { currentPage: number; perPage: number; total: number; totalPages: number; hasNextPage: boolean; hasPrevPage: boolean; }; }; /** * Get distinct values for a field */ distinct<K extends keyof ModelInstance<T>>(field: K): Array<ModelInstance<T>[K]>; /** * Group results by a field value */ groupBy<K extends keyof ModelInstance<T>>(field: K): Map<ModelInstance<T>[K], Array<ModelInstance<T>>>; /** * Get aggregated statistics for numeric fields */ aggregate<K extends keyof ModelInstance<T>>(field: K): { count: number; sum: number; avg: number; min: number; max: number; } | null; /** * Execute a custom callback on the results */ tap(callback: (results: Array<ModelInstance<T>>) => void): this; /** * Clone the query builder for reuse */ clone(): EmbeddedQueryBuilder<T>; } export {}; //# sourceMappingURL=embedded_query_builder.d.ts.map