spice-couchbase 2.0.20 → 2.0.21

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 CHANGED
@@ -77,6 +77,27 @@ module.exports = class Database {
77
77
  }
78
78
  }
79
79
 
80
+ setGlobalConnectionObject(connection) {
81
+ if (spice.checked_collections == undefined) {
82
+ spice.checked_collections = {};
83
+ }
84
+
85
+ _.set(spice.checked_collections, connection, true);
86
+ }
87
+
88
+ checkGlobelConnectionObject(connection) {
89
+ if (spice.checked_collections == undefined) {
90
+ spice.checked_collections = {};
91
+ }
92
+
93
+ if (_.get(spice.checked_collections, connection)) {
94
+ return true;
95
+ }
96
+
97
+ this.setGlobalConnectionObject(connection);
98
+ return false;
99
+ }
100
+
80
101
  connect(connection_name, config) {
81
102
  var _this = this;
82
103
 
@@ -147,10 +168,12 @@ module.exports = class Database {
147
168
  try {
148
169
  var collection_exists = yield _this3.collectionExists(_this3.collection_name, _this3.scope_name);
149
170
 
150
- if (!collection_exists) {
151
- yield _this3.createCollection(_this3.collection_name, _this3.scope_name);
152
- yield _this3.wait(2000);
153
- yield _this3.createPrimaryIndex(_this3.scope_name, _this3.collection_name);
171
+ if (!_this3.checkGlobelConnectionObject(_this3.collection_name)) {
172
+ if (!collection_exists) {
173
+ yield _this3.createCollection(_this3.collection_name, _this3.scope_name);
174
+ yield _this3.wait(2000);
175
+ yield _this3.createPrimaryIndex(_this3.scope_name, _this3.collection_name);
176
+ }
154
177
  }
155
178
  } catch (e) {
156
179
  console.log(e);
@@ -255,10 +278,15 @@ module.exports = class Database {
255
278
  var _this9 = this;
256
279
 
257
280
  return _asyncToGenerator(function* () {
258
- console.log("insert", _this9.use_bucket_name, _this9.connection._name, _this9.collection._name);
259
- yield (_this9.use_bucket_name ? _this9.connection : _this9.collection).insert(doc_id, document, {
260
- expiry: expiry
261
- });
281
+ try {
282
+ yield (_this9.use_bucket_name ? _this9.connection : _this9.collection).insert(doc_id, document, {
283
+ expiry: expiry
284
+ });
285
+ } catch (e) {
286
+ console.log(e.message, e, doc_id);
287
+ }
288
+
289
+ console.log("Return from Insert", doc_id);
262
290
  return yield _this9.get(doc_id);
263
291
  })();
264
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-couchbase",
3
- "version": "2.0.20",
3
+ "version": "2.0.21",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -22,6 +22,7 @@ if (!Promise.allSettled) {
22
22
  )
23
23
  );
24
24
  }
25
+
25
26
  module.exports = class Database {
26
27
  constructor(
27
28
  connection,
@@ -85,6 +86,24 @@ module.exports = class Database {
85
86
  }
86
87
  }
87
88
 
89
+ setGlobalConnectionObject(connection) {
90
+ if (spice.checked_collections == undefined) {
91
+ spice.checked_collections = {};
92
+ }
93
+ _.set(spice.checked_collections, connection, true);
94
+ }
95
+
96
+ checkGlobelConnectionObject(connection) {
97
+ if (spice.checked_collections == undefined) {
98
+ spice.checked_collections = {};
99
+ }
100
+ if (_.get(spice.checked_collections, connection)) {
101
+ return true;
102
+ }
103
+ this.setGlobalConnectionObject(connection);
104
+ return false;
105
+ }
106
+
88
107
  async connect(connection_name, config) {
89
108
  let cluster = await couchbase.connect(config.nodes, {
90
109
  username: config.username,
@@ -153,10 +172,12 @@ module.exports = class Database {
153
172
  this.collection_name,
154
173
  this.scope_name
155
174
  );
156
- if (!collection_exists) {
157
- await this.createCollection(this.collection_name, this.scope_name);
158
- await this.wait(2000);
159
- await this.createPrimaryIndex(this.scope_name, this.collection_name);
175
+ if (!this.checkGlobelConnectionObject(this.collection_name)) {
176
+ if (!collection_exists) {
177
+ await this.createCollection(this.collection_name, this.scope_name);
178
+ await this.wait(2000);
179
+ await this.createPrimaryIndex(this.scope_name, this.collection_name);
180
+ }
160
181
  }
161
182
  } catch (e) {
162
183
  console.log(e);
@@ -245,19 +266,18 @@ module.exports = class Database {
245
266
  }
246
267
 
247
268
  async insert(doc_id, document, expiry) {
248
- console.log(
249
- "insert",
250
- this.use_bucket_name,
251
- this.connection._name,
252
- this.collection._name
253
- );
254
- await (this.use_bucket_name ? this.connection : this.collection).insert(
255
- doc_id,
256
- document,
257
- {
258
- expiry: expiry,
259
- }
260
- );
269
+ try {
270
+ await (this.use_bucket_name ? this.connection : this.collection).insert(
271
+ doc_id,
272
+ document,
273
+ {
274
+ expiry: expiry,
275
+ }
276
+ );
277
+ } catch (e) {
278
+ console.log(e.message, e, doc_id);
279
+ }
280
+ console.log("Return from Insert", doc_id);
261
281
  return await this.get(doc_id);
262
282
  }
263
283