Skip to main content
Version: 6.4

使用原生 BigInt PK(MySQL 和 PostgreSQL)

自 v6 起,bigint 由原生 BigInt 类型表示,因此,它们不需要在装饰器选项中明确指定类型:

¥Since v6, bigints are represented by the native BigInt type, and as such, they don't require explicit type in the decorator options:

@PrimaryKey()
id: bigint;

你还可以指定希望将 bigint 映射到的目标类型:

¥You can also specify the target type you want your bigints to be mapped to:

@PrimaryKey({ type: new BigIntType('bigint') })
id1: bigint;

@PrimaryKey({ type: new BigIntType('string') })
id2: string;

@PrimaryKey({ type: new BigIntType('number') })
id3: number;

当映射到 number 类型时,JavaScript 无法表示 bigint 的所有可能值 - 仅安全支持高达 Number.MAX_SAFE_INTEGER(2^53 - 1)的值。

¥JavaScript cannot represent all the possible values of a bigint when mapping to the number type - only values up to Number.MAX_SAFE_INTEGER (2^53 - 1) are safely supported.