improving query
This commit is contained in:
@@ -12,6 +12,13 @@
|
|||||||
:else
|
:else
|
||||||
(keyword "transaction" sort-by)))
|
(keyword "transaction" sort-by)))
|
||||||
|
|
||||||
|
(defn add-where [query & wheres]
|
||||||
|
(reduce #(update-in %1 [:query :where] conj %2) query wheres))
|
||||||
|
|
||||||
|
(defn add-wheres [query wheres]
|
||||||
|
(apply add-where query wheres))
|
||||||
|
|
||||||
|
|
||||||
(defn add-arg [query name value where & rest]
|
(defn add-arg [query name value where & rest]
|
||||||
(let [query (-> query
|
(let [query (-> query
|
||||||
(update :args conj value)
|
(update :args conj value)
|
||||||
@@ -19,6 +26,13 @@
|
|||||||
(update-in [:query :where] conj where))]
|
(update-in [:query :where] conj where))]
|
||||||
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
|
||||||
|
|
||||||
|
(defn add-sorter-field [q sort-map args]
|
||||||
|
(-> q
|
||||||
|
(update-in [:query :find] conj '?sorter)
|
||||||
|
(add-wheres (sort-map
|
||||||
|
(:sort-by args)
|
||||||
|
(println "Warning, trying to sort by unsupported field" (:sort-by args))))))
|
||||||
|
|
||||||
(defn apply-sort [args sort-fn results ]
|
(defn apply-sort [args sort-fn results ]
|
||||||
(cond->> results
|
(cond->> results
|
||||||
sort-fn (sort-by sort-fn)
|
sort-fn (sort-by sort-fn)
|
||||||
@@ -32,21 +46,19 @@
|
|||||||
:count (count results)})
|
:count (count results)})
|
||||||
|
|
||||||
(defn raw-graphql-ids [db args]
|
(defn raw-graphql-ids [db args]
|
||||||
(let [query (cond-> {:query {:find (if (:sort-by args)
|
(let [query (cond-> {:query {:find ['?e]
|
||||||
['?e '?sorter]
|
|
||||||
['?e])
|
|
||||||
:in ['$ ]
|
:in ['$ ]
|
||||||
:where
|
:where ['[?e :transaction/id]]}
|
||||||
(condp = (:sort-by args)
|
:args [db]}
|
||||||
"client" ['[?e :transaction/id]
|
|
||||||
|
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction/id]
|
||||||
'[?e :transaction/client ?c]
|
'[?e :transaction/client ?c]
|
||||||
'[?c :client/name ?sorter]]
|
'[?c :client/name ?sorter]]
|
||||||
|
"description-original" ['[?e :transaction/description-original ?sorter]]
|
||||||
nil [['?e :transaction/id]]
|
"date" ['[?e :transaction/date ?sorter]]
|
||||||
|
"amount" ['[?e :transaction/amount ?sorter]]
|
||||||
[['?e (keyword "transaction" (:sort-by args)) '?sorter]])
|
"status" ['[?e :transaction/status ?sorter]]}
|
||||||
}
|
args)
|
||||||
:args [db]}
|
|
||||||
|
|
||||||
(limited-clients (:id args)) (add-arg '[?xx ...] (set (map :db/id (limited-clients (:id args))))
|
(limited-clients (:id args)) (add-arg '[?xx ...] (set (map :db/id (limited-clients (:id args))))
|
||||||
'[?e :transaction/client ?xx])
|
'[?e :transaction/client ?xx])
|
||||||
|
|||||||
Reference in New Issue
Block a user