@opengis/fastify-table 1.1.86 → 1.1.87
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
|
@@ -19,7 +19,7 @@ export default async function dataInsert({
|
|
|
19
19
|
const systemColumns = ['cdate', 'editor_date'].filter((el) => names.includes(el)).map((el) => [el, 'now()']);
|
|
20
20
|
|
|
21
21
|
const filterData = Object.keys(data)
|
|
22
|
-
.filter((el) => !['cdate', 'editor_date'].includes(el) && data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
22
|
+
.filter((el) => !['cdate', 'editor_date'].includes(el) && (typeof data[el] === 'boolean' ? true : data[el]) && names.includes(el)).map((el) => [el, data[el]]);
|
|
23
23
|
|
|
24
24
|
const insertQuery = `insert into ${table}
|
|
25
25
|
|
|
@@ -7,6 +7,16 @@ import logChanges from './utils/logChanges.js';
|
|
|
7
7
|
|
|
8
8
|
const srids = {};
|
|
9
9
|
|
|
10
|
+
function assignValue(key, i, srid = 4326) {
|
|
11
|
+
if (key === 'geom') {
|
|
12
|
+
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)`;
|
|
13
|
+
}
|
|
14
|
+
if (key?.includes('geom')) {
|
|
15
|
+
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srid})`;
|
|
16
|
+
}
|
|
17
|
+
return `"${key}"=$${i + 2}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
export default async function dataUpdate({
|
|
11
21
|
table, id, data, pg: pg1, uid,
|
|
12
22
|
}) {
|
|
@@ -22,7 +32,13 @@ export default async function dataUpdate({
|
|
|
22
32
|
|
|
23
33
|
const systemColumns = [['editor_date', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : []].filter((el) => names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
24
34
|
|
|
25
|
-
const filterValue = filterData.map((el) =>
|
|
35
|
+
const filterValue = filterData.map((el) => {
|
|
36
|
+
const { dataTypeID = 25 } = columns?.find?.((col) => col?.name === el) || {};
|
|
37
|
+
if (pg.pgType[dataTypeID]?.endsWith('[]') && ['string', 'number'].includes(typeof data[el])) {
|
|
38
|
+
Object.assign(data, { [el]: data[el].split(',') });
|
|
39
|
+
}
|
|
40
|
+
return [el, data[el]];
|
|
41
|
+
}).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
26
42
|
|
|
27
43
|
// update geometry with srid
|
|
28
44
|
if (!srids[table]) {
|
|
@@ -34,11 +50,9 @@ export default async function dataUpdate({
|
|
|
34
50
|
Object.assign(srids, srids1);
|
|
35
51
|
}
|
|
36
52
|
|
|
37
|
-
const updateQuery = `UPDATE ${table} SET ${systemColumns},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.join(',')}
|
|
41
|
-
WHERE ${pk} = $1 returning *`;
|
|
53
|
+
const updateQuery = `UPDATE ${table} SET ${systemColumns},
|
|
54
|
+
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326))?.join(',')}
|
|
55
|
+
WHERE ${pk} = $1 returning *`;
|
|
42
56
|
// console.log(updateQuery, filterValue);
|
|
43
57
|
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
44
58
|
|