Nie można wstawić bigint w SQL Server za pomocą typeorm (NestJS)

0

Pytanie

Chcę wstawić nagranie do programu SQL Server przy użyciu typeorm, gdzie kolumna jest typu bigint. Mam istotę "Koty" z typ identyfikatora: bigint.

import { Column, Entity } from 'typeorm';

@Entity('Cats')
export class CatsEntity {
  @Column({ type: 'bigint', name: 'CatID' })
  public id: string;

  @Column('int', { primary: true, name: 'CatDB' })
  public db: number;

  @Column('varchar', { name: 'Name' })
  public name: string;

  @Column('datetime', { name: 'DDB_LAST_MOD' })
  public ddbLastMod: Date;
}

I dto, co mam w kontrolerze:

export class InsertCatsDto {
  public id: string;

  public db: number;

  public name: string;
}

Zapisywanie odbywa się w kontrolerze:

@Post('/cats')
  public async insertEobResponse(@Body() insertCatsDto: InsertCatsDto): Promise<any> {
    const cats = new CatsEntity();

    cats.id = insertCatsDto.id;
    cats.db = insertCatsDto.db;
    cats.name = insertCatsDto.name;
    cats.ddbLastMod = new Date();

    return this.catsRepository.insert(cats);
  }

Ale gdy wysyłam zapytanie z identyfikatorem w postaci wiersza przez listonosza, otrzymuję następujący błąd:

"błąd": "Błąd: Nie udało się wykonać test parametru "0". Wartość musi mieścić się w zakresie od -9007199254740991 do 9007199254740991 włącznie. Dla mniejszych lub większych liczb należy użyć typu VarChar."

Nie jestem pewien, że po prostu coś mi umknęło, czy trzeba dokonać jakiś konwersja wartości, czy jest to prawdziwy problem z typeorm.

nestjs sql-server typeorm
2021-11-23 18:27:43
1

Najlepsza odpowiedź

0

Aby twój kod pracował z bigInt w typeorm, trzeba tylko zmienić typ jednostki z "bigint" na "varchar".:

import { Column, Entity } from 'typeorm';

@Entity('Cats')
export class CatsEntity {
@Column({ type: 'varchar', name: 'CatID' })
public id: string;

@Column('int', { primary: true, name: 'CatDB' })
public db: number;

@Column('varchar', { name: 'Name' })
public name: string;

@Column('datetime', { name: 'DDB_LAST_MOD' })
public ddbLastMod: Date;
}
2021-12-13 17:06:13

W innych językach

Ta strona jest w innych językach

Русский
..................................................................................................................
Italiano
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................