spice-couchbase 2.0.31 → 2.0.33
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 +67 -17
- package/package.json +2 -2
- package/src/index.js +47 -21
package/build/index.js
CHANGED
|
@@ -24,6 +24,10 @@ var {
|
|
|
24
24
|
ConflictResolutionType
|
|
25
25
|
} = require("couchbase");
|
|
26
26
|
|
|
27
|
+
var {
|
|
28
|
+
QueryScanConsistency
|
|
29
|
+
} = require("couchbase");
|
|
30
|
+
|
|
27
31
|
if (!Promise.allSettled) {
|
|
28
32
|
Promise.allSettled = promises => Promise.all(promises.map((promise, i) => promise.then(value => ({
|
|
29
33
|
status: "fulfilled",
|
|
@@ -45,6 +49,8 @@ module.exports = class Database {
|
|
|
45
49
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
46
50
|
|
|
47
51
|
if (connection) {
|
|
52
|
+
var _spice, _spice$db;
|
|
53
|
+
|
|
48
54
|
this.connection_name = connection;
|
|
49
55
|
this.connection = spice.database.connections[connection];
|
|
50
56
|
this.query_scope = query_scope;
|
|
@@ -69,6 +75,11 @@ module.exports = class Database {
|
|
|
69
75
|
this.collection = this.scope.collection(this.collection_name);
|
|
70
76
|
this.userManager = this.getUserManager(connection);
|
|
71
77
|
|
|
78
|
+
if (!((_spice = spice) === null || _spice === void 0 ? void 0 : (_spice$db = _spice.db) === null || _spice$db === void 0 ? void 0 : _spice$db.collections)) {
|
|
79
|
+
spice.db = spice.db || {};
|
|
80
|
+
spice.db.collections = new Set();
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
if (this.auto_create_collection) {
|
|
73
84
|
this.upsertCollection();
|
|
74
85
|
}
|
|
@@ -170,9 +181,9 @@ module.exports = class Database {
|
|
|
170
181
|
|
|
171
182
|
if (!_this3.checkGlobelConnectionObject(_this3.collection_name)) {
|
|
172
183
|
if (!collection_exists) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
184
|
+
/* await this.createCollection(this.collection_name, this.scope_name);
|
|
185
|
+
await this.wait(2000);
|
|
186
|
+
await this.createPrimaryIndex(this.scope_name, this.collection_name); */
|
|
176
187
|
}
|
|
177
188
|
}
|
|
178
189
|
} catch (e) {
|
|
@@ -186,20 +197,56 @@ module.exports = class Database {
|
|
|
186
197
|
|
|
187
198
|
return _asyncToGenerator(function* () {
|
|
188
199
|
try {
|
|
189
|
-
var
|
|
200
|
+
var _spice2, _spice2$db, _spice2$db$collection;
|
|
190
201
|
|
|
191
|
-
var
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
var that = _this4;
|
|
203
|
+
|
|
204
|
+
function loadAllCollections() {
|
|
205
|
+
return _loadAllCollections.apply(this, arguments);
|
|
206
|
+
}
|
|
207
|
+
/* console.log("================================");
|
|
208
|
+
console.log(
|
|
209
|
+
"Collection Set",
|
|
210
|
+
spice?.db?.collections?.has(collection_name),
|
|
211
|
+
collection_name
|
|
212
|
+
); */
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
function _loadAllCollections() {
|
|
216
|
+
_loadAllCollections = _asyncToGenerator(function* () {
|
|
217
|
+
var all_scopes = yield axios.get("".concat(that.getCouchbaseHost(), "/pools/default/buckets/").concat(that.db_config.bucket, "/scopes"), {
|
|
218
|
+
auth: {
|
|
219
|
+
username: that.db_config.username,
|
|
220
|
+
password: that.db_config.password
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
var scope = _.find(all_scopes.data.scopes, {
|
|
225
|
+
name: scope_name
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
var collectionSet = new Set();
|
|
229
|
+
|
|
230
|
+
_.each(scope.collections, collection => {
|
|
231
|
+
collectionSet.add(collection.name);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return collectionSet;
|
|
235
|
+
});
|
|
236
|
+
return _loadAllCollections.apply(this, arguments);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if ((_spice2 = spice) === null || _spice2 === void 0 ? void 0 : (_spice2$db = _spice2.db) === null || _spice2$db === void 0 ? void 0 : (_spice2$db$collection = _spice2$db.collections) === null || _spice2$db$collection === void 0 ? void 0 : _spice2$db$collection.has(collection_name)) {
|
|
240
|
+
//console.log("Using Internal Collection Set", true);
|
|
241
|
+
return true;
|
|
242
|
+
} else {
|
|
243
|
+
var _spice3, _spice3$db, _spice3$db$collection;
|
|
244
|
+
|
|
245
|
+
//console.log("Using Internal Collection Set", false);
|
|
246
|
+
spice.db.collections = yield loadAllCollections(); //console.log("Collection Set", spice.db.collections.entries());
|
|
247
|
+
|
|
248
|
+
return (_spice3 = spice) === null || _spice3 === void 0 ? void 0 : (_spice3$db = _spice3.db) === null || _spice3$db === void 0 ? void 0 : (_spice3$db$collection = _spice3$db.collections) === null || _spice3$db$collection === void 0 ? void 0 : _spice3$db$collection.has(collection_name);
|
|
249
|
+
}
|
|
203
250
|
} catch (e) {
|
|
204
251
|
console.log("Exists error happened", e);
|
|
205
252
|
}
|
|
@@ -623,7 +670,10 @@ module.exports = class Database {
|
|
|
623
670
|
|
|
624
671
|
|
|
625
672
|
var startTime = process.hrtime.bigint();
|
|
626
|
-
var
|
|
673
|
+
var options = {
|
|
674
|
+
scanConsistency: QueryScanConsistency.RequestPlus
|
|
675
|
+
};
|
|
676
|
+
var response = yield exec_scope.query(sanitizedQuery, options); // End time
|
|
627
677
|
|
|
628
678
|
var endTime = process.hrtime.bigint(); // Calculate duration in microseconds
|
|
629
679
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spice-couchbase",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.33",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"axios": "^0.26.1",
|
|
13
|
-
"couchbase": "4.2.
|
|
13
|
+
"couchbase": "^4.2.7",
|
|
14
14
|
"lodash": "^4.17.15",
|
|
15
15
|
"qs": "^6.10.3"
|
|
16
16
|
},
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ let couchbase = require("couchbase");
|
|
|
5
5
|
const { default: axios } = require("axios");
|
|
6
6
|
var qs = require("qs");
|
|
7
7
|
const { ConflictResolutionType } = require("couchbase");
|
|
8
|
+
const { QueryScanConsistency } = require("couchbase");
|
|
8
9
|
|
|
9
10
|
if (!Promise.allSettled) {
|
|
10
11
|
Promise.allSettled = (promises) =>
|
|
@@ -76,6 +77,10 @@ module.exports = class Database {
|
|
|
76
77
|
this.SearchQuery = couchbase.SearchQuery;
|
|
77
78
|
this.collection = this.scope.collection(this.collection_name);
|
|
78
79
|
this.userManager = this.getUserManager(connection);
|
|
80
|
+
if (!spice?.db?.collections) {
|
|
81
|
+
spice.db = spice.db || {};
|
|
82
|
+
spice.db.collections = new Set();
|
|
83
|
+
}
|
|
79
84
|
if (this.auto_create_collection) {
|
|
80
85
|
this.upsertCollection();
|
|
81
86
|
}
|
|
@@ -174,9 +179,9 @@ module.exports = class Database {
|
|
|
174
179
|
);
|
|
175
180
|
if (!this.checkGlobelConnectionObject(this.collection_name)) {
|
|
176
181
|
if (!collection_exists) {
|
|
177
|
-
await this.createCollection(this.collection_name, this.scope_name);
|
|
182
|
+
/* await this.createCollection(this.collection_name, this.scope_name);
|
|
178
183
|
await this.wait(2000);
|
|
179
|
-
await this.createPrimaryIndex(this.scope_name, this.collection_name);
|
|
184
|
+
await this.createPrimaryIndex(this.scope_name, this.collection_name); */
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
} catch (e) {
|
|
@@ -186,24 +191,42 @@ module.exports = class Database {
|
|
|
186
191
|
|
|
187
192
|
async collectionExists(collection_name, scope_name) {
|
|
188
193
|
try {
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
let that = this;
|
|
195
|
+
async function loadAllCollections() {
|
|
196
|
+
let all_scopes = await axios.get(
|
|
197
|
+
`${that.getCouchbaseHost()}/pools/default/buckets/${
|
|
198
|
+
that.db_config.bucket
|
|
199
|
+
}/scopes`,
|
|
200
|
+
{
|
|
201
|
+
auth: {
|
|
202
|
+
username: that.db_config.username,
|
|
203
|
+
password: that.db_config.password,
|
|
204
|
+
},
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
let scope = _.find(all_scopes.data.scopes, { name: scope_name });
|
|
208
|
+
let collectionSet = new Set();
|
|
209
|
+
_.each(scope.collections, (collection) => {
|
|
210
|
+
collectionSet.add(collection.name);
|
|
211
|
+
});
|
|
212
|
+
return collectionSet;
|
|
213
|
+
}
|
|
214
|
+
/* console.log("================================");
|
|
215
|
+
console.log(
|
|
216
|
+
"Collection Set",
|
|
217
|
+
spice?.db?.collections?.has(collection_name),
|
|
218
|
+
collection_name
|
|
219
|
+
); */
|
|
220
|
+
if (spice?.db?.collections?.has(collection_name)) {
|
|
221
|
+
//console.log("Using Internal Collection Set", true);
|
|
222
|
+
return true;
|
|
223
|
+
} else {
|
|
224
|
+
//console.log("Using Internal Collection Set", false);
|
|
225
|
+
|
|
226
|
+
spice.db.collections = await loadAllCollections();
|
|
227
|
+
//console.log("Collection Set", spice.db.collections.entries());
|
|
228
|
+
return spice?.db?.collections?.has(collection_name);
|
|
229
|
+
}
|
|
207
230
|
} catch (e) {
|
|
208
231
|
console.log("Exists error happened", e);
|
|
209
232
|
}
|
|
@@ -561,7 +584,10 @@ module.exports = class Database {
|
|
|
561
584
|
}
|
|
562
585
|
// Start time
|
|
563
586
|
let startTime = process.hrtime.bigint();
|
|
564
|
-
|
|
587
|
+
const options = {
|
|
588
|
+
scanConsistency: QueryScanConsistency.RequestPlus,
|
|
589
|
+
};
|
|
590
|
+
let response = await exec_scope.query(sanitizedQuery, options);
|
|
565
591
|
// End time
|
|
566
592
|
let endTime = process.hrtime.bigint();
|
|
567
593
|
// Calculate duration in microseconds
|