As of April 27, 2023, Datomic Pro is free!
This repository contains example Docker and Docker Compose files for running Datomic Pro locally on your computer.
These examples are designed for prototyping and educational purposes; they should not be considered suitable or ready for production use.
This is not an official Datomic project or documentation and is not affiliated with Datomic in any way.
Official Documentation: Storage Services
Official Documentation: Provisioning dev mode
Copy the Docker Compose file:
cp compose/dev-mode.yml docker-compose.yml
Run the Datomic Transactor:
docker compose up datomic-transactor
To restore a backup of the MusicBrainz Sample Database:
docker compose run datomic-tools ./bin/datomic restore-db file:/usr/mbrainz-1968-1973 "datomic:dev://datomic-transactor:4334/my-datomic?password=unsafe"
Official Documentation Provisioning a SQL database
Copy the Docker Compose file:
cp compose/postgresql.yml docker-compose.yml
Run the Datomic Storage Service (PostgreSQL):
docker compose up datomic-storage
Create the table for Datomic:
docker compose run datomic-tools psql -f bin/sql/postgres-table.sql -h datomic-storage -U datomic-user -d my-datomic
You will be prompted for a password, which is unsafe
.
Run the Datomic Transactor:
docker compose up datomic-transactor
To restore a backup of the MusicBrainz Sample Database:
docker compose run datomic-tools ./bin/datomic restore-db file:/usr/mbrainz-1968-1973 "datomic:sql://?jdbc:postgresql://datomic-storage:5432/my-datomic?user=datomic-user&password=unsafe"
To run Datomic Console:
docker compose up datomic-console
Starting a REPL:
docker compose run datomic-tools clojure -M:repl
Documentation: Getting Started
Require the API and set the appropriate db-uri
:
(require '[datomic.api :as d])
; If you are using Dev Mode:
(def db-uri "datomic:dev://datomic-transactor:4334/my-datomic/?password=unsafe")
; If you are using PostgreSQL:
(def db-uri "datomic:sql://?jdbc:postgresql://datomic-storage:5432/my-datomic?user=datomic-user&password=unsafe")
If you have restored a backup of the MusicBrainz sample database:
(def conn (d/connect db-uri))
(def db (d/db conn))
(d/q '[:find ?id ?type ?gender
:in $ ?name
:where
[?e :artist/name ?name]
[?e :artist/gid ?id]
[?e :artist/type ?teid]
[?teid :db/ident ?type]
[?e :artist/gender ?geid]
[?geid :db/ident ?gender]]
db
"Jimi Hendrix")
If you are creating a new database from scratch:
(d/create-database db-uri)
(def conn (d/connect db-uri))
@(d/transact conn [{:db/doc "Hello world"}])
@(d/transact conn [{:db/ident :movie/title
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The title of the movie"}
{:db/ident :movie/genre
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The genre of the movie"}
{:db/ident :movie/release-year
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "The year the movie was released in theaters"}])
@(d/transact conn [{:movie/title "The Goonies"
:movie/genre "action/adventure"
:movie/release-year 1985}
{:movie/title "Commando"
:movie/genre "action/adventure"
:movie/release-year 1985}
{:movie/title "Repo Man"
:movie/genre "punk dystopia"
:movie/release-year 1984}])
(def db (d/db conn))
(d/q '[:find ?e ?movie-title
:where [?e :movie/title ?movie-title]]
db)
To exit the REPL, press Ctrl+D or type:
:repl/quit
Sometimes the REPL insists on hanging; in that case, you can kill the container:
docker compose kill datomic-tools
Dependencies reference: