spice-couchbase 2.0.49 → 2.0.50
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/build/index.js +26 -1
- package/package.json +1 -1
- package/src/index.js +29 -0
package/build/index.js
CHANGED
|
@@ -275,11 +275,36 @@ module.exports = class Database {
|
|
|
275
275
|
})();
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
primaryIndexExists(scope_name, col_name) {
|
|
279
|
+
var _this6 = this;
|
|
280
|
+
|
|
281
|
+
return _asyncToGenerator(function* () {
|
|
282
|
+
try {
|
|
283
|
+
var response = yield _this6.cluster.query("SELECT RAW name\n FROM system:indexes\n WHERE bucket_id = $bucket\n AND scope_id = $scope\n AND keyspace_id = $collection\n AND is_primary = true\n LIMIT 1", {
|
|
284
|
+
namedParameters: {
|
|
285
|
+
bucket: _this6.db_config.bucket,
|
|
286
|
+
scope: scope_name,
|
|
287
|
+
collection: col_name
|
|
288
|
+
},
|
|
289
|
+
scanConsistency: QueryScanConsistency.RequestPlus
|
|
290
|
+
});
|
|
291
|
+
return Array.isArray(response && response.rows) && response.rows.length > 0;
|
|
292
|
+
} catch (e) {
|
|
293
|
+
console.log("Primary index lookup failed:", e);
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
})();
|
|
297
|
+
}
|
|
298
|
+
|
|
278
299
|
createPrimaryIndex(scope_name, col_name) {
|
|
279
300
|
var _this6 = this;
|
|
280
301
|
|
|
281
302
|
return _asyncToGenerator(function* () {
|
|
282
303
|
try {
|
|
304
|
+
if (yield _this6.primaryIndexExists(scope_name, col_name)) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
283
308
|
var response = yield _this6.query("CREATE PRIMARY INDEX ON default:`".concat(_this6.db_config.bucket, "`.`").concat(scope_name, "`.`").concat(col_name, "`"));
|
|
284
309
|
return response;
|
|
285
310
|
} catch (e) {
|
|
@@ -872,4 +897,4 @@ module.exports = class Database {
|
|
|
872
897
|
})();
|
|
873
898
|
}
|
|
874
899
|
|
|
875
|
-
};
|
|
900
|
+
};
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -250,8 +250,37 @@ module.exports = class Database {
|
|
|
250
250
|
} catch (e) {}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
async primaryIndexExists(scope_name, col_name) {
|
|
254
|
+
try {
|
|
255
|
+
let response = await this.cluster.query(
|
|
256
|
+
`SELECT RAW name
|
|
257
|
+
FROM system:indexes
|
|
258
|
+
WHERE bucket_id = $bucket
|
|
259
|
+
AND scope_id = $scope
|
|
260
|
+
AND keyspace_id = $collection
|
|
261
|
+
AND is_primary = true
|
|
262
|
+
LIMIT 1`,
|
|
263
|
+
{
|
|
264
|
+
namedParameters: {
|
|
265
|
+
bucket: this.db_config.bucket,
|
|
266
|
+
scope: scope_name,
|
|
267
|
+
collection: col_name,
|
|
268
|
+
},
|
|
269
|
+
scanConsistency: QueryScanConsistency.RequestPlus,
|
|
270
|
+
},
|
|
271
|
+
);
|
|
272
|
+
return Array.isArray(response?.rows) && response.rows.length > 0;
|
|
273
|
+
} catch (e) {
|
|
274
|
+
console.log("Primary index lookup failed:", e);
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
253
279
|
async createPrimaryIndex(scope_name, col_name) {
|
|
254
280
|
try {
|
|
281
|
+
if (await this.primaryIndexExists(scope_name, col_name)) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
255
284
|
let response = await this.query(
|
|
256
285
|
`CREATE PRIMARY INDEX ON default:\`${this.db_config.bucket}\`.\`${scope_name}\`.\`${col_name}\``,
|
|
257
286
|
);
|