Skip to content

Instantly share code, notes, and snippets.

@jdkealy
Created June 15, 2017 18:38
Show Gist options
  • Save jdkealy/240bdb36986e708863a54d7ebefba50a to your computer and use it in GitHub Desktop.
Save jdkealy/240bdb36986e708863a54d7ebefba50a to your computer and use it in GitHub Desktop.
(defn concat-memo [current _new]
(let [oldq (:query current)
oldi (:inputs current)
newq (:query _new)
newi (:inputs _new)
_all {:query {:find (if-let [_find (:find newq)]
(vec (concat (:find oldq) _find))
(:find oldq))
:in (if-let [_in (:in newq)]
(vec (concat (:in oldq) _in))
(:in oldq))
:where (if-let [_where (:where newq)]
(conj (:where oldq) _where)
(:where oldq)) }
:inputs (vec (concat oldi newi))}]
;(concat [(:query _all) (:inputs _all)])
;(:query _all)
_all
))
(defn concat-query [inputs]
(vec (concat [(:query inputs)] (:inputs inputs))))
(defn build-user-query [inputs base-org]
(let [input (conj inputs {:org base-org})]
(concat-query (reduce (fn [memo item]
(let [_key (-> item keys first)
_val (-> item vals first)
adding (case _key
:all {:query {:in ['[?attrs ...] '?stext]
:where ['[?u attrs ?val]
['(clojure.string/includes? ?val ?stext)]]}
:inputs [[:user/email :user/name] _val]}
:org {:query {:in ['?orgid]
}
:inputs [_val]})]
(concat-memo memo adding))
) {:query {:find [(quote ?u)] :in ['$] :where []}
:inputs []} input))))
(comment
(let [query (build-user-query [{:all "john"}]
123)]
;(apply d/q query)
query
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment