dbgate-sqltree 7.1.0 → 7.1.2

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.
@@ -3,6 +3,52 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dumpSqlCondition = void 0;
4
4
  const dumpSqlExpression_1 = require("./dumpSqlExpression");
5
5
  const dumpSqlCommand_1 = require("./dumpSqlCommand");
6
+ function dumpLikeAsFunctionCondition(dmp, condition) {
7
+ // For DynamoDB: contains() works only on string attributes
8
+ // For numeric values, search both as number and as string
9
+ const likeExpr = condition.right;
10
+ let isNumericValue = false;
11
+ let numericStringValue = '';
12
+ if (likeExpr.exprType === 'value' && typeof likeExpr.value === 'string') {
13
+ const cleanedStr = (likeExpr.value || '').replace(/%/g, '').trim();
14
+ // Only match valid decimal numbers (not Infinity, NaN, etc.)
15
+ isNumericValue = /^-?\d+(\.\d+)?$/.test(cleanedStr);
16
+ numericStringValue = cleanedStr;
17
+ }
18
+ else if (likeExpr.exprType === 'value' && typeof likeExpr.value === 'number') {
19
+ isNumericValue = Number.isFinite(likeExpr.value);
20
+ numericStringValue = String(likeExpr.value);
21
+ }
22
+ if (isNumericValue) {
23
+ // For numeric values: (column = value OR contains(column, 'value'))
24
+ dmp.putRaw('(');
25
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.left);
26
+ dmp.putRaw(' = ');
27
+ dmp.put('%s', numericStringValue);
28
+ dmp.putRaw(' OR contains(');
29
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.left);
30
+ dmp.putRaw(', ');
31
+ dmp.put('%v', numericStringValue);
32
+ dmp.putRaw('))');
33
+ }
34
+ else {
35
+ // String value: contains(column, value)
36
+ dmp.putRaw('contains(');
37
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.left);
38
+ dmp.putRaw(', ');
39
+ if (likeExpr.exprType === 'value') {
40
+ let cleanValue = likeExpr.value;
41
+ if (typeof cleanValue === 'string') {
42
+ cleanValue = cleanValue.replace(/%/g, '');
43
+ }
44
+ dmp.put('%v', cleanValue);
45
+ }
46
+ else {
47
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, likeExpr);
48
+ }
49
+ dmp.putRaw(')');
50
+ }
51
+ }
6
52
  function dumpSqlCondition(dmp, condition) {
7
53
  var _a, _b, _c, _d, _e, _f;
8
54
  switch (condition.conditionType) {
@@ -54,9 +100,14 @@ function dumpSqlCondition(dmp, condition) {
54
100
  });
55
101
  break;
56
102
  case 'like':
57
- (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.left);
58
- dmp.put(dmp.dialect.ilike ? ' ^ilike ' : ' ^like ');
59
- (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.right);
103
+ if (dmp.dialect.likeAsFunction) {
104
+ dumpLikeAsFunctionCondition(dmp, condition);
105
+ }
106
+ else {
107
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.left);
108
+ dmp.put(dmp.dialect.ilike ? ' ^ilike ' : ' ^like ');
109
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.right);
110
+ }
60
111
  break;
61
112
  case 'notLike':
62
113
  (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.left);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.1.0",
2
+ "version": "7.1.2",
3
3
  "name": "dbgate-sqltree",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "devDependencies": {
29
29
  "@types/node": "^13.7.0",
30
- "dbgate-types": "^7.1.0",
30
+ "dbgate-types": "^7.1.2",
31
31
  "typescript": "^4.4.3"
32
32
  },
33
33
  "dependencies": {