@opengis/fastify-table 1.4.11 → 1.4.12
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/package.json
CHANGED
|
@@ -22,19 +22,27 @@ export default async function getSelectVal({
|
|
|
22
22
|
if (!cls?.sql) return null;
|
|
23
23
|
|
|
24
24
|
// select id column name
|
|
25
|
-
if (!selectIds[name])
|
|
25
|
+
if (!selectIds[name]) {
|
|
26
|
+
selectIds[name] = await pg.queryCache(`select * from (${cls.sql})q limit 0`)
|
|
27
|
+
.then((res) => res.fields?.[0]?.name)
|
|
28
|
+
.catch(err => console.error('getSelectVal error: 1', name, cls.sql, err.toString()));
|
|
29
|
+
}
|
|
26
30
|
const id = selectIds[name];
|
|
27
31
|
|
|
28
32
|
// cache
|
|
29
33
|
const key = `select:${name}`;
|
|
34
|
+
|
|
30
35
|
const cache = values?.length && config.redis ? (await rclient.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
|
|
31
36
|
const filteredValues = values.filter(el => !cache[el]);
|
|
32
37
|
|
|
33
38
|
// query select
|
|
39
|
+
const q = `with c(id,text) as (select * from (${cls.sql})q where ${id} = any('{${filteredValues.join(',').replace(/\"/g, '\\"').replace(/'/g, "''")}}')) select * from c`;
|
|
34
40
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
const data = filteredValues.length
|
|
42
|
+
? await pg.query(q)
|
|
43
|
+
.then(el => el.rows)
|
|
44
|
+
.catch(err => console.error('getSelectVal error: 2', name, q, err.toString()))
|
|
45
|
+
: [];
|
|
38
46
|
|
|
39
47
|
const clsObj = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
|
|
40
48
|
|
|
@@ -376,7 +376,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
376
376
|
uid,
|
|
377
377
|
array: 1,
|
|
378
378
|
});
|
|
379
|
-
Object.assign(res, { addToken: addTokens[0] });
|
|
379
|
+
Object.assign(res, { addToken: addTokens?.[0] });
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
const result = await applyHook('afterData', {
|