I'm looking for:
- Interface of a mutable collection akin to key-value map that will somehow retain previous states for individual elements, i.e. it's possible to get all previous and current states of an element knowning its key.
- Implementation of such interface, preferably backed in some sort of database or some other persistent storage.
Slick database accessing kit indeed allows to access SQL databases as if they were regular Scala collections, however, it doesn't cover accessing any historical states of an entry in a collection. You can do, for example:
suppliers(42) // => gets current state of a supplier with ID=42
suppliers.get(42) // => gets current state or None if not found
but you can't get a list of all previous states, neither you can get a particular historical state by some sort of history ID. I've browsed through Scala collection overview and it seems that neither of them provides such an API. Everything that conforms to Map[T]
interface returns only a single (latest, current) value of T
when getting an element.
This concept is implemented in several database backends, for example:
- Are old data accessible in CouchDB? — discusses keeping history (versioning) data in CouchDB.
- Ways to implement data versioning in MongoDB — discusses the same in MongoDB.
- Ways to implement data versioning in Cassandra — the same in Cassandra
There are quite a few ready-made solutions in other languages, for example:
- Vermongo — for MongoDB & Java
- mongodb-revision-objects — for MongoDB & Java
- mongoid-history — for MongoDB & Ruby
- couchbase-how-to-versioning — for Couchbase & Java