Updates not persisting
Hi, I'm new to DB and I'm stuggling to get this simple CRUD setup working.
I can't see why the update is not mutating the record on the collection or calling the onUpdate() callback. The object is valid.
Any ideas? Any help would be much appreciated. Thank you in advance.
export const sessionsCollection = createCollection(
queryCollectionOptions({
queryKey: [QUERY_KEY_OWNED_SESSIONS],
queryFn: async () => listSessionsServerFn({}),
schema: ActiveSessionSchema,
queryClient,
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
const newItem = transaction.mutations[0].modified;
const saved = await insertSessionServerFn({ data: newItem });
return { upsert: [saved] };
},
onUpdate: async ({ transaction }) => {
const mutation = transaction.mutations[0].modified;
console.log('mutation', mutation);
const updated = await updateSessionServerFn({ data: mutation });
return { upsert: [updated], refetch: false };
},
onDelete: async ({ transaction }) => {
const id = transaction.mutations[0].key;
await deleteSessionServerFn({ data: { sessionId: id } });
return { remove: [id], refetch: false };
},
})
);
... later
const tx = sessionsCollection.update('id_12345' (draft) => {
return {
...draft,
...form.getValues(),
};
});
await tx.isPersisted.promise;export const sessionsCollection = createCollection(
queryCollectionOptions({
queryKey: [QUERY_KEY_OWNED_SESSIONS],
queryFn: async () => listSessionsServerFn({}),
schema: ActiveSessionSchema,
queryClient,
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
const newItem = transaction.mutations[0].modified;
const saved = await insertSessionServerFn({ data: newItem });
return { upsert: [saved] };
},
onUpdate: async ({ transaction }) => {
const mutation = transaction.mutations[0].modified;
console.log('mutation', mutation);
const updated = await updateSessionServerFn({ data: mutation });
return { upsert: [updated], refetch: false };
},
onDelete: async ({ transaction }) => {
const id = transaction.mutations[0].key;
await deleteSessionServerFn({ data: { sessionId: id } });
return { remove: [id], refetch: false };
},
})
);
... later
const tx = sessionsCollection.update('id_12345' (draft) => {
return {
...draft,
...form.getValues(),
};
});
await tx.isPersisted.promise;I can't see why the update is not mutating the record on the collection or calling the onUpdate() callback. The object is valid.
Any ideas? Any help would be much appreciated. Thank you in advance.