@opengis/fastify-table 1.1.93 → 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/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/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);
|
|
@@ -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}
|