Skip to content

Commit c614869

Browse files
committed
A bit more async-ification
1 parent 7965a3a commit c614869

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

doc/api.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,9 +4815,7 @@ time `pool.getConnection()` is called, a connection for that user is
48154815
returned:
48164816
48174817
```javascript
4818-
pool.getConnection(
4819-
function (err, conn) { ... }
4820-
);
4818+
const connection = await pool.getConnection();
48214819
```
48224820

48234821
If a heterogeneous pool was created by setting
@@ -4826,13 +4824,12 @@ creation and credentials were omitted, then the user name and password
48264824
may be used in `pool.getConnection()` like:
48274825

48284826
```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+
);,
48364833
```
48374834

48384835
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
68356832
```javascript
68366833
const oracledb = require('oracledb');
68376834

6838-
oracledb.getConnection(
6835+
const connection = await oracledb.getConnection(
68396836
{
68406837
user : "hr",
68416838
password : mypw, // mypw contains the hr schema password
68426839
connectString : "localhost/XEPDB1"
6843-
},
6844-
. . .
6840+
}
6841+
);
68456842
```
68466843

68476844
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
68536850
to connect:
68546851

68556852
```javascript
6856-
const oracledb = require('oracledb');
6857-
6858-
oracledb.getConnection(
6853+
const connection = await oracledb.getConnection(
68596854
{
68606855
user : "hr",
68616856
password : mypw, // mypw contains the hr schema password
68626857
connectString : "sales"
6863-
},
6864-
. . .
6858+
}
6859+
);
68656860
```
68666861

68676862
This could be defined in a directory server, or in a local
@@ -6903,15 +6898,13 @@ documentation on `tnsnames.ora`][18].
69036898
Full connection strings can be embedded in applications:
69046899

69056900
```javascript
6906-
const oracledb = require('oracledb');
6907-
6908-
oracledb.getConnection(
6901+
const connection = await oracledb.getConnection(
69096902
{
69106903
user : "hr",
69116904
password : mypw, // mypw contains the hr schema password
69126905
connectString : "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mymachine.example.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))"
6913-
},
6914-
. . .
6906+
}
6907+
);
69156908
```
69166909

69176910
#### <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
69266919
can use Oracle's Easy Connect syntax in node-oracledb:
69276920

69286921
```javascript
6929-
const oracledb = require('oracledb');
6930-
6931-
oracledb.getConnection(
6922+
const connection = await oracledb.getConnection(
69326923
{
69336924
user : "hr",
69346925
password : mypw, // mypw contains the hr schema password
69356926
connectString : "hostname:port/service_name"
6936-
},
6937-
. . .
6927+
}
6928+
);
69386929
```
69396930

69406931
Alternatively, if a JDBC connection string uses an old-style
@@ -6959,15 +6950,13 @@ finance =
69596950
This can be referenced in node-oracledb:
69606951

69616952
```javascript
6962-
const oracledb = require('oracledb');
6963-
6964-
oracledb.getConnection(
6953+
const connection = await oracledb.getConnection(
69656954
{
69666955
user : "hr",
69676956
password : mypw, // mypw contains the hr schema password
69686957
connectString : "finance"
6969-
},
6970-
. . .
6958+
}
6959+
);
69716960
```
69726961

69736962
Alternatively the connection string can be [embedded](#embedtns) in the application.
@@ -12385,14 +12374,14 @@ const subscrOptions = {
1238512374
};
1238612375

1238712376
async function ProcessAqMessages() {
12388-
connection = await oracledb.getConnection();
12377+
const connection = await oracledb.getConnection(); // get connection from a pool
1238912378
const queue = await connection.queue(queueName);
1239012379
const msg = await queue.deqOne();
1239112380
console.log(msg.payload.toString()
1239212381
await connection.close();
1239312382
}
1239412383

12395-
const connection = await oracledb.getConnection();
12384+
const connection = await oracledb.getConnection(); // get connection from a pool
1239612385
await connection.subscribe(queueName, subscrOptions);
1239712386
await connection.close();
1239812387
```
@@ -13339,8 +13328,8 @@ oracledb.getConnection(
1333913328
```
1334013329
1334113330
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
1334413333
`unhandledRejection` event to prevent such rejections from going
1334513334
unnoticed:
1334613335

0 commit comments

Comments
 (0)