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



개발자 디스코드 서버에 초대합니다.

사진) 아래링크 클릭시 커뮤니티로 초대

Comunity Discord Link

댓글

이 블로그의 인기 게시물

Lesson 12_1 프로퍼티 노드(Property Node)

DAQ로 전압 측정하기-2

Lesson 12_2 참조를 이용한 프로퍼티노드(Property Node)