问题
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?
回答1:
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)))
回答2:
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.
来源:https://stackoverflow.com/questions/28771605/is-there-a-clojure-in-memory-data-store