import type { DeferMode, CheckCallback, Dictionary, EntityProperty, GroupOperator, RawQueryFragment, QBFilterQuery, QueryOrderMap, Type, QueryFlag, AnyEntity, EntityName } from '@mikro-orm/core'; import type { Knex } from 'knex'; import type { JoinType, QueryType } from './query/enums'; import type { DatabaseSchema, DatabaseTable } from './schema'; export interface Table { table_name: string; schema_name?: string; table_comment?: string; } export type KnexStringRef = Knex.Ref; type AnyString = string & {}; export type Field = AnyString | keyof T | RawQueryFragment | KnexStringRef | Knex.QueryBuilder; export interface JoinOptions { table: string; schema?: string; type: JoinType; alias: string; ownerAlias: string; inverseAlias?: string; joinColumns?: string[]; inverseJoinColumns?: string[]; primaryKeys?: string[]; path?: string; prop: EntityProperty; cond: Dictionary; cond_?: Dictionary; subquery?: string; nested?: Set; } export interface Column { name: string; type: string; mappedType: Type; unsigned?: boolean; autoincrement?: boolean; nullable?: boolean; length?: number; precision?: number; scale?: number; default?: string | null; comment?: string; generated?: string; nativeEnumName?: string; enumItems?: string[]; primary?: boolean; unique?: boolean; /** mysql only */ extra?: string; ignoreSchemaChanges?: ('type' | 'extra' | 'default')[]; } export interface ForeignKey { columnNames: string[]; constraintName: string; localTableName: string; referencedTableName: string; referencedColumnNames: string[]; updateRule?: string; deleteRule?: string; deferMode?: DeferMode; } export interface IndexDef { columnNames: string[]; keyName: string; unique: boolean; constraint: boolean; primary: boolean; composite?: boolean; expression?: string; options?: Dictionary; type?: string | Readonly<{ indexType?: string; storageEngineIndexType?: 'hash' | 'btree'; predicate?: Knex.QueryBuilder; }>; deferMode?: DeferMode; } export interface CheckDef { name: string; expression: string | CheckCallback; definition?: string; columnName?: string; } export interface ColumnDifference { oldColumnName: string; column: Column; fromColumn: Column; changedProperties: Set; } export interface TableDifference { name: string; changedComment?: string; fromTable: DatabaseTable; toTable: DatabaseTable; addedColumns: Dictionary; changedColumns: Dictionary; removedColumns: Dictionary; renamedColumns: Dictionary; addedIndexes: Dictionary; changedIndexes: Dictionary; removedIndexes: Dictionary; renamedIndexes: Dictionary; addedChecks: Dictionary; changedChecks: Dictionary; removedChecks: Dictionary; addedForeignKeys: Dictionary; changedForeignKeys: Dictionary; removedForeignKeys: Dictionary; } export interface SchemaDifference { newNamespaces: Set; newNativeEnums: { name: string; schema?: string; items: string[]; }[]; newTables: Dictionary; changedTables: Dictionary; removedTables: Dictionary; removedNamespaces: Set; removedNativeEnums: { name: string; schema?: string; }[]; orphanedForeignKeys: ForeignKey[]; fromSchema: DatabaseSchema; } export interface IQueryBuilder { readonly alias: string; readonly type?: QueryType; _fields?: Field[]; /** @internal */ helper: any; select(fields: Field | Field[], distinct?: boolean): this; addSelect(fields: string | string[]): this; from = AnyEntity>(target: EntityName | IQueryBuilder, aliasName?: string): IQueryBuilder; insert(data: any): this; update(data: any): this; delete(cond?: QBFilterQuery): this; truncate(): this; count(field?: string | string[], distinct?: boolean): this; join(field: string, alias: string, cond?: QBFilterQuery, type?: JoinType, path?: string): this; innerJoin(field: string, alias: string, cond?: QBFilterQuery): this; leftJoin(field: string, alias: string, cond?: QBFilterQuery): this; joinAndSelect(field: string, alias: string, cond?: QBFilterQuery): this; leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): this; innerJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): this; withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this; where(cond: QBFilterQuery, operator?: keyof typeof GroupOperator): this; where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this; andWhere(cond: QBFilterQuery): this; andWhere(cond: string, params?: any[]): this; orWhere(cond: QBFilterQuery): this; orWhere(cond: string, params?: any[]): this; orderBy(orderBy: QueryOrderMap): this; groupBy(fields: (string | keyof T) | (string | keyof T)[]): this; having(cond?: QBFilterQuery | string, params?: any[]): this; getAliasForJoinPath(path: string, options?: ICriteriaNodeProcessOptions): string | undefined; getJoinForPath(path?: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined; getNextAlias(entityName?: string): string; clone(reset?: boolean): IQueryBuilder; setFlag(flag: QueryFlag): this; unsetFlag(flag: QueryFlag): this; hasFlag(flag: QueryFlag): boolean; scheduleFilterCheck(path: string): void; } export interface ICriteriaNodeProcessOptions { alias?: string; matchPopulateJoins?: boolean; ignoreBranching?: boolean; preferNoBranch?: boolean; type?: 'orderBy'; } export interface ICriteriaNode { readonly entityName: string; readonly parent?: ICriteriaNode | undefined; readonly key?: string | undefined; payload: any; prop?: EntityProperty; index?: number; process(qb: IQueryBuilder, options?: ICriteriaNodeProcessOptions): any; shouldInline(payload: any): boolean; willAutoJoin(qb: IQueryBuilder, alias?: string, options?: ICriteriaNodeProcessOptions): boolean; shouldRename(payload: any): boolean; renameFieldToPK(qb: IQueryBuilder): string; getPath(addIndex?: boolean): string; getPivotPath(path: string): string; } export type MySqlIncrementOptions = { primaryKey?: boolean; unsigned?: boolean; type?: Column['type']; }; export interface MySqlTableBuilder extends Knex.TableBuilder { increments(columnName?: string, options?: MySqlIncrementOptions): Knex.ColumnBuilder; bigIncrements(columnName?: string, options?: MySqlIncrementOptions): Knex.ColumnBuilder; } export {};