DEV Community

Discussion on: Advanced NestJS: How to build completely dynamic NestJS modules

johnbiundo profile image
John Biundo Author

@fwoelffel Thank you for your feedback!

Right, I didn't really cover that in this article, but good question. The Massive library uses pg-promise under the covers and the db object I briefly mention actually represents a connection pool. So the recommended pattern for Massive (and any pg-promise library) is to use a singleton connection object which manages the connection pool under the covers. The full Massive integration library I built has additional options to configure the connection pool size and some other parameters to let you fine tune.

Oh, and there's a tiny bit more plumbing in the full library. Basically, it builds an injection token representing the shared connection object, and to use it in any module, you just inject that token. I tried to cover that in the @nestjsplus/massive docs, but let me know if it's still not clear. I felt like this detail - while relevant to understanding the full MassiveJS library - was a bit too distracting to cover in this article, but I'm not surprised you picked up on it!

Hope that answers the question!