You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am working in a project with supabase and using legend-state for "offline first" purposes. Everything is great apart from a small problem I run into. A little disclaimer tho, I just started using the library so please don't hesitate to correct me if you feel I understood something wrong.
This far this is my global config:
export const globalSynced = configureSynced(syncedSupabase, {
// Use React Native Async Storage
as: "Map",
persist: {
plugin: observablePersistAsyncStorage({
AsyncStorage,
}),
},
generateId, // This is hooked to uuidv4() but as I understand, it's only used for insert
supabase,
changesSince: "last-sync",
fieldCreatedAt: "created_at",
fieldUpdatedAt: "updated_at",
// Optionally enable soft deletes
fieldDeleted: "deleted",
});
and then I access my tables like this:
export const trainings$ = observable(
globalSynced({
collection: "training_units", //This is a joint table with a composite primary key and no id field
fieldId: "What should this be", // This accept one field only so it doesn't work with composite keys
generateId: () => "No Idea what to put here" // This doesn't give access to the row so I can't work something up from the 2 columns I use as primary key
select: (from) => from.select(trainingUnitsFields),
})
);
Now for testing purposes I have 2 rows in the training_units table but when I access it with const trainingUnits = trainingUnits$.get();
it returns a map with only one element with an undefined key. Since the 2 rows end up with an undefined id they overwrite each others in the map.
I have some proposition for the solution but I have no idea if it's feasible or not:
Give access to the row in the "generateId" param.
Add an array as an option for the "as" param, but I suppose this isn't really an option since there is a mention about it in the docs.
Add support to composite primary keys.
Please let me know if this is something that can be resolved in my side, if it needs to be implemented to the library to be possible, or if it's just impossible for the foreseeable future.
Thank you in advance for your replies.
The text was updated successfully, but these errors were encountered:
Hi,
I am working in a project with supabase and using legend-state for "offline first" purposes. Everything is great apart from a small problem I run into. A little disclaimer tho, I just started using the library so please don't hesitate to correct me if you feel I understood something wrong.
This far this is my global config:
and then I access my tables like this:
Now for testing purposes I have 2 rows in the training_units table but when I access it with
const trainingUnits = trainingUnits$.get();
it returns a map with only one element with an undefined key. Since the 2 rows end up with an undefined id they overwrite each others in the map.
I have some proposition for the solution but I have no idea if it's feasible or not:
Please let me know if this is something that can be resolved in my side, if it needs to be implemented to the library to be possible, or if it's just impossible for the foreseeable future.
Thank you in advance for your replies.
The text was updated successfully, but these errors were encountered: