@514labs/moose-lib 0.6.435 → 0.6.437

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.mjs CHANGED
@@ -1027,11 +1027,18 @@ function sqlImpl(strings, ...values) {
1027
1027
  return new Sql(strings, values);
1028
1028
  }
1029
1029
  var sql = sqlImpl;
1030
+ sql.statement = function(strings, ...values) {
1031
+ return new Sql(strings, values, false);
1032
+ };
1033
+ sql.fragment = function(strings, ...values) {
1034
+ return new Sql(strings, values, true);
1035
+ };
1030
1036
  var instanceofSql = (value) => typeof value === "object" && "values" in value && "strings" in value;
1031
1037
  var Sql = class _Sql {
1032
1038
  values;
1033
1039
  strings;
1034
- constructor(rawStrings, rawValues) {
1040
+ isFragment;
1041
+ constructor(rawStrings, rawValues, isFragment) {
1035
1042
  if (rawStrings.length - 1 !== rawValues.length) {
1036
1043
  if (rawStrings.length === 0) {
1037
1044
  throw new TypeError("Expected at least 1 string");
@@ -1046,6 +1053,7 @@ var Sql = class _Sql {
1046
1053
  );
1047
1054
  this.values = new Array(valuesLength);
1048
1055
  this.strings = new Array(valuesLength + 1);
1056
+ this.isFragment = isFragment;
1049
1057
  this.strings[0] = rawStrings[0];
1050
1058
  let i = 0, pos = 0;
1051
1059
  while (i < rawValues.length) {
@@ -1092,19 +1100,26 @@ var Sql = class _Sql {
1092
1100
  * Append another Sql fragment, returning a new Sql instance.
1093
1101
  */
1094
1102
  append(other) {
1095
- return new _Sql([...this.strings, ""], [...this.values, other]);
1103
+ return new _Sql(
1104
+ [...this.strings, ""],
1105
+ [...this.values, other],
1106
+ this.isFragment
1107
+ );
1096
1108
  }
1097
1109
  };
1098
1110
  sql.join = function(fragments, separator) {
1099
- if (fragments.length === 0) return new Sql([""], []);
1100
- if (fragments.length === 1) return fragments[0];
1111
+ if (fragments.length === 0) return new Sql([""], [], true);
1112
+ if (fragments.length === 1) {
1113
+ const frag = fragments[0];
1114
+ return new Sql(frag.strings, frag.values, true);
1115
+ }
1101
1116
  const sep = separator ?? ", ";
1102
1117
  const normalized = sep.includes(" ") ? sep : ` ${sep} `;
1103
1118
  const strings = ["", ...Array(fragments.length - 1).fill(normalized), ""];
1104
- return new Sql(strings, fragments);
1119
+ return new Sql(strings, fragments, true);
1105
1120
  };
1106
1121
  sql.raw = function(text) {
1107
- return new Sql([text], []);
1122
+ return new Sql([text], [], true);
1108
1123
  };
1109
1124
  var toStaticQuery = (sql3) => {
1110
1125
  const [query, params] = toQuery(sql3);