Skip to content

Commit

Permalink
aggregates, predicates, sortings
Browse files Browse the repository at this point in the history
  • Loading branch information
ApricotLace committed Aug 4, 2023
1 parent 1d28a79 commit 4b50541
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
60 changes: 54 additions & 6 deletions src/zd/blocks/content.clj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
(filterv #(not (str/blank? %)))
(mapv (fn [x]
(if (str/starts-with? x "(")
['expr (edamame.core/parse-string x)]
['expr (edamame.core/parse-string x {:regex true})]
(let [[e k] (str/split x #":" 2)]
[(symbol e) (cond
(= k "*") (symbol k)
Expand All @@ -84,17 +84,45 @@
(conj acc (list 'pull k cs))
(conj acc k))))))
[]))
where-items (->> xs
(filterv #(not (re-matches #"^\s?>.*" %)))
(mapv (fn [x] (edamame.core/parse-string (str/replace (str "[" x "]") #"#" ":symbol/")))))
where-items
(->> xs
(filterv (every-pred #(not (str/ends-with? % " :asc"))
#(not (str/ends-with? % " :desc"))
#(not (re-matches #"^\s?>.*" %))))
(mapv (fn [x] (let [res (edamame.core/parse-string (str/replace (str "[" x "]") #"#" ":symbol/")
{:regex true})]
(cond
(list? (get res 1))
(vector res)

:else
res)
))))
where (->> where-items
(mapv (fn [x]
(clojure.walk/postwalk
(fn [y]
(if (and (keyword? y) (= "symbol" (namespace y)))
(str "'" (name y))
y)) x))))]
y)) x))))

order-items
(->> xs
(filterv (every-pred #(or (str/ends-with? % " :asc")
(str/ends-with? % " :desc"))
#(not (re-matches #"^\s?>.*" %))))
(mapv (fn [x] (edamame.core/parse-string (str/replace (str "[" x "]") #"#" ":symbol/") {:regex true}))))

order
(->> order-items
(mapv (fn [x]
(clojure.walk/postwalk
(fn [y]
(if (and (keyword? y) (= "symbol" (namespace y)))
(str "'" (name y))
y)) x))))]
(into {:where where
:order order
:find find-items
:columns columns
:index @index} )))
Expand All @@ -114,7 +142,27 @@ p :role #roles.cto
> (mean e)
")

;; (parse-query q)
(def q2
"
e :parent #customers
e :category cat
(clojure.string/starts-with? cat \"s\")
e :customer-since since
e :asc
> e:name
> (count e)
"
)

(def q3
"
e :parent #customers
e asc
> e
")

(parse-query q3)

(defn render-table-value [ztx v block]
(cond
Expand Down
4 changes: 3 additions & 1 deletion test/zd/system_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
(zen/start-system ztx 'zd.test/system))

(comment
(restart! ztx))
(restart! ztx)

)

0 comments on commit 4b50541

Please sign in to comment.