forge-sql-orm 2.1.7 → 2.1.8
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/ForgeSQLORM.js +17 -4
- package/dist/ForgeSQLORM.js.map +1 -1
- package/dist/ForgeSQLORM.mjs +17 -4
- package/dist/ForgeSQLORM.mjs.map +1 -1
- package/dist/utils/cacheContextUtils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/utils/cacheContextUtils.ts +22 -2
- package/src/utils/forgeDriver.ts +2 -2
package/dist/ForgeSQLORM.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -1090,8 +1103,8 @@ async function processExecuteMethod(query, params) {
|
|
|
1090
1103
|
}
|
|
1091
1104
|
const result = await withTimeout$1(sqlStatement.execute());
|
|
1092
1105
|
await saveMetaDataToContext(result.metadata);
|
|
1093
|
-
if (!result?.rows) {
|
|
1094
|
-
return { rows: [] };
|
|
1106
|
+
if (!result?.rows || Array.isArray(result.rows) && result.rows.length === 0) {
|
|
1107
|
+
return { rows: [void 0] };
|
|
1095
1108
|
}
|
|
1096
1109
|
if (isUpdateQueryResponse(result.rows)) {
|
|
1097
1110
|
const oneRow = result.rows;
|