spice-couchbase 2.0.19 → 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
@@ -20,6 +20,10 @@ var {
20
20
 
21
21
  var qs = require("qs");
22
22
 
23
+ var {
24
+ ConflictResolutionType
25
+ } = require("couchbase");
26
+
23
27
  if (!Promise.allSettled) {
24
28
  Promise.allSettled = promises => Promise.all(promises.map((promise, i) => promise.then(value => ({
25
29
  status: "fulfilled",
@@ -50,20 +54,48 @@ module.exports = class Database {
50
54
  this.collection_manager = spice.database.buckets[connection].collections();
51
55
  this.auto_create_collection = auto_create_collection || (collection || spice.config.database.connections[connection].collection) != undefined && (collection || spice.config.database.connections[connection].collection) != "default" && (scope || spice.config.database.connections[connection].scope) != "_default";
52
56
  this.collection_name = collection || spice.config.database.connections[connection].collection || "_default";
57
+ /* console.log(
58
+ "Collection",
59
+ collection,
60
+ spice.config.database.connections[connection].collection,
61
+ this.collection_name
62
+ );*/
63
+
53
64
  this.scope_name = scope || spice.config.database.connections[connection].scope || "_default";
54
65
  this.scope = spice.database.scopes[connection];
55
66
  this.full_text_index = spice.config.database.connections[connection].full_text_index || full_text_index;
56
67
  this.N1qlQuery = couchbase.N1qlQuery;
57
68
  this.SearchQuery = couchbase.SearchQuery;
58
- this.connection = this.scope.collection(this.collection_name);
69
+ this.collection = this.scope.collection(this.collection_name);
59
70
  this.userManager = this.getUserManager(connection);
60
71
 
61
72
  if (this.auto_create_collection) {
62
73
  this.upsertCollection();
63
74
  }
64
75
 
65
- this.use_bucket_name = !spice.config.database.connections[this.connection_name].scope;
76
+ this.use_bucket_name = spice.config.database.connections[this.connection_name].scope == undefined;
77
+ }
78
+ }
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 = {};
66
91
  }
92
+
93
+ if (_.get(spice.checked_collections, connection)) {
94
+ return true;
95
+ }
96
+
97
+ this.setGlobalConnectionObject(connection);
98
+ return false;
67
99
  }
68
100
 
69
101
  connect(connection_name, config) {
@@ -136,10 +168,12 @@ module.exports = class Database {
136
168
  try {
137
169
  var collection_exists = yield _this3.collectionExists(_this3.collection_name, _this3.scope_name);
138
170
 
139
- if (!collection_exists) {
140
- yield _this3.createCollection(_this3.collection_name, _this3.scope_name);
141
- yield _this3.wait(2000);
142
- 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
+ }
143
177
  }
144
178
  } catch (e) {
145
179
  console.log(e);
@@ -244,9 +278,15 @@ module.exports = class Database {
244
278
  var _this9 = this;
245
279
 
246
280
  return _asyncToGenerator(function* () {
247
- yield (_this9.use_bucket_name ? _this9.connection : _this9.collection).insert(doc_id, document, {
248
- expiry: expiry
249
- });
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);
250
290
  return yield _this9.get(doc_id);
251
291
  })();
252
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-couchbase",
3
- "version": "2.0.19",
3
+ "version": "2.0.21",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ let _ = require("lodash");
4
4
  let couchbase = require("couchbase");
5
5
  const { default: axios } = require("axios");
6
6
  var qs = require("qs");
7
+ const { ConflictResolutionType } = require("couchbase");
7
8
 
8
9
  if (!Promise.allSettled) {
9
10
  Promise.allSettled = (promises) =>
@@ -21,6 +22,7 @@ if (!Promise.allSettled) {
21
22
  )
22
23
  );
23
24
  }
25
+
24
26
  module.exports = class Database {
25
27
  constructor(
26
28
  connection,
@@ -51,10 +53,17 @@ module.exports = class Database {
51
53
  "default" &&
52
54
  (scope || spice.config.database.connections[connection].scope) !=
53
55
  "_default");
56
+
54
57
  this.collection_name =
55
58
  collection ||
56
59
  spice.config.database.connections[connection].collection ||
57
60
  "_default";
61
+ /* console.log(
62
+ "Collection",
63
+ collection,
64
+ spice.config.database.connections[connection].collection,
65
+ this.collection_name
66
+ );*/
58
67
  this.scope_name =
59
68
  scope ||
60
69
  spice.config.database.connections[connection].scope ||
@@ -65,15 +74,34 @@ module.exports = class Database {
65
74
  full_text_index;
66
75
  this.N1qlQuery = couchbase.N1qlQuery;
67
76
  this.SearchQuery = couchbase.SearchQuery;
68
- this.connection = this.scope.collection(this.collection_name);
77
+ this.collection = this.scope.collection(this.collection_name);
69
78
  this.userManager = this.getUserManager(connection);
70
79
  if (this.auto_create_collection) {
71
80
  this.upsertCollection();
72
81
  }
73
82
 
74
83
  this.use_bucket_name =
75
- !spice.config.database.connections[this.connection_name].scope;
84
+ spice.config.database.connections[this.connection_name].scope ==
85
+ undefined;
86
+ }
87
+ }
88
+
89
+ setGlobalConnectionObject(connection) {
90
+ if (spice.checked_collections == undefined) {
91
+ spice.checked_collections = {};
76
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;
77
105
  }
78
106
 
79
107
  async connect(connection_name, config) {
@@ -144,10 +172,12 @@ module.exports = class Database {
144
172
  this.collection_name,
145
173
  this.scope_name
146
174
  );
147
- if (!collection_exists) {
148
- await this.createCollection(this.collection_name, this.scope_name);
149
- await this.wait(2000);
150
- 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
+ }
151
181
  }
152
182
  } catch (e) {
153
183
  console.log(e);
@@ -236,13 +266,18 @@ module.exports = class Database {
236
266
  }
237
267
 
238
268
  async insert(doc_id, document, expiry) {
239
- await (this.use_bucket_name ? this.connection : this.collection).insert(
240
- doc_id,
241
- document,
242
- {
243
- expiry: expiry,
244
- }
245
- );
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);
246
281
  return await this.get(doc_id);
247
282
  }
248
283