Peer Language Support
The Datomic team supports the Java and Clojure APIs. Community supported, third-party libraries are described in the section Third-party Libraries.
The Clojure API is a functional projection of the Java API. The methods of the Java types are flattened to functions in a single datomic.api namespace with an instance of the given type as the first argument.
It is idiomatic to reference the datomic.api namespace as d, with db and q added to the current namespace.
(ns project-ns (:require [datomic.api :as d :refer [db q]]))
The code below illustrates the translation of the Java API to Clojure.
Here is the code in Java:
String uri = "datomic:mem://test"; Connection conn = Peer.connect(uri); Collection results = Peer.query("[:find ?e :where [?e :db/doc]]", conn.db);
and the equivalent code in Clojure:
;; clojure (def uri "datomic:mem://test") (def conn (d/connect uri)) (def results (q '[:find ?e :where [?e :db/doc]] (db conn)))
Users of other JVM languages can use the Java API via their respective Java interop capabilities.
Non-JVM languages can access Datomic through the REST service via HTTP.
A Datomic peer can be run as a standalone HTTP service. See the REST service documentation for information on starting and stopping the service. Many clients can connect to a single instance of the HTTP service, and one instance of the service represents one licensed peer.
The service is its own documentation. Just point a browser at the root of the server:port on which you started the service. Note that the 'web app' that results is the service. It is not an app built on the service, nor a set of documentation pages about the service. The URIs, query params, and POST data are the same ones you will use when accessing the service programmatically.
In addition to the self-describing nature of the REST service, some basic documentation of the available endpoints is available in the REST service documentation.
The REST service accepts and responds with EDN data.
A full-featured client of the Datomic REST service should support round-trip conversions between native data structures and EDN, the data format that the REST service sends and receives. Doing so would allow users of the native language to build transactions and queries using native data structures, just like users of the Peer library in JVM languages.
Datomic community members have contributed the following language-specific libraries which provide idiomatic support for Datomic. The Datomic team encourages third-party language libraries, but does not support them directly.
- https://github.com/pellucidanalytics/datomisca – Native JVM Peer with Scala idioms
- https://github.com/relevance/diametric – Native (JRuby) and REST ActiveModel wrapper for Ruby
- https://github.com/jeffbrown/groovy-datomic – Native JVM Peer with Groovy idioms
- https://github.com/gns24/pydatomic – REST client in Python