workers-qb 1.6.5 → 1.6.7

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/dist/index.js CHANGED
@@ -524,8 +524,9 @@ var QueryBuilder = class {
524
524
  conditions = value.conditions;
525
525
  }
526
526
  if (typeof conditions === "string") return ` WHERE ${conditions.toString()}`;
527
- if (conditions.length > 0) {
528
- return ` WHERE ${conditions.join(" AND ")}`;
527
+ if (conditions.length === 1) return ` WHERE ${conditions[0].toString()}`;
528
+ if (conditions.length > 1) {
529
+ return ` WHERE (${conditions.join(") AND (")})`;
529
530
  }
530
531
  return "";
531
532
  }
@@ -712,26 +713,20 @@ var DOQB = class extends QueryBuilder {
712
713
  }
713
714
  execute(query) {
714
715
  return this.loggerWrapper(query, this.options.logger, () => {
716
+ let cursor;
715
717
  if (query.arguments) {
716
- let stmt = this.db.prepare(query.query);
717
- const result = stmt(...query.arguments);
718
- if (query.fetchType == "ONE" /* ONE */) {
719
- return {
720
- results: Array.from(result)[0]
721
- };
722
- }
723
- return {
724
- results: Array.from(result)
725
- };
718
+ cursor = this.db.exec(query.query, ...query.arguments);
719
+ } else {
720
+ cursor = this.db.exec(query.query);
726
721
  }
727
- const cursor = this.db.exec(query.query);
722
+ const result = cursor.toArray();
728
723
  if (query.fetchType == "ONE" /* ONE */) {
729
724
  return {
730
- results: Array.from(cursor)[0]
725
+ results: result.length > 0 ? result[0] : void 0
731
726
  };
732
727
  }
733
728
  return {
734
- results: Array.from(cursor)
729
+ results: result
735
730
  };
736
731
  });
737
732
  }
package/dist/index.mjs CHANGED
@@ -484,8 +484,9 @@ var QueryBuilder = class {
484
484
  conditions = value.conditions;
485
485
  }
486
486
  if (typeof conditions === "string") return ` WHERE ${conditions.toString()}`;
487
- if (conditions.length > 0) {
488
- return ` WHERE ${conditions.join(" AND ")}`;
487
+ if (conditions.length === 1) return ` WHERE ${conditions[0].toString()}`;
488
+ if (conditions.length > 1) {
489
+ return ` WHERE (${conditions.join(") AND (")})`;
489
490
  }
490
491
  return "";
491
492
  }
@@ -672,26 +673,20 @@ var DOQB = class extends QueryBuilder {
672
673
  }
673
674
  execute(query) {
674
675
  return this.loggerWrapper(query, this.options.logger, () => {
676
+ let cursor;
675
677
  if (query.arguments) {
676
- let stmt = this.db.prepare(query.query);
677
- const result = stmt(...query.arguments);
678
- if (query.fetchType == "ONE" /* ONE */) {
679
- return {
680
- results: Array.from(result)[0]
681
- };
682
- }
683
- return {
684
- results: Array.from(result)
685
- };
678
+ cursor = this.db.exec(query.query, ...query.arguments);
679
+ } else {
680
+ cursor = this.db.exec(query.query);
686
681
  }
687
- const cursor = this.db.exec(query.query);
682
+ const result = cursor.toArray();
688
683
  if (query.fetchType == "ONE" /* ONE */) {
689
684
  return {
690
- results: Array.from(cursor)[0]
685
+ results: result.length > 0 ? result[0] : void 0
691
686
  };
692
687
  }
693
688
  return {
694
- results: Array.from(cursor)
689
+ results: result
695
690
  };
696
691
  });
697
692
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workers-qb",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "Zero dependencies Query Builder for Cloudflare Workers",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",