NestJS SQLite 연결(TypeORM)
NestJS 설치 : nest js - install & Create Project from Linux or Ubuntu
NestJS CLI로 TypeORM 및 sqlite설치
npm 모듈은 nestjs에서 TypeORM 으로 sqlite을 사용할수 있는 모듈이다. 자새한 사항은 링크 참조
$ npm i --save sqlite3 typeorm @nestjs/typeorm
참고로 사용하는 버전은 다음과 같습니다.
@nestjs/typeorm : ^9.0.1
sqlite3 : ^5.0.11
typeorm : ^0.3.9
// src/app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [TypeOrmModule.forRoot({
type : 'sqlite', // 사용하는 DBMS종료
database : `${__dirname.split('/dist')[0]}/test.db`, // DB의 위치. 실제 root경로/test.db
entities: [__dirname + "/**/*.entity{.ts,.js}"], // 엔티티 위치
synchronize: true // 프로그램이 DB구조 변경 허용(true)
})
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
해당 NestJS서버를 실행하면 위 사진과 같이 test.db파일이 생성된 것을 알수 있습니다. 이제 SQLite를 NestJS으로 이용할수 있습니다.
참고 gitRepository : https://github.com/Alex-Choi0/NestJS_SetSQLite.git
댓글
댓글 쓰기