@opengis/fastify-table 1.1.92 → 1.1.94
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/index.js +2 -0
- package/package.json +1 -1
- package/server/plugins/crud/funcs/dataDelete.js +1 -1
- package/server/plugins/crud/funcs/dataInsert.js +1 -1
- package/server/plugins/crud/funcs/dataUpdate.js +2 -2
- package/server/plugins/table/funcs/getSelect.js +13 -3
- package/server/plugins/table/funcs/getSelectMeta.js +1 -1
- package/server/plugins/table/funcs/gisIRColumn.js +5 -2
- package/server/plugins/table/funcs/metaFormat/getSelectVal.js +1 -1
- package/server/routes/crud/controllers/table.js +3 -3
- package/server/routes/table/controllers/card.js +2 -2
- package/server/routes/table/controllers/data.js +1 -1
- package/server/routes/table/controllers/filter.js +1 -1
package/index.js
CHANGED
|
@@ -71,6 +71,8 @@ async function plugin(fastify, opt) {
|
|
|
71
71
|
// core templates && cls
|
|
72
72
|
const filename = fileURLToPath(import.meta.url);
|
|
73
73
|
const cwd = path.dirname(filename);
|
|
74
|
+
|
|
75
|
+
config.templates?.forEach(el => addTemplateDir(el));
|
|
74
76
|
addTemplateDir(path.join(cwd, 'module/core'));
|
|
75
77
|
}
|
|
76
78
|
export default fp(plugin);
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ export default async function dataDelete({
|
|
|
9
9
|
table, id, pg: pg1, uid,
|
|
10
10
|
}) {
|
|
11
11
|
const pg = pg1 || getPG({ name: 'client' });
|
|
12
|
-
const { pk } = await getMeta(table);
|
|
12
|
+
const { pk } = await getMeta({ pg, table });
|
|
13
13
|
if (!pg.tlist?.includes(table)) return 'table not exist';
|
|
14
14
|
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
15
15
|
// console.log(updateDataset);
|
|
@@ -10,7 +10,7 @@ export default async function dataInsert({
|
|
|
10
10
|
}) {
|
|
11
11
|
const pg = pg1 || getPG({ name: 'client' });
|
|
12
12
|
if (!data) return null;
|
|
13
|
-
const { columns } = await getMeta(table);
|
|
13
|
+
const { columns } = await getMeta({ pg, table });
|
|
14
14
|
if (!columns) return null;
|
|
15
15
|
|
|
16
16
|
const names = columns.map((el) => el.name);
|
|
@@ -23,7 +23,7 @@ export default async function dataUpdate({
|
|
|
23
23
|
if (!data || !table || !id) return null;
|
|
24
24
|
|
|
25
25
|
const pg = pg1 || getPG({ name: 'client' });
|
|
26
|
-
const { columns, pk } = await getMeta(table);
|
|
26
|
+
const { columns, pk } = await getMeta({ pg, table });
|
|
27
27
|
|
|
28
28
|
const names = columns?.map((el) => el.name);
|
|
29
29
|
|
|
@@ -50,7 +50,7 @@ export default async function dataUpdate({
|
|
|
50
50
|
Object.assign(srids, srids1);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}
|
|
53
|
+
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? ',' : ''}` : ''}
|
|
54
54
|
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326))?.join(',')}
|
|
55
55
|
WHERE ${pk} = $1 returning *`;
|
|
56
56
|
// console.log(updateQuery, filterValue);
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import pgClients from '../../pg/pgClients.js';
|
|
1
2
|
import getTemplate from './getTemplate.js';
|
|
2
3
|
|
|
3
4
|
const loadCls = {};
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const sqls = {
|
|
7
|
+
sql: 'select data from admin.cls where name=$1',
|
|
8
|
+
json: 'select json_agg(json_build_object(\'id\', code, \'text\', name, \'icon\', icon, \'color\', color)) as data from admin.cls where parent=$1',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default async function getSelect(name, pg = pgClients.client) {
|
|
6
12
|
if (loadCls[name]) return loadCls[name];
|
|
7
13
|
|
|
8
|
-
const
|
|
9
|
-
|
|
14
|
+
const clsDataGIT = await getTemplate(['cls', 'select'], name);
|
|
15
|
+
const { type } = !clsDataGIT && pg.pk?.['admin.cls'] ? await pg.query('select type from admin.cls where parent is null and name=$1 limit 1', [name]).then(el => el.rows?.[0] || {}) : {};
|
|
16
|
+
const q = !clsDataGIT && type && ['sql', 'json'].includes(type) ? sqls[type] : undefined;
|
|
17
|
+
const clsDataDB = q ? await pg.query(q, [name]).then(el => el.rows?.[0]?.data) : {};
|
|
18
|
+
const clsData = clsDataGIT || clsDataDB;
|
|
19
|
+
if (!clsData) return null;
|
|
10
20
|
|
|
11
21
|
// console.log(clsData);
|
|
12
22
|
if (clsData && Array.isArray(clsData)) {
|
|
@@ -10,7 +10,7 @@ const selectMeta = {};
|
|
|
10
10
|
export default async function getSelectMeta({ name, pg = pgClients.client, nocache }) {
|
|
11
11
|
if (selectMeta[name] && !nocache) return selectMeta[name];
|
|
12
12
|
|
|
13
|
-
const cls = await getSelect(name);
|
|
13
|
+
const cls = await getSelect(name, pg);
|
|
14
14
|
|
|
15
15
|
if (!cls) return null;
|
|
16
16
|
if (cls.arr) return cls;
|
|
@@ -4,13 +4,14 @@ import getFilterSQL from './getFilterSQL/index.js';
|
|
|
4
4
|
import getTemplate from './getTemplate.js';
|
|
5
5
|
import pgClients from '../../pg/pgClients.js';
|
|
6
6
|
import config from '../../../../config.js';
|
|
7
|
+
import getSelectVal from './metaFormat/getSelectVal.js';
|
|
7
8
|
|
|
8
9
|
export default async function gisIRColumn({
|
|
9
10
|
pg = pgClients.client, layer, column, sql, query = '1=1', filter, state, search, custom,
|
|
10
11
|
}) {
|
|
11
12
|
const time = Date.now();
|
|
12
13
|
|
|
13
|
-
const sel = await getSelect(query.cls || column);
|
|
14
|
+
const sel = await getSelect(query.cls || column, pg);
|
|
14
15
|
|
|
15
16
|
const body = await getTemplate('table', layer);
|
|
16
17
|
const fData = await getFilterSQL({
|
|
@@ -58,7 +59,9 @@ export default async function gisIRColumn({
|
|
|
58
59
|
|
|
59
60
|
const { rows } = await pg.query(q);
|
|
60
61
|
const cls = query.cls || body?.columns?.find((el) => el.name === column)?.data || col.data || col.option;
|
|
61
|
-
const select = await
|
|
62
|
+
const select = await getSelectVal({
|
|
63
|
+
pg, name: cls, values: rows.map((el) => el.id), ar: 1,
|
|
64
|
+
});
|
|
62
65
|
rows.forEach((el) => {
|
|
63
66
|
const data = select?.arr ? select.arr?.find((item) => item.id?.toString() === el.id?.toString()) : undefined;
|
|
64
67
|
Object.assign(el, data || {});
|
|
@@ -6,7 +6,7 @@ const selectIds = {};
|
|
|
6
6
|
export default async function getSelectVal({ pg = pgClients.client, name, values: valuesOrigin }) {
|
|
7
7
|
if (!valuesOrigin?.length) return null;
|
|
8
8
|
const values = valuesOrigin.map(el => el.toString());
|
|
9
|
-
const cls = await getSelect(name);
|
|
9
|
+
const cls = await getSelect(name, pg);
|
|
10
10
|
|
|
11
11
|
// === array ===
|
|
12
12
|
if (cls?.arr && Array.isArray(cls?.arr)) {
|
|
@@ -57,10 +57,10 @@ export default async function tableAPI(req) {
|
|
|
57
57
|
|
|
58
58
|
const { fields = [] } = !loadTable?.table ? await pg.query(`select * from ${tableName} limit 0`) : {};
|
|
59
59
|
const cols = loadTable?.table
|
|
60
|
-
? Object.keys(schema || {}).filter((col) => columnList.includes(col) && !extraKeys.includes(col))?.map((col) => (col?.includes('geom') ? `st_asgeojson(${col})::json as "${col}"` : `"${col}"`))?.join(',')
|
|
61
|
-
: fields.map((el) => (el?.name?.includes('geom') ? `st_asgeojson(${el.name})::json as "${el.name}"` : `"${el?.name}"`)).join(',');
|
|
60
|
+
? Object.keys(schema || {}).filter((col) => columnList.includes(col) && !extraKeys.includes(col))?.map((col) => (col?.includes('geom') && schema?.[col]?.type === 'Geom' ? `st_asgeojson(${col})::json as "${col}"` : `"${col}"`))?.join(',')
|
|
61
|
+
: fields.map((el) => (el?.name?.includes('geom') && pg.pgType[el?.dataTypeID] === 'geometry' ? `st_asgeojson(${el.name})::json as "${el.name}"` : `"${el?.name}"`)).join(',');
|
|
62
62
|
const where = [`"${pk}" = $1`, loadTable.query, accessQuery].filter((el) => el);
|
|
63
|
-
const geom =
|
|
63
|
+
const geom = dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? ',st_asgeojson(geom)::json as geom' : '';
|
|
64
64
|
const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${tableName} t where ${where.join(' and ') || 'true'} limit 1`;
|
|
65
65
|
|
|
66
66
|
if (query?.sql === '1') return q;
|
|
@@ -41,14 +41,14 @@ export default async function card(req) {
|
|
|
41
41
|
if (!pk) return { message: `table not found: ${table}`, status: 404 };
|
|
42
42
|
|
|
43
43
|
const cols = columns.map((el) => el.name || el).join(',');
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
46
46
|
const cardSqlFiltered = hookData?.id || params.id ? cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) : [];
|
|
47
47
|
const cardSqlTable = cardSqlFiltered?.length ? cardSqlFiltered.map((el, i) => ` left join lateral (select json_agg(row_to_json(q)) as ${el.name} from (${el.sql})q) ct${i} on 1=1 `).join('') || '' : '';
|
|
48
48
|
|
|
49
49
|
const where = [`"${pk}" = $1`, loadTable.query].filter((el) => el);
|
|
50
50
|
const cardColumns = cardSqlFiltered?.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
|
|
51
|
-
const q = `select ${pk ? `"${pk}" as id,` : ''} ${
|
|
51
|
+
const q = `select ${pk ? `"${pk}" as id,` : ''} ${dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? 'st_asgeojson(geom)::json as geom,' : ''} ${cols || '*'} ${cardColumns} from ${table} t ${sqlTable} ${cardSqlTable}
|
|
52
52
|
where ${where.join(' and ') || 'true'} limit 1`;
|
|
53
53
|
|
|
54
54
|
if (query.sql === '1') { return q; }
|
|
@@ -94,7 +94,7 @@ export default async function dataAPI(req) {
|
|
|
94
94
|
|
|
95
95
|
const cardColumns = cardSqlFiltered.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
|
|
96
96
|
const q = `select ${pk ? `"${pk}" as id,` : ''}
|
|
97
|
-
${dbColumns.
|
|
97
|
+
${dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? 'st_asgeojson(geom)::json as geom,' : ''}
|
|
98
98
|
${query.id || query.key ? '*' : sqlColumns || cols || '*'}
|
|
99
99
|
${metaCols}
|
|
100
100
|
${cardColumns}
|
|
@@ -27,7 +27,7 @@ export default async function filterAPI(req) {
|
|
|
27
27
|
|
|
28
28
|
const filters = loadTable?.filters || loadTable?.filterList || [];
|
|
29
29
|
await Promise.all(filters.filter((el) => el.data).map(async (el) => {
|
|
30
|
-
const cls = await getSelect(el.data);
|
|
30
|
+
const cls = await getSelect(el.data, req.pg);
|
|
31
31
|
if (!cls?.arr || !loadTable.table) return;
|
|
32
32
|
const { dataTypeID } = columns.find((item) => item.name === el.id) || {};
|
|
33
33
|
const countArr = req.pg.pgType[dataTypeID]?.includes('[]')
|