프로그래밍(Web)/업무관련

[바미] TypeORM 타임존 이슈

Bami 2022. 11. 3. 15:29
728x90
반응형

Typescript로 클라이언트 서버 개발 때 발견한 이슈를 공유하고자 글을 쓰게 되었습니다.

서버와 클라이언트가 Socket.io 통신을 통해 TypeORM을 사용하여 특정값을 조회한 데이터를 주고 받는 작업중에

TypeORM에서 조회한 타임존 값과 실제 테이블 제 컬럼값이 다른 것을 발견하였습니다.

 

 

예를들어 DB 내 실제 값은 2022-10-04 00:00:00 인데, 이 값을 TypeORM으로 가져왔을 때는 2022-10-03 15:00:00으로

변경되어 출력되어 있었던 것이죠.

 

처음에는 개발 서버 내부의 timezone이 상이해서 그런줄 알았는데 알고보니 코드 상에서 DB 연결을 위한 ORM 설정 부분에서 timezone 파라미터를 추가해주면 됐었습니다.

const connectionInfo = ({ 
  type: 'mysql',
  name: 'mysql',
  port: config.jdbc.port,
  host: config.jdbc.host,
  username: config.jdbc.user,
  password: config.jdbc.password,
  database: config.jdbc.database,

  timezone: 'Z',

  synchronize: false,
  entities: [__dirname + '/sql/*{.js,.ts}']
} 
as MysqlConnectionOptions);

 

 

관련링크 : 

https://github.com/typeorm/typeorm/issues/976#issuecomment-386925989

 

Is it internally converting the date object to UTC before saving. · Issue #976 · typeorm/typeorm

I have an entity like this: @Entity('jobs') export class Job { @Column(type => DateTimeWithOffset) start: DateTimeWithOffset; } export class DateTimeWithOffset { @Column({ name: '_of...

728x90
반응형