Finish off TOP implementation #292
This commit is contained in:
parent
479008c294
commit
6b070df52c
3 changed files with 19 additions and 2 deletions
|
|
@ -232,6 +232,8 @@ user=> (sql/format {:select [:id, [[:* :cost 2] :total], [:event :status]]
|
|||
HoneySQL does not yet support `SELECT .. INTO ..`
|
||||
or `SELECT .. BULK COLLECT INTO ..`.
|
||||
|
||||
## select-top, select-distinct-top
|
||||
|
||||
## select-distinct-on
|
||||
|
||||
Similar to `:select-distinct` above but the first element
|
||||
|
|
|
|||
|
|
@ -330,7 +330,9 @@
|
|||
(format-expr top)
|
||||
[sql' & params']
|
||||
(format-selects-common
|
||||
(str (sql-kw k) " " sql (str/join " " (map sql-kw parts)))
|
||||
(str (sql-kw k) "(" sql ")"
|
||||
(when (seq parts) " ")
|
||||
(str/join " " (map sql-kw parts)))
|
||||
true
|
||||
cols)]
|
||||
(-> [sql'] (into params) (into params'))))
|
||||
|
|
|
|||
|
|
@ -80,7 +80,20 @@
|
|||
:dialect :mysql :quoted false}))))))
|
||||
|
||||
(deftest select-top-tests
|
||||
(is true))
|
||||
(testing "Basic TOP syntax"
|
||||
(is (= ["SELECT TOP(?) foo FROM bar ORDER BY quux ASC" 10]
|
||||
(sql/format {:select-top [10 :foo] :from :bar :order-by [:quux]})))
|
||||
(is (= ["SELECT TOP(?) foo FROM bar ORDER BY quux ASC" 10]
|
||||
(sql/format (-> (select-top 10 :foo)
|
||||
(from :bar)
|
||||
(order-by :quux))))))
|
||||
(testing "Expanded TOP syntax"
|
||||
(is (= ["SELECT TOP(?) PERCENT WITH TIES foo, baz FROM bar ORDER BY quux ASC" 10]
|
||||
(sql/format {:select-top [[10 :percent :with-ties] :foo :baz] :from :bar :order-by [:quux]})))
|
||||
(is (= ["SELECT TOP(?) PERCENT WITH TIES foo, baz FROM bar ORDER BY quux ASC" 10]
|
||||
(sql/format (-> (select-top [10 :percent :with-ties] :foo :baz)
|
||||
(from :bar)
|
||||
(order-by :quux)))))))
|
||||
|
||||
(deftest join-by-test
|
||||
(testing "Natural JOIN orders"
|
||||
|
|
|
|||
Loading…
Reference in a new issue