import { BaseEntity, EntityMetadata, FindOperator, ObjectType, QueryBuilder, Repository, SelectQueryBuilder } from 'typeorm'; import { EntityMetaInfoOptions, MetaInfoOptions } from '../../common/decorators/meta.decorator'; import { Profile } from '../../common/helpers/normal'; export interface ColumnSchema { name: string; config?: { type?: any; primaryKey?: boolean; nullable?: boolean; many?: boolean; relation?: 'ManyToOne' | 'ManyToMany' | 'OneToMany' | 'OneToOne'; selectable?: string; info?: MetaInfoOptions; }; } export interface ModelNameObject { model: string; module: string; /** * 在数据库重的名称 */ dbName: string; /** * EntityInfo 注解的名称,约定上,应该是 module 和 name 的组合 */ entityName: string; } /** * https://github.com/typeorm/typeorm/issues/1101 * @param {string} value * @returns {any} */ export declare function parseWhere(value: string): string[] | FindOperator[] | null; export declare const parseNormalWheres: (where: any, repository: any) => any | any[]; export declare function parseNormalWhereAndRelatedFields(where: any, repository: any): { allRelations: any[]; normalWhere: any[]; relatedFields: string[]; relatedWhere: { [key: string]: string[]; }; }; export declare function parseOrder(model: string, value: string): { [name: string]: string; }; /** * value 为 string 时按 `,` 拆分为数组 * value 为 string[] 时直接返回 * @param {string | string[]} value * @param map * @returns {string[] | undefined} */ export declare function parseListParam(value: string | string[], map?: (field: any) => any): string[] | any | undefined; export interface ParsedFields { fields: string[]; relatedFieldsMap: object; } export declare function parseFields(value: string | string[], allRelations?: string[]): ParsedFields; export interface OriginSchema { info: EntityMetaInfoOptions; columns: ColumnSchema[]; manyToManyRelations: ColumnSchema[]; manyToOneRelations: ColumnSchema[]; oneToManyRelations: ColumnSchema[]; oneToOneRelations: ColumnSchema[]; } export declare class DBHelper { static metadatas: EntityMetadata[]; static isValidEntity(metadata: any): boolean; private static extractSelectableByColumn; private static extractSelectableByRelation; static loadMetadatas(): EntityMetadata[]; static hasRelation(fullModelName: string, relation: ObjectType): boolean; static getModelsHasRelation(entity: ObjectType, excludes?: typeof BaseEntity[]): (typeof BaseEntity & { entityInfo: EntityMetaInfoOptions; })[]; /** * 获取不包括 t_ 的模型名称, app__t_model -> app__model * 如果 module 为空,则使用默认的 module 名称 * @param model * @param module 模块名称,不包括 __ */ static getModelNameObject(model: string, module?: string): ModelNameObject; static getMetadata(model: string): EntityMetadata; static getEntityInfo(metadata: EntityMetadata): EntityMetaInfoOptions; static getPropertyNames(entity: ObjectType): string[]; static filterSelect(entity: ObjectType, select: (keyof Entity | string)[]): (keyof Entity)[]; static getPropertyNamesByRepo(repo: Repository): string[]; static getPropertyNamesByMetadata(metadata: EntityMetadata): string[]; static getRelationPropertyNames(entity: ObjectType): string[]; static getColumnNames(entity: ObjectType): string[]; static repo(entity: ObjectType | string | ModelNameObject): Repository; /** * getPrimaryKeys */ static getPrimaryKeys(repository: any): string[]; static getPrimaryKeyByModel(modelNameObject: ModelNameObject): string; static getPrimaryKey(repository: any): string; static extractOriginAsunaSchemasByModel(modelNameObject: ModelNameObject): OriginSchema; /** * @see extractOriginAsunaSchemasByModel */ static extractOriginAsunaSchemas(repository: any, opts?: { module?: string; prefix?: string; }): OriginSchema; static extractAsunaSchemas(repository: any, opts?: { module?: string; prefix?: string; }): ColumnSchema[]; /** * profile.ids -> load all ids for relationship * profile.detail -> (you should not do this, it may cause memory leak) * load all details about relationship * @param model * @param queryBuilder * @param repository * @param profile * @param relationsStr * @param parsedFields * @param where */ static wrapProfile(model: string, queryBuilder: SelectQueryBuilder, repository: Repository, profile: Profile, relationsStr: string | string[], parsedFields: ParsedFields, where: string[] | FindOperator[] | null): void; static wrapNormalWhere(model: string, queryBuilder: any, normalWheres: any): void; static wrapParsedFields(model: string, { queryBuilder, parsedFields, primaryKeys, }: { queryBuilder: QueryBuilder; parsedFields: ParsedFields; primaryKeys?: string[]; }): void; static toSqlValue(queryBuilder: any, condition: { field: string; value: string | FindOperator; }, suffix?: string): string | { [key: string]: string | FindOperator; }; }