pqb 0.37.0 → 0.38.0
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/index.d.ts +13 -2
- package/dist/index.js +26 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1501,6 +1501,9 @@ interface JsonPathQuery {
|
|
|
1501
1501
|
*
|
|
1502
1502
|
* Optionally takes `vars` and `silent` parameters, see [Postgres docs](https://www.postgresql.org/docs/current/functions-json.html) for details.
|
|
1503
1503
|
*
|
|
1504
|
+
* The `type` option sets the output type when selecting a value,
|
|
1505
|
+
* also it makes specific operators available in `where`, so that you can apply `contains` if the type is text, and `gt` if the type is numeric.
|
|
1506
|
+
*
|
|
1504
1507
|
* ```ts
|
|
1505
1508
|
* // query a single value from a JSON data,
|
|
1506
1509
|
* // because of the provided type, string JSON value will be parsed to a Date object.
|
|
@@ -1531,6 +1534,14 @@ interface JsonPathQuery {
|
|
|
1531
1534
|
* name: (q) =>
|
|
1532
1535
|
* q.get('data').jsonPathQueryFirst('$.name', { type: (t) => t.string() }),
|
|
1533
1536
|
* });
|
|
1537
|
+
*
|
|
1538
|
+
* // filtering records to contain 'word' in the json property "name"
|
|
1539
|
+
* await db.table.where((q) =>
|
|
1540
|
+
* q
|
|
1541
|
+
* .get('data')
|
|
1542
|
+
* .jsonPathQueryFirst('$.name', { type: (t) => t.string() })
|
|
1543
|
+
* .contains('word'),
|
|
1544
|
+
* );
|
|
1534
1545
|
* ```
|
|
1535
1546
|
*
|
|
1536
1547
|
* @param path - JSON path
|
|
@@ -1813,9 +1824,9 @@ type WhereArg<T extends PickQueryMetaRelations> = {
|
|
|
1813
1824
|
* ```
|
|
1814
1825
|
*/
|
|
1815
1826
|
type WhereQueryBuilder<T extends PickQueryRelations> = EmptyObject extends T['relations'] ? {
|
|
1816
|
-
[K in keyof T]: K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' ? T[K] : never;
|
|
1827
|
+
[K in keyof T]: K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' | 'columnTypes' ? T[K] : never;
|
|
1817
1828
|
} : {
|
|
1818
|
-
[K in keyof T]: K extends keyof T['relations'] ? T['relations'][K] : K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' ? T[K] : never;
|
|
1829
|
+
[K in keyof T]: K extends keyof T['relations'] ? T['relations'][K] : K extends keyof QueryBase | keyof Where | keyof ExpressionMethods | 'sql' | 'get' | 'ref' | 'columnTypes' ? T[K] : never;
|
|
1819
1830
|
};
|
|
1820
1831
|
type WhereArgs<T extends PickQueryMetaRelations> = WhereArg<T>[];
|
|
1821
1832
|
type WhereNotArgs<T extends PickQueryMetaRelations> = [WhereArg<T>];
|
package/dist/index.js
CHANGED
|
@@ -935,6 +935,22 @@ const quoteValue$1 = (arg, ctx, quotedAs, jsonArray) => {
|
|
|
935
935
|
}
|
|
936
936
|
return orchidCore.addValue(ctx.values, arg);
|
|
937
937
|
};
|
|
938
|
+
const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
|
|
939
|
+
if (arg && typeof arg === "object") {
|
|
940
|
+
if (!jsonArray && Array.isArray(arg)) {
|
|
941
|
+
return `(${arg.map((value) => orchidCore.addValue(ctx.values, value)).join(", ")})`;
|
|
942
|
+
}
|
|
943
|
+
if (orchidCore.isExpression(arg)) {
|
|
944
|
+
return arg.toSQL(ctx, quotedAs);
|
|
945
|
+
}
|
|
946
|
+
if ("toSQL" in arg) {
|
|
947
|
+
return `replace(replace((${getSqlText(
|
|
948
|
+
arg.toSQL({ values: ctx.values })
|
|
949
|
+
)}), '%', '\\\\%'), '_', '\\\\_')`;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return orchidCore.addValue(ctx.values, arg.replace(/[%_]/g, "\\$&"));
|
|
953
|
+
};
|
|
938
954
|
const base = {
|
|
939
955
|
equals: make(
|
|
940
956
|
(key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue$1(value, ctx, quotedAs)}`
|
|
@@ -980,22 +996,22 @@ const numeric = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
980
996
|
});
|
|
981
997
|
const text = __spreadProps$9(__spreadValues$j({}, base), {
|
|
982
998
|
contains: make(
|
|
983
|
-
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${
|
|
999
|
+
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
984
1000
|
),
|
|
985
1001
|
containsSensitive: make(
|
|
986
|
-
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${
|
|
1002
|
+
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
987
1003
|
),
|
|
988
1004
|
startsWith: make(
|
|
989
|
-
(key, value, ctx, quotedAs) => `${key} ILIKE ${
|
|
1005
|
+
(key, value, ctx, quotedAs) => `${key} ILIKE ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
990
1006
|
),
|
|
991
1007
|
startsWithSensitive: make(
|
|
992
|
-
(key, value, ctx, quotedAs) => `${key} LIKE ${
|
|
1008
|
+
(key, value, ctx, quotedAs) => `${key} LIKE ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
993
1009
|
),
|
|
994
1010
|
endsWith: make(
|
|
995
|
-
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${
|
|
1011
|
+
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
|
|
996
1012
|
),
|
|
997
1013
|
endsWithSensitive: make(
|
|
998
|
-
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${
|
|
1014
|
+
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
|
|
999
1015
|
)
|
|
1000
1016
|
});
|
|
1001
1017
|
const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
@@ -1009,9 +1025,10 @@ const json = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
1009
1025
|
this.q.parsers[orchidCore.getValueKey] = void 0;
|
|
1010
1026
|
}
|
|
1011
1027
|
if (options == null ? void 0 : options.type) {
|
|
1012
|
-
const
|
|
1013
|
-
if (
|
|
1014
|
-
((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[orchidCore.getValueKey] =
|
|
1028
|
+
const type = options.type(this.columnTypes);
|
|
1029
|
+
if (type.parseFn)
|
|
1030
|
+
((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[orchidCore.getValueKey] = type.parseFn;
|
|
1031
|
+
return setQueryOperators(this, type.operators);
|
|
1015
1032
|
}
|
|
1016
1033
|
return this;
|
|
1017
1034
|
},
|