-
Notifications
You must be signed in to change notification settings - Fork 6
RFC: Specialized Collection Types for Data Sources #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One option to explore here is just wrapping tanstack/query — https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientfetchquery could be used under the hood. Inside mutationFn, the query object could be exposed to invalidate it after the mutation finishes. |
Ok, plan now is to make a So you can write:
|
Updated the main body with a detailed proposal |
Makes lots of sense to me 👌 |
Summary
This RFC proposes a new package
@tanstack/db-collections
that introduces specialized collection types for common data sources. By providing dedicated implementations for ElectricSQL and API-based data, we simplify the developer experience and enhance type safety. Instead of manually configuring sync implementations, developers can use purpose-built factory functions that handle the complexity of data synchronization while exposing source-specific features like transaction tracking for ElectricSQL or cache invalidation for API queries.The proposal maintains the core Collection functionality while adding type-safe specialized methods where they make sense. This approach gives developers the best of both worlds: the familiar optimistic updates of the base Collection, plus streamlined integration with their chosen data source. By separating different collection types into their own classes, we provide better IDE support, clearer error messages, and a more maintainable codebase that can grow to support additional data sources in the future.
Background
new Collection(config)
Problem
awaitTxId
for ElectricSQL) aren't available out of the boxProposal
@tanstack/db-collections
that provides specialized collection implementations:Implementation Strategy:
a. ElectricCollection:
streamOptions
andprimaryKey
awaitTxId
functionalityprimaryKey
configurationb. QueryCollection:
queryFn
and TanStack Query optionsinvalidate
method that triggers query refetchPackage Structure:
Error Handling:
Type Safety:
Definition of Success
Developer Experience
API Design
awaitTxId
,invalidate
) are intuitive and well-typedImplementation Quality
Extensibility
The text was updated successfully, but these errors were encountered: