@pi-r/oracle 0.3.5 → 0.3.6
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 +6 -6
- package/README.md +4 -6
- package/client/index.d.ts +6 -6
- package/client/index.js +5 -4
- package/client/pool.js +54 -0
- package/package.json +28 -28
- package/types/index.d.ts +11 -11
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
package/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
2
|
-
|
|
3
|
-
import type { OracleDataSource } from '../types';
|
|
4
|
-
|
|
5
|
-
declare const Oracle: IDbSourceClient<OracleDataSource>;
|
|
6
|
-
|
|
1
|
+
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
2
|
+
|
|
3
|
+
import type { OracleDataSource } from '../types';
|
|
4
|
+
|
|
5
|
+
declare const Oracle: IDbSourceClient<OracleDataSource>;
|
|
6
|
+
|
|
7
7
|
export = Oracle;
|
package/client/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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");
|
|
5
4
|
const util_1 = require("@e-mc/db/util");
|
|
6
5
|
const types_1 = require("@e-mc/types");
|
|
7
6
|
const Db = require("@e-mc/db");
|
|
@@ -128,6 +127,7 @@ async function setCredential(item) {
|
|
|
128
127
|
const poolKey = getPoolKey(credential);
|
|
129
128
|
if (poolKey) {
|
|
130
129
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
130
|
+
const { createPool } = require("oracledb");
|
|
131
131
|
const config = this.getPoolConfig("oracle", password);
|
|
132
132
|
if (config) {
|
|
133
133
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
@@ -147,7 +147,7 @@ async function setCredential(item) {
|
|
|
147
147
|
(_e = credential.queueTimeout) !== null && _e !== void 0 ? _e : (credential.queueTimeout = queue_idle);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
new OraclePool(await
|
|
150
|
+
new OraclePool(await createPool(credential), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
153
|
pool.add(item);
|
|
@@ -168,6 +168,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
168
168
|
if (length === 0) {
|
|
169
169
|
return [];
|
|
170
170
|
}
|
|
171
|
+
const db = require("oracledb");
|
|
171
172
|
let parallel, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
172
173
|
if ((0, types_1.isPlainObject)(options)) {
|
|
173
174
|
({ parallel, connectOnce, errorQuery, sessionKey } = options);
|
|
@@ -228,7 +229,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
228
229
|
pool.connected = false;
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
|
-
clients.push(client || (client = await
|
|
232
|
+
clients.push(client || (client = await db.getConnection((oracleCredential || credential))));
|
|
232
233
|
if (connectOnce) {
|
|
233
234
|
if (!parallel) {
|
|
234
235
|
oracleClient = client;
|
|
@@ -299,7 +300,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
299
300
|
if (oracleClient && parallel) {
|
|
300
301
|
oracleClient = undefined;
|
|
301
302
|
}
|
|
302
|
-
const executeOptions = { outFormat:
|
|
303
|
+
const executeOptions = { outFormat: db.OUT_FORMAT_OBJECT, ...clientOptions, resultSet: false, autoCommit: true };
|
|
303
304
|
commandType = this.commandType.SELECT;
|
|
304
305
|
if (streamRow) {
|
|
305
306
|
const rows = [];
|
package/client/pool.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const DbPool = require('@e-mc/db/pool');
|
|
3
|
+
const POOL_ACTIVE = new WeakSet();
|
|
4
|
+
class OraclePool extends DbPool {
|
|
5
|
+
static CACHE_UNUSED = ['connectTimeout', 'transportConnectTimeout', 'expireTime', 'poolMax', 'poolMin', 'poolIncrement', 'poolTimeout', 'poolPingInterval', 'poolMaxPerShard', 'queueMax', 'queueRequests', 'queueTimeout', 'enableStatistics', 'sodaMetaDataCache', 'stmtCacheSize', 'httpsProxy', 'httpsProxyPort'];
|
|
6
|
+
static CACHE_IGNORE = ['sessionCallback'];
|
|
7
|
+
static asString(credential) {
|
|
8
|
+
if (credential.connectString && (credential.user && credential.password || credential.externalAuth) || credential.poolAlias) {
|
|
9
|
+
return JSON.stringify(this.removeUUIDKey(credential));
|
|
10
|
+
}
|
|
11
|
+
return super.asString(credential);
|
|
12
|
+
}
|
|
13
|
+
static sanitize(credential) {
|
|
14
|
+
if (!this.canCache(credential)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!POOL_ACTIVE.has(credential) || credential.uuidKey) {
|
|
18
|
+
return credential;
|
|
19
|
+
}
|
|
20
|
+
return super.sanitize(credential);
|
|
21
|
+
}
|
|
22
|
+
get closeable() {
|
|
23
|
+
return super.closeable || this.client.status === 6001;
|
|
24
|
+
}
|
|
25
|
+
async getConnection(credential) {
|
|
26
|
+
if (credential) {
|
|
27
|
+
POOL_ACTIVE.add(credential);
|
|
28
|
+
}
|
|
29
|
+
return this.client.getConnection();
|
|
30
|
+
}
|
|
31
|
+
async close() {
|
|
32
|
+
return this.client.close();
|
|
33
|
+
}
|
|
34
|
+
isEmpty() {
|
|
35
|
+
if (this.closed) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const data = this.client.getStatistics();
|
|
40
|
+
if (data) {
|
|
41
|
+
const { connectionsInUse, currentQueueLength } = data;
|
|
42
|
+
return connectionsInUse === 0 && currentQueueLength === 0;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
get closed() {
|
|
51
|
+
return this.client.status === 6002;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
module.exports = OraclePool;
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/oracle",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "Oracle client driver for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"types": "client/index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
|
-
"directory": "src/db/oracle"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"e-mc",
|
|
18
|
-
"squared-functions"
|
|
19
|
-
],
|
|
20
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.6.
|
|
25
|
-
"@e-mc/types": "^0.6.
|
|
26
|
-
"oracledb": "^6.5.1"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/oracle",
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"description": "Oracle client driver for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"types": "client/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
|
+
"directory": "src/db/oracle"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"e-mc",
|
|
18
|
+
"squared-functions"
|
|
19
|
+
],
|
|
20
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@e-mc/db": "^0.6.16",
|
|
25
|
+
"@e-mc/types": "^0.6.16",
|
|
26
|
+
"oracledb": "^6.5.1"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import type { BindParameters, ConnectionAttributes, ExecuteOptions, PoolAttributes } from 'oracledb';
|
|
7
|
-
|
|
8
|
-
export interface OracleDataSource extends DbDataSource<string, ExecuteOptions, unknown, string | OracleCredential, string>, ExecuteAction<BindParameters> {
|
|
9
|
-
source: "oracle";
|
|
10
|
-
}
|
|
11
|
-
|
|
1
|
+
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import type { BindParameters, ConnectionAttributes, ExecuteOptions, PoolAttributes } from 'oracledb';
|
|
7
|
+
|
|
8
|
+
export interface OracleDataSource extends DbDataSource<string, ExecuteOptions, unknown, string | OracleCredential, string>, ExecuteAction<BindParameters> {
|
|
9
|
+
source: "oracle";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
12
|
export interface OracleCredential extends ServerAuth, ConnectionAttributes, PoolAttributes {}
|