Fixes #239 by never qualifying inserted column names
This commit is contained in:
parent
14293688cf
commit
d86150784b
3 changed files with 21 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
## 1.0.next in progress
|
||||
|
||||
* Fix #259 so column names are always unqualified in inserts. (@jrdoane)
|
||||
* Switch dev/test pipeline to use CLI/`deps.edn` instead of Leiningen.
|
||||
* Remove macrovich dependency as this is no longer needed with modern ClojureScript.
|
||||
* Add mention of `next.jdbc` everywhere `clojure.java.jdbc` was mentioned.
|
||||
|
|
|
|||
|
|
@ -615,13 +615,15 @@
|
|||
(if (and (sequential? table) (sequential? (first table)))
|
||||
(str "INSERT INTO "
|
||||
(to-sql (ffirst table))
|
||||
" (" (comma-join (map to-sql (second (first table)))) ") "
|
||||
(binding [*namespace-as-table?* false]
|
||||
(str " (" (comma-join (map to-sql (second (first table)))) ") "))
|
||||
(binding [*subquery?* false]
|
||||
(to-sql (second table))))
|
||||
(str "INSERT INTO " (to-sql table))))
|
||||
|
||||
(defmethod format-clause :columns [[_ fields] _]
|
||||
(str "(" (comma-join (map to-sql fields)) ")"))
|
||||
(binding [*namespace-as-table?* false]
|
||||
(str "(" (comma-join (map to-sql fields)) ")")))
|
||||
|
||||
(defmethod format-clause :composite [[_ fields] _]
|
||||
(comma-join (map to-sql fields)))
|
||||
|
|
@ -632,7 +634,9 @@
|
|||
(str "(" (comma-join (map to-sql x)) ")"))))
|
||||
(let [cols (keys (first values))]
|
||||
(str
|
||||
"(" (comma-join (map to-sql cols)) ") VALUES "
|
||||
(binding [*namespace-as-table?* false]
|
||||
(str "(" (comma-join (map to-sql cols)) ")"))
|
||||
" VALUES "
|
||||
(comma-join (for [x values]
|
||||
(str "(" (comma-join (map #(to-sql (get x %)) cols)) ")")))))))
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,19 @@
|
|||
(is (= (format {:insert-into [[:foo [:a :b :c]] {:select [:d :e :f] :from [:baz]}]})
|
||||
["INSERT INTO foo (a, b, c) SELECT d, e, f FROM baz"])))
|
||||
|
||||
(deftest insert-into-namespaced
|
||||
;; un-namespaced: works as expected:
|
||||
(is (= (format {:insert-into :foo :values [{:foo/id 1}]})
|
||||
["INSERT INTO foo (id) VALUES (?)" 1]))
|
||||
(is (= (format {:insert-into :foo :columns [:foo/id] :values [[2]]})
|
||||
["INSERT INTO foo (id) VALUES (?)" 2]))
|
||||
(is (= (format {:insert-into :foo :values [{:foo/id 1}]}
|
||||
:namespace-as-table? true)
|
||||
["INSERT INTO foo (id) VALUES (?)" 1]))
|
||||
(is (= (format {:insert-into :foo :columns [:foo/id] :values [[2]]}
|
||||
:namespace-as-table? true)
|
||||
["INSERT INTO foo (id) VALUES (?)" 2])))
|
||||
|
||||
(deftest exists-test
|
||||
(is (= (format {:exists {:select [:a] :from [:foo]}})
|
||||
["EXISTS (SELECT a FROM foo)"]))
|
||||
|
|
|
|||
Loading…
Reference in a new issue