spice-couchbase 2.0.18 → 2.0.19

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/build/index.js +48 -72
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -61,6 +61,8 @@ module.exports = class Database {
61
61
  if (this.auto_create_collection) {
62
62
  this.upsertCollection();
63
63
  }
64
+
65
+ this.use_bucket_name = !spice.config.database.connections[this.connection_name].scope;
64
66
  }
65
67
  }
66
68
 
@@ -228,7 +230,7 @@ module.exports = class Database {
228
230
 
229
231
  return _asyncToGenerator(function* () {
230
232
  try {
231
- var response = yield _this8.connection.get(doc_id);
233
+ var response = yield (_this8.use_bucket_name ? _this8.connection : _this8.collection).get(doc_id);
232
234
  return _objectSpread({
233
235
  id: doc_id
234
236
  }, response.content);
@@ -239,56 +241,31 @@ module.exports = class Database {
239
241
  }
240
242
 
241
243
  insert(doc_id, document, expiry) {
242
- var that = this;
243
- return new Promise(
244
- /*#__PURE__*/
245
- function () {
246
- var _ref = _asyncToGenerator(function* (resolve, reject) {
247
- that.connection.insert(doc_id, document, {
248
- expiry: expiry
249
- },
250
- /*#__PURE__*/
251
- function () {
252
- var _ref2 = _asyncToGenerator(function* (err, res) {
253
- if (err) {
254
- reject(err);
255
- } else {
256
- try {
257
- var created = yield that.get(doc_id);
258
- resolve(created);
259
- } catch (e) {
260
- reject(e);
261
- }
262
- }
263
- });
244
+ var _this9 = this;
264
245
 
265
- return function (_x3, _x4) {
266
- return _ref2.apply(this, arguments);
267
- };
268
- }());
246
+ return _asyncToGenerator(function* () {
247
+ yield (_this9.use_bucket_name ? _this9.connection : _this9.collection).insert(doc_id, document, {
248
+ expiry: expiry
269
249
  });
270
-
271
- return function (_x, _x2) {
272
- return _ref.apply(this, arguments);
273
- };
274
- }());
250
+ return yield _this9.get(doc_id);
251
+ })();
275
252
  }
276
253
 
277
254
  touch(doc_id) {
278
- var _this9 = this;
255
+ var _this10 = this;
279
256
 
280
257
  var expiry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
281
258
  return _asyncToGenerator(function* () {
282
- yield _this9.connection.touch(doc_id, expiry);
283
- return yield that.get(doc_id);
259
+ yield (_this10.use_bucket_name ? _this10.connection : _this10.collection).touch(doc_id, expiry);
260
+ return yield _this10.get(doc_id);
284
261
  })();
285
262
  }
286
263
 
287
264
  count(doc_id, adjustment, initial_value) {
288
- var _this10 = this;
265
+ var _this11 = this;
289
266
 
290
267
  return _asyncToGenerator(function* () {
291
- var res = yield _this10.connection.counter(doc_id, adjustment, {
268
+ var res = yield (_this11.use_bucket_name ? _this11.connection : _this11.collection).counter(doc_id, adjustment, {
292
269
  initial: initial_value
293
270
  });
294
271
  return res.value;
@@ -296,25 +273,25 @@ module.exports = class Database {
296
273
  }
297
274
 
298
275
  update(doc_id, document) {
299
- var _this11 = this;
276
+ var _this12 = this;
300
277
 
301
278
  return _asyncToGenerator(function* () {
302
- var res = yield _this11.connection.replace(doc_id, document);
279
+ var res = yield (_this12.use_bucket_name ? _this12.connection : _this12.collection).replace(doc_id, document);
303
280
  return res.value;
304
281
  })();
305
282
  }
306
283
 
307
284
  delete(doc_id) {
308
- var _this12 = this;
285
+ var _this13 = this;
309
286
 
310
287
  return _asyncToGenerator(function* () {
311
- var res = yield _this12.connection.remove(doc_id);
288
+ var res = yield (_this13.use_bucket_name ? _this13.connection : _this13.collection).remove(doc_id);
312
289
  return res.value;
313
290
  })();
314
291
  }
315
292
 
316
293
  multi_get(keys, keep_type) {
317
- var _this13 = this;
294
+ var _this14 = this;
318
295
 
319
296
  return _asyncToGenerator(function* () {
320
297
  /* var that = this; */
@@ -326,7 +303,7 @@ module.exports = class Database {
326
303
 
327
304
 
328
305
  if (_.isArray(keys) && keys.length > 0) {
329
- var functions = _.map(keys, key => _this13.connection.get(key));
306
+ var functions = _.map(keys, key => (_this14.use_bucket_name ? _this14.connection : _this14.collection).get(key));
330
307
 
331
308
  var returned_all = yield Promise.allSettled(functions);
332
309
 
@@ -353,7 +330,7 @@ module.exports = class Database {
353
330
  return new Promise(
354
331
  /*#__PURE__*/
355
332
  function () {
356
- var _ref3 = _asyncToGenerator(function* (resolve, reject) {
333
+ var _ref = _asyncToGenerator(function* (resolve, reject) {
357
334
  var ViewQuery = couchbase.ViewQuery;
358
335
  var query = ViewQuery.from(design_doc, view);
359
336
 
@@ -380,7 +357,7 @@ module.exports = class Database {
380
357
  that.connection.query(query,
381
358
  /*#__PURE__*/
382
359
  function () {
383
- var _ref4 = _asyncToGenerator(function* (err, results, matrix) {
360
+ var _ref2 = _asyncToGenerator(function* (err, results, matrix) {
384
361
  var return_value = [];
385
362
 
386
363
  if (err) {
@@ -403,26 +380,25 @@ module.exports = class Database {
403
380
  }
404
381
  });
405
382
 
406
- return function (_x7, _x8, _x9) {
407
- return _ref4.apply(this, arguments);
383
+ return function (_x3, _x4, _x5) {
384
+ return _ref2.apply(this, arguments);
408
385
  };
409
386
  }());
410
387
  });
411
388
 
412
- return function (_x5, _x6) {
413
- return _ref3.apply(this, arguments);
389
+ return function (_x, _x2) {
390
+ return _ref.apply(this, arguments);
414
391
  };
415
392
  }());
416
393
  }
417
394
 
418
395
  search(type, columns, query, limit, offset, order_by, do_count, query_scope) {
419
- var _this14 = this;
396
+ var _this15 = this;
420
397
 
421
398
  return _asyncToGenerator(function* () {
422
- var use_bucket_name = !(spice.config.database.connections[_this14.connection_name].scope && spice.config.database.connections[_this14.connection_name].collection);
423
- var is_legacy = _this14.scope_name !== "_default" && _this14.collection_name !== "_default";
399
+ var is_legacy = _this15.scope_name !== "_default" && _this15.collection_name !== "_default";
424
400
  var alias = "_reference";
425
- var bucket = "`".concat(use_bucket_name ? _this14.bucket : _this14.collection_name, "`");
401
+ var bucket = "`".concat(_this15.use_bucket_name ? _this15.bucket : _this15.collection_name, "`");
426
402
 
427
403
  try {
428
404
  //let uses_scopes = this.scope this.scope_name !== "_default";
@@ -464,7 +440,7 @@ module.exports = class Database {
464
440
 
465
441
  var conditions = [];
466
442
 
467
- if (use_bucket_name) {
443
+ if (_this15.use_bucket_name) {
468
444
  conditions.push("type = '".concat(type, "'"));
469
445
  }
470
446
 
@@ -475,7 +451,7 @@ module.exports = class Database {
475
451
  query = front_query + conditions.join(" AND ");
476
452
  count_query = "SELECT count(meta().id) as count FROM ".concat(bucket);
477
453
 
478
- if (use_bucket_name || query) {
454
+ if (_this15.use_bucket_name || query) {
479
455
  count_query += " WHERE ";
480
456
  }
481
457
 
@@ -493,11 +469,11 @@ module.exports = class Database {
493
469
  query = query + " OFFSET " + offset;
494
470
  }
495
471
 
496
- var active_query_space = query_scope || !use_bucket_name ? "scope" : "cluster";
497
- var queries = [_this14.getData(query, active_query_space)];
472
+ var active_query_space = query_scope || !_this15.use_bucket_name ? "scope" : "cluster";
473
+ var queries = [_this15.getData(query, active_query_space)];
498
474
 
499
475
  if (do_count === "true") {
500
- queries.push(_this14.getCount(count_query, active_query_space));
476
+ queries.push(_this15.getCount(count_query, active_query_space));
501
477
  }
502
478
 
503
479
  var responses = yield Promise.all(queries);
@@ -518,7 +494,7 @@ module.exports = class Database {
518
494
  return new Promise(
519
495
  /*#__PURE__*/
520
496
  function () {
521
- var _ref5 = _asyncToGenerator(function* (resolve, reject) {
497
+ var _ref3 = _asyncToGenerator(function* (resolve, reject) {
522
498
  try {
523
499
  var full_query = search_query + " AND type:" + type;
524
500
  var query = that.SearchQuery.new(that.full_text_index || full_text_index, that.SearchQuery.queryString(full_query));
@@ -539,7 +515,7 @@ module.exports = class Database {
539
515
  that.cluster.query(query,
540
516
  /*#__PURE__*/
541
517
  function () {
542
- var _ref6 = _asyncToGenerator(function* (err, results, matrix) {
518
+ var _ref4 = _asyncToGenerator(function* (err, results, matrix) {
543
519
  var return_value = [];
544
520
 
545
521
  if (err) {
@@ -565,8 +541,8 @@ module.exports = class Database {
565
541
  }
566
542
  });
567
543
 
568
- return function (_x12, _x13, _x14) {
569
- return _ref6.apply(this, arguments);
544
+ return function (_x8, _x9, _x10) {
545
+ return _ref4.apply(this, arguments);
570
546
  };
571
547
  }());
572
548
  } catch (e) {
@@ -574,43 +550,43 @@ module.exports = class Database {
574
550
  }
575
551
  });
576
552
 
577
- return function (_x10, _x11) {
578
- return _ref5.apply(this, arguments);
553
+ return function (_x6, _x7) {
554
+ return _ref3.apply(this, arguments);
579
555
  };
580
556
  }());
581
557
  }
582
558
 
583
559
  getCount(count_query_element) {
584
- var _this15 = this;
560
+ var _this16 = this;
585
561
 
586
562
  var query_scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cluster";
587
563
  return _asyncToGenerator(function* () {
588
- var response = yield _this15.query(count_query_element, query_scope);
564
+ var response = yield _this16.query(count_query_element, query_scope);
589
565
  return response.rows[0].count;
590
566
  })();
591
567
  }
592
568
 
593
569
  getData(query_element) {
594
- var _this16 = this;
570
+ var _this17 = this;
595
571
 
596
572
  var query_scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cluster";
597
573
  return _asyncToGenerator(function* () {
598
- var response = yield _this16.query(query_element, query_scope);
574
+ var response = yield _this17.query(query_element, query_scope);
599
575
  return response.rows;
600
576
  })();
601
577
  }
602
578
 
603
579
  query(query) {
604
- var _this17 = this;
580
+ var _this18 = this;
605
581
 
606
582
  var query_scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cluster";
607
583
  return _asyncToGenerator(function* () {
608
- var scope = query_scope || _this17.query_scope;
584
+ var scope = query_scope || _this18.query_scope;
609
585
 
610
586
  if (scope == "cluster") {
611
- return yield _this17.cluster.query(query);
587
+ return yield _this18.cluster.query(query);
612
588
  } else {
613
- return yield _this17.scope.query(query);
589
+ return yield _this18.scope.query(query);
614
590
  }
615
591
  })();
616
592
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-couchbase",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {