Samstag, 29. November 2014

PossibleDB


 Recently I discovered that Datascript ('An immutable in-memory database and Datalog query engine in ClojureScript') can also be used to query a RethinkDB database.

This is made possible by a project called PossibleDB.

As I am interested in free alternatives to Datomic, I had to try it out and describe my experience with it.

The PossibleDB-Website describes the following steps for getting started:

1)git clone https://github.com/runexec/PossibleDB

2)cd PossibleDB/possibledb/

3)npm install rethinkdb

4)chmod +x possibledb.js

5)./possibledb.js {optional port}


One stumbling block I discovered was that the executable for node is called nodejs under Ubuntu and that obviously rethinkdb has to be running/executed. Luckily, the corresponding section on the RethinkDB website describes how to install it under Ubuntu.

In a similar vein, I studied the getting started section for Datascript and modified the statements to run them under PossibleDB.  After starting RethinkDB and PossibleDB via


rethinkdb


/usr/bin/nodejs possibledb.js 6666


I opened my friendly clojure repl after adding the dependency

[possibledb-client "1.6"] to project.clj.


(require '[possibledb-client.core :as d])


(def conn (d/connect! "localhost" 6666))


(d/create-db! "example")


(d/transact! "example" [ { :db/id -1 :name "Maksim" :age 45 :aka ["Maks Otto von Stirlitz", "Jack Ryan"] }])


(d/q "example" '[ :find ?n ?a :where [?e :aka ["Maks Otto von Stirlitz", "Jack Ryan"]] [?e :name ?n] [?e :age ?a]])


Notice that not only do you need to pass the name of the database, you also need to modify the last query from "Maks Otto von Stirlitz" to ["Maks Otto von Stirlitz", "Jack Ryan"].

By the way, if you need to debug your installation, the RethinkDB javascript tutorial might be helpful.


So far, the whole setup seems interesting and I will try out some more.


That's it for now. Have fun,

Markus


Update: I just noticed that the layout of my blog post looked completely random and also completely different than the editor view that blogger.com provides. Also, the editor is quite slow. But at least now everything looks the same.