Best Practice for combining queries of same object type for a collection
Per the
useLiveQuery Optimization, I have multiple queries across multiple accounts (for example purposes lets say 9) that all return arrays of the same object type.
Is it better to create 9 collections for each source and stitch those together with a live query, or make a single collection that pulls the data together as part of its Tanstack Query definition.
I'm more inclined to the latter and route the CRUD update hooks directly via one collection rather than having to have a map to find which one it came from and act on that collection.4 Replies
fascinating-indigo•2mo ago
a union operator will make the first quite nice https://github.com/TanStack/db/issues/58
GitHub
Query builder needs a
union method to combine similar collections...Union operator We want a way to union two or more collections so that they can be used as a single source within a live query. There needs to be both static and dynamic union operators, with the la...
fascinating-indigo•2mo ago
but yeah, nothing wrong with just loading everything together — it should be easy to send mutations the right way based on accountId or whatever
rising-crimsonOP•2mo ago
yeah as part of the query each object gets weakMapped to the account it was fetched from so I just look it up in the weakmap to find the collection to CRUD it. Thanks!
fascinating-indigo•2mo ago
An neat solution