阅读 722

typeorm整理翻译

英文水平有限,主要靠百度翻译!将就看!

Entity

Entity

/**
 * 此装饰器用于标记将是实体的类(表或文档依赖于数据库类型)
 * 数据库模式将为所有与它一起装饰的类创建,并且可以检索并使用存储库.
 */
export declare function Entity(options?: EntityOptions): Function;
export declare function Entity(name?: string, options?: EntityOptions): Function;
复制代码
export declare type OrderByCondition = {
    [columnName: string]: ("ASC" | "DESC") | {
        order: "ASC" | "DESC";
        nulls: "NULLS FIRST" | "NULLS LAST";
    };
};
export interface EntityOptions {
    /**
     * 表名,如果未指定,默认是类名。
     */
    name?: string;
    /**
     * 默认排序
     */
    orderBy?: OrderByCondition | ((object: any) => OrderByCondition | any);
    /**
     * 数据库引擎,如:"InnoDB", "MyISAM"
     */
    engine?: string;
    /**
     * 指定数据库名称
     */
    database?: string;
    /**
     * Schema 名称.
     */
    schema?: string;
    /**
     * 是否为该实体启用或禁用架构同步
     * 如果将其设置为false,则模式同步将与迁移忽略该实体
     * 默认情况下,对所有实体启用模式同步.
     */
    synchronize?: boolean;
}
复制代码

ChildEntity

export declare function ChildEntity(discriminatorValue?: any): (target: Function) => void;
复制代码

TableInheritance


export declare function TableInheritance(options?: {
    pattern?: "STI";
    column?: string | ColumnOptions;
}): (target: Function) => void;
复制代码
export declare type OrderByCondition = {
    [columnName: string]: ("ASC" | "DESC") | {
        order: "ASC" | "DESC";
        nulls: "NULLS FIRST" | "NULLS LAST";
    };
};
export interface EntityOptions {
    /**
     * 表名,如果未指定,默认是类名。
     */
    name?: string;
    /**
     * 默认排序
     */
    orderBy?: OrderByCondition | ((object: any) => OrderByCondition | any);
    /**
     * 数据库引擎,如:"InnoDB", "MyISAM"
     */
    engine?: string;
    /**
     * 指定数据库名称
     */
    database?: string;
    /**
     * Schema 名称.
     */
    schema?: string;
    /**
     * 是否为该实体启用或禁用架构同步
     * 如果将其设置为false,则模式同步将与迁移忽略该实体
     * 默认情况下,对所有实体启用模式同步.
     */
    synchronize?: boolean;
}
复制代码

Column

/**
 * 用于 @PrimaryGeneratedColumn() 装饰器的列类型.
 */
export declare type PrimaryGeneratedColumnType = "int" | "int2" | "int2" | "int4" | "int8" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint" | "dec" | "decimal" | "numeric" | "number";
/**
 * 带有精度或比例的列类型.
 */
export declare type WithPrecisionColumnType = "float" | "double" | "dec" | "decimal" | "numeric" | "real" | "double precision" | "number" | "datetime" | "datetime2" | "datetimeoffset" | "time" | "time with time zone" | "time without time zone" | "timestamp" | "timestamp without time zone" | "timestamp with time zone" | "timestamp with local time zone";
/**
 * 带有长度的列类型.
 */
export declare type WithLengthColumnType = "character varying" | "varying character" | "nvarchar" | "character" | "native character" | "varchar" | "char" | "nchar" | "varchar2" | "nvarchar2" | "raw" | "binary" | "varbinary";
export declare type WithWidthColumnType = "tinyint" | "smallint" | "mediumint" | "int" | "bigint";
/**
 * 所有其他常规列类型.
 */
export declare type SimpleColumnType = "simple-array" | "simple-json" | "bit" | "int2" | "integer" | "int4" | "int8" | "unsigned big int" | "float4" | "float8" | "smallmoney" | "money" | "boolean" | "bool" | "tinyblob" | "tinytext" | "mediumblob" | "mediumtext" | "blob" | "text" | "ntext" | "citext" | "hstore" | "longblob" | "longtext" | "bytea" | "long" | "raw" | "long raw" | "bfile" | "clob" | "nclob" | "image" | "timetz" | "timestamptz" | "timestamp with local time zone" | "smalldatetime" | "date" | "interval year to month" | "interval day to second" | "interval" | "year" | "point" | "line" | "lseg" | "box" | "circle" | "path" | "polygon" | "geography" | "geometry" | "linestring" | "multipoint" | "multilinestring" | "multipolygon" | "geometrycollection" | "int4range" | "int8range" | "numrange" | "tsrange" | "tstzrange" | "daterange" | "enum" | "cidr" | "inet" | "macaddr" | "bit" | "bit varying" | "varbit" | "tsvector" | "tsquery" | "uuid" | "xml" | "json" | "jsonb" | "varbinary" | "hierarchyid" | "sql_variant" | "rowid" | "urowid" | "uniqueidentifier" | "rowversion";
/**
 * 所有列类型.
 */
export declare type ColumnType = WithPrecisionColumnType | WithLengthColumnType | WithWidthColumnType | SimpleColumnType | BooleanConstructor | DateConstructor | NumberConstructor | StringConstructor;


export interface ValueTransformer {
    /**
     * 写入数据库时.
     */
    to(value: any): any;
    /**
     * 读取数据库时
     */
    from(value: any): any;
}

export interface ColumnOptions {
    /**
     * 列类型。必须是来自ColumnType类的值之一
     */
    type?: ColumnType;
    /**
     * 列名称.
     */
    name?: string;
    /**
     * 列类型的长度,仅用于WithLengthColumnType|WithWidthColumnType的类型,
     * 如type=string,lenght=100,将创建一个具有Varchar类型长度为100的列.
     */
    length?: string | number;
    /**
     * 列宽度/精度,可用于WithPrecisionColumnType.
     */
    width?: number;
    /**
     * 列的值是否可以设置为空.
     */
    nullable?: boolean;
    /**
     * 是否只读,如果是那么只能在insert中赋值,更新不能改变!
     */
    readonly?: boolean;
    /**
     * 可被QueryBuilder选择并查找。默认值为“true”
     */
    select?: boolean;
    /**
     * 默认值.
     */
    default?: any;
    /**
     * 更新触发器,仅支持mysql.
     */
    onUpdate?: string;
    /**
     * 是否为主键,与@PrimaryColumn效果相同
     */
    primary?: boolean;
    /**
     * 是否唯一
     */
    unique?: boolean;
    /**
     * 备注信息.
     */
    comment?: string;
    /**
     * 十进制(精确数字)列的精度(仅适用于十进制列),这是为值存储的最大位数
     */
    precision?: number | null;
    /**
     * 小数(精确数字)列的刻度(仅适用于十进制列),它表示小数点右边的位数,不能大于精度
     */
    scale?: number;
    /**
     * 如果为true,MySQL会自动将未签名的属性添加到此列中。
     */
    zerofill?: boolean;
    /**
     * 标注是否签名.
     */
    unsigned?: boolean;
    /**
     * 字符集
     */
    charset?: string;
    /**
     * 列排序规则.
     */
    collation?: string;
    /**
     * 规定可枚举的数据.
     */
    enum?: any[] | Object;
    /**
     * 生成的列表达式.
     */
    asExpression?: string;
    /**
     * 生成的列类型.
     */
    generatedType?: "VIRTUAL" | "STORED";
    /**
     * 返回列类型
     */
    hstoreType?: "object" | "string";
    /**
     * 是否数组
     */
    array?: boolean;
    /**
     * 转换器
     */
    transformer?: ValueTransformer;
}

/**
 * 列装饰器用于标记特定的类属性作为列。只有在保存实体时,使用该装饰器的属性才会被持久化到数据库中。
 */
export declare function Column(): Function;
export declare function Column(options: ColumnOptions): Function;
export declare function Column(type: SimpleColumnType, options?: ColumnCommonOptions): Function;
export declare function Column(type: WithLengthColumnType, options?: ColumnCommonOptions & ColumnWithLengthOptions): Function;
export declare function Column(type: WithWidthColumnType, options?: ColumnCommonOptions & ColumnWithWidthOptions): Function;
export declare function Column(type: WithPrecisionColumnType, options?: ColumnCommonOptions & ColumnNumericOptions): Function;
export declare function Column(type: "enum", options?: ColumnCommonOptions & ColumnEnumOptions): Function;
export declare function Column(type: "hstore", options?: ColumnCommonOptions & ColumnHstoreOptions): Function;
/**
 * 实体中的属性可以标记为嵌入式,并且在持久性上,
 * 所有来自嵌入式的列都映射到使用嵌入的实体的单个表。
 * 在水化过程中,所有被嵌入的列都将从单个表映射到它。
 */
export declare function Column(type: (type?: any) => Function, options?: ColumnEmbeddedOptions): Function;

复制代码

OneToMany


export interface RelationOptions {
    /**
     * 设置给定关系的级联选项。
     * 如果设置为true,则意味着可以允许在数据库中插入或更新相关对象。
     * 可以使用以下语法单独限制级联插入或更新:
     * cascade: ["insert", "update"]
     */
    cascade?: boolean | ("insert" | "update" | "remove")[];
    /**
     * 标示关系列值是否可以为空值。
     */
    nullable?: boolean;
    /**
     * 删除数据库时操作.
     */
    onDelete?: OnDeleteType;
    /**
     * 更新数据库时操作
     */
    onUpdate?: OnUpdateType;
    /**
     * 此关系是否为主键。只能用于多对一和业主一对一的关系
     */
    primary?: boolean;
    /**
     * 是否懒加载,当使用时获取
     */
    lazy?: boolean;
    /**
     * find查找时,是否自动加载关系,可以设置其中一方
     */
    eager?: boolean;
    /**
     * 是否持久性
     * 如果其已禁用,则只能更改关系的反面或使用关系查询生成器功能
     */
    persistence?: boolean;
}


/**
 * 一对多
 * 如: 一个员工,只能属于一个公司,公司可以有多个员工
 * 一是公司 多是员工 type=>员工 员工.公司 string
 */
export declare function OneToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide: string | ((object: T) => any), options?: RelationOptions): Function;
复制代码

ManyToOne

/**
 * 多对一
 * 一个员工,只能属于一个公司,公司可以有多个员工
 * 多是公司,一是员工 type=>公司, 公司.员工 array
 */
export declare function ManyToOne<T>(typeFunction: (type?: any) => ObjectType<T>, options?: RelationOptions): Function;
export declare function ManyToOne<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide?: string | ((object: T) => any), options?: RelationOptions): Function;
复制代码

PrimaryGeneratedColumn

export declare type PrimaryGeneratedColumnType = "int" | "int2" | "int2" | "int4" | "int8" | "integer" | "tinyint" | "smallint" | "mediumint" | "bigint" | "dec" | "decimal" | "numeric" | "number";
/**
 * PrimaryGeneratedColumn
 */
export interface PrimaryGeneratedColumnNumericOptions {
    /**
     * 列类型.
     */
    type?: PrimaryGeneratedColumnType;
    /**
     * 名称
     */
    name?: string;
    /**
     * 备注.
     */
    comment?: string;
    /**
     * 是否 zero fill
     */
    zerofill?: boolean;
    /**
     * 是否unsigned
     */
    unsigned?: boolean;
}

export interface PrimaryGeneratedColumnUUIDOptions {
    /**
     * 名称
     */
    name?: string;
    /**
     * 备注.
     */
    comment?: string;
}

/**
 * 主键自增
 */
export declare function PrimaryGeneratedColumn(): Function;
/**
 * 主键自增
 */
export declare function PrimaryGeneratedColumn(options: PrimaryGeneratedColumnNumericOptions): Function;
/**
 * 主键自增
 */
export declare function PrimaryGeneratedColumn(strategy: "increment", options?: PrimaryGeneratedColumnNumericOptions): Function;
/**
 * 主键uuid模式
 */
export declare function PrimaryGeneratedColumn(strategy: "uuid", options?: PrimaryGeneratedColumnUUIDOptions): Function;

复制代码

PrimaryColumn

/**
 * PRIMARY KEY
 */
export declare function PrimaryColumn(options?: ColumnOptions): Function;
/**
 * PRIMARY KEY
 */
export declare function PrimaryColumn(type?: ColumnType, options?: ColumnOptions): Function;

复制代码

UpdateDateColumn

// 更新日期
export declare function UpdateDateColumn(options?: ColumnOptions): Function;
复制代码

CreateDateColumn

// 插入日期
export declare function CreateDateColumn(options?: ColumnOptions): Function;
复制代码

VersionColumn

// 数字版本
export declare function VersionColumn(options?: ColumnOptions): Function;

复制代码

AfterInsert

// 插入后执行脚本
export declare function AfterInsert(): (object: Object, propertyName: string) => void;

复制代码

AfterLoad

// 加载后钩子
export declare function AfterLoad(): (object: Object, propertyName: string) => void;

复制代码

AfterRemove

// remove后钩子
export declare function AfterRemove(): (object: Object, propertyName: string) => void;
复制代码

AfterUpdate

// 更新钩子
export declare function AfterUpdate(): (object: Object, propertyName: string) => void;
复制代码

BeforeInsert

// insert前
export declare function BeforeInsert(): (object: Object, propertyName: string) => void;
复制代码

BeforeRemove

// remove前
export declare function BeforeRemove(): (object: Object, propertyName: string) => void;
复制代码

BeforeUpdate

// 更新前
export declare function BeforeUpdate(): (object: Object, propertyName: string) => void;
复制代码

EventSubscriber

// 事件监听
export declare function EventSubscriber(): (target: Function) => void;
复制代码

JoinColumn


export interface JoinColumnOptions {
    /**
     * 名称
     */
    name?: string;
    /**
     * 引用该列的实体中列的名称
     */
    referencedColumnName?: string;
}

/**
 * 一对一或多对一关系指定
 */
export declare function JoinColumn(): Function;
export declare function JoinColumn(options: JoinColumnOptions): Function;
export declare function JoinColumn(options: JoinColumnOptions[]): Function;
复制代码

JoinTable

export interface JoinColumnOptions {
    /**
     * 自定义名称
     */
    name?: string;
    /**
     * 列名称
     */
    referencedColumnName?: string;
}

/**
 * Describes join table options.
 */
export interface JoinTableOptions {
    /**
     * 名称
     */
    name?: string;
    /**
     * 连接表的第一列
     */
    joinColumn?: JoinColumnOptions;
    /**
     * 连接表的第二列
     */
    inverseJoinColumn?: JoinColumnOptions;
    /**
     * 表明
     */
    database?: string;
    /**
     * 创建连接表schema
     */
    schema?: string;
}


export interface JoinTableMultipleColumnsOptions {
    /**
     * 连接表值得表名称,默认自动创建
     */
    name?: string;
    /**
     * 连接表的第一列
     */
    joinColumns?: JoinColumnOptions[];
    /**
     * 连接表的第二列
     */
    inverseJoinColumns?: JoinColumnOptions[];
    /**
     * 数据库
     */
    database?: string;
    /**
     * schema
     */
    schema?: string;
}

/**
 * 多对多关系
 */
export declare function JoinTable(): Function;
export declare function JoinTable(options: JoinTableOptions): Function;
export declare function JoinTable(options: JoinTableMultipleColumnsOptions): Function;

复制代码

ManyToMany

export interface RelationOptions {
    /**
     * cascade
     */
    cascade?: boolean | ("insert" | "update" | "remove")[];
    /**
     * 是否可以null.
     */
    nullable?: boolean;
    /**
     * 删除时
     */
    onDelete?: OnDeleteType;
    /**
     * 更新时
     */
    onUpdate?: OnUpdateType;
    /**
     * 主键
     */
    primary?: boolean;
    /**
     * 惰性加载
     */
    lazy?: boolean;
    /**
     * eager
     */
    eager?: boolean;
    /**
     * persistence
     */
    persistence?: boolean;
}

/**
 * 多对多关系,这种类型的关系创建一个连接表,用于保存关系数据
 */
export declare function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, options?: RelationOptions): Function;
export declare function ManyToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide?: string | ((object: T) => any), options?: RelationOptions): Function;
复制代码

ManyToOne

// 多对一
export declare function ManyToOne<T>(typeFunction: (type?: any) => ObjectType<T>, options?: RelationOptions): Function;
export declare function ManyToOne<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide?: string | ((object: T) => any), options?: RelationOptions): Function;
复制代码

OneToMany

// 一对多
export declare function OneToMany<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide: string | ((object: T) => any), options?: RelationOptions): Function;
复制代码

OneToOne

/**
 * 一对一
 */
export declare function OneToOne<T>(typeFunction: (type?: any) => ObjectType<T>, options?: RelationOptions): Function;
export declare function OneToOne<T>(typeFunction: (type?: any) => ObjectType<T>, inverseSide?: string | ((object: T) => any), options?: RelationOptions): Function;
复制代码

RelationCount

// 数量
export declare function RelationCount<T>(relation: string | ((object: T) => any), alias?: string, queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>): Function;
复制代码

RelationId

// 提取id
export declare function RelationId<T>(relation: string | ((object: T) => any), alias?: string, queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>): Function;
复制代码

Tree

Tree

TreeParent

TreeLevelColumn

TreeChildren

/**
 * 标记实体像树一样工作。
 * 应该指定树实体的树模式。
 * @TreeParent。
 */
export declare function Tree(type: TreeType): Function;

export declare function TreeParent(): Function;

export declare function TreeLevelColumn(): Function;

export declare function TreeChildren(options?: {
    cascade?: boolean | ("insert" | "update" | "remove")[];
}): Function;

复制代码

Transaction

Transaction

TransactionRepository

TransactionManager

/**
 * 将一些方法封装成事务.
 *
 * 如果想要使用实体管理器
 * then use @TransactionEntityManager() decorator.
 *
 * 如果想要使用存储库
 * then use @TransactionRepository() decorator.
 */
export declare function Transaction(connectionName?: string): MethodDecorator;
/**
 * 事物存储库
 */
export declare function TransactionRepository(entityType?: Function): ParameterDecorator;
/**
 * 事物实体管理器
 */
export declare function TransactionManager(): Function;

复制代码
评论