-
[에러대백과] Typeorm createConnection deprecatedWEB Dev/에러대백과 2023. 4. 3. 18:31728x90
⛔ 에러 코드
//error Connection is a single database ORM connection to a specific database. Its not required to be a database connection, depend on database type it can create connection pool. You can have multiple connections to multiple databases in your application. @deprecated
node.js 생태계의 데이터베이스 ORM 라이브러리인 TypeORM 설치 후 책에 나온 코드를 따라 입력하니 Connection 과 createConnection 메소드에 취소선이 그어지고, deprecated(더 이상 사용되지 않는) 되었다는 메시지를 받았다.
*기존코드
import { Connection, createConnection } from "typeorm"; export const createDB = async (): Promise<Connection> => createConnection({ type: "mysql", host: "localhost", port: 3306, username: "test", password: "test", database: "test", })
💊 해결 방법
기존에 createConnection을 이용해 만들던 객체는 DataSourse를 이용하면 된다.
import { DataSource } from "typeorm" const AppDataSource = new DataSource({ type: "mysql", host: "localhost", port: 3306, username: "test", password: "test", database: "test", })
new DataSource 인스턴스를 호출하여 생성자를 초기화 해 줄 수 있다.
내부 객체에 필요한 정보를 입력해준다.
*참고문서
https://typeorm.io/data-source
728x90'WEB Dev > 에러대백과' 카테고리의 다른 글