@ronin/compiler 0.14.9-leo-ron-1099-1-experimental-342 → 0.14.9-leo-ron-1099-1-experimental-344

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +20 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -70,7 +70,7 @@ executed and their results can be formatted by the compiler as well:
70
70
 
71
71
  ```typescript
72
72
  // Passing `rawResults` (rows being arrays of values) provided by the database (ideal)
73
- const results: Array<Result> = transaction.formatResults(rawResults);
73
+ const results: Array<Result> = transaction.formatResults(rawResults, true);
74
74
 
75
75
  // Passing `objectResults` (rows being objects) provided by a driver
76
76
  const results: Array<Result> = transaction.formatResults(objectResults, false);
package/dist/index.js CHANGED
@@ -25,12 +25,13 @@ var CURRENT_TIME_EXPRESSION = {
25
25
  };
26
26
  var MOUNTING_PATH_SUFFIX = /(.*?)(\{(\d+)\})?$/;
27
27
  var composeMountingPath = (single, key, mountingPath) => {
28
- const subMountingPath = key === "ronin_root" ? mountingPath ? mountingPath.replace(
29
- MOUNTING_PATH_SUFFIX,
30
- (_, p, __, n) => `${p}{${n ? +n + 1 : 1}}`
31
- ) : void 0 : `${mountingPath ? `${mountingPath}.` : ""}${single ? key : `${key}[0]`}`;
32
- const tableAlias = `including_${subMountingPath || key}`;
33
- return { subMountingPath, tableAlias };
28
+ if (key === "ronin_root") {
29
+ return mountingPath ? mountingPath.replace(
30
+ MOUNTING_PATH_SUFFIX,
31
+ (_, p, __, n) => `${p}{${n ? +n + 1 : 1}}`
32
+ ) : key;
33
+ }
34
+ return `${mountingPath ? `${mountingPath}.` : ""}${single ? key : `${key}[0]`}`;
34
35
  };
35
36
  var MODEL_ENTITY_ERROR_CODES = {
36
37
  field: "FIELD_NOT_FOUND",
@@ -318,11 +319,12 @@ var handleIncluding = (models, model, statementParams, single, instruction, opti
318
319
  let joinType = "LEFT";
319
320
  let relatedTableSelector = `"${relatedModel.table}"`;
320
321
  const subSingle = queryModel !== relatedModel.pluralSlug;
321
- const { tableAlias, subMountingPath } = composeMountingPath(
322
+ const subMountingPath = composeMountingPath(
322
323
  subSingle,
323
324
  ephemeralFieldSlug,
324
325
  options.mountingPath
325
326
  );
327
+ const tableAlias = `including_${subMountingPath}`;
326
328
  if (!modifiableQueryInstructions?.with) {
327
329
  joinType = "CROSS";
328
330
  if (subSingle) {
@@ -419,7 +421,7 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
419
421
  instructions.selecting
420
422
  ).filter((field) => !(field.type === "link" && field.kind === "many")).map((field) => {
421
423
  const newField = { ...field, mountingPath: field.slug };
422
- if (options.mountingPath) {
424
+ if (options.mountingPath && options.mountingPath !== "ronin_root") {
423
425
  newField.mountingPath = `${options.mountingPath.replace(/\{\d+\}/g, "")}.${field.slug}`;
424
426
  }
425
427
  return newField;
@@ -442,14 +444,10 @@ var handleSelecting = (models, model, statementParams, single, instructions, opt
442
444
  const subSingle = queryModel !== subQueryModel.pluralSlug;
443
445
  if (!model.tableAlias)
444
446
  model.tableAlias = single && !subSingle ? `sub_${model.table}` : model.table;
445
- const { tableAlias, subMountingPath } = composeMountingPath(
446
- subSingle,
447
- key,
448
- options.mountingPath
449
- );
447
+ const subMountingPath = composeMountingPath(subSingle, key, options.mountingPath);
450
448
  const { columns: nestedColumns, selectedFields: nestedSelectedFields } = handleSelecting(
451
449
  models,
452
- { ...subQueryModel, tableAlias },
450
+ { ...subQueryModel, tableAlias: `including_${subMountingPath}` },
453
451
  statementParams,
454
452
  subSingle,
455
453
  {
@@ -637,8 +635,7 @@ var compileQueryInput = (defaultQuery, models, statementParams, options) => {
637
635
  {
638
636
  selecting: instructions?.selecting,
639
637
  including: instructions?.including
640
- },
641
- options
638
+ }
642
639
  );
643
640
  let statement = "";
644
641
  switch (queryType) {
@@ -2078,17 +2075,17 @@ var Transaction = class {
2078
2075
  *
2079
2076
  * @param results - A list of results from the database, where each result is an array
2080
2077
  * of rows.
2081
- * @param raw - By default, rows are expected to be arrays of values, which is how SQL
2082
- * databases return rows by default. If the driver being used returns rows as objects
2083
- * instead, this option should be set to `false`.
2078
+ * @param raw - By default, rows are expected to be objects. If the driver being used
2079
+ * returns rows as arrays of values (which is how SQL databases return rows directly),
2080
+ * this option should be set to `true`.
2084
2081
  *
2085
2082
  * @returns A list of formatted RONIN results, where each result is either a single
2086
2083
  * RONIN record, an array of RONIN records, or a RONIN count result.
2087
2084
  */
2088
- formatResults(results, raw = true) {
2089
- const normalizedResults = raw ? results : results.map((rows) => {
2090
- return rows.map((row, index) => {
2091
- const { query } = this.#internalStatements[index];
2085
+ formatResults(results, raw = false) {
2086
+ const normalizedResults = raw ? results : results.map((rows, index) => {
2087
+ const { query } = this.#internalStatements[index];
2088
+ return rows.map((row) => {
2092
2089
  if (Array.isArray(row)) return row;
2093
2090
  if (query.count) return [row.amount];
2094
2091
  return Object.values(row);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronin/compiler",
3
- "version": "0.14.9-leo-ron-1099-1-experimental-342",
3
+ "version": "0.14.9-leo-ron-1099-1-experimental-344",
4
4
  "type": "module",
5
5
  "description": "Compiles RONIN queries to SQL statements.",
6
6
  "publishConfig": {