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.js
CHANGED
|
@@ -565,6 +565,9 @@ async function setCacheResult(query, options, results, cacheTtl) {
|
|
|
565
565
|
console.error(`Error setting cache: ${error.message}`, error);
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
|
+
function isQuery(obj) {
|
|
569
|
+
return typeof obj === "object" && obj !== null && typeof obj.sql === "string" && Array.isArray(obj.params);
|
|
570
|
+
}
|
|
568
571
|
const cacheApplicationContext = new node_async_hooks.AsyncLocalStorage();
|
|
569
572
|
const localCacheApplicationContext = new node_async_hooks.AsyncLocalStorage();
|
|
570
573
|
async function saveTableIfInsideCacheContext(table$1) {
|
|
@@ -580,7 +583,12 @@ async function saveQueryLocalCacheQuery(query, rows, options) {
|
|
|
580
583
|
if (!context.cache) {
|
|
581
584
|
context.cache = {};
|
|
582
585
|
}
|
|
583
|
-
|
|
586
|
+
let sql2;
|
|
587
|
+
if (isQuery(query)) {
|
|
588
|
+
sql2 = { toSQL: () => query };
|
|
589
|
+
} else {
|
|
590
|
+
sql2 = query;
|
|
591
|
+
}
|
|
584
592
|
const key = hashKey(sql2.toSQL());
|
|
585
593
|
context.cache[key] = {
|
|
586
594
|
sql: sql2.toSQL().sql.toLowerCase(),
|
|
@@ -600,7 +608,12 @@ async function getQueryLocalCacheQuery(query, options) {
|
|
|
600
608
|
if (!context.cache) {
|
|
601
609
|
context.cache = {};
|
|
602
610
|
}
|
|
603
|
-
|
|
611
|
+
let sql2;
|
|
612
|
+
if (isQuery(query)) {
|
|
613
|
+
sql2 = { toSQL: () => query };
|
|
614
|
+
} else {
|
|
615
|
+
sql2 = query;
|
|
616
|
+
}
|
|
604
617
|
const key = hashKey(sql2.toSQL());
|
|
605
618
|
if (context.cache[key] && context.cache[key].sql === sql2.toSQL().sql.toLowerCase()) {
|
|
606
619
|
if (options.logCache) {
|
|
@@ -1109,8 +1122,8 @@ async function processExecuteMethod(query, params) {
|
|
|
1109
1122
|
}
|
|
1110
1123
|
const result = await withTimeout$1(sqlStatement.execute());
|
|
1111
1124
|
await saveMetaDataToContext(result.metadata);
|
|
1112
|
-
if (!result?.rows) {
|
|
1113
|
-
return { rows: [] };
|
|
1125
|
+
if (!result?.rows || Array.isArray(result.rows) && result.rows.length === 0) {
|
|
1126
|
+
return { rows: [void 0] };
|
|
1114
1127
|
}
|
|
1115
1128
|
if (isUpdateQueryResponse(result.rows)) {
|
|
1116
1129
|
const oneRow = result.rows;
|