mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 03:16:37 +00:00
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:
@@ -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!)
|
||||
|
||||
Reference in New Issue
Block a user