Re:DataScript: Immutable database and Datalog query engine i...
by wereHamster on Friday July 03, 2015 @06:47PM
(#9828329)
That's how every langauge with immutable data structures works. What makes this one special?
Re:DataScript: Immutable database and Datalog query engine i...
by dwwoelfel on Friday July 03, 2015 @07:12PM
(#9828408)
With this one, the database is an immutable value, so you can hold on to old versions of it. Here's an incomplete example of how you could implement optimistic updates:
tx_report = datascript.transact(db_conn, [{:key "value"}]);
set_db_to_render_from(tx_report.db_after);
send_report_to_server(tx_report, function(error) {
set_db_to_render_from(tx.report.db_before);
});
Re:DataScript: Immutable database and Datalog query engine i...
by sheepmullet on Friday July 03, 2015 @09:06PM
(#9828720)
Normally when you update a row in a database you lose the ability to access the previous values. E.g. If you update your address it overwrites your previous address
With datomic you are just adding a new fact. My address is now x. This has a lot of nice properties. I can now easily write a query to tell me your previous 5 addresses, rolling back is easy, you can get amazing and scalable read performance, etc etc
In the past we have either had to hand roll our own features (e.g. Have a table of past addresses, or add date columns to specific tables) or rely on error prone/brittle techniques like using audit tables, source control, or transaction logs.
Datomic makes it easy!
You don't write to the database, you perform an operation that takes a database and a write request and returns a new database. Same with updates. Essentially, the kind of things you think of as "mutating" operations have a signature of, in Haskell-ish notation: