improving query
This commit is contained in:
@@ -12,6 +12,13 @@
|
||||
:else
|
||||
(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]
|
||||
(let [query (-> query
|
||||
(update :args conj value)
|
||||
@@ -19,6 +26,13 @@
|
||||
(update-in [:query :where] conj where))]
|
||||
(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 ]
|
||||
(cond->> results
|
||||
sort-fn (sort-by sort-fn)
|
||||
@@ -32,22 +46,20 @@
|
||||
:count (count results)})
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find (if (:sort-by args)
|
||||
['?e '?sorter]
|
||||
['?e])
|
||||
(let [query (cond-> {:query {:find ['?e]
|
||||
:in ['$ ]
|
||||
:where
|
||||
(condp = (:sort-by args)
|
||||
"client" ['[?e :transaction/id]
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
|
||||
nil [['?e :transaction/id]]
|
||||
|
||||
[['?e (keyword "transaction" (:sort-by args)) '?sorter]])
|
||||
}
|
||||
:where ['[?e :transaction/id]]}
|
||||
:args [db]}
|
||||
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction/id]
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
"description-original" ['[?e :transaction/description-original ?sorter]]
|
||||
"date" ['[?e :transaction/date ?sorter]]
|
||||
"amount" ['[?e :transaction/amount ?sorter]]
|
||||
"status" ['[?e :transaction/status ?sorter]]}
|
||||
args)
|
||||
|
||||
(limited-clients (:id args)) (add-arg '[?xx ...] (set (map :db/id (limited-clients (:id args))))
|
||||
'[?e :transaction/client ?xx])
|
||||
(:client-id args) (add-arg '?client-id (:client-id args)
|
||||
|
||||
Reference in New Issue
Block a user