@steedos/odata-v4-typeorm 1.20.0 → 2.2.27
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/LICENSE +21 -21
- package/README.md +125 -125
- package/config/default.json +6 -6
- package/{build/lib → lib}/createFilter.d.ts +13 -13
- package/{build/lib → lib}/createFilter.js +17 -15
- package/lib/createFilter.js.map +1 -0
- package/{build/lib → lib}/createQuery.d.ts +13 -13
- package/{build/lib → lib}/createQuery.js +14 -12
- package/lib/createQuery.js.map +1 -0
- package/{build/lib → lib}/executeQuery.d.ts +5 -5
- package/{build/lib → lib}/executeQuery.js +277 -268
- package/lib/executeQuery.js.map +1 -0
- package/{build/lib → lib}/index.d.ts +6 -6
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/{build/lib → lib}/odataQueryMiddleware.d.ts +3 -3
- package/{build/lib → lib}/odataQueryMiddleware.js +29 -26
- package/lib/odataQueryMiddleware.js.map +1 -0
- package/{build/lib → lib}/sqlOptions.d.ts +7 -7
- package/lib/sqlOptions.js +3 -0
- package/{build/lib → lib}/sqlOptions.js.map +1 -1
- package/{build/lib → lib}/visitor.d.ts +20 -20
- package/{build/lib → lib}/visitor.js +308 -302
- package/lib/visitor.js.map +1 -0
- package/package.json +40 -52
- package/src/{lib/createFilter.ts → createFilter.ts} +26 -26
- package/src/{lib/createQuery.ts → createQuery.ts} +22 -22
- package/src/{lib/executeQuery.ts → executeQuery.ts} +291 -282
- package/src/{lib/index.ts → index.ts} +6 -6
- package/src/{lib/odataQueryMiddleware.ts → odataQueryMiddleware.ts} +17 -17
- package/src/{lib/sqlOptions.ts → sqlOptions.ts} +7 -7
- package/src/{lib/visitor.ts → visitor.ts} +301 -298
- package/tsconfig.json +11 -10
- package/build/example/sql.d.ts +0 -0
- package/build/example/sql.js +0 -131
- package/build/example/sql.js.map +0 -1
- package/build/lib/createFilter.js.map +0 -1
- package/build/lib/createQuery.js.map +0 -1
- package/build/lib/executeQuery.js.map +0 -1
- package/build/lib/index.js +0 -12
- package/build/lib/index.js.map +0 -1
- package/build/lib/odataQueryMiddleware.js.map +0 -1
- package/build/lib/sqlOptions.js +0 -2
- package/build/lib/visitor.js.map +0 -1
- package/src/example/sql.ts +0 -82
- package/src/example/world.sql +0 -5388
|
@@ -1,303 +1,309 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.type =
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
case visitor_1.SQLLang.
|
|
75
|
-
case visitor_1.SQLLang.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
this[context.target] +=
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
this.where +=
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
fn = "
|
|
246
|
-
break;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
262
|
-
this.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this.
|
|
267
|
-
this.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
this.
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
case "
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
case "
|
|
286
|
-
case "
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
case "
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
this.where += "
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOrmVisitor = void 0;
|
|
4
|
+
const odata_v4_literal_1 = require("odata-v4-literal");
|
|
5
|
+
const visitor_1 = require("odata-v4-sql/lib/visitor");
|
|
6
|
+
// import {SqlOptions} from './index';
|
|
7
|
+
class TypeOrmVisitor extends visitor_1.Visitor {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
|
+
//parameters:any[] = [];
|
|
11
|
+
this.includes = [];
|
|
12
|
+
this.alias = ''; // 'typeorm_query';
|
|
13
|
+
if (!options.type) {
|
|
14
|
+
this.type = visitor_1.SQLLang.Oracle;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.type = options.type;
|
|
18
|
+
}
|
|
19
|
+
this.alias = options.alias || this.alias;
|
|
20
|
+
}
|
|
21
|
+
from(table) {
|
|
22
|
+
let sql = `SELECT ${this.select} FROM [${table}] WHERE ${this.where} ORDER BY ${this.orderby}`;
|
|
23
|
+
switch (this.type) {
|
|
24
|
+
case visitor_1.SQLLang.Oracle:
|
|
25
|
+
if (typeof this.skip == "number")
|
|
26
|
+
sql += ` OFFSET ${this.skip} ROWS`;
|
|
27
|
+
if (typeof this.limit == "number") {
|
|
28
|
+
if (typeof this.skip != "number")
|
|
29
|
+
sql += " OFFSET 0 ROWS";
|
|
30
|
+
sql += ` FETCH NEXT ${this.limit} ROWS ONLY`;
|
|
31
|
+
}
|
|
32
|
+
case visitor_1.SQLLang.MsSql:
|
|
33
|
+
if (typeof this.orderby !== "string" || this.orderby === "1") {
|
|
34
|
+
this.orderby = "(select null) ASC";
|
|
35
|
+
}
|
|
36
|
+
let start = this.skip ? this.skip : 0;
|
|
37
|
+
let end = start + this.limit;
|
|
38
|
+
sql = `SELECT * from (SELECT ${this.select}, ROW_NUMBER() OVER(ORDER BY ${this.orderby}) AS RowId
|
|
39
|
+
FROM [${table}] WHERE ${this.where}) as a WHERE RowId BETWEEN ${start} + 1 and ${end}`;
|
|
40
|
+
break;
|
|
41
|
+
case visitor_1.SQLLang.MySql:
|
|
42
|
+
case visitor_1.SQLLang.PostgreSql:
|
|
43
|
+
default:
|
|
44
|
+
if (typeof this.limit == "number")
|
|
45
|
+
sql += ` LIMIT ${this.limit}`;
|
|
46
|
+
if (typeof this.skip == "number")
|
|
47
|
+
sql += ` OFFSET ${this.skip}`;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
// 给sql语句中字段名称增加中括号,防止字段名称使用了数据库的关键字
|
|
51
|
+
sql = sql.replace(/(\b\w+\b)\.(\b\w+\b)/g, '[$1].[$2]');
|
|
52
|
+
return sql;
|
|
53
|
+
}
|
|
54
|
+
asMsSql() {
|
|
55
|
+
this.type = visitor_1.SQLLang.MsSql;
|
|
56
|
+
let rx = new RegExp("\\?", "g");
|
|
57
|
+
let keys = this.parameters.keys();
|
|
58
|
+
this.originalWhere = this.where;
|
|
59
|
+
this.where = this.where.replace(rx, () => `:${keys.next().value}`);
|
|
60
|
+
this.includes.forEach((item) => item.asMsSql());
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
asPostgreSql() {
|
|
64
|
+
this.type = visitor_1.SQLLang.ANSI;
|
|
65
|
+
let rx = new RegExp("\\?", "g");
|
|
66
|
+
let keys = this.parameters.keys();
|
|
67
|
+
this.originalWhere = this.where;
|
|
68
|
+
this.where = this.where.replace(rx, () => `:${keys.next().value}`);
|
|
69
|
+
this.includes.forEach((item) => item.asPostgreSql());
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
asType() {
|
|
73
|
+
switch (this.type) {
|
|
74
|
+
case visitor_1.SQLLang.MsSql: return this.asMsSql();
|
|
75
|
+
case visitor_1.SQLLang.ANSI:
|
|
76
|
+
case visitor_1.SQLLang.MySql:
|
|
77
|
+
case visitor_1.SQLLang.PostgreSql: return this.asPostgreSql();
|
|
78
|
+
case visitor_1.SQLLang.Oracle: return this.asOracleSql();
|
|
79
|
+
default: return this;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
VisitExpand(node, context) {
|
|
83
|
+
node.value.items.forEach((item) => {
|
|
84
|
+
let expandPath = item.value.path.raw;
|
|
85
|
+
let visitor = this.includes.filter(v => v.navigationProperty == expandPath)[0];
|
|
86
|
+
if (!visitor) {
|
|
87
|
+
visitor = new TypeOrmVisitor(this.options);
|
|
88
|
+
visitor.parameterSeed = this.parameterSeed;
|
|
89
|
+
this.includes.push(visitor);
|
|
90
|
+
}
|
|
91
|
+
visitor.Visit(item);
|
|
92
|
+
this.parameterSeed = visitor.parameterSeed;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
VisitSelectItem(node, context) {
|
|
96
|
+
let item = node.raw.replace(/\//g, '.');
|
|
97
|
+
this.select += this.getIdentifier(item, context.identifier); //`${this.alias}.${item}`;
|
|
98
|
+
}
|
|
99
|
+
VisitODataIdentifier(node, context) {
|
|
100
|
+
if (context.identifier && context.identifier.endsWith('.')) {
|
|
101
|
+
this[context.target] += '.';
|
|
102
|
+
}
|
|
103
|
+
if (node.value.name === 'NULL') {
|
|
104
|
+
this[context.target] += node.value.name;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const ident = this.getIdentifier(node.value.name, context); //`${this.alias ? this.alias + '.' : ''}${node.value.name}`;
|
|
108
|
+
this[context.target] += ident;
|
|
109
|
+
}
|
|
110
|
+
context.identifier = /*this.getIdentifier(node.value.name, context); //*/ node.value.name;
|
|
111
|
+
}
|
|
112
|
+
getIdentifier(originalIdentifier, context) {
|
|
113
|
+
let alias = '';
|
|
114
|
+
if (!context || !context.identifier || !context.identifier.endsWith('.')) {
|
|
115
|
+
alias = this.alias + '.';
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this[context.target] = this[context.target].replace(new RegExp(this.alias + '.' + context.identifier, 'g'), context.identifier);
|
|
119
|
+
}
|
|
120
|
+
return `${alias}${originalIdentifier}`;
|
|
121
|
+
}
|
|
122
|
+
;
|
|
123
|
+
VisitEqualsExpression(node, context) {
|
|
124
|
+
this.Visit(node.value.left, context);
|
|
125
|
+
this.where += ' = ';
|
|
126
|
+
this.Visit(node.value.right, context);
|
|
127
|
+
if (this.options.useParameters && context.literal == null) {
|
|
128
|
+
this.where = this.where.replace(/= :p\d*$/, 'IS NULL')
|
|
129
|
+
.replace(new RegExp(`\\:p\\d* = ${context.identifier}$`), `${context.identifier} IS NULL`);
|
|
130
|
+
}
|
|
131
|
+
else if (context.literal == 'NULL') {
|
|
132
|
+
this.where = this.where.replace(/= NULL$/, 'IS NULL')
|
|
133
|
+
.replace(new RegExp(`NULL = ${context.identifier}$`), `${context.identifier} IS NULL`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
VisitNotEqualsExpression(node, context) {
|
|
137
|
+
this.Visit(node.value.left, context);
|
|
138
|
+
this.where += ' <> ';
|
|
139
|
+
this.Visit(node.value.right, context);
|
|
140
|
+
if (this.options.useParameters && context.literal == null) {
|
|
141
|
+
this.where = this.where.replace(/<> :p\d*$/, 'IS NOT NULL')
|
|
142
|
+
.replace(new RegExp(`\\:p\\d* <> ${context.identifier}$`), `${context.identifier} IS NOT NULL`);
|
|
143
|
+
}
|
|
144
|
+
else if (context.literal == 'NULL') {
|
|
145
|
+
this.where = this.where.replace(/<> NULL$/, 'IS NOT NULL')
|
|
146
|
+
.replace(new RegExp(`NULL <> ${context.identifier}$`), `${context.identifier} IS NOT NULL`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
VisitLiteral(node, context) {
|
|
150
|
+
if (this.options.useParameters) {
|
|
151
|
+
let name = `p${this.parameterSeed++}`;
|
|
152
|
+
let value = odata_v4_literal_1.Literal.convert(node.value, node.raw);
|
|
153
|
+
context.literal = value;
|
|
154
|
+
if (context.literal != null) {
|
|
155
|
+
this.parameters.set(name, value);
|
|
156
|
+
}
|
|
157
|
+
// this.where += `:${name}`;
|
|
158
|
+
// 因为useParameters为true,所以这里不可以把where追加为:p1这种格式,因为asOracleSql、asPostgreSql等用了正则替换?占位的方式重新设置:p{index}值
|
|
159
|
+
// 如果把where追加为:p1这种格式,已知的问题是VisitMethodCallExpression函数中的包括contains在内的所有method都只能写在过滤条件的最前面,而不可以写在后面的位置
|
|
160
|
+
this.where += `?`;
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
this.where += (context.literal = visitor_1.SQLLiteral.convert(node.value, node.raw));
|
|
164
|
+
}
|
|
165
|
+
VisitNotExpression(node, context) {
|
|
166
|
+
if (node.value && node.value.type === "MethodCallExpression" && node.value.value.method) {
|
|
167
|
+
node.value.value.method = `not ${node.value.value.method}`;
|
|
168
|
+
this.VisitMethodCallExpression(node.value, context);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
VisitMethodCallExpression(node, context) {
|
|
172
|
+
var method = node.value.method;
|
|
173
|
+
var params = node.value.parameters || [];
|
|
174
|
+
switch (method) {
|
|
175
|
+
case "contains":
|
|
176
|
+
this.Visit(params[0], context);
|
|
177
|
+
if (this.options.useParameters) {
|
|
178
|
+
let name = `p${this.parameterSeed++}`;
|
|
179
|
+
let value = odata_v4_literal_1.Literal.convert(params[1].value, params[1].raw);
|
|
180
|
+
this.parameters.set(name, `%${value}%`);
|
|
181
|
+
this.where += " like ?";
|
|
182
|
+
}
|
|
183
|
+
else
|
|
184
|
+
this.where += ` like '%${visitor_1.SQLLiteral.convert(params[1].value, params[1].raw).slice(1, -1)}%'`;
|
|
185
|
+
break;
|
|
186
|
+
case "not contains":
|
|
187
|
+
this.Visit(params[0], context);
|
|
188
|
+
if (this.options.useParameters) {
|
|
189
|
+
let name = `p${this.parameterSeed++}`;
|
|
190
|
+
let value = odata_v4_literal_1.Literal.convert(params[1].value, params[1].raw);
|
|
191
|
+
this.parameters.set(name, `%${value}%`);
|
|
192
|
+
this.where += " not like ?";
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
this.where += ` not like '%${visitor_1.SQLLiteral.convert(params[1].value, params[1].raw).slice(1, -1)}%'`;
|
|
196
|
+
break;
|
|
197
|
+
case "endswith":
|
|
198
|
+
this.Visit(params[0], context);
|
|
199
|
+
if (this.options.useParameters) {
|
|
200
|
+
let name = `p${this.parameterSeed++}`;
|
|
201
|
+
let value = odata_v4_literal_1.Literal.convert(params[1].value, params[1].raw);
|
|
202
|
+
this.parameters.set(name, `%${value}`);
|
|
203
|
+
this.where += " like ?";
|
|
204
|
+
}
|
|
205
|
+
else
|
|
206
|
+
this.where += ` like '%${visitor_1.SQLLiteral.convert(params[1].value, params[1].raw).slice(1, -1)}'`;
|
|
207
|
+
break;
|
|
208
|
+
case "not endswith":
|
|
209
|
+
this.Visit(params[0], context);
|
|
210
|
+
if (this.options.useParameters) {
|
|
211
|
+
let name = `p${this.parameterSeed++}`;
|
|
212
|
+
let value = odata_v4_literal_1.Literal.convert(params[1].value, params[1].raw);
|
|
213
|
+
this.parameters.set(name, `%${value}`);
|
|
214
|
+
this.where += " not like ?";
|
|
215
|
+
}
|
|
216
|
+
else
|
|
217
|
+
this.where += ` not like '%${visitor_1.SQLLiteral.convert(params[1].value, params[1].raw).slice(1, -1)}'`;
|
|
218
|
+
break;
|
|
219
|
+
case "startswith":
|
|
220
|
+
this.Visit(params[0], context);
|
|
221
|
+
if (this.options.useParameters) {
|
|
222
|
+
let name = `p${this.parameterSeed++}`;
|
|
223
|
+
let value = odata_v4_literal_1.Literal.convert(params[1].value, params[1].raw);
|
|
224
|
+
this.parameters.set(name, `${value}%`);
|
|
225
|
+
this.where += " like ?";
|
|
226
|
+
}
|
|
227
|
+
else
|
|
228
|
+
this.where += ` like '${visitor_1.SQLLiteral.convert(params[1].value, params[1].raw).slice(1, -1)}%'`;
|
|
229
|
+
break;
|
|
230
|
+
case "not startswith":
|
|
231
|
+
this.Visit(params[0], context);
|
|
232
|
+
if (this.options.useParameters) {
|
|
233
|
+
let name = `p${this.parameterSeed++}`;
|
|
234
|
+
let value = odata_v4_literal_1.Literal.convert(params[1].value, params[1].raw);
|
|
235
|
+
this.parameters.set(name, `${value}%`);
|
|
236
|
+
this.where += " not like ?";
|
|
237
|
+
}
|
|
238
|
+
else
|
|
239
|
+
this.where += ` not like '${visitor_1.SQLLiteral.convert(params[1].value, params[1].raw).slice(1, -1)}%'`;
|
|
240
|
+
break;
|
|
241
|
+
case "indexof":
|
|
242
|
+
let fn = "";
|
|
243
|
+
switch (this.type) {
|
|
244
|
+
case visitor_1.SQLLang.MsSql:
|
|
245
|
+
fn = "CHARINDEX";
|
|
246
|
+
break;
|
|
247
|
+
case visitor_1.SQLLang.ANSI:
|
|
248
|
+
case visitor_1.SQLLang.MySql:
|
|
249
|
+
case visitor_1.SQLLang.PostgreSql:
|
|
250
|
+
default:
|
|
251
|
+
fn = "INSTR";
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (fn === "CHARINDEX") {
|
|
255
|
+
const tmp = params[0];
|
|
256
|
+
params[0] = params[1];
|
|
257
|
+
params[1] = tmp;
|
|
258
|
+
}
|
|
259
|
+
this.where += `${fn}(`;
|
|
260
|
+
this.Visit(params[0], context);
|
|
261
|
+
this.where += ', ';
|
|
262
|
+
this.Visit(params[1], context);
|
|
263
|
+
this.where += ") - 1";
|
|
264
|
+
break;
|
|
265
|
+
case "round":
|
|
266
|
+
this.where += "ROUND(";
|
|
267
|
+
this.Visit(params[0], context);
|
|
268
|
+
this.where += ")";
|
|
269
|
+
break;
|
|
270
|
+
case "length":
|
|
271
|
+
this.where += "LEN(";
|
|
272
|
+
this.Visit(params[0], context);
|
|
273
|
+
this.where += ")";
|
|
274
|
+
break;
|
|
275
|
+
case "tolower":
|
|
276
|
+
this.where += "LOWER(";
|
|
277
|
+
this.Visit(params[0], context);
|
|
278
|
+
this.where += ")";
|
|
279
|
+
break;
|
|
280
|
+
case "toupper":
|
|
281
|
+
this.where += "UPPER(";
|
|
282
|
+
this.Visit(params[0], context);
|
|
283
|
+
this.where += ")";
|
|
284
|
+
break;
|
|
285
|
+
case "floor":
|
|
286
|
+
case "ceiling":
|
|
287
|
+
case "year":
|
|
288
|
+
case "month":
|
|
289
|
+
case "day":
|
|
290
|
+
case "hour":
|
|
291
|
+
case "minute":
|
|
292
|
+
case "second":
|
|
293
|
+
this.where += `${method.toUpperCase()}(`;
|
|
294
|
+
this.Visit(params[0], context);
|
|
295
|
+
this.where += ")";
|
|
296
|
+
break;
|
|
297
|
+
case "now":
|
|
298
|
+
this.where += "NOW()";
|
|
299
|
+
break;
|
|
300
|
+
case "trim":
|
|
301
|
+
this.where += "TRIM(' ' FROM ";
|
|
302
|
+
this.Visit(params[0], context);
|
|
303
|
+
this.where += ")";
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
exports.TypeOrmVisitor = TypeOrmVisitor;
|
|
303
309
|
//# sourceMappingURL=visitor.js.map
|