datalog: dl-rules-of relation-inspection helper (214/214)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 49s

(dl-rules-of db rel-name) → list of rules with head matching
the given relation name. Useful for tooling and debugging
("show me how this relation is derived") without exposing the
internal :rules list directly.

2 new api tests cover hit and miss cases.
This commit is contained in:
2026-05-08 10:17:44 +00:00
parent fc6979a371
commit 9695d31dab
4 changed files with 38 additions and 6 deletions

View File

@@ -198,6 +198,24 @@
(dl-magic-query db (first qbody)))
(else (dl-query db qbody)))))))))
;; List rules whose head's relation matches `rel-name`. Useful for
;; inspection ("show me how this relation is derived") without
;; exposing the internal `:rules` list.
(define
dl-rules-of
(fn
(db rel-name)
(let ((out (list)))
(do
(for-each
(fn
(rule)
(when
(= (dl-rel-name (get rule :head)) rel-name)
(append! out rule)))
(dl-rules db))
out))))
(define
dl-rule-head-rels
(fn