I program mostly in Node, and like document stores, but I'd like to prototype the data calls between the client and the server first. I've used lowdb and da-base in the past to setup a quick Json data store. Is there something similar for Clojure?
-
1http://www.h2database.com/html/main.html is embeddable – danneu Feb 27 '15 at 18:12
-
see also http://stackoverflow.com/questions/6922340/embedded-pure-java-database-for-clojure – edbond Feb 27 '15 at 19:14
-
1https://github.com/mmcgrana/fleetdb – edbond Feb 27 '15 at 19:15
-
do you need the data to persist or just something that runs in memory and mocks a db while it runs? – sbensu Feb 27 '15 at 19:31
-
@sbensu Well, by persist here, I'm willing to consider write to file. So writing out the data as per pr-str, and the read-string. That might be all I need. – lucidquiet Feb 27 '15 at 20:18
-
1@edbond didn't know about fleetdb, I'll have to take a look at that. – lucidquiet Feb 27 '15 at 20:18
-
h2 meets all your requirements if you are willing to configure a table with an ID and a BLOB attribute and then write a kv protocol that uses pr-str and read-string like you said. Check [this](http://stackoverflow.com/questions/6922340/embedded-pure-java-database-for-clojure) – sbensu Feb 27 '15 at 20:27
-
@sbensu I don't think a DB is as flexible (initially anyway). I'd have to add meta data columns to search the blobs, or load every blob into memory as an object of some kind to search for the right things. Though a file would be simplest, I still want easy search capabilities. – lucidquiet Feb 28 '15 at 02:34
2 Answers
Given that you are just prototype, if you don't need durability, a simple atom will do. If you want durability using simple files have a look at https://github.com/alandipert/enduro
You can have one atom per table or you can have an atom with a map of table->docs, whatever you find simpler. Any query will just be a filter.
For example, to add a document:
(def my-db (atom {}))
(defn add [table doc] (swap! my-db update-in [table] conj doc))
(defn search-by-name [table name]
(filter #(= name (:name %)) (get @my-db table)))

- 8,545
- 1
- 29
- 30
Datascript seems like a perfect (though poorly named) fit for your needs. Basically, it's a lightweight in-memory store designed after Datomic. With a map-in-an-atom approach you very quickly would find yourself writing quirky code for selection, id management, etc. Datascript takes care of such stuff and allows you to write complex queries easily, still being almost as lightweight as a map in an atom.

- 141
- 1