import { AggregateOptions, ClientSession, CountDocumentsOptions, ExplainVerbosityLike, FindCursor, FindOptions, UpdateFilter, UpdateOptions } from "mongodb"; import { Database } from "../database"; import { Document, Filter, ModelDocument } from "../model/types"; import { CountedEventPayload, CountingEventPayload, CreatedEventPayload, CreatingEventPayload, DeletedEventPayload, DeletingEventPayload, ExplainedEventPayload, ExplainingEventPayload, FetchedEventPayload, FetchingEventPayload, ReplacedEventPayload, ReplacingEventPayload, SavedEventPayload, SavingEventPayload, UpdatedEventPayload, UpdatingEventPayload, UpsertedEventPayload, UpsertingEventPayload } from "./types"; export declare class Query { /** * Connection instance */ protected database: Database; /** * class event name */ eventName: string; /** * Set the database instance */ setDatabase(database: Database): this; /** * Get collection query for the given collection name */ query(collection: string): Collection; /** * Get current active session from database object */ getCurrentSession(): ClientSession; /** * Create a new document in the given collection */ create(collection: string, data: Document, { session }?: { session?: ClientSession; }): Promise>; /** * Create many documents in the given collection */ createMany(collection: string, data: Document[], { session }?: { session?: ClientSession; }): Promise<{ _id: any; }[]>; /** * Update model by the given id */ update(collection: string, filter: Filter, data: Document, { session }?: { session?: ClientSession; }): Promise | null>; /** * Update many documents */ updateMany(collection: string, filter: Filter, updateOptions: UpdateFilter, options?: UpdateOptions, { session }?: { session?: ClientSession; }): Promise; /** * Replace the entire document for the given document id with the given new data */ replace(collection: string, filter: Filter, data: Document, { session }?: { session?: ClientSession; }): Promise | null>; /** * Find and update the document for the given filter with the given data or create a new document/record * if filter has no matching */ upsert(collection: string, filter: Filter, data: Document, { session }?: { session?: ClientSession; }): Promise | null>; /** * Perform a single delete operation for the given collection */ deleteOne(collection: string, filter?: Filter, { session }?: { session?: ClientSession; }): Promise; /** * Delete multiple documents from the given collection */ delete(collection: string, filter?: Filter, { session }?: { session?: ClientSession; }): Promise; /** * Alias to delete */ deleteMany(collection: string, filter?: Filter, { session }?: { session?: ClientSession; }): Promise; /** * Check if document exists for the given collection with the given filter */ exists(collection: string, filter?: Filter, { session }?: { session?: ClientSession; }): Promise; /** * Find a single document for the given collection with the given filter */ first(collection: string, filter?: Filter, findOptions?: FindOptions, { session }?: { session?: ClientSession; }): Promise; /** * Find last document for the given collection with the given filter */ last(collection: string, filter?: Filter, options?: FindOptions, { session }?: { session?: ClientSession; }): Promise; /** * Find multiple document for the given collection with the given filter */ list(collection: string, filter?: Filter, queryHandler?: (query: FindCursor) => void, findOptions?: FindOptions, { session }?: { session?: ClientSession; }): Promise; /** * Find latest documents for the given collection with the given filter */ latest(collection: string, filter?: Filter, findOptions?: FindOptions, { session }?: { session?: ClientSession; }): Promise; /** * Find oldest documents for the given collection with the given filter */ oldest(collection: string, filter?: Filter, findOptions?: FindOptions, { session }?: { session?: ClientSession; }): Promise; /** * Get distinct values for the given collection with the given filter */ distinct(collection: string, field: string, filter?: Filter, { session }?: { session?: ClientSession; }): Promise; /** * Count documents for the given collection with the given filter */ count(collection: string, filter?: Filter, options?: CountDocumentsOptions, { session }?: { session?: ClientSession; }): Promise; /** * Create an explain fetch query */ explain(collection: string, filter?: Filter, findOptions?: FindOptions, verbosity?: ExplainVerbosityLike, { session }?: { session?: ClientSession; }): Promise; /** * Create aggregate query */ aggregate(collection: string, pipeline: Document[], options?: AggregateOptions, { session }?: { session?: ClientSession; }): Promise; /** * Trigger event */ trigger(eventName: string, payload?: Record): Promise; /** * Listen on creating event */ onCreating(callback: (payload: CreatingEventPayload) => void): this; /** * Listen on created event */ onCreated(callback: (payload: CreatedEventPayload) => void): this; /** * Listen on updating event */ onUpdating(callback: (payload: UpdatingEventPayload) => void): this; /** * Listen on updated event */ onUpdated(callback: (payload: UpdatedEventPayload) => void): this; /** * Listen on upserting event */ onUpserting(callback: (payload: UpsertingEventPayload) => void): this; /** * Listen on upserted event */ onUpserted(callback: (payload: UpsertedEventPayload) => void): this; /** * Listen on replacing event */ onReplacing(callback: (payload: ReplacingEventPayload) => void): this; /** * Listen on replaced event */ onReplaced(callback: (payload: ReplacedEventPayload) => void): this; /** * Listen on saving event */ onSaving(callback: (payload: SavingEventPayload) => void): this; /** * Listen on saved event */ onSaved(callback: (payload: SavedEventPayload) => void): this; /** * Listen on fetching event */ onFetching(callback: (payload: FetchingEventPayload) => void): this; /** * Listen on fetched event */ onFetched(callback: (payload: FetchedEventPayload) => void): this; /** * Listen on counting event */ onCounting(callback: (payload: CountingEventPayload) => void): this; /** * Listen on counted event */ onCounted(callback: (payload: CountedEventPayload) => void): this; /** * Listen on explaining event */ onExplaining(callback: (payload: ExplainingEventPayload) => void): this; /** * Listen on explained event */ onExplained(callback: (payload: ExplainedEventPayload) => void): this; /** * Listen on deleting event */ onDeleting(callback: (payload: DeletingEventPayload) => void): this; /** * Listen on deleted event */ onDeleted(callback: (payload: DeletedEventPayload) => void): this; /** * Listen to the given event */ on(event: string, callback: (payload: any) => void): void; } export declare const query: Query; //# sourceMappingURL=query.d.ts.map