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
@@ -0,0 +1,144 @@
1
+ // Copyright (c) 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
+
20
+ 'use strict';
21
+
22
+ const util = require('util');
23
+
24
+ // define base database object class; instances of this class are never
25
+ // instantiated; instead, classes subclassed from this one will be
26
+ // instantiated; a cache of these classes are maintained on each connection
27
+ class BaseDbObject {
28
+
29
+ // extend class with promisified functions
30
+ _extend(oracledb) {
31
+ this._oracledb = oracledb;
32
+ }
33
+
34
+ // initialize object with value
35
+ _initialize(initialValue) {
36
+ if (this.isCollection) {
37
+ for (let i = 0; i < initialValue.length; i++) {
38
+ this.append(initialValue[i]);
39
+ }
40
+ } else {
41
+ Object.assign(this, initialValue);
42
+ }
43
+ }
44
+
45
+ // return as a plain object
46
+ _toPojo() {
47
+ if (this.isCollection) {
48
+ return this.getValues();
49
+ }
50
+ const result = {};
51
+ for (let name in this.attributes) {
52
+ let value = this[name];
53
+ if (value instanceof BaseDbObject) {
54
+ value = value._toPojo();
55
+ }
56
+ result[name] = value;
57
+ }
58
+ return result;
59
+ }
60
+
61
+ // custom inspection routine
62
+ [util.inspect.custom](depth, options) {
63
+ return '[' + this.fqn + '] ' + util.inspect(this._toPojo(), options);
64
+ }
65
+
66
+ [Symbol.iterator]() {
67
+ if (this.isCollection) {
68
+ const values = this.getValues();
69
+ return values[Symbol.iterator]();
70
+ }
71
+ throw TypeError("obj is not iterable");
72
+ }
73
+
74
+ [Symbol.toPrimitive](hint) {
75
+ switch (hint) {
76
+ case 'number':
77
+ return NaN;
78
+ default:
79
+ return '[' + this.fqn + '] ' + util.inspect(this._toPojo(), {});
80
+ }
81
+ }
82
+
83
+ get [Symbol.toStringTag]() {
84
+ return this.fqn;
85
+ }
86
+
87
+ toJSON() {
88
+ return this._toPojo();
89
+ }
90
+
91
+ }
92
+
93
+
94
+ // define proxy handler used for collections
95
+ BaseDbObject._collectionProxyHandler = {
96
+
97
+ deleteProperty(target, prop) {
98
+ if (typeof prop === 'string') {
99
+ const index = +prop;
100
+ if (!isNaN(index)) {
101
+ return target.deleteElement(index);
102
+ }
103
+ }
104
+ return delete target[prop];
105
+ },
106
+
107
+ get(target, prop) {
108
+ if (typeof prop === 'string') {
109
+
110
+ // when binding collections, we must be consistent in getting the target
111
+ // of the proxy, since napi_wrap() called on the proxy will not be
112
+ // available when calling napi_unwrap() on the target; this property
113
+ // forces the target to get returned
114
+ if (prop === '_target') {
115
+ return target;
116
+ }
117
+ const index = +prop;
118
+ if (!isNaN(index)) {
119
+ return target.getElement(index);
120
+ }
121
+ }
122
+ const value = target[prop];
123
+ if (typeof value === 'function') {
124
+ return value.bind(target);
125
+ }
126
+ return value;
127
+ },
128
+
129
+ set(target, prop, value) {
130
+ if (typeof prop === 'string') {
131
+ const index = +prop;
132
+ if (!isNaN(index)) {
133
+ target.setElement(index, value);
134
+ return true;
135
+ }
136
+ }
137
+ target[prop] = value;
138
+ return true;
139
+ }
140
+
141
+ };
142
+
143
+
144
+ module.exports = BaseDbObject;
package/lib/lob.js CHANGED
@@ -1,153 +1,146 @@
1
- /* Copyright (c) 2016, 2017, 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 Duplex = require('stream').Duplex;
23
- var util = require('util');
24
- var nodbUtil = require('./util.js');
25
- var closePromisified;
22
+ const Duplex = require('stream').Duplex;
23
+ const nodbUtil = require('./util.js');
24
+ const util = require('util');
26
25
 
27
- util.inherits(Lob, Duplex);
28
-
29
- // the Lob class is used to support the streaming of LOB data to/from the
30
- // database; the iLob refers to the C++ implementation of the Lob class
31
- function Lob(iLob, opt, oracledb) {
32
- Duplex.call(this, opt);
33
-
34
- this.iLob = iLob;
35
-
36
- Object.defineProperties(
37
- this,
38
- {
39
- _oracledb: { // _oracledb property used by promisify () in util.js
40
- value: oracledb
41
- },
42
- _autoCloseLob: { // Tells whether to close at the end of stream or not
43
- value: iLob.autoCloseLob,
44
- writable: false
45
- },
46
- chunkSize: {
47
- value: iLob.chunkSize,
48
- writable: false
49
- },
50
- length: {
51
- get: function() {
52
- return iLob.length;
53
- }
54
- },
55
- pieceSize: {
56
- get: function() {
57
- return iLob.pieceSize;
58
- },
59
- set: function(newPieceSize) {
60
- iLob.pieceSize = newPieceSize;
61
- }
62
- },
63
- type: {
64
- get: function() {
65
- return iLob.type;
66
- }
67
- },
68
- close: {
69
- value: closePromisified,
70
- enumerable: true,
71
- writable: true
72
- }
73
- });
26
+ function close(closeCb) {
27
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
74
28
 
75
- if (this._autoCloseLob) {
76
- this.once('finish', function() {
77
- this.close(function() {});
78
- });
29
+ // Return if LOB already closed to support multiple close() calls should be
30
+ // no-op
31
+ if (!this.valid) {
32
+ closeCb(null);
33
+ return;
79
34
  }
35
+
36
+ this._close(function(err) {
37
+ if (err) {
38
+ this.emit('error', err);
39
+ } else {
40
+ this.emit('close');
41
+ }
42
+
43
+ closeCb(err);
44
+ });
80
45
  }
81
46
 
82
- // implementation of streaming read; if lob is set to auto-close, the lob is
83
- // automatically closed within the C++ code when an error occurs or when there
84
- // are no more bytes to transfer; all that needs to be done in the JS layer is
85
- // to emit the close and/or error events
86
- Lob.prototype._read = function() {
87
- var self = this;
88
-
89
- self.iLob.read(
90
- function(err, str) {
91
- if (err) {
92
- self.emit('error', err);
93
- if (self._autoCloseLob) {
94
- self.emit('close');
95
- }
96
- return;
97
- }
98
47
 
99
- self.push(str);
48
+ function getData(getDataCb) {
49
+ nodbUtil.checkAsyncArgs(arguments, 1, 1);
50
+ this._getData(getDataCb);
51
+ }
52
+
100
53
 
101
- if (self._autoCloseLob && !str) {
102
- process.nextTick(function() {
103
- self.emit('close');
104
- });
54
+ class Lob {
55
+
56
+ constructor() {
57
+ Duplex.call(this, {decodeStrings: false});
58
+ this.offset = 1;
59
+ this.once('finish', function() {
60
+ if (this._autoCloseLob) {
61
+ this.close(function() {});
105
62
  }
106
- }
107
- );
108
- };
109
-
110
- // implementation of streaming write; if lob is set to auto-close, the lob is
111
- // automatically closed in the "finish" event; all that needs to be done here
112
- // is to emit the close event in the event of an error
113
- Lob.prototype._write = function(data, encoding, cb) {
114
- var self = this;
115
-
116
- self.iLob.write(
117
- data,
118
- function(err) {
119
- if (err && self._autoCloseLob) {
120
- self.emit('close');
63
+ });
64
+ }
65
+
66
+ _extend(oracledb) {
67
+ this._oracledb = oracledb;
68
+ this.close = nodbUtil.promisify(oracledb, close);
69
+ this.getData = nodbUtil.promisify(oracledb, getData);
70
+ }
71
+
72
+ // called by stream.destroy() and ensures that the LOB is closed if it has
73
+ // not already been closed (never called directly)
74
+ _destroy(err, cb) {
75
+ this._close(function(closeErr) {
76
+ if (closeErr) {
77
+ cb(closeErr);
78
+ } else {
79
+ cb(err);
121
80
  }
122
- cb(err);
123
- }
124
- );
125
- };
81
+ });
82
+ }
126
83
 
127
- Lob.prototype.close = function(closeCb) {
128
- var self = this;
84
+ // implementation of streaming read; if lob is set to auto-close, the lob is
85
+ // automatically closed within the C++ code when an error occurs or when
86
+ // there are no more bytes to transfer; all that needs to be done in the JS
87
+ // layer is to emit the close and/or error events
88
+ _read() {
89
+ const self = this;
90
+
91
+ self.__read(self.offset,
92
+ function(err, data) {
93
+ if (err) {
94
+ self.emit('error', err);
95
+ if (self._autoCloseLob) {
96
+ self.emit('close');
97
+ }
98
+ return;
99
+ }
129
100
 
130
- nodbUtil.assert(arguments.length === 1, 'NJS-009');
131
- nodbUtil.assert(typeof closeCb === 'function', 'NJS-006', 1);
101
+ if (data) {
102
+ self.offset += data.length;
103
+ }
132
104
 
133
- // Return if LOB already closed to support multiple close() calls should be
134
- // no-op
135
- if (!self.iLob.valid) {
136
- closeCb(null);
137
- return;
105
+ self.push(data);
106
+
107
+ if (self._autoCloseLob && !data) {
108
+ process.nextTick(function() {
109
+ self.emit('close');
110
+ });
111
+ }
112
+ }
113
+ );
138
114
  }
139
115
 
140
- self.iLob.close(function(err) {
141
- if (err) {
142
- self.emit('error', err);
143
- } else {
144
- self.emit('close');
116
+ // implementation of streaming write; if lob is set to auto-close, the lob is
117
+ // automatically closed in the "finish" event; all that needs to be done here
118
+ // is to emit the close event in the event of an error
119
+ _write(data, encoding, cb) {
120
+ const self = this;
121
+
122
+ if (self.type == self._oracledb.BLOB && !Buffer.isBuffer(data)) {
123
+ data = Buffer.from(data);
124
+ } else if (self.type == self._oracledb.CLOB && Buffer.isBuffer(data)) {
125
+ data = data.toString();
145
126
  }
127
+ self.__write(
128
+ self.offset,
129
+ data,
130
+ function(err) {
131
+ if (err && self._autoCloseLob) {
132
+ self.emit('close');
133
+ }
134
+ if (!err) {
135
+ self.offset += data.length;
136
+ }
137
+ cb(err);
138
+ }
139
+ );
140
+ }
146
141
 
147
- closeCb(err);
148
- });
149
- };
142
+ }
150
143
 
151
- closePromisified = nodbUtil.promisify(Lob.prototype.close);
144
+ util.inherits(Lob, Duplex);
152
145
 
153
- module.exports.Lob = Lob;
146
+ module.exports = Lob;