codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.62k stars 343 forks source link

Data change example #697

Closed hasanAjsf closed 3 years ago

hasanAjsf commented 3 years ago

I saw your example https://youtu.be/01_wEMdOp1U about writing and reading engineer salary, which looks to be very simple. my question is: If later the engineer salary had been increased by 20000$ how can I post this info to the DB, and how can I read the new salary of the engineer?

Simple example how to handle such cases is rquired.

Thanks

jeroiraz commented 3 years ago

Thanks for reaching out @hajsf

Keys can be updated without limitation, currently the entire history of changes to keys get tracked. So following the example it's possible to call UpdateSalary method as many times as needed.

Get will return the latest assigned value. And using History (https://docs.immudb.io/master/sdks-api.html#history) it's possible to retrieve all the values associated a given key.

Extending the examples it's a good idea, meanwhile please let us know if using history operation is clear enough

dmacvicar commented 3 years ago

@hajsf As @jeroiraz mentioned, just calling a Set operation with the same key, would update the new salary while keeping the old one in the history. A Get operation would retrieve the latest version. In Pseudocode:

SET(employee:001:salary, 1000)
GET(employee:001:salary) -> 1000
SET(employee:001:salary, 2000)
GET(employee:001:salary) -> 2000

That means you can use the hello world example described here and just set the salary twice.

Let us know if there is an example we can provide to make things more clear, or if you are not using the Go SDK.

hasanAjsf commented 3 years ago

https://docs.immudb.io/master/sdks-api.html#history

It gave me 404 error!

dmacvicar commented 3 years ago

Sorry, I renamed it as part of a restructure of the docs. https://docs.immudb.io/master/sdk.html#history

hasanAjsf commented 3 years ago

Thanks alot