Search code examples
node.jsdatabasenestjstypeorm

TypeORM limit number o created connections with createConnection(...)


I need help to limit the allowed number of connections typeORM can hold in his connectionManager.

Today I have many database, more than 12 thousands that are distributed on some servers, and each request in my application can connect to a different database because each database is related to the user, so for each user requesting something from my API my service runs the createConnection(userParams) but I don't know how to control this connection.

I tried limiting inside the userParams something like

createConnection(...userParams, {extra: connectionLimit: 5})

but it seems this only limit the inner Pool that is created each time. I need a way so I can limit the total number of connections the connectionManager can have.

Basically I want a global pool instead of one for each connection created. Can someone please give me any hints?


Solution

  • It looks like what I wanted to achieve was not possible before typeorm version 0.3.6. On current versions the connectionManager does not exists, thus I'm able to control connections by myself