Is it possible to use FleetDB embedded in clojure?

83 views
Skip to first unread message

tbatchelli

unread,
Feb 20, 2010, 5:42:05 PM2/20/10
to FleetDB
All,

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?

Mark McGranaghan

unread,
Feb 20, 2010, 7:38:15 PM2/20/10
to FleetDB
Yes, you can absolutely use FleetDB from Clojure as an embedded
database. Actually, the FleetDB server is just a thin TCP+JSON wrapper
around this embedded interface.

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

Reply all
Reply to author
Forward
0 new messages