Is there a way of formatting data at the collection level on certain queries?
I have a use-case where I have a metadata field that is json, it contains a structure that holds foreign key references to other tables/collections. This can be things like people/location/attachment references.
In postgres I've created a view which enriches this data so when you load the row's metadata it would have the fresh data. Eg if a person changes their name, it would be updated automatically.
Is there anything in tanstack/db & tanstack/react-db that can do something like this? I was hoping there'd be some type of onSelect?
The only approach I've found so far is running the first live query, extracting the metadata from all objects returned then batching those to fetch the additional items to then rebuild it.
Since this would be somewhat heavy compared to other queries where this wouldn't be needed it would be good to only trigger this if that field is requested.
4 Replies
abundant-blushOP•7d ago
Here's an example of the metadata, the top-level field keys are references to custom fields in another table which don't need to be matched, but the type/values map to other tables eg lookup_location = public.location table.
vicious-gold•6d ago
I'm confused what you're trying to do — format what?
abundant-blushOP•6d ago
I'm trying to convert the uuid in the value of these jsonb fields into a reference from another collection. Eg if I have a location collection I'd like to extract out that value which is just a plain string in that object to the full record details so I can display the locations name for example.
But that big jsonb blob is on every row of the items table so I'd like to do it in one sweep instead of needing to do a follow up parsing.
vicious-gold•6d ago
oh so you're trying to normalize the data?
so you're fetching a big blog of denormalized data and you want to split it out to different collections?