@pi-r/oci 0.6.0 → 0.6.2

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
@@ -71,25 +71,25 @@ async function executeBatchQuery(credential, batch, sessionKey) {
71
71
  const caching = length > 0 && this.hasCache(batch[0].service, sessionKey);
72
72
  const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
73
73
  let client;
74
- const createClient = async () => createDatabaseClient.call(this, length === 1 ? credential : { ...credential });
74
+ const createClient = async () => createDatabaseClient.call(this, credential);
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
- }
83
- const renewCache = ignoreCache === 0;
78
+ const { service, table = '', id, query, ignoreCache } = item;
84
79
  const getCache = (value) => {
85
80
  if (ignoreCache !== 1) {
86
- cacheValue.renewCache = renewCache;
81
+ cacheValue.renewCache = ignoreCache === 0;
87
82
  return this.getQueryResult(service, credential, value, cacheValue);
88
83
  }
89
84
  };
90
- let rows, queryString = caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache ? table + '_' : '';
85
+ cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
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,8 +140,12 @@ async function executeBatchQuery(credential, batch, sessionKey) {
140
140
  }
141
141
  }
142
142
  else if (query) {
143
- const maxRows = typeof item.limit === 'number' ? Math.max(item.limit, 0) : undefined;
143
+ let maxRows = typeof item.limit === 'number' ? Math.max(item.limit, 0) : undefined;
144
144
  if ((0, types_1.isPlainObject)(query)) {
145
+ if (!table) {
146
+ closeClient();
147
+ throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
148
+ }
145
149
  if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows ? maxRows : '')))) {
146
150
  result[i] = rows;
147
151
  continue;
@@ -159,11 +163,43 @@ async function executeBatchQuery(credential, batch, sessionKey) {
159
163
  }
160
164
  else {
161
165
  const { params, options } = item;
166
+ maxRows || (maxRows = options?.maxRows);
162
167
  if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows ? maxRows : '')))) {
163
168
  result[i] = rows;
164
169
  continue;
165
170
  }
166
- ({ rows } = await (client || (client = await createClient())).execute(query, params || [], { ...options, outFormat: 4002 /* OUT_FORMAT.OBJECT */, maxRows, resultSet: false, autoCommit: true }));
171
+ client || (client = await createClient());
172
+ const executeOptions = { ...options, outFormat: 4002 /* OUT_FORMAT.OBJECT */, maxRows, resultSet: false, autoCommit: true };
173
+ if (item.streamRow) {
174
+ rows = [];
175
+ await new Promise((resolve, reject) => {
176
+ let error;
177
+ const stream = client.queryStream(query, params || [], executeOptions);
178
+ stream
179
+ .on('data', row => {
180
+ rows.push(row);
181
+ })
182
+ .on('error', err => {
183
+ error = true;
184
+ reject(err);
185
+ })
186
+ .on('close', () => {
187
+ if (!error) {
188
+ resolve(rows);
189
+ }
190
+ })
191
+ .on('end', () => {
192
+ stream.destroy();
193
+ });
194
+ })
195
+ .catch(err => {
196
+ closeClient();
197
+ throw (0, util_1.formatError)(item, err instanceof Error ? err.message : "Missing database query" /* ERR_DB.QUERY */);
198
+ });
199
+ }
200
+ else {
201
+ ({ rows } = await client.execute(query, params || [], executeOptions));
202
+ }
167
203
  }
168
204
  }
169
205
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/oci",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Oracle (OCI) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -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.0",
24
- "@e-mc/module": "^0.8.0",
25
- "@e-mc/types": "^0.8.0",
26
- "@pi-r/aws": "^0.6.0",
27
- "@pi-r/oracle": "^0.6.0",
28
- "aws-sdk": "^2.1524.0",
23
+ "@e-mc/cloud": "^0.8.2",
24
+ "@e-mc/module": "^0.8.2",
25
+ "@e-mc/types": "^0.8.2",
26
+ "@pi-r/aws": "^0.6.2",
27
+ "@pi-r/oracle": "^0.6.2",
28
+ "aws-sdk": "^2.1545.0",
29
29
  "oracledb": "^6.3.0"
30
30
  }
31
31
  }