@@ -4815,9 +4815,7 @@ time `pool.getConnection()` is called, a connection for that user is
4815
4815
returned:
4816
4816
4817
4817
```javascript
4818
- pool.getConnection(
4819
- function (err, conn) { ... }
4820
- );
4818
+ const connection = await pool.getConnection();
4821
4819
```
4822
4820
4823
4821
If a heterogeneous pool was created by setting
@@ -4826,13 +4824,12 @@ creation and credentials were omitted, then the user name and password
4826
4824
may be used in ` pool.getConnection() ` like:
4827
4825
4828
4826
``` javascript
4829
- pool .getConnection (
4830
- {
4831
- user : ' hr' ,
4832
- password : mypw, // mypw contains the hr schema password
4833
- },
4834
- function (err , conn ) { ... }
4835
- );
4827
+ const connection = await pool .getConnection (
4828
+ {
4829
+ user : ' hr' ,
4830
+ password : mypw, // mypw contains the hr schema password
4831
+ }
4832
+ );,
4836
4833
```
4837
4834
4838
4835
In this case, different user names may be used each time
@@ -6835,13 +6832,13 @@ For example, use *"localhost/XEPDB1"* to connect to the database *XE* on the loc
6835
6832
``` javascript
6836
6833
const oracledb = require (' oracledb' );
6837
6834
6838
- oracledb .getConnection (
6835
+ const connection = await oracledb .getConnection (
6839
6836
{
6840
6837
user : " hr" ,
6841
6838
password : mypw, // mypw contains the hr schema password
6842
6839
connectString : " localhost/XEPDB1"
6843
- },
6844
- . . .
6840
+ }
6841
+ );
6845
6842
```
6846
6843
6847
6844
For more information on Easy Connect strings see [ Understanding the
@@ -6853,15 +6850,13 @@ A Net Service Name, such as `sales` in the example below, can be used
6853
6850
to connect:
6854
6851
6855
6852
``` javascript
6856
- const oracledb = require (' oracledb' );
6857
-
6858
- oracledb .getConnection (
6853
+ const connection = await oracledb .getConnection (
6859
6854
{
6860
6855
user : " hr" ,
6861
6856
password : mypw, // mypw contains the hr schema password
6862
6857
connectString : " sales"
6863
- },
6864
- . . .
6858
+ }
6859
+ );
6865
6860
```
6866
6861
6867
6862
This could be defined in a directory server, or in a local
@@ -6903,15 +6898,13 @@ documentation on `tnsnames.ora`][18].
6903
6898
Full connection strings can be embedded in applications:
6904
6899
6905
6900
``` javascript
6906
- const oracledb = require (' oracledb' );
6907
-
6908
- oracledb .getConnection (
6901
+ const connection = await oracledb .getConnection (
6909
6902
{
6910
6903
user : " hr" ,
6911
6904
password : mypw, // mypw contains the hr schema password
6912
6905
connectString : " (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mymachine.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
6913
- },
6914
- . . .
6906
+ }
6907
+ );
6915
6908
```
6916
6909
6917
6910
#### <a name =" notjdbc " ></a > 14.2.4 JDBC and Node-oracledb Connection Strings Compared
@@ -6926,15 +6919,13 @@ jdbc:oracle:thin:@hostname:port/service_name
6926
6919
can use Oracle's Easy Connect syntax in node-oracledb:
6927
6920
6928
6921
``` javascript
6929
- const oracledb = require (' oracledb' );
6930
-
6931
- oracledb .getConnection (
6922
+ const connection = await oracledb .getConnection (
6932
6923
{
6933
6924
user : " hr" ,
6934
6925
password : mypw, // mypw contains the hr schema password
6935
6926
connectString : " hostname:port/service_name"
6936
- },
6937
- . . .
6927
+ }
6928
+ );
6938
6929
```
6939
6930
6940
6931
Alternatively, if a JDBC connection string uses an old-style
@@ -6959,15 +6950,13 @@ finance =
6959
6950
This can be referenced in node-oracledb:
6960
6951
6961
6952
``` javascript
6962
- const oracledb = require (' oracledb' );
6963
-
6964
- oracledb .getConnection (
6953
+ const connection = await oracledb .getConnection (
6965
6954
{
6966
6955
user : " hr" ,
6967
6956
password : mypw, // mypw contains the hr schema password
6968
6957
connectString : " finance"
6969
- },
6970
- . . .
6958
+ }
6959
+ );
6971
6960
```
6972
6961
6973
6962
Alternatively the connection string can be [ embedded] ( #embedtns ) in the application.
@@ -12385,14 +12374,14 @@ const subscrOptions = {
12385
12374
};
12386
12375
12387
12376
async function ProcessAqMessages () {
12388
- connection = await oracledb .getConnection ();
12377
+ const connection = await oracledb .getConnection (); // get connection from a pool
12389
12378
const queue = await connection .queue (queueName);
12390
12379
const msg = await queue .deqOne ();
12391
12380
console .log (msg .payload .toString ()
12392
12381
await connection .close ();
12393
12382
}
12394
12383
12395
- const connection = await oracledb .getConnection ();
12384
+ const connection = await oracledb .getConnection (); // get connection from a pool
12396
12385
await connection .subscribe (queueName, subscrOptions);
12397
12386
await connection .close ();
12398
12387
` ` `
@@ -13339,8 +13328,8 @@ oracledb.getConnection(
13339
13328
` ` `
13340
13329
13341
13330
Since the returned promise will not have a catch block, as the
13342
- developer intended to use the callback programming style, any
13343
- rejections that occur will go unnoticed. Node.js 4.0 added the
13331
+ intention was to use the callback programming style, any rejections
13332
+ that occur will go unnoticed. Node.js 4.0 added the
13344
13333
` unhandledRejection` event to prevent such rejections from going
13345
13334
unnoticed:
13346
13335
0 commit comments