Skip to content

Commit d9aec27

Browse files
committed
Prefer new constants OUT_FORMAT_ARRAY and OUT_FORMAT_OBJECT
1 parent 5087862 commit d9aec27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+335
-318
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@
4444
This is an efficient alternative to `ALTER SESSION SET
4545
CURRENT_SCHEMA`.
4646

47-
- Improved the performance of `oracledb.outFormat = oracledb.OBJECT`.
47+
- Introduced [Query `outFormat`
48+
Constants](https://oracle.github.io/node-oracledb/doc/api.html#oracledbconstantsoutformat)
49+
`oracledb.OUT_FORMAT_ARRAY` and `oracledb.OUT_FORMAT_OBJECT`. The
50+
previous constants `oracledb.ARRAY` and `oracledb.OBJECT` are
51+
deprecated but still usable.
52+
53+
- Improved the performance of `oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT`.
4854

4955
- Updated the JavaScript syntax in class implementations.
5056

doc/api.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ node myscript.js
489489

490490
const oracledb = require('oracledb');
491491

492-
oracledb.outFormat = oracledb.OBJECT;
492+
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
493493

494494
const mypw = ... // set mypw to the hr schema password
495495

@@ -699,8 +699,13 @@ Constants for the query result [outFormat](#propdboutformat) option:
699699

700700
Constant Name | Value |Description
701701
-------------------------------------|-------|-----------------------------------------------
702-
`oracledb.ARRAY` | 4001 | Fetch each row as array of column values
703-
`oracledb.OBJECT` | 4002 | Fetch each row as an object
702+
`oracledb.OUT_FORMAT_ARRAY` | 4001 | Fetch each row as array of column values
703+
`oracledb.OUT_FORMAT_OBJECT` | 4002 | Fetch each row as an object
704+
705+
The `oracledb.OUT_FORMAT_ARRAY` and `oracledb.OUT_FORMAT_OBJECT`
706+
constants were introduced in node-oracledb 4.0. The previous
707+
constants `oracledb.ARRAY` and `oracledb.OBJECT` are deprecated but
708+
still usable.
704709

705710
#### <a name="oracledbconstantsnodbtype"></a> 3.1.2 Node-oracledb Type Constants
706711

@@ -1323,18 +1328,18 @@ both [ResultSet](#propexecresultset) and non-ResultSet queries. It
13231328
can be used for top level queries and REF CURSOR output.
13241329

13251330
This can be either of
1326-
the [Oracledb constants](#oracledbconstantsoutformat) `oracledb.ARRAY` or
1327-
`oracledb.OBJECT`. The default value is `oracledb.ARRAY` which is more efficient.
1331+
the [Oracledb constants](#oracledbconstantsoutformat)
1332+
`oracledb.OUT_FORMAT_ARRAY` or `oracledb.OUT_FORMAT_OBJECT`. The default value
1333+
is `oracledb.OUT_FORMAT_ARRAY` which is more efficient.
13281334

1329-
If specified as `oracledb.ARRAY`, each row is fetched as an array of column
1330-
values.
1335+
If specified as `oracledb.OUT_FORMAT_ARRAY`, each row is fetched as an array of
1336+
column values.
13311337

1332-
If specified as `oracledb.OBJECT`, each row is fetched as a JavaScript object.
1333-
The object has a property for each column name, with the property
1334-
value set to the respective column value. The property name follows
1335-
Oracle's standard name-casing rules. It will commonly be uppercase,
1336-
since most applications create tables using unquoted, case-insensitive
1337-
names.
1338+
If specified as `oracledb.OUT_FORMAT_OBJECT`, each row is fetched as a
1339+
JavaScript object. The object has a property for each column name, with the
1340+
property value set to the respective column value. The property name follows
1341+
Oracle's standard name-casing rules. It will commonly be uppercase, since most
1342+
applications create tables using unquoted, case-insensitive names.
13381343

13391344
This property may be overridden in
13401345
an [`execute()`](#executeoptions)
@@ -1346,7 +1351,7 @@ See [Query Output Formats](#queryoutputformats) for more information.
13461351

13471352
```javascript
13481353
const oracledb = require('oracledb');
1349-
oracledb.outFormat = oracledb.ARRAY;
1354+
oracledb.outFormat = oracledb.OUT_FORMAT_ARRAY;
13501355
```
13511356

13521357
#### <a name="propdbpoolincrement"></a> 3.2.15 `oracledb.poolIncrement`
@@ -3071,8 +3076,8 @@ contains an array of fetched rows. It will be NULL if there is an
30713076
error or the SQL statement was not a SELECT statement. By default,
30723077
the rows are in an array of column value arrays, but this can be
30733078
changed to arrays of objects by setting
3074-
[`outFormat`](#propdboutformat) to `oracledb.OBJECT`. If a single row
3075-
is fetched, then `rows` is an array that contains one single row.
3079+
[`outFormat`](#propdboutformat) to `oracledb.OUT_FORMAT_OBJECT`. If a single
3080+
row is fetched, then `rows` is an array that contains one single row.
30763081
30773082
The number of rows returned is limited by
30783083
[`oracledb.maxRows`](#propdbmaxrows) or the
@@ -8399,10 +8404,10 @@ If run with Oracle's sample HR schema, the output is:
83998404
Using this format is recommended for efficiency.
84008405
84018406
Alternatively, rows may be fetched as JavaScript objects. To do so,
8402-
specify the `outFormat` option to be `oracledb.OBJECT`:
8407+
specify the `outFormat` option to be `oracledb.OUT_FORMAT_OBJECT`:
84038408
84048409
```javascript
8405-
oracledb.outFormat = oracledb.OBJECT;
8410+
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
84068411
```
84078412
84088413
The value can also be set as an `execute()` option:
@@ -8413,7 +8418,7 @@ const result = await connection.execute(
84138418
FROM departments
84148419
WHERE manager_id < :id`,
84158420
[110], // bind value for :id
8416-
{ outFormat: oracledb.OBJECT }
8421+
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
84178422
);
84188423

84198424
console.log(result.rows);
@@ -9336,7 +9341,7 @@ const result = await connection.execute(
93369341
FROM parts
93379342
ORDER BY id`,
93389343
[],
9339-
{ outFormat: oracledb.OBJECT }
9344+
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
93409345
);
93419346

93429347
console.log(result.rows);

examples/connectionpool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function dostuff() {
7777
connection = await oracledb.getConnection();
7878
const sql = `SELECT sysdate FROM dual WHERE :b = 1`;
7979
const binds = [1];
80-
const options = { outFormat: oracledb.OBJECT };
80+
const options = { outFormat: oracledb.OUT_FORMAT_OBJECT };
8181
const result = await connection.execute(sql, binds, options);
8282
console.log(result);
8383
} catch (err) {

examples/date.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ process.env.ORA_SDTZ = 'UTC';
3535
const oracledb = require('oracledb');
3636
const dbConfig = require('./dbconfig.js');
3737

38-
oracledb.outFormat = oracledb.OBJECT;
38+
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
3939

4040
async function run() {
4141

examples/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function run() {
8888

8989
// For a complete list of options see the documentation.
9090
options = {
91-
outFormat: oracledb.OBJECT // query result format
91+
outFormat: oracledb.OUT_FORMAT_OBJECT // query result format
9292
// extendedMetaData: true, // get extra metadata
9393
// fetchArraySize: 100 // internal buffer allocation size for tuning
9494
};

examples/impres.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
const oracledb = require('oracledb');
3333
const dbConfig = require('./dbconfig.js');
3434

35-
oracledb.outFormat = oracledb.OBJECT;
35+
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
3636

3737
async function run() {
3838
let connection;

examples/lobbinds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async function doshowvtemplob(connection) {
291291
const result = await connection.execute(
292292
`SELECT * FROM V$TEMPORARY_LOBS`,
293293
[],
294-
{ outFormat: oracledb.OBJECT }
294+
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
295295
);
296296
297297
console.log(result.rows[0]);

examples/select1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function run() {
6666
// the documentation.
6767
{
6868
maxRows: 1
69-
//, outFormat: oracledb.OBJECT // query result format
69+
//, outFormat: oracledb.OUT_FORMAT_OBJECT // query result format
7070
//, extendedMetaData: true // get extra metadata
7171
//, fetchArraySize: 100 // internal buffer allocation size for tuning
7272
});

examples/select2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const dbConfig = require('./dbconfig.js');
4949

5050
// This script sets outFormat in the execute() call but it could be set here instead:
5151
//
52-
// oracledb.outFormat = oracledb.OBJECT;
52+
// oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
5353

5454
async function run() {
5555

@@ -82,7 +82,7 @@ async function run() {
8282
result = await connection.execute(
8383
sql,
8484
{}, // A bind parameter is needed to disambiguate the following options parameter and avoid ORA-01036
85-
{ outFormat: oracledb.OBJECT }); // outFormat can be OBJECT or ARRAY. The default is ARRAY
85+
{ outFormat: oracledb.OUT_FORMAT_OBJECT }); // outFormat can be OBJECT or ARRAY. The default is ARRAY
8686
console.log("----- Cities beginning with 'S' (OBJECT output format) --------");
8787
console.log(result.rows);
8888

src/njsOracleDb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ static njsConstant njsClassConstants[] = {
196196
{ "BIND_OUT", NJS_BIND_OUT },
197197

198198
// outFormat values
199+
{ "OUT_FORMAT_ARRAY", NJS_ROWS_ARRAY },
200+
{ "OUT_FORMAT_OBJECT", NJS_ROWS_OBJECT },
199201
{ "ARRAY", NJS_ROWS_ARRAY },
200202
{ "OBJECT", NJS_ROWS_OBJECT },
201203

0 commit comments

Comments
 (0)