mirror of
https://github.com/logseq/logseq.git
synced 2026-04-25 06:35:02 +00:00
enhance(dev): scripts can read or write db graphs as full path files
This allows for easier use of debugging graphs as they are exported by users as a file. Also DRYed up duplicated helper
This commit is contained in:
13
deps/db/script/dump_datoms.cljs
vendored
13
deps/db/script/dump_datoms.cljs
vendored
@@ -3,28 +3,21 @@
|
||||
|
||||
$ yarn -s nbb-logseq script/dump_datoms.cljs db-name datoms.edn"
|
||||
(:require ["fs" :as fs]
|
||||
["os" :as os]
|
||||
["path" :as path]
|
||||
["path" :as node-path]
|
||||
[clojure.pprint :as pprint]
|
||||
[datascript.core :as d]
|
||||
[logseq.db.common.sqlite-cli :as sqlite-cli]
|
||||
[nbb.core :as nbb]))
|
||||
|
||||
(defn read-graph
|
||||
"The db graph bare version of gp-cli/parse-graph"
|
||||
[graph-name]
|
||||
(let [graphs-dir (path/join (os/homedir) "logseq/graphs")]
|
||||
(sqlite-cli/open-db! graphs-dir graph-name)))
|
||||
|
||||
(defn -main [args]
|
||||
(when (< (count args) 2)
|
||||
(println "Usage: $0 GRAPH FILE")
|
||||
(js/process.exit 1))
|
||||
(let [[graph-name file*] args
|
||||
conn (read-graph graph-name)
|
||||
conn (apply sqlite-cli/open-db! (sqlite-cli/->open-db-args graph-name))
|
||||
datoms (mapv #(vec %) (d/datoms @conn :eavt))
|
||||
parent-dir (or js/process.env.ORIGINAL_PWD ".")
|
||||
file (path/join parent-dir file*)]
|
||||
file (node-path/join parent-dir file*)]
|
||||
(println "Writing" (count datoms) "datoms to" file)
|
||||
(fs/writeFileSync file (with-out-str (pprint/pprint datoms)))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user