|
7 | 7 | OplogEntryJSON, |
8 | 8 | PowerSyncConnectionOptions, |
9 | 9 | ProgressWithOperations, |
| 10 | + Schema, |
10 | 11 | SyncClientImplementation, |
11 | 12 | SyncStreamConnectionMethod |
12 | 13 | } from '@powersync/common'; |
@@ -638,6 +639,85 @@ function defineSyncTests(impl: SyncClientImplementation) { |
638 | 639 | expect(another.currentStatus.statusForPriority(0).hasSynced).toBeTruthy(); |
639 | 640 | await another.waitForFirstSync({ priority: 0 }); |
640 | 641 | }); |
| 642 | + |
| 643 | + if (impl == SyncClientImplementation.RUST) { |
| 644 | + mockSyncServiceTest('raw tables', async ({ syncService }) => { |
| 645 | + const customSchema = new Schema({}); |
| 646 | + customSchema.withRawTables({ |
| 647 | + lists: { |
| 648 | + put: { |
| 649 | + sql: 'INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)', |
| 650 | + params: ['Id', { Column: 'name' }] |
| 651 | + }, |
| 652 | + delete: { |
| 653 | + sql: 'DELETE FROM lists WHERE id = ?', |
| 654 | + params: ['Id'] |
| 655 | + } |
| 656 | + } |
| 657 | + }); |
| 658 | + |
| 659 | + const powersync = await syncService.createDatabase({ schema: customSchema }); |
| 660 | + await powersync.execute('CREATE TABLE lists (id TEXT NOT NULL PRIMARY KEY, name TEXT);'); |
| 661 | + |
| 662 | + const query = powersync.watchWithAsyncGenerator('SELECT * FROM lists')[Symbol.asyncIterator](); |
| 663 | + expect((await query.next()).value.rows._array).toStrictEqual([]); |
| 664 | + |
| 665 | + powersync.connect(new TestConnector(), options); |
| 666 | + await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1)); |
| 667 | + |
| 668 | + syncService.pushLine({ |
| 669 | + checkpoint: { |
| 670 | + last_op_id: '1', |
| 671 | + buckets: [bucket('a', 1)] |
| 672 | + } |
| 673 | + }); |
| 674 | + syncService.pushLine({ |
| 675 | + data: { |
| 676 | + bucket: 'a', |
| 677 | + data: [ |
| 678 | + { |
| 679 | + checksum: 0, |
| 680 | + op_id: '1', |
| 681 | + op: 'PUT', |
| 682 | + object_id: 'my_list', |
| 683 | + object_type: 'lists', |
| 684 | + data: '{"name": "custom list"}' |
| 685 | + } |
| 686 | + ] |
| 687 | + } |
| 688 | + }); |
| 689 | + syncService.pushLine({ checkpoint_complete: { last_op_id: '1' } }); |
| 690 | + await powersync.waitForFirstSync(); |
| 691 | + |
| 692 | + expect((await query.next()).value.rows._array).toStrictEqual([{ id: 'my_list', name: 'custom list' }]); |
| 693 | + |
| 694 | + syncService.pushLine({ |
| 695 | + checkpoint: { |
| 696 | + last_op_id: '2', |
| 697 | + buckets: [bucket('a', 2)] |
| 698 | + } |
| 699 | + }); |
| 700 | + await vi.waitFor(() => powersync.currentStatus.dataFlowStatus.downloading == true); |
| 701 | + syncService.pushLine({ |
| 702 | + data: { |
| 703 | + bucket: 'a', |
| 704 | + data: [ |
| 705 | + { |
| 706 | + checksum: 0, |
| 707 | + op_id: '2', |
| 708 | + op: 'REMOVE', |
| 709 | + object_id: 'my_list', |
| 710 | + object_type: 'lists' |
| 711 | + } |
| 712 | + ] |
| 713 | + } |
| 714 | + }); |
| 715 | + syncService.pushLine({ checkpoint_complete: { last_op_id: '2' } }); |
| 716 | + await vi.waitFor(() => powersync.currentStatus.dataFlowStatus.downloading == false); |
| 717 | + |
| 718 | + expect((await query.next()).value.rows._array).toStrictEqual([]); |
| 719 | + }); |
| 720 | + } |
641 | 721 | } |
642 | 722 |
|
643 | 723 | function bucket(name: string, count: number, options: { priority: number } = { priority: 3 }): BucketChecksum { |
|
0 commit comments