Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@david-mcneil
Created March 17, 2012 15:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-mcneil/2060731 to your computer and use it in GitHub Desktop.
Save david-mcneil/2060731 to your computer and use it in GitHub Desktop.
Port of part of the datomic tutorial to Clojure
(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)))
@djpowell
Copy link

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:

  (q '[:find ?c :where [?c :community/name]] (db conn)))

@noahlz
Copy link

noahlz commented Jul 18, 2012

Here's my version of their "getting started" page in clojure https://gist.github.com/3132207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment