Skip to content

Instantly share code, notes, and snippets.

@ga2arch
Created March 24, 2018 09:08
Show Gist options
  • Save ga2arch/4ec6f63744099d456c0e2511fa3b301b to your computer and use it in GitHub Desktop.
Save ga2arch/4ec6f63744099d456c0e2511fa3b301b to your computer and use it in GitHub Desktop.
datascript-persistent
(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