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.
- package/CHANGELOG.md +277 -4
- package/LICENSE.md +5906 -360
- package/README.md +7 -8
- package/build/Release/oracledb-4.2.0-darwin-x64.node +0 -0
- package/build/Release/oracledb-4.2.0-darwin-x64.node-buildinfo.txt +1 -0
- package/build/Release/oracledb-4.2.0-linux-x64.node +0 -0
- package/build/Release/oracledb-4.2.0-linux-x64.node-buildinfo.txt +1 -0
- package/build/Release/oracledb-4.2.0-win32-x64.node +0 -0
- package/build/Release/oracledb-4.2.0-win32-x64.node-buildinfo.txt +1 -0
- package/lib/aqDeqOptions.js +29 -0
- package/lib/aqEnqOptions.js +29 -0
- package/lib/aqMessage.js +29 -0
- package/lib/aqQueue.js +84 -0
- package/lib/connection.js +294 -326
- package/lib/dbObject.js +144 -0
- package/lib/lob.js +125 -132
- package/lib/oracledb.js +162 -483
- package/lib/pool.js +95 -109
- package/lib/{querystream.js → queryStream.js} +31 -30
- package/lib/resultset.js +75 -125
- package/lib/sodaCollection.js +99 -165
- package/lib/sodaDatabase.js +58 -133
- package/lib/sodaDocCursor.js +27 -70
- package/lib/sodaDocument.js +35 -65
- package/lib/sodaOperation.js +96 -252
- package/lib/util.js +78 -71
- package/package/README.md +41 -36
- package/package/install.js +30 -24
- package/package.json +2 -2
- package/build/Release/oracledb-abi48-darwin-x64.node +0 -0
- package/build/Release/oracledb-abi48-darwin-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi48-linux-x64.node +0 -0
- package/build/Release/oracledb-abi48-linux-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi48-win32-x64.node +0 -0
- package/build/Release/oracledb-abi48-win32-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi57-darwin-x64.node +0 -0
- package/build/Release/oracledb-abi57-darwin-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi57-linux-x64.node +0 -0
- package/build/Release/oracledb-abi57-linux-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi57-win32-x64.node +0 -0
- package/build/Release/oracledb-abi57-win32-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi64-darwin-x64.node +0 -0
- package/build/Release/oracledb-abi64-darwin-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi64-linux-x64.node +0 -0
- package/build/Release/oracledb-abi64-linux-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi64-win32-x64.node +0 -0
- package/build/Release/oracledb-abi64-win32-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi67-darwin-x64.node +0 -0
- package/build/Release/oracledb-abi67-darwin-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi67-linux-x64.node +0 -0
- package/build/Release/oracledb-abi67-linux-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-abi67-win32-x64.node +0 -0
- package/build/Release/oracledb-abi67-win32-x64.node-buildinfo.txt +0 -1
package/lib/connection.js
CHANGED
|
@@ -1,84 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
// Copyright (c) 2016, 2020, 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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var executePromisified;
|
|
28
|
-
var executeManyPromisified;
|
|
29
|
-
var getStatementInfoPromisified;
|
|
30
|
-
var commitPromisified;
|
|
31
|
-
var createLobPromisified;
|
|
32
|
-
var rollbackPromisified;
|
|
33
|
-
var closePromisified;
|
|
34
|
-
var breakPromisified;
|
|
35
|
-
var changePasswordPromisified;
|
|
36
|
-
var pingPromisified;
|
|
37
|
-
var subscribePromisified;
|
|
38
|
-
var unsubscribePromisified;
|
|
39
|
-
|
|
40
|
-
// The queryStream function is similar to execute except that it immediately
|
|
41
|
-
// returns a QueryStream.
|
|
42
|
-
function queryStream(sql, binding, options) {
|
|
43
|
-
var self = this;
|
|
44
|
-
var stream;
|
|
45
|
-
|
|
46
|
-
nodbUtil.assert(arguments.length > 0 && arguments.length < 4, 'NJS-009');
|
|
47
|
-
nodbUtil.assert(typeof sql === 'string', 'NJS-006', 1);
|
|
48
|
-
|
|
49
|
-
if (binding) {
|
|
50
|
-
nodbUtil.assert(nodbUtil.isObjectOrArray(binding), 'NJS-006', 2);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (options) {
|
|
54
|
-
nodbUtil.assert(nodbUtil.isObject(options), 'NJS-006', 3);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
binding = binding || [];
|
|
58
|
-
options = options || {};
|
|
59
|
-
|
|
60
|
-
options.resultSet = true;
|
|
61
|
-
|
|
62
|
-
stream = new QueryStream(null, self._oracledb);
|
|
63
|
-
|
|
64
|
-
self._execute(sql, binding, options, function(err, result) {
|
|
65
|
-
if (err) {
|
|
66
|
-
stream._open(err, null);
|
|
67
|
-
} else {
|
|
68
|
-
resultset.extend(result.resultSet, self._oracledb, options);
|
|
69
|
-
stream._open(null, result.resultSet);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return stream;
|
|
74
|
-
}
|
|
22
|
+
const BaseDbObject = require('./dbObject.js');
|
|
23
|
+
const EventEmitter = require('events');
|
|
24
|
+
const QueryStream = require('./queryStream.js');
|
|
25
|
+
const nodbUtil = require('./util.js');
|
|
26
|
+
const util = require('util');
|
|
75
27
|
|
|
76
28
|
// fetchRowsToReturn is used to materialize the rows for an execute call using
|
|
77
29
|
// the resultSet returned from the C layer.
|
|
78
|
-
function fetchRowsToReturn(oracledb, executeOpts,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
30
|
+
function fetchRowsToReturn(oracledb, executeOpts, resultSet, cb) {
|
|
31
|
+
let rowsFetched = [];
|
|
32
|
+
let fetchArraySize;
|
|
33
|
+
let maxRows;
|
|
82
34
|
|
|
83
35
|
fetchArraySize = executeOpts.fetchArraySize;
|
|
84
36
|
if (fetchArraySize === undefined) {
|
|
@@ -90,10 +42,10 @@ function fetchRowsToReturn(oracledb, executeOpts, result, executeCb) {
|
|
|
90
42
|
maxRows = oracledb.maxRows;
|
|
91
43
|
}
|
|
92
44
|
|
|
93
|
-
|
|
45
|
+
const fetchRowsCb = function(err, rows) {
|
|
94
46
|
|
|
95
47
|
if (err) {
|
|
96
|
-
|
|
48
|
+
cb(err);
|
|
97
49
|
return;
|
|
98
50
|
}
|
|
99
51
|
|
|
@@ -102,49 +54,41 @@ function fetchRowsToReturn(oracledb, executeOpts, result, executeCb) {
|
|
|
102
54
|
}
|
|
103
55
|
|
|
104
56
|
if (rowsFetched.length == maxRows || rows.length < fetchArraySize) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
delete result.resultSet;
|
|
108
|
-
|
|
109
|
-
executeCb(null, result);
|
|
110
|
-
|
|
57
|
+
cb(null, rowsFetched);
|
|
111
58
|
return;
|
|
112
59
|
}
|
|
113
60
|
|
|
114
|
-
|
|
61
|
+
resultSet.getRows(fetchArraySize, fetchRowsCb);
|
|
115
62
|
};
|
|
116
63
|
|
|
117
|
-
|
|
64
|
+
resultSet.getRows(fetchArraySize, fetchRowsCb);
|
|
118
65
|
}
|
|
119
66
|
|
|
120
67
|
// This execute function is used to override the execute method of the Connection
|
|
121
68
|
// class, which is defined in the C layer. The override allows us to do things
|
|
122
69
|
// like extend out the resultSet instance prior to passing it to the caller.
|
|
123
70
|
function execute(sql, a2, a3, a4) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
71
|
+
const self = this;
|
|
72
|
+
let binds = [];
|
|
73
|
+
let executeOpts = {};
|
|
74
|
+
let executeCb;
|
|
75
|
+
let custExecuteCb;
|
|
129
76
|
|
|
130
|
-
nodbUtil.
|
|
131
|
-
nodbUtil.assert(typeof sql === 'string', 'NJS-
|
|
77
|
+
nodbUtil.checkAsyncArgs(arguments, 2, 4);
|
|
78
|
+
nodbUtil.assert(typeof sql === 'string', 'NJS-005', 1);
|
|
132
79
|
|
|
133
80
|
switch (arguments.length) {
|
|
134
81
|
case 2:
|
|
135
|
-
nodbUtil.assert(typeof a2 === 'function', 'NJS-006', 2);
|
|
136
82
|
executeCb = a2;
|
|
137
83
|
break;
|
|
138
84
|
case 3:
|
|
139
|
-
nodbUtil.assert(nodbUtil.isObjectOrArray(a2), 'NJS-
|
|
140
|
-
nodbUtil.assert(typeof a3 === 'function', 'NJS-006', 3);
|
|
85
|
+
nodbUtil.assert(nodbUtil.isObjectOrArray(a2), 'NJS-005', 2);
|
|
141
86
|
binds = a2;
|
|
142
87
|
executeCb = a3;
|
|
143
88
|
break;
|
|
144
89
|
case 4:
|
|
145
|
-
nodbUtil.assert(nodbUtil.isObjectOrArray(a2), 'NJS-
|
|
146
|
-
nodbUtil.assert(nodbUtil.isObject(a3), 'NJS-
|
|
147
|
-
nodbUtil.assert(typeof a4 === 'function', 'NJS-006', 4);
|
|
90
|
+
nodbUtil.assert(nodbUtil.isObjectOrArray(a2), 'NJS-005', 2);
|
|
91
|
+
nodbUtil.assert(nodbUtil.isObject(a3), 'NJS-005', 3);
|
|
148
92
|
binds = a2;
|
|
149
93
|
executeOpts = a3;
|
|
150
94
|
executeCb = a4;
|
|
@@ -152,8 +96,8 @@ function execute(sql, a2, a3, a4) {
|
|
|
152
96
|
}
|
|
153
97
|
|
|
154
98
|
custExecuteCb = function(err, result) {
|
|
155
|
-
|
|
156
|
-
|
|
99
|
+
let outBindsKeys;
|
|
100
|
+
let outBindsIdx;
|
|
157
101
|
|
|
158
102
|
if (err) {
|
|
159
103
|
executeCb(err);
|
|
@@ -161,13 +105,23 @@ function execute(sql, a2, a3, a4) {
|
|
|
161
105
|
}
|
|
162
106
|
|
|
163
107
|
// Need to extend resultsets which may come from either the query results
|
|
164
|
-
// or outBinds
|
|
108
|
+
// or outBinds or implicit results
|
|
165
109
|
if (result.resultSet) {
|
|
110
|
+
result.resultSet._setup(executeOpts);
|
|
166
111
|
if (executeOpts.resultSet) {
|
|
167
|
-
resultset.extend(result.resultSet, self._oracledb, executeOpts);
|
|
168
112
|
executeCb(null, result);
|
|
169
113
|
} else {
|
|
170
|
-
fetchRowsToReturn(self._oracledb, executeOpts, result,
|
|
114
|
+
fetchRowsToReturn(self._oracledb, executeOpts, result.resultSet,
|
|
115
|
+
function(err, rows) {
|
|
116
|
+
if (err) {
|
|
117
|
+
executeCb(err);
|
|
118
|
+
} else {
|
|
119
|
+
result.rows = rows;
|
|
120
|
+
delete result.resultSet;
|
|
121
|
+
executeCb(null, result);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
);
|
|
171
125
|
}
|
|
172
126
|
} else {
|
|
173
127
|
if (result.outBinds) {
|
|
@@ -175,11 +129,37 @@ function execute(sql, a2, a3, a4) {
|
|
|
175
129
|
|
|
176
130
|
for (outBindsIdx = 0; outBindsIdx < outBindsKeys.length; outBindsIdx += 1) {
|
|
177
131
|
if (result.outBinds[outBindsKeys[outBindsIdx]] instanceof self._oracledb.ResultSet) {
|
|
178
|
-
|
|
132
|
+
result.outBinds[outBindsKeys[outBindsIdx]]._setup(executeOpts);
|
|
179
133
|
}
|
|
180
134
|
}
|
|
181
135
|
}
|
|
182
|
-
|
|
136
|
+
if (result.implicitResults && !executeOpts.resultSet) {
|
|
137
|
+
const processImplicitResult = function(ix) {
|
|
138
|
+
const resultSet = result.implicitResults[ix];
|
|
139
|
+
if (!resultSet) {
|
|
140
|
+
executeCb(null, result);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
fetchRowsToReturn(self._oracledb, executeOpts, resultSet,
|
|
144
|
+
function(err, rows) {
|
|
145
|
+
if (err) {
|
|
146
|
+
executeCb(err);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
result.implicitResults[ix] = rows;
|
|
150
|
+
processImplicitResult(ix + 1);
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
processImplicitResult(0);
|
|
155
|
+
} else {
|
|
156
|
+
if (result.implicitResults) {
|
|
157
|
+
for (let i = 0; i < result.implicitResults.length; i++) {
|
|
158
|
+
result.implicitResults[i]._setup(executeOpts);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
executeCb(null, result);
|
|
162
|
+
}
|
|
183
163
|
}
|
|
184
164
|
|
|
185
165
|
};
|
|
@@ -187,107 +167,113 @@ function execute(sql, a2, a3, a4) {
|
|
|
187
167
|
self._execute.call(self, sql, binds, executeOpts, custExecuteCb);
|
|
188
168
|
}
|
|
189
169
|
|
|
190
|
-
executePromisified = nodbUtil.promisify(execute);
|
|
191
|
-
|
|
192
170
|
// This executeMany function is used to override the executeMany method of
|
|
193
171
|
// the Connection class, which is defined in the C layer.
|
|
194
172
|
function executeMany(sql, bindsOrNumIters, a3, a4) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
173
|
+
const self = this;
|
|
174
|
+
let options = {};
|
|
175
|
+
let executeCb;
|
|
176
|
+
let okBinds;
|
|
198
177
|
|
|
199
|
-
nodbUtil.
|
|
200
|
-
nodbUtil.assert(typeof sql === 'string', 'NJS-
|
|
178
|
+
nodbUtil.checkAsyncArgs(arguments, 3, 4);
|
|
179
|
+
nodbUtil.assert(typeof sql === 'string', 'NJS-005', 1);
|
|
201
180
|
if (typeof bindsOrNumIters === 'number') {
|
|
202
|
-
nodbUtil.assert(Number.isInteger(bindsOrNumIters)
|
|
203
|
-
|
|
181
|
+
nodbUtil.assert(Number.isInteger(bindsOrNumIters), 'NJS-005', 2);
|
|
182
|
+
okBinds = (bindsOrNumIters > 0);
|
|
204
183
|
} else {
|
|
205
|
-
nodbUtil.assert(Array.isArray(bindsOrNumIters), 'NJS-
|
|
184
|
+
nodbUtil.assert(Array.isArray(bindsOrNumIters), 'NJS-005', 2);
|
|
185
|
+
okBinds = (bindsOrNumIters.length > 0);
|
|
206
186
|
}
|
|
207
187
|
|
|
208
188
|
switch (arguments.length) {
|
|
209
189
|
case 3:
|
|
210
|
-
nodbUtil.assert(typeof a3 === 'function', 'NJS-006', 3);
|
|
211
190
|
executeCb = a3;
|
|
212
191
|
break;
|
|
213
192
|
case 4:
|
|
214
|
-
nodbUtil.assert(nodbUtil.isObject(a3), 'NJS-
|
|
215
|
-
nodbUtil.assert(typeof a4 === 'function', 'NJS-006', 4);
|
|
193
|
+
nodbUtil.assert(nodbUtil.isObject(a3), 'NJS-005', 3);
|
|
216
194
|
options = a3;
|
|
217
195
|
executeCb = a4;
|
|
218
196
|
break;
|
|
219
197
|
}
|
|
198
|
+
if (!okBinds) {
|
|
199
|
+
executeCb(new Error(nodbUtil.getErrorMessage('NJS-005', 2)));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
220
202
|
|
|
221
203
|
self._executeMany.call(self, sql, bindsOrNumIters, options, executeCb);
|
|
222
204
|
}
|
|
223
205
|
|
|
224
|
-
|
|
206
|
+
// define method for getting a database object class; the cache is searched
|
|
207
|
+
// first, but if not found, the database is queried and the result is cached
|
|
208
|
+
// using the fully qualified name
|
|
209
|
+
function getDbObjectClass(name, cb) {
|
|
210
|
+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
|
|
211
|
+
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
|
|
212
|
+
|
|
213
|
+
// check the cache; if the class is found there, nothing further to do
|
|
214
|
+
let cls = this._dbObjectClasses[name];
|
|
215
|
+
if (cls) {
|
|
216
|
+
cb(null, cls);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// otherwise, ask the database for the class; the C method will internally
|
|
221
|
+
// call back into JavaScript to store the type found in the cache
|
|
222
|
+
this._getDbObjectClass(name, cb);
|
|
223
|
+
}
|
|
225
224
|
|
|
226
225
|
// This getStatementInfo function is just a place holder to allow for easier extension later.
|
|
227
|
-
function getStatementInfo(sql, getStatementInfoCb) {
|
|
228
|
-
|
|
226
|
+
function getStatementInfo(sql, getStatementInfoCb) { //eslint-disable-line
|
|
227
|
+
const self = this;
|
|
229
228
|
|
|
230
|
-
nodbUtil.
|
|
231
|
-
nodbUtil.assert(typeof getStatementInfoCb === 'function', 'NJS-006', 1);
|
|
229
|
+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
|
|
232
230
|
|
|
233
231
|
self._getStatementInfo.apply(self, arguments);
|
|
234
232
|
}
|
|
235
233
|
|
|
236
|
-
getStatementInfoPromisified = nodbUtil.promisify(getStatementInfo);
|
|
237
|
-
|
|
238
234
|
// This commit function is just a place holder to allow for easier extension later.
|
|
239
|
-
function commit(commitCb) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
nodbUtil.assert(arguments.length === 1, 'NJS-009');
|
|
243
|
-
nodbUtil.assert(typeof commitCb === 'function', 'NJS-006', 1);
|
|
235
|
+
function commit(commitCb) { //eslint-disable-line
|
|
236
|
+
const self = this;
|
|
244
237
|
|
|
238
|
+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
|
|
245
239
|
self._commit.apply(self, arguments);
|
|
246
240
|
}
|
|
247
241
|
|
|
248
|
-
commitPromisified = nodbUtil.promisify(commit);
|
|
249
|
-
|
|
250
242
|
// This createLob function is just a place holder to allow for easier extension later.
|
|
251
|
-
function createLob(type, createLobCb) {
|
|
252
|
-
|
|
243
|
+
function createLob(type, createLobCb) { //eslint-disable-line
|
|
244
|
+
const self = this;
|
|
253
245
|
|
|
254
|
-
nodbUtil.
|
|
255
|
-
nodbUtil.assert(typeof
|
|
246
|
+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
|
|
247
|
+
nodbUtil.assert(typeof type === 'number', 'NJS-005', 1);
|
|
248
|
+
nodbUtil.assert(typeof createLobCb === 'function', 'NJS-005', 2);
|
|
256
249
|
|
|
257
250
|
self._createLob.apply(self, arguments);
|
|
258
251
|
}
|
|
259
252
|
|
|
260
|
-
createLobPromisified = nodbUtil.promisify(createLob);
|
|
261
|
-
|
|
262
253
|
// This rollback function is just a place holder to allow for easier extension later.
|
|
263
|
-
function rollback(rollbackCb) {
|
|
264
|
-
|
|
254
|
+
function rollback(rollbackCb) { //eslint-disable-line
|
|
255
|
+
const self = this;
|
|
265
256
|
|
|
266
|
-
nodbUtil.
|
|
267
|
-
nodbUtil.assert(typeof rollbackCb === 'function', 'NJS-006', 1);
|
|
257
|
+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
|
|
268
258
|
|
|
269
259
|
self._rollback.apply(self, arguments);
|
|
270
260
|
}
|
|
271
261
|
|
|
272
|
-
rollbackPromisified = nodbUtil.promisify(rollback);
|
|
273
|
-
|
|
274
262
|
// This close function is used to override the close method of the Connection
|
|
275
263
|
// class, which is defined in the C layer.
|
|
276
264
|
function close(a1, a2) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
265
|
+
const self = this;
|
|
266
|
+
let options = {};
|
|
267
|
+
let closeCb;
|
|
280
268
|
|
|
281
|
-
nodbUtil.
|
|
269
|
+
nodbUtil.checkAsyncArgs(arguments, 1, 2);
|
|
282
270
|
|
|
283
271
|
switch (arguments.length) {
|
|
284
272
|
case 1:
|
|
285
|
-
nodbUtil.assert(typeof a1 === 'function', 'NJS-006', 1);
|
|
286
273
|
closeCb = a1;
|
|
287
274
|
break;
|
|
288
275
|
case 2:
|
|
289
|
-
nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-
|
|
290
|
-
nodbUtil.assert(typeof a2 === 'function', 'NJS-006', 2);
|
|
276
|
+
nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-005', 1);
|
|
291
277
|
options = a1;
|
|
292
278
|
closeCb = a2;
|
|
293
279
|
break;
|
|
@@ -295,6 +281,10 @@ function close(a1, a2) {
|
|
|
295
281
|
|
|
296
282
|
self._close(options, function(err) {
|
|
297
283
|
if (!err) {
|
|
284
|
+
for (const cls of Object.values(this._dbObjectClasses)) {
|
|
285
|
+
cls.prototype.constructor = Object;
|
|
286
|
+
cls.prototype = null;
|
|
287
|
+
}
|
|
298
288
|
self.emit('_after_close');
|
|
299
289
|
}
|
|
300
290
|
|
|
@@ -302,219 +292,197 @@ function close(a1, a2) {
|
|
|
302
292
|
});
|
|
303
293
|
}
|
|
304
294
|
|
|
305
|
-
closePromisified = nodbUtil.promisify(close);
|
|
306
|
-
|
|
307
295
|
// This break function is just a place holder to allow for easier extension later.
|
|
308
296
|
// It's attached to the module as break is a reserved word.
|
|
309
|
-
module.break = function(breakCb) {
|
|
310
|
-
|
|
297
|
+
module.break = function(breakCb) { //eslint-disable-line
|
|
298
|
+
const self = this;
|
|
311
299
|
|
|
312
|
-
nodbUtil.
|
|
313
|
-
nodbUtil.assert(typeof breakCb === 'function', 'NJS-006', 1);
|
|
300
|
+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
|
|
314
301
|
|
|
315
302
|
self._break.apply(self, arguments);
|
|
316
303
|
};
|
|
317
304
|
|
|
318
|
-
breakPromisified = nodbUtil.promisify(module.break);
|
|
319
|
-
|
|
320
305
|
// This changePassword function is just a place holder to allow for easier extension later.
|
|
321
306
|
function changePassword(user, password, newPassword, changePasswordCb) {
|
|
322
|
-
|
|
307
|
+
const self = this;
|
|
323
308
|
|
|
324
|
-
nodbUtil.
|
|
325
|
-
nodbUtil.assert(typeof user === 'string', 'NJS-
|
|
326
|
-
nodbUtil.assert(typeof password === 'string', 'NJS-
|
|
327
|
-
nodbUtil.assert(typeof newPassword === 'string', 'NJS-
|
|
328
|
-
nodbUtil.assert(typeof changePasswordCb === 'function', 'NJS-
|
|
309
|
+
nodbUtil.checkAsyncArgs(arguments, 4, 4);
|
|
310
|
+
nodbUtil.assert(typeof user === 'string', 'NJS-005', 1);
|
|
311
|
+
nodbUtil.assert(typeof password === 'string', 'NJS-005', 2);
|
|
312
|
+
nodbUtil.assert(typeof newPassword === 'string', 'NJS-005', 3);
|
|
313
|
+
nodbUtil.assert(typeof changePasswordCb === 'function', 'NJS-005', 4);
|
|
329
314
|
|
|
330
315
|
self._changePassword.apply(self, arguments);
|
|
331
316
|
}
|
|
332
317
|
|
|
333
|
-
|
|
318
|
+
// Returns an AQ queue
|
|
319
|
+
function getQueue(name, a2, a3) {
|
|
320
|
+
let options = {};
|
|
321
|
+
let queueCb;
|
|
334
322
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
323
|
+
nodbUtil.checkAsyncArgs(arguments, 2, 3);
|
|
324
|
+
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
|
|
325
|
+
switch (arguments.length) {
|
|
326
|
+
case 2:
|
|
327
|
+
queueCb = a2;
|
|
328
|
+
break;
|
|
329
|
+
case 3:
|
|
330
|
+
nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-005', 2);
|
|
331
|
+
options = a2;
|
|
332
|
+
queueCb = a3;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
this._getQueue(name, options, queueCb);
|
|
336
|
+
}
|
|
338
337
|
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
// This ping function is just a place holder to allow for easier extension later.
|
|
339
|
+
function ping(pingCb) { //eslint-disable-line
|
|
340
|
+
const self = this;
|
|
341
341
|
|
|
342
|
+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
|
|
342
343
|
self._ping.apply(self, arguments);
|
|
343
344
|
}
|
|
344
345
|
|
|
345
|
-
pingPromisified = nodbUtil.promisify(ping);
|
|
346
|
-
|
|
347
346
|
// create a subscription which can be used to get notifications of database
|
|
348
347
|
// changes
|
|
349
348
|
function subscribe(name, options, subscribeCb) {
|
|
350
|
-
|
|
349
|
+
const self = this;
|
|
351
350
|
|
|
352
|
-
nodbUtil.
|
|
353
|
-
nodbUtil.assert(typeof name === 'string', 'NJS-
|
|
354
|
-
nodbUtil.assert(nodbUtil.isObject(options), 'NJS-
|
|
355
|
-
nodbUtil.assert(typeof subscribeCb === 'function', 'NJS-006', 3);
|
|
351
|
+
nodbUtil.checkAsyncArgs(arguments, 3, 3);
|
|
352
|
+
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
|
|
353
|
+
nodbUtil.assert(nodbUtil.isObject(options), 'NJS-005', 2);
|
|
356
354
|
self._subscribe.call(self, name, options, subscribeCb);
|
|
357
355
|
}
|
|
358
356
|
|
|
359
|
-
subscribePromisified = nodbUtil.promisify(subscribe);
|
|
360
|
-
|
|
361
357
|
// destroy a subscription which was earlier created using subscribe()
|
|
362
358
|
function unsubscribe(name, cb) {
|
|
363
|
-
|
|
359
|
+
const self = this;
|
|
364
360
|
|
|
365
|
-
nodbUtil.
|
|
366
|
-
nodbUtil.assert(typeof name === 'string', 'NJS-
|
|
367
|
-
nodbUtil.assert(typeof cb === 'function', 'NJS-006', 2);
|
|
361
|
+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
|
|
362
|
+
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
|
|
368
363
|
|
|
369
364
|
self._unsubscribe.call(self, name, cb);
|
|
370
365
|
}
|
|
371
366
|
|
|
372
|
-
|
|
367
|
+
// build a database object class
|
|
368
|
+
function buildDbObjectClass(schema, name, fqn) {
|
|
369
|
+
const DbObject = function(initialValue) {
|
|
370
|
+
if (this.isCollection) {
|
|
371
|
+
const proxy = new Proxy(this, BaseDbObject._collectionProxyHandler);
|
|
372
|
+
if (initialValue !== undefined) {
|
|
373
|
+
for (let i = 0; i < initialValue.length; i++) {
|
|
374
|
+
this.append(initialValue[i]);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return proxy;
|
|
378
|
+
} else if (initialValue !== undefined) {
|
|
379
|
+
Object.assign(this, initialValue);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
DbObject.prototype = Object.create(BaseDbObject.prototype);
|
|
383
|
+
DbObject.prototype.constructor = DbObject;
|
|
384
|
+
DbObject.prototype.schema = schema;
|
|
385
|
+
DbObject.prototype.name = name;
|
|
386
|
+
DbObject.prototype.fqn = fqn;
|
|
387
|
+
DbObject.toString = function() {
|
|
388
|
+
return 'DbObjectClass [' + fqn + ']';
|
|
389
|
+
};
|
|
390
|
+
return DbObject;
|
|
391
|
+
}
|
|
373
392
|
|
|
393
|
+
// define class
|
|
394
|
+
class Connection extends EventEmitter {
|
|
374
395
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
let db = this._getSodaDatabase();
|
|
380
|
-
sodaDatabase.extend(db, this);
|
|
381
|
-
return db;
|
|
382
|
-
}
|
|
396
|
+
constructor() {
|
|
397
|
+
super();
|
|
398
|
+
this._dbObjectClasses = {};
|
|
399
|
+
}
|
|
383
400
|
|
|
401
|
+
// extend class with promisified functions
|
|
402
|
+
_extend(oracledb) {
|
|
403
|
+
this._oracledb = oracledb;
|
|
404
|
+
this.break = nodbUtil.promisify(oracledb, module.break);
|
|
405
|
+
this.changePassword = nodbUtil.promisify(oracledb, changePassword);
|
|
406
|
+
this.close = nodbUtil.promisify(oracledb, close);
|
|
407
|
+
this.commit = nodbUtil.promisify(oracledb, commit);
|
|
408
|
+
this.createLob = nodbUtil.promisify(oracledb, createLob);
|
|
409
|
+
this.execute = nodbUtil.promisify(oracledb, execute);
|
|
410
|
+
this.executeMany = nodbUtil.promisify(oracledb, executeMany);
|
|
411
|
+
this.getDbObjectClass = nodbUtil.promisify(oracledb, getDbObjectClass);
|
|
412
|
+
this.getQueue = nodbUtil.promisify(oracledb, getQueue);
|
|
413
|
+
this.getStatementInfo = nodbUtil.promisify(oracledb, getStatementInfo);
|
|
414
|
+
this.ping = nodbUtil.promisify(oracledb, ping);
|
|
415
|
+
this.release = nodbUtil.promisify(oracledb, close);
|
|
416
|
+
this.rollback = nodbUtil.promisify(oracledb, rollback);
|
|
417
|
+
this.subscribe = nodbUtil.promisify(oracledb, subscribe);
|
|
418
|
+
this.unsubscribe = nodbUtil.promisify(oracledb, unsubscribe);
|
|
419
|
+
}
|
|
384
420
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
// Using Object.defineProperties to add properties to the Connection instance with
|
|
392
|
-
// special properties, such as enumerable but not writable.
|
|
393
|
-
Object.defineProperties(
|
|
394
|
-
conn,
|
|
395
|
-
{
|
|
396
|
-
_oracledb: { // storing a reference to the base instance to avoid circular references with require
|
|
397
|
-
value: oracledb
|
|
398
|
-
},
|
|
399
|
-
_pool: { // storing a reference to the pool, if any, from which the connection was obtained
|
|
400
|
-
value: pool
|
|
401
|
-
},
|
|
402
|
-
_execute: {
|
|
403
|
-
value: conn.execute
|
|
404
|
-
},
|
|
405
|
-
_getStatementInfo: {
|
|
406
|
-
value: conn.getStatementInfo
|
|
407
|
-
},
|
|
408
|
-
getStatementInfo: {
|
|
409
|
-
value: getStatementInfoPromisified,
|
|
410
|
-
enumerable: true,
|
|
411
|
-
writable: true
|
|
412
|
-
},
|
|
413
|
-
queryStream: {
|
|
414
|
-
value: queryStream,
|
|
415
|
-
enumerable: true,
|
|
416
|
-
writable: true
|
|
417
|
-
},
|
|
418
|
-
execute: {
|
|
419
|
-
value: executePromisified,
|
|
420
|
-
enumerable: true,
|
|
421
|
-
writable: true
|
|
422
|
-
},
|
|
423
|
-
_executeMany: {
|
|
424
|
-
value: conn.executeMany
|
|
425
|
-
},
|
|
426
|
-
executeMany: {
|
|
427
|
-
value: executeManyPromisified,
|
|
428
|
-
enumerable: true,
|
|
429
|
-
writable: true
|
|
430
|
-
},
|
|
431
|
-
_commit: {
|
|
432
|
-
value: conn.commit
|
|
433
|
-
},
|
|
434
|
-
commit: {
|
|
435
|
-
value: commitPromisified,
|
|
436
|
-
enumerable: true,
|
|
437
|
-
writable: true
|
|
438
|
-
},
|
|
439
|
-
_createLob: {
|
|
440
|
-
value: conn.createLob
|
|
441
|
-
},
|
|
442
|
-
createLob: {
|
|
443
|
-
value: createLobPromisified,
|
|
444
|
-
enumerable: true,
|
|
445
|
-
writable: true
|
|
446
|
-
},
|
|
447
|
-
_rollback: {
|
|
448
|
-
value: conn.rollback
|
|
449
|
-
},
|
|
450
|
-
rollback: {
|
|
451
|
-
value: rollbackPromisified,
|
|
452
|
-
enumerable: true,
|
|
453
|
-
writable: true
|
|
454
|
-
},
|
|
455
|
-
_close: {
|
|
456
|
-
value: conn.close
|
|
457
|
-
},
|
|
458
|
-
close: {
|
|
459
|
-
value: closePromisified,
|
|
460
|
-
enumerable: true,
|
|
461
|
-
writable: true
|
|
462
|
-
},
|
|
463
|
-
release: { // alias for close
|
|
464
|
-
value: closePromisified,
|
|
465
|
-
enumerable: true,
|
|
466
|
-
writable: true
|
|
467
|
-
},
|
|
468
|
-
_break: {
|
|
469
|
-
value: conn.break
|
|
470
|
-
},
|
|
471
|
-
break: {
|
|
472
|
-
value: breakPromisified,
|
|
473
|
-
enumerable: true,
|
|
474
|
-
writable: true
|
|
475
|
-
},
|
|
476
|
-
_changePassword: {
|
|
477
|
-
value: conn.changePassword
|
|
478
|
-
},
|
|
479
|
-
changePassword: {
|
|
480
|
-
value: changePasswordPromisified,
|
|
481
|
-
enumerable: true,
|
|
482
|
-
writable: true
|
|
483
|
-
},
|
|
484
|
-
_ping: {
|
|
485
|
-
value: conn.ping
|
|
486
|
-
},
|
|
487
|
-
ping: {
|
|
488
|
-
value: pingPromisified,
|
|
489
|
-
enumerable: true,
|
|
490
|
-
writable: true
|
|
491
|
-
},
|
|
492
|
-
_subscribe: {
|
|
493
|
-
value: conn.subscribe
|
|
494
|
-
},
|
|
495
|
-
subscribe: {
|
|
496
|
-
value: subscribePromisified,
|
|
497
|
-
enumerable: true,
|
|
498
|
-
writable: true
|
|
499
|
-
},
|
|
500
|
-
_unsubscribe: {
|
|
501
|
-
value: conn.unsubscribe
|
|
502
|
-
},
|
|
503
|
-
unsubscribe: {
|
|
504
|
-
value: unsubscribePromisified,
|
|
505
|
-
enumerable: true,
|
|
506
|
-
writable: true
|
|
507
|
-
},
|
|
508
|
-
_getSodaDatabase: {
|
|
509
|
-
value: conn.getSodaDatabase
|
|
510
|
-
},
|
|
511
|
-
getSodaDatabase: {
|
|
512
|
-
value: getSodaDatabase,
|
|
513
|
-
enumerable: true,
|
|
514
|
-
writable: true
|
|
515
|
-
}
|
|
421
|
+
_getDbObjectClassJS(schema, name) {
|
|
422
|
+
const fqn = `${schema}.${name}`;
|
|
423
|
+
let cls = this._dbObjectClasses[fqn];
|
|
424
|
+
if (!cls) {
|
|
425
|
+
cls = buildDbObjectClass(schema, name, fqn);
|
|
426
|
+
this._dbObjectClasses[fqn] = cls;
|
|
516
427
|
}
|
|
517
|
-
|
|
428
|
+
return cls;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
_isDate(val) {
|
|
432
|
+
return util.isDate(val);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// To obtain a SodaDatabase object (high-level SODA object associated with
|
|
436
|
+
// current connection)
|
|
437
|
+
getSodaDatabase() {
|
|
438
|
+
nodbUtil.checkArgCount(arguments, 0, 0);
|
|
439
|
+
return this._getSodaDatabase();
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// The queryStream function is similar to execute except that it immediately
|
|
443
|
+
// returns a QueryStream.
|
|
444
|
+
queryStream(sql, binding, options) {
|
|
445
|
+
const self = this;
|
|
446
|
+
let stream;
|
|
447
|
+
|
|
448
|
+
nodbUtil.checkArgCount(arguments, 1, 3);
|
|
449
|
+
nodbUtil.assert(typeof sql === 'string', 'NJS-005', 1);
|
|
450
|
+
|
|
451
|
+
if (binding) {
|
|
452
|
+
nodbUtil.assert(nodbUtil.isObjectOrArray(binding), 'NJS-005', 2);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (options) {
|
|
456
|
+
nodbUtil.assert(nodbUtil.isObject(options), 'NJS-005', 3);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
binding = binding || [];
|
|
460
|
+
options = options || {};
|
|
461
|
+
|
|
462
|
+
options.resultSet = true;
|
|
463
|
+
|
|
464
|
+
stream = new QueryStream(null);
|
|
465
|
+
|
|
466
|
+
// calling execute() via nextTick to ensure that handlers are registered
|
|
467
|
+
// prior to the events being emitted
|
|
468
|
+
process.nextTick(function() {
|
|
469
|
+
self._execute(sql, binding, options, function(err, result) {
|
|
470
|
+
if (err) {
|
|
471
|
+
stream._open(err, null);
|
|
472
|
+
} else if (result.resultSet) {
|
|
473
|
+
result.resultSet._setup(options);
|
|
474
|
+
stream._open(null, result.resultSet);
|
|
475
|
+
} else {
|
|
476
|
+
stream._open(new Error(nodbUtil.getErrorMessage('NJS-019')));
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
return stream;
|
|
482
|
+
}
|
|
483
|
+
|
|
518
484
|
}
|
|
519
485
|
|
|
520
|
-
|
|
486
|
+
|
|
487
|
+
// module.exports.extend = extend;
|
|
488
|
+
module.exports = Connection;
|