oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.25k stars 1.07k forks source link

Does getConnection() return a new javascript object? #1509

Closed deostroll closed 2 years ago

deostroll commented 2 years ago

When working with connection pools, just wanted to know if getConnection() is going to give the "same object"?

Just to clarify the picture...lets assume an express app which uses oracledb and it has about 4 pools. Lets say one api call a getConnection() was called and we've obtained the object. Lets say that with this connection object is specific to the 2nd connection in the connection pool. That api call did some crud operation and released it back into the pool. Some other api call checks out the the same 2nd connection from the pool...will those two objects have the same object reference?

cjbj commented 2 years ago

You should assume that what is returned from the second pool.getConnection() is different to the first - there is no guarantee about it. You can store & restore session state on the underlying C library "connection" using the session callback. It is up to the app to restore any app-specific state that you want to have. Oracle features like Application Continuity can also help restore the C library connection state, but its purpose and when it kicks in is different to a normal application getConnection() call.