What’s the recommended way to use in-memory databases - for automated tests - via the Datomic Client API?
Is that something I could/should do with dev-local
?
So far I was using the Peer API for that purpose, but if I want to transition to using the Client API, then I can’t use that approach anymore, can I?
I’m aware of the https://github.com/ComputeSoftware/datomic-client-memdb library, which has been deprecated in favour of dev-local
recently, but I don’t see how dev-local
serves the in-memory use-case.
According to https://docs.datomic.com/on-prem/peer-server.html, we can start a peer-server, which exposes an in-memory db, but it doesn’t allow my automated test suite to isolate my tests into different, independent in-memory DBs.
I also haven’t found any official way to directly start a temporary peer-server from my application’s process, without shelling out.
I did look into what happens when I bin/run -m datomic.peer-server ...
, so I could start a peer-server, but I have no idea how to shut it down.
I’ve added these to deps.edn
(where CURRENT
is a link to datomic-pro-1.0.6165/
):
:aliases
{:datomic-peer
{:extra-paths
["CURRENT/resources"
"CURRENT/datomic-transactor-pro-1.0.6165.jar"
"CURRENT/lib/*"
"CURRENT/bin"]}
then I could do the following:
;; Start a Peer Server for convenience
(comment
;; Based on
;; https://docs.datomic.com/on-prem/getting-started/connect-to-a-database.html
;; bin/run -m peer-server -h localhost -p 8998 \
;; -a myaccesskey,mysecret -d hello,datomic:mem://hello
(require '[datomic.peer-server :as peer-server]
'[clojure.tools.cli :as cli])
@(def peer-server-config
(-> ["-h" "localhost"
"-p" "8998"
"-a" "myaccesskey,mysecret"
"-d" "hello,datomic:mem://hello"]
(cli/parse-opts datomic.peer-server/cli-options)))
@(def peer-server
(datomic.peer-server/create (:options peer-server-config)))
)