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