/* * MIT License * * Copyright (c) 2018-2020 Ardalan Amini * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import * as mongodb from "mongodb"; import * as Odin from ".."; import DB, { Operator, JoinQuery, Callback, Iterator, Id } from "../DB"; import Filter from "../DB/Filter"; import Relation from "../Relation/Base"; declare namespace Query { interface Rel { relation: Relation; relations: Relation.Relation[]; } } declare class Query = any> extends DB { protected readonly _model: typeof Odin; protected readonly _relations: Query.Rel[]; protected _withTrashed: boolean; protected _lean: boolean; constructor(model: typeof Odin, relations?: Query.Rel[]); protected _apply_options(withRelations?: boolean): this; /******************************* With Trashed *******************************/ withTrashed(): this; /*********************************** Lean ***********************************/ lean(): this; /****************************** Has & WhereHas ******************************/ has(relation: string, count?: number): this; has(relation: string, operator: Operator, count?: number): this; whereHas(relation: string, filter: (q: Filter) => Filter, count?: number): this; whereHas(relation: string, filter: (q: Filter) => Filter, operator: Operator, count?: number): this; /*********************************** Joins **********************************/ join(collection: string | typeof Odin, query?: JoinQuery, as?: string): this; /*********************************** Read ***********************************/ exists(): Promise; exists(callback: Callback): void; count(): Promise; count(callback: Callback): void; iterate(): Iterator; get(): Promise; get(callback: Callback): void; first(): Promise; first(callback: Callback): void; value(field: string): Promise; value(field: string, callback: Callback): void; pluck(field: string): Promise; pluck(field: string, callback: Callback): void; max(field: string): Promise; max(field: string, callback: Callback): void; min(field: string): Promise; min(field: string, callback: Callback): void; avg(field: string): Promise; avg(field: string, callback: Callback): void; /********************************** Inserts *********************************/ insert(items: T[]): Promise; insert(items: T[], callback: Callback): void; insertGetId(item: T): Promise; insertGetId(item: T, callback: Callback): void; /********************************** Updates *********************************/ protected _update(update: { [key: string]: any; }, callback?: Callback, soft?: { type: "delete" | "restore"; field: string; value?: Date; }): Promise; update(update: Partial): Promise; update(update: Partial, callback: Callback): void; increment(field: string, count?: number): Promise; increment(field: string, callback: Callback): void; increment(field: string, count: number, callback: Callback): void; decrement(field: string, count?: number): Promise; decrement(field: string, callback: Callback): void; decrement(field: string, count: number, callback: Callback): void; unset(fields: string[]): Promise; unset(fields: string[], callback: Callback): void; /********************************** Deletes *********************************/ delete(force?: boolean): Promise; delete(callback: Callback): void; delete(force: boolean, callback: Callback): void; /********************************* Restoring ********************************/ restore(): Promise; restore(callback: Callback): void; } export default Query;