Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store big int in nest js using typeorm

Tags:

typeorm

nestjs

some.entity.ts

amount:number

But when I store a very large data in my postgres it throws error '''integer out of range'''

My question is how can I store Big Int as type in psql using typeorm

like image 427
Ashish Choubey Avatar asked Dec 11 '25 06:12

Ashish Choubey


2 Answers

Define type bigint in @Column decorator,

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

Note: that based on TypeOrm documentation bigint is mapped to string.

like image 172
Riajul Islam Avatar answered Dec 15 '25 18:12

Riajul Islam


Just add { bigNumberStrings: false } to TypeORM's configuration, such as:

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

Then the bigint will return number type.

like image 33
Lanistor Avatar answered Dec 15 '25 17:12

Lanistor