spice-couchbase 2.0.21 → 2.0.22
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/package.json +1 -1
- package/src/index.js +23 -58
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -402,57 +402,32 @@ module.exports = class Database {
|
|
|
402
402
|
type,
|
|
403
403
|
columns,
|
|
404
404
|
query,
|
|
405
|
-
limit,
|
|
406
|
-
offset,
|
|
405
|
+
limit = 0,
|
|
406
|
+
offset = 0,
|
|
407
407
|
order_by,
|
|
408
|
-
do_count,
|
|
408
|
+
do_count = "false",
|
|
409
409
|
query_scope
|
|
410
410
|
) {
|
|
411
|
-
|
|
411
|
+
const is_legacy =
|
|
412
412
|
this.scope_name !== "_default" && this.collection_name !== "_default";
|
|
413
|
-
|
|
414
|
-
let bucket = `\`${
|
|
413
|
+
const bucket = `\`${
|
|
415
414
|
this.use_bucket_name ? this.bucket : this.collection_name
|
|
416
415
|
}\``;
|
|
417
416
|
|
|
418
417
|
try {
|
|
419
|
-
|
|
418
|
+
const fix = `, META(${bucket}).id AS id`;
|
|
420
419
|
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (!limit) {
|
|
427
|
-
limit = 0;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (!offset) {
|
|
431
|
-
offset = 0;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
if (columns == "*") {
|
|
435
|
-
columns = "(" + bucket + ").*";
|
|
436
|
-
fix = ", META(" + bucket + ").id AS id";
|
|
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";
|
|
420
|
+
if (columns === "*" || !columns) {
|
|
421
|
+
columns = `(${bucket}).*`;
|
|
422
|
+
} else if (columns !== "id") {
|
|
423
|
+
columns = `${columns}${fix}`;
|
|
424
|
+
} else {
|
|
446
425
|
columns = "";
|
|
447
426
|
}
|
|
448
427
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (is_legacy || query) {
|
|
452
|
-
front_query += " WHERE ";
|
|
453
|
-
}
|
|
428
|
+
const front_query = `SELECT ${columns} ${fix} FROM ${bucket}`;
|
|
429
|
+
const conditions = [];
|
|
454
430
|
|
|
455
|
-
let conditions = [];
|
|
456
431
|
if (this.use_bucket_name) {
|
|
457
432
|
conditions.push(`type = '${type}'`);
|
|
458
433
|
}
|
|
@@ -460,34 +435,24 @@ module.exports = class Database {
|
|
|
460
435
|
conditions.push(query);
|
|
461
436
|
}
|
|
462
437
|
|
|
463
|
-
|
|
438
|
+
const where_clause = conditions.length ? " WHERE " : "";
|
|
439
|
+
query = front_query + where_clause + conditions.join(" AND ");
|
|
464
440
|
|
|
465
|
-
count_query = `SELECT count(meta().id) as count FROM ${bucket}`;
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
query = front_query + conditions.join(" AND ");
|
|
441
|
+
const count_query = `SELECT count(meta().id) as count FROM ${bucket}${where_clause}`;
|
|
442
|
+
const order_by_clause = order_by ? ` ORDER BY ${order_by}` : "";
|
|
443
|
+
const limit_clause = limit > 0 ? ` LIMIT ${limit}` : "";
|
|
444
|
+
const offset_clause = offset > 0 ? ` OFFSET ${offset}` : "";
|
|
470
445
|
|
|
471
|
-
|
|
472
|
-
query = `${query} ORDER BY ${order_by}`;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (limit > 0) {
|
|
476
|
-
query = query + " LIMIT " + limit;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
if (offset > 0) {
|
|
480
|
-
query = query + " OFFSET " + offset;
|
|
481
|
-
}
|
|
446
|
+
query = query + order_by_clause + limit_clause + offset_clause;
|
|
482
447
|
|
|
483
|
-
|
|
448
|
+
const active_query_space =
|
|
484
449
|
query_scope || !this.use_bucket_name ? "scope" : "cluster";
|
|
485
450
|
|
|
486
|
-
|
|
451
|
+
const queries = [this.getData(query, active_query_space)];
|
|
487
452
|
if (do_count === "true") {
|
|
488
453
|
queries.push(this.getCount(count_query, active_query_space));
|
|
489
454
|
}
|
|
490
|
-
|
|
455
|
+
const responses = await Promise.all(queries);
|
|
491
456
|
|
|
492
457
|
return {
|
|
493
458
|
data: responses[0],
|