Dieter Komendera / Nov 27 2018

MusicBrainz Datomic

This article sets up a Datomic environment with the MusicBrainz sample database for easy exploration of the data with Datalog.

By reusing a Datomic environment, we have Datomic installed and can already start the transactor.

/usr/bin/nohup /datomic-free/bin/transactor /datomic-free/config/samples/ &> /datomic-free.log & sleep 1
tail /datomic-free.log

Let's create a deps.edn file which brings in the datomic-free dependency with which we can connect to Datomic later.

 {org.clojure/clojure {:mvn/version "1.10.0-beta8"}
  com.datomic/datomic-free {:mvn/version "0.9.5697"}
  {:git/url ""
   :sha "f6c080bd0049211021ea59e516d1785b08302515"}}}

Download, unpack and import the MusicBrainz dataset:

wget --progress=bar:force -O /results/mbrainz.tar
tar -xf mbrainz.tar
/datomic-free/bin/datomic restore-db file:/mbrainz-1968-1973 datomic:free://localhost:4334/mbrainz-1968-1973

After this, we can already connect start querying the database from Clojure.

(require '[datomic.api :as d])

(def uri "datomic:free://localhost:4334/mbrainz-1968-1973")
(def conn (d/connect uri))

(def db (d/db conn))

(into [] (d/q '[:find ?title
 	:in $ ?artist-name
 [?a :artist/name ?artist-name]
 [?t :track/artists ?a]
 [?t :track/name ?title]]
     db "John Lennon"))

The environment built in this article is exported, so you can transclude it in your own articles, just remember to start the transactor in a bash cell as shown at the very top in this article.