@opengis/fastify-table 1.1.72 → 1.1.74
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/README.md +26 -26
- package/config.js +10 -10
- package/package.json +1 -1
- package/server/plugins/cron/funcs/addCron.js +7 -5
- package/server/plugins/redis/index.js +6 -4
- package/server/plugins/table/funcs/getSelectMeta.js +2 -3
- package/server/plugins/table/funcs/metaFormat/getSelectVal.js +5 -3
- package/server/routes/table/controllers/data.js +3 -1
package/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
# fastify-table
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@opengis/fastify-table)
|
|
4
|
-
[](http://standardjs.com/)
|
|
5
|
-
|
|
6
|
-
It standardizes the entire form building process, while taking care of everything from rendering to validation and processing:
|
|
7
|
-
|
|
8
|
-
- pg
|
|
9
|
-
- redis
|
|
10
|
-
- crud
|
|
11
|
-
|
|
12
|
-
## Install
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm i @opengis/fastify-table
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```js
|
|
21
|
-
fastify.register(import('@opengis/fastify-table'), config);
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Documenation
|
|
25
|
-
|
|
26
|
-
For a detailed understanding fastify-table, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/gis.storage/).
|
|
1
|
+
# fastify-table
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@opengis/fastify-table)
|
|
4
|
+
[](http://standardjs.com/)
|
|
5
|
+
|
|
6
|
+
It standardizes the entire form building process, while taking care of everything from rendering to validation and processing:
|
|
7
|
+
|
|
8
|
+
- pg
|
|
9
|
+
- redis
|
|
10
|
+
- crud
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm i @opengis/fastify-table
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
fastify.register(import('@opengis/fastify-table'), config);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Documenation
|
|
25
|
+
|
|
26
|
+
For a detailed understanding fastify-table, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/gis.storage/).
|
package/config.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
|
|
3
|
-
const fileName = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
4
|
-
const config = fileName ? JSON.parse(fs.readFileSync(fileName)) : {};
|
|
5
|
-
|
|
6
|
-
Object.assign(config, {
|
|
7
|
-
allTemplates: config?.allTemplates || {},
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export default config;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
const fileName = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
4
|
+
const config = fileName ? JSON.parse(fs.readFileSync(fileName)) : {};
|
|
5
|
+
|
|
6
|
+
Object.assign(config, {
|
|
7
|
+
allTemplates: config?.allTemplates || {},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -65,15 +65,17 @@ async function runCron({
|
|
|
65
65
|
|
|
66
66
|
if (!unique) return;
|
|
67
67
|
const db = pg.options.database;
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
try {
|
|
70
70
|
const data = await func({ pg });
|
|
71
|
-
logger.
|
|
72
|
-
|
|
71
|
+
logger.file('cron', {
|
|
72
|
+
level: 'INFO', db, name, result: data,
|
|
73
|
+
});
|
|
73
74
|
}
|
|
74
75
|
catch (err) {
|
|
75
|
-
logger.
|
|
76
|
-
|
|
76
|
+
logger.file('cron', {
|
|
77
|
+
level: 'ERROR', db, name, error: err.toString(),
|
|
78
|
+
});
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
// import redis from './client.js';
|
|
2
|
+
import redisClients from './funcs/redisClients.js';
|
|
2
3
|
|
|
3
4
|
function close(fastify) {
|
|
4
|
-
|
|
5
|
+
// redis.quit();
|
|
6
|
+
Object.keys(redisClients).forEach((key) => redisClients[key].quit());
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
async function plugin(fastify) {
|
|
8
|
-
const client = getRedis({ db: 0 });
|
|
9
|
-
client.getJSON = client.get;
|
|
10
|
+
// const client = getRedis({ db: 0 });
|
|
11
|
+
// client.getJSON = client.get;
|
|
10
12
|
// fastify.decorate('rclient', client);
|
|
11
13
|
// fastify.decorate('getRedis', getRedis);
|
|
12
14
|
fastify.addHook('onClose', close);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pgClients from '../../pg/pgClients.js';
|
|
2
2
|
|
|
3
3
|
import getSelect from './getSelect.js';
|
|
4
4
|
|
|
5
5
|
const selectMeta = {};
|
|
6
6
|
|
|
7
|
-
export default async function getSelectMeta({ name, pg
|
|
7
|
+
export default async function getSelectMeta({ name, pg = pgClients.client, nocache }) {
|
|
8
8
|
if (selectMeta[name] && !nocache) return selectMeta[name];
|
|
9
9
|
|
|
10
10
|
const cls = await getSelect(name);
|
|
@@ -13,7 +13,6 @@ export default async function getSelectMeta({ name, pg: pg1, nocache }) {
|
|
|
13
13
|
if (cls.arr) return cls;
|
|
14
14
|
if (!cls.sql) return null;
|
|
15
15
|
|
|
16
|
-
const pg = pg1 || getPG({ db: cls.db || 'client' });
|
|
17
16
|
const { sql: original } = cls;
|
|
18
17
|
if (!original.toLowerCase) { console.log(`sql select null: ${name}`); return null; }
|
|
19
18
|
|
|
@@ -4,15 +4,17 @@ import redis from '../../../redis/client.js';
|
|
|
4
4
|
|
|
5
5
|
// import { pgClients, getSelect } from '../../../../../utils.js';
|
|
6
6
|
|
|
7
|
-
export default async function getSelectVal({ pg
|
|
8
|
-
const pg = pg1 || pgClients.client;
|
|
7
|
+
export default async function getSelectVal({ pg = pgClients.client, name, values }) {
|
|
9
8
|
const cls = await getSelect(name);
|
|
10
9
|
if (!cls?.arr && !cls?.sql) return null;
|
|
11
10
|
const key = `select:${name}`;
|
|
12
11
|
const cache = !cls.arr ? (await redis.hmget(key, values)).reduce((p, el, i) => ({ ...p, [values[i]]: el }), {}) : {};
|
|
13
12
|
|
|
13
|
+
const id = cls?.sql?.toLowerCase()?.split(',')?.shift()?.split(' ')
|
|
14
|
+
?.pop();
|
|
15
|
+
const q = `with c(id,text) as (select * from (${cls.sql})q where ${id} = any('{${values.filter(el => !cache[el])}}')) select * from c`;
|
|
14
16
|
const data = cls.arr || (values.filter(el => !cache[el]).length
|
|
15
|
-
? await pg.query(
|
|
17
|
+
? await pg.query(q).then(el => el.rows)
|
|
16
18
|
: []);
|
|
17
19
|
|
|
18
20
|
const clsAr = { ...cache, ...data.reduce((p, el) => ({ ...p, [el.id.toString()]: el.color ? el : el.text }), {}) };
|
|
@@ -98,7 +98,9 @@ export default async function dataAPI(req) {
|
|
|
98
98
|
${query.id || query.key ? '*' : sqlColumns || cols || '*'}
|
|
99
99
|
${metaCols}
|
|
100
100
|
${cardColumns}
|
|
101
|
-
from ${table}
|
|
101
|
+
from (select * from ${table} where ${where.join(' and ') || 'true'} ${order}) t
|
|
102
|
+
${sqlTable}
|
|
103
|
+
${cardSqlTable}
|
|
102
104
|
where ${where.join(' and ') || 'true'}
|
|
103
105
|
${order} ${offset} limit ${limit}`
|
|
104
106
|
.replace(/{{uid}}/g, uid);
|