@opengis/fastify-table 1.2.72 → 1.2.73
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
|
@@ -128,7 +128,7 @@ export default async function getFilterSQL({
|
|
|
128
128
|
|
|
129
129
|
// table
|
|
130
130
|
|
|
131
|
-
const obj = {
|
|
131
|
+
const obj = { body, extraSqlColumns, table, q };
|
|
132
132
|
const optimizedSQL = `select * from ${getOptimizedQuery(obj)} `;
|
|
133
133
|
const tableCount = getOptimizedQuery(obj, true);
|
|
134
134
|
|
|
@@ -71,7 +71,7 @@ function formatValue({
|
|
|
71
71
|
if (!name || !value || !fieldType) return {};
|
|
72
72
|
|
|
73
73
|
// Date filter
|
|
74
|
-
if (
|
|
74
|
+
if (['date', 'datepicker'].includes(filterType) /* && dateTypeList.includes(fieldType) */) {
|
|
75
75
|
const [min, max] = getDates(value, name);
|
|
76
76
|
|
|
77
77
|
// check date is valid
|
|
@@ -147,8 +147,22 @@ function formatValue({
|
|
|
147
147
|
const matchMulti = value?.indexOf(',') !== -1 ? `= any('{${value}}'::text[])` : null;
|
|
148
148
|
const match = matchNull || matchBoolean || matchMulti || (operator === '=' ? `='${value}'` : `ilike '%${value}%'`);
|
|
149
149
|
|
|
150
|
+
const formatType = {
|
|
151
|
+
float8: 'numeric',
|
|
152
|
+
numeric: 'numeric',
|
|
153
|
+
int4: 'numeric',
|
|
154
|
+
integer: 'integer',
|
|
155
|
+
int8: 'numeric',
|
|
156
|
+
"double precision": 'double precision',
|
|
157
|
+
varchar: 'text',
|
|
158
|
+
"character varying": 'character varying',
|
|
159
|
+
bool: 'boolean',
|
|
160
|
+
boolean: 'boolean',
|
|
161
|
+
geometry: 'geom',
|
|
162
|
+
}[fieldType] || 'text';
|
|
163
|
+
|
|
150
164
|
/* select query - from admin.cls / filter options */
|
|
151
|
-
if (['check', 'autocomplete', 'text',
|
|
165
|
+
if (['check', 'autocomplete', 'text', 'tags', 'avatar', 'radio'].includes(filterType)) {
|
|
152
166
|
|
|
153
167
|
// extra table, example: crm.extra_data
|
|
154
168
|
if (extra?.table && pk) {
|
|
@@ -162,7 +176,7 @@ function formatValue({
|
|
|
162
176
|
// default
|
|
163
177
|
const query = select && filterType === 'text'
|
|
164
178
|
? `${name}::text in ( ( with q(id,name) as (${select}) select id from q where name::text ${match}) )` // filter with cls
|
|
165
|
-
: `${name}
|
|
179
|
+
: `${name}::${formatType} ${match}`; // simple filter
|
|
166
180
|
return { op: operator, query };
|
|
167
181
|
}
|
|
168
182
|
|
|
@@ -178,15 +192,6 @@ function formatValue({
|
|
|
178
192
|
return { op: '=', query };
|
|
179
193
|
}
|
|
180
194
|
|
|
181
|
-
const formatType = {
|
|
182
|
-
float8: 'numeric',
|
|
183
|
-
int4: 'numeric',
|
|
184
|
-
int8: 'numeric',
|
|
185
|
-
varchar: 'text',
|
|
186
|
-
bool: 'boolean',
|
|
187
|
-
geometry: 'geom',
|
|
188
|
-
}[fieldType] || 'text';
|
|
189
|
-
|
|
190
195
|
// sql column?
|
|
191
196
|
if (optimize && optimize.name !== optimize.pk) {
|
|
192
197
|
const val = filterType === 'text' ? `ilike '%${value}%'` : `= any('{${value}}')`;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export default function getOptimizedQuery({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export default function getOptimizedQuery({ body, extraSqlColumns, table, q }, count) {
|
|
2
|
+
const order = body?.orderby || body?.order ? `order by ${body?.orderby || body?.order}` : '';
|
|
3
|
+
|
|
4
|
+
const tableName = body?.table || body?.model || table;
|
|
5
|
+
|
|
6
|
+
const sqlList = body?.sql?.filter((el) => !el.disabled && el?.sql?.replace && (count ? el.count !== false : true))
|
|
7
|
+
.map((el) => ` left join lateral (${el.filter ? el.sql.replace(/limit 1/ig, '') : el.sql}) as ${el.name} on 1=1 `).join(' ');
|
|
8
|
+
|
|
9
|
+
return `(select * ${extraSqlColumns || ''} from ${tableName} t ${sqlList ? ` ${sqlList}` : ''} where 1=1 and ${q?.replace('q.', 't.') || '1=1'} ${order})q`;
|
|
6
10
|
}
|