Skip to content

Commit

Permalink
feat(pglite/sync): Add commitGranularity and onInitialSync parame…
Browse files Browse the repository at this point in the history
…ters to `syncShapeToTable` (#456)

* Add `commitGranularity` parameter in the `syncShapeToTable`

* Fix tests

* Docs

* add tests for commitGranularity

* Add test of the commitThrottle option

* Fix onInitialSync and add test

* doc: export return type for syncShapeToTable (#452)

* doc: export return type for syncShapeToTable

* feat: expose stream object as of for useShape hook

* Changeset

---------

Co-authored-by: Sam Willis <[email protected]>

* Remove part of test thats flaky on CI

* formatting

* Fix types

* Remove transaction commit granularity until Electric has stabilised on LSN metadata

* Post review changes

---------

Co-authored-by: Yacine <[email protected]>
  • Loading branch information
samwillis and yacineb authored Dec 9, 2024
1 parent 515a155 commit 46c102c
Show file tree
Hide file tree
Showing 4 changed files with 791 additions and 123 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-jokes-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite-sync': patch
---

Add options for the `commitGranularity` parameter in the `syncShapeToTable` function, enabling the user to choose how often the sync should commit.
15 changes: 15 additions & 0 deletions docs/docs/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ It takes the following options as an object:
- `useCopy: boolean`<br>
Whether to use the `COPY FROM` command to insert the initial data, defaults to `false`. This process may be faster than inserting row by row as it combines the inserts into a CSV to be passed to Postgres.

- `commitGranularity: CommitGranularity`<br>
The granularity of the commit operation, defaults to `"up-to-date"`. Note that a commit will always be performed immediately on the `up-to-date` message.
Options:

- `"up-to-date"`: Commit all messages when the `up-to-date` message is received.
<!-- - `"transaction"`: Commit all messages within transactions as they were applied to the source Postgres. -->
- `"operation"`: Commit each message in its own transaction.
- `number`: Commit every N messages.

- `commitThrottle: number`<br>
The number of milliseconds to wait between commits, defaults to `0`.

- `onInitialSync: () => void`<br>
A callback that is called when the initial sync is complete.

The returned `shape` object from the `syncShapeToTable` call has the following methods:

- `isUpToDate: boolean`<br>
Expand Down
Loading

0 comments on commit 46c102c

Please sign in to comment.