@sqb/postgres-dialect 4.20.7 → 4.21.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/package.json +9 -25
- package/cjs/index.js +0 -5
- package/cjs/package.json +0 -3
- package/cjs/postgres-serializer.js +0 -115
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -1
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/postgres-serializer.d.ts → postgres-serializer.d.ts} +0 -0
- /package/{esm/postgres-serializer.js → postgres-serializer.js} +0 -0
package/package.json
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/postgres-dialect",
|
|
3
3
|
"description": "SQB serialization extension for PostgreSQL database",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.21.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"tslib": "^2.8.1"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
|
-
"@sqb/builder": "^4.
|
|
11
|
+
"@sqb/builder": "^4.21.0"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
|
+
"module": "./index.js",
|
|
15
|
+
"types": "./index.d.ts",
|
|
14
16
|
"exports": {
|
|
15
17
|
".": {
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"default": "./esm/index.js"
|
|
19
|
-
},
|
|
20
|
-
"require": {
|
|
21
|
-
"types": "./types/index.d.cts",
|
|
22
|
-
"default": "./cjs/index.js"
|
|
23
|
-
},
|
|
24
|
-
"default": "./esm/index.js"
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"default": "./index.js"
|
|
25
20
|
},
|
|
26
21
|
"./package.json": "./package.json"
|
|
27
22
|
},
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20.0"
|
|
25
|
+
},
|
|
31
26
|
"contributors": [
|
|
32
27
|
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
33
28
|
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
@@ -37,17 +32,6 @@
|
|
|
37
32
|
"url": "https://github.com/panates/sqb.git",
|
|
38
33
|
"directory": "packages/postgres-dialect"
|
|
39
34
|
},
|
|
40
|
-
"engines": {
|
|
41
|
-
"node": ">=18.0"
|
|
42
|
-
},
|
|
43
|
-
"files": [
|
|
44
|
-
"bin/",
|
|
45
|
-
"cjs/",
|
|
46
|
-
"esm/",
|
|
47
|
-
"types/",
|
|
48
|
-
"LICENSE",
|
|
49
|
-
"README.md"
|
|
50
|
-
],
|
|
51
35
|
"keywords": [
|
|
52
36
|
"sqb",
|
|
53
37
|
"postgresql",
|
package/cjs/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const builder_1 = require("@sqb/builder");
|
|
4
|
-
const postgres_serializer_js_1 = require("./postgres-serializer.js");
|
|
5
|
-
builder_1.SerializerRegistry.register(new postgres_serializer_js_1.PostgresSerializer());
|
package/cjs/package.json
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostgresSerializer = void 0;
|
|
4
|
-
const builder_1 = require("@sqb/builder");
|
|
5
|
-
const reservedWords = ['comment'];
|
|
6
|
-
class PostgresSerializer {
|
|
7
|
-
dialect = 'postgres';
|
|
8
|
-
isReservedWord(ctx, s) {
|
|
9
|
-
return (s && typeof s === 'string' && reservedWords.includes(s.toLowerCase()));
|
|
10
|
-
}
|
|
11
|
-
serialize(ctx, type, o, defFn) {
|
|
12
|
-
switch (type) {
|
|
13
|
-
case builder_1.SerializationType.SELECT_QUERY:
|
|
14
|
-
return this._serializeSelect(ctx, o, defFn);
|
|
15
|
-
case builder_1.SerializationType.COMPARISON_EXPRESSION:
|
|
16
|
-
return this._serializeComparison(ctx, o, defFn);
|
|
17
|
-
case builder_1.SerializationType.EXTERNAL_PARAMETER:
|
|
18
|
-
return this._serializeParameter(ctx, o, defFn);
|
|
19
|
-
default:
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
_serializeSelect(ctx, o, defFn) {
|
|
24
|
-
let out = defFn(ctx, o);
|
|
25
|
-
const limit = o.limit || 0;
|
|
26
|
-
const offset = Math.max(o.offset || 0, 0);
|
|
27
|
-
if (limit)
|
|
28
|
-
out += '\nLIMIT ' + limit;
|
|
29
|
-
if (offset)
|
|
30
|
-
out += (!limit ? '\n' : ' ') + 'OFFSET ' + offset;
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
_serializeComparison(ctx, o, defFn) {
|
|
34
|
-
if (o.right) {
|
|
35
|
-
if ((o.right.expression && o.right?.expression === 'null') ||
|
|
36
|
-
(o.right.value == null &&
|
|
37
|
-
(!o.right.expression || o.right.expression.startsWith('$')))) {
|
|
38
|
-
if (o.right.expression?.startsWith('$')) {
|
|
39
|
-
const i = parseInt(o.right.expression.substring(1), 10);
|
|
40
|
-
if (i > 0) {
|
|
41
|
-
const _ctx = ctx;
|
|
42
|
-
_ctx.removedParams = _ctx.removedParams || [];
|
|
43
|
-
if (!_ctx.removedParams.includes(i)) {
|
|
44
|
-
_ctx.removedParams.push(i);
|
|
45
|
-
if (Array.isArray(ctx.preparedParams))
|
|
46
|
-
ctx.preparedParams.splice(i - 1, 1);
|
|
47
|
-
if (Array.isArray(ctx.paramOptions))
|
|
48
|
-
ctx.paramOptions.splice(i - 1, 1);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
o.right.expression = 'null';
|
|
52
|
-
o.right.isParam = false;
|
|
53
|
-
}
|
|
54
|
-
if (o.operatorType === 'eq')
|
|
55
|
-
return defFn(ctx, {
|
|
56
|
-
...o,
|
|
57
|
-
operatorType: builder_1.OperatorType.is,
|
|
58
|
-
symbol: 'is',
|
|
59
|
-
});
|
|
60
|
-
if (o.operatorType === 'ne')
|
|
61
|
-
return defFn(ctx, {
|
|
62
|
-
...o,
|
|
63
|
-
operatorType: builder_1.OperatorType.isNot,
|
|
64
|
-
symbol: 'is not',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (o.left.isParam &&
|
|
68
|
-
o.left.isArray &&
|
|
69
|
-
o.left.value != null &&
|
|
70
|
-
!Array.isArray(o.left.value)) {
|
|
71
|
-
o.left.value = [o.left.value];
|
|
72
|
-
}
|
|
73
|
-
if (o.right.isParam &&
|
|
74
|
-
o.right.isArray &&
|
|
75
|
-
o.right.value != null &&
|
|
76
|
-
!Array.isArray(o.right.value)) {
|
|
77
|
-
o.right.value = [o.right.value];
|
|
78
|
-
}
|
|
79
|
-
if (o.operatorType === 'in' || o.operatorType === 'notIn') {
|
|
80
|
-
if (o.left.isArray && !o.right.isArray && o.right.isParam) {
|
|
81
|
-
const left = o.left;
|
|
82
|
-
const right = o.right;
|
|
83
|
-
left.expression = 'ANY(' + left.expression + ')';
|
|
84
|
-
return defFn(ctx, {
|
|
85
|
-
...o,
|
|
86
|
-
operatorType: builder_1.OperatorType.eq,
|
|
87
|
-
symbol: o.operatorType === 'notIn' ? '!=' : '=',
|
|
88
|
-
left: right,
|
|
89
|
-
right: left,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (o.left.isArray && o.right.isArray) {
|
|
93
|
-
if (o.operatorType === 'notIn')
|
|
94
|
-
o.left.expression = 'not ' + o.left.expression;
|
|
95
|
-
return defFn(ctx, { ...o, symbol: '&&' });
|
|
96
|
-
}
|
|
97
|
-
if (!o.left.isArray && o.right.isArray && o.right.isParam) {
|
|
98
|
-
o.right.expression = 'ANY(' + o.right.expression + ')';
|
|
99
|
-
return defFn(ctx, {
|
|
100
|
-
...o,
|
|
101
|
-
operatorType: builder_1.OperatorType.eq,
|
|
102
|
-
symbol: o.operatorType === 'notIn' ? '!=' : '=',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return defFn(ctx, o);
|
|
108
|
-
}
|
|
109
|
-
_serializeParameter(ctx, o, defFn) {
|
|
110
|
-
ctx.preparedParams = ctx.preparedParams || [];
|
|
111
|
-
defFn(ctx, o);
|
|
112
|
-
return '$' + ctx.preparedParams.length;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.PostgresSerializer = PostgresSerializer;
|
package/esm/package.json
DELETED
package/types/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|