one.love - an inspired rethink
by Chris Zheng,
I've been wanting to play around with rethinkdb ever since two years ago, when I had a really memorable conversation with about developer communities and how open the rethinkdb brand is (as compared to datomic which has amazing functionality, but because of it's closed source, has not been as widely adopted).
(map inc [1 2 3])
rethinkdb is super cool. I've been looking at it for the past two weeks, and pestering apa512, the author of clj-rethinkdb about how it's implemented. I've reached the following conclusion:
It's like mongodb but better.
rethinkdb is a document store with change notification and server side functions built in, sitting inbetween datomic and mongodb in terms of functionality. One highlight for me was that the Reql syntax was actually a lisp in disguise that is sent through the javascript protobuf protocol. clj-rethinkdb does just that.
I've wrapped the rethinkdb driver to support a more lispy, data-driven query instead of the jquery style syntax that is reql within one.love. Now it kind of reminds me of datomic transactions, but because there is more flexible semantics on the serverside calls, we can do some pretty cool things:
connecting:
(use 'one.love)
(def conn (connect {:host "localhost"
:port 28015}))
creating a table:
(run conn
[[:db "test"]
[:table-create "movies"]])
import over http:
(run conn
[[:table "movies"]
[:insert [:http "http://rethinkdb.com/sample/top-250-ratings.json"]]])
getting the top movie:
(run conn
[[:table "movies"]
[:without "id"]
[:filter {:rank 1}]])
=> [{:title "The Shawshank Redemption"
:year 1994,
:rating 9.2,
:rank 1,
:votes 1262930,}]
moving tables:
(doto conn
(run [:table-create "unique_movies"])
(run [[:table "unique_movies"]
[:insert [[:table "movies"]
[:without "id"]
[:distinct]]]]))
server side functions:
(run conn
[[:table "unique_movies"]
[:order-by "rank"]
[:limit 10]
[:map '(fn [movie] movie.title)]])
=> ["The Shawshank Redemption"
"The Godfather"
"The Godfather: Part II"
"The Dark Knight"
"Pulp Fiction"
"Il buono, il brutto, il cattivo."
"Schindler's List"
"12 Angry Men"
"The Lord of the Rings: The Return of the King"
"Fight Club"]
There are other ideas I want to integrate into this library (from cassius and adi) but for my initial use case, this suffices and I'm extremely stoked with how this data driven syntax looks and feels. Please check it out!