@pi-r/oci 0.6.0 → 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.
Files changed (2) hide show
  1. package/client/index.js +38 -6
  2. package/package.json +7 -7
package/client/index.js CHANGED
@@ -71,7 +71,7 @@ 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];
@@ -80,14 +80,14 @@ async function executeBatchQuery(credential, batch, sessionKey) {
80
80
  closeClient();
81
81
  throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
82
82
  }
83
- const renewCache = ignoreCache === 0;
84
83
  const getCache = (value) => {
85
84
  if (ignoreCache !== 1) {
86
- cacheValue.renewCache = renewCache;
85
+ cacheValue.renewCache = ignoreCache === 0;
87
86
  return this.getQueryResult(service, credential, value, cacheValue);
88
87
  }
89
88
  };
90
- let rows, queryString = caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache ? table + '_' : '';
89
+ cacheValue.exclusiveOf = Array.isArray(ignoreCache) ? ignoreCache : undefined;
90
+ let rows, queryString = caching && ignoreCache !== true ? table + '_' : '';
91
91
  invalid: {
92
92
  if (id) {
93
93
  const update = item.update;
@@ -140,7 +140,7 @@ 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
145
  if (queryString && (rows = getCache(queryString += Module.asString(query, true) + (maxRows ? maxRows : '')))) {
146
146
  result[i] = rows;
@@ -159,11 +159,43 @@ async function executeBatchQuery(credential, batch, sessionKey) {
159
159
  }
160
160
  else {
161
161
  const { params, options } = item;
162
+ maxRows || (maxRows = options?.maxRows);
162
163
  if (queryString && (rows = getCache(queryString += query + Module.asString(params, true) + Module.asString(options, true) + (maxRows ? maxRows : '')))) {
163
164
  result[i] = rows;
164
165
  continue;
165
166
  }
166
- ({ rows } = await (client || (client = await createClient())).execute(query, params || [], { ...options, outFormat: 4002 /* OUT_FORMAT.OBJECT */, maxRows, resultSet: false, autoCommit: true }));
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
+ }
167
199
  }
168
200
  }
169
201
  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.1",
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.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
29
  "oracledb": "^6.3.0"
30
30
  }
31
31
  }