使用原生 BigInt PK(MySQL 和 PostgreSQL)
自 v6 起,bigint
由原生 BigInt
类型表示,因此,它们不需要在装饰器选项中明确指定类型:
¥Since v6, bigint
s 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 thenumber
type - only values up toNumber.MAX_SAFE_INTEGER
(2^53 - 1) are safely supported.