spice-couchbase 2.0.21 → 2.0.23
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 +31 -65
- package/package.json +1 -1
- package/src/index.js +37 -70
package/build/index.js
CHANGED
|
@@ -347,18 +347,20 @@ module.exports = class Database {
|
|
|
347
347
|
|
|
348
348
|
var returned_all = yield Promise.allSettled(functions);
|
|
349
349
|
|
|
350
|
-
var responses = _.flatten(_.
|
|
351
|
-
|
|
352
|
-
}))
|
|
350
|
+
var responses = _.flatten(_.map(returned_all, returned_obj => {
|
|
351
|
+
return returned_obj === null || returned_obj === void 0 ? void 0 : returned_obj.value;
|
|
352
|
+
}));
|
|
353
|
+
|
|
354
|
+
return _.compact(_.map(responses, (res, index) => {
|
|
355
|
+
if (res) {
|
|
356
|
+
if (!keep_type) {
|
|
357
|
+
delete res.value.type;
|
|
358
|
+
}
|
|
353
359
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
delete res.value.type;
|
|
360
|
+
res.value.id = keys[index];
|
|
361
|
+
return res.value;
|
|
357
362
|
}
|
|
358
|
-
|
|
359
|
-
res.value.id = keys[index];
|
|
360
|
-
return res.value;
|
|
361
|
-
});
|
|
363
|
+
}));
|
|
362
364
|
} else {
|
|
363
365
|
return [];
|
|
364
366
|
}
|
|
@@ -432,52 +434,30 @@ module.exports = class Database {
|
|
|
432
434
|
}());
|
|
433
435
|
}
|
|
434
436
|
|
|
435
|
-
search(type, columns, query
|
|
437
|
+
search(type, columns, query) {
|
|
436
438
|
var _this15 = this;
|
|
437
439
|
|
|
440
|
+
var limit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
441
|
+
var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
442
|
+
var order_by = arguments.length > 5 ? arguments[5] : undefined;
|
|
443
|
+
var do_count = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : "false";
|
|
444
|
+
var query_scope = arguments.length > 7 ? arguments[7] : undefined;
|
|
438
445
|
return _asyncToGenerator(function* () {
|
|
439
446
|
var is_legacy = _this15.scope_name !== "_default" && _this15.collection_name !== "_default";
|
|
440
|
-
var alias = "_reference";
|
|
441
447
|
var bucket = "`".concat(_this15.use_bucket_name ? _this15.bucket : _this15.collection_name, "`");
|
|
442
448
|
|
|
443
449
|
try {
|
|
444
|
-
|
|
445
|
-
if (do_count == undefined) {
|
|
446
|
-
do_count = "false";
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
var fix = "";
|
|
450
|
-
var count_query = "";
|
|
451
|
-
|
|
452
|
-
if (!limit) {
|
|
453
|
-
limit = 0;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (!offset) {
|
|
457
|
-
offset = 0;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (columns == "*") {
|
|
461
|
-
columns = "(" + bucket + ").*";
|
|
462
|
-
fix = ", META(" + bucket + ").id AS id";
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (!columns) {
|
|
466
|
-
columns = "(" + bucket + ").*";
|
|
467
|
-
fix = ", META(" + bucket + ").id AS id";
|
|
468
|
-
}
|
|
450
|
+
var fix = ", META(".concat(bucket, ").id AS id");
|
|
469
451
|
|
|
470
|
-
if (columns
|
|
471
|
-
|
|
452
|
+
if (columns === "*" || !columns) {
|
|
453
|
+
columns = "(".concat(bucket, ").*");
|
|
454
|
+
} else if (columns !== "id") {
|
|
455
|
+
columns = "".concat(columns).concat(fix);
|
|
456
|
+
} else {
|
|
472
457
|
columns = "";
|
|
473
458
|
}
|
|
474
459
|
|
|
475
460
|
var front_query = "SELECT ".concat(columns, " ").concat(fix, " FROM ").concat(bucket);
|
|
476
|
-
|
|
477
|
-
if (is_legacy || query) {
|
|
478
|
-
front_query += " WHERE ";
|
|
479
|
-
}
|
|
480
|
-
|
|
481
461
|
var conditions = [];
|
|
482
462
|
|
|
483
463
|
if (_this15.use_bucket_name) {
|
|
@@ -488,27 +468,13 @@ module.exports = class Database {
|
|
|
488
468
|
conditions.push(query);
|
|
489
469
|
}
|
|
490
470
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
query = front_query + conditions.join(" AND ");
|
|
499
|
-
|
|
500
|
-
if (order_by) {
|
|
501
|
-
query = "".concat(query, " ORDER BY ").concat(order_by);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
if (limit > 0) {
|
|
505
|
-
query = query + " LIMIT " + limit;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (offset > 0) {
|
|
509
|
-
query = query + " OFFSET " + offset;
|
|
510
|
-
}
|
|
511
|
-
|
|
471
|
+
var where_clause = conditions.length ? " WHERE " : "";
|
|
472
|
+
query = front_query + where_clause + conditions.join(" AND ");
|
|
473
|
+
var count_query = "SELECT count(meta().id) as count FROM ".concat(bucket).concat(where_clause);
|
|
474
|
+
var order_by_clause = order_by ? " ORDER BY ".concat(order_by) : "";
|
|
475
|
+
var limit_clause = limit > 0 ? " LIMIT ".concat(limit) : "";
|
|
476
|
+
var offset_clause = offset > 0 ? " OFFSET ".concat(offset) : "";
|
|
477
|
+
query = query + order_by_clause + limit_clause + offset_clause;
|
|
512
478
|
var active_query_space = query_scope || !_this15.use_bucket_name ? "scope" : "cluster";
|
|
513
479
|
var queries = [_this15.getData(query, active_query_space)];
|
|
514
480
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -329,20 +329,22 @@ module.exports = class Database {
|
|
|
329
329
|
let returned_all = await Promise.allSettled(functions);
|
|
330
330
|
|
|
331
331
|
let responses = _.flatten(
|
|
332
|
-
_.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
})
|
|
336
|
-
)
|
|
332
|
+
_.map(returned_all, (returned_obj) => {
|
|
333
|
+
return returned_obj?.value;
|
|
334
|
+
})
|
|
337
335
|
);
|
|
338
336
|
|
|
339
|
-
return _.
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
337
|
+
return _.compact(
|
|
338
|
+
_.map(responses, (res, index) => {
|
|
339
|
+
if (res) {
|
|
340
|
+
if (!keep_type) {
|
|
341
|
+
delete res.value.type;
|
|
342
|
+
}
|
|
343
|
+
res.value.id = keys[index];
|
|
344
|
+
return res.value;
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
);
|
|
346
348
|
} else {
|
|
347
349
|
return [];
|
|
348
350
|
}
|
|
@@ -402,57 +404,32 @@ module.exports = class Database {
|
|
|
402
404
|
type,
|
|
403
405
|
columns,
|
|
404
406
|
query,
|
|
405
|
-
limit,
|
|
406
|
-
offset,
|
|
407
|
+
limit = 0,
|
|
408
|
+
offset = 0,
|
|
407
409
|
order_by,
|
|
408
|
-
do_count,
|
|
410
|
+
do_count = "false",
|
|
409
411
|
query_scope
|
|
410
412
|
) {
|
|
411
|
-
|
|
413
|
+
const is_legacy =
|
|
412
414
|
this.scope_name !== "_default" && this.collection_name !== "_default";
|
|
413
|
-
|
|
414
|
-
let bucket = `\`${
|
|
415
|
+
const bucket = `\`${
|
|
415
416
|
this.use_bucket_name ? this.bucket : this.collection_name
|
|
416
417
|
}\``;
|
|
417
418
|
|
|
418
419
|
try {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (do_count == undefined) {
|
|
422
|
-
do_count = "false";
|
|
423
|
-
}
|
|
424
|
-
var fix = "";
|
|
425
|
-
var count_query = "";
|
|
426
|
-
if (!limit) {
|
|
427
|
-
limit = 0;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (!offset) {
|
|
431
|
-
offset = 0;
|
|
432
|
-
}
|
|
420
|
+
const fix = `, META(${bucket}).id AS id`;
|
|
433
421
|
|
|
434
|
-
if (columns
|
|
435
|
-
columns =
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (!columns) {
|
|
440
|
-
columns = "(" + bucket + ").*";
|
|
441
|
-
fix = ", META(" + bucket + ").id AS id";
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
if (columns == "id") {
|
|
445
|
-
fix = ", META(" + bucket + ").id AS id";
|
|
422
|
+
if (columns === "*" || !columns) {
|
|
423
|
+
columns = `(${bucket}).*`;
|
|
424
|
+
} else if (columns !== "id") {
|
|
425
|
+
columns = `${columns}${fix}`;
|
|
426
|
+
} else {
|
|
446
427
|
columns = "";
|
|
447
428
|
}
|
|
448
429
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (is_legacy || query) {
|
|
452
|
-
front_query += " WHERE ";
|
|
453
|
-
}
|
|
430
|
+
const front_query = `SELECT ${columns} ${fix} FROM ${bucket}`;
|
|
431
|
+
const conditions = [];
|
|
454
432
|
|
|
455
|
-
let conditions = [];
|
|
456
433
|
if (this.use_bucket_name) {
|
|
457
434
|
conditions.push(`type = '${type}'`);
|
|
458
435
|
}
|
|
@@ -460,34 +437,24 @@ module.exports = class Database {
|
|
|
460
437
|
conditions.push(query);
|
|
461
438
|
}
|
|
462
439
|
|
|
463
|
-
|
|
440
|
+
const where_clause = conditions.length ? " WHERE " : "";
|
|
441
|
+
query = front_query + where_clause + conditions.join(" AND ");
|
|
464
442
|
|
|
465
|
-
count_query = `SELECT count(meta().id) as count FROM ${bucket}`;
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
query = front_query + conditions.join(" AND ");
|
|
470
|
-
|
|
471
|
-
if (order_by) {
|
|
472
|
-
query = `${query} ORDER BY ${order_by}`;
|
|
473
|
-
}
|
|
443
|
+
const count_query = `SELECT count(meta().id) as count FROM ${bucket}${where_clause}`;
|
|
444
|
+
const order_by_clause = order_by ? ` ORDER BY ${order_by}` : "";
|
|
445
|
+
const limit_clause = limit > 0 ? ` LIMIT ${limit}` : "";
|
|
446
|
+
const offset_clause = offset > 0 ? ` OFFSET ${offset}` : "";
|
|
474
447
|
|
|
475
|
-
|
|
476
|
-
query = query + " LIMIT " + limit;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
if (offset > 0) {
|
|
480
|
-
query = query + " OFFSET " + offset;
|
|
481
|
-
}
|
|
448
|
+
query = query + order_by_clause + limit_clause + offset_clause;
|
|
482
449
|
|
|
483
|
-
|
|
450
|
+
const active_query_space =
|
|
484
451
|
query_scope || !this.use_bucket_name ? "scope" : "cluster";
|
|
485
452
|
|
|
486
|
-
|
|
453
|
+
const queries = [this.getData(query, active_query_space)];
|
|
487
454
|
if (do_count === "true") {
|
|
488
455
|
queries.push(this.getCount(count_query, active_query_space));
|
|
489
456
|
}
|
|
490
|
-
|
|
457
|
+
const responses = await Promise.all(queries);
|
|
491
458
|
|
|
492
459
|
return {
|
|
493
460
|
data: responses[0],
|