@pi-r/oci 0.5.2 → 0.6.1
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 +50 -34
- package/package.json +8 -7
package/client/index.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.executeBatchQuery = exports.executeQuery = exports.deleteObjectsV2 = exp
|
|
|
4
4
|
const oracledb = require("oracledb");
|
|
5
5
|
const types_1 = require("@e-mc/types");
|
|
6
6
|
const aws_1 = require("@pi-r/aws");
|
|
7
|
+
const oracle_1 = require("@pi-r/oracle");
|
|
7
8
|
const util_1 = require("@e-mc/cloud/util");
|
|
8
9
|
const Module = require("@e-mc/module");
|
|
9
10
|
function validateStorage(credential) {
|
|
@@ -26,52 +27,36 @@ function setStorageCredential(credential) {
|
|
|
26
27
|
credential.signatureVersion = 'v4';
|
|
27
28
|
}
|
|
28
29
|
exports.setStorageCredential = setStorageCredential;
|
|
29
|
-
function createDatabaseClient(credential) {
|
|
30
|
+
async function createDatabaseClient(credential) {
|
|
30
31
|
if (credential.username) {
|
|
31
32
|
credential.user || (credential.user = credential.username);
|
|
32
33
|
delete credential.username;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
oracledb.initOracleClient({ libDir: credential.libDir, driverName: credential.driverName, errorUrl: credential.errorUrl });
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
if (err instanceof Error) {
|
|
40
|
-
switch (err.code) {
|
|
41
|
-
case 'NJS-090':
|
|
42
|
-
this.addLog(this.statusType.WARN, err, 'oracledb', credential.libDir);
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
this.writeFail(["Unable to configure client" /* ERR_DB.CLIENT */, 'oracledb'], err, { type: this.logType.CLOUD, fatal: false });
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
35
|
+
oracle_1.initOracleClient.call(this, credential, this.logType.CLOUD);
|
|
51
36
|
return oracledb.getConnection(credential);
|
|
52
37
|
}
|
|
53
38
|
exports.createDatabaseClient = createDatabaseClient;
|
|
54
|
-
function createBucket(credential, bucket, publicRead) {
|
|
39
|
+
async function createBucket(credential, bucket, publicRead) {
|
|
55
40
|
return aws_1.createBucketV2.call(this, credential, bucket, publicRead ? 'public-read' : undefined, undefined, 'oci');
|
|
56
41
|
}
|
|
57
42
|
exports.createBucket = createBucket;
|
|
58
|
-
function createBucketV2(credential, bucket, ACL, options) {
|
|
43
|
+
async function createBucketV2(credential, bucket, ACL, options) {
|
|
59
44
|
return aws_1.createBucketV2.call(this, credential, bucket, ACL, options, 'oci');
|
|
60
45
|
}
|
|
61
46
|
exports.createBucketV2 = createBucketV2;
|
|
62
|
-
function setBucketPolicy(credential, bucket, options) {
|
|
47
|
+
async function setBucketPolicy(credential, bucket, options) {
|
|
63
48
|
return aws_1.setBucketPolicy.call(this, credential, bucket, options, 'oci');
|
|
64
49
|
}
|
|
65
50
|
exports.setBucketPolicy = setBucketPolicy;
|
|
66
|
-
function setBucketWebsite(credential, bucket, options) {
|
|
51
|
+
async function setBucketWebsite(credential, bucket, options) {
|
|
67
52
|
return aws_1.setBucketWebsite.call(this, credential, bucket, options, 'oci');
|
|
68
53
|
}
|
|
69
54
|
exports.setBucketWebsite = setBucketWebsite;
|
|
70
|
-
function deleteObjects(credential, bucket) {
|
|
55
|
+
async function deleteObjects(credential, bucket) {
|
|
71
56
|
return deleteObjectsV2.call(this, credential, bucket, true);
|
|
72
57
|
}
|
|
73
58
|
exports.deleteObjects = deleteObjects;
|
|
74
|
-
function deleteObjectsV2(credential, bucket, recursive = true) {
|
|
59
|
+
async function deleteObjectsV2(credential, bucket, recursive = true) {
|
|
75
60
|
setStorageCredential(credential);
|
|
76
61
|
return aws_1.deleteObjectsV2.call(this, credential, bucket, recursive, 'oci');
|
|
77
62
|
}
|
|
@@ -86,8 +71,8 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
86
71
|
const caching = length > 0 && this.hasCache(batch[0].service, sessionKey);
|
|
87
72
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
88
73
|
let client;
|
|
89
|
-
const createClient = () => createDatabaseClient.call(this,
|
|
90
|
-
const closeClient = () => client?.close();
|
|
74
|
+
const createClient = async () => createDatabaseClient.call(this, credential);
|
|
75
|
+
const closeClient = async () => client?.close();
|
|
91
76
|
for (let i = 0; i < length; ++i) {
|
|
92
77
|
const item = batch[i];
|
|
93
78
|
const { service, table, id, query, ignoreCache } = item;
|
|
@@ -95,15 +80,14 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
95
80
|
closeClient();
|
|
96
81
|
throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
|
|
97
82
|
}
|
|
98
|
-
const renewCache = ignoreCache === 0;
|
|
99
83
|
const getCache = (value) => {
|
|
100
|
-
if (ignoreCache
|
|
101
|
-
|
|
84
|
+
if (ignoreCache !== 1) {
|
|
85
|
+
cacheValue.renewCache = ignoreCache === 0;
|
|
86
|
+
return this.getQueryResult(service, credential, value, cacheValue);
|
|
102
87
|
}
|
|
103
|
-
cacheValue.renewCache = renewCache;
|
|
104
|
-
return this.getQueryResult(service, credential, value, cacheValue);
|
|
105
88
|
};
|
|
106
|
-
|
|
89
|
+
cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
|
|
90
|
+
let rows, queryString = caching && ignoreCache !== true ? table + '_' : '';
|
|
107
91
|
invalid: {
|
|
108
92
|
if (id) {
|
|
109
93
|
const update = item.update;
|
|
@@ -156,7 +140,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
156
140
|
}
|
|
157
141
|
}
|
|
158
142
|
else if (query) {
|
|
159
|
-
|
|
143
|
+
let maxRows = typeof item.limit === 'number' ? Math.max(item.limit, 0) : undefined;
|
|
160
144
|
if ((0, types_1.isPlainObject)(query)) {
|
|
161
145
|
if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows ? maxRows : '')))) {
|
|
162
146
|
result[i] = rows;
|
|
@@ -175,11 +159,43 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
175
159
|
}
|
|
176
160
|
else {
|
|
177
161
|
const { params, options } = item;
|
|
162
|
+
maxRows || (maxRows = options?.maxRows);
|
|
178
163
|
if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows ? maxRows : '')))) {
|
|
179
164
|
result[i] = rows;
|
|
180
165
|
continue;
|
|
181
166
|
}
|
|
182
|
-
|
|
167
|
+
client || (client = await createClient());
|
|
168
|
+
const executeOptions = { ...options, outFormat: 4002 /* OUT_FORMAT.OBJECT */, maxRows, resultSet: false, autoCommit: true };
|
|
169
|
+
if (item.streamRow) {
|
|
170
|
+
rows = [];
|
|
171
|
+
await new Promise((resolve, reject) => {
|
|
172
|
+
let error;
|
|
173
|
+
const stream = client.queryStream(query, params || [], executeOptions);
|
|
174
|
+
stream
|
|
175
|
+
.on('data', row => {
|
|
176
|
+
rows.push(row);
|
|
177
|
+
})
|
|
178
|
+
.on('error', err => {
|
|
179
|
+
error = true;
|
|
180
|
+
reject(err);
|
|
181
|
+
})
|
|
182
|
+
.on('close', () => {
|
|
183
|
+
if (!error) {
|
|
184
|
+
resolve(rows);
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
.on('end', () => {
|
|
188
|
+
stream.destroy();
|
|
189
|
+
});
|
|
190
|
+
})
|
|
191
|
+
.catch(err => {
|
|
192
|
+
closeClient();
|
|
193
|
+
throw (0, util_1.formatError)(item, err instanceof Error ? err.message : "Missing database query" /* ERR_DB.QUERY */);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
({ rows } = await client.execute(query, params || [], executeOptions));
|
|
198
|
+
}
|
|
183
199
|
}
|
|
184
200
|
}
|
|
185
201
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/oci",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Oracle (OCI) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/module": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"@pi-r/aws": "^0.
|
|
27
|
-
"
|
|
28
|
-
"
|
|
23
|
+
"@e-mc/cloud": "^0.8.1",
|
|
24
|
+
"@e-mc/module": "^0.8.1",
|
|
25
|
+
"@e-mc/types": "^0.8.1",
|
|
26
|
+
"@pi-r/aws": "^0.6.1",
|
|
27
|
+
"@pi-r/oracle": "^0.6.1",
|
|
28
|
+
"aws-sdk": "^2.1531.0",
|
|
29
|
+
"oracledb": "^6.3.0"
|
|
29
30
|
}
|
|
30
31
|
}
|