/* * 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 Odin from ".."; import Base from "../Base"; import { Operator, JoinQuery, FilterQuery, Order, Callback, Iterator, Id } from "../DB"; import Filter from "../DB/Filter"; import Query from "./Query"; declare class QueryBuilder = any> extends Base { protected static query>(relations?: Query.Rel[]): Query; /******************************* With Trashed *******************************/ static withTrashed>(): Query; /*********************************** Lean ***********************************/ static lean>(): Query; /****************************** Has & WhereHas ******************************/ static has = any>(relation: string, count?: number): Query; static has = any>(relation: string, operator: Operator, count?: number): Query; static whereHas = any>(relation: string, filter: (q: Filter) => Filter, count?: number): Query; static whereHas = any>(relation: string, filter: (q: Filter) => Filter, operator: Operator, count?: number): Query; /****************************** With Relations ******************************/ static with>(...relations: string[]): Query; /*********************************** Joins **********************************/ static join>(collection: string | typeof Odin, query?: JoinQuery, as?: string): Query; /******************************* Where Clauses ******************************/ static where>(query: FilterQuery): Query; static where>(field: string, value: any): Query; static where>(field: string, operator: Operator, value: any): Query; static whereLike>(field: string, values: any): Query; static whereNotLike>(field: string, values: any): Query; static whereIn>(field: string, values: any[]): Query; static whereNotIn>(field: string, values: any[]): Query; static whereBetween>(field: string, start: any, end: any): Query; static whereNotBetween>(field: string, start: any, end: any): Query; static whereNull>(field: string): Query; static whereNotNull>(field: string): Query; /********* Mapping, Ordering, Grouping, Limit, Offset & Pagination *********/ static orderBy>(field: string, order?: Order): Query; static skip>(offset: number): Query; static offset>(offset: number): Query; static limit>(limit: number): Query; static take>(limit: number): Query; static paginate>(page?: number, limit?: number): Query; /*********************************** Read ***********************************/ static exists(): Promise; static exists(callback: Callback): void; static count(): Promise; static count(callback: Callback): void; static iterate>(): Iterator; static get>(): Promise; static get>(callback: Callback): void; static first>(): Promise>; static first>(callback: Callback>): void; static find>(ids: Id | Id[]): Promise>; static find>(ids: Id | Id[], callback: Callback>): void; static findBy>(field: string, values: any | any[]): Promise>; static findBy>(field: string, values: any | any[], callback: Callback>): void; static value(field: string): Promise; static value(field: string, callback: Callback): void; static pluck(field: string): Promise; static pluck(field: string, callback: Callback): void; static max(field: string): Promise; static max(field: string, callback: Callback): void; static min(field: string): Promise; static min(field: string, callback: Callback): void; /********************************** Inserts *********************************/ static insert(items: T[]): Promise; static insert(items: T[], callback: Callback): void; static create>(item: T): Promise>; static create>(item: T, callback: Callback>): void; /********************************** Updates *********************************/ save(): Promise; save(callback: Callback): void; /********************************** Deletes *********************************/ static delete(): Promise; static delete(callback: Callback): void; static destroy(ids: Id | Id[], force?: boolean): Promise; static destroy(ids: Id | Id[], callback: Callback): void; static destroy(ids: Id | Id[], force: boolean, callback: Callback): void; delete(force?: boolean): Promise; delete(callback: Callback): void; delete(force: boolean, callback: Callback): void; /********************************* Restoring ********************************/ restore(): Promise; restore(callback: Callback): void; } export default QueryBuilder;