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 +36 -8
- package/package.json +1 -1
- package/src/index.js +37 -17
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 (!
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
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 (!
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
|