postgres를 typeorm을 활용해서 nest.js 에 연결하고 있다.
여러가지 환경설정이 있다. 환경설정을 잘 진행해줘야 한다.
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
export const typeOrmConfig: TypeOrmModuleOptions = {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'username',
password: 'password',
database: 'database',
entities: [__dirname + '/../**/*.entity.{js,ts}'],
synchronize: true,
timezone: 'Asia/Seoul',
};
username, password, database는 각자의 설정값을 입력해줘야한다.
위와 같이 설장하고 진행하려는데 vscode에 timezone 부분이 지속해서 빨간색으로 에러가 발생했다.
검색해보니, timezone 프로퍼티를 postgres 에서는 지원하지 않는다는 것을 확인할 수 있었다.
그러면 어떻게 처리해야 하는가?
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
export const typeOrmConfig: TypeOrmModuleOptions = {
type: 'postgres',
url: 'postgres://username:password@localhost:5432/database?timezone=Asia/Seoul',
entities: [__dirname + '/../**/*.entity.{js,ts}'],
synchronize: true,
};
이런식으로 처리를 하면 접속할 수 있다. 이렇게 변경한 후에 구동을 했더니.. 이럴수가
MissingDriverError: Wrong driver: "undefined" given 오류가 발생했다. driver를 찾을 수 없는 오류라고 발생하더라 이 문제를 해결한 방법은 역시 구글링이다.
똑같은 에러로 git에 질문을 올려놓으신 분이 있었다.방법은 typeOrmConfig를 OrmConfig로 변경하고 실행했다.
아주 정상적으로 작동되는 것을 확인할 수 있었다. 이유는 정확하게 알 수 없는데 왜 그런 것일까~?
좀 더 공부를 해봐야 할 거 같다.!