@objectql/driver-excel 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +31 -0
- package/dist/index.d.ts +43 -219
- package/dist/index.js +202 -810
- package/dist/index.js.map +1 -1
- package/jest.config.js +14 -1
- package/package.json +4 -3
- package/src/index.ts +218 -934
- package/test/index.test.ts +82 -30
- package/tsconfig.tsbuildinfo +1 -1
package/test/index.test.ts
CHANGED
|
@@ -233,7 +233,7 @@ describe('ExcelDriver', () => {
|
|
|
233
233
|
|
|
234
234
|
it('should filter records with equality operator', async () => {
|
|
235
235
|
const results = await driver.find(TEST_OBJECT, {
|
|
236
|
-
|
|
236
|
+
where: { role: { $eq: 'user' } }
|
|
237
237
|
});
|
|
238
238
|
expect(results.length).toBe(2);
|
|
239
239
|
expect(results.every(r => r.role === 'user')).toBe(true);
|
|
@@ -241,7 +241,7 @@ describe('ExcelDriver', () => {
|
|
|
241
241
|
|
|
242
242
|
it('should filter records with greater than operator', async () => {
|
|
243
243
|
const results = await driver.find(TEST_OBJECT, {
|
|
244
|
-
|
|
244
|
+
where: { age: { $gt: 25 } }
|
|
245
245
|
});
|
|
246
246
|
expect(results.length).toBe(2);
|
|
247
247
|
expect(results.every(r => r.age > 25)).toBe(true);
|
|
@@ -249,25 +249,26 @@ describe('ExcelDriver', () => {
|
|
|
249
249
|
|
|
250
250
|
it('should filter records with contains operator', async () => {
|
|
251
251
|
const results = await driver.find(TEST_OBJECT, {
|
|
252
|
-
|
|
252
|
+
where: { name: { $regex: 'li' } }
|
|
253
253
|
});
|
|
254
254
|
expect(results.length).toBe(2); // Alice and Charlie
|
|
255
255
|
});
|
|
256
256
|
|
|
257
257
|
it('should support OR filters', async () => {
|
|
258
258
|
const results = await driver.find(TEST_OBJECT, {
|
|
259
|
-
|
|
260
|
-
[
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
where: {
|
|
260
|
+
$or: [
|
|
261
|
+
{ name: { $eq: 'Alice' } },
|
|
262
|
+
{ name: { $eq: 'Bob' } }
|
|
263
|
+
]
|
|
264
|
+
}
|
|
264
265
|
});
|
|
265
266
|
expect(results.length).toBe(2);
|
|
266
267
|
});
|
|
267
268
|
|
|
268
269
|
it('should sort records ascending', async () => {
|
|
269
270
|
const results = await driver.find(TEST_OBJECT, {
|
|
270
|
-
|
|
271
|
+
orderBy: [{ field: 'age', order: 'asc' }]
|
|
271
272
|
});
|
|
272
273
|
expect(results[0].age).toBe(25);
|
|
273
274
|
expect(results[1].age).toBe(30);
|
|
@@ -276,7 +277,7 @@ describe('ExcelDriver', () => {
|
|
|
276
277
|
|
|
277
278
|
it('should sort records descending', async () => {
|
|
278
279
|
const results = await driver.find(TEST_OBJECT, {
|
|
279
|
-
|
|
280
|
+
orderBy: [{ field: 'age', order: 'desc' }]
|
|
280
281
|
});
|
|
281
282
|
expect(results[0].age).toBe(35);
|
|
282
283
|
expect(results[1].age).toBe(30);
|
|
@@ -292,7 +293,7 @@ describe('ExcelDriver', () => {
|
|
|
292
293
|
|
|
293
294
|
it('should support pagination with skip', async () => {
|
|
294
295
|
const results = await driver.find(TEST_OBJECT, {
|
|
295
|
-
|
|
296
|
+
offset: 1,
|
|
296
297
|
limit: 2
|
|
297
298
|
});
|
|
298
299
|
expect(results.length).toBe(2);
|
|
@@ -315,7 +316,7 @@ describe('ExcelDriver', () => {
|
|
|
315
316
|
|
|
316
317
|
it('should count filtered records', async () => {
|
|
317
318
|
const count = await driver.count(TEST_OBJECT, {
|
|
318
|
-
|
|
319
|
+
where: { role: { $eq: 'user' } }
|
|
319
320
|
});
|
|
320
321
|
expect(count).toBe(2);
|
|
321
322
|
});
|
|
@@ -354,7 +355,7 @@ describe('ExcelDriver', () => {
|
|
|
354
355
|
expect(result.modifiedCount).toBe(2);
|
|
355
356
|
|
|
356
357
|
const users = await driver.find(TEST_OBJECT, {
|
|
357
|
-
|
|
358
|
+
where: { role: { $eq: 'member' } }
|
|
358
359
|
});
|
|
359
360
|
expect(users).toHaveLength(2);
|
|
360
361
|
});
|
|
@@ -465,7 +466,7 @@ describe('ExcelDriver', () => {
|
|
|
465
466
|
|
|
466
467
|
it('should handle filters on empty data', async () => {
|
|
467
468
|
const results = await driver.find(TEST_OBJECT, {
|
|
468
|
-
|
|
469
|
+
where: { name: { $eq: 'Alice' } }
|
|
469
470
|
});
|
|
470
471
|
expect(results).toEqual([]);
|
|
471
472
|
});
|
|
@@ -582,15 +583,12 @@ describe('ExcelDriver', () => {
|
|
|
582
583
|
const result = await driver.executeQuery({
|
|
583
584
|
object: TEST_OBJECT,
|
|
584
585
|
fields: ['name', 'age'],
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
field: 'age',
|
|
588
|
-
operator: '>',
|
|
589
|
-
value: 25
|
|
586
|
+
where: {
|
|
587
|
+
age: { $gt: 25 }
|
|
590
588
|
},
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
589
|
+
orderBy: [{ field: 'age', order: 'asc' }],
|
|
590
|
+
limit: 10,
|
|
591
|
+
offset: 0
|
|
594
592
|
});
|
|
595
593
|
|
|
596
594
|
expect(result.value).toHaveLength(2);
|
|
@@ -606,11 +604,10 @@ describe('ExcelDriver', () => {
|
|
|
606
604
|
|
|
607
605
|
const result = await driver.executeQuery({
|
|
608
606
|
object: TEST_OBJECT,
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
{
|
|
613
|
-
{ type: 'comparison', field: 'city', operator: '=', value: 'NYC' }
|
|
607
|
+
where: {
|
|
608
|
+
$and: [
|
|
609
|
+
{ age: { $gt: 25 } },
|
|
610
|
+
{ city: { $eq: 'NYC' } }
|
|
614
611
|
]
|
|
615
612
|
}
|
|
616
613
|
});
|
|
@@ -626,9 +623,9 @@ describe('ExcelDriver', () => {
|
|
|
626
623
|
|
|
627
624
|
const result = await driver.executeQuery({
|
|
628
625
|
object: TEST_OBJECT,
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
626
|
+
orderBy: [{ field: 'name', order: 'asc' }],
|
|
627
|
+
offset: 1,
|
|
628
|
+
limit: 1
|
|
632
629
|
});
|
|
633
630
|
|
|
634
631
|
expect(result.value).toHaveLength(1);
|
|
@@ -747,4 +744,59 @@ describe('ExcelDriver', () => {
|
|
|
747
744
|
});
|
|
748
745
|
});
|
|
749
746
|
});
|
|
747
|
+
|
|
748
|
+
describe('Aggregation Operations', () => {
|
|
749
|
+
beforeEach(async () => {
|
|
750
|
+
// Create sample data for aggregation tests
|
|
751
|
+
await driver.create('orders', { id: '1', customer: 'Alice', product: 'Phone', amount: 500, quantity: 2, status: 'completed' });
|
|
752
|
+
await driver.create('orders', { id: '2', customer: 'Bob', product: 'Tablet', amount: 300, quantity: 1, status: 'pending' });
|
|
753
|
+
await driver.create('orders', { id: '3', customer: 'Alice', product: 'Laptop', amount: 700, quantity: 1, status: 'completed' });
|
|
754
|
+
await driver.create('orders', { id: '4', customer: 'Charlie', product: 'Monitor', amount: 250, quantity: 2, status: 'completed' });
|
|
755
|
+
await driver.create('orders', { id: '5', customer: 'Bob', product: 'Keyboard', amount: 100, quantity: 1, status: 'cancelled' });
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
test('should aggregate with $match stage', async () => {
|
|
759
|
+
const results = await driver.aggregate('orders', [
|
|
760
|
+
{ $match: { status: 'completed' } }
|
|
761
|
+
]);
|
|
762
|
+
|
|
763
|
+
expect(results).toBeDefined();
|
|
764
|
+
expect(results.length).toBe(3);
|
|
765
|
+
expect(results.every((r: any) => r.status === 'completed')).toBe(true);
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
test('should aggregate with $group and $sum', async () => {
|
|
769
|
+
const results = await driver.aggregate('orders', [
|
|
770
|
+
{ $match: { status: 'completed' } },
|
|
771
|
+
{
|
|
772
|
+
$group: {
|
|
773
|
+
_id: '$customer',
|
|
774
|
+
totalAmount: { $sum: '$amount' }
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
]);
|
|
778
|
+
|
|
779
|
+
expect(results).toBeDefined();
|
|
780
|
+
expect(results.length).toBeGreaterThan(0);
|
|
781
|
+
|
|
782
|
+
const alice = results.find((r: any) => r._id === 'Alice');
|
|
783
|
+
expect(alice).toBeDefined();
|
|
784
|
+
expect(alice.totalAmount).toBe(1200);
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
test('should aggregate with $group and $avg', async () => {
|
|
788
|
+
const results = await driver.aggregate('orders', [
|
|
789
|
+
{
|
|
790
|
+
$group: {
|
|
791
|
+
_id: null,
|
|
792
|
+
avgAmount: { $avg: '$amount' }
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
]);
|
|
796
|
+
|
|
797
|
+
expect(results).toBeDefined();
|
|
798
|
+
expect(results.length).toBe(1);
|
|
799
|
+
expect(results[0].avgAmount).toBeCloseTo(370, 0);
|
|
800
|
+
});
|
|
801
|
+
});
|
|
750
802
|
});
|