pqb 0.37.0 → 0.38.1

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, addValue, isExpression, joinTruthy, numberDataToCode, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, logColors, emptyArray, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, snakeCaseKey } from 'orchid-core';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy, numberDataToCode, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, logColors, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, snakeCaseKey } from 'orchid-core';
2
2
  import pg from 'pg';
3
3
  import { inspect } from 'node:util';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -933,6 +933,22 @@ const quoteValue$1 = (arg, ctx, quotedAs, jsonArray) => {
933
933
  }
934
934
  return addValue(ctx.values, arg);
935
935
  };
936
+ const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
937
+ if (arg && typeof arg === "object") {
938
+ if (!jsonArray && Array.isArray(arg)) {
939
+ return `(${arg.map((value) => addValue(ctx.values, value)).join(", ")})`;
940
+ }
941
+ if (isExpression(arg)) {
942
+ return arg.toSQL(ctx, quotedAs);
943
+ }
944
+ if ("toSQL" in arg) {
945
+ return `replace(replace((${getSqlText(
946
+ arg.toSQL({ values: ctx.values })
947
+ )}), '%', '\\\\%'), '_', '\\\\_')`;
948
+ }
949
+ }
950
+ return addValue(ctx.values, arg.replace(/[%_]/g, "\\$&"));
951
+ };
936
952
  const base = {
937
953
  equals: make(
938
954
  (key, value, ctx, quotedAs) => value === null ? `${key} IS NULL` : `${key} = ${quoteValue$1(value, ctx, quotedAs)}`
@@ -978,22 +994,22 @@ const numeric = __spreadProps$9(__spreadValues$j({}, base), {
978
994
  });
979
995
  const text = __spreadProps$9(__spreadValues$j({}, base), {
980
996
  contains: make(
981
- (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteValue$1(value, ctx, quotedAs)} || '%'`
997
+ (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
982
998
  ),
983
999
  containsSensitive: make(
984
- (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteValue$1(value, ctx, quotedAs)} || '%'`
1000
+ (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
985
1001
  ),
986
1002
  startsWith: make(
987
- (key, value, ctx, quotedAs) => `${key} ILIKE ${quoteValue$1(value, ctx, quotedAs)} || '%'`
1003
+ (key, value, ctx, quotedAs) => `${key} ILIKE ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
988
1004
  ),
989
1005
  startsWithSensitive: make(
990
- (key, value, ctx, quotedAs) => `${key} LIKE ${quoteValue$1(value, ctx, quotedAs)} || '%'`
1006
+ (key, value, ctx, quotedAs) => `${key} LIKE ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
991
1007
  ),
992
1008
  endsWith: make(
993
- (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteValue$1(value, ctx, quotedAs)}`
1009
+ (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
994
1010
  ),
995
1011
  endsWithSensitive: make(
996
- (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteValue$1(value, ctx, quotedAs)}`
1012
+ (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
997
1013
  )
998
1014
  });
999
1015
  const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
@@ -1002,14 +1018,21 @@ const json = __spreadProps$9(__spreadValues$j({}, base), {
1002
1018
  jsonPathQueryFirst: Object.assign(
1003
1019
  function(path, options) {
1004
1020
  var _a, _b, _c, _d, _e;
1005
- ((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(jsonPathQueryOp, [path, options]);
1021
+ const chain = (_b = (_a = this.q).chain) != null ? _b : _a.chain = [];
1022
+ chain.push(jsonPathQueryOp, [path, options]);
1006
1023
  if ((_c = this.q.parsers) == null ? void 0 : _c[getValueKey]) {
1007
1024
  this.q.parsers[getValueKey] = void 0;
1008
1025
  }
1009
1026
  if (options == null ? void 0 : options.type) {
1010
- const parse = options.type(this.columnTypes).parseFn;
1011
- if (parse)
1012
- ((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[getValueKey] = parse;
1027
+ const type = options.type(this.columnTypes);
1028
+ if (type.parseFn)
1029
+ ((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[getValueKey] = type.parseFn;
1030
+ chain.push = (...args) => {
1031
+ chain.push = Array.prototype.push;
1032
+ chain.push((s) => `${s}::${type.dataType}`, emptyArray);
1033
+ return chain.push(...args);
1034
+ };
1035
+ return setQueryOperators(this, type.operators);
1013
1036
  }
1014
1037
  return this;
1015
1038
  },