Created
March 24, 2018 09:08
-
-
Save ga2arch/4ec6f63744099d456c0e2511fa3b301b to your computer and use it in GitHub Desktop.
datascript-persistent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn crete-persistent-conn | |
[schema] | |
(letfn [(read-file [source] | |
(with-open [r (PushbackReader. (jio/reader source))] | |
(edn/read | |
{:readers {'datascript/DB (fn [{:keys [datoms schema]}] | |
(db/init-db (mapv #(apply db/datom %) datoms) schema))}} | |
r))) | |
(write-file [filepath data] | |
(with-open [w (jio/writer filepath)] | |
(.write ^BufferedWriter w (pr-str data))))] | |
(with-meta (duratom/duratom | |
:local-file | |
:file-path "./db" | |
:rw {:read read-file | |
:write write-file} | |
:init @(d/create-conn schema)) {:listeners (atom {})}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment