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,10 +633,17 @@
|
||||||
[sql & params] (if (map? selectable)
|
[sql & params] (if (map? selectable)
|
||||||
(format-dsl selectable {:nested true})
|
(format-dsl selectable {:nested true})
|
||||||
(format-expr selectable))
|
(format-expr selectable))
|
||||||
|
*-qualifier (and (map? alias)
|
||||||
|
(some #(contains? alias %)
|
||||||
|
[:exclude :rename
|
||||||
|
'exclude 'rename]))
|
||||||
[sql' & params'] (when alias
|
[sql' & params'] (when alias
|
||||||
(if (sequential? alias)
|
(cond (sequential? alias)
|
||||||
(let [[sqls params] (format-expr-list alias {:aliased true})]
|
(let [[sqls params] (format-expr-list alias {:aliased true})]
|
||||||
(into [(join " " sqls)] params))
|
(into [(join " " sqls)] params))
|
||||||
|
*-qualifier
|
||||||
|
(format-dsl alias)
|
||||||
|
:else
|
||||||
(format-selectable-dsl alias {:aliased true})))
|
(format-selectable-dsl alias {:aliased true})))
|
||||||
[sql'' & params''] (when temporal
|
[sql'' & params''] (when temporal
|
||||||
(format-temporal temporal))]
|
(format-temporal temporal))]
|
||||||
|
|
@ -646,8 +653,9 @@
|
||||||
(str " " sql''))
|
(str " " sql''))
|
||||||
(when sql' ; alias
|
(when sql' ; alias
|
||||||
(str (if as
|
(str (if as
|
||||||
(if (and (contains? *dialect* :as)
|
(if (or *-qualifier
|
||||||
(not (:as *dialect*)))
|
(and (contains? *dialect* :as)
|
||||||
|
(not (:as *dialect*))))
|
||||||
" "
|
" "
|
||||||
" AS ")
|
" AS ")
|
||||||
" ")
|
" ")
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,20 @@
|
||||||
(sql/format (-> (select :*) (exclude :_id)
|
(sql/format (-> (select :*) (exclude :_id)
|
||||||
(rename [:value :foo_value]
|
(rename [:value :foo_value]
|
||||||
[:a :b])
|
[: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))))))
|
(from :foo))))))
|
||||||
(testing "select, nest_one, nest_many"
|
(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"]
|
(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