@ronin/compiler 0.11.7 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -6064,8 +6064,7 @@ interface TransactionOptions {
6064
6064
  declare class Transaction {
6065
6065
  statements: Array<Statement>;
6066
6066
  models: Array<Model>;
6067
- private queries;
6068
- private fields;
6067
+ private internalStatements;
6069
6068
  constructor(queries: Array<Query>, options?: TransactionOptions);
6070
6069
  /**
6071
6070
  * Composes SQL statements for the provided RONIN queries.
package/dist/index.js CHANGED
@@ -1570,14 +1570,12 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
1570
1570
 
1571
1571
  // src/index.ts
1572
1572
  var Transaction = class {
1573
- statements;
1573
+ statements = [];
1574
1574
  models = [];
1575
- queries;
1576
- fields = [];
1575
+ internalStatements = [];
1577
1576
  constructor(queries, options) {
1578
1577
  const models = options?.models || [];
1579
- this.statements = this.compileQueries(queries, models, options);
1580
- this.queries = queries;
1578
+ this.compileQueries(queries, models, options);
1581
1579
  }
1582
1580
  /**
1583
1581
  * Composes SQL statements for the provided RONIN queries.
@@ -1607,8 +1605,15 @@ var Transaction = class {
1607
1605
  options?.inlineParams ? null : [],
1608
1606
  { expandColumns: options?.expandColumns }
1609
1607
  );
1610
- statements.push(...result.dependencies, result.main);
1611
- this.fields.push(result.loadedFields);
1608
+ const subStatements = [...result.dependencies, result.main];
1609
+ this.statements.push(...subStatements);
1610
+ this.internalStatements.push(
1611
+ ...subStatements.map((statement) => ({
1612
+ ...statement,
1613
+ query,
1614
+ fields: result.loadedFields
1615
+ }))
1616
+ );
1612
1617
  }
1613
1618
  this.models = modelListWithPresets;
1614
1619
  return statements;
@@ -1655,19 +1660,16 @@ var Transaction = class {
1655
1660
  * RONIN record, an array of RONIN records, or a RONIN count result.
1656
1661
  */
1657
1662
  formatResults(results, raw = true) {
1658
- const relevantResults = results.filter((_, index) => {
1659
- return this.statements[index].returning;
1660
- });
1661
- const normalizedResults = raw ? relevantResults : relevantResults.map((rows) => {
1663
+ const normalizedResults = raw ? results : results.map((rows) => {
1662
1664
  return rows.map((row) => {
1663
1665
  if (Array.isArray(row)) return row;
1664
1666
  if (row["COUNT(*)"]) return [row["COUNT(*)"]];
1665
1667
  return Object.values(row);
1666
1668
  });
1667
1669
  });
1668
- return normalizedResults.map((rows, index) => {
1669
- const query = this.queries.at(-index);
1670
- const rawModelFields = this.fields.at(-index);
1670
+ const formattedResults = normalizedResults.map((rows, index) => {
1671
+ const { returning, query, fields: rawModelFields } = this.internalStatements[index];
1672
+ if (!returning) return null;
1671
1673
  const { queryType, queryModel, queryInstructions } = splitQuery(query);
1672
1674
  const model = getModelBySlug(this.models, queryModel);
1673
1675
  const modelFields = Object.fromEntries(
@@ -1719,6 +1721,7 @@ var Transaction = class {
1719
1721
  }
1720
1722
  return output;
1721
1723
  });
1724
+ return formattedResults.filter((result) => result !== null);
1722
1725
  }
1723
1726
  };
1724
1727
  var CLEAN_ROOT_MODEL = omit(ROOT_MODEL, ["system"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.11.7",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {