如何使用Typeorm将Big Int存储在Nest JS中

时间:2020-01-27 08:47:10

标签: nestjs typeorm

some.entity.ts

amount:number

但是当我在postgres中存储非常大的数据时,它将引发错误“''整数超出范围”''

我的问题是如何使用typeorm将 Big Int 存储为psql中的类型

2 个答案:

答案 0 :(得分:1)

在@Column装饰器中定义类型bigint

@Column({type: 'bigint'})
columnName: number;

答案 1 :(得分:0)

在TypeORM的配置中加入{ bigNumberStrings: false }即可,如:

TypeOrmModule.forRoot({
  bigNumberStrings: false,
  ...config.database,
}),

那么 bigint 将返回数字类型。