address #532 by supporting exclude/rename in alias position
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
e2f7991ad8
commit
f4d212ae18
2 changed files with 28 additions and 6 deletions
|
|
@ -633,11 +633,18 @@
|
|||
[sql & params] (if (map? selectable)
|
||||
(format-dsl selectable {:nested true})
|
||||
(format-expr selectable))
|
||||
*-qualifier (and (map? alias)
|
||||
(some #(contains? alias %)
|
||||
[:exclude :rename
|
||||
'exclude 'rename]))
|
||||
[sql' & params'] (when alias
|
||||
(if (sequential? alias)
|
||||
(let [[sqls params] (format-expr-list alias {:aliased true})]
|
||||
(into [(join " " sqls)] params))
|
||||
(format-selectable-dsl alias {:aliased true})))
|
||||
(cond (sequential? alias)
|
||||
(let [[sqls params] (format-expr-list alias {:aliased true})]
|
||||
(into [(join " " sqls)] params))
|
||||
*-qualifier
|
||||
(format-dsl alias)
|
||||
:else
|
||||
(format-selectable-dsl alias {:aliased true})))
|
||||
[sql'' & params''] (when temporal
|
||||
(format-temporal temporal))]
|
||||
|
||||
|
|
@ -646,8 +653,9 @@
|
|||
(str " " sql''))
|
||||
(when sql' ; alias
|
||||
(str (if as
|
||||
(if (and (contains? *dialect* :as)
|
||||
(not (:as *dialect*)))
|
||||
(if (or *-qualifier
|
||||
(and (contains? *dialect* :as)
|
||||
(not (:as *dialect*))))
|
||||
" "
|
||||
" AS ")
|
||||
" ")
|
||||
|
|
|
|||
|
|
@ -18,6 +18,20 @@
|
|||
(sql/format (-> (select :*) (exclude :_id)
|
||||
(rename [:value :foo_value]
|
||||
[:a :b])
|
||||
(from :foo)))))
|
||||
(is (= ["SELECT * EXCLUDE _id RENAME value AS foo_value, c.x FROM foo"]
|
||||
(sql/format (-> (select [:* (-> (exclude :_id) (rename [:value :foo_value]))]
|
||||
:c.x)
|
||||
(from :foo)))))
|
||||
(is (= ["SELECT * EXCLUDE (_id, a) RENAME value AS foo_value, c.x FROM foo"]
|
||||
(sql/format (-> (select [:* (-> (exclude :_id :a) (rename [:value :foo_value]))]
|
||||
:c.x)
|
||||
(from :foo)))))
|
||||
(is (= ["SELECT * EXCLUDE _id RENAME (value AS foo_value, a AS b), c.x FROM foo"]
|
||||
(sql/format (-> (select [:* (-> (exclude :_id)
|
||||
(rename [:value :foo_value]
|
||||
[:a :b]))]
|
||||
:c.x)
|
||||
(from :foo))))))
|
||||
(testing "select, nest_one, nest_many"
|
||||
(is (= ["SELECT a._id, NEST_ONE (SELECT * FROM foo AS b WHERE b_id = a._id) FROM bar AS a"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue