Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Clojure in memory data store?

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?

like image 633
lucidquiet Avatar asked Feb 27 '15 18:02

lucidquiet


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)))
like image 87
DanLebrero Avatar answered Nov 05 '22 22:11

DanLebrero


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.

like image 27
M-x Avatar answered Nov 05 '22 20:11

M-x