@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.
@@ -630,11 +630,18 @@ function sqlImpl(strings, ...values) {
630
630
  return new Sql(strings, values);
631
631
  }
632
632
  var sql = sqlImpl;
633
+ sql.statement = function(strings, ...values) {
634
+ return new Sql(strings, values, false);
635
+ };
636
+ sql.fragment = function(strings, ...values) {
637
+ return new Sql(strings, values, true);
638
+ };
633
639
  var instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
634
640
  var Sql = class _Sql {
635
641
  values;
636
642
  strings;
637
- constructor(rawStrings, rawValues) {
643
+ isFragment;
644
+ constructor(rawStrings, rawValues, isFragment) {
638
645
  if (rawStrings.length - 1 !== rawValues.length) {
639
646
  if (rawStrings.length === 0) {
640
647
  throw new TypeError("Expected at least 1 string");
@@ -649,6 +656,7 @@ var Sql = class _Sql {
649
656
  );
650
657
  this.values = new Array(valuesLength);
651
658
  this.strings = new Array(valuesLength + 1);
659
+ this.isFragment = isFragment;
652
660
  this.strings[0] = rawStrings[0];
653
661
  let i = 0, pos = 0;
654
662
  while (i < rawValues.length) {
@@ -695,19 +703,26 @@ var Sql = class _Sql {
695
703
  * Append another Sql fragment, returning a new Sql instance.
696
704
  */
697
705
  append(other) {
698
- return new _Sql([...this.strings, ""], [...this.values, other]);
706
+ return new _Sql(
707
+ [...this.strings, ""],
708
+ [...this.values, other],
709
+ this.isFragment
710
+ );
699
711
  }
700
712
  };
701
713
  sql.join = function(fragments, separator) {
702
- if (fragments.length === 0) return new Sql([""], []);
703
- if (fragments.length === 1) return fragments[0];
714
+ if (fragments.length === 0) return new Sql([""], [], true);
715
+ if (fragments.length === 1) {
716
+ const frag = fragments[0];
717
+ return new Sql(frag.strings, frag.values, true);
718
+ }
704
719
  const sep = separator ?? ", ";
705
720
  const normalized = sep.includes(" ") ? sep : ` ${sep} `;
706
721
  const strings = ["", ...Array(fragments.length - 1).fill(normalized), ""];
707
- return new Sql(strings, fragments);
722
+ return new Sql(strings, fragments, true);
708
723
  };
709
724
  sql.raw = function(text) {
710
- return new Sql([text], []);
725
+ return new Sql([text], [], true);
711
726
  };
712
727
  var toStaticQuery = (sql3) => {
713
728
  const [query, params] = toQuery(sql3);