How could I count a user's sent chat messages?

@novabyte Sorry for late replay

I’ve never seen a game which restricts chat messages to some kind of daily limit. I have seen rate limits implemented but never a hard count limit. Are you sure this is right for your game design?

I still did not finalize this approach, but you are right about

I think if you limit that ability it could dramatically hurt your retention numbers.

I am trying to make a reasonable limit that usually fine for the normal usage.

so I spent sometime reading about jsonb functions and tried it, i found your answer

the SQL query will look like this for me

UPDATE storage SET value = value
|| jsonb_build_object(‘messageRemainingCount’, COALESCE((value->> ‘s’)::INT - 1::INT, 0::INT))
WHERE collection = ‘PlayerData’ AND user_id = $1 AND key = ‘profile’;

This will only change the count only
can you please help if possible to do the below in one call to the databese

if messageRemainingCount > 0 {
messageRemainingCount–
return messageRemainingCount
}else{
return -1
}

I need return value to check if to allow the message to be sent or not