728x90

- 설치

yarn add @nestjs/typeorm typeorm

 

+ mysql 쓸꺼면 mysql2 까지 한번에

yarn add @nestjs/typeorm typeorm mysql2

 

+ postgresql 쓸꺼면

yarn add @nestjs/typeorm typeorm pg

 

- app.module에 import 작성

++ 이거 보지 말고 아래 환경변수에 작성한거 보기

TypeOrmModule.forRoot({
      type: process.env.DB_TYPE as 'mysql',
      host: process.env.DB_HOST,
      port: Number(process.env.DB_PORT),
      username: process.env.DB_USERNAME,
      password: process.env.DB_PASSWORD,
      database: process.env.DB_DATABASE,
      entities: [__dirname + '/apis/**/*.entity.*'], // 각각의 entity 일일이 입력 or 자동순회
      synchronize: true, // 스키마 동기화
      logging: false, // 쿼리 실행 내역 터미널에 띄움
    }),

 

- 환경변수 내용은 아래 내용 참고

https://springdream0406.tistory.com/88

 

환경변수 ConfigModule

- 설치 yarn add @nestjs/config - import ConfigModule.forRoot(), - 환경변수 위치를 지정하거나, 다른 모듈에서도 사용할 수 있도록 글로벌 설정할 경우 ConfigModule.forRoot({ isGlobal: true, envFilePath: './env/.dev.env', }),

springdream0406.tistory.com

 

 

https://docs.nestjs.com/techniques/database#database

 

Documentation | NestJS - A progressive Node.js framework

Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Rea

docs.nestjs.com

 

https://typeorm.io/

 

TypeORM - Amazing ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server,

 

typeorm.io

 

728x90

'코딩 > TypeORM' 카테고리의 다른 글

Find Options  (0) 2024.10.15
Relationship  (0) 2024.10.15
[Entity] Table Inheritance - 클래스 상속을 이용한 테이블 늘리기  (1) 2024.10.11
사용 방법 예시들  (0) 2024.04.22
entities  (0) 2024.04.22

+ Recent posts