@pi-r/oracle 0.3.0 → 0.5.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 +23 -10
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
|
|
4
|
+
const oracledb = require("oracledb");
|
|
4
5
|
const util_1 = require("@e-mc/db/util");
|
|
5
6
|
const types_1 = require("@e-mc/types");
|
|
6
7
|
const Db = require("@e-mc/db");
|
|
@@ -24,11 +25,22 @@ class OraclePool extends DbPool {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
const POOL_STATE = {};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'connectTimeout', 'queueMax', 'queueRequests', 'queueTimeout'];
|
|
29
|
+
function removePoolProperties(credential) {
|
|
30
|
+
if (!credential.uuidKey) {
|
|
31
|
+
let result;
|
|
32
|
+
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
33
|
+
const attr = POOL_UNUSED[i];
|
|
34
|
+
if (attr in credential) {
|
|
35
|
+
result || (result = { ...credential });
|
|
36
|
+
delete result[attr];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (result) {
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
30
42
|
}
|
|
31
|
-
return
|
|
43
|
+
return credential;
|
|
32
44
|
}
|
|
33
45
|
function getPoolKey(credential) {
|
|
34
46
|
if (credential.connectString && (credential.user && credential.password || credential.externalAuth)) {
|
|
@@ -114,10 +126,9 @@ async function setCredential(item) {
|
|
|
114
126
|
const poolKey = getPoolKey(credential);
|
|
115
127
|
if (poolKey) {
|
|
116
128
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
117
|
-
const { createPool } = require("oracledb" /* STRINGS.PACKAGE_NAME */);
|
|
118
129
|
const config = this.getPoolConfig("oracle" /* STRINGS.MODULE_NAME */, password);
|
|
119
130
|
if (config) {
|
|
120
|
-
const { min, max, idle, queue_max, queue_idle } = config;
|
|
131
|
+
const { min, max, idle, queue_max, queue_idle, timeout } = config;
|
|
121
132
|
if (min >= 0) {
|
|
122
133
|
credential.poolMin ?? (credential.poolMin = min);
|
|
123
134
|
}
|
|
@@ -133,8 +144,11 @@ async function setCredential(item) {
|
|
|
133
144
|
if (queue_idle >= 0) {
|
|
134
145
|
credential.queueTimeout ?? (credential.queueTimeout = queue_idle);
|
|
135
146
|
}
|
|
147
|
+
if (timeout >= 0) {
|
|
148
|
+
credential.connectTimeout ?? (credential.connectTimeout = idle / 1000);
|
|
149
|
+
}
|
|
136
150
|
}
|
|
137
|
-
new OraclePool(await createPool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
151
|
+
new OraclePool(await oracledb.createPool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
138
152
|
}
|
|
139
153
|
else {
|
|
140
154
|
pool.add(item);
|
|
@@ -155,7 +169,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
155
169
|
if (length === 0) {
|
|
156
170
|
return [];
|
|
157
171
|
}
|
|
158
|
-
const db = require("oracledb" /* STRINGS.PACKAGE_NAME */);
|
|
159
172
|
let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
160
173
|
if ((0, types_1.isPlainObject)(options)) {
|
|
161
174
|
({ parallel, connectOnce, errorQuery, sessionKey } = options);
|
|
@@ -216,7 +229,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
216
229
|
pool.connected = false;
|
|
217
230
|
}
|
|
218
231
|
}
|
|
219
|
-
clients.push(client || (client = await
|
|
232
|
+
clients.push(client || (client = await oracledb.getConnection((oracleCredential || credential))));
|
|
220
233
|
if (connectOnce) {
|
|
221
234
|
if (!parallel) {
|
|
222
235
|
oracleClient = client;
|
|
@@ -287,7 +300,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
287
300
|
if (oracleClient && parallel) {
|
|
288
301
|
oracleClient = undefined;
|
|
289
302
|
}
|
|
290
|
-
const executeOptions = { outFormat:
|
|
303
|
+
const executeOptions = { outFormat: oracledb.OUT_FORMAT_OBJECT, ...clientOptions, resultSet: false, autoCommit: true };
|
|
291
304
|
commandType = this.commandType.SELECT;
|
|
292
305
|
if (streamRow) {
|
|
293
306
|
const rows = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/oracle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Oracle client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"oracledb": "^6.
|
|
24
|
+
"@e-mc/db": "^0.7.0",
|
|
25
|
+
"@e-mc/types": "^0.7.0",
|
|
26
|
+
"oracledb": "^6.2.0"
|
|
27
27
|
}
|
|
28
28
|
}
|