This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-03
Channels
- # announcements (17)
- # asami (17)
- # babashka (20)
- # beginners (110)
- # calva (1)
- # cherry (3)
- # cider (1)
- # clj-kondo (21)
- # clj-on-windows (1)
- # cljsrn (5)
- # clojure (142)
- # clojure-austin (1)
- # clojure-europe (72)
- # clojure-france (28)
- # clojure-hungary (2)
- # clojure-nl (2)
- # clojure-norway (38)
- # clojure-poland (2)
- # clojure-uk (3)
- # clojurescript (4)
- # cursive (33)
- # data-science (3)
- # datahike (5)
- # datomic (1)
- # emacs (27)
- # events (3)
- # fulcro (15)
- # graalvm (4)
- # gratitude (2)
- # honeysql (7)
- # humbleui (8)
- # introduce-yourself (11)
- # jobs-discuss (9)
- # lambdaisland (3)
- # lsp (18)
- # malli (62)
- # music (1)
- # nbb (3)
- # off-topic (10)
- # pathom (3)
- # pedestal (6)
- # polylith (5)
- # re-frame (7)
- # releases (2)
- # shadow-cljs (33)
- # sql (1)
- # test-check (23)
- # vim (20)
- # xtdb (9)
how can I covert string vector to honeysql like this:
(defn sql-vec ["or",
["and", ["=","col_a","a"],["=","col_b",1]]
,
["and", ["=","col_d","a"],["=","col_e",1]]])
(what-fn sql-vec)
output :
[:or
[:and [:= :col_a "a"],[:= :col_b 1]
[:and [:= :col_c "a"],[:= :col_d 1]]]
Is there a function that already existsHow would you tell the difference between a column or function name and an actual string value?
How/why are you using strings in the first place? HoneySQL accepts symbols as well as keywords, if that's any help and lets you use lists instead of vectors in most places: '(or (and (= col_a "a") (= col_b 1)) (and (= col_d "a") (= col_e 1)))
thank you. but I want to use a json string to define sql where condition, frontend post json where to backend. I wrote it for a long time, and it basically worked. but it felt ugly. the recursive processing of the data confused me.
(defn first-second->key
[[f1 f2 f3]]
[(keyword f1) (keyword f2) f3])
(defn reslove-exp-v
[v]
(if (vector? v)
(if (every? #(not (vector? %)) v)
(first-second->key v)
(mapv reslove-exp-v v))
(keyword v)))
(defn reslove-exp
[exp]
(if (every? #(not (vector? %)) exp)
(first-second->key exp)
(mapv reslove-exp-v exp)))
(reslove-exp ["=" "id" "1234"])
;; => [:= :id "1234"]
(reslove-exp ["or",
["and", ["=","col_a","a"],["=","dff",1]]
,
["and", ["=","col_b","bb"],["=","abc",1]]])
;; => [:or [:and [:= :col_a "a"] [:= :dff 1]] [:and [:= :col_b "bb"] [:= :abc 1]]]
Bear in mind that [:= "a" :col_x]
is a perfectly valid condition too...