Skip to content

How does Connection.prototype.useDb() works under the hood? #13266

Discussion options

You must be logged in to vote

I did a little experiment and I found these results

summary:

  1. It seems like if there is an available connection(socket) in the connection pool conn.useDb will reuse the connection, in other words a connection used/created by conn.useDb('db1'), can be reused by conn.useDb('db2').
  2. [options.useCache=true] works like this:
if the cached connection exists in the connection pool(it's not checked out of the pool(it's available and not currently being used))
  then the cached connection will get returned
else
  if connection pool is not empty
    a connection from the connection pool is returned
  else if maxPoolSize has not reached
     creates a new connection in the connection pool
  else 
  …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sadeghhosseini
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants