feat: simple query builder (#8774)

Simple query builder

---------

Co-authored-by: Gabriel Horner <gabriel@logseq.com>
Co-authored-by: charlie <xyhp915@qq.com>
This commit is contained in:
Tienson Qin
2023-03-21 14:27:00 +08:00
committed by GitHub
parent 7a905583cf
commit db6fc6b7ee
37 changed files with 1263 additions and 295 deletions

View File

@@ -45,6 +45,30 @@
;; Tests
;; =====
(deftest pre-transform-test
(testing "page references should be quoted and tags should be handled"
(are [x y] (= (query-dsl/pre-transform x) y)
"#foo"
"#tag foo"
"(and #foo)"
"(and #tag foo)"
"[[test #foo]]"
"\"[[test #foo]]\""
"(and [[test #foo]] (or #foo))"
"(and \"[[test #foo]]\" (or #tag foo))"
"\"for #clojure\""
"\"for #clojure\""
"(and \"for #clojure\")"
"(and \"for #clojure\")"
"(and \"for #clojure\" #foo)"
"(and \"for #clojure\" #tag foo)")))
(defn- block-property-queries-test
[]
(load-test-files [{:file/path "journals/2022_02_28.md"
@@ -529,6 +553,26 @@ created-at:: 1608968448116
(->> (dsl-query "(and (page-property rating) (sort-by rating))")
(map #(get-in % [:block/properties :rating])))))))
(deftest simplify-query
(are [x y] (= (query-dsl/simplify-query x) y)
'(and [[foo]])
'[[foo]]
'(and (and [[foo]]))
'[[foo]]
'(and (or [[foo]]))
'[[foo]]
'(and (not [[foo]]))
'(not [[foo]])
'(and (or (and [[foo]])))
'[[foo]]
'(not (or [[foo]]))
'(not [[foo]])))
(comment
(require '[clojure.pprint :as pprint])
(test-helper/start-test-db!)