@pi-r/oracle 0.11.2 → 0.12.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/client/index.js +38 -44
- package/client/pool.js +2 -0
- package/package.json +6 -3
package/client/index.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.checkTimeout = checkTimeout;
|
|
9
|
-
const oracledb = require("oracledb");
|
|
10
|
-
const Db = require("@e-mc/db");
|
|
11
|
-
const types_1 = require("@e-mc/types");
|
|
12
|
-
const util_1 = require("@e-mc/db/util");
|
|
13
|
-
const DbPool = require("@pi-r/oracle/client/pool");
|
|
2
|
+
|
|
3
|
+
const oracledb = require('oracledb');
|
|
4
|
+
const Db = require('@e-mc/db');
|
|
5
|
+
const { DB_TYPE, asFunction, errorMessage, isError, isErrorCode, isPlainObject, isString } = require('@e-mc/types');
|
|
6
|
+
const { parseConnectionString, parseServerAuth } = require('@e-mc/db/util');
|
|
7
|
+
const DbPool = require('@pi-r/oracle/client/pool');
|
|
14
8
|
const POOL_STATE = {};
|
|
15
9
|
const DRIVER_MODE = process.env.NODE_ORACLEDB_DRIVER_MODE;
|
|
16
10
|
const useLibDir = () => Db.PLATFORM_WIN32 || process.platform === 'darwin' && process.arch === 'x64';
|
|
17
11
|
if (DRIVER_MODE === 'thick' && oracledb.thin) {
|
|
18
12
|
let libDir;
|
|
19
|
-
if (!useLibDir() ||
|
|
13
|
+
if (!useLibDir() || isString(libDir = process.env.NODE_ORACLEDB_CLIENT_LIB_DIR || process.env.ORACLE_HOME)) {
|
|
20
14
|
try {
|
|
21
15
|
oracledb.initOracleClient({ libDir, configDir: process.env.NODE_ORACLEDB_CLIENT_CONFIG_DIR, driverName: process.env.NODE_ORACLEDB_CLIENT_DRIVER_NAME, errorUrl: process.env.NODE_ORACLEDB_CLIENT_ERROR_URL });
|
|
22
16
|
}
|
|
@@ -26,7 +20,7 @@ if (DRIVER_MODE === 'thick' && oracledb.thin) {
|
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
22
|
function getConfigObject(value) {
|
|
29
|
-
return
|
|
23
|
+
return isString(value) && /^config-(?:ociobject|azure):\/\//i.test(value) ? value : '';
|
|
30
24
|
}
|
|
31
25
|
function initOracleClient(credential, type) {
|
|
32
26
|
if (credential.libDir && oracledb.thin) {
|
|
@@ -35,20 +29,16 @@ function initOracleClient(credential, type) {
|
|
|
35
29
|
oracledb.initOracleClient({ libDir: useLibDir() ? credential.libDir : undefined, driverName: credential.driverName, errorUrl: credential.errorUrl });
|
|
36
30
|
}
|
|
37
31
|
catch (err) {
|
|
38
|
-
if (err
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
default:
|
|
44
|
-
this.writeFail(["Unable to configure client", 'oracledb'], err, { type: type ?? 65536, fatal: false });
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
32
|
+
if (isErrorCode(err, 'NJS-090')) {
|
|
33
|
+
this.addLog(3, err, "oracle", credential.libDir);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.writeFail(["Unable to configure client", 'oracledb'], err, { type: type ?? 65536, fatal: false });
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
39
|
}
|
|
50
40
|
else {
|
|
51
|
-
this.writeFail(["Unable to configure client", 'oracledb'],
|
|
41
|
+
this.writeFail(["Unable to configure client", 'oracledb'], errorMessage('oracledb', 'Environment variable "NODE_ORACLEDB_DRIVER_MODE" was not set', 'thick'), { type: type ?? 65536, fatal: false });
|
|
52
42
|
}
|
|
53
43
|
delete credential.libDir;
|
|
54
44
|
}
|
|
@@ -56,7 +46,7 @@ function initOracleClient(credential, type) {
|
|
|
56
46
|
async function setCredential(item) {
|
|
57
47
|
let credential = this.getCredential(item), hostname, port, username, database;
|
|
58
48
|
if (credential) {
|
|
59
|
-
({ hostname, port, database, username } =
|
|
49
|
+
({ hostname, port, database, username } = parseServerAuth(credential));
|
|
60
50
|
credential.user ||= username;
|
|
61
51
|
if ('connectionString' in credential) {
|
|
62
52
|
credential.connectString ||= credential.connectionString;
|
|
@@ -67,7 +57,7 @@ async function setCredential(item) {
|
|
|
67
57
|
const uri = item.uri;
|
|
68
58
|
credential = {};
|
|
69
59
|
if (uri) {
|
|
70
|
-
const connection =
|
|
60
|
+
const connection = parseConnectionString(uri);
|
|
71
61
|
if (connection) {
|
|
72
62
|
({ hostname, port, username: credential.user, password: credential.password, database } = connection);
|
|
73
63
|
}
|
|
@@ -104,7 +94,7 @@ async function setCredential(item) {
|
|
|
104
94
|
errors.push('connectString');
|
|
105
95
|
}
|
|
106
96
|
if (errors.length > 0) {
|
|
107
|
-
throw
|
|
97
|
+
throw errorMessage("oracle", "Invalid credentials", errors.join(', '));
|
|
108
98
|
}
|
|
109
99
|
}
|
|
110
100
|
initOracleClient.call(this, credential);
|
|
@@ -118,7 +108,7 @@ async function setCredential(item) {
|
|
|
118
108
|
}
|
|
119
109
|
const poolAlias = credential.poolAlias;
|
|
120
110
|
let password, pool;
|
|
121
|
-
if (
|
|
111
|
+
if (isString(usePool)) {
|
|
122
112
|
username = credential.user || poolAlias || configObject;
|
|
123
113
|
if (username) {
|
|
124
114
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
@@ -189,8 +179,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
189
179
|
return [];
|
|
190
180
|
}
|
|
191
181
|
let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
192
|
-
if (
|
|
193
|
-
({ parallel, connectOnce, errorQuery, sessionKey } = options);
|
|
182
|
+
if (isPlainObject(options)) {
|
|
183
|
+
({ parallel, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
|
|
194
184
|
}
|
|
195
185
|
else {
|
|
196
186
|
if (typeof options === 'string') {
|
|
@@ -231,17 +221,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
231
221
|
}
|
|
232
222
|
catch (err) {
|
|
233
223
|
let close;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
close = 1;
|
|
237
|
-
break;
|
|
238
|
-
default:
|
|
239
|
-
close = pool.closeable;
|
|
240
|
-
break;
|
|
224
|
+
if (!isErrorCode(err, 'ORA-01017')) {
|
|
225
|
+
close = pool.closeable;
|
|
241
226
|
}
|
|
242
|
-
if (close) {
|
|
227
|
+
if (close !== false) {
|
|
243
228
|
await pool.detach(true);
|
|
244
|
-
if (close
|
|
229
|
+
if (!close) {
|
|
245
230
|
throw err;
|
|
246
231
|
}
|
|
247
232
|
}
|
|
@@ -265,7 +250,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
265
250
|
const item = batch[i];
|
|
266
251
|
const { source, query, params, ignoreCache, options: clientOptions } = item;
|
|
267
252
|
let credential = oracleCredential || onceCredential, error;
|
|
268
|
-
if (!credential && !
|
|
253
|
+
if (!credential && !isPlainObject(credential = item.credential) && (error = errorMessage(source, "Invalid credentials")) || !query && (error = errorMessage(source, "Missing database query"))) {
|
|
269
254
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
270
255
|
if (!parallel) {
|
|
271
256
|
tasks.length = 0;
|
|
@@ -282,7 +267,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
282
267
|
continue;
|
|
283
268
|
}
|
|
284
269
|
item.transactionState = 1;
|
|
285
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', credential) &&
|
|
270
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', credential) && asFunction(item.streamRow) : item.streamRow;
|
|
286
271
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
287
272
|
let queryString = '';
|
|
288
273
|
if (caching && ignoreCache !== true && !streamRow) {
|
|
@@ -334,7 +319,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
334
319
|
if (err === false) {
|
|
335
320
|
return;
|
|
336
321
|
}
|
|
337
|
-
if (err
|
|
322
|
+
if (isError(err)) {
|
|
338
323
|
error = err;
|
|
339
324
|
return;
|
|
340
325
|
}
|
|
@@ -394,5 +379,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
394
379
|
async function checkTimeout(value, limit = 0) {
|
|
395
380
|
return DbPool.checkTimeout(POOL_STATE, value, limit);
|
|
396
381
|
}
|
|
397
|
-
|
|
398
|
-
|
|
382
|
+
const DB_SOURCE_CLIENT = true;
|
|
383
|
+
const DB_SOURCE_TYPE = DB_TYPE.SQL;
|
|
384
|
+
|
|
385
|
+
exports.DB_SOURCE_CLIENT = DB_SOURCE_CLIENT;
|
|
386
|
+
exports.DB_SOURCE_TYPE = DB_SOURCE_TYPE;
|
|
387
|
+
exports.checkTimeout = checkTimeout;
|
|
388
|
+
exports.executeBatchQuery = executeBatchQuery;
|
|
389
|
+
exports.executeQuery = executeQuery;
|
|
390
|
+
exports.getConfigObject = getConfigObject;
|
|
391
|
+
exports.initOracleClient = initOracleClient;
|
|
392
|
+
exports.setCredential = setCredential;
|
package/client/pool.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
|
|
2
3
|
const DbPool = require('@e-mc/db/pool');
|
|
3
4
|
const POOL_ACTIVE = new WeakSet();
|
|
4
5
|
class OraclePool extends DbPool {
|
|
@@ -51,4 +52,5 @@ class OraclePool extends DbPool {
|
|
|
51
52
|
return this.client.status === 6002;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
|
|
54
56
|
module.exports = OraclePool;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/oracle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Oracle client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -20,8 +20,11 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/db": "^0.
|
|
24
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/db": "^0.14.0",
|
|
24
|
+
"@e-mc/types": "^0.14.0",
|
|
25
25
|
"oracledb": "^6.10.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@types/oracledb": "^6"
|
|
26
29
|
}
|
|
27
30
|
}
|