@sqb/postgres-dialect 4.0.1-beta.9 → 4.0.6

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.
@@ -18,7 +18,7 @@ class PostgresSerializer {
18
18
  case builder_1.SerializationType.COMPARISON_EXPRESSION:
19
19
  return this._serializeComparison(ctx, o, defFn);
20
20
  case builder_1.SerializationType.EXTERNAL_PARAMETER:
21
- return this._serializeParameter(ctx, o);
21
+ return this._serializeParameter(ctx, o, defFn);
22
22
  }
23
23
  }
24
24
  _serializeSelect(ctx, o, defFn) {
@@ -32,40 +32,51 @@ 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
- o.symbol = '=';
38
- }
39
- else if (o.right.startsWith('(')) {
35
+ if (o.right) {
36
+ if (o.right.expression.toLowerCase() === 'null') {
40
37
  if (o.operatorType === 'eq')
41
- o.symbol = 'in';
38
+ return defFn(ctx, { ...o, operatorType: builder_1.OperatorType.is, symbol: 'is' });
42
39
  if (o.operatorType === 'ne')
43
- o.symbol = 'not in';
40
+ return defFn(ctx, { ...o, operatorType: builder_1.OperatorType.isNot, symbol: 'is not' });
44
41
  }
45
- else {
46
- if (o.right.substring(0, 1) === '$') {
47
- if (o.operatorType === 'in') {
48
- o.symbol = '=';
49
- o.right = 'ANY(' + o.right + ')';
50
- }
51
- if (o.operatorType === 'notIn') {
52
- o.symbol = '!=';
53
- o.right = 'ANY(' + o.right + ')';
54
- }
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 + ')';
51
+ return defFn(ctx, {
52
+ ...o,
53
+ operatorType: builder_1.OperatorType.eq,
54
+ symbol: o.operatorType === 'notIn' ? '!=' : '=',
55
+ left: right,
56
+ right: left
57
+ });
58
+ }
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
+ });
55
71
  }
56
72
  }
57
73
  }
58
74
  return defFn(ctx, o);
59
75
  }
60
- _serializeParameter(ctx, o) {
61
- let prmValue = ctx.params && ctx.params[o.name];
62
- if (prmValue === undefined)
63
- return 'null';
64
- if (o.isArray && !Array.isArray(prmValue))
65
- prmValue = [prmValue];
66
- ctx.queryParams = ctx.queryParams || [];
67
- ctx.queryParams.push(prmValue);
68
- return '$' + ctx.queryParams.length;
76
+ _serializeParameter(ctx, o, defFn) {
77
+ ctx.preparedParams = ctx.preparedParams || [];
78
+ defFn(ctx, o);
79
+ return '$' + ctx.preparedParams.length;
69
80
  }
70
81
  }
71
82
  exports.PostgresSerializer = PostgresSerializer;
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const builder_1 = require("@sqb/builder");
4
4
  const PostgresSerializer_1 = require("./PostgresSerializer");
5
- builder_1.registerSerializer(new PostgresSerializer_1.PostgresSerializer());
5
+ (0, builder_1.registerSerializer)(new PostgresSerializer_1.PostgresSerializer());
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.9",
4
+ "version": "4.0.6",
5
5
  "author": "Panates Ltd.",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -24,13 +24,13 @@
24
24
  "database"
25
25
  ],
26
26
  "dependencies": {
27
- "compare-versions": "^3.6.0"
27
+ "compare-versions": "^4.1.1"
28
28
  },
29
29
  "devDependencies": {},
30
30
  "main": "dist/index.js",
31
31
  "types": "dist/index.d.ts",
32
32
  "engines": {
33
- "node": ">= 10.0"
33
+ "node": ">= 14.0"
34
34
  },
35
35
  "directories": {
36
36
  "lib": "dist",
@@ -45,7 +45,7 @@
45
45
  "temp-dir": "./coverage/.nyc_output"
46
46
  },
47
47
  "scripts": {
48
- "test": "ts-mocha -p test/tsconfig.json --paths --reporter spec test/**/*.spec.ts",
48
+ "test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts",
49
49
  "cover": "nyc --reporter=cobertura --reporter html --reporter text npm run test",
50
50
  "build": "tsc -b tsconfig-build.json",
51
51
  "compile": "tsc -b tsconfig.json",