@opengis/fastify-table 1.0.91 → 1.0.93

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/Changelog.md CHANGED
@@ -1,273 +1,281 @@
1
- # fastify-table
2
-
3
- ## 1.0.91 - 30.08.2024
4
-
5
- - add CRUD and Auth logs
6
-
7
- ## 1.0.90 - 27.08.2024
8
-
9
- - logger file API to core
10
-
11
- ## 1.0.89 - 26.08.2024
12
-
13
- - data API meta bbox polyline support
14
-
15
- ## 1.0.87 - 26.08.2024
16
-
17
- - change of null handling method of update crud API
18
-
19
- ## 1.0.86 - 23.08.2024
20
-
21
- - data API meta cls support
22
-
23
- ## 1.0.84 - 22.08.2024
24
-
25
- - suggest table:column support
26
-
27
- ## 1.0.83 - 20.08.2024
28
-
29
- - code optimization
30
-
31
- ## 1.0.81 - 15.08.2024
32
-
33
- - refactor /table API
34
-
35
- ## 1.0.78 - 14.08.2024
36
-
37
- - add sqlColumns to /api/data/:table/?:id
38
-
39
- ## 1.0.77 - 13.08.2024
40
-
41
- - add statusMonitor API
42
-
43
- ## 1.0.75 - 12.08.2024
44
-
45
- - something do
46
-
47
- ## 1.0.71 - 01.08.2024
48
-
49
- - add compile settings to form
50
-
51
- ## 1.0.70 - 29.07.2024
52
-
53
- - add cron funcs and API
54
-
55
- ## 1.0.69 - 26.07.2024
56
-
57
- - add column classifier mode for data API
58
-
59
- ## 1.0.68 - 26.07.2024
60
-
61
- - code optimization
62
-
63
- ## 1.0.66 - 25.07.2024
64
-
65
- - add notification compile template from data params support
66
-
67
- ## 1.0.65 - 23.07.2024
68
-
69
- - add rest API token support
70
-
71
- ## 1.0.62 - 22.07.2024
72
-
73
- - add email notification func and test api
74
-
75
- ## 1.0.61 - 18.07.2024
76
-
77
- - add custom actions for table
78
-
79
- ## 1.0.60 - 12.07.2024
80
-
81
- - code optimization
82
-
83
- ## 1.0.59 - 12.07.2024
84
-
85
- - code optimization
86
-
87
- ## 1.0.58 - 08.07.2024
88
-
89
- - code optimization
90
-
91
- ## 1.0.57 - 04.07.2024
92
-
93
- - fix crud update boolean column
94
-
95
- ## 1.0.56 - 04.07.2024
96
-
97
- - code optimization
98
-
99
- ## 1.0.55 - 02.07.2024
100
-
101
- - callback support
102
-
103
- ## 1.0.54 - 01.07.2024
104
-
105
- - code optimization
106
-
107
- ## 1.0.53 - 28.06.2024
108
-
109
- - add migrations support
110
-
111
- ## 1.0.52 - 28.06.2024
112
-
113
- - add table get api
114
-
115
- ## 1.0.51 - 27.06.2024
116
-
117
- - add next-id api
118
-
119
- ## 1.0.50 - 27.06.2024
120
-
121
- - refactor search api
122
-
123
- ## 1.0.49 - 26.06.2024
124
-
125
- - refactor - npm settings
126
-
127
- ## 1.0.48 - 26.06.2024
128
-
129
- - search api no specified table mode support
130
-
131
- ## 1.0.47 - 25.06.2024
132
-
133
- - add extra properties support
134
-
135
- ## 1.0.46 - 24.06.2024
136
-
137
- - fix data api edit geometry
138
-
139
- ## 1.0.45 - 19.06.2024
140
-
141
- - fix data api table template order
142
-
143
- ## 1.0.44 - 18.06.2024
144
-
145
- - add extra data support (form DataTable)
146
-
147
- ## 1.0.43 - 14.06.2024
148
-
149
- - add settings api, funcs, migration
150
-
151
- ## 1.0.42 - 12.06.2024
152
-
153
- - table cardSql support
154
-
155
- ## 1.0.41 - 12.06.2024
156
-
157
- - cls to db (crm.cls)
158
-
159
- ## 1.0.40 - 12.06.2024
160
-
161
- - fix widget GET API
162
-
163
- ## 1.0.39 - 29.05.2024
164
-
165
- - add getFolder func
166
-
167
- ## 1.0.37 - 23.05.2024
168
-
169
- - add gallery widget
170
-
171
- ## 1.0.36 - 22.05.2024
172
-
173
- - fix filter api array processing
174
-
175
- ## 1.0.31 - 20.05.2024
176
-
177
- - widget db structure refactor
178
-
179
- ## 1.0.30 - 17.05.2024
180
-
181
- - code optimization
182
-
183
- ## 1.0.29 - 17.05.2024
184
-
185
- - widget api post (file)
186
-
187
- ## 1.0.28 - 14.05.2024
188
-
189
- - dblist api set
190
-
191
- ## 1.0.27 - 12.05.2024
192
-
193
- - code optimization
194
-
195
- ## 1.0.26 - 09.05.2024
196
-
197
- - fix getTableSql
198
-
199
- ## 1.0.25 - 08.05.2024
200
-
201
- - decorator to hook
202
-
203
- ## 1.0.24 - 07.05.2024
204
-
205
- - getTemplate page
206
-
207
- ## 1.0.23 - 07.05.2024
208
-
209
- - getTemplate funcs
210
- - dblist api
211
-
212
- ## 1.0.22 - 03.05.2024
213
-
214
- - getFilterSQL funcs
215
-
216
- ## 1.0.21 - 03.05.2024
217
-
218
- - fix widget db structure
219
-
220
- ## 1.0.20 - 03.05.2024
221
-
222
- - fix filter separator
223
-
224
- ## 1.0.19 - 02.05.2024
225
-
226
- - widget plugin
227
- - notification plugin
228
-
229
- ## 1.0.9 - 29.04.2024
230
-
231
- - crud token support
232
- - security - xss restriction
233
-
234
- ## 1.0.8 - 29.04.2024
235
-
236
- - filter fix
237
-
238
- ## 1.0.7 - 26.04.2024
239
-
240
- - code optimization
241
-
242
- ## 1.0.6 - 25.04.2024
243
-
244
- - code optimization
245
-
246
- ## 1.0.5 - 24.04.2024
247
-
248
- - code optimization
249
-
250
- ## 1.0.4 - 20.04.2024
251
-
252
- - data api - order
253
- - suggest api - db support
254
- - del api fix
255
-
256
- ## 1.0.3 - 17.04.2024
257
-
258
- - fix unit test
259
-
260
- ## 1.0.2 - 14.04.2024
261
-
262
- - fix redis
263
-
264
- ## 1.0.1 - 14.04.2024
265
-
266
- - fix redis
267
-
268
- ## 1.0.0 - 14.04.2024
269
-
270
- - crud
271
- - pg
272
- - redis
273
- - table
1
+ # fastify-table
2
+
3
+ ## 1.0.93 - 05.09.2024
4
+
5
+ - fix data API with sql columns filter
6
+
7
+ ## 1.0.92 - 03.09.2024
8
+
9
+ - fix getTemplate
10
+
11
+ ## 1.0.91 - 30.08.2024
12
+
13
+ - add CRUD and Auth logs
14
+
15
+ ## 1.0.90 - 27.08.2024
16
+
17
+ - logger file API to core
18
+
19
+ ## 1.0.89 - 26.08.2024
20
+
21
+ - data API meta bbox polyline support
22
+
23
+ ## 1.0.87 - 26.08.2024
24
+
25
+ - change of null handling method of update crud API
26
+
27
+ ## 1.0.86 - 23.08.2024
28
+
29
+ - data API meta cls support
30
+
31
+ ## 1.0.84 - 22.08.2024
32
+
33
+ - suggest table:column support
34
+
35
+ ## 1.0.83 - 20.08.2024
36
+
37
+ - code optimization
38
+
39
+ ## 1.0.81 - 15.08.2024
40
+
41
+ - refactor /table API
42
+
43
+ ## 1.0.78 - 14.08.2024
44
+
45
+ - add sqlColumns to /api/data/:table/?:id
46
+
47
+ ## 1.0.77 - 13.08.2024
48
+
49
+ - add statusMonitor API
50
+
51
+ ## 1.0.75 - 12.08.2024
52
+
53
+ - something do
54
+
55
+ ## 1.0.71 - 01.08.2024
56
+
57
+ - add compile settings to form
58
+
59
+ ## 1.0.70 - 29.07.2024
60
+
61
+ - add cron funcs and API
62
+
63
+ ## 1.0.69 - 26.07.2024
64
+
65
+ - add column classifier mode for data API
66
+
67
+ ## 1.0.68 - 26.07.2024
68
+
69
+ - code optimization
70
+
71
+ ## 1.0.66 - 25.07.2024
72
+
73
+ - add notification compile template from data params support
74
+
75
+ ## 1.0.65 - 23.07.2024
76
+
77
+ - add rest API token support
78
+
79
+ ## 1.0.62 - 22.07.2024
80
+
81
+ - add email notification func and test api
82
+
83
+ ## 1.0.61 - 18.07.2024
84
+
85
+ - add custom actions for table
86
+
87
+ ## 1.0.60 - 12.07.2024
88
+
89
+ - code optimization
90
+
91
+ ## 1.0.59 - 12.07.2024
92
+
93
+ - code optimization
94
+
95
+ ## 1.0.58 - 08.07.2024
96
+
97
+ - code optimization
98
+
99
+ ## 1.0.57 - 04.07.2024
100
+
101
+ - fix crud update boolean column
102
+
103
+ ## 1.0.56 - 04.07.2024
104
+
105
+ - code optimization
106
+
107
+ ## 1.0.55 - 02.07.2024
108
+
109
+ - callback support
110
+
111
+ ## 1.0.54 - 01.07.2024
112
+
113
+ - code optimization
114
+
115
+ ## 1.0.53 - 28.06.2024
116
+
117
+ - add migrations support
118
+
119
+ ## 1.0.52 - 28.06.2024
120
+
121
+ - add table get api
122
+
123
+ ## 1.0.51 - 27.06.2024
124
+
125
+ - add next-id api
126
+
127
+ ## 1.0.50 - 27.06.2024
128
+
129
+ - refactor search api
130
+
131
+ ## 1.0.49 - 26.06.2024
132
+
133
+ - refactor - npm settings
134
+
135
+ ## 1.0.48 - 26.06.2024
136
+
137
+ - search api no specified table mode support
138
+
139
+ ## 1.0.47 - 25.06.2024
140
+
141
+ - add extra properties support
142
+
143
+ ## 1.0.46 - 24.06.2024
144
+
145
+ - fix data api edit geometry
146
+
147
+ ## 1.0.45 - 19.06.2024
148
+
149
+ - fix data api table template order
150
+
151
+ ## 1.0.44 - 18.06.2024
152
+
153
+ - add extra data support (form DataTable)
154
+
155
+ ## 1.0.43 - 14.06.2024
156
+
157
+ - add settings api, funcs, migration
158
+
159
+ ## 1.0.42 - 12.06.2024
160
+
161
+ - table cardSql support
162
+
163
+ ## 1.0.41 - 12.06.2024
164
+
165
+ - cls to db (crm.cls)
166
+
167
+ ## 1.0.40 - 12.06.2024
168
+
169
+ - fix widget GET API
170
+
171
+ ## 1.0.39 - 29.05.2024
172
+
173
+ - add getFolder func
174
+
175
+ ## 1.0.37 - 23.05.2024
176
+
177
+ - add gallery widget
178
+
179
+ ## 1.0.36 - 22.05.2024
180
+
181
+ - fix filter api array processing
182
+
183
+ ## 1.0.31 - 20.05.2024
184
+
185
+ - widget db structure refactor
186
+
187
+ ## 1.0.30 - 17.05.2024
188
+
189
+ - code optimization
190
+
191
+ ## 1.0.29 - 17.05.2024
192
+
193
+ - widget api post (file)
194
+
195
+ ## 1.0.28 - 14.05.2024
196
+
197
+ - dblist api set
198
+
199
+ ## 1.0.27 - 12.05.2024
200
+
201
+ - code optimization
202
+
203
+ ## 1.0.26 - 09.05.2024
204
+
205
+ - fix getTableSql
206
+
207
+ ## 1.0.25 - 08.05.2024
208
+
209
+ - decorator to hook
210
+
211
+ ## 1.0.24 - 07.05.2024
212
+
213
+ - getTemplate page
214
+
215
+ ## 1.0.23 - 07.05.2024
216
+
217
+ - getTemplate funcs
218
+ - dblist api
219
+
220
+ ## 1.0.22 - 03.05.2024
221
+
222
+ - getFilterSQL funcs
223
+
224
+ ## 1.0.21 - 03.05.2024
225
+
226
+ - fix widget db structure
227
+
228
+ ## 1.0.20 - 03.05.2024
229
+
230
+ - fix filter separator
231
+
232
+ ## 1.0.19 - 02.05.2024
233
+
234
+ - widget plugin
235
+ - notification plugin
236
+
237
+ ## 1.0.9 - 29.04.2024
238
+
239
+ - crud token support
240
+ - security - xss restriction
241
+
242
+ ## 1.0.8 - 29.04.2024
243
+
244
+ - filter fix
245
+
246
+ ## 1.0.7 - 26.04.2024
247
+
248
+ - code optimization
249
+
250
+ ## 1.0.6 - 25.04.2024
251
+
252
+ - code optimization
253
+
254
+ ## 1.0.5 - 24.04.2024
255
+
256
+ - code optimization
257
+
258
+ ## 1.0.4 - 20.04.2024
259
+
260
+ - data api - order
261
+ - suggest api - db support
262
+ - del api fix
263
+
264
+ ## 1.0.3 - 17.04.2024
265
+
266
+ - fix unit test
267
+
268
+ ## 1.0.2 - 14.04.2024
269
+
270
+ - fix redis
271
+
272
+ ## 1.0.1 - 14.04.2024
273
+
274
+ - fix redis
275
+
276
+ ## 1.0.0 - 14.04.2024
277
+
278
+ - crud
279
+ - pg
280
+ - redis
281
+ - table
@@ -1,29 +1,30 @@
1
- import getPG from '../../pg/funcs/getPG.js';
2
-
3
- import getMeta from '../../pg/funcs/getMeta.js';
4
- import logChanges from './utils/logChanges.js';
5
-
6
- export default async function dataUpdate({
7
- table, id, data, pg: pg1, uid,
8
- }) {
9
- if (!data || !table || !id) return null;
10
-
11
- const pg = pg1 || getPG({ name: 'client' });
12
- const { columns, pk } = await getMeta(table);
13
-
14
- const names = columns?.map((el) => el.name);
15
- const filterData = Object.keys(data)
16
- .filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el)));
17
-
18
- const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
19
-
20
- await logChanges({
21
- pg, table, data, id, uid, type: 'UPDATE',
22
- });
23
-
24
- const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
25
- WHERE ${pk} = $1 returning *`;
26
- // console.log(updateQuery, filterValue);
27
- const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
28
- return res;
29
- }
1
+ import getPG from '../../pg/funcs/getPG.js';
2
+
3
+ import getMeta from '../../pg/funcs/getMeta.js';
4
+ import logChanges from './utils/logChanges.js';
5
+
6
+ export default async function dataUpdate({
7
+ table, id, data, pg: pg1, uid,
8
+ }) {
9
+ if (!data || !table || !id) return null;
10
+
11
+ const pg = pg1 || getPG({ name: 'client' });
12
+ const { columns, pk } = await getMeta(table);
13
+
14
+ const names = columns?.map((el) => el.name);
15
+ const filterData = Object.keys(data)
16
+ .filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el)));
17
+
18
+ const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
19
+
20
+ const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
21
+ WHERE ${pk} = $1 returning *`;
22
+ // console.log(updateQuery, filterValue);
23
+ const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
24
+
25
+ await logChanges({
26
+ pg, table, data, id, uid, type: 'UPDATE',
27
+ });
28
+
29
+ return res;
30
+ }
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "@opengis/fastify-table",
3
- "version": "1.0.91",
4
- "type": "module",
5
- "description": "core-plugins",
6
- "main": "index.js",
7
- "scripts": {
8
- "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
9
- "test": "node --test"
10
- },
11
- "dependencies": {
12
- "@opengis/fastify-hb": "^1.1.0",
13
- "@fastify/sensible": "^5.0.0",
14
- "@fastify/url-data": "^5.4.0",
15
- "fastify": "^4.26.1",
16
- "fastify-plugin": "^4.0.0",
17
- "ioredis": "^5.3.2",
18
- "pg": "^8.11.3",
19
- "nodemailer": "^6.5.0"
20
- },
21
- "devDependencies": {
22
- "eslint": "^8.49.0",
23
- "eslint-config-airbnb": "^19.0.4"
24
- },
25
- "author": "Softpro",
26
- "license": "ISC"
1
+ {
2
+ "name": "@opengis/fastify-table",
3
+ "version": "1.0.93",
4
+ "type": "module",
5
+ "description": "core-plugins",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
9
+ "test": "node --test"
10
+ },
11
+ "dependencies": {
12
+ "@opengis/fastify-hb": "^1.1.0",
13
+ "@fastify/sensible": "^5.0.0",
14
+ "@fastify/url-data": "^5.4.0",
15
+ "fastify": "^4.26.1",
16
+ "fastify-plugin": "^4.0.0",
17
+ "ioredis": "^5.3.2",
18
+ "pg": "^8.11.3",
19
+ "nodemailer": "^6.5.0"
20
+ },
21
+ "devDependencies": {
22
+ "eslint": "^8.49.0",
23
+ "eslint-config-airbnb": "^19.0.4"
24
+ },
25
+ "author": "Softpro",
26
+ "license": "ISC"
27
27
  }
@@ -2,7 +2,7 @@ import getSelectMeta from './utils/getSelectMeta.js';
2
2
  import getPG from '../../pg/funcs/getPG.js';
3
3
  import config from '../../config.js';
4
4
  import getTemplate from './utils/getTemplate.js';
5
- import getTableSql from '../funcs/getFilterSQL/util/getTableSql.js';
5
+ // import getTableSql from '../funcs/getFilterSQL/util/getTableSql.js';
6
6
 
7
7
  const limit = 50;
8
8
  const headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Cache-Control': 'no-cache' };
@@ -22,7 +22,7 @@ export default async function suggest(req) {
22
22
  if (table && !pg1.pk[body?.table || table]) {
23
23
  return { headers, status: 400, message: 'param name is invalid: 1' };
24
24
  }
25
- const columnExists = true;
25
+ const columnExists = body?.columns?.find((col) => col?.name === column);
26
26
  if (table && (!column || !columnExists)) {
27
27
  return { headers, status: 400, message: 'param name is invalid: 2' };
28
28
  }
@@ -32,7 +32,7 @@ export default async function suggest(req) {
32
32
  original: `with c(id,text) as (select row_number() over(), ${column} from ${body?.table || table} group by ${column} ) select * from c`,
33
33
  searchQuery: '("text" ilike $1 )',
34
34
  }
35
- : await getSelectMeta({ name: selectName });
35
+ : await getSelectMeta({ name: selectName, nocache: query?.nocache });
36
36
  const pg = meta?.db ? getPG(meta.db) : pg1;
37
37
  if (!meta) return { headers, status: 404, message: 'Not found query select ' };
38
38
  if (query.meta) return meta;
@@ -1,66 +1,66 @@
1
- // import pgClients from '../../../pg/pgClients.js';
2
- import getPG from '../../../pg/funcs/getPG.js';
3
-
4
- import getSelect from './getSelect.js';
5
-
6
- /*
7
- function getTable(table) {
8
- // eslint-disable-next-line class-methods-use-this
9
- const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
10
- .map((el) => el.split(/[ )]/)[0]);
11
- return result?.pop();
12
- } */
13
-
14
- const selectMeta = {};
15
-
16
- export default async function getSelectMeta({ name, pg: pg1 }) {
17
- if (selectMeta[name]) return selectMeta[name];
18
-
19
- const cls = await getSelect(name);
20
-
21
- if (!cls) return null;
22
- if (cls.arr) return cls;
23
- if (!cls.sql) return null;
24
-
25
- const pg = pg1 || getPG({ db: cls.db || 'client' });
26
- const { sql: original } = cls;
27
- const sql = `with c(id,text) as (${original} ) select * from c `;
28
-
29
- /*= == meta table === */
30
- const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
31
- .map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
32
-
33
- const dataOrigin = await pg.query(`${sql} limit 0`);
34
-
35
- const dataOrigin1 = await pg.query(`${original} limit 0`);
36
-
37
- // const table = getTable(original);
38
- const count = cls?.count ?? await pg.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
39
-
40
- // column name
41
- const cols = dataOrigin.fields.map((el) => el.name);
42
- const type = dataOrigin.fields.map((el) => pg.pgType?.[el.dataTypeID] || 'text');
43
-
44
- const searchColumn = cls?.searchColumn || (
45
- dataOrigin.fields.find((el) => el.name === 'search') ? 'search' : dataOrigin.fields[1].name);
46
-
47
- const searchQuery = `(${searchColumn.split(',').map((el) => `"${el}" ilike $1 `).join(' or ')})`;
48
-
49
- const data = {
50
-
51
- type: type.join(','),
52
- cols: cols.join(','),
53
- originalCols: dataOrigin1.fields.map((el) => el.name).join(','),
54
- db: cls.db,
55
- original: original?.includes('where') ? `select * from (${sql})q` : sql,
56
- sql,
57
- count,
58
- searchQuery,
59
- table: tableNew.join(','),
60
- time: new Date().toISOString(),
61
-
62
- };
63
-
64
- selectMeta[name] = data;
65
- return data;
66
- }
1
+ // import pgClients from '../../../pg/pgClients.js';
2
+ import getPG from '../../../pg/funcs/getPG.js';
3
+
4
+ import getSelect from './getSelect.js';
5
+
6
+ /*
7
+ function getTable(table) {
8
+ // eslint-disable-next-line class-methods-use-this
9
+ const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
10
+ .map((el) => el.split(/[ )]/)[0]);
11
+ return result?.pop();
12
+ } */
13
+
14
+ const selectMeta = {};
15
+
16
+ export default async function getSelectMeta({ name, pg: pg1, nocache }) {
17
+ if (selectMeta[name] && !nocache) return selectMeta[name];
18
+
19
+ const cls = await getSelect(name);
20
+
21
+ if (!cls) return null;
22
+ if (cls.arr) return cls;
23
+ if (!cls.sql) return null;
24
+
25
+ const pg = pg1 || getPG({ db: cls.db || 'client' });
26
+ const { sql: original } = cls;
27
+ const sql = `with c(id,text) as (${original} ) select * from c `;
28
+
29
+ /*= == meta table === */
30
+ const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
31
+ .map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
32
+
33
+ const dataOrigin = await pg.query(`${sql} limit 0`);
34
+
35
+ const dataOrigin1 = await pg.query(`${original} limit 0`);
36
+
37
+ // const table = getTable(original);
38
+ const count = cls?.count ?? await pg.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
39
+
40
+ // column name
41
+ const cols = dataOrigin.fields.map((el) => el.name);
42
+ const type = dataOrigin.fields.map((el) => pg.pgType?.[el.dataTypeID] || 'text');
43
+
44
+ const searchColumn = cls?.searchColumn || (
45
+ dataOrigin.fields.find((el) => el.name === 'search') ? 'search' : dataOrigin.fields[1].name);
46
+
47
+ const searchQuery = `(${searchColumn.split(',').map((el) => `"${el}" ilike $1 `).join(' or ')})`;
48
+
49
+ const data = {
50
+
51
+ type: type.join(','),
52
+ cols: cols.join(','),
53
+ originalCols: dataOrigin1.fields.map((el) => el.name).join(','),
54
+ db: cls.db,
55
+ original: original?.includes('where') ? `select * from (${sql})q` : sql,
56
+ sql,
57
+ count,
58
+ searchQuery,
59
+ table: tableNew.join(','),
60
+ time: new Date().toISOString(),
61
+
62
+ };
63
+
64
+ selectMeta[name] = data;
65
+ return data;
66
+ }
@@ -1,28 +1,28 @@
1
- import { readFile } from 'fs/promises';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import config from '../../../config.js';
5
-
6
- const loadTemplate = {};
7
-
8
- export default async function getTemplateDir(type, name) {
9
- if (!type) return null;
10
- if (!name) return null;
11
-
12
- const cwd = process.cwd();
13
- const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
14
-
15
- if (!loadTemplate[type]) {
16
- const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
17
- loadTemplate[type] = typeList;
18
- }
19
-
20
- const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
21
- const ext = fullname ? path.extname(fullname)?.slice(1) : null;
22
- if (!ext) return null;
23
-
24
- const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
25
- const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
26
- if (sql) return { ...data || {}, sql };
27
- return data;
28
- }
1
+ import { readFile } from 'fs/promises';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import config from '../../../config.js';
5
+
6
+ const loadTemplate = {};
7
+
8
+ export default async function getTemplateDir(type, name) {
9
+ if (!type) return null;
10
+ if (!name) return null;
11
+
12
+ const cwd = process.cwd();
13
+ const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
14
+
15
+ if (!loadTemplate[type]) {
16
+ const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
17
+ loadTemplate[type] = typeList;
18
+ }
19
+
20
+ const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
21
+ const ext = fullname ? path.extname(fullname)?.slice(1) : null;
22
+ if (!ext) return null;
23
+
24
+ const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
25
+ const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
26
+ if (sql) return { sql };
27
+ return data;
28
+ }
@@ -18,8 +18,12 @@ async function getFilterSQL({
18
18
 
19
19
  const body = await getTemplate('table', table);
20
20
 
21
+ const sqlList = body?.sql?.length
22
+ ? body?.sql?.filter((el) => !el.disabled && el?.sql?.replace)
23
+ .map((el) => ` left join lateral (${el.filter ? el.sql.replace(/limit 1/ig, '') : el.sql}) as ${el.name} on 1=1 `).join(' ')
24
+ : '';
21
25
  const fieldQuery = config.allTemplates?.table?.[table] ? `${config.allTemplates?.table?.[table]} limit 0`
22
- : `select * from ${body?.table || table} limit 0`;
26
+ : `select * from ${body?.table || table} ${sqlList ? ` t ${sqlList}` : ''} where 1=1 limit 0`;
23
27
  const { fields = [] } = await pg.query(fieldQuery);
24
28
 
25
29
  const { fields: fieldsModel } = pg.pk[body?.table] ? await pg.query(`select * from ${body.table} limit 0`) : {};