I am using nodejs and mysql.
In my table event
, assumed that there are currently 3 rows of data.
There should be exactly one featured Event.
GET /event
[
{
id: 1,
content: "content 1",
isFeaturedEvent: false
},
{
id: 2,
content: "content 2",
isFeaturedEvent: true
},
{
id: 3,
content: "content 3",
isFeaturedEvent: false
},
]
Is it possible to make sure there is always only/at most one isFeaturedEvent: true
, in server side/database side?
For example, if the third event(id:3) change the value of isFeaturedEvent
from false to true, it will then throw error.