An Integrant component that wraps a Datomic Peer connection. It creates the database, transacts your schemas, and manages the connection lifecycle automatically — with built-in retry logic on startup.
project.clj
[net.clojars.macielti/datomic "1.0.0"]
deps.edn
net.clojars.macielti/datomic {:mvn/version "1.0.0"}
(require '[integrant.core :as ig]
'[datomic.component]
'[datomic.api :as d])
(def config
{:datomic.component/datomic
{:schemas [{:db/ident :user/id
:db/valueType :db.type/uuid
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity}
{:db/ident :user/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}]
:components {:config {:datomic-uri "datomic:mem://myapp"}}}})
;; Start the system — creates the DB, connects, and transacts schemas
(def system (ig/init config))
;; Get the connection
(def conn (:datomic.component/datomic system))
;; Use it
@(d/transact conn [{:user/id (random-uuid) :user/name "Alice"}])
;; Stop the system
(ig/halt! system)
Omit :datomic-uri and the component will create a temporary in-memory database automatically.
See doc/intro.md for the full guide, including:
transact-and-lookup-entity! helpermocked-datomicCopyright © 2024
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |