@opengis/fastify-table 1.3.43 → 1.3.45
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
|
@@ -30,7 +30,7 @@ export default async function dataDelete({
|
|
|
30
30
|
});
|
|
31
31
|
const table1 = table.replace(/"/g, '');
|
|
32
32
|
if (!pg.tlist?.includes(table1)) return 'table not exist';
|
|
33
|
-
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
33
|
+
const delQuery = `delete from ${table} WHERE ${pk}::text = $1::text returning *`;
|
|
34
34
|
|
|
35
35
|
const extraRes = await extraData({
|
|
36
36
|
table, form: tokenData?.form, id, uid,
|
|
@@ -4,6 +4,7 @@ import getRedis from '../../redis/funcs/getRedis.js';
|
|
|
4
4
|
import pgClients from '../../pg/pgClients.js';
|
|
5
5
|
|
|
6
6
|
import logChanges from './utils/logChanges.js';
|
|
7
|
+
import logger from '../../logger/getLogger.js';
|
|
7
8
|
import extraData from '../../extra/extraData.js';
|
|
8
9
|
|
|
9
10
|
const rclient = getRedis();
|
|
@@ -49,7 +50,11 @@ export default async function dataInsert({
|
|
|
49
50
|
|
|
50
51
|
returning *`;
|
|
51
52
|
|
|
52
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))])
|
|
53
|
+
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))])
|
|
54
|
+
.catch(err => {
|
|
55
|
+
logger.file('crud/insert', { error: err.toString(), stack: err.stack, table, id, referer, uid, q: insertQuery });
|
|
56
|
+
throw new Error(err.toString());
|
|
57
|
+
}).then(el => el || {});
|
|
53
58
|
|
|
54
59
|
const table1 = pg.pk[table] ? table : table.replace(/"/g, '');
|
|
55
60
|
|
|
@@ -46,7 +46,7 @@ export default async function dataUpdate({
|
|
|
46
46
|
const filterData = Object.keys(data)
|
|
47
47
|
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
|
|
48
48
|
|
|
49
|
-
const systemColumns = [['editor_date', 'now()', 'updated_at', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'
|
|
49
|
+
const systemColumns = [['editor_date', 'now()'], ['updated_at', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : null, uid ? ['updated_by', `'${uid.replace(/'/g, "''")}'`] : null].filter((el) => el && names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
50
50
|
|
|
51
51
|
const filterValue = filterData.map((el) => {
|
|
52
52
|
const { dataTypeID = 25 } = columns.find((col) => col?.name === el) || {};
|
|
@@ -68,7 +68,7 @@ export default async function dataUpdate({
|
|
|
68
68
|
|
|
69
69
|
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? ',' : ''}` : ''}
|
|
70
70
|
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326, pg.pgType?.[columns.find(col => col.name === key)?.dataTypeID || '']))?.join(',')}
|
|
71
|
-
WHERE ${pk} = $1 returning *`;
|
|
71
|
+
WHERE ${pk}::text = $1::text returning *`;
|
|
72
72
|
// console.log(updateQuery, filterValue);
|
|
73
73
|
const res = await pg.query(updateQuery, [id, ...filterValue])
|
|
74
74
|
.catch(err => {
|
|
@@ -2,14 +2,14 @@ import config from '../../../../config.js';
|
|
|
2
2
|
import hookList from '../hookList.js';
|
|
3
3
|
|
|
4
4
|
export default async function applyHook(name, data) {
|
|
5
|
-
const {
|
|
6
|
-
if (
|
|
5
|
+
const { trace } = config;
|
|
6
|
+
if (trace) console.log('applyHook', name);
|
|
7
7
|
if (!hookList[name]?.length) return null;
|
|
8
8
|
const result = {};
|
|
9
9
|
await Promise.all(hookList[name].map(async (hook) => {
|
|
10
10
|
const hookData = await hook({ ...data, config });
|
|
11
11
|
if (hookData) {
|
|
12
|
-
if (
|
|
12
|
+
if (trace) console.log('applyHook', name, hookData);
|
|
13
13
|
Object.assign(result, hookData);
|
|
14
14
|
}
|
|
15
15
|
})).catch((err) => {
|
|
@@ -189,7 +189,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
189
189
|
count(*)::int as total,
|
|
190
190
|
count(*) FILTER(WHERE ${filterWhere.join(' and ') || 'true'})::int as filtered
|
|
191
191
|
${aggregates.length ? `,${aggregates.map((el) => `${aggColumns[el.name]}(${el.name}) FILTER(WHERE ${filterWhere.join(' and ') || 'true'}) as ${el.name}`).join(',')}` : ''}
|
|
192
|
-
from (select * ${sql?.filter(el => el.inline).map(el => `,(${el.sql})`).join('') || ''} from ${table} t ${sqlTable})
|
|
192
|
+
from (select * ${sql?.filter(el => el.inline).map(el => `,(${el.sql})`).join('') || ''} from ${table} t ${sqlTable})q
|
|
193
193
|
where ${[loadTable?.query, tokenData?.query, accessQuery, contextQuery].filter(el => el).filter((el) => checkQuery(el)).join(' and ') || 'true'} `
|
|
194
194
|
.replace(/{{uid}}/g, uid);
|
|
195
195
|
|
|
@@ -321,6 +321,10 @@ export default async function dataAPI(req, reply, called) {
|
|
|
321
321
|
filters: filters?.map?.(el => ({ ...el, sql: undefined })),
|
|
322
322
|
};
|
|
323
323
|
|
|
324
|
+
if (!res.columns?.length && dbColumns?.length) {
|
|
325
|
+
Object.assign(res, { columns: dbColumns.map(({ name, title, dataTypeID }) => ({ name, title, type: pg.pgType[dataTypeID] })) });
|
|
326
|
+
}
|
|
327
|
+
|
|
324
328
|
// console.log({ add: loadTable.table, form: loadTable.form });
|
|
325
329
|
if (uid && actions.includes('add')) {
|
|
326
330
|
const addTokens = setToken({
|