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
Describe the bug
By using useInsertMutation (or upsert or update of course), whatever we want to select() in the third parameter, it returns an array.
A .single() method exists in the supabase query also on the insert which enables the possibility to not return an array but an object directly.
To Reproduce
In the following query, we can see the insertNewTeam which is used only to insert a single row, and so using normally a .single() in the insert is perfect, so that the value in the data return doesn't need to use a data[0] which is hugly.
const{mutateAsync: insertNewTeamMember}=useInsertMutation(createClient().from("teams_members"),["id_user","id_team","permission"],"id_user, id_team, permission",);const{mutateAsync: insertNewTeam}=useInsertMutation(createClient().from("teams"),["id_owner","name","id"],"id, name, id_owner",);consthandleInsertNewPersonnalTeam=async()=>{if(!dataSession?.userId){returnnull;}insertNewTeam([{id_owner: dataSession.userId,name: "Main Team"}],{onSuccess: (data,variables)=>{if(!variables[0].id_owner){thrownewError("No user id");}//@ts-ignoreif(!data[0].id){thrownewError("No team id");}//@ts-ignoreinsertNewTeamMember([{id_user: variables[0].id_owner,//@ts-ignoreid_team: data[0].id,permission: "full_access",},]);},});};
Expected behavior
Have the possibility to use .single() or .maybeSingle() method probably or at least an option "single" in the useInsert, useUpdate, etc.
yes this is on purpose, because it was much easier to get the types working for the array case only. changed the label to enhancement to reflect the request.
@psteinroe Yes I totally understand as we can achieve quite everything with arrays, but is there a specific reason why the updateMutation is receiving an object and not an array so ?
because cache helpers operates on primary keys only, so you can only update one at a time per request. its different for upsert and insert, because you pass the primary keys in the input.
Describe the bug
By using useInsertMutation (or upsert or update of course), whatever we want to select() in the third parameter, it returns an array.
A .single() method exists in the supabase query also on the insert which enables the possibility to not return an array but an object directly.
To Reproduce
In the following query, we can see the
insertNewTeam
which is used only to insert a single row, and so using normally a .single() in the insert is perfect, so that the value in the data return doesn't need to use a data[0] which is hugly.Expected behavior
Have the possibility to use .single() or .maybeSingle() method probably or at least an option "single" in the useInsert, useUpdate, etc.
Additional context
Maybe this refine handling dataProvider could help think about the best way to achieve it : https://github.com/refinedev/refine/blob/master/packages/supabase/src/dataProvider/index.ts
The text was updated successfully, but these errors were encountered: