From 07bfc2edff412f31378aadd2f5f7dbf06c1766dd Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 18 Feb 2021 13:06:03 +0800 Subject: [PATCH] fix: api.q --- src/main/api.cljs | 2 +- src/main/frontend/db/query_custom.cljs | 55 ++++++++++++++------------ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/api.cljs b/src/main/api.cljs index 9159b52cb6..6411258d5c 100644 --- a/src/main/api.cljs +++ b/src/main/api.cljs @@ -10,7 +10,7 @@ (when-let [repo (state/get-current-repo)] (when-let [conn (db/get-conn repo)] (when-let [result (query-dsl/query repo query-string)] - @result)))) + (clj->js @result))))) (defn ^:export datascript_query [query & inputs] diff --git a/src/main/frontend/db/query_custom.cljs b/src/main/frontend/db/query_custom.cljs index f8434dec07..9cb863ab23 100644 --- a/src/main/frontend/db/query_custom.cljs +++ b/src/main/frontend/db/query_custom.cljs @@ -45,32 +45,35 @@ (defn custom-query-result-transform [query-result remove-blocks q] - (let [repo (state/get-current-repo) - result (db-utils/seq-flatten query-result) - block? (:block/uuid (first result))] - (let [result (if block? - (let [result (if (seq remove-blocks) - (let [remove-blocks (set remove-blocks)] - (remove (fn [h] - (contains? remove-blocks (:block/uuid h))) - result)) - result)] - (some->> result - (db-utils/with-repo repo) - (model/with-block-refs-count repo) - (model/sort-blocks))) - result)] - (if-let [result-transform (:result-transform q)] - (if-let [f (sci/eval-string (pr-str result-transform))] - (try - (sci/call-fn f result) - (catch js/Error e - (log/error :sci/call-error e) - result)) - result) - (if block? - (db-utils/group-by-page result) - result))))) + (try + (let [repo (state/get-current-repo) + result (db-utils/seq-flatten query-result) + block? (:block/uuid (first result))] + (let [result (if block? + (let [result (if (seq remove-blocks) + (let [remove-blocks (set remove-blocks)] + (remove (fn [h] + (contains? remove-blocks (:block/uuid h))) + result)) + result)] + (some->> result + (db-utils/with-repo repo) + (model/with-block-refs-count repo) + (model/sort-blocks))) + result)] + (if-let [result-transform (:result-transform q)] + (if-let [f (sci/eval-string (pr-str result-transform))] + (try + (sci/call-fn f result) + (catch js/Error e + (log/error :sci/call-error e) + result)) + result) + (if block? + (db-utils/group-by-page result) + result)))) + (catch js/Error e + (log/error :query/failed e)))) (defn- resolve-query [query]