import { Connection } from "mysql"; import { Pagination } from "../common/Pagination.js"; import Model from "./Model.js"; import ModelFactory from "./ModelFactory.js"; import { RelationDatabaseProperties } from "./ModelRelation.js"; import { QueryResult, QueryVariable } from "./MysqlConnectionManager.js"; export default class ModelQuery implements WhereFieldConsumer { static select(factory: ModelFactory, ...fields: QueryFields): ModelQuery; static insert(factory: ModelFactory, data: Pick): ModelQuery; static update(factory: ModelFactory, data: Pick): ModelQuery; static delete(factory: ModelFactory): ModelQuery; private readonly type; private readonly factory; private readonly table; private readonly fields; private _leftJoin?; private _leftJoinAlias?; private _leftJoinOn; private _where; private _limit?; private _offset?; private _sortBy?; private _sortDirection?; private readonly relations; private readonly subRelations; private _pivot?; private _union?; private _recursiveRelation?; private _reverseRecursiveRelation?; private constructor(); leftJoin(table: string, alias?: string): this; on(field1: string, field2: string, test?: WhereTest, operator?: WhereOperator): this; where(field: string, value: ModelFieldData, test?: WhereTest, operator?: WhereOperator): this; groupWhere(setter: (query: WhereFieldConsumer) => void, operator?: WhereOperator): this; private collectWheres; limit(limit: number, offset?: number): this; sortBy(field: string, direction?: SortDirection, raw?: boolean): this; /** * @param relations The relations field names to eagerload. To load nested relations, separate fields with '.' * (i.e.: "author.roles.permissions" loads authors, their roles, and the permissions of these roles) */ with(...relations: string[]): this; pivot(...fields: string[]): this; union(query: ModelQuery, sortBy: string, direction?: SortDirection, raw?: boolean, limit?: number, offset?: number): this; recursive(relation: RelationDatabaseProperties, reverse: boolean): this; toString(final?: boolean): string; build(): string; get variables(): QueryVariable[]; private getVariables; execute(connection?: Connection): Promise; get(connection?: Connection): Promise>; paginate(page: number, perPage: number, connection?: Connection): Promise>; first(): Promise; count(removeLimit?: boolean, connection?: Connection): Promise; } export interface ModelQueryResult extends Array { originalData?: Record[]; pagination?: Pagination; pivot?: Record[]; } export declare enum QueryType { SELECT = 0, INSERT = 1, UPDATE = 2, DELETE = 3 } export declare enum WhereOperator { AND = "AND", OR = "OR" } export declare enum WhereTest { EQ = "=", NE = "!=", GT = ">", GE = ">=", LT = "<", LE = "<=", IN = " IN " } declare class FieldValue { protected readonly field: string; protected value: ModelFieldData; protected raw: boolean; constructor(field: string, value: ModelFieldData, raw: boolean); toString(first?: boolean): string; protected get test(): string; get variables(): QueryVariable[]; get fieldName(): string; get fieldValue(): ModelFieldData; } export declare class SelectFieldValue extends FieldValue { toString(): string; } export interface WhereFieldConsumer { where(field: string, value: ModelFieldData, test?: WhereTest, operator?: WhereOperator): this; groupWhere(setter: (query: WhereFieldConsumer) => void, operator?: WhereOperator): this; } export declare type QueryFields = (string | SelectFieldValue | FieldValue)[]; export declare type SortDirection = 'ASC' | 'DESC'; export declare type ModelFieldData = QueryVariable | ModelQuery | { toString(): string; } | (QueryVariable | { toString(): string; })[]; export {};