Merge ff760e12de into 1157887edd
This commit is contained in:
commit
2e68476016
2 changed files with 21 additions and 7 deletions
|
|
@ -156,7 +156,7 @@
|
|||
|
||||
(def clause-order
|
||||
"Determines the order that clauses will be placed within generated SQL"
|
||||
[:select :insert-into :update :delete-from :columns :set :from :join
|
||||
[:select :select-top :insert-into :update :delete-from :columns :set :from :join
|
||||
:left-join :right-join :where :group-by :having :order-by :limit :offset
|
||||
:values :query-values])
|
||||
|
||||
|
|
@ -306,13 +306,19 @@
|
|||
(defmethod format-clause :default [& _]
|
||||
"")
|
||||
|
||||
(defn- -handle-select [fields sql-map]
|
||||
(str
|
||||
(when (:modifiers sql-map)
|
||||
(str (space-join (map (comp string/upper-case name)
|
||||
(:modifiers sql-map)))
|
||||
" "))
|
||||
(comma-join (map to-sql fields))))
|
||||
|
||||
(defmethod format-clause :select [[_ fields] sql-map]
|
||||
(str "SELECT "
|
||||
(when (:modifiers sql-map)
|
||||
(str (space-join (map (comp string/upper-case name)
|
||||
(:modifiers sql-map)))
|
||||
" "))
|
||||
(comma-join (map to-sql fields))))
|
||||
(str "SELECT " (-handle-select fields sql-map)))
|
||||
|
||||
(defmethod format-clause :select-top [[_ [limit-count fields]] sql-map]
|
||||
(str "SELECT TOP " limit-count " " (-handle-select fields sql-map)))
|
||||
|
||||
(defmethod format-clause :from [[_ tables] _]
|
||||
(str "FROM " (comma-join (map to-sql tables))))
|
||||
|
|
|
|||
|
|
@ -55,3 +55,11 @@
|
|||
"bort" "gabba" 2])))
|
||||
(testing "SQL data prints and reads correctly"
|
||||
(is (= m1 (read-string (pr-str m1)))))))
|
||||
|
||||
(deftest test-select-top
|
||||
(let [m1 {:select-top [10 [:fieldx :fieldy]]
|
||||
:modifiers [:distinct]
|
||||
:from [:foo]}]
|
||||
(testing "select-top formats correctly"
|
||||
(is (= (sql/format m1)
|
||||
["SELECT TOP 10 DISTINCT fieldx, fieldy FROM foo "])))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue