@514labs/moose-lib 0.6.435 → 0.6.436

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.
@@ -640,11 +640,18 @@ function sqlImpl(strings, ...values) {
640
640
  return new Sql(strings, values);
641
641
  }
642
642
  var sql = sqlImpl;
643
+ sql.statement = function(strings, ...values) {
644
+ return new Sql(strings, values, false);
645
+ };
646
+ sql.fragment = function(strings, ...values) {
647
+ return new Sql(strings, values, true);
648
+ };
643
649
  var instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
644
650
  var Sql = class _Sql {
645
651
  values;
646
652
  strings;
647
- constructor(rawStrings, rawValues) {
653
+ isFragment;
654
+ constructor(rawStrings, rawValues, isFragment) {
648
655
  if (rawStrings.length - 1 !== rawValues.length) {
649
656
  if (rawStrings.length === 0) {
650
657
  throw new TypeError("Expected at least 1 string");
@@ -659,6 +666,7 @@ var Sql = class _Sql {
659
666
  );
660
667
  this.values = new Array(valuesLength);
661
668
  this.strings = new Array(valuesLength + 1);
669
+ this.isFragment = isFragment;
662
670
  this.strings[0] = rawStrings[0];
663
671
  let i = 0, pos = 0;
664
672
  while (i < rawValues.length) {
@@ -705,19 +713,26 @@ var Sql = class _Sql {
705
713
  * Append another Sql fragment, returning a new Sql instance.
706
714
  */
707
715
  append(other) {
708
- return new _Sql([...this.strings, ""], [...this.values, other]);
716
+ return new _Sql(
717
+ [...this.strings, ""],
718
+ [...this.values, other],
719
+ this.isFragment
720
+ );
709
721
  }
710
722
  };
711
723
  sql.join = function(fragments, separator) {
712
- if (fragments.length === 0) return new Sql([""], []);
713
- if (fragments.length === 1) return fragments[0];
724
+ if (fragments.length === 0) return new Sql([""], [], true);
725
+ if (fragments.length === 1) {
726
+ const frag = fragments[0];
727
+ return new Sql(frag.strings, frag.values, true);
728
+ }
714
729
  const sep = separator ?? ", ";
715
730
  const normalized = sep.includes(" ") ? sep : ` ${sep} `;
716
731
  const strings = ["", ...Array(fragments.length - 1).fill(normalized), ""];
717
- return new Sql(strings, fragments);
732
+ return new Sql(strings, fragments, true);
718
733
  };
719
734
  sql.raw = function(text) {
720
- return new Sql([text], []);
735
+ return new Sql([text], [], true);
721
736
  };
722
737
  var toStaticQuery = (sql3) => {
723
738
  const [query, params] = toQuery(sql3);