@pi-r/oracle 0.2.2 → 0.2.9
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/LICENSE +1 -1
- package/README.md +4 -2
- package/client/index.d.ts +2 -2
- package/client/index.js +32 -21
- package/package.json +4 -4
- package/types/index.d.ts +1 -0
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2020-24 Code Geass
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/client/index.d.ts
CHANGED
package/client/index.js
CHANGED
|
@@ -17,18 +17,29 @@ class OraclePool extends DbPool {
|
|
|
17
17
|
return this.closed || connectionsInUse === 0 && currentQueueLength === 0;
|
|
18
18
|
}
|
|
19
19
|
get closeable() {
|
|
20
|
-
return super.closeable || this.client.status === 6001
|
|
20
|
+
return super.closeable || this.client.status === 6001;
|
|
21
21
|
}
|
|
22
22
|
get closed() {
|
|
23
|
-
return this.client.status === 6002
|
|
23
|
+
return this.client.status === 6002;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
const POOL_STATE = {};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const POOL_UNUSED = ['poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'queueMax', 'queueRequests', 'queueTimeout'];
|
|
28
|
+
function removePoolProperties(credential) {
|
|
29
|
+
if (!credential.uuidKey) {
|
|
30
|
+
let result;
|
|
31
|
+
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
32
|
+
const attr = POOL_UNUSED[i];
|
|
33
|
+
if (attr in credential) {
|
|
34
|
+
result || (result = { ...credential });
|
|
35
|
+
delete result[attr];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (result) {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
|
-
return
|
|
42
|
+
return credential;
|
|
32
43
|
}
|
|
33
44
|
function getPoolKey(credential) {
|
|
34
45
|
if (credential.connectString && (credential.user && credential.password || credential.externalAuth)) {
|
|
@@ -84,7 +95,7 @@ async function setCredential(item) {
|
|
|
84
95
|
errors.push('connectString');
|
|
85
96
|
}
|
|
86
97
|
if (errors.length) {
|
|
87
|
-
throw (0, types_1.errorMessage)("oracle"
|
|
98
|
+
throw (0, types_1.errorMessage)("oracle", 'Not defined - ' + errors.join(' | '));
|
|
88
99
|
}
|
|
89
100
|
}
|
|
90
101
|
const usePool = item.usePool;
|
|
@@ -114,8 +125,8 @@ async function setCredential(item) {
|
|
|
114
125
|
const poolKey = getPoolKey(credential);
|
|
115
126
|
if (poolKey) {
|
|
116
127
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
117
|
-
const { createPool } = require("oracledb"
|
|
118
|
-
const config = this.getPoolConfig("oracle"
|
|
128
|
+
const { createPool } = require("oracledb");
|
|
129
|
+
const config = this.getPoolConfig("oracle", password);
|
|
119
130
|
if (config) {
|
|
120
131
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
121
132
|
if (min >= 0) {
|
|
@@ -155,7 +166,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
155
166
|
if (length === 0) {
|
|
156
167
|
return [];
|
|
157
168
|
}
|
|
158
|
-
const db = require("oracledb"
|
|
169
|
+
const db = require("oracledb");
|
|
159
170
|
let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
160
171
|
if ((0, types_1.isPlainObject)(options)) {
|
|
161
172
|
({ parallel, connectOnce, errorQuery, sessionKey } = options);
|
|
@@ -176,16 +187,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
176
187
|
if (!parallel) {
|
|
177
188
|
outResult || (outResult = new Array(length));
|
|
178
189
|
}
|
|
179
|
-
const caching = this.hasCache("oracle"
|
|
190
|
+
const caching = this.hasCache("oracle", sessionKey);
|
|
180
191
|
const tasks = new Array(length);
|
|
181
192
|
const clients = [];
|
|
182
193
|
let oraclePool, oracleClient, oracleCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
|
|
183
194
|
const getConnection = async (item, credential) => {
|
|
184
|
-
item.transactionState = 64
|
|
195
|
+
item.transactionState = 64;
|
|
185
196
|
let client;
|
|
186
197
|
if (oraclePool) {
|
|
187
198
|
clients.push(client = await oraclePool.getConnection());
|
|
188
|
-
item.transactionState &= ~64
|
|
199
|
+
item.transactionState &= ~64;
|
|
189
200
|
return client;
|
|
190
201
|
}
|
|
191
202
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -223,14 +234,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
223
234
|
}
|
|
224
235
|
oracleCredential = credential;
|
|
225
236
|
}
|
|
226
|
-
item.transactionState &= ~64
|
|
237
|
+
item.transactionState &= ~64;
|
|
227
238
|
return client;
|
|
228
239
|
};
|
|
229
240
|
for (let i = 0; i < length; ++i) {
|
|
230
241
|
const item = batch[i];
|
|
231
242
|
const { source, query, params, ignoreCache, options: clientOptions } = item;
|
|
232
243
|
let credential = oracleCredential || onceCredential, error;
|
|
233
|
-
if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
244
|
+
if (!credential && !(0, types_1.isPlainObject)(credential = item.credential) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !query && (error = (0, types_1.errorMessage)(source, "Missing database query"))) {
|
|
234
245
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
235
246
|
if (!parallel) {
|
|
236
247
|
tasks.length = 0;
|
|
@@ -246,8 +257,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
246
257
|
}
|
|
247
258
|
continue;
|
|
248
259
|
}
|
|
249
|
-
item.transactionState = 1
|
|
250
|
-
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle"
|
|
260
|
+
item.transactionState = 1;
|
|
261
|
+
const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle", 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
|
|
251
262
|
const renewCache = ignoreCache === 0;
|
|
252
263
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
253
264
|
let queryString = '';
|
|
@@ -262,7 +273,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
262
273
|
else {
|
|
263
274
|
outResult[i] = result;
|
|
264
275
|
}
|
|
265
|
-
this.add(item, 4
|
|
276
|
+
this.add(item, 4 | 128);
|
|
266
277
|
continue;
|
|
267
278
|
}
|
|
268
279
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -313,7 +324,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
313
324
|
reject(error);
|
|
314
325
|
}
|
|
315
326
|
else {
|
|
316
|
-
this.add(item, 4
|
|
327
|
+
this.add(item, 4);
|
|
317
328
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
|
|
318
329
|
}
|
|
319
330
|
})
|
|
@@ -321,7 +332,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
321
332
|
}
|
|
322
333
|
else {
|
|
323
334
|
const { rows } = await client.execute(query, params || [], executeOptions);
|
|
324
|
-
this.add(item, 4
|
|
335
|
+
this.add(item, 4);
|
|
325
336
|
resolve(rows ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
|
|
326
337
|
}
|
|
327
338
|
}
|
|
@@ -345,7 +356,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
345
356
|
}
|
|
346
357
|
}
|
|
347
358
|
return this.processRows(batch, tasks, {
|
|
348
|
-
disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection"
|
|
359
|
+
disconnect: () => clients.forEach(item => item.close(err => err && this.writeFail(["Unable to close connnection", "oracle"], err, { type: 65536, fatal: false }))),
|
|
349
360
|
parallel
|
|
350
361
|
}, outResult);
|
|
351
362
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/oracle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Oracle client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/oracle"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.5.
|
|
25
|
-
"@e-mc/types": "^0.5.
|
|
24
|
+
"@e-mc/db": "^0.5.5",
|
|
25
|
+
"@e-mc/types": "^0.5.5",
|
|
26
26
|
"oracledb": "^5.5.0"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
|
2
2
|
|
|
3
3
|
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
4
|
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
import type { BindParameters, ConnectionAttributes, ExecuteOptions, PoolAttributes } from 'oracledb';
|
|
6
7
|
|
|
7
8
|
export interface OracleDataSource extends DbDataSource<string, ExecuteOptions, unknown, string | OracleCredential, string>, ExecuteAction<BindParameters> {
|