Delta Updates
#1463
Replies: 1 comment
-
Converted to discussion from issue. Sorry for missing this for so long - there's no direct way in the API to update a value based on an existing value in the table, as updates You can fetch the table's data by using from perspective import Table
table = Table({"player_id": str, "score": int}, index="player_id")
view = table.view()
# when new increments come in, grab the table's data and increment by pkey
table_data = view.to_dict()
num_rows = view.num_rows()
for row_index in num_rows:
player_id = table_data["player_id"][row_index]
score = table_data["score"][row_index]
score += get_increment(player_id)
table.update(table_data) Example is in Python for simplicity, but the API between Python and JS is the same besides general syntax. You can't get a specific primary key value from the view, but the view is cheap to create and as long as you keep it in memory it will have the latest data on the table when you query it with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Support Question
Hi,
Does the engine support a way of passing in incremental updates. I know the current table.update method allows for a replace like update. The use case currently being looked at is to stream a delta/increment of an update into an existing table/view.
Example: Assuming a very basic example (not real use case) where a table has PlayerId, Score. There are a series of events that leads to score. If a use generates next series of events and that leads to an increase of the score by 50, I would like to send +50 as an increment to an existing value in the table long with the player id. Or is there a way to fetch an existing value in the table by index?
If this is achievable through some other means, I am open to suggestions.
Beta Was this translation helpful? Give feedback.
All reactions