How to update supabase record?

130 Views Asked by At

I want "item" to be unique so if a user click on the same item again, it'll update and add 1 to my "quantity" and add "price" and insert a new record if not unique. I tried using upsert/onConflict but there's not much information.

const incrementOrder = async ({item, quantity, price}) =>{
    const {data, error} = await supabase
    .from("ordereditems")
    .insert([{item, quantity, price}])

  }
1

There are 1 best solutions below

2
Angus Moore On

If you click on your Supabase project, go to your project tables, click on the column dropdown icon that you want to edit and then select 'Edit Column' (picture below): enter image description here

If you then scroll down, you should see the ability to set that item to be unique

enter image description here

Hopefully that solved your issue. You should just be able to upsert and postgresql will enforce the uniqueness of the item column.