@sqb/postgres-dialect 4.0.1-beta.43 → 4.0.1-beta.48

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.
@@ -32,35 +32,42 @@ class PostgresSerializer {
32
32
  return out;
33
33
  }
34
34
  _serializeComparison(ctx, o, defFn) {
35
- if (typeof o.right === 'string') {
36
- if (o.operatorType === 'in' && o.right.toLowerCase() === 'null')
37
- return defFn(ctx, { ...o, symbol: '=' });
38
- if (o.right.startsWith('(')) {
35
+ if (o.right) {
36
+ if (o.right.expression.toLowerCase() === 'null') {
39
37
  if (o.operatorType === 'eq')
40
- return defFn(ctx, { ...o, symbol: 'in' });
38
+ return defFn(ctx, { ...o, operatorType: builder_1.OperatorType.is, symbol: 'is' });
41
39
  if (o.operatorType === 'ne')
42
- return defFn(ctx, { ...o, symbol: 'not in' });
40
+ return defFn(ctx, { ...o, operatorType: builder_1.OperatorType.isNot, symbol: 'is not' });
43
41
  }
44
- if (o.right.substring(0, 1) === '$') {
45
- if (o.paramValue == null) {
46
- const symbol = o.operatorType === 'eq' ? 'is' :
47
- (o.operatorType === 'ne' ? 'is not' : o.symbol);
48
- return defFn(ctx, { ...o, symbol, right: 'null' });
49
- }
50
- if (o.isArray) {
51
- if (Array.isArray(o.paramValue))
52
- return defFn(ctx, { ...o, symbol: '&&', right: 'ANY(' + o.right + ')' });
42
+ if (o.left.isParam && o.left.isArray && o.left.value != null && !Array.isArray(o.left.value))
43
+ o.left.value = [o.left.value];
44
+ if (o.right.isParam && o.right.isArray && o.right.value != null && !Array.isArray(o.right.value))
45
+ o.right.value = [o.right.value];
46
+ if ((o.operatorType === 'in' || o.operatorType === 'notIn')) {
47
+ if (o.left.isArray && !o.right.isArray && o.right.isParam) {
48
+ const left = o.left;
49
+ const right = o.right;
50
+ left.expression = 'ANY(' + left.expression + ')';
53
51
  return defFn(ctx, {
54
52
  ...o,
55
- symbol: '=',
56
- left: o.right,
57
- right: 'ANY(' + o.left + ')'
53
+ operatorType: builder_1.OperatorType.eq,
54
+ symbol: o.operatorType === 'notIn' ? '!=' : '=',
55
+ left: right,
56
+ right: left
58
57
  });
59
58
  }
60
- const isInOp = (o.operatorType === 'in' || o.operatorType === 'notIn');
61
- if (Array.isArray(o.paramValue) || isInOp) {
62
- o.symbol = o.operatorType === 'notIn' ? '!=' : '=';
63
- o.right = 'ANY(' + o.right + ')';
59
+ if (o.left.isArray && o.right.isArray) {
60
+ if (o.operatorType === 'notIn')
61
+ o.left.expression = 'not ' + o.left.expression;
62
+ return defFn(ctx, { ...o, symbol: '&&' });
63
+ }
64
+ if (!o.left.isArray && o.right.isArray && o.right.isParam) {
65
+ o.right.expression = 'ANY(' + o.right.expression + ')';
66
+ return defFn(ctx, {
67
+ ...o,
68
+ operatorType: builder_1.OperatorType.eq,
69
+ symbol: o.operatorType === 'notIn' ? '!=' : '='
70
+ });
64
71
  }
65
72
  }
66
73
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/postgres-dialect",
3
3
  "description": "SQB serialization extension for PostgreSQL database",
4
- "version": "4.0.1-beta.43",
4
+ "version": "4.0.1-beta.48",
5
5
  "author": "Panates Ltd.",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"