DB에 bigint로 저장된 컬럼을 API에서 꺼내서 그대로 사용하면 바이트 부족으로 인해서 데이터가 손실됩니다..!!
Sequelize에서는 아래와 같이 dialectOptions의 supportBigNumbers를 정의해서, 손실을 방지할 수 있고, bigNumberStrings를 정의해서 string으로 받을 수도 있습니다.
import { Sequelize } from "sequelize";
const shopDB = new Sequelize(
"shopDB",
"root",
"root",
{
host: "localhost",
dialect: "mysql",
pool: {
max: 10,
min: 0,
acquire: 5000,
idle: 10000,
},
timezone: "+09:00",
dialectOptions: {
supportBigNumbers : true,
bigNumberStrings : true
},
define: {
underscored: true
}
}
);
export default shopDB;
underscored는 camelCase의 DTO와 snake_case의 table을 연결시킬 수 있습니다.
'Server > Node.js' 카테고리의 다른 글
NodeJS - 권한 제어 (Endpoint별 인증, 인가) 하는 법! (+ middleware) (0) | 2022.02.13 |
---|---|
Jest - 테스트 환경 구축하는 방법 (Test용 DB 사용) with Setup, Teardown (0) | 2022.02.13 |
Sequelize - 커스텀 메서드 (Custom method) 구현 (0) | 2022.01.08 |
Sequelize - 일괄 등록, 일괄 수정 하기 (bulk create, bulk update) (0) | 2022.01.05 |
NodeJS - 전역 예외 핸들러 구현 (Custom global exception handler) (0) | 2021.12.29 |