@villedemontreal/utils-knex 7.0.1

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 (66) hide show
  1. package/README.md +236 -0
  2. package/dist/src/config/configs.d.ts +19 -0
  3. package/dist/src/config/configs.d.ts.map +1 -0
  4. package/dist/src/config/configs.js +27 -0
  5. package/dist/src/config/configs.js.map +1 -0
  6. package/dist/src/config/constants.d.ts +21 -0
  7. package/dist/src/config/constants.d.ts.map +1 -0
  8. package/dist/src/config/constants.js +21 -0
  9. package/dist/src/config/constants.js.map +1 -0
  10. package/dist/src/config/init.d.ts +16 -0
  11. package/dist/src/config/init.d.ts.map +1 -0
  12. package/dist/src/config/init.js +33 -0
  13. package/dist/src/config/init.js.map +1 -0
  14. package/dist/src/databaseContext.d.ts +9 -0
  15. package/dist/src/databaseContext.d.ts.map +1 -0
  16. package/dist/src/databaseContext.js +3 -0
  17. package/dist/src/databaseContext.js.map +1 -0
  18. package/dist/src/index.d.ts +5 -0
  19. package/dist/src/index.d.ts.map +1 -0
  20. package/dist/src/index.js +26 -0
  21. package/dist/src/index.js.map +1 -0
  22. package/dist/src/knexUtils.d.ts +134 -0
  23. package/dist/src/knexUtils.d.ts.map +1 -0
  24. package/dist/src/knexUtils.js +349 -0
  25. package/dist/src/knexUtils.js.map +1 -0
  26. package/dist/src/knexUtils.test.d.ts +2 -0
  27. package/dist/src/knexUtils.test.d.ts.map +1 -0
  28. package/dist/src/knexUtils.test.js +897 -0
  29. package/dist/src/knexUtils.test.js.map +1 -0
  30. package/dist/src/transactionManager.d.ts +34 -0
  31. package/dist/src/transactionManager.d.ts.map +1 -0
  32. package/dist/src/transactionManager.js +75 -0
  33. package/dist/src/transactionManager.js.map +1 -0
  34. package/dist/src/transactionManager.test.d.ts +10 -0
  35. package/dist/src/transactionManager.test.d.ts.map +1 -0
  36. package/dist/src/transactionManager.test.js +255 -0
  37. package/dist/src/transactionManager.test.js.map +1 -0
  38. package/dist/src/utils/logger.d.ts +12 -0
  39. package/dist/src/utils/logger.d.ts.map +1 -0
  40. package/dist/src/utils/logger.js +53 -0
  41. package/dist/src/utils/logger.js.map +1 -0
  42. package/dist/src/utils/testingConfigurations.d.ts +9 -0
  43. package/dist/src/utils/testingConfigurations.d.ts.map +1 -0
  44. package/dist/src/utils/testingConfigurations.js +16 -0
  45. package/dist/src/utils/testingConfigurations.js.map +1 -0
  46. package/dist/testing/testClient.d.ts +15 -0
  47. package/dist/testing/testClient.d.ts.map +1 -0
  48. package/dist/testing/testClient.js +55 -0
  49. package/dist/testing/testClient.js.map +1 -0
  50. package/dist/testing/testRepo.d.ts +8 -0
  51. package/dist/testing/testRepo.d.ts.map +1 -0
  52. package/dist/testing/testRepo.js +31 -0
  53. package/dist/testing/testRepo.js.map +1 -0
  54. package/dist/tsconfig.tsbuildinfo +1 -0
  55. package/package.json +76 -0
  56. package/src/config/configs.ts +34 -0
  57. package/src/config/constants.ts +33 -0
  58. package/src/config/init.ts +33 -0
  59. package/src/databaseContext.ts +9 -0
  60. package/src/index.ts +9 -0
  61. package/src/knexUtils.test.ts +1526 -0
  62. package/src/knexUtils.ts +459 -0
  63. package/src/transactionManager.test.ts +302 -0
  64. package/src/transactionManager.ts +94 -0
  65. package/src/utils/logger.ts +60 -0
  66. package/src/utils/testingConfigurations.ts +13 -0
@@ -0,0 +1,1526 @@
1
+ // Ok for test files
2
+ // tslint:disable:max-func-body-length
3
+
4
+ import { isPaginatedResult } from '@villedemontreal/general-utils';
5
+ import { assert } from 'chai';
6
+ import { Knex } from 'knex';
7
+ import { IKnexMockedClient, knexUtils } from './knexUtils';
8
+ import { setTestingConfigurations } from './utils/testingConfigurations';
9
+
10
+ // ==========================================
11
+ // Set Testing configurations
12
+ // ==========================================
13
+ setTestingConfigurations();
14
+
15
+ // ==========================================
16
+ // Knex Utilities
17
+ // ==========================================
18
+ describe('Knex Utilities', () => {
19
+ let mockedClient: IKnexMockedClient;
20
+
21
+ before(async () => {
22
+ mockedClient = await knexUtils.createKnexMockedClient();
23
+ });
24
+
25
+ beforeEach(async () => {
26
+ mockedClient.beforeQuerySpy.resetHistory();
27
+ mockedClient.resultStub.returns([]);
28
+ mockedClient.totalCountStub.returns(0);
29
+ });
30
+
31
+ // ==========================================
32
+ // paginate() and totalCount()
33
+ // ==========================================
34
+ describe('paginate() and totalCount()', () => {
35
+ // ==========================================
36
+ // totalCount()
37
+ // ==========================================
38
+ describe('- totalCount()', () => {
39
+ it('default', async () => {
40
+ const queryBuilder = mockedClient
41
+ .select('id', 'author', 'title')
42
+ .from('books')
43
+ .orderBy('author');
44
+
45
+ await knexUtils.totalCount(mockedClient, queryBuilder);
46
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
47
+
48
+ assert.isOk(queryInfo);
49
+ assert.isOk(queryInfo.sql);
50
+ assert.isOk(queryInfo.bindings);
51
+
52
+ assert.strictEqual(
53
+ queryInfo.sql,
54
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
55
+ );
56
+ assert.strictEqual(queryInfo.bindings.length, 1);
57
+ assert.strictEqual(queryInfo.bindings[0], 1);
58
+ });
59
+
60
+ it('removes offset and limit', async () => {
61
+ await knexUtils.totalCount(
62
+ mockedClient,
63
+ mockedClient
64
+ .select('id', 'author', 'title')
65
+ .from('books')
66
+ .orderBy('author')
67
+ .offset(2)
68
+ .limit(3),
69
+ );
70
+
71
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
72
+ assert.strictEqual(
73
+ queryInfo.sql,
74
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
75
+ );
76
+ assert.strictEqual(queryInfo.bindings.length, 1);
77
+ assert.strictEqual(queryInfo.bindings[0], 1);
78
+ });
79
+
80
+ it('more complex query', async () => {
81
+ const subSelect = mockedClient
82
+ .select('title')
83
+ .from('books')
84
+ .where('author', 'author_02')
85
+ .as('test');
86
+
87
+ const queryBuilder = mockedClient
88
+ .select('id', 'author', subSelect)
89
+ .from('books')
90
+ .whereIn('author', ['author_01', 'author_03', 'author_04'])
91
+ .orderBy('author', 'desc');
92
+
93
+ await knexUtils.totalCount(mockedClient, queryBuilder);
94
+
95
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
96
+ assert.strictEqual(
97
+ queryInfo.sql,
98
+ 'select count(*) as `count` from (select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` ' +
99
+ 'from `books` where `author` in (?, ?, ?)) as `_knexSub` limit ?',
100
+ );
101
+ assert.strictEqual(queryInfo.bindings.length, 5);
102
+ assert.strictEqual(queryInfo.bindings[4], 1);
103
+ });
104
+
105
+ it('with distinct', async () => {
106
+ await knexUtils.totalCount(
107
+ mockedClient,
108
+ mockedClient.distinct('info').from('books').orderBy('author').offset(0).limit(3),
109
+ );
110
+
111
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
112
+ assert.strictEqual(
113
+ queryInfo.sql,
114
+ 'select count(*) as `count` from (select distinct `info` from `books`) as `_knexSub` limit ?',
115
+ );
116
+ assert.strictEqual(queryInfo.bindings.length, 1);
117
+ assert.strictEqual(queryInfo.bindings[0], 1);
118
+ });
119
+ });
120
+
121
+ // ==========================================
122
+ // paginate()
123
+ // ==========================================
124
+ describe('- paginate()', () => {
125
+ it('Without pagination', async () => {
126
+ await mockedClient.select('id', 'author', 'title').from('books').orderBy('author');
127
+
128
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
129
+ assert.strictEqual(
130
+ queryInfo.sql,
131
+ 'select `id`, `author`, `title` from `books` order by `author` asc',
132
+ );
133
+ assert.strictEqual(queryInfo.bindings.length, 0);
134
+ });
135
+
136
+ it('offset : 0 | limit : 3', async () => {
137
+ const queryBuilder = mockedClient
138
+ .select('id', 'author', 'title')
139
+ .from('books')
140
+ .orderBy('author');
141
+
142
+ await knexUtils.paginate(mockedClient, queryBuilder, 0, 3);
143
+
144
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
145
+ assert.strictEqual(
146
+ queryInfoCount.sql,
147
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
148
+ );
149
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
150
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
151
+
152
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
153
+ assert.strictEqual(
154
+ queryInfoResultSet.sql,
155
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
156
+ );
157
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
158
+ assert.strictEqual(queryInfoResultSet.bindings[0], 3);
159
+ });
160
+
161
+ it('offset : 3 | limit : 3', async () => {
162
+ await knexUtils.paginate(
163
+ mockedClient,
164
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
165
+ 3,
166
+ 3,
167
+ );
168
+
169
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
170
+ assert.strictEqual(
171
+ queryInfoCount.sql,
172
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
173
+ );
174
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
175
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
176
+
177
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
178
+ assert.strictEqual(
179
+ queryInfoResultSet.sql,
180
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
181
+ );
182
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
183
+ assert.strictEqual(queryInfoResultSet.bindings[0], 3);
184
+ assert.strictEqual(queryInfoResultSet.bindings[1], 3);
185
+ });
186
+
187
+ it('offset : 6 | limit : 3', async () => {
188
+ await knexUtils.paginate(
189
+ mockedClient,
190
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
191
+ 6,
192
+ 3,
193
+ );
194
+
195
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
196
+ assert.strictEqual(
197
+ queryInfoCount.sql,
198
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
199
+ );
200
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
201
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
202
+
203
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
204
+ assert.strictEqual(
205
+ queryInfoResultSet.sql,
206
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
207
+ );
208
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
209
+ assert.strictEqual(queryInfoResultSet.bindings[0], 3);
210
+ assert.strictEqual(queryInfoResultSet.bindings[1], 6);
211
+ });
212
+
213
+ it('offset : 9 | limit : 3', async () => {
214
+ await knexUtils.paginate(
215
+ mockedClient,
216
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
217
+ 9,
218
+ 3,
219
+ );
220
+
221
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
222
+ assert.strictEqual(
223
+ queryInfoCount.sql,
224
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
225
+ );
226
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
227
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
228
+
229
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
230
+ assert.strictEqual(
231
+ queryInfoResultSet.sql,
232
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
233
+ );
234
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
235
+ assert.strictEqual(queryInfoResultSet.bindings[0], 3);
236
+ assert.strictEqual(queryInfoResultSet.bindings[1], 9);
237
+ });
238
+
239
+ it('offset : 9 | limit : 1', async () => {
240
+ await knexUtils.paginate(
241
+ mockedClient,
242
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
243
+ 9,
244
+ 1,
245
+ );
246
+
247
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
248
+ assert.strictEqual(
249
+ queryInfoCount.sql,
250
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
251
+ );
252
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
253
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
254
+
255
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
256
+ assert.strictEqual(
257
+ queryInfoResultSet.sql,
258
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
259
+ );
260
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
261
+ assert.strictEqual(queryInfoResultSet.bindings[0], 1);
262
+ assert.strictEqual(queryInfoResultSet.bindings[1], 9);
263
+ });
264
+
265
+ it('offset : 9 | limit : 0', async () => {
266
+ await knexUtils.paginate(
267
+ mockedClient,
268
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
269
+ 9,
270
+ 0,
271
+ );
272
+
273
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
274
+ assert.strictEqual(
275
+ queryInfoCount.sql,
276
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
277
+ );
278
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
279
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
280
+
281
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
282
+ assert.strictEqual(
283
+ queryInfoResultSet.sql,
284
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
285
+ );
286
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
287
+ assert.strictEqual(queryInfoResultSet.bindings[0], 1);
288
+ assert.strictEqual(queryInfoResultSet.bindings[1], 9);
289
+ });
290
+
291
+ it('offset : 0 | limit : 1', async () => {
292
+ await knexUtils.paginate(
293
+ mockedClient,
294
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
295
+ 0,
296
+ 1,
297
+ );
298
+
299
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
300
+ assert.strictEqual(
301
+ queryInfoCount.sql,
302
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
303
+ );
304
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
305
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
306
+
307
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
308
+ assert.strictEqual(
309
+ queryInfoResultSet.sql,
310
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
311
+ );
312
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
313
+ assert.strictEqual(queryInfoResultSet.bindings[0], 1);
314
+ });
315
+
316
+ it('offset : -1 | limit : 1', async () => {
317
+ await knexUtils.paginate(
318
+ mockedClient,
319
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
320
+ -1,
321
+ 1,
322
+ );
323
+
324
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
325
+ assert.strictEqual(
326
+ queryInfoCount.sql,
327
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
328
+ );
329
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
330
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
331
+
332
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
333
+ assert.strictEqual(
334
+ queryInfoResultSet.sql,
335
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
336
+ );
337
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
338
+ assert.strictEqual(queryInfoResultSet.bindings[0], 1);
339
+ });
340
+
341
+ it('offset : 0 | limit : 0', async () => {
342
+ await knexUtils.paginate(
343
+ mockedClient,
344
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
345
+ 0,
346
+ 0,
347
+ );
348
+
349
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
350
+ assert.strictEqual(
351
+ queryInfoCount.sql,
352
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
353
+ );
354
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
355
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
356
+
357
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
358
+ assert.strictEqual(
359
+ queryInfoResultSet.sql,
360
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
361
+ );
362
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
363
+ assert.strictEqual(queryInfoResultSet.bindings[0], 1);
364
+ });
365
+
366
+ it('offset : 0 | limit : -1', async () => {
367
+ await knexUtils.paginate(
368
+ mockedClient,
369
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
370
+ 0,
371
+ -1,
372
+ );
373
+
374
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
375
+ assert.strictEqual(
376
+ queryInfoCount.sql,
377
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
378
+ );
379
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
380
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
381
+
382
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
383
+ assert.strictEqual(
384
+ queryInfoResultSet.sql,
385
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
386
+ );
387
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
388
+ assert.strictEqual(queryInfoResultSet.bindings[0], 1);
389
+ });
390
+
391
+ it('offset : 0 | limit : 100', async () => {
392
+ await knexUtils.paginate(
393
+ mockedClient,
394
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
395
+ 0,
396
+ 100,
397
+ );
398
+
399
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
400
+ assert.strictEqual(
401
+ queryInfoCount.sql,
402
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
403
+ );
404
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
405
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
406
+
407
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
408
+ assert.strictEqual(
409
+ queryInfoResultSet.sql,
410
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
411
+ );
412
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
413
+ assert.strictEqual(queryInfoResultSet.bindings[0], 100);
414
+ });
415
+
416
+ it('offset : 9 | limit : 100', async () => {
417
+ await knexUtils.paginate(
418
+ mockedClient,
419
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
420
+ 9,
421
+ 100,
422
+ );
423
+
424
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
425
+ assert.strictEqual(
426
+ queryInfoCount.sql,
427
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
428
+ );
429
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
430
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
431
+
432
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
433
+ assert.strictEqual(
434
+ queryInfoResultSet.sql,
435
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
436
+ );
437
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
438
+ assert.strictEqual(queryInfoResultSet.bindings[0], 100);
439
+ assert.strictEqual(queryInfoResultSet.bindings[1], 9);
440
+ });
441
+
442
+ it('offset : 10 | limit : 100', async () => {
443
+ await knexUtils.paginate(
444
+ mockedClient,
445
+ mockedClient.select('id', 'author', 'title').from('books').orderBy('author'),
446
+ 10,
447
+ 100,
448
+ );
449
+
450
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
451
+ assert.strictEqual(
452
+ queryInfoCount.sql,
453
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
454
+ );
455
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
456
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
457
+
458
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
459
+ assert.strictEqual(
460
+ queryInfoResultSet.sql,
461
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ? offset ?',
462
+ );
463
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
464
+ assert.strictEqual(queryInfoResultSet.bindings[0], 100);
465
+ assert.strictEqual(queryInfoResultSet.bindings[1], 10);
466
+ });
467
+
468
+ it(`only 'select' is valid - update`, async () => {
469
+ let error = false;
470
+ try {
471
+ await knexUtils.paginate(
472
+ mockedClient,
473
+ mockedClient
474
+ .update('author', 'author_updated')
475
+ .from('books')
476
+ .where('author', 'author_01'),
477
+ 0,
478
+ 1,
479
+ );
480
+ } catch (err) {
481
+ error = true;
482
+ }
483
+ assert.isTrue(error);
484
+ });
485
+
486
+ it(`only 'select' is valid - insert`, async () => {
487
+ let error = false;
488
+ try {
489
+ await knexUtils.paginate(
490
+ mockedClient,
491
+ mockedClient
492
+ .insert({
493
+ author: 'author_11',
494
+ title: 'title_11',
495
+ })
496
+ .into('books'),
497
+ 0,
498
+ 1,
499
+ );
500
+ } catch (err) {
501
+ error = true;
502
+ }
503
+ assert.isTrue(error);
504
+ });
505
+
506
+ it(`only 'select' is valid - delete`, async () => {
507
+ let error = false;
508
+ try {
509
+ await knexUtils.paginate(mockedClient, mockedClient.delete().from('books'), 0, 1);
510
+ } catch (err) {
511
+ error = true;
512
+ }
513
+ assert.isTrue(error);
514
+ });
515
+
516
+ it('More complex select query - offset : 0 | limit : 2', async () => {
517
+ const subSelect = mockedClient
518
+ .select('title')
519
+ .from('books')
520
+ .where('author', 'author_02')
521
+ .as('test');
522
+
523
+ const queryBuilder = mockedClient
524
+ .select('id', 'author', subSelect)
525
+ .from('books')
526
+ .whereIn('author', ['author_01', 'author_03', 'author_04'])
527
+ .orderBy('author', 'desc');
528
+
529
+ await knexUtils.paginate(mockedClient, queryBuilder, 0, 2);
530
+
531
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
532
+ assert.strictEqual(
533
+ queryInfoCount.sql,
534
+ 'select count(*) as `count` from (select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` from `books` where `author` in (?, ?, ?)) as `_knexSub` limit ?',
535
+ );
536
+ assert.strictEqual(queryInfoCount.bindings.length, 5);
537
+ assert.strictEqual(queryInfoCount.bindings[4], 1);
538
+
539
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
540
+ assert.strictEqual(
541
+ queryInfoResultSet.sql,
542
+ 'select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` from `books` where `author` in (?, ?, ?) order by `author` desc limit ?',
543
+ );
544
+ assert.strictEqual(queryInfoResultSet.bindings.length, 5);
545
+ assert.strictEqual(queryInfoResultSet.bindings[4], 2);
546
+ });
547
+
548
+ it('More complex select query - offset : 2 | limit : 2', async () => {
549
+ const subSelect = mockedClient
550
+ .select('title')
551
+ .from('books')
552
+ .where('author', 'author_02')
553
+ .as('test');
554
+
555
+ const queryBuilder = mockedClient
556
+ .select('id', 'author', subSelect)
557
+ .from('books')
558
+ .whereIn('author', ['author_01', 'author_03', 'author_04'])
559
+ .orderBy('author', 'desc');
560
+
561
+ await knexUtils.paginate(mockedClient, queryBuilder, 2, 2);
562
+
563
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
564
+ assert.strictEqual(
565
+ queryInfoCount.sql,
566
+ 'select count(*) as `count` from (select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` from `books` where `author` in (?, ?, ?)) as `_knexSub` limit ?',
567
+ );
568
+ assert.strictEqual(queryInfoCount.bindings.length, 5);
569
+ assert.strictEqual(queryInfoCount.bindings[4], 1);
570
+
571
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
572
+ assert.strictEqual(
573
+ queryInfoResultSet.sql,
574
+ 'select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` from `books` where `author` in (?, ?, ?) order by `author` desc limit ? offset ?',
575
+ );
576
+ assert.strictEqual(queryInfoResultSet.bindings.length, 6);
577
+ assert.strictEqual(queryInfoResultSet.bindings[4], 2);
578
+ assert.strictEqual(queryInfoResultSet.bindings[5], 2);
579
+ });
580
+
581
+ it('More complex select query - offset : 3 | limit : 2', async () => {
582
+ const subSelect = mockedClient
583
+ .select('title')
584
+ .from('books')
585
+ .where('author', 'author_02')
586
+ .as('test');
587
+
588
+ const queryBuilder = mockedClient
589
+ .select('id', 'author', subSelect)
590
+ .from('books')
591
+ .whereIn('author', ['author_01', 'author_03', 'author_04'])
592
+ .orderBy('author', 'desc');
593
+
594
+ await knexUtils.paginate(mockedClient, queryBuilder, 3, 2);
595
+
596
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
597
+ assert.strictEqual(
598
+ queryInfoCount.sql,
599
+ 'select count(*) as `count` from (select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` from `books` where `author` in (?, ?, ?)) as `_knexSub` limit ?',
600
+ );
601
+ assert.strictEqual(queryInfoCount.bindings.length, 5);
602
+ assert.strictEqual(queryInfoCount.bindings[4], 1);
603
+
604
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
605
+ assert.strictEqual(
606
+ queryInfoResultSet.sql,
607
+ 'select `id`, `author`, (select `title` from `books` where `author` = ?) as `test` from `books` where `author` in (?, ?, ?) order by `author` desc limit ? offset ?',
608
+ );
609
+ assert.strictEqual(queryInfoResultSet.bindings.length, 6);
610
+ assert.strictEqual(queryInfoResultSet.bindings[4], 2);
611
+ assert.strictEqual(queryInfoResultSet.bindings[5], 3);
612
+ });
613
+
614
+ it('with distinct', async () => {
615
+ await knexUtils.paginate(
616
+ mockedClient,
617
+ mockedClient.distinct('info').from('books').orderBy('author'),
618
+ 1,
619
+ 100,
620
+ );
621
+
622
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
623
+ assert.strictEqual(
624
+ queryInfoCount.sql,
625
+ 'select count(*) as `count` from (select distinct `info` from `books`) as `_knexSub` limit ?',
626
+ );
627
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
628
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
629
+
630
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
631
+ assert.strictEqual(
632
+ queryInfoResultSet.sql,
633
+ 'select distinct `info` from `books` order by `author` asc limit ? offset ?',
634
+ );
635
+ assert.strictEqual(queryInfoResultSet.bindings.length, 2);
636
+ assert.strictEqual(queryInfoResultSet.bindings[0], 100);
637
+ assert.strictEqual(queryInfoResultSet.bindings[1], 1);
638
+ });
639
+
640
+ it('with multiple distincts', async () => {
641
+ await knexUtils.paginate(
642
+ mockedClient,
643
+ mockedClient.distinct('info', 'info2').from('books').orderBy('author'),
644
+ 0,
645
+ 2,
646
+ );
647
+
648
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
649
+ assert.strictEqual(
650
+ queryInfoCount.sql,
651
+ 'select count(*) as `count` from (select distinct `info`, `info2` from `books`) as `_knexSub` limit ?',
652
+ );
653
+ assert.strictEqual(queryInfoCount.bindings.length, 1);
654
+ assert.strictEqual(queryInfoCount.bindings[0], 1);
655
+
656
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
657
+ assert.strictEqual(
658
+ queryInfoResultSet.sql,
659
+ 'select distinct `info`, `info2` from `books` order by `author` asc limit ?',
660
+ );
661
+ assert.strictEqual(queryInfoResultSet.bindings.length, 1);
662
+ assert.strictEqual(queryInfoResultSet.bindings[0], 2);
663
+ });
664
+
665
+ it('with multiple distincts and where clause', async () => {
666
+ await knexUtils.paginate(
667
+ mockedClient,
668
+ mockedClient
669
+ .distinct('info', 'info2')
670
+ .from('books')
671
+ .whereIn('title', ['title_01', 'title_02', 'title_03'])
672
+ .orderBy('author'),
673
+ 1,
674
+ 1,
675
+ );
676
+
677
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
678
+ assert.strictEqual(
679
+ queryInfoCount.sql,
680
+ 'select count(*) as `count` from (select distinct `info`, `info2` from `books` where `title` in (?, ?, ?)) as `_knexSub` limit ?',
681
+ );
682
+ assert.strictEqual(queryInfoCount.bindings.length, 4);
683
+ assert.strictEqual(queryInfoCount.bindings[3], 1);
684
+
685
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
686
+ assert.strictEqual(
687
+ queryInfoResultSet.sql,
688
+ 'select distinct `info`, `info2` from `books` where `title` in (?, ?, ?) order by `author` asc limit ? offset ?',
689
+ );
690
+ assert.strictEqual(queryInfoResultSet.bindings.length, 5);
691
+ assert.strictEqual(queryInfoResultSet.bindings[3], 1);
692
+ assert.strictEqual(queryInfoResultSet.bindings[4], 1);
693
+ });
694
+ });
695
+
696
+ // ==========================================
697
+ // paginate() and count() together
698
+ // ==========================================
699
+ describe('- Full example', () => {
700
+ it('Full example', async () => {
701
+ // ==========================================
702
+ // SELECT query
703
+ // ==========================================
704
+ const query = mockedClient.select('id', 'author', 'title').from('books').orderBy('author');
705
+
706
+ // ==========================================
707
+ // Run as is
708
+ // ==========================================
709
+ await query;
710
+
711
+ // ==========================================
712
+ // Paginated results
713
+ // offset 0 | limit 3
714
+ // ==========================================
715
+ await knexUtils.paginate(mockedClient, query, 0, 3);
716
+
717
+ // ==========================================
718
+ // Total count
719
+ // ==========================================
720
+ await knexUtils.totalCount(mockedClient, query);
721
+
722
+ const queryInfoResultSetAsIs: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
723
+ assert.strictEqual(
724
+ queryInfoResultSetAsIs.sql,
725
+ 'select `id`, `author`, `title` from `books` order by `author` asc',
726
+ );
727
+ assert.strictEqual(queryInfoResultSetAsIs.bindings.length, 0);
728
+
729
+ const queryInfoCountPaginated: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
730
+ assert.strictEqual(
731
+ queryInfoCountPaginated.sql,
732
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
733
+ );
734
+ assert.strictEqual(queryInfoCountPaginated.bindings.length, 1);
735
+ assert.strictEqual(queryInfoCountPaginated.bindings[0], 1);
736
+
737
+ const queryInfoResultSetPaginated: any = mockedClient.beforeQuerySpy.getCall(2).args[0];
738
+ assert.strictEqual(
739
+ queryInfoResultSetPaginated.sql,
740
+ 'select `id`, `author`, `title` from `books` order by `author` asc limit ?',
741
+ );
742
+ assert.strictEqual(queryInfoResultSetPaginated.bindings.length, 1);
743
+ assert.strictEqual(queryInfoResultSetPaginated.bindings[0], 3);
744
+
745
+ const queryInfoCountAlone: any = mockedClient.beforeQuerySpy.getCall(3).args[0];
746
+ assert.strictEqual(
747
+ queryInfoCountAlone.sql,
748
+ 'select count(*) as `count` from (select `id`, `author`, `title` from `books`) as `_knexSub` limit ?',
749
+ );
750
+ assert.strictEqual(queryInfoCountAlone.bindings.length, 1);
751
+ assert.strictEqual(queryInfoCountAlone.bindings[0], 1);
752
+ });
753
+ });
754
+ });
755
+
756
+ // ==========================================
757
+ // Knex mocked client
758
+ // ==========================================
759
+ describe('Knex mocked client', () => {
760
+ it('default', async () => {
761
+ const query = mockedClient
762
+ .select('somethingA', 'somethingB')
763
+ .from('someTbale')
764
+ .where('someColumn', 'someValue')
765
+ .orderBy('somethingB');
766
+
767
+ const result = await query;
768
+ assert.isOk(result);
769
+ assert.deepEqual(result, []);
770
+ });
771
+
772
+ it('beforeQuerySpy spy', async () => {
773
+ const query = mockedClient
774
+ .select('somethingA', 'somethingB')
775
+ .from('someTbale')
776
+ .where('someColumn', 'someValue')
777
+ .orderBy('somethingB');
778
+
779
+ await query;
780
+
781
+ assert.isTrue(mockedClient.beforeQuerySpy.calledOnce);
782
+
783
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
784
+ assert.isOk(queryInfo);
785
+ assert.isOk(queryInfo.sql);
786
+ assert.isOk(queryInfo.bindings);
787
+
788
+ assert.strictEqual(
789
+ queryInfo.sql,
790
+ 'select `somethingA`, `somethingB` from `someTbale` where `someColumn` = ? order by `somethingB` asc',
791
+ );
792
+ assert.strictEqual(queryInfo.bindings.length, 1);
793
+ assert.strictEqual(queryInfo.bindings[0], 'someValue');
794
+ });
795
+
796
+ it('custom result - single value', async () => {
797
+ mockedClient.resultStub.returns(123);
798
+
799
+ const query = mockedClient
800
+ .select('somethingA', 'somethingB')
801
+ .from('someTbale')
802
+ .where('someColumn', 'someValue')
803
+ .orderBy('somethingB');
804
+
805
+ const result: any = await query;
806
+ assert.isOk(result);
807
+ assert.deepEqual(result, 123);
808
+ });
809
+
810
+ it('custom result - object', async () => {
811
+ mockedClient.resultStub.returns({
812
+ name: 'toto',
813
+ });
814
+
815
+ const query = mockedClient
816
+ .select('somethingA', 'somethingB')
817
+ .from('someTbale')
818
+ .where('someColumn', 'someValue')
819
+ .orderBy('somethingB');
820
+
821
+ const result: any = await query;
822
+ assert.isOk(result);
823
+ assert.deepEqual(result, {
824
+ name: 'toto',
825
+ });
826
+ });
827
+
828
+ it('custom result - array', async () => {
829
+ mockedClient.resultStub.returns([
830
+ {
831
+ name: 'toto',
832
+ },
833
+ {
834
+ name: 'titi',
835
+ },
836
+ ]);
837
+
838
+ const query = mockedClient
839
+ .select('somethingA', 'somethingB')
840
+ .from('someTbale')
841
+ .where('someColumn', 'someValue')
842
+ .orderBy('somethingB');
843
+
844
+ const result = await query;
845
+ assert.isOk(result);
846
+ assert.deepEqual(result, [
847
+ {
848
+ name: 'toto',
849
+ },
850
+ {
851
+ name: 'titi',
852
+ },
853
+ ]);
854
+ });
855
+
856
+ it('pagination - default', async () => {
857
+ const query = mockedClient
858
+ .select('somethingA', 'somethingB')
859
+ .from('someTbale')
860
+ .where('someColumn', 'someValue')
861
+ .orderBy('somethingB');
862
+
863
+ const paginatedResult = await knexUtils.paginate(mockedClient, query, 0, 10);
864
+ assert.isTrue(isPaginatedResult(paginatedResult));
865
+
866
+ assert.strictEqual(paginatedResult.paging.offset, 0);
867
+ assert.strictEqual(paginatedResult.paging.limit, 10);
868
+ assert.strictEqual(paginatedResult.paging.totalCount, 0);
869
+ assert.strictEqual(paginatedResult.items.length, 0);
870
+ });
871
+
872
+ it('pagination - custom totalCount', async () => {
873
+ const query = mockedClient
874
+ .select('somethingA', 'somethingB')
875
+ .from('someTbale')
876
+ .where('someColumn', 'someValue')
877
+ .orderBy('somethingB');
878
+ mockedClient.totalCountStub.returns(123);
879
+
880
+ const paginatedResult = await knexUtils.paginate(mockedClient, query, 0, 10);
881
+ assert.isTrue(isPaginatedResult(paginatedResult));
882
+
883
+ assert.strictEqual(paginatedResult.paging.offset, 0);
884
+ assert.strictEqual(paginatedResult.paging.limit, 10);
885
+ assert.strictEqual(paginatedResult.paging.totalCount, 123);
886
+ assert.strictEqual(paginatedResult.items.length, 0);
887
+ });
888
+
889
+ it('pagination - full example', async () => {
890
+ mockedClient.resultStub.returns([
891
+ {
892
+ name: 'toto',
893
+ },
894
+ {
895
+ name: 'titi',
896
+ },
897
+ ]);
898
+
899
+ const query = mockedClient
900
+ .select('somethingA', 'somethingB')
901
+ .from('someTbale')
902
+ .where('someColumn', 'someValue')
903
+ .orderBy('somethingB');
904
+ mockedClient.totalCountStub.returns(123);
905
+
906
+ const paginatedResult = await knexUtils.paginate(mockedClient, query, 3, 7);
907
+ assert.isTrue(isPaginatedResult(paginatedResult));
908
+
909
+ assert.strictEqual(paginatedResult.paging.offset, 3);
910
+ assert.strictEqual(paginatedResult.paging.limit, 7);
911
+ assert.strictEqual(paginatedResult.paging.totalCount, 123);
912
+ assert.strictEqual(paginatedResult.items.length, 2);
913
+
914
+ assert.deepEqual(paginatedResult.items, [
915
+ {
916
+ name: 'toto',
917
+ },
918
+ {
919
+ name: 'titi',
920
+ },
921
+ ]);
922
+
923
+ assert.isTrue(mockedClient.beforeQuerySpy.calledTwice);
924
+
925
+ const queryInfo: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
926
+ assert.isOk(queryInfo);
927
+ assert.isOk(queryInfo.sql);
928
+ assert.isOk(queryInfo.bindings);
929
+
930
+ const queryInfoCount: any = mockedClient.beforeQuerySpy.getCall(0).args[0];
931
+ assert.strictEqual(
932
+ queryInfoCount.sql,
933
+ 'select count(*) as `count` from (select `somethingA`, `somethingB` from `someTbale` where `someColumn` = ?) as `_knexSub` limit ?',
934
+ );
935
+ assert.strictEqual(queryInfoCount.bindings.length, 2);
936
+ assert.strictEqual(queryInfoCount.bindings[1], 1);
937
+
938
+ const queryInfoResultSet: any = mockedClient.beforeQuerySpy.getCall(1).args[0];
939
+ assert.strictEqual(
940
+ queryInfoResultSet.sql,
941
+ 'select `somethingA`, `somethingB` from `someTbale` where `someColumn` = ? order by `somethingB` asc limit ? offset ?',
942
+ );
943
+ assert.strictEqual(queryInfoResultSet.bindings.length, 3);
944
+ assert.strictEqual(queryInfoResultSet.bindings[1], 7);
945
+ assert.strictEqual(queryInfoResultSet.bindings[2], 3);
946
+ });
947
+
948
+ it('transaction - select', async () => {
949
+ mockedClient.resultStub.returns(123);
950
+
951
+ await mockedClient.transaction(async (trx) => {
952
+ const query = trx
953
+ .select('somethingA', 'somethingB')
954
+ .from('someTbale')
955
+ .where('someColumn', 'someValue')
956
+ .orderBy('somethingB');
957
+
958
+ const result: any = await query;
959
+ assert.isOk(result);
960
+ assert.deepEqual(result, 123);
961
+ });
962
+ });
963
+
964
+ it('transaction - update', async () => {
965
+ mockedClient.resultStub.returns(123);
966
+
967
+ await mockedClient.transaction(async (trx) => {
968
+ const query = trx('someTable')
969
+ .update({
970
+ someColumn: 'someValue2',
971
+ })
972
+ .where('someColumn', 'someValue');
973
+
974
+ const result: any = await query;
975
+ assert.isOk(result);
976
+ assert.deepEqual(result, 123);
977
+ });
978
+ });
979
+
980
+ it('transaction - insert', async () => {
981
+ mockedClient.resultStub.returns(123);
982
+
983
+ await mockedClient.transaction(async (trx) => {
984
+ const query = trx('someTable')
985
+ .insert({
986
+ someColumn: 'someValue2',
987
+ })
988
+ .returning('someColumn');
989
+
990
+ const result: any = await query;
991
+ assert.isOk(result);
992
+ assert.deepEqual(result, 123);
993
+ });
994
+ });
995
+ });
996
+
997
+ // ==========================================
998
+ // wrapWithOracleModificationkeywords
999
+ // ==========================================
1000
+ describe('- wrapWithOracleModificationkeywords()', () => {
1001
+ it('no convert, no lower', async () => {
1002
+ let result = knexUtils.wrapWithOracleModificationkeywords('test', false, false);
1003
+ assert.strictEqual(result, 'test');
1004
+
1005
+ result = knexUtils.wrapWithOracleModificationkeywords('?', false, false);
1006
+ assert.strictEqual(result, '?');
1007
+ });
1008
+
1009
+ it('convert, no lower', async () => {
1010
+ let result = knexUtils.wrapWithOracleModificationkeywords('test', true, false);
1011
+ assert.strictEqual(result, "CONVERT(test, 'US7ASCII', 'WE8ISO8859P1')");
1012
+
1013
+ result = knexUtils.wrapWithOracleModificationkeywords('?', true, false);
1014
+ assert.strictEqual(result, "CONVERT(?, 'US7ASCII', 'WE8ISO8859P1')");
1015
+ });
1016
+
1017
+ it('no convert, lower', async () => {
1018
+ let result = knexUtils.wrapWithOracleModificationkeywords('test', false, true);
1019
+ assert.strictEqual(result, 'LOWER(test)');
1020
+
1021
+ result = knexUtils.wrapWithOracleModificationkeywords('?', false, true);
1022
+ assert.strictEqual(result, 'LOWER(?)');
1023
+ });
1024
+
1025
+ it('convert, lower', async () => {
1026
+ let result = knexUtils.wrapWithOracleModificationkeywords('test', true, true);
1027
+ assert.strictEqual(result, "LOWER(CONVERT(test, 'US7ASCII', 'WE8ISO8859P1'))");
1028
+
1029
+ result = knexUtils.wrapWithOracleModificationkeywords('?', true, true);
1030
+ assert.strictEqual(result, "LOWER(CONVERT(?, 'US7ASCII', 'WE8ISO8859P1'))");
1031
+ });
1032
+ });
1033
+
1034
+ // ==========================================
1035
+ // addOracleLikeClause
1036
+ // ==========================================
1037
+ describe('- addOracleLikeClause()', () => {
1038
+ let queryBuilder: Knex.QueryBuilder;
1039
+
1040
+ beforeEach(async () => {
1041
+ queryBuilder = mockedClient.select('titi');
1042
+ });
1043
+
1044
+ it('no convert, no lower, no wildcard', async () => {
1045
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val', false, false);
1046
+ assert.strictEqual(result.toQuery(), "select `titi` where `test` = 'val'");
1047
+ });
1048
+
1049
+ it('no convert, no lower, wildcard left', async () => {
1050
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val', false, false);
1051
+ assert.strictEqual(result.toQuery(), "select `titi` where test LIKE '%' || 'val'");
1052
+ });
1053
+
1054
+ it('no convert, no lower, wildcard right', async () => {
1055
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val*', false, false);
1056
+ assert.strictEqual(result.toQuery(), "select `titi` where test LIKE 'val' || '%'");
1057
+ });
1058
+
1059
+ it('no convert, no lower, wildcard left right', async () => {
1060
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val*', false, false);
1061
+ assert.strictEqual(result.toQuery(), "select `titi` where test LIKE '%' || 'val' || '%'");
1062
+ });
1063
+
1064
+ // ---
1065
+
1066
+ it('convert, no lower, no wildcard', async () => {
1067
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val', true, false);
1068
+ assert.strictEqual(
1069
+ result.toQuery(),
1070
+ "select `titi` where CONVERT(test, 'US7ASCII', 'WE8ISO8859P1') LIKE CONVERT('val', 'US7ASCII', 'WE8ISO8859P1')",
1071
+ );
1072
+ });
1073
+
1074
+ it('convert, no lower, wildcard left', async () => {
1075
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val', true, false);
1076
+ assert.strictEqual(
1077
+ result.toQuery(),
1078
+ "select `titi` where CONVERT(test, 'US7ASCII', 'WE8ISO8859P1') LIKE '%' || CONVERT('val', 'US7ASCII', 'WE8ISO8859P1')",
1079
+ );
1080
+ });
1081
+
1082
+ it('convert, no lower, wildcard right', async () => {
1083
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val*', true, false);
1084
+ assert.strictEqual(
1085
+ result.toQuery(),
1086
+ "select `titi` where CONVERT(test, 'US7ASCII', 'WE8ISO8859P1') LIKE CONVERT('val', 'US7ASCII', 'WE8ISO8859P1') || '%'",
1087
+ );
1088
+ });
1089
+
1090
+ it('convert, no lower, wildcard left right', async () => {
1091
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val*', true, false);
1092
+ assert.strictEqual(
1093
+ result.toQuery(),
1094
+ "select `titi` where CONVERT(test, 'US7ASCII', 'WE8ISO8859P1') LIKE '%' || CONVERT('val', 'US7ASCII', 'WE8ISO8859P1') || '%'",
1095
+ );
1096
+ });
1097
+
1098
+ // ---
1099
+
1100
+ it('no convert, lower, no wildcard', async () => {
1101
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val', false, true);
1102
+ assert.strictEqual(result.toQuery(), "select `titi` where LOWER(test) LIKE LOWER('val')");
1103
+ });
1104
+
1105
+ it('no convert, lower, wildcard left', async () => {
1106
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val', false, true);
1107
+ assert.strictEqual(
1108
+ result.toQuery(),
1109
+ "select `titi` where LOWER(test) LIKE '%' || LOWER('val')",
1110
+ );
1111
+ });
1112
+
1113
+ it('no convert, lower, wildcard right', async () => {
1114
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val*', false, true);
1115
+ assert.strictEqual(
1116
+ result.toQuery(),
1117
+ "select `titi` where LOWER(test) LIKE LOWER('val') || '%'",
1118
+ );
1119
+ });
1120
+
1121
+ it('no convert, lower, wildcard left right', async () => {
1122
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val*', false, true);
1123
+ assert.strictEqual(
1124
+ result.toQuery(),
1125
+ "select `titi` where LOWER(test) LIKE '%' || LOWER('val') || '%'",
1126
+ );
1127
+ });
1128
+
1129
+ // ---
1130
+
1131
+ it('convert, lower, no wildcard', async () => {
1132
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val', true, true);
1133
+ assert.strictEqual(
1134
+ result.toQuery(),
1135
+ "select `titi` where LOWER(CONVERT(test, 'US7ASCII', 'WE8ISO8859P1')) LIKE LOWER(CONVERT('val', 'US7ASCII', 'WE8ISO8859P1'))",
1136
+ );
1137
+ });
1138
+
1139
+ it('convert, lower, wildcard left', async () => {
1140
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val', true, true);
1141
+ assert.strictEqual(
1142
+ result.toQuery(),
1143
+ "select `titi` where LOWER(CONVERT(test, 'US7ASCII', 'WE8ISO8859P1')) LIKE '%' || LOWER(CONVERT('val', 'US7ASCII', 'WE8ISO8859P1'))",
1144
+ );
1145
+ });
1146
+
1147
+ it('convert, lower, wildcard right', async () => {
1148
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', 'val*', true, true);
1149
+ assert.strictEqual(
1150
+ result.toQuery(),
1151
+ "select `titi` where LOWER(CONVERT(test, 'US7ASCII', 'WE8ISO8859P1')) LIKE LOWER(CONVERT('val', 'US7ASCII', 'WE8ISO8859P1')) || '%'",
1152
+ );
1153
+ });
1154
+
1155
+ it('convert, lower, wildcard left right', async () => {
1156
+ const result = knexUtils.addOracleLikeClause(queryBuilder, 'test', '*val*', true, true);
1157
+ assert.strictEqual(
1158
+ result.toQuery(),
1159
+ "select `titi` where LOWER(CONVERT(test, 'US7ASCII', 'WE8ISO8859P1')) LIKE '%' || LOWER(CONVERT('val', 'US7ASCII', 'WE8ISO8859P1')) || '%'",
1160
+ );
1161
+ });
1162
+ });
1163
+
1164
+ // ==========================================
1165
+ // wrapWithSqlServerModificationKeywords
1166
+ // ==========================================
1167
+ describe('- wrapWithSqlServerModificationKeywords()', () => {
1168
+ it('no convert, no lower', async () => {
1169
+ let result = knexUtils.wrapWithSqlServerModificationKeywords('test', false, false);
1170
+ assert.strictEqual(result, 'test');
1171
+
1172
+ result = knexUtils.wrapWithSqlServerModificationKeywords('?', false, false);
1173
+ assert.strictEqual(result, '?');
1174
+ });
1175
+
1176
+ it('convert, no lower', async () => {
1177
+ let result = knexUtils.wrapWithSqlServerModificationKeywords('test', true, false);
1178
+ assert.strictEqual(
1179
+ result,
1180
+ `CAST(` +
1181
+ `REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')` +
1182
+ `AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS`,
1183
+ );
1184
+
1185
+ result = knexUtils.wrapWithSqlServerModificationKeywords('?', true, false);
1186
+ assert.strictEqual(
1187
+ result,
1188
+ `CAST(` +
1189
+ `REPLACE(REPLACE(REPLACE(REPLACE(?, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')` +
1190
+ `AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS`,
1191
+ );
1192
+ });
1193
+
1194
+ it('no convert, lower', async () => {
1195
+ let result = knexUtils.wrapWithSqlServerModificationKeywords('test', false, true);
1196
+ assert.strictEqual(result, 'LOWER(test)');
1197
+
1198
+ result = knexUtils.wrapWithSqlServerModificationKeywords('?', false, true);
1199
+ assert.strictEqual(result, 'LOWER(?)');
1200
+ });
1201
+
1202
+ it('convert, lower', async () => {
1203
+ let result = knexUtils.wrapWithSqlServerModificationKeywords('test', true, true);
1204
+ assert.strictEqual(
1205
+ result,
1206
+ `LOWER(CAST(` +
1207
+ `REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')` +
1208
+ `AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS)`,
1209
+ );
1210
+
1211
+ result = knexUtils.wrapWithSqlServerModificationKeywords('?', true, true);
1212
+ assert.strictEqual(
1213
+ result,
1214
+ `LOWER(CAST(` +
1215
+ `REPLACE(REPLACE(REPLACE(REPLACE(?, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')` +
1216
+ `AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS)`,
1217
+ );
1218
+ });
1219
+ });
1220
+
1221
+ // ==========================================
1222
+ // addSqlServerLikeClause
1223
+ // ==========================================
1224
+ describe('- addSqlServerLikeClause()', () => {
1225
+ let queryBuilder: Knex.QueryBuilder;
1226
+
1227
+ beforeEach(async () => {
1228
+ queryBuilder = mockedClient.select('titi');
1229
+ });
1230
+
1231
+ describe('- wildcards allowed', () => {
1232
+ it('no convert, no lower, no wildcard', async () => {
1233
+ const result = knexUtils.addSqlServerLikeClause(
1234
+ queryBuilder,
1235
+ 'test',
1236
+ 'val',
1237
+ true,
1238
+ false,
1239
+ false,
1240
+ );
1241
+ assert.strictEqual(result.toQuery(), "select `titi` where `test` = 'val'");
1242
+ });
1243
+
1244
+ it('no convert, no lower, wildcard left', async () => {
1245
+ const result = knexUtils.addSqlServerLikeClause(
1246
+ queryBuilder,
1247
+ 'test',
1248
+ '*val',
1249
+ true,
1250
+ false,
1251
+ false,
1252
+ );
1253
+ assert.strictEqual(result.toQuery(), "select `titi` where test LIKE '%' + 'val'");
1254
+ });
1255
+
1256
+ it('no convert, no lower, wildcard right', async () => {
1257
+ const result = knexUtils.addSqlServerLikeClause(
1258
+ queryBuilder,
1259
+ 'test',
1260
+ 'val*',
1261
+ true,
1262
+ false,
1263
+ false,
1264
+ );
1265
+ assert.strictEqual(result.toQuery(), "select `titi` where test LIKE 'val' + '%'");
1266
+ });
1267
+
1268
+ it('no convert, no lower, wildcard left right', async () => {
1269
+ const result = knexUtils.addSqlServerLikeClause(
1270
+ queryBuilder,
1271
+ 'test',
1272
+ '*val*',
1273
+ true,
1274
+ false,
1275
+ false,
1276
+ );
1277
+ assert.strictEqual(result.toQuery(), "select `titi` where test LIKE '%' + 'val' + '%'");
1278
+ });
1279
+
1280
+ // ---
1281
+
1282
+ it('convert, no lower, no wildcard', async () => {
1283
+ const result = knexUtils.addSqlServerLikeClause(
1284
+ queryBuilder,
1285
+ 'test',
1286
+ 'val',
1287
+ true,
1288
+ true,
1289
+ false,
1290
+ );
1291
+ assert.strictEqual(
1292
+ result.toQuery(),
1293
+ 'select `titi` where CAST(' +
1294
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1295
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS ' +
1296
+ 'LIKE CAST(' +
1297
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1298
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS',
1299
+ );
1300
+ });
1301
+
1302
+ it('convert, no lower, wildcard left', async () => {
1303
+ const result = knexUtils.addSqlServerLikeClause(
1304
+ queryBuilder,
1305
+ 'test',
1306
+ '*val',
1307
+ true,
1308
+ true,
1309
+ false,
1310
+ );
1311
+ assert.strictEqual(
1312
+ result.toQuery(),
1313
+ 'select `titi` where CAST(' +
1314
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1315
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS ' +
1316
+ "LIKE '%' + CAST(" +
1317
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1318
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS',
1319
+ );
1320
+ });
1321
+
1322
+ it('convert, no lower, wildcard right', async () => {
1323
+ const result = knexUtils.addSqlServerLikeClause(
1324
+ queryBuilder,
1325
+ 'test',
1326
+ 'val*',
1327
+ true,
1328
+ true,
1329
+ false,
1330
+ );
1331
+ assert.strictEqual(
1332
+ result.toQuery(),
1333
+ 'select `titi` where CAST(' +
1334
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1335
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS ' +
1336
+ 'LIKE CAST(' +
1337
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1338
+ "AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS + '%'",
1339
+ );
1340
+ });
1341
+
1342
+ it('convert, no lower, wildcard left right', async () => {
1343
+ const result = knexUtils.addSqlServerLikeClause(
1344
+ queryBuilder,
1345
+ 'test',
1346
+ '*val*',
1347
+ true,
1348
+ true,
1349
+ false,
1350
+ );
1351
+ assert.strictEqual(
1352
+ result.toQuery(),
1353
+ 'select `titi` where CAST(' +
1354
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1355
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS ' +
1356
+ "LIKE '%' + CAST(" +
1357
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1358
+ "AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS + '%'",
1359
+ );
1360
+ });
1361
+
1362
+ // ---
1363
+
1364
+ it('no convert, lower, no wildcard', async () => {
1365
+ const result = knexUtils.addSqlServerLikeClause(
1366
+ queryBuilder,
1367
+ 'test',
1368
+ 'val',
1369
+ true,
1370
+ false,
1371
+ true,
1372
+ );
1373
+ assert.strictEqual(result.toQuery(), "select `titi` where LOWER(test) LIKE LOWER('val')");
1374
+ });
1375
+
1376
+ it('no convert, lower, wildcard left', async () => {
1377
+ const result = knexUtils.addSqlServerLikeClause(
1378
+ queryBuilder,
1379
+ 'test',
1380
+ '*val',
1381
+ true,
1382
+ false,
1383
+ true,
1384
+ );
1385
+ assert.strictEqual(
1386
+ result.toQuery(),
1387
+ "select `titi` where LOWER(test) LIKE '%' + LOWER('val')",
1388
+ );
1389
+ });
1390
+
1391
+ it('no convert, lower, wildcard right', async () => {
1392
+ const result = knexUtils.addSqlServerLikeClause(
1393
+ queryBuilder,
1394
+ 'test',
1395
+ 'val*',
1396
+ true,
1397
+ false,
1398
+ true,
1399
+ );
1400
+ assert.strictEqual(
1401
+ result.toQuery(),
1402
+ "select `titi` where LOWER(test) LIKE LOWER('val') + '%'",
1403
+ );
1404
+ });
1405
+
1406
+ it('no convert, lower, wildcard left right', async () => {
1407
+ const result = knexUtils.addSqlServerLikeClause(
1408
+ queryBuilder,
1409
+ 'test',
1410
+ '*val*',
1411
+ true,
1412
+ false,
1413
+ true,
1414
+ );
1415
+ assert.strictEqual(
1416
+ result.toQuery(),
1417
+ "select `titi` where LOWER(test) LIKE '%' + LOWER('val') + '%'",
1418
+ );
1419
+ });
1420
+
1421
+ // ---
1422
+
1423
+ it('convert, lower, no wildcard', async () => {
1424
+ const result = knexUtils.addSqlServerLikeClause(
1425
+ queryBuilder,
1426
+ 'test',
1427
+ 'val',
1428
+ true,
1429
+ true,
1430
+ true,
1431
+ );
1432
+ assert.strictEqual(
1433
+ result.toQuery(),
1434
+ 'select `titi` where LOWER(CAST(' +
1435
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1436
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) ' +
1437
+ 'LIKE LOWER(CAST(' +
1438
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1439
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS)',
1440
+ );
1441
+ });
1442
+
1443
+ it('convert, lower, wildcard left', async () => {
1444
+ const result = knexUtils.addSqlServerLikeClause(
1445
+ queryBuilder,
1446
+ 'test',
1447
+ '*val',
1448
+ true,
1449
+ true,
1450
+ true,
1451
+ );
1452
+ assert.strictEqual(
1453
+ result.toQuery(),
1454
+ 'select `titi` where LOWER(CAST(' +
1455
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1456
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) ' +
1457
+ "LIKE '%' + LOWER(CAST(" +
1458
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1459
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS)',
1460
+ );
1461
+ });
1462
+
1463
+ it('convert, lower, wildcard right', async () => {
1464
+ const result = knexUtils.addSqlServerLikeClause(
1465
+ queryBuilder,
1466
+ 'test',
1467
+ 'val*',
1468
+ true,
1469
+ true,
1470
+ true,
1471
+ );
1472
+ assert.strictEqual(
1473
+ result.toQuery(),
1474
+ 'select `titi` where LOWER(CAST(' +
1475
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1476
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) ' +
1477
+ 'LIKE LOWER(CAST(' +
1478
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1479
+ "AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) + '%'",
1480
+ );
1481
+ });
1482
+
1483
+ it('convert, lower, wildcard left right', async () => {
1484
+ const result = knexUtils.addSqlServerLikeClause(
1485
+ queryBuilder,
1486
+ 'test',
1487
+ '*val*',
1488
+ true,
1489
+ true,
1490
+ true,
1491
+ );
1492
+ assert.strictEqual(
1493
+ result.toQuery(),
1494
+ 'select `titi` where LOWER(CAST(' +
1495
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1496
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) ' +
1497
+ "LIKE '%' + LOWER(CAST(" +
1498
+ "REPLACE(REPLACE(REPLACE(REPLACE('val', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1499
+ "AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) + '%'",
1500
+ );
1501
+ });
1502
+ });
1503
+
1504
+ describe('- no wildcards allowed', () => {
1505
+ it('no convert, no lower, no wildcard', async () => {
1506
+ const result = knexUtils.addSqlServerLikeClause(
1507
+ queryBuilder,
1508
+ 'test',
1509
+ '*val*',
1510
+ false,
1511
+ true,
1512
+ true,
1513
+ );
1514
+ assert.strictEqual(
1515
+ result.toQuery(),
1516
+ 'select `titi` where LOWER(CAST(' +
1517
+ "REPLACE(REPLACE(REPLACE(REPLACE(test, 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1518
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS) ' +
1519
+ 'LIKE LOWER(CAST(' +
1520
+ "REPLACE(REPLACE(REPLACE(REPLACE('*val*', 'œ', 'oe'), 'Œ', 'OE'), 'æ', 'ae'), 'Æ', 'AE')" +
1521
+ 'AS VARCHAR(max)) COLLATE SQL_Latin1_General_Cp1251_CS_AS)',
1522
+ );
1523
+ });
1524
+ });
1525
+ });
1526
+ });