persist.cljs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (ns frontend.db.persist
  2. (:require [frontend.util :as util]
  3. [frontend.idb :as idb]
  4. [frontend.config :as config]
  5. [electron.ipc :as ipc]
  6. [frontend.db.conn :as db-conn]
  7. [promesa.core :as p]))
  8. (defn get-all-graphs
  9. []
  10. (if (util/electron?)
  11. (p/let [result (ipc/ipc "getGraphs")
  12. result (vec result)
  13. ;; backward compatibility (release <= 0.5.4)
  14. result (if (seq result) result (idb/get-nfs-dbs))]
  15. result)
  16. (idb/get-nfs-dbs)))
  17. (defn get-serialized-graph
  18. [graph-name]
  19. (if (util/electron?)
  20. (p/let [result (ipc/ipc "getSerializedGraph" graph-name)
  21. result (if result result
  22. (let [graph-name (str config/idb-db-prefix graph-name)]
  23. (idb/get-item graph-name)))]
  24. result)
  25. (idb/get-item graph-name)))
  26. (defn save-graph!
  27. [key value]
  28. (if (util/electron?)
  29. (do
  30. (ipc/ipc "saveGraph" key value)
  31. ;; remove cache before 0.5.5
  32. (idb/remove-item! key))
  33. (idb/set-batch! [{:key key :value value}])))
  34. (defn delete-graph!
  35. [graph]
  36. (let [key (db-conn/datascript-db graph)]
  37. (if (util/electron?)
  38. (do
  39. (ipc/ipc "deleteGraph" key)
  40. (idb/remove-item! key))
  41. (idb/remove-item! key))))