nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Manual connection

aaliakseyenka opened this issue · comments

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I am trying to run Nest for generating Swagger document. Nest tries to connect to database, although that is not needed and fails due to not having local database at this moment. So we need to run Nest without connecting to db.

Describe the solution you'd like

Be able to postpone database connection until required, by manual setup.

Teachability, documentation, adoption, migration strategy

Ideally there should be an option, ie. boolean flag on TypeOrmModuleOptions to disable auto connection.

What is the motivation / use case for changing the behavior?

  1. Generate Swagger document in the pipeline. This happens without having Database locally. We should be able to configure app bootstrap without auto connect to db.

You've told your application you need to use the TypeOrmModule so it's necessary for starting the application, even if it's just to generate the swagger, because that's how the swagger module works. What you could do is use the @nestjs/testing module to make the application but replace the TypeORM configuration with an in memory solution, or an outright mock all together so you don't need to connect while generating the application. There's no plans to add in any sort of "makeConnection` flag to tell it not to connect.

although that is not needed and fails due to not having local database at this moment

It is necessary honestly, because the SwaggerModule uses the created application to read through the routes, controllers, and metadata. You must have a proper application for the SwaggerModule, so while you might not think it's necessary, it is.