spice-couchbase 2.0.41 → 2.0.43
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 +39 -12
- package/package.json +1 -1
- package/src/index.js +42 -14
package/build/index.js
CHANGED
|
@@ -483,19 +483,46 @@ module.exports = class Database {
|
|
|
483
483
|
var is_legacy = _this15.scope_name !== "_default" && _this15.collection_name !== "_default";
|
|
484
484
|
var bucket = "`".concat(_this15.use_bucket_name ? _this15.bucket : _this15.collection_name, "`");
|
|
485
485
|
|
|
486
|
-
function
|
|
487
|
-
return
|
|
488
|
-
|
|
486
|
+
function processColumns(columnsStr) {
|
|
487
|
+
// If columns is empty or *, return default
|
|
488
|
+
if (columnsStr === "*" || !columnsStr) {
|
|
489
|
+
return "(".concat(bucket, ").*, META(").concat(bucket, ").id AS id");
|
|
490
|
+
} // Split by comma and process each column
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
var columnList = columnsStr.split(",").map(col => col.trim());
|
|
494
|
+
var hasId = false;
|
|
495
|
+
var processedColumns = columnList.map(col => {
|
|
496
|
+
// Check if this column is an id field in various formats
|
|
497
|
+
// Patterns: `collection`.`id`, collection.id, `id`, id
|
|
498
|
+
var idPattern = /^(?:`?(\w+)`?\.)?`?id`?$/i;
|
|
499
|
+
var match = col.match(idPattern);
|
|
500
|
+
|
|
501
|
+
if (match) {
|
|
502
|
+
hasId = true; // match[1] contains the collection name if present
|
|
503
|
+
|
|
504
|
+
if (match[1]) {
|
|
505
|
+
// Has collection prefix: `collection`.`id` or collection.id
|
|
506
|
+
return "META(`".concat(match[1], "`).id AS id");
|
|
507
|
+
} else {
|
|
508
|
+
// Just id without collection prefix
|
|
509
|
+
return "META(".concat(bucket, ").id AS id");
|
|
510
|
+
}
|
|
511
|
+
} // Return the column as-is
|
|
489
512
|
|
|
490
|
-
try {
|
|
491
|
-
var fix = ", META(".concat(bucket, ").id AS id");
|
|
492
513
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
514
|
+
return col;
|
|
515
|
+
}); // If no id column was provided, add it automatically
|
|
516
|
+
|
|
517
|
+
if (!hasId) {
|
|
518
|
+
processedColumns.push("META(".concat(bucket, ").id AS id"));
|
|
497
519
|
}
|
|
498
520
|
|
|
521
|
+
return processedColumns.join(", ");
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
try {
|
|
525
|
+
columns = processColumns(columns);
|
|
499
526
|
var front_query = "SELECT ".concat(columns, " FROM ").concat(bucket, " ").concat(join);
|
|
500
527
|
var conditions = [];
|
|
501
528
|
|
|
@@ -518,7 +545,7 @@ module.exports = class Database {
|
|
|
518
545
|
var active_query_space = query_scope || !_this15.use_bucket_name ? "scope" : "cluster";
|
|
519
546
|
var queries = [_this15.getData(query, active_query_space)];
|
|
520
547
|
|
|
521
|
-
if (do_count
|
|
548
|
+
if (do_count != "false") {
|
|
522
549
|
queries.push(_this15.getCount(count_query, active_query_space));
|
|
523
550
|
}
|
|
524
551
|
|
|
@@ -668,8 +695,8 @@ module.exports = class Database {
|
|
|
668
695
|
|
|
669
696
|
var durationInMilliseconds = (endTime - startTime) / BigInt(1000000); // optimize if response time is greater than 1 second
|
|
670
697
|
|
|
671
|
-
if (durationInMilliseconds >
|
|
672
|
-
|
|
698
|
+
if (durationInMilliseconds > 2000) {
|
|
699
|
+
_this18.optimize(query, exec_scope);
|
|
673
700
|
}
|
|
674
701
|
|
|
675
702
|
return response;
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -424,20 +424,48 @@ module.exports = class Database {
|
|
|
424
424
|
this.use_bucket_name ? this.bucket : this.collection_name
|
|
425
425
|
}\``;
|
|
426
426
|
|
|
427
|
-
function
|
|
428
|
-
return
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
427
|
+
function processColumns(columnsStr) {
|
|
428
|
+
// If columns is empty or *, return default
|
|
429
|
+
if (columnsStr === "*" || !columnsStr) {
|
|
430
|
+
return `(${bucket}).*, META(${bucket}).id AS id`;
|
|
431
|
+
}
|
|
432
432
|
|
|
433
|
-
|
|
434
|
-
const
|
|
433
|
+
// Split by comma and process each column
|
|
434
|
+
const columnList = columnsStr.split(",").map((col) => col.trim());
|
|
435
|
+
let hasId = false;
|
|
436
|
+
|
|
437
|
+
const processedColumns = columnList.map((col) => {
|
|
438
|
+
// Check if this column is an id field in various formats
|
|
439
|
+
// Patterns: `collection`.`id`, collection.id, `id`, id
|
|
440
|
+
const idPattern = /^(?:`?(\w+)`?\.)?`?id`?$/i;
|
|
441
|
+
const match = col.match(idPattern);
|
|
442
|
+
|
|
443
|
+
if (match) {
|
|
444
|
+
hasId = true;
|
|
445
|
+
// match[1] contains the collection name if present
|
|
446
|
+
if (match[1]) {
|
|
447
|
+
// Has collection prefix: `collection`.`id` or collection.id
|
|
448
|
+
return `META(\`${match[1]}\`).id AS id`;
|
|
449
|
+
} else {
|
|
450
|
+
// Just id without collection prefix
|
|
451
|
+
return `META(${bucket}).id AS id`;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
435
454
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
455
|
+
// Return the column as-is
|
|
456
|
+
return col;
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// If no id column was provided, add it automatically
|
|
460
|
+
if (!hasId) {
|
|
461
|
+
processedColumns.push(`META(${bucket}).id AS id`);
|
|
440
462
|
}
|
|
463
|
+
|
|
464
|
+
return processedColumns.join(", ");
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
try {
|
|
468
|
+
columns = processColumns(columns);
|
|
441
469
|
const front_query = `SELECT ${columns} FROM ${bucket} ${join}`;
|
|
442
470
|
const conditions = [];
|
|
443
471
|
|
|
@@ -462,7 +490,7 @@ module.exports = class Database {
|
|
|
462
490
|
const active_query_space =
|
|
463
491
|
query_scope || !this.use_bucket_name ? "scope" : "cluster";
|
|
464
492
|
const queries = [this.getData(query, active_query_space)];
|
|
465
|
-
if (do_count
|
|
493
|
+
if (do_count != "false") {
|
|
466
494
|
queries.push(this.getCount(count_query, active_query_space));
|
|
467
495
|
}
|
|
468
496
|
const responses = await Promise.all(queries);
|
|
@@ -578,8 +606,8 @@ module.exports = class Database {
|
|
|
578
606
|
// Calculate duration in microseconds
|
|
579
607
|
let durationInMilliseconds = (endTime - startTime) / BigInt(1000000);
|
|
580
608
|
// optimize if response time is greater than 1 second
|
|
581
|
-
if (durationInMilliseconds >
|
|
582
|
-
|
|
609
|
+
if (durationInMilliseconds > 2000) {
|
|
610
|
+
this.optimize(query, exec_scope);
|
|
583
611
|
}
|
|
584
612
|
return response;
|
|
585
613
|
}
|