Datomex
Datomex is a low level driver for the Datomic database.
Datomex utilizes Datomic's REST API, so in order to use Datomex, a Datomic peer to serve as an HTTP server must be running. The peer can be executed with the following:
bin/rest -p port [-o origins]? [alias uri]+
For example, to run Datomex's tests, start Datomic with:
bin/rest -p 8888 -o /'*'/ db datomic:mem://
More information about the REST API is available at http://docs.datomic.com/rest.html .
Datomex must be initialized by calling start_link
and passing in the server
, port
, alias
and name
. For example:
Datomex.start_link "localhost", 8888, "db", "test"
server
- the host where Datomic is running, as a binary, example:"localhost"
port
- the port where Datomic is running as an integer, example:80
alias_db
- the name of the alias for the datomic uri, example:"db"
name
- the name of the default database, example:"test"
Summary
create_database(name) | Create a new database at the configured alias |
create_database(alias_name, name) | Create a new database at the passed in alias |
databases() | Get a list of Datomic databases from the configured alias |
databases(alias_name) | Get a list of Datomic databases from a passed in alias |
datoms(index) | Get some datoms from Datomic by index |
datoms(index, opts) | Get some datoms from Datomic by index with optional arguments |
entity(opts) | Get an entity from Datomic |
entity(eid, opts) | |
index_range(index, attrid) | Get a range of index data |
index_range(index, attrid, opts) | |
q(query) | Query datomic |
q(query, opts) | |
q(query, args, opts) | |
start_link(server, port, alias_db, name) | Configures Datomex for connection with your Datomic Peer |
storages() | Get a list of Datomic storages |
transact(data) | Send a transaction to Datomic |
Functions
Query datomic.
Datomex.q(~s([:find ?m :where [?m :movie/title "trainspotting"]]))
Configures Datomex for connection with your Datomic Peer.
Datomex.start_link "localhost", 8888, "db", "test"
server
- the host where Datomic is running, as a binary, example:"localhost"
port
- the port where Datomic is running as an integer, example:80
alias_db
- the name of the alias for the datomic uri, example:"db"
name
- the name of the default database, example:"test"
Get a list of Datomic storages
iex> Datomex.storages {:ok, %HTTPoison.Response{body: "["db"]", headers: %{"Content-Length" => "6", "Content-Type" => "application/edn;charset=UTF-8", "Date" => "Mon, 24 Nov 2014 10:14:24 GMT", "Server" => "Jetty(8.1.11.v20130520)", "Vary" => "Accept"}, status_code: 200}}
Send a transaction to Datomic.
movies = ~s([
{:db/id #db/id[:db.part/db]
:db/ident :movie/title
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "movie's title"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :movie/rating
:db/valueType :db.type/double
:db/cardinality :db.cardinality/one
:db/doc "movie's rating"
:db.install/_attribute :db.part/db}
])
Datomex.transact movies