From 7728648b3972f31552be71d20431aaca8a5530cd Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Fri, 7 Oct 2016 16:06:48 -0700 Subject: [PATCH] Support order-by query option from JS. --- src/common/datomish/js.cljs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/common/datomish/js.cljs b/src/common/datomish/js.cljs index f649c6d9..2a9710e0 100644 --- a/src/common/datomish/js.cljs +++ b/src/common/datomish/js.cljs @@ -8,6 +8,9 @@ [datomish.pair-chan :refer [go-pair !]] [cljs.reader] [cljs-promises.core :refer [promise]] @@ -27,9 +30,29 @@ (def ^:export db d/db) +(defn- cljify-options [options] + ;; Step one: basic parsing. + (let [o (cljify options)] + ;; Step two: convert `order-by` into keywords. + (if-let [ord (:order-by o)] + (assoc o + :order-by + (map + (fn [[var dir]] + [(keyword var) + (case dir + "asc" :asc + "desc" :desc + nil :asc + :default + (raise "Unexpected order-by direction " dir + {:direction dir}))]) + ord)) + o))) + (defn ^:export q [db find options] (let [find (cljs.reader/read-string find) - opts (cljify options)] + opts (cljify-options options)] (take-pair-as-promise! (d/js))) @@ -37,7 +60,6 @@ (defn ^:export ensure-schema [conn simple-schema] (let [simple-schema (cljify simple-schema) datoms (simple-schema/simple-schema->schema simple-schema)] - (println "Transacting schema datoms" (pr-str datoms)) (take-pair-as-promise! (d/