Is there a Clojure in memory data store?

早过忘川 提交于 2019-12-10 17:34:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!