@ronin/compiler 0.14.8 → 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.
package/dist/index.d.ts CHANGED
@@ -361,7 +361,7 @@ type PublicModel<T extends Array<ModelField> = Array<ModelField>> = Omit<Partial
361
361
 
362
362
  type RawRow = Array<unknown>;
363
363
  type ObjectRow = Record<string, unknown>;
364
- type NativeRecord = Record<string, unknown> & {
364
+ type ResultRecord = Record<string, unknown> & {
365
365
  id: string;
366
366
  ronin: {
367
367
  locked: boolean;
@@ -371,11 +371,11 @@ type NativeRecord = Record<string, unknown> & {
371
371
  updatedBy: string | null;
372
372
  };
373
373
  };
374
- type SingleRecordResult<T = NativeRecord> = {
374
+ type SingleRecordResult<T = ResultRecord> = {
375
375
  record: T | null;
376
376
  modelFields: Record<ModelField['slug'], ModelField['type']>;
377
377
  };
378
- type MultipleRecordResult<T = NativeRecord> = {
378
+ type MultipleRecordResult<T = ResultRecord> = {
379
379
  records: Array<T>;
380
380
  moreAfter?: string;
381
381
  moreBefore?: string;
@@ -384,7 +384,7 @@ type MultipleRecordResult<T = NativeRecord> = {
384
384
  type AmountResult = {
385
385
  amount: number;
386
386
  };
387
- type Result<T = NativeRecord> = SingleRecordResult<T> | MultipleRecordResult<T> | AmountResult;
387
+ type Result<T = ResultRecord> = SingleRecordResult<T> | MultipleRecordResult<T> | AmountResult;
388
388
 
389
389
  interface TransactionOptions {
390
390
  /** A list of models that already exist in the database. */
@@ -408,4 +408,4 @@ declare class Transaction {
408
408
 
409
409
  declare const CLEAN_ROOT_MODEL: PublicModel;
410
410
 
411
- export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, type DropQuery, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
411
+ export { type AddInstructions, type AddQuery, type AddInstructions as AddQueryInstructions, type AlterQuery, type CombinedInstructions, type CountInstructions, type CountQuery, type CountInstructions as CountQueryInstructions, type CreateQuery, type DropQuery, type GetInstructions, type GetQuery, type GetInstructions as GetQueryInstructions, type PublicModel as Model, type ModelField, type ModelIndex, type ModelPreset, type ModelTrigger, QUERY_SYMBOLS, type Query, type QueryInstructionType as QueryInstruction, type QuerySchemaType, type QueryType, CLEAN_ROOT_MODEL as ROOT_MODEL, type RemoveInstructions, type RemoveQuery, type RemoveInstructions as RemoveQueryInstructions, type Result, type ResultRecord, RoninError, type SetInstructions, type SetQuery, type SetInstructions as SetQueryInstructions, type Statement, type StoredObject, Transaction, type WithInstruction, getQuerySymbol };
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",
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": {