Using a Supabase database, I'm have having an issue with subtracting from a quantity total which exists in the database field. here is my code:
const { data, error } = await supabase
.from('product')
.update({ quantity: `quantity - ${Number(orderItem.quantity)}` })
.eq('id', orderItem.id);
if (error){
throw error;
}
The error being thrown is stating that a string can't be added to a numeric field type (which makes sense), i have also attempted the following:
.update({ quantity: quantity - Number(orderItem.quantity) })
Which outputs the following error: ReferenceError: quantity is not defined
I realise I could fetch the quantity from a prior database call, do the quantity equation then do a simple update with the result, however i'd like to know if it's possible in a single db call?