/* * 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 { FilterQuery, Operator } from "."; export interface Filters { $and?: Array>; $or?: Array>; [operator: string]: any; } export default class Filter = any> { protected _filter: Filters; protected get _filters(): { [x: string]: any; $and?: mongodb.FilterQuery[] | undefined; $or?: mongodb.FilterQuery[] | undefined; }; /********************************** Helpers *********************************/ protected _push_filter(operator: "and" | "or", value: any): this; protected _where(field: string, operator: string, value: any): this; protected _or_where(field: string, operator: string, value: any): this; /******************************* Where Clauses ******************************/ where(query: FilterQuery): this; where(field: K, value: T[K]): this; where(field: string, value: any): this; where(field: K, operator: Operator, value: T[K]): this; where(field: string, operator: Operator, value: any): this; orWhere(query: FilterQuery): this; orWhere(field: K, value: T[K]): this; orWhere(field: string, value: any): this; orWhere(field: K, operator: Operator, value: T[K]): this; orWhere(field: string, operator: Operator, value: any): this; whereLike(field: K, value: string | RegExp): this; whereLike(field: string, value: string | RegExp): this; whereNotLike(field: K, value: string | RegExp): this; whereNotLike(field: string, value: string | RegExp): this; whereIn(field: string, embeddedField: string): this; whereIn(field: K, embeddedField: string): this; whereIn(field: string, values: any[]): this; whereIn(field: K, values: Array): this; whereNotIn(field: string, embeddedField: string): this; whereNotIn(field: K, embeddedField: string): this; whereNotIn(field: string, values: any[]): this; whereNotIn(field: K, values: Array): this; whereBetween(field: K, start: T[K], end: T[K]): this; whereBetween(field: string, start: any, end: any): this; whereNotBetween(field: K, start: T[K], end: T[K]): this; whereNotBetween(field: string, start: any, end: any): this; whereNull(field: K): this; whereNull(field: string): this; whereNotNull(field: K): this; whereNotNull(field: string): this; }