/// /// import IQueryBuilder = NajsEloquent.QueryBuilder.IQueryBuilder; import SubCondition = NajsEloquent.QueryGrammar.SubCondition; import Range = NajsEloquent.QueryGrammar.Range; import { ModelEvent } from './ModelEvent'; export interface Model extends NajsEloquent.Model.IModel { } export declare class Model { id?: any; constructor(data?: object, isGuarded?: boolean); protected makeDriver(): Najs.Contracts.Eloquent.Driver; getDriver(): Najs.Contracts.Eloquent.Driver; getModelName(): string; newQuery(name?: string): IQueryBuilder; /** * Register a model class. * * @param modelClass */ static register(modelClass: typeof Model): void; static Event: typeof ModelEvent; /** * Start new query of model. */ static newQuery(this: T): IQueryBuilder>; /** * Start new query of model with name. */ static newQuery(this: T, name: string): IQueryBuilder>; /** * Get global event emitter which used by all models. */ static eventEmitter(this: T): Najs.Contracts.Event.AsyncEventEmitter; /** * Adds the listener function to the end of the listeners array for the event named eventName. * No checks are made to see if the listener has already been added. * Multiple calls passing the same combination of eventName and listener will result in the listener being added, * and called, multiple times. * * @param {string} eventName * @param {Function} listener */ static on(this: T, eventName: string, listener: Function): T; /** * Adds a one-time listener function for the event named eventName. * The next time eventName is triggered, this listener is removed and then invoked. * * @param {string} eventName * @param {Function} listener */ static once(this: T, eventName: string, listener: Function): T; /** * Removes the specified listener from the listener array for the event named eventName. * * @param {string} eventName * @param {Function} listener */ static off(this: T, eventName: string, listener: Function): T; /** * Set the query with given name * * @param {string} name */ static queryName(this: T, name: string): IQueryBuilder>; /** * Set the query log group name * * @param {string} group QueryLog group */ static setLogGroup(this: T, group: string): IQueryBuilder>; /** * Set the columns or fields to be selected. * * @param {string|string[]} fields */ static select(this: T, ...fields: Array): IQueryBuilder>; /** * Set the "limit" value of the query. * @param {number} records */ static limit(this: T, record: number): IQueryBuilder>; /** * Add an "order by" clause to the query. * * @param {string} field */ static orderBy(this: T, field: string): IQueryBuilder>; /** * Add an "order by" clause to the query. * * @param {string} field * @param {string} direction */ static orderBy(this: T, field: string, direction: 'asc' | 'desc'): IQueryBuilder>; /** * Add an "order by" clause to the query with direction ASC. * * @param {string} field * @param {string} direction */ static orderByAsc(this: T, field: string): IQueryBuilder>; /** * Add an "order by" clause to the query with direction DESC. * * @param {string} field * @param {string} direction */ static orderByDesc(this: T, field: string): IQueryBuilder>; /** * Consider all soft-deleted or not-deleted items. */ static withTrashed(this: T): IQueryBuilder>; /** * Consider soft-deleted items only. */ static onlyTrashed(this: T): IQueryBuilder>; /** * Add a basic where clause to the query. * * @param {Function} conditionBuilder sub-query builder */ static where(this: T, conditionBuilder: SubCondition): IQueryBuilder>; /** * Add a basic where clause to the query. * * @param {string} field * @param {mixed} value */ static where(this: T, field: string, value: any): IQueryBuilder>; /** * Add a basic where clause to the query. * * @param {string} field * @param {string} operator * @param {mixed} value */ static where(this: T, field: string, operator: Operator, value: any): IQueryBuilder>; /** * Add a "where not" clause to the query. * * @param {string} field * @param {mixed} value */ static whereNot(this: T, field: string, value: any): IQueryBuilder>; /** * Add a "where in" clause to the query. * * @param {string} field * @param {any[]} values */ static whereIn(this: T, field: string, values: Array): IQueryBuilder>; /** * Add a "where not in" clause to the query. * * @param {string} field * @param {any[]} values */ static whereNotIn(this: T, field: string, values: Array): IQueryBuilder>; /** * Add a "where null" clause to the query. * * @param {string} field */ static whereNull(this: T, field: string): IQueryBuilder>; /** * Add a "where null" clause to the query. * * @param {string} field */ static whereNotNull(this: T, field: string): IQueryBuilder>; /** * Add a "where between" clause to the query. * * @param {string} field */ static whereBetween(this: T, field: string, range: Range): IQueryBuilder>; /** * Add a "where not between" clause to the query. * * @param {string} field */ static whereNotBetween(this: T, field: string, range: Range): IQueryBuilder>; /** * Execute query and return result as a Collection. */ static get(this: T): Promise>>; /** * Select some fields and get result as Collection. */ static get(this: T, ...fields: Array): Promise>>; /** * Execute query and return result as a Collection. */ static all(this: T): Promise>>; /** * return count of the records. */ static count(this: T): Promise; /** * Execute query and returns "pluck" result. */ static pluck(this: T, valueKey: string): Promise; /** * Execute query and returns "pluck" result. */ static pluck(this: T, valueKey: string, indexKey: string): Promise; /** * Find first record by id. * * @param {string} id */ static findById(this: T, id: any): Promise | null>; /** * Find first record by id and throws NotFoundException if there is no record * @param {string} id */ static findOrFail(this: T, id?: any): Promise>; /** * Find first record by id and throws NotFoundException if there is no record * @param {string} id */ static firstOrFail(this: T, id?: any): Promise>; /** * Load given relations name when the query get executed. * * @param {string|string[]} relations */ static with(this: T, ...relations: Array): IQueryBuilder>; }