@platformatic/sql-mapper 0.45.1 → 0.46.2

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.
@@ -1,889 +0,0 @@
1
- 'use strict'
2
-
3
- const { test } = require('tap')
4
- const { connect } = require('..')
5
- const { clear, connInfo, isMysql, isSQLite } = require('./helper')
6
-
7
- const fakeLogger = {
8
- trace: () => {},
9
- error: () => {}
10
- }
11
-
12
- test('list', async ({ pass, teardown, same, rejects }) => {
13
- const mapper = await connect({
14
- ...connInfo,
15
- log: fakeLogger,
16
- async onDatabaseLoad (db, sql) {
17
- teardown(() => db.dispose())
18
- pass('onDatabaseLoad called')
19
-
20
- await clear(db, sql)
21
-
22
- if (isSQLite) {
23
- await db.query(sql`CREATE TABLE posts (
24
- id INTEGER PRIMARY KEY,
25
- title VARCHAR(42),
26
- long_text TEXT,
27
- counter INTEGER
28
- );`)
29
- } else {
30
- await db.query(sql`CREATE TABLE posts (
31
- id SERIAL PRIMARY KEY,
32
- title VARCHAR(42),
33
- long_text TEXT,
34
- counter INTEGER
35
- );`)
36
- }
37
- }
38
- })
39
-
40
- const entity = mapper.entities.post
41
-
42
- const posts = [{
43
- title: 'Dog',
44
- longText: 'Foo',
45
- counter: 10
46
- }, {
47
- title: 'Cat',
48
- longText: 'Bar',
49
- counter: 20
50
- }, {
51
- title: 'Mouse',
52
- longText: 'Baz',
53
- counter: 30
54
- }, {
55
- title: 'Duck',
56
- longText: 'A duck tale',
57
- counter: 40
58
- }]
59
-
60
- await entity.insert({
61
- inputs: posts
62
- })
63
-
64
- rejects(entity.find.bind(entity, { where: { invalidField: { eq: 'Dog' } } }), 'Unknown field invalidField')
65
-
66
- same(await entity.find({ where: { title: { eq: 'Dog' } }, fields: ['id', 'title', 'longText'] }), [{
67
- id: '1',
68
- title: 'Dog',
69
- longText: 'Foo'
70
- }])
71
-
72
- same(await entity.find({ limit: 1, fields: ['id', 'title', 'longText'] }), [{
73
- id: '1',
74
- title: 'Dog',
75
- longText: 'Foo'
76
- }])
77
-
78
- same(await entity.find({ offset: 3, fields: ['id', 'title', 'longText'] }), [{
79
- id: '4',
80
- title: 'Duck',
81
- longText: 'A duck tale'
82
- }])
83
-
84
- same(await entity.find({ limit: 1, offset: 0, fields: ['id', 'title', 'longText'] }), [{
85
- id: '1',
86
- title: 'Dog',
87
- longText: 'Foo'
88
- }])
89
-
90
- same(await entity.find({ limit: 1, offset: 0, orderBy: [{ field: 'id', direction: 'desc' }], fields: ['id', 'title'] }), [{
91
- id: '4',
92
- title: 'Duck'
93
- }])
94
-
95
- same(await entity.find({ where: { title: { neq: 'Dog' } }, fields: ['id', 'title', 'longText'] }), [{
96
- id: '2',
97
- title: 'Cat',
98
- longText: 'Bar'
99
- }, {
100
- id: '3',
101
- title: 'Mouse',
102
- longText: 'Baz'
103
- }, {
104
- id: '4',
105
- title: 'Duck',
106
- longText: 'A duck tale'
107
- }])
108
-
109
- same(await entity.find({ where: { counter: { gt: 10 } }, fields: ['id', 'title', 'longText'] }), [{
110
- id: '2',
111
- title: 'Cat',
112
- longText: 'Bar'
113
- }, {
114
- id: '3',
115
- title: 'Mouse',
116
- longText: 'Baz'
117
- }, {
118
- id: '4',
119
- title: 'Duck',
120
- longText: 'A duck tale'
121
- }])
122
-
123
- same(await entity.find({ where: { counter: { lt: 40 } }, fields: ['id', 'title', 'longText'] }), [{
124
- id: '1',
125
- title: 'Dog',
126
- longText: 'Foo'
127
- }, {
128
- id: '2',
129
- title: 'Cat',
130
- longText: 'Bar'
131
- }, {
132
- id: '3',
133
- title: 'Mouse',
134
- longText: 'Baz'
135
- }])
136
-
137
- same(await entity.find({ where: { counter: { lte: 30 } }, fields: ['id', 'title', 'longText'] }), [{
138
- id: '1',
139
- title: 'Dog',
140
- longText: 'Foo'
141
- }, {
142
- id: '2',
143
- title: 'Cat',
144
- longText: 'Bar'
145
- }, {
146
- id: '3',
147
- title: 'Mouse',
148
- longText: 'Baz'
149
- }])
150
-
151
- same(await entity.find({ where: { counter: { gte: 20 } }, fields: ['id', 'title', 'longText'] }), [{
152
- id: '2',
153
- title: 'Cat',
154
- longText: 'Bar'
155
- }, {
156
- id: '3',
157
- title: 'Mouse',
158
- longText: 'Baz'
159
- }, {
160
- id: '4',
161
- title: 'Duck',
162
- longText: 'A duck tale'
163
- }])
164
-
165
- same(await entity.find({ where: { counter: { in: [20, 30] } }, fields: ['id', 'title', 'longText'] }), [{
166
- id: '2',
167
- title: 'Cat',
168
- longText: 'Bar'
169
- }, {
170
- id: '3',
171
- title: 'Mouse',
172
- longText: 'Baz'
173
- }])
174
-
175
- same(await entity.find({ where: { counter: { nin: [10, 40] } }, fields: ['id', 'title', 'longText'] }), [{
176
- id: '2',
177
- title: 'Cat',
178
- longText: 'Bar'
179
- }, {
180
- id: '3',
181
- title: 'Mouse',
182
- longText: 'Baz'
183
- }])
184
-
185
- same(await entity.find({ where: { counter: { gt: 10, lt: 40 } }, fields: ['id', 'title', 'longText'] }), [{
186
- id: '2',
187
- title: 'Cat',
188
- longText: 'Bar'
189
- }, {
190
- id: '3',
191
- title: 'Mouse',
192
- longText: 'Baz'
193
- }])
194
- })
195
-
196
- test('totalCount', async ({ pass, teardown, same, equal }) => {
197
- const mapper = await connect({
198
- ...connInfo,
199
- log: fakeLogger,
200
- async onDatabaseLoad (db, sql) {
201
- teardown(() => db.dispose())
202
- pass('onDatabaseLoad called')
203
-
204
- await clear(db, sql)
205
-
206
- if (isSQLite) {
207
- await db.query(sql`CREATE TABLE posts (
208
- id INTEGER PRIMARY KEY,
209
- title VARCHAR(42),
210
- long_text TEXT,
211
- counter INTEGER
212
- );`)
213
- } else {
214
- await db.query(sql`CREATE TABLE posts (
215
- id SERIAL PRIMARY KEY,
216
- title VARCHAR(42),
217
- long_text TEXT,
218
- counter INTEGER
219
- );`)
220
- }
221
- }
222
- })
223
-
224
- const entity = mapper.entities.post
225
-
226
- const posts = [{
227
- title: 'Dog',
228
- longText: 'Foo',
229
- counter: 10
230
- }, {
231
- title: 'Cat',
232
- longText: 'Bar',
233
- counter: 20
234
- }, {
235
- title: 'Mouse',
236
- longText: 'Baz',
237
- counter: 30
238
- }, {
239
- title: 'Duck',
240
- longText: 'A duck tale',
241
- counter: 40
242
- }]
243
-
244
- await entity.insert({
245
- inputs: posts
246
- })
247
-
248
- same(await entity.count(), 4)
249
-
250
- same(await entity.count({ where: { title: { eq: 'Dog' } } }), 1)
251
-
252
- same(await entity.count({ where: { title: { neq: 'Dog' } } }), 3)
253
-
254
- same(await entity.count({ limit: 2, offset: 0, fields: ['id', 'title', 'longText'] }), 4)
255
- })
256
-
257
- test('foreign keys', async ({ pass, teardown, same, equal }) => {
258
- const mapper = await connect({
259
- ...connInfo,
260
- log: fakeLogger,
261
- async onDatabaseLoad (db, sql) {
262
- teardown(() => db.dispose())
263
- pass('onDatabaseLoad called')
264
-
265
- await clear(db, sql)
266
-
267
- if (isMysql) {
268
- await db.query(sql`
269
- CREATE TABLE owners (
270
- id SERIAL PRIMARY KEY,
271
- name VARCHAR(255)
272
- );
273
- CREATE TABLE posts (
274
- id SERIAL PRIMARY KEY,
275
- title VARCHAR(42),
276
- long_text TEXT,
277
- counter INTEGER,
278
- owner_id BIGINT UNSIGNED,
279
- FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE
280
- );
281
- `)
282
- } else if (isSQLite) {
283
- await db.query(sql`
284
- CREATE TABLE owners (
285
- id INTEGER PRIMARY KEY,
286
- name VARCHAR(255)
287
- );
288
- `)
289
-
290
- await db.query(sql`
291
- CREATE TABLE posts (
292
- id INTEGER PRIMARY KEY,
293
- title VARCHAR(42),
294
- long_text TEXT,
295
- counter INTEGER,
296
- owner_id BIGINT UNSIGNED,
297
- FOREIGN KEY (owner_id) REFERENCES owners(id) ON DELETE CASCADE
298
- );
299
- `)
300
- } else {
301
- await db.query(sql`
302
- CREATE TABLE owners (
303
- id SERIAL PRIMARY KEY,
304
- name VARCHAR(255)
305
- );
306
- CREATE TABLE posts (
307
- id SERIAL PRIMARY KEY,
308
- title VARCHAR(42),
309
- long_text TEXT,
310
- counter INTEGER,
311
- owner_id INTEGER REFERENCES owners(id)
312
- );`)
313
- }
314
- }
315
- })
316
-
317
- const owners = [{
318
- name: 'Matteo'
319
- }, {
320
- name: 'Luca'
321
- }]
322
-
323
- const posts = [{
324
- title: 'Dog',
325
- longText: 'Foo',
326
- counter: 10
327
- }, {
328
- title: 'Cat',
329
- longText: 'Bar',
330
- counter: 20
331
- }, {
332
- title: 'Mouse',
333
- longText: 'Baz',
334
- counter: 30
335
- }, {
336
- title: 'Duck',
337
- longText: 'A duck tale',
338
- counter: 40
339
- }]
340
-
341
- {
342
- const res = await mapper.entities.owner.insert({
343
- inputs: owners
344
- })
345
- const toAssign = [...posts]
346
- for (const owner of res) {
347
- toAssign.shift().ownerId = owner.id
348
- toAssign.shift().ownerId = owner.id
349
- }
350
- await mapper.entities.post.insert({
351
- inputs: posts
352
- })
353
- }
354
-
355
- {
356
- const owners = await mapper.entities.owner.find()
357
- equal(owners.length, 2)
358
-
359
- for (const owner of owners) {
360
- owner.posts = await mapper.entities.post.find({ where: { ownerId: { eq: owner.id } }, fields: ['id', 'title', 'longText', 'ownerId'] })
361
- }
362
- same(owners, [{
363
- id: '1',
364
- name: 'Matteo',
365
- posts: [{
366
- id: '1',
367
- title: 'Dog',
368
- longText: 'Foo',
369
- ownerId: '1'
370
- }, {
371
- id: '2',
372
- title: 'Cat',
373
- longText: 'Bar',
374
- ownerId: '1'
375
- }]
376
- }, {
377
- id: '2',
378
- name: 'Luca',
379
- posts: [{
380
- id: '3',
381
- title: 'Mouse',
382
- longText: 'Baz',
383
- ownerId: '2'
384
- }, {
385
- id: '4',
386
- title: 'Duck',
387
- longText: 'A duck tale',
388
- ownerId: '2'
389
- }]
390
- }])
391
- }
392
- })
393
-
394
- test('limit should be 10 by default 100 at max', async ({ pass, teardown, same, fail, match }) => {
395
- const mapper = await connect({
396
- ...connInfo,
397
- log: fakeLogger,
398
- async onDatabaseLoad (db, sql) {
399
- teardown(() => db.dispose())
400
- pass('onDatabaseLoad called')
401
-
402
- await clear(db, sql)
403
-
404
- if (isSQLite) {
405
- await db.query(sql`CREATE TABLE posts (
406
- id INTEGER PRIMARY KEY,
407
- title VARCHAR(42),
408
- long_text TEXT,
409
- counter INTEGER
410
- );`)
411
- } else {
412
- await db.query(sql`CREATE TABLE posts (
413
- id SERIAL PRIMARY KEY,
414
- title VARCHAR(42),
415
- long_text TEXT,
416
- counter INTEGER
417
- );`)
418
- }
419
- }
420
- })
421
-
422
- const entity = mapper.entities.post
423
-
424
- const posts = []
425
-
426
- for (let i = 0; i <= 105; i++) {
427
- posts.push({
428
- title: 'Dog',
429
- longText: 'Foo',
430
- counter: i
431
- })
432
- }
433
-
434
- await entity.insert({
435
- inputs: posts
436
- })
437
-
438
- const defaultLimit = 10
439
- const max = 100
440
-
441
- same(await (await entity.find()).length, defaultLimit)
442
-
443
- same(await (await entity.find({ limit: 1 })).length, 1)
444
-
445
- same(await (await entity.find({ offset: 3 })).length, defaultLimit)
446
-
447
- same(await (await entity.find({ limit: 1, offset: 0 })).length, 1)
448
-
449
- same(await (await entity.find({ limit: 0 })).length, 0)
450
-
451
- try {
452
- await entity.find({ limit: -1 })
453
- fail('Expected error for limit not allowed value')
454
- } catch (e) {
455
- match(e.message, 'Param limit=-1 not allowed. It must be a not negative value.')
456
- match(e.code, 'PLT_SQL_MAPPER_PARAM_LIMIT_MUST_BE_NOT_NEGATIVE')
457
- }
458
-
459
- same(await (await entity.find({ limit: 1, offset: 0 })).length, 1)
460
-
461
- try {
462
- await entity.find({ limit: 1, offset: -1 })
463
- fail('Expected error for offset not allowed value')
464
- } catch (e) {
465
- match(e, new Error('Param offset=-1 not allowed. It must be not negative value.'))
466
- }
467
-
468
- try {
469
- await entity.find({ limit: 200 })
470
- fail('Expected error for limit exceeding max allowed value')
471
- } catch (e) {
472
- match(e, new Error(`Param limit=200 not allowed. Max accepted value ${max}.`))
473
- }
474
- })
475
-
476
- test('limit must accept custom configuration', async ({ pass, teardown, same, fail, match }) => {
477
- const customLimitConf = {
478
- default: 1,
479
- max: 5
480
- }
481
- const mapper = await connect({
482
- ...connInfo,
483
- log: fakeLogger,
484
- async onDatabaseLoad (db, sql) {
485
- teardown(() => db.dispose())
486
- pass('onDatabaseLoad called')
487
-
488
- await clear(db, sql)
489
-
490
- if (isSQLite) {
491
- await db.query(sql`CREATE TABLE posts (
492
- id INTEGER PRIMARY KEY,
493
- title VARCHAR(42),
494
- long_text TEXT,
495
- counter INTEGER
496
- );`)
497
- } else {
498
- await db.query(sql`CREATE TABLE posts (
499
- id SERIAL PRIMARY KEY,
500
- title VARCHAR(42),
501
- long_text TEXT,
502
- counter INTEGER
503
- );`)
504
- }
505
- },
506
- limit: customLimitConf
507
- })
508
-
509
- const entity = mapper.entities.post
510
-
511
- const posts = []
512
-
513
- for (let i = 0; i <= 10; i++) {
514
- posts.push({
515
- title: 'Dog',
516
- longText: 'Foo',
517
- counter: i
518
- })
519
- }
520
-
521
- await entity.insert({
522
- inputs: posts
523
- })
524
-
525
- same(await (await entity.find()).length, customLimitConf.default)
526
-
527
- same(await (await entity.find({ limit: 1 })).length, 1)
528
-
529
- same(await (await entity.find({ offset: 3 })).length, customLimitConf.default)
530
-
531
- same(await (await entity.find({ limit: 1, offset: 0 })).length, 1)
532
-
533
- same(await (await entity.find({ limit: 0 })).length, 0)
534
-
535
- try {
536
- await entity.find({ limit: -1 })
537
- fail('Expected error for limit not allowed value')
538
- } catch (e) {
539
- match(e.message, 'Param limit=-1 not allowed. It must be a not negative value.')
540
- match(e.code, 'PLT_SQL_MAPPER_PARAM_LIMIT_MUST_BE_NOT_NEGATIVE')
541
- }
542
-
543
- same(await (await entity.find({ limit: 1, offset: 0 })).length, 1)
544
-
545
- try {
546
- await entity.find({ limit: 1, offset: -1 })
547
- fail('Expected error for offset not allowed value')
548
- } catch (e) {
549
- match(e, new Error('Param offset=-1 not allowed. It must be not negative value.'))
550
- }
551
-
552
- try {
553
- await entity.find({ limit: 200 })
554
- fail('Expected error for limit exceeding max allowed value')
555
- } catch (e) {
556
- match(e, new Error(`Param limit=200 not allowed. Max accepted value ${customLimitConf.max}.`))
557
- }
558
- })
559
-
560
- test('is NULL', async ({ pass, teardown, same, equal }) => {
561
- const mapper = await connect({
562
- ...connInfo,
563
- log: fakeLogger,
564
- async onDatabaseLoad (db, sql) {
565
- teardown(() => db.dispose())
566
- pass('onDatabaseLoad called')
567
-
568
- await clear(db, sql)
569
-
570
- if (isSQLite) {
571
- await db.query(sql`CREATE TABLE posts (
572
- id INTEGER PRIMARY KEY,
573
- title VARCHAR(42)
574
- );`)
575
- } else {
576
- await db.query(sql`CREATE TABLE posts (
577
- id SERIAL PRIMARY KEY,
578
- title VARCHAR(42)
579
- );`)
580
- }
581
- }
582
- })
583
-
584
- const entity = mapper.entities.post
585
-
586
- const posts = [{
587
- title: 'Dog'
588
- }, {
589
- title: null
590
- }]
591
-
592
- await entity.insert({
593
- inputs: posts
594
- })
595
-
596
- same(await entity.find({ where: { title: { eq: null } } }), [{
597
- id: '2',
598
- title: null
599
- }])
600
-
601
- same(await entity.find({ where: { title: { neq: null } } }), [{
602
- id: '1',
603
- title: 'Dog'
604
- }])
605
- })
606
-
607
- test('LIKE', async ({ pass, teardown, same, equal }) => {
608
- const mapper = await connect({
609
- ...connInfo,
610
- log: fakeLogger,
611
- async onDatabaseLoad (db, sql) {
612
- teardown(() => db.dispose())
613
- pass('onDatabaseLoad called')
614
-
615
- await clear(db, sql)
616
-
617
- if (isSQLite) {
618
- await db.query(sql`CREATE TABLE posts (
619
- id INTEGER PRIMARY KEY,
620
- title VARCHAR(42),
621
- long_text TEXT,
622
- counter INTEGER
623
- );`)
624
- } else {
625
- await db.query(sql`CREATE TABLE posts (
626
- id SERIAL PRIMARY KEY,
627
- title VARCHAR(42),
628
- long_text TEXT,
629
- counter INTEGER
630
- );`)
631
- }
632
- }
633
- })
634
-
635
- const entity = mapper.entities.post
636
-
637
- const posts = [
638
- {
639
- title: 'Dog',
640
- longText: 'The Dog barks',
641
- counter: 1
642
- },
643
- {
644
- title: 'Cat',
645
- longText: 'The Cat meows',
646
- counter: 2
647
- },
648
- {
649
- title: 'Potato',
650
- longText: 'The Potato is vegetable',
651
- counter: 3
652
- },
653
- {
654
- title: 'atmosphere',
655
- longText: 'The atmosphere is not a sphere',
656
- counter: 4
657
- },
658
- {
659
- title: 'planet',
660
- longText: 'The planet have atmosphere',
661
- counter: 14
662
- }
663
- ]
664
-
665
- await entity.insert({
666
- inputs: posts
667
- })
668
-
669
- same(await entity.find({ where: { title: { like: '%at' } } }), [{
670
- id: '2',
671
- title: 'Cat',
672
- longText: 'The Cat meows',
673
- counter: 2
674
- }], 'where: { title: { like: \'%at\' } }')
675
-
676
- same(await entity.find({ where: { title: { like: '%at%' } } }), [{
677
- id: '2',
678
- title: 'Cat',
679
- longText: 'The Cat meows',
680
- counter: 2
681
- },
682
- {
683
- id: '3',
684
- title: 'Potato',
685
- longText: 'The Potato is vegetable',
686
- counter: 3
687
- },
688
- {
689
- id: '4',
690
- title: 'atmosphere',
691
- longText: 'The atmosphere is not a sphere',
692
- counter: 4
693
- }], 'where: { title: { like: \'%at%\' } }')
694
-
695
- same(await entity.find({ where: { title: { like: 'at%' } } }), [{
696
- id: '4',
697
- title: 'atmosphere',
698
- longText: 'The atmosphere is not a sphere',
699
- counter: 4
700
- }], 'where: { title: { like: \'at%\' } }')
701
-
702
- same(await entity.find({ where: { longText: { like: '%is%' } } }), [{
703
- id: '3',
704
- title: 'Potato',
705
- longText: 'The Potato is vegetable',
706
- counter: 3
707
- },
708
- {
709
- id: '4',
710
- title: 'atmosphere',
711
- longText: 'The atmosphere is not a sphere',
712
- counter: 4
713
- }], 'where: { longText: { like: \'%is%\' } }')
714
-
715
- same(await entity.find({ where: { longText: { like: null } } }), [], 'where: { longText: { like: null } }')
716
-
717
- if (!isSQLite) {
718
- same(await entity.find({ where: { counter: { like: 4 } } }), [{
719
- id: '4',
720
- title: 'atmosphere',
721
- longText: 'The atmosphere is not a sphere',
722
- counter: 4
723
- }], 'where: { counter: { like: 4 } }')
724
- }
725
-
726
- same(await entity.find({ where: { counter: { like: '%4' } } }), [{
727
- id: '4',
728
- title: 'atmosphere',
729
- longText: 'The atmosphere is not a sphere',
730
- counter: 4
731
- },
732
- {
733
- id: '5',
734
- title: 'planet',
735
- longText: 'The planet have atmosphere',
736
- counter: 14
737
- }], 'where: { counter: { like: \'%4\' } }')
738
-
739
- same(await entity.find({ where: { counter: { like: '4%' } } }), [{
740
- id: '4',
741
- title: 'atmosphere',
742
- longText: 'The atmosphere is not a sphere',
743
- counter: 4
744
- }], 'where: { counter: { like: \'4%\' } }')
745
-
746
- same(await entity.find({ where: { counter: { like: null } } }), [], 'where: { counter: { like: null } }')
747
- })
748
-
749
- test('ILIKE', async ({ pass, teardown, same, equal }) => {
750
- const mapper = await connect({
751
- ...connInfo,
752
- log: fakeLogger,
753
- async onDatabaseLoad (db, sql) {
754
- teardown(() => db.dispose())
755
- pass('onDatabaseLoad called')
756
-
757
- await clear(db, sql)
758
-
759
- if (isSQLite) {
760
- await db.query(sql`CREATE TABLE posts (
761
- id INTEGER PRIMARY KEY,
762
- title VARCHAR(42),
763
- long_text TEXT,
764
- counter INTEGER
765
- );`)
766
- } else {
767
- await db.query(sql`CREATE TABLE posts (
768
- id SERIAL PRIMARY KEY,
769
- title VARCHAR(42),
770
- long_text TEXT,
771
- counter INTEGER
772
- );`)
773
- }
774
- }
775
- })
776
-
777
- const entity = mapper.entities.post
778
-
779
- const posts = [
780
- {
781
- title: 'Dog',
782
- longText: 'The Dog barks',
783
- counter: 1
784
- },
785
- {
786
- title: 'Cat',
787
- longText: 'The Cat meows',
788
- counter: 2
789
- },
790
- {
791
- title: 'Potato',
792
- longText: 'The Potato is vegetable',
793
- counter: 3
794
- },
795
- {
796
- title: 'Atmosphere',
797
- longText: 'The atmosphere is not a sphere',
798
- counter: 4
799
- },
800
- {
801
- title: 'planet',
802
- longText: 'The planet have atmosphere',
803
- counter: 14
804
- }
805
- ]
806
-
807
- await entity.insert({
808
- inputs: posts
809
- })
810
-
811
- same(await entity.find({ where: { title: { ilike: '%at' } } }), [{
812
- id: '2',
813
- title: 'Cat',
814
- longText: 'The Cat meows',
815
- counter: 2
816
- }], 'where: { title: { like: \'%at\' } }')
817
-
818
- same(await entity.find({ where: { title: { ilike: '%at%' } } }), [{
819
- id: '2',
820
- title: 'Cat',
821
- longText: 'The Cat meows',
822
- counter: 2
823
- },
824
- {
825
- id: '3',
826
- title: 'Potato',
827
- longText: 'The Potato is vegetable',
828
- counter: 3
829
- },
830
- {
831
- id: '4',
832
- title: 'Atmosphere',
833
- longText: 'The atmosphere is not a sphere',
834
- counter: 4
835
- }], 'where: { title: { ilike: \'%at%\' } }')
836
-
837
- same(await entity.find({ where: { title: { ilike: 'at%' } } }), [{
838
- id: '4',
839
- title: 'Atmosphere',
840
- longText: 'The atmosphere is not a sphere',
841
- counter: 4
842
- }], 'where: { title: { ilike: \'at%\' } }')
843
-
844
- same(await entity.find({ where: { longText: { ilike: '%is%' } } }), [{
845
- id: '3',
846
- title: 'Potato',
847
- longText: 'The Potato is vegetable',
848
- counter: 3
849
- },
850
- {
851
- id: '4',
852
- title: 'Atmosphere',
853
- longText: 'The atmosphere is not a sphere',
854
- counter: 4
855
- }], 'where: { longText: { ilike: \'%is%\' } }')
856
-
857
- same(await entity.find({ where: { longText: { ilike: null } } }), [], 'where: { longText: { ilike: null } }')
858
-
859
- if (!isSQLite) {
860
- same(await entity.find({ where: { counter: { ilike: 4 } } }), [{
861
- id: '4',
862
- title: 'Atmosphere',
863
- longText: 'The atmosphere is not a sphere',
864
- counter: 4
865
- }], 'where: { counter: { ilike: 4 } }')
866
- }
867
-
868
- same(await entity.find({ where: { counter: { ilike: '%4' } } }), [{
869
- id: '4',
870
- title: 'Atmosphere',
871
- longText: 'The atmosphere is not a sphere',
872
- counter: 4
873
- },
874
- {
875
- id: '5',
876
- title: 'planet',
877
- longText: 'The planet have atmosphere',
878
- counter: 14
879
- }], 'where: { counter: { ilike: \'%4\' } }')
880
-
881
- same(await entity.find({ where: { counter: { ilike: '4%' } } }), [{
882
- id: '4',
883
- title: 'Atmosphere',
884
- longText: 'The atmosphere is not a sphere',
885
- counter: 4
886
- }], 'where: { counter: { ilike: \'4%\' } }')
887
-
888
- same(await entity.find({ where: { counter: { ilike: null } } }), [], 'where: { counter: { ilike: null } }')
889
- })