oldmanfleming
oldmanfleming4mo ago

Deno KV: How to query for all records that have been updated since a given timestamp?

I'm evaluating Deno KV for project and looking through the API I'm unsure of how to achieve the functionality in the title. Is the answer to maintain a secondary index that has the timestamps as a part of the key and then do a list call with a range selector?
2 Replies
cknight
cknight4mo ago
Yes, unless the number of records is very small, you'd want the timestamp as part of the keys so that you can do a list on it starting at a given timestamp. This could be a secondary index key or even a primary key where you "delete and set with new timestamp" atomic transaction each time the entry gets updated. However, as you mention, a secondary index may work best depending on your exact use case.
oldmanfleming
oldmanfleming4mo ago
Thanks! That makes sense. I think secondary index makes more sense for my usecase but I just need to also think about how I will cleanup old versions so that the index doesn't maintain every version of a record, only latest. Not sure if this can be achieved atomically, similar to what you described with the "delete and set" in the primary key example. Will need to think more maybe