fix: sort-by filter for db graphs

Also fixed a dsl-query sorting bug where nil property values where
incorrectly being treated as greater than non-nil values. Also
fixed a bug where blocks with an explicit :block/created-at weren't
being set for sqlite-build
This commit is contained in:
Gabriel Horner
2024-06-05 16:57:51 -04:00
parent 29faedc4d0
commit 8f6f52d630
3 changed files with 54 additions and 38 deletions

View File

@@ -532,7 +532,7 @@ created-at:: 1608968448116
(if js/process.env.DB_GRAPH
(def get-property-value query-dsl/get-db-property-value)
(def get-property-value #(get-in %1 [:block/properties %2])))
(def get-property-value #(get-in %1 [:block/properties %2])))
(deftest sort-by-queries
(load-test-files [{:file/path "journals/2020_02_25.md"
@@ -550,44 +550,45 @@ created-at:: 1608968448115
- 26-b4
created-at:: 1608968448116
"}])
(testing "sort-by user block property fruit"
(let [result (->> (dsl-query "(and (task now later done) (sort-by fruit))")
(map #(get-property-value % :fruit)))]
(is (= ["plum" "apple" nil]
result)
"sort-by correctly defaults to desc"))
(let [task-filter (if js/process.env.DB_GRAPH "(task todo done)" "(task later done)")]
(testing "sort-by user block property fruit"
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit))"))
(map #(get-property-value % :fruit)))]
(is (= ["plum" "apple" nil]
result)
"sort-by correctly defaults to desc"))
(let [result (->> (dsl-query "(and (task now later done) (sort-by fruit desc))")
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit desc))"))
(map #(get-property-value % :fruit)))]
(is (= ["plum" "apple" nil]
result)
"sort-by desc"))
(let [result (->> (dsl-query "(and (task now later done) (sort-by fruit asc))")
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit asc))"))
(map #(get-property-value % :fruit)))]
(is (= ["apple" "plum" nil]
(is (= [nil "apple" "plum"]
result)
"sort-by asc")))
(testing "sort-by hidden, built-in block property created-at"
(let [result (->> (dsl-query "(and (task now later done) (sort-by created-at desc))")
(testing "sort-by hidden, built-in block property created-at"
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by created-at desc))"))
(map #(get-property-value % :created-at)))]
(is (= [1608968448115 1608968448114 1608968448113]
result))
"sorted-by desc")
(let [result (->> (dsl-query "(and (todo now later done) (sort-by created-at asc))")
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by created-at asc))"))
(map #(get-property-value % :created-at)))]
(is (= [1608968448113 1608968448114 1608968448115]
result)
"sorted-by asc")))
(testing "user page property rating"
(testing "user page property rating"
(is (= [10 8]
(->> (dsl-query "(and (page-property rating) (sort-by rating))")
(map #(get-property-value % :rating)))))))
(map #(get-property-value % :rating))))))))
(deftest simplify-query
(deftest ^:done simplify-query
(are [x y] (= (query-dsl/simplify-query x) y)
'(and [[foo]])
'[[foo]]