oracledb 3.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +277 -4
  2. package/LICENSE.md +5906 -360
  3. package/README.md +7 -8
  4. package/build/Release/oracledb-4.2.0-darwin-x64.node +0 -0
  5. package/build/Release/oracledb-4.2.0-darwin-x64.node-buildinfo.txt +1 -0
  6. package/build/Release/oracledb-4.2.0-linux-x64.node +0 -0
  7. package/build/Release/oracledb-4.2.0-linux-x64.node-buildinfo.txt +1 -0
  8. package/build/Release/oracledb-4.2.0-win32-x64.node +0 -0
  9. package/build/Release/oracledb-4.2.0-win32-x64.node-buildinfo.txt +1 -0
  10. package/lib/aqDeqOptions.js +29 -0
  11. package/lib/aqEnqOptions.js +29 -0
  12. package/lib/aqMessage.js +29 -0
  13. package/lib/aqQueue.js +84 -0
  14. package/lib/connection.js +294 -326
  15. package/lib/dbObject.js +144 -0
  16. package/lib/lob.js +125 -132
  17. package/lib/oracledb.js +162 -483
  18. package/lib/pool.js +95 -109
  19. package/lib/{querystream.js → queryStream.js} +31 -30
  20. package/lib/resultset.js +75 -125
  21. package/lib/sodaCollection.js +99 -165
  22. package/lib/sodaDatabase.js +58 -133
  23. package/lib/sodaDocCursor.js +27 -70
  24. package/lib/sodaDocument.js +35 -65
  25. package/lib/sodaOperation.js +96 -252
  26. package/lib/util.js +78 -71
  27. package/package/README.md +41 -36
  28. package/package/install.js +30 -24
  29. package/package.json +2 -2
  30. package/build/Release/oracledb-abi48-darwin-x64.node +0 -0
  31. package/build/Release/oracledb-abi48-darwin-x64.node-buildinfo.txt +0 -1
  32. package/build/Release/oracledb-abi48-linux-x64.node +0 -0
  33. package/build/Release/oracledb-abi48-linux-x64.node-buildinfo.txt +0 -1
  34. package/build/Release/oracledb-abi48-win32-x64.node +0 -0
  35. package/build/Release/oracledb-abi48-win32-x64.node-buildinfo.txt +0 -1
  36. package/build/Release/oracledb-abi57-darwin-x64.node +0 -0
  37. package/build/Release/oracledb-abi57-darwin-x64.node-buildinfo.txt +0 -1
  38. package/build/Release/oracledb-abi57-linux-x64.node +0 -0
  39. package/build/Release/oracledb-abi57-linux-x64.node-buildinfo.txt +0 -1
  40. package/build/Release/oracledb-abi57-win32-x64.node +0 -0
  41. package/build/Release/oracledb-abi57-win32-x64.node-buildinfo.txt +0 -1
  42. package/build/Release/oracledb-abi64-darwin-x64.node +0 -0
  43. package/build/Release/oracledb-abi64-darwin-x64.node-buildinfo.txt +0 -1
  44. package/build/Release/oracledb-abi64-linux-x64.node +0 -0
  45. package/build/Release/oracledb-abi64-linux-x64.node-buildinfo.txt +0 -1
  46. package/build/Release/oracledb-abi64-win32-x64.node +0 -0
  47. package/build/Release/oracledb-abi64-win32-x64.node-buildinfo.txt +0 -1
  48. package/build/Release/oracledb-abi67-darwin-x64.node +0 -0
  49. package/build/Release/oracledb-abi67-darwin-x64.node-buildinfo.txt +0 -1
  50. package/build/Release/oracledb-abi67-linux-x64.node +0 -0
  51. package/build/Release/oracledb-abi67-linux-x64.node-buildinfo.txt +0 -1
  52. package/build/Release/oracledb-abi67-win32-x64.node +0 -0
  53. package/build/Release/oracledb-abi67-win32-x64.node-buildinfo.txt +0 -1
package/lib/pool.js CHANGED
@@ -1,34 +1,33 @@
1
- /* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. */
2
-
3
- /******************************************************************************
4
- *
5
- * You may not use the identified files except in compliance with the Apache
6
- * License, Version 2.0 (the "License.")
7
- *
8
- * You may obtain a copy of the License at
9
- * http://www.apache.org/licenses/LICENSE-2.0.
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- *
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- *
18
- *****************************************************************************/
1
+ // Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // You may not use the identified files except in compliance with the Apache
6
+ // License, Version 2.0 (the "License.")
7
+ //
8
+ // You may obtain a copy of the License at
9
+ // http://www.apache.org/licenses/LICENSE-2.0.
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ //
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ //
18
+ //-----------------------------------------------------------------------------
19
19
 
20
20
  'use strict';
21
21
 
22
- var connection = require('./connection.js');
23
- var nodbUtil = require('./util.js');
24
- var getConnectionPromisified;
25
- var closePromisified;
22
+ const EventEmitter = require('events');
23
+ const nodbUtil = require('./util.js');
24
+ const util = require('util');
26
25
 
27
26
  // completeConnectionRequest does the actual work of getting a connection from
28
27
  // a pool. It's abstracted out so it can be called from getConnection and
29
28
  // checkRequestQueue consistently.
30
29
  function completeConnectionRequest(config, getConnectionCb) {
31
- var self = this;
30
+ const self = this;
32
31
 
33
32
  // Incrementing _connectionsOut prior to making the async call to get a connection
34
33
  // to prevent other connection requests from exceeding the poolMax.
@@ -53,8 +52,6 @@ function completeConnectionRequest(config, getConnectionCb) {
53
52
  return;
54
53
  }
55
54
 
56
- connection.extend(connInst, self._oracledb, self);
57
-
58
55
  connInst.on('_after_close', function() {
59
56
  self._connectionsOut -= 1;
60
57
  if (self._connectionsOut == 0 && self._closeCb)
@@ -92,9 +89,9 @@ function completeConnectionRequest(config, getConnectionCb) {
92
89
  // when requests for connections should be completed and cancels any timeout
93
90
  // that may have been associated with the request.
94
91
  function checkRequestQueue() {
95
- var self = this;
96
- var payload;
97
- var waitTime;
92
+ const self = this;
93
+ let payload;
94
+ let waitTime;
98
95
 
99
96
  if (self._connRequestQueue.length === 0 || self._connectionsOut === self.poolMax) {
100
97
  return; // no need to do any work
@@ -128,9 +125,9 @@ function checkRequestQueue() {
128
125
  // queue for too long. The number of milliseconds can be set via queueTimeout
129
126
  // property of the poolAttrs used when creating a pool.
130
127
  function onRequestTimeout(timerIdx) {
131
- var self = this;
132
- var payloadToDequeue = self._connRequestTimersMap[timerIdx];
133
- var requestIndex;
128
+ const self = this;
129
+ let payloadToDequeue = self._connRequestTimersMap[timerIdx];
130
+ let requestIndex;
134
131
 
135
132
  if (payloadToDequeue) {
136
133
  if (self._enableStats) {
@@ -143,7 +140,7 @@ function onRequestTimeout(timerIdx) {
143
140
  self._connRequestQueue.splice(requestIndex, 1);
144
141
  delete self._connRequestTimersMap[timerIdx];
145
142
 
146
- payloadToDequeue.getConnectionCb(new Error(nodbUtil.getErrorMessage('NJS-040')));
143
+ payloadToDequeue.getConnectionCb(new Error(nodbUtil.getErrorMessage('NJS-040', self.queueTimeout)));
147
144
  }
148
145
  }
149
146
 
@@ -152,26 +149,25 @@ function onRequestTimeout(timerIdx) {
152
149
  // immediately; otherwise, the request will be queued for up to queueTimeout
153
150
  // milliseconds.
154
151
  function getConnection(a1, a2) {
155
- var self = this;
156
- var payload;
157
- var timeoutHandle;
158
- var timerIdx;
159
- var poolMax;
160
- var getConnectionCb;
161
- var options = {};
162
-
163
- nodbUtil.assert(arguments.length >= 1 && arguments.length <= 2, 'NJS-009');
152
+ const self = this;
153
+ let payload;
154
+ let timeoutHandle;
155
+ let timerIdx;
156
+ let poolMax;
157
+ let getConnectionCb;
158
+ let options = {};
159
+
160
+ nodbUtil.checkAsyncArgs(arguments, 1, 2);
164
161
  switch (arguments.length) {
165
162
  case 1:
166
163
  getConnectionCb = a1;
167
164
  break;
168
165
  case 2:
169
- nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-006', 1);
166
+ nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-005', 1);
170
167
  options = a1;
171
168
  getConnectionCb = a2;
172
169
  break;
173
170
  }
174
- nodbUtil.assert(typeof getConnectionCb === 'function', 'NJS-006', arguments.length);
175
171
 
176
172
  if (self.status === self._oracledb.POOL_STATUS_DRAINING) { // closing soon
177
173
  getConnectionCb(new Error(nodbUtil.getErrorMessage('NJS-064')));
@@ -233,28 +229,27 @@ function getConnection(a1, a2) {
233
229
  }
234
230
  }
235
231
 
236
- getConnectionPromisified = nodbUtil.promisify(getConnection);
237
232
 
238
233
  function close(a1, a2) {
239
234
  const upperLimitTimeout = 2147483647;
240
- var self = this;
241
- var forceClose;
242
- var drainTime;
243
- var timeoutCb;
244
- var closeCb;
235
+ const self = this;
236
+ let forceClose;
237
+ let drainTime;
238
+ let timeoutCb;
239
+ let closeCb;
245
240
 
246
- nodbUtil.assert(arguments.length === 1 || arguments.length === 2, 'NJS-009');
241
+ nodbUtil.checkArgCount(arguments, 1, 2);
247
242
 
248
243
  switch (arguments.length) {
249
244
  case 1:
250
- nodbUtil.assert(typeof a1 === 'function', 'NJS-006', 1);
245
+ nodbUtil.assert(typeof a1 === 'function', 'NJS-005', 1);
251
246
  closeCb = a1;
252
247
  drainTime = 0;
253
248
  forceClose = false;
254
249
  break;
255
250
  case 2:
256
- nodbUtil.assert(typeof a1 === 'number', 'NJS-006', 1);
257
- nodbUtil.assert(typeof a2 === 'function', 'NJS-006', 2);
251
+ nodbUtil.assert(typeof a1 === 'number', 'NJS-005', 1);
252
+ nodbUtil.assert(typeof a2 === 'function', 'NJS-005', 2);
258
253
  closeCb = a2;
259
254
  forceClose = true;
260
255
 
@@ -262,7 +257,10 @@ function close(a1, a2) {
262
257
  drainTime = self._connectionsOut === 0 ? 0 : a1 * 1000; // a1 represents seconds of time
263
258
 
264
259
  // SetTimeout does not accept numbers greater than a 32-bit signed integer.
265
- nodbUtil.assert(drainTime >= 0 && drainTime <= upperLimitTimeout, 'NJS-005', 1);
260
+ if (drainTime < 0 || isNaN(drainTime) || drainTime > upperLimitTimeout) {
261
+ closeCb(new Error(nodbUtil.getErrorMessage('NJS-005', 1)));
262
+ return;
263
+ }
266
264
  break;
267
265
  }
268
266
 
@@ -279,7 +277,7 @@ function close(a1, a2) {
279
277
  self._closeCb = function() {
280
278
  self._close({forceClose : forceClose}, function(err) {
281
279
  if (!err) {
282
- self.status = self._oracledb.POOL_STATUS_CLOSED;
280
+ self._status = self._oracledb.POOL_STATUS_CLOSED;
283
281
  self.emit('_after_close', self);
284
282
  }
285
283
  self._closeCb = undefined;
@@ -290,7 +288,7 @@ function close(a1, a2) {
290
288
  };
291
289
 
292
290
  if (forceClose) {
293
- self.status = self._oracledb.POOL_STATUS_DRAINING;
291
+ self._status = self._oracledb.POOL_STATUS_DRAINING;
294
292
  }
295
293
  if (drainTime === 0) {
296
294
  self._closeCb();
@@ -300,15 +298,14 @@ function close(a1, a2) {
300
298
 
301
299
  }
302
300
 
303
- closePromisified = nodbUtil.promisify(close);
304
301
 
305
- // logStats is used to add a hidden method (_logStats) to each pool instance. This
306
- // provides an easy way to log out the statistics related information that's collected
307
- // when _enableStats is set to true when creating a pool. This functionality may
308
- // be altered or enhanced in the future.
302
+ // logStats is used to add a hidden method (_logStats) to each pool instance.
303
+ // This provides an easy way to log out the statistics related information
304
+ // that's collected when _enableStats is set to true when creating a pool. This
305
+ // functionality may be altered or enhanced in the future.
309
306
  function logStats() {
310
- var self = this;
311
- var averageTimeInQueue;
307
+ const self = this;
308
+ let averageTimeInQueue;
312
309
 
313
310
  if (self.status === self._oracledb.POOL_STATUS_CLOSED) {
314
311
  throw new Error(nodbUtil.getErrorMessage('NJS-065'));
@@ -357,11 +354,11 @@ function logStats() {
357
354
  console.log('...process.env.UV_THREADPOOL_SIZE:', process.env.UV_THREADPOOL_SIZE);
358
355
  }
359
356
 
360
- // The extend method is used to extend Pool instances from the C layer with custom
361
- // properties, methods, and method overrides. References to the original methods are
362
- // maintained so they can be invoked by the overriding method at the right time.
363
- function extend(pool, poolAttrs, poolAlias, oracledb) {
364
- var queueTimeout;
357
+ // sets up the instance with additional attributes used for logging statistics
358
+ // and managing the connection queue
359
+ function setup(poolAttrs, poolAlias, oracledb) {
360
+ const self = this;
361
+ let queueTimeout;
365
362
 
366
363
  if (typeof poolAttrs.queueTimeout !== 'undefined') {
367
364
  queueTimeout = poolAttrs.queueTimeout;
@@ -369,23 +366,15 @@ function extend(pool, poolAttrs, poolAlias, oracledb) {
369
366
  queueTimeout = oracledb.queueTimeout;
370
367
  }
371
368
 
372
- nodbUtil.makeEventEmitter(pool);
373
-
374
- // Using Object.defineProperties to add properties to the Pool instance with special
375
- // properties, such as enumerable but not writable.
369
+ // Using Object.defineProperties to add properties to the Pool instance with
370
+ // special properties, such as enumerable but not writable.
376
371
  Object.defineProperties(
377
- pool,
372
+ self,
378
373
  {
379
- _oracledb: { // storing a reference to the base instance to avoid circular references with require
380
- value: oracledb
381
- },
382
374
  queueTimeout: { // milliseconds a connection request can spend in queue before being failed
383
375
  enumerable: true,
384
376
  get: function() {
385
377
  return queueTimeout;
386
- },
387
- set: function() {
388
- throw new Error(nodbUtil.getErrorMessage('NJS-014', 'queueTimeout'));
389
378
  }
390
379
  },
391
380
  _closeCb: { // performs close when drainTime expires or connections closed
@@ -455,53 +444,50 @@ function extend(pool, poolAttrs, poolAlias, oracledb) {
455
444
  value: {},
456
445
  writable: true
457
446
  },
458
- _getConnection: {
459
- value: pool.getConnection
447
+ _status: { // open/closing/closed
448
+ value: oracledb.POOL_STATUS_OPEN,
449
+ writable: true
460
450
  },
461
451
  poolAlias: {
462
452
  enumerable: true,
463
453
  get: function() {
464
454
  return poolAlias;
465
- },
466
- set: function() {
467
- throw new Error(nodbUtil.getErrorMessage('NJS-014', 'poolAlias'));
468
455
  }
469
456
  },
470
- getConnection: {
471
- value: getConnectionPromisified,
472
- enumerable: true,
473
- writable: true
474
- },
475
- _close: {
476
- value: pool.close
477
- },
478
- close: {
479
- value: closePromisified,
480
- enumerable: true,
481
- writable: true
482
- },
483
- terminate: { // alias for close
484
- value: closePromisified,
485
- enumerable: true,
486
- writable: true
487
- },
488
457
  status: { // open/closing/closed
489
- writable: true,
490
458
  enumerable: true,
491
- value: oracledb.POOL_STATUS_OPEN
459
+ get: function() {
460
+ return this._status;
461
+ }
492
462
  },
493
463
  sessionCallback: { // session callback
494
464
  enumerable: true,
495
465
  get: function() {
496
466
  return poolAttrs.sessionCallback;
497
- },
498
- set: function() {
499
- throw new Error(nodbUtil.getErrorMessage('NJS-014',
500
- 'sessionCallback'));
501
467
  }
502
468
  }
503
469
  }
504
470
  );
505
471
  }
506
472
 
507
- module.exports.extend = extend;
473
+
474
+ class Pool extends EventEmitter {
475
+
476
+ _extend(oracledb) {
477
+ this._oracledb = oracledb;
478
+ this._setup = setup;
479
+ this.close = nodbUtil.promisify(oracledb, close);
480
+ this.getConnection = nodbUtil.promisify(oracledb, getConnection);
481
+ this.terminate = this.close;
482
+ }
483
+
484
+ // temporary method for determining if an object is a date until
485
+ // napi_is_date() can be used (when N-API v5 can be used)
486
+ _isDate(val) {
487
+ return util.isDate(val);
488
+ }
489
+
490
+ }
491
+
492
+
493
+ module.exports = Pool;
@@ -1,37 +1,34 @@
1
- /* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. */
2
-
3
- /******************************************************************************
4
- *
5
- * You may not use the identified files except in compliance with the Apache
6
- * License, Version 2.0 (the "License.")
7
- *
8
- * You may obtain a copy of the License at
9
- * http://www.apache.org/licenses/LICENSE-2.0.
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- *
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- *
18
- *****************************************************************************/
1
+ // Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved
2
+
3
+ //-----------------------------------------------------------------------------
4
+ //
5
+ // You may not use the identified files except in compliance with the Apache
6
+ // License, Version 2.0 (the "License.")
7
+ //
8
+ // You may obtain a copy of the License at
9
+ // http://www.apache.org/licenses/LICENSE-2.0.
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ //
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ //
18
+ //-----------------------------------------------------------------------------
19
19
 
20
20
  'use strict';
21
21
 
22
- var util = require('util');
23
- var Readable = require('stream').Readable;
22
+ const util = require('util');
23
+ const Readable = require('stream').Readable;
24
24
 
25
25
  // This class was originally based on https://github.com/sagiegurari/simple-oracledb/blob/master/lib/resultset-read-stream.js
26
- function QueryStream(resultSet, oracledb) {
27
- var self = this;
26
+ function QueryStream(resultSet) {
27
+ const self = this;
28
28
 
29
29
  Object.defineProperties(
30
30
  self,
31
31
  {
32
- _oracledb: { // storing a reference to the base instance to avoid circular references with require
33
- value: oracledb
34
- },
35
32
  _resultSet: {
36
33
  value: resultSet,
37
34
  writable: true
@@ -70,7 +67,11 @@ function QueryStream(resultSet, oracledb) {
70
67
  // Using setImmediate to ensure that end event handlers are processed
71
68
  // before the destroy logic is invoked.
72
69
  setImmediate(function() {
73
- self._destroy(null, function() {});
70
+ self._destroy(null, function(err) {
71
+ if (err) {
72
+ self.emit('error', err);
73
+ }
74
+ });
74
75
  });
75
76
  });
76
77
  }
@@ -80,7 +81,7 @@ util.inherits(QueryStream, Readable);
80
81
  // The _open method is called by Connection.execute() when the ResultSet is
81
82
  // ready.
82
83
  QueryStream.prototype._open = function(err, rs) {
83
- var self = this;
84
+ const self = this;
84
85
 
85
86
  if (err) {
86
87
  self.emit('error', err);
@@ -99,7 +100,7 @@ QueryStream.prototype._open = function(err, rs) {
99
100
  };
100
101
 
101
102
  QueryStream.prototype._read = function() {
102
- var self = this;
103
+ const self = this;
103
104
 
104
105
  if (!self._resultSet) {
105
106
  // Still waiting on the ResultSet to be added via _open, add an event listener
@@ -163,7 +164,7 @@ QueryStream.prototype._read = function() {
163
164
  // The destroyCallback is only used when _close is invoked by _destroy. In that
164
165
  // case, errors are passed back via the callback rather than emitted.
165
166
  QueryStream.prototype._close = function(callback) {
166
- var self = this;
167
+ const self = this;
167
168
 
168
169
  if (self._closed) {
169
170
  return;
@@ -213,7 +214,7 @@ QueryStream.prototype._close = function(callback) {
213
214
  // pass an error that will be emitted after the ResultSet is closed (provided
214
215
  // no other errors occur).
215
216
  QueryStream.prototype._destroy = function(userErr, callback) {
216
- var self = this;
217
+ const self = this;
217
218
 
218
219
  this._close(function(closeErr) {
219
220
  // Invoking this callback will signal the end of destroy. If an error is