Created
March 17, 2012 15:03
-
-
Save david-mcneil/2060731 to your computer and use it in GitHub Desktop.
Port of part of the datomic tutorial to Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns datomic-tutorial (:import [datomic Peer Util] | |
[java.io FileReader])) | |
;;create database | |
(Peer/createDatabase "datomic:mem://seattle") | |
(Peer/createDatabase "datomic:mem://seattle") | |
(let [conn (Peer/connect "datomic:mem://seattle")] | |
;; setup sample schema | |
(.get (.transact conn | |
(first (Util/readAll | |
(FileReader. "samples/seattle/seattle-schema.dtm"))))) | |
;; load sample data | |
(.get (.transact conn | |
(first (Util/readAll | |
(FileReader. "samples/seattle/seattle-data0.dtm"))))) | |
;; query the database | |
(let [results (Peer/q "[:find ?c :where [?c :community/name]]" | |
(to-array [(.db conn)])) | |
e (.entity (.db conn) (first (first results)))] | |
(:community/name e))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a native Clojure API btw:
http://www.datomic.com/company/resources/clojure-api
Notably, the Clojure API lets you write the datalog as clojure data-structure literals, rather than strings: