@pi-r/oci 0.6.1 → 0.6.3

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @pi-r/oci
2
2
 
3
+ https://e-mc.readthedocs.io/en/latest/cloud/oci.html
4
+
3
5
  ### LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -75,11 +75,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
75
75
  const closeClient = async () => client?.close();
76
76
  for (let i = 0; i < length; ++i) {
77
77
  const item = batch[i];
78
- const { service, table, id, query, ignoreCache } = item;
79
- if (!table) {
80
- closeClient();
81
- throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
82
- }
78
+ const { service, table = '', id, query, ignoreCache } = item;
83
79
  const getCache = (value) => {
84
80
  if (ignoreCache !== 1) {
85
81
  cacheValue.renewCache = ignoreCache === 0;
@@ -90,6 +86,10 @@ async function executeBatchQuery(credential, batch, sessionKey) {
90
86
  let rows, queryString = caching && ignoreCache !== true ? table + '_' : '';
91
87
  invalid: {
92
88
  if (id) {
89
+ if (!table) {
90
+ closeClient();
91
+ throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
92
+ }
93
93
  const update = item.update;
94
94
  if (queryString) {
95
95
  queryString += id;
@@ -140,9 +140,13 @@ async function executeBatchQuery(credential, batch, sessionKey) {
140
140
  }
141
141
  }
142
142
  else if (query) {
143
- let maxRows = typeof item.limit === 'number' ? Math.max(item.limit, 0) : undefined;
143
+ let maxRows = typeof item.limit === 'number' ? item.limit : NaN;
144
144
  if ((0, types_1.isPlainObject)(query)) {
145
- if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows ? maxRows : '')))) {
145
+ if (!table) {
146
+ closeClient();
147
+ throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
148
+ }
149
+ if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows > 0 ? maxRows : '')))) {
146
150
  result[i] = rows;
147
151
  continue;
148
152
  }
@@ -151,16 +155,40 @@ async function executeBatchQuery(credential, batch, sessionKey) {
151
155
  closeClient();
152
156
  throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
153
157
  }
154
- let operation = db.find().filter(query);
155
- if (maxRows) {
156
- operation = operation.limit(maxRows);
158
+ const tryQuery = async () => {
159
+ let operation = db.find().filter(query);
160
+ if (maxRows > 0) {
161
+ operation = operation.limit(maxRows);
162
+ }
163
+ return (await operation.getDocuments()).map(doc => doc.getContent());
164
+ };
165
+ try {
166
+ rows = await tryQuery();
167
+ }
168
+ catch (err) {
169
+ switch (err instanceof Error && err.code) {
170
+ case 'ORA-40820':
171
+ if (maxRows > 0) {
172
+ const limit = maxRows;
173
+ maxRows = 0;
174
+ rows = await tryQuery();
175
+ if (limit > rows.length) {
176
+ rows = rows.slice(0, limit);
177
+ }
178
+ this.addLog(types_1.STATUS_TYPE.WARN, err, service, Module.asString(query, true));
179
+ break;
180
+ }
181
+ default:
182
+ throw err;
183
+ }
157
184
  }
158
- rows = (await operation.getDocuments()).map(doc => doc.getContent());
159
185
  }
160
186
  else {
161
187
  const { params, options } = item;
162
- maxRows || (maxRows = options?.maxRows);
163
- if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows ? maxRows : '')))) {
188
+ if (options?.maxRows && isNaN(maxRows)) {
189
+ maxRows = options.maxRows;
190
+ }
191
+ if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows > 0 ? maxRows : '')))) {
164
192
  result[i] = rows;
165
193
  continue;
166
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oci",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Oracle (OCI) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/anpham6/pi-r.git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
12
  "directory": "src/cloud/oci"
13
13
  },
14
14
  "keywords": [
@@ -20,12 +20,12 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
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",
23
+ "@e-mc/cloud": "^0.8.3",
24
+ "@e-mc/module": "^0.8.3",
25
+ "@e-mc/types": "^0.8.3",
26
+ "@pi-r/aws": "^0.6.3",
27
+ "@pi-r/oracle": "^0.6.3",
28
+ "aws-sdk": "^2.1547.0",
29
29
  "oracledb": "^6.3.0"
30
30
  }
31
31
  }