How do you use the Database Service's UpdateAsync where Database is a table?

I’ve seen a lot of tutorials and most of them display that:

  • Using SetAsync can cause data loss if triggered across servers at the same time,
  • Tutorials for UpdateAsync mostly include a shown example from a single value displayed,
  • Few familiar topics are created but they usually target the problem as an example and it’s incredibly difficult to tell.

I simply need to see a proper plain example of how you’d change a value inside the table.

e.g.
table consists of a player’s name as a string, a player’s inventory as a second table inside.
I kinda only understand how to do it the lazy way using SetAsync by replicating the whole database table, throw data onto a dupe and use that dupe to alter the original.

it callbacks with current value
as the name implies you are updating the current value

local DataStore = {
	Player1 = {
		level = 1,
		isAdmin = true 
	}
}

local function UpdateAsync(data, updateFunction)
	assert(DataStore[data], "Data does not exist")
	DataStore[data] = updateFunction(DataStore[data])
end

UpdateAsync("Player1", function(current)
	if current.isAdmin then
		current.level = 999
	end
		
	return current
end)

print(DataStore.Player1.level) ---// 999

imagine its working like this,

table is a reference so u can just directly mutate the table