@ronin/compiler 0.14.8-leo-ron-1099-1-experimental-340 → 0.14.9-leo-ron-1099-1-experimental-341

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -631,6 +631,15 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
631
631
  if (instructions && Object.hasOwn(instructions, "for")) {
632
632
  instructions = handleFor(model, instructions);
633
633
  }
634
+ if (queryType === "count") {
635
+ if (!instructions) instructions = {};
636
+ instructions.selecting = ["amount"];
637
+ instructions.including = Object.assign(instructions?.including || {}, {
638
+ amount: {
639
+ [QUERY_SYMBOLS.EXPRESSION]: "COUNT(*)"
640
+ }
641
+ });
642
+ }
634
643
  const { columns, isJoining, selectedFields } = handleSelecting(
635
644
  models,
636
645
  model,
@@ -645,6 +654,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
645
654
  let statement = "";
646
655
  switch (queryType) {
647
656
  case "get":
657
+ case "count":
648
658
  statement += `SELECT ${columns} FROM `;
649
659
  break;
650
660
  case "set":
@@ -656,9 +666,6 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
656
666
  case "remove":
657
667
  statement += "DELETE FROM ";
658
668
  break;
659
- case "count":
660
- statement += `SELECT COUNT(${columns}) FROM `;
661
- break;
662
669
  }
663
670
  let isJoiningMultipleRows = false;
664
671
  if (isJoining) {
@@ -2092,9 +2099,10 @@ var Transaction = class {
2092
2099
  */
2093
2100
  formatResults(results, raw = true) {
2094
2101
  const normalizedResults = raw ? results : results.map((rows) => {
2095
- return rows.map((row) => {
2102
+ return rows.map((row, index) => {
2103
+ const { query } = this.#internalStatements[index];
2096
2104
  if (Array.isArray(row)) return row;
2097
- if (row["COUNT(*)"]) return [row["COUNT(*)"]];
2105
+ if (query.count) return [row.amount];
2098
2106
  return Object.values(row);
2099
2107
  });
2100
2108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.8-leo-ron-1099-1-experimental-340",
3
+ "version": "0.14.9-leo-ron-1099-1-experimental-341",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {