feat: export repo as sqlite db

feat/datascript-storage-test
Tienson Qin 2023-12-11 19:14:10 +08:00
parent 4437534685
commit 4d445b8387
3 changed files with 18 additions and 1 deletions

View File

@ -26,6 +26,9 @@
[:li.mb-4
[:a.font-medium {:on-click #(export/export-repo-as-json-v2! current-repo)}
(t :export-json)]]
[:li.mb-4
[:a.font-medium {:on-click #(export/export-repo-as-sqlite-db! current-repo)}
(t :export-sqlite-db)]]
(when (util/electron?)
[:li.mb-4
[:a.font-medium {:on-click #(export/download-repo-as-html! current-repo)}
@ -44,6 +47,7 @@
(t :export-roam-json)]])]
[:a#download-as-edn-v2.hidden]
[:a#download-as-json-v2.hidden]
[:a#download-as-sqlite-db.hidden]
[:a#download-as-roam-json.hidden]
[:a#download-as-html.hidden]
[:a#download-as-zip.hidden]

View File

@ -24,7 +24,8 @@
[logseq.graph-parser.property :as gp-property]
[logseq.graph-parser.util.block-ref :as block-ref]
[logseq.graph-parser.util.page-ref :as page-ref]
[promesa.core :as p])
[promesa.core :as p]
[frontend.persist-db :as persist-db])
(:import
[goog.string StringBuffer]))
@ -397,6 +398,17 @@
(.setAttribute anchor "download" filename)
(.click anchor))))))
(defn export-repo-as-sqlite-db!
[repo]
(p/let [data (persist-db/<export-db repo {:return-data? true})
filename (str repo ".sqlite")
url (js/URL.createObjectURL (js/Blob. data))]
(when-not (mobile-util/native-platform?)
(when-let [anchor (gdom/getElement "download-as-sqlite-db")]
(.setAttribute anchor "href" url)
(.setAttribute anchor "download" filename)
(.click anchor)))))
;;;;;;;;;;;;;;;;;;;;;;;;;
;; Export to roam json ;;
;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -503,6 +503,7 @@
:export-opml "Export as OPML"
:export-public-pages "Export public pages"
:export-json "Export as JSON"
:export-sqlite-db "Export as SQLite DB"
:export-roam-json "Export as Roam JSON"
:export-edn "Export as EDN"
:export-transparent-background "Transparent background"