@benjosivo/table-query 1.0.2 → 1.0.3
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/server/index.js +16 -3
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -139,7 +139,11 @@ export function createTableQueryModule(deps) {
|
|
|
139
139
|
const columns = Object.keys(payload.items[0]);
|
|
140
140
|
if (cleRecupFiltre && cache) {
|
|
141
141
|
const titreRecupFiltres = `tableQuery:recupFiltres:${cleRecupFiltre}`;
|
|
142
|
-
await cache.setSQLCache(titreRecupFiltres, {
|
|
142
|
+
await cache.setSQLCache(titreRecupFiltres, {
|
|
143
|
+
title: titreRecupFiltres,
|
|
144
|
+
data: { status: `Waiting` },
|
|
145
|
+
expiration: Date.now() + 60 * 60 * 1000,
|
|
146
|
+
});
|
|
143
147
|
}
|
|
144
148
|
const filtres = await computeFiltersViaTempTable({ baseQuery, argsQuery, columns, paramFilter });
|
|
145
149
|
if (cleRecupFiltre && cache) {
|
|
@@ -147,7 +151,11 @@ export function createTableQueryModule(deps) {
|
|
|
147
151
|
await cache.setSQLCache(titreRecupFiltres, { title: titreRecupFiltres, data: { filtres }, expiration: Date.now() + 60 * 60 * 1000 });
|
|
148
152
|
}
|
|
149
153
|
if (keepCache && cache) {
|
|
150
|
-
await cache.setSQLCache(keepCache.titleSQLCacheFiltre, {
|
|
154
|
+
await cache.setSQLCache(keepCache.titleSQLCacheFiltre, {
|
|
155
|
+
title: keepCache.titleSQLCacheFiltre,
|
|
156
|
+
data: filtres,
|
|
157
|
+
expiration: Date.now() + keepCache.keepCache,
|
|
158
|
+
});
|
|
151
159
|
}
|
|
152
160
|
return filtres;
|
|
153
161
|
}
|
|
@@ -155,6 +163,8 @@ export function createTableQueryModule(deps) {
|
|
|
155
163
|
if (Object.keys(filtres).length === 0)
|
|
156
164
|
return '';
|
|
157
165
|
function singleCondition(key, val) {
|
|
166
|
+
if (!val)
|
|
167
|
+
return undefined;
|
|
158
168
|
const lower = val.toLowerCase();
|
|
159
169
|
if (lower === 'null' || lower === 'vide')
|
|
160
170
|
return `\`${key}\` IS NULL`;
|
|
@@ -166,7 +176,10 @@ export function createTableQueryModule(deps) {
|
|
|
166
176
|
}
|
|
167
177
|
const conditions = Object.entries(filtres).map(([key, value]) => {
|
|
168
178
|
if (Array.isArray(value)) {
|
|
169
|
-
|
|
179
|
+
if (value.length > 0)
|
|
180
|
+
return `(${value.map((val) => singleCondition(key, String(val).replaceAll('/*/', '%'))).join(' OR ')})`;
|
|
181
|
+
else
|
|
182
|
+
return undefined;
|
|
170
183
|
}
|
|
171
184
|
if (value !== null && typeof value === 'object' && 'min' in value && 'max' in value) {
|
|
172
185
|
const min = value.date ? `'${deps.convertToMySQLDateTime(value.min)}'` : value.min;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@benjosivo/table-query",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Table triable/filtrable/paginée : hook + composants React d'un côté (`/react`), logique SQL de pagination/tri/filtres côté serveur de l'autre (`/server`). Un projet peut n'utiliser qu'un des deux côtés.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/benjosivo/table-query#readme",
|