refactor: use rules

pull/1347/head
Tienson Qin 2021-02-18 22:20:30 +08:00
parent 2b9b9429a8
commit 5e50ac671d
1 changed files with 13 additions and 11 deletions

View File

@ -22,6 +22,13 @@
;; TODO: extract to specific models and move data transform logic to the
;; correponding handlers.
(def rules
'[[(parent ?p ?c)
[?p :block/children ?c]]
[(parent ?p ?c)
[?t :block/children ?c]
(parent ?p ?t)]])
(defn transact-files-db!
([tx-data]
(db-utils/transact! (state/get-current-repo) tx-data))
@ -569,17 +576,12 @@
(when-let [conn (conn/get-conn repo)]
(let [eid (:db/id (db-utils/entity repo [:block/uuid block-uuid]))]
(->> (d/q
'[:find ?e1
:in $ ?e2 %
:where (parent ?e2 ?e1)]
conn
eid
;; recursive rules
'[[(parent ?e2 ?e1)
[?e2 :block/children ?e1]]
[(parent ?e2 ?e1)
[?t :block/children ?e1]
(parent ?e2 ?t)]])
'[:find ?c
:in $ ?p %
:where (parent ?p ?c)]
conn
eid
rules)
(apply concat)))))
(defn get-block-immediate-children