forge-sql-orm 2.1.7 → 2.1.9

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.
@@ -546,6 +546,9 @@ async function setCacheResult(query, options, results, cacheTtl) {
546
546
  console.error(`Error setting cache: ${error.message}`, error);
547
547
  }
548
548
  }
549
+ function isQuery(obj) {
550
+ return typeof obj === "object" && obj !== null && typeof obj.sql === "string" && Array.isArray(obj.params);
551
+ }
549
552
  const cacheApplicationContext = new AsyncLocalStorage();
550
553
  const localCacheApplicationContext = new AsyncLocalStorage();
551
554
  async function saveTableIfInsideCacheContext(table) {
@@ -561,7 +564,12 @@ async function saveQueryLocalCacheQuery(query, rows, options) {
561
564
  if (!context.cache) {
562
565
  context.cache = {};
563
566
  }
564
- const sql2 = query;
567
+ let sql2;
568
+ if (isQuery(query)) {
569
+ sql2 = { toSQL: () => query };
570
+ } else {
571
+ sql2 = query;
572
+ }
565
573
  const key = hashKey(sql2.toSQL());
566
574
  context.cache[key] = {
567
575
  sql: sql2.toSQL().sql.toLowerCase(),
@@ -581,7 +589,12 @@ async function getQueryLocalCacheQuery(query, options) {
581
589
  if (!context.cache) {
582
590
  context.cache = {};
583
591
  }
584
- const sql2 = query;
592
+ let sql2;
593
+ if (isQuery(query)) {
594
+ sql2 = { toSQL: () => query };
595
+ } else {
596
+ sql2 = query;
597
+ }
585
598
  const key = hashKey(sql2.toSQL());
586
599
  if (context.cache[key] && context.cache[key].sql === sql2.toSQL().sql.toLowerCase()) {
587
600
  if (options.logCache) {
@@ -1091,13 +1104,13 @@ async function processExecuteMethod(query, params) {
1091
1104
  const result = await withTimeout$1(sqlStatement.execute());
1092
1105
  await saveMetaDataToContext(result.metadata);
1093
1106
  if (!result?.rows) {
1094
- return { rows: [] };
1107
+ return { rows: [[]] };
1095
1108
  }
1096
1109
  if (isUpdateQueryResponse(result.rows)) {
1097
1110
  const oneRow = result.rows;
1098
- return { ...oneRow, rows: [oneRow] };
1111
+ return { rows: [oneRow] };
1099
1112
  }
1100
- return { rows: result.rows };
1113
+ return { rows: [result.rows] };
1101
1114
  }
1102
1115
  async function processAllMethod(query, params) {
1103
1116
  const sqlStatement = await sql$1.prepare(query);