浏览代码

Add fn to clean up all dbs

Tienson Qin 1 年之前
父节点
当前提交
aeb5026a26
共有 2 个文件被更改,包括 23 次插入11 次删除
  1. 16 11
      src/main/frontend/db_worker.cljs
  2. 7 0
      src/main/frontend/persist_db/browser.cljs

+ 16 - 11
src/main/frontend/db_worker.cljs

@@ -174,16 +174,6 @@
         (swap! *datascript-conns assoc repo conn)
         nil))))
 
-(comment
-  (defn <remove-all-files!
-    "!! Dangerous: use it only for development."
-    []
-    (p/let [all-files (<list-all-files)
-            files (filter #(= (.-kind %) "file") all-files)
-            dirs (filter #(= (.-kind %) "directory") all-files)
-            _ (p/all (map (fn [file] (.remove file)) files))]
-      (p/all (map (fn [dir] (.remove dir)) dirs)))))
-
 (defn- remove-vfs!
   [^js pool]
   (when pool
@@ -281,10 +271,25 @@
    [this repo data]
    (when-not (string/blank? repo)
      (p/let [pool (<get-opfs-pool repo)]
-       (<import-db pool data)))))
+       (<import-db pool data))))
+
+  (dangeriousRemoveAllDbs
+   [this repo]
+   (p/let [dbs (.listDB this)]
+     (p/all (map #(.unsafeUnlinkDB this %) dbs)))))
 
 (defn init
   "web worker entry"
   []
   (let [^js obj (SQLiteDB.)]
     (Comlink/expose obj)))
+
+(comment
+  (defn <remove-all-files!
+   "!! Dangerous: use it only for development."
+   []
+   (p/let [all-files (<list-all-files)
+           files (filter #(= (.-kind %) "file") all-files)
+           dirs (filter #(= (.-kind %) "directory") all-files)
+           _ (p/all (map (fn [file] (.remove file)) files))]
+     (p/all (map (fn [dir] (.remove dir)) dirs)))))

+ 7 - 0
src/main/frontend/persist_db/browser.cljs

@@ -114,3 +114,10 @@
                      (prn :debug :import-db-error repo)
                      (js/console.error error)
                      (notification/show! [:div (str "SQLiteDB import error: " error)] :error) {}))))))
+
+(comment
+  (defn clean-all-dbs!
+    []
+    (when-let [sqlite @*sqlite]
+      (.dangeriousRemoveAllDbs sqlite)
+      (state/set-current-repo! nil))))