@@ -1842,7 +1842,7 @@ String sessionCallback | function sessionCallback(Connection connection, String
1842
1842
```
1843
1843
1844
1844
When ` sessionCallback ` is a Node.js function, it will be invoked for
1845
- each ` pool.getConnection() ` call that will return a brand new
1845
+ each ` pool.getConnection() ` call that will return a newly created
1846
1846
connection in the pool. It will also be called if
1847
1847
` pool.getConnection() ` requests a connection from the pool with a
1848
1848
given [ ` tag ` ] ( #getconnectiondbattrstag ) , and that tag value does not
@@ -1852,7 +1852,7 @@ other `getConnection()` calls. The tag requested by
1852
1852
the actual tag is available in [ ` connection.tag ` ] ( #propconntag ) .
1853
1853
1854
1854
The session callback is called before ` getConnection() ` returns so it
1855
- can be used to do logging, or efficiently set session state such as
1855
+ can be used to do logging or efficiently set session state such as
1856
1856
with ALTER SESSION statements. Make sure any session state is set and
1857
1857
` connection.tag ` is updated in the ` sessionCallback ` function prior to
1858
1858
it calling its own ` callback ` function otherwise the session will not
@@ -2338,6 +2338,14 @@ When node-oracledb is using Oracle Client libraries 12.2 or later, the
2338
2338
tag must be a [ multi-property tag] [ 125 ] with name=value pairs like
2339
2339
"k1=v1;k2=v2".
2340
2340
2341
+ An empty string represents not having a tag set.
2342
+
2343
+ See [ Connection Tagging and Session State] ( #connpooltagging ) .
2344
+
2345
+ This property was added in node-oracledb 3.1.
2346
+
2347
+ ##### Getting the tag
2348
+
2341
2349
After a ` pool.getConnection() ` requests a [ tagged
2342
2350
connection] ( #getconnectiondbattrstag ) :
2343
2351
@@ -2346,21 +2354,22 @@ connection](#getconnectiondbattrstag):
2346
2354
connection.
2347
2355
2348
2356
- When a Node.js ` sessionCallback ` function is used, then
2349
- ` connection.tag ` will be set to the value of the connection's actual
2350
- tag prior to invoking the callback. The callback can then set the
2351
- connection state and alter ` connection.tag ` as desired.
2357
+ ` connection.tag ` will be set to the value of the connection's actual
2358
+ tag prior to invoking the callback. The callback can then set
2359
+ connection state and alter ` connection.tag ` as desired.
2352
2360
2353
2361
- When a PL/SQL ` sessionCallback ` is used, then ` connection.tag `
2354
- contains the value of the tag that was requested by
2355
- ` pool.getConnection() ` . The PL/SQL callback is expected to set the
2356
- state to match.
2362
+ contains the value of the tag that was requested by
2363
+ ` pool.getConnection() ` . The PL/SQL callback is expected to set the
2364
+ state to match.
2357
2365
2358
- An empty string represents no tag. To clear a connection's tag, set
2359
- ` connection.tag = "" ` prior to closing the connection.
2366
+ ##### Setting the tag
2360
2367
2361
- See [ Connection Tagging and Session State] ( #connpooltagging ) .
2368
+ A tag can be set anytime prior to closing the connection. If a
2369
+ Node.js ` sessionCallback ` function is being used, the best practice
2370
+ recommendation is to set the tag in the callback function.
2362
2371
2363
- This property was added in node-oracledb 3.1 .
2372
+ To clear a connection's tag, set ` connection.tag = "" ` .
2364
2373
2365
2374
### <a name =" connectionmethods " ></a > 4.2 Connection Methods
2366
2375
@@ -6525,7 +6534,7 @@ database. The `requestedTag` parameter is ignored because it is only
6525
6534
valid when tagging is being used:
6526
6535
6527
6536
` ` ` javascript
6528
- function mySetState (connection , requestedTag , cb ) {
6537
+ function initSession (connection , requestedTag , cb ) {
6529
6538
connection .execute (
6530
6539
` alter session set nls_date_format = 'YYYY-MM-DD' nls_language = AMERICAN` ,
6531
6540
cb);
@@ -6536,7 +6545,7 @@ try {
6536
6545
user: ' hr' ,
6537
6546
password: ' welcome' ,
6538
6547
connectString: ' localhost/XEPDB1' ,
6539
- sessionCallback: mySetState
6548
+ sessionCallback: initSession
6540
6549
});
6541
6550
. . .
6542
6551
}
@@ -6598,7 +6607,7 @@ properties that may be set:
6598
6607
` ` ` javascript
6599
6608
const sessionTag = " location=USA" ;
6600
6609
6601
- function mySetState (connection , requestedTag , cb ) {
6610
+ function initSession (connection , requestedTag , cb ) {
6602
6611
let seen = connection .tag ? connection .tag .split (" ;" ).includes (requestedTag) : false ;
6603
6612
if (seen) {
6604
6613
cb ()
@@ -6619,7 +6628,7 @@ try {
6619
6628
user: ' hr' ,
6620
6629
password: ' welcome' ,
6621
6630
connectString: ' localhost/XEPDB1' ,
6622
- sessionCallback: mySetState
6631
+ sessionCallback: initSession
6623
6632
});
6624
6633
6625
6634
// Request a connection with a given tag from the pool cache, but accept any tag being returned.
0 commit comments