minor refactoring
This commit is contained in:
parent
21b4cea2c2
commit
36d13d32dc
2 changed files with 8 additions and 7 deletions
|
|
@ -17,13 +17,14 @@
|
||||||
(defn paren-wrap [x]
|
(defn paren-wrap [x]
|
||||||
(str "(" x ")"))
|
(str "(" x ")"))
|
||||||
|
|
||||||
;; Checks if the first is a `DISTINCT ON` statement, if yes then return a string
|
;; Checks if the first elemnet of the list is a `DISTINCT ON` statement, if yes
|
||||||
;; with an appended space at the end of the first and then comma joining the rest
|
;; then return a string with an appended space at the end of the first and then
|
||||||
;; else simply return a comma joined string
|
;; comma joining the rest else simply return a comma joined string
|
||||||
(defn construct-select [s]
|
(defn construct-select [s]
|
||||||
(if (re-find #"DISTINCT ON" (first s))
|
(let [[fst & rst] s]
|
||||||
(str (first s) " " (comma-join (rest s)))
|
(if (re-find #"DISTINCT ON" fst)
|
||||||
(comma-join s)))
|
(str fst " " (comma-join rst))
|
||||||
|
(comma-join s))))
|
||||||
|
|
||||||
(def ^:dynamic *clause*
|
(def ^:dynamic *clause*
|
||||||
"During formatting, *clause* is bound to :select, :from, :where, etc."
|
"During formatting, *clause* is bound to :select, :from, :where, etc."
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@
|
||||||
sql/format)))))
|
sql/format)))))
|
||||||
|
|
||||||
(deftest distinct-on
|
(deftest distinct-on
|
||||||
(testing "Distinct on"
|
(testing "Distinct on query generation"
|
||||||
(is (= ["SELECT DISTINCT ON (name) name, created_by"]
|
(is (= ["SELECT DISTINCT ON (name) name, created_by"]
|
||||||
(-> (select (sql/call :distinct-on :name) :name :created_by)
|
(-> (select (sql/call :distinct-on :name) :name :created_by)
|
||||||
sql/format)))
|
sql/format)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue