adonis-odm
Version:
A comprehensive MongoDB ODM for AdonisJS with Lucid-style API, type-safe relationships, embedded documents, and transaction support
67 lines • 2.8 kB
TypeScript
import { BaseModel } from '../base_model/base_model.js';
/**
* Utility functions for handling nested documents efficiently
*/
export declare class NestedDocumentHelpers {
/**
* Bulk load referenced documents for multiple models
* This helps avoid N+1 query problems
*/
static bulkLoadReferences<T extends BaseModel, R extends BaseModel>(models: T[], referenceField: string, ReferenceModel: typeof BaseModel & (new (...args: any[]) => R), targetField?: string): Promise<void>;
/**
* Paginate with selective reference loading
* Only load references for the current page, not all data
*/
static paginateWithReferences<T extends BaseModel, R extends BaseModel>(ModelClass: typeof BaseModel & (new (...args: any[]) => T), page: number, perPage: number, referenceField: string, ReferenceModel: typeof BaseModel & (new (...args: any[]) => R), targetField?: string, conditions?: any[]): Promise<any>;
/**
* Create document with nested data
* Handles both embedded and referenced approaches
*/
static createWithNested<T extends BaseModel>(ModelClass: typeof BaseModel & (new (...args: any[]) => T), data: any, nestedConfig?: {
field: string;
isEmbedded: boolean;
NestedModel?: typeof BaseModel;
referenceField?: string;
}): Promise<T>;
/**
* Update document with nested data
*/
static updateWithNested<T extends BaseModel>(model: T, data: any, nestedConfig?: {
field: string;
isEmbedded: boolean;
NestedModel?: typeof BaseModel;
referenceField?: string;
}): Promise<T>;
/**
* Query with nested conditions
* Handles different approaches for embedded vs referenced documents
*/
static queryWithNestedConditions<T extends BaseModel>(ModelClass: typeof BaseModel & (new (...args: any[]) => T), nestedConditions: Array<{
field: string;
operator: string;
value: any;
isEmbedded: boolean;
NestedModel?: typeof BaseModel;
referenceField?: string;
}>, mainConditions?: any[], options?: {
page?: number;
perPage?: number;
orderBy?: {
field: string;
direction: 'asc' | 'desc';
};
}): Promise<any>;
/**
* Aggregate nested document statistics
*/
static aggregateNestedStats<T extends BaseModel>(ModelClass: typeof BaseModel & (new (...args: any[]) => T), nestedField: string, isEmbedded: boolean, NestedModel?: typeof BaseModel): Promise<{
totalWithNested: number;
totalWithoutNested: number;
totalNested?: undefined;
} | {
totalWithNested: any;
totalWithoutNested: number;
totalNested: any;
}>;
}
//# sourceMappingURL=nested_document_helpers.d.ts.map