There is this little Clojure project that I am working on, and I am
thinking on using FleetDB as means of storage, but I was wondering if
FleetDB can be used in embedded mode. Is that a use case/possible or
the only way to use FleetDB from clojure is via the clojure-client/
JSON?
Here is a hello world example:
(require '(fleetdb [embedded :as embedded]))
(let [db-atom (embedded/init-persistent "/tmp/fleetdb-demo.fdb")]
(embedded/query db-atom
["insert" "records" [{"id" 1 "name" "foo"} {"id" 2 "name"
"bar"}]])
(embedded/close db-atom))
(let [db-atom (embedded/load-persistent "/tmp/fleetdb-demo.fdb")]
(prn (embedded/query db-atom
["select" "records"]))
(embedded/close db-atom))
The query syntax is the same for an embedded database as for a remote
server; just pass Clojure data structures instead of JSON. A few
places you might want to look for more info:
- The embedded.clj in the FleetDB source; this defines the embedded
API.
- The gitcred project (http://github.com/mmcgrana/gitcred), which uses
a FleetDB embedded database; search for "(embedded/" in the source to
see the calls into the embedded API.
I hope this helps. Let me know if you have more questions.
- Mark