prostgles-server 2.0.119 → 2.0.123
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/dist/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder.js +13 -12
- package/dist/DboBuilder.js.map +1 -1
- package/dist/Filtering.d.ts.map +1 -1
- package/dist/Filtering.js +11 -3
- package/dist/Filtering.js.map +1 -1
- package/dist/Prostgles.js +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/QueryBuilder.d.ts +2 -1
- package/dist/QueryBuilder.d.ts.map +1 -1
- package/dist/QueryBuilder.js +12 -0
- package/dist/QueryBuilder.js.map +1 -1
- package/lib/DboBuilder.ts +13 -12
- package/lib/Filtering.ts +11 -4
- package/lib/Prostgles.ts +1 -1
- package/lib/QueryBuilder.ts +14 -1
- package/package.json +1 -1
- package/tests/client/PID.txt +1 -1
- package/tests/isomorphic_queries.js +10 -0
- package/tests/isomorphic_queries.ts +11 -0
- package/tests/server/media/{13b4236b-5aea-4d2e-bbad-2db2e2805bed.txt → 03197694-815a-4269-9f1e-59471c22d67b.txt} +0 -0
- package/tests/server/media/{9ac6b13b-ae7b-4fd0-a2b1-306475553d70.txt → 192b5d4b-7823-423c-94d8-4a6e427aa839.txt} +0 -0
- package/tests/server/media/{dc98a9ca-317e-472b-9fd9-9430c74bb574.txt → cabaa296-a778-41c2-8540-c665365d3137.txt} +0 -0
- package/tests/server/media/{dfcda106-8e08-476a-8afb-5a48f6952432.txt → d2058409-f621-4f8a-bdb1-51b1a6bc35e0.txt} +0 -0
- package/tests/server/package-lock.json +1 -1
package/lib/Filtering.ts
CHANGED
|
@@ -40,7 +40,7 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
|
|
|
40
40
|
// parseExistsFilter()
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
let selItem;
|
|
43
|
+
let selItem: SelectItem | undefined;
|
|
44
44
|
if(select) selItem = select.find(s => fKey === s.alias);
|
|
45
45
|
let rightF: FilterDataType = _f[fKey];
|
|
46
46
|
|
|
@@ -191,6 +191,11 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
|
|
|
191
191
|
}
|
|
192
192
|
// console.log({ fOpType, fVal, sOpType })
|
|
193
193
|
|
|
194
|
+
/** JSON cannot be compared so we'll cast it to TEXT */
|
|
195
|
+
if(selItem?.column_udt_type === "json" || ["$ilike", "$like"].includes(fOpType)){
|
|
196
|
+
leftQ += "::TEXT "
|
|
197
|
+
}
|
|
198
|
+
|
|
194
199
|
/** st_makeenvelope */
|
|
195
200
|
if(GeomFilterKeys.includes(fOpType) && sOpType && GeomFilter_Funcs.includes(sOpType)){
|
|
196
201
|
/** If leftQ is geography then this err can happen: 'Antipodal (180 degrees long) edge detected!' */
|
|
@@ -218,11 +223,13 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
|
|
|
218
223
|
return leftQ + " <= " + parseRightVal(fVal);
|
|
219
224
|
|
|
220
225
|
} else if(["$in"].includes(fOpType)){
|
|
226
|
+
if(!fVal?.length) throw "$in filter array is empty";
|
|
221
227
|
let res = leftQ + " IN " + parseRightVal(fVal, "csv");
|
|
222
228
|
if(fVal.includes(null)) res += ` OR ${leftQ} IS NULL `
|
|
223
229
|
return res;
|
|
224
230
|
|
|
225
231
|
} else if(["$nin"].includes(fOpType)){
|
|
232
|
+
if(!fVal?.length) throw "$nin filter array is empty";
|
|
226
233
|
let res = leftQ + " NOT IN " + parseRightVal(fVal, "csv");
|
|
227
234
|
if(fVal.includes(null)) res += ` AND ${leftQ} IS NOT NULL `
|
|
228
235
|
return res;
|
|
@@ -234,10 +241,10 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
|
|
|
234
241
|
return leftQ + " BETWEEN " + asValue(fVal[0]) + " AND " + asValue(fVal[1]);
|
|
235
242
|
|
|
236
243
|
} else if(["$ilike"].includes(fOpType)){
|
|
237
|
-
return leftQ + "
|
|
244
|
+
return leftQ + " ILIKE " + asValue(fVal);
|
|
238
245
|
|
|
239
246
|
} else if(["$like"].includes(fOpType)){
|
|
240
|
-
return leftQ + "
|
|
247
|
+
return leftQ + " LIKE " + asValue(fVal);
|
|
241
248
|
|
|
242
249
|
/* MAYBE TEXT OR MAYBE ARRAY */
|
|
243
250
|
} else if(["@>", "<@", "$contains", "$containedBy", "&&", "@@"].includes(fOpType)){
|
|
@@ -253,7 +260,7 @@ export const parseFilterItem = (args: ParseFilterItemArgs): string => {
|
|
|
253
260
|
/* FTSQuery */
|
|
254
261
|
} else if(["@@"].includes(fOpType) && TextFilter_FullTextSearchFilterKeys.includes(sOpType)) {
|
|
255
262
|
let lq = `to_tsvector(${leftQ}::text)`;
|
|
256
|
-
if(selItem && selItem.
|
|
263
|
+
if(selItem && selItem.columnPGDataType === "tsvector") lq = leftQ;
|
|
257
264
|
|
|
258
265
|
let res = `${lq} ${operand} ` + `${sOpType}${parseRightVal(sVal, "csv")}`;
|
|
259
266
|
|
package/lib/Prostgles.ts
CHANGED
|
@@ -544,7 +544,7 @@ export class Prostgles<DBO = DbHandler> {
|
|
|
544
544
|
if(watchSchema && this.loaded){
|
|
545
545
|
console.log("Schema changed");
|
|
546
546
|
const { query } = event;
|
|
547
|
-
if(query && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)){
|
|
547
|
+
if(typeof query === "string" && query.includes(PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID)){
|
|
548
548
|
console.log("Schema change event excluded from triggers due to EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID");
|
|
549
549
|
return;
|
|
550
550
|
}
|
package/lib/QueryBuilder.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { pgp, Filter, LocalParams, isPlainObject, TableHandler, ViewHandler, postgresToTsType } from "./DboBuilder";
|
|
8
8
|
import { TableRule, flat } from "./Prostgles";
|
|
9
|
-
import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, TS_PG_Types, ColumnInfo } from "prostgles-types";
|
|
9
|
+
import { SelectParamsBasic as SelectParams, isEmpty, FieldFilter, asName, TextFilter_FullTextSearchFilterKeys, TS_PG_Types, ColumnInfo, PG_COLUMN_UDT_DATA_TYPE } from "prostgles-types";
|
|
10
10
|
import { get } from "./utils";
|
|
11
11
|
|
|
12
12
|
|
|
@@ -15,6 +15,7 @@ export type SelectItem = {
|
|
|
15
15
|
getFields: (args?: any[]) => string[] | "*";
|
|
16
16
|
getQuery: (tableAlias?: string) => string;
|
|
17
17
|
columnPGDataType?: string;
|
|
18
|
+
column_udt_type?: PG_COLUMN_UDT_DATA_TYPE;
|
|
18
19
|
// columnName?: string; /* Must only exist if type "column" ... dissalow aliased columns? */
|
|
19
20
|
alias: string;
|
|
20
21
|
selected: boolean;
|
|
@@ -422,6 +423,17 @@ export const FUNCTIONS: FunctionSpec[] = [
|
|
|
422
423
|
return pgp.as.format("LEFT(" + asNameAlias(args[0], tableAlias) + ", $1)", [args[1]]);
|
|
423
424
|
}
|
|
424
425
|
},
|
|
426
|
+
{
|
|
427
|
+
name: "$unnest_words",
|
|
428
|
+
description: ` :[column_name, number] -> substring`,
|
|
429
|
+
type: "function",
|
|
430
|
+
numArgs: 1,
|
|
431
|
+
singleColArg: true,
|
|
432
|
+
getFields: (args: any[]) => [args[0]],
|
|
433
|
+
getQuery: ({ allowedFields, args, tableAlias }) => {
|
|
434
|
+
return pgp.as.format("unnest(string_to_array(" + asNameAlias(args[0], tableAlias) + "::TEXT , ' '))");//, [args[1]]
|
|
435
|
+
}
|
|
436
|
+
},
|
|
425
437
|
{
|
|
426
438
|
name: "$right",
|
|
427
439
|
description: ` :[column_name, number] -> substring`,
|
|
@@ -945,6 +957,7 @@ export class SelectItemBuilder {
|
|
|
945
957
|
this.addItem({
|
|
946
958
|
type: "column",
|
|
947
959
|
columnPGDataType: colDef?.data_type,
|
|
960
|
+
column_udt_type: colDef?.udt_name,
|
|
948
961
|
alias,
|
|
949
962
|
getQuery: () => asName(fieldName),
|
|
950
963
|
getFields: () => [fieldName],
|
package/package.json
CHANGED
package/tests/client/PID.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4994
|
|
@@ -174,6 +174,16 @@ async function isomorphic(db) {
|
|
|
174
174
|
}
|
|
175
175
|
]);
|
|
176
176
|
});
|
|
177
|
+
await tryRun("$unnest_words", async () => {
|
|
178
|
+
const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
|
|
179
|
+
console.trace(res);
|
|
180
|
+
assert_1.strict.deepStrictEqual(res, [
|
|
181
|
+
'abc9',
|
|
182
|
+
'abc1',
|
|
183
|
+
'abc81',
|
|
184
|
+
'here'
|
|
185
|
+
]);
|
|
186
|
+
});
|
|
177
187
|
/**
|
|
178
188
|
* Group by/Distinct
|
|
179
189
|
*/
|
|
@@ -172,6 +172,17 @@ export default async function isomorphic(db: Partial<DbHandler> | Partial<DBHand
|
|
|
172
172
|
);
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
+
await tryRun("$unnest_words", async () => {
|
|
176
|
+
const res = await db.various.find({}, { returnType: "values", select: { name: "$unnest_words" } });
|
|
177
|
+
console.trace(res)
|
|
178
|
+
assert.deepStrictEqual( res, [
|
|
179
|
+
'abc9',
|
|
180
|
+
'abc1',
|
|
181
|
+
'abc81',
|
|
182
|
+
'here'
|
|
183
|
+
]);
|
|
184
|
+
})
|
|
185
|
+
|
|
175
186
|
/**
|
|
176
187
|
* Group by/Distinct
|
|
177
188
|
*/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|