-
Notifications
You must be signed in to change notification settings - Fork 77
docs: add electric-collection reference page #429
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
🦋 Changeset detectedLatest commit: f88cf4d The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Size Change: 0 B Total Size: 62.5 kB ℹ️ View Unchanged
|
Size Change: 0 B Total Size: 1.16 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up!
const todosCollection = createCollection( | ||
electricCollectionOptions({ | ||
shapeOptions: { | ||
url: 'https://example.com/v1/shape', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's used named routes and not put that table as a param
### Shape Options | ||
|
||
- `url`: The URL to your Electric sync service | ||
- `params`: Shape parameters including: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, let's not document this as the normal pattern. Show adding these in the proxy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the proxy example and mention the other shape parameters there
|
||
## Persistence Handlers | ||
|
||
You can define handlers that are called when mutations occur, for instance to persist changes to your backend. Such handlers **must return a transaction ID** (`txid`) to track when the mutation has been synchronized back from Electric: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Txid is recommended but there are already other ways of doing this and we'll be adding more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to explain why this is ideal for sync matching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've mentioned the alternative approaches and took an example.
await api.todos.create(item) // API doesn't return txid | ||
|
||
return { | ||
matchStream: (stream) => matchStream( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh the issue I linked to isn't implemented yet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I thought you wanted to document it already. Removed it.
|
||
// the shape parameters | ||
originUrl.searchParams.set("table", "todos") | ||
// originUrl.searchParams.set("where", "completed = true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment explaining these are other ways you can modify the shape definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comment and linked to the spec. Not sure if links to external sources are permitted.
Reference page for electric-collection.
Explains how to configure electric collection and how to do mutations with the transaction Id tracking pattern either with handlers or explicit transactions.