Merge remote-tracking branch 'dave/master' into HEAD

This commit is contained in:
Mike Blume 2015-03-09 09:56:11 -07:00
commit 34f84e41b4
2 changed files with 15 additions and 1 deletions

View file

@ -46,6 +46,7 @@
(defn- undasherize [s]
(string/replace s "-" "_"))
(defn quote-identifier [x & {:keys [style split] :or {split true}}]
(let [qf (if style
(quote-fns style)
@ -392,7 +393,12 @@
(str "OFFSET " (to-sql offset)))
(defmethod format-clause :insert-into [[_ table] _]
(str "INSERT INTO " (to-sql table)))
(if (and (sequential? table) (sequential? (first table)))
(str "INSERT INTO "
(to-sql (ffirst table))
" (" (comma-join (map to-sql (second (first table)))) ") "
(to-sql (second table)))
(str "INSERT INTO " (to-sql table))))
(defmethod format-clause :columns [[_ fields] _]
(str "(" (comma-join (map to-sql fields)) ")"))

View file

@ -25,3 +25,11 @@
(is (= (format-clause
(first {:with-recursive [[:query {:select [:foo] :from [:bar]}]]}) nil)
"WITH RECURSIVE query AS SELECT foo FROM bar")))
(deftest insert-into
(is (= (format-clause (first {:insert-into :foo}) nil)
"INSERT INTO foo"))
(is (= (format-clause (first {:insert-into [:foo {:select [:bar] :from [:baz]}]}) nil)
"INSERT INTO foo SELECT bar FROM baz"))
(is (= (format-clause (first {:insert-into [[:foo [:a :b :c]] {:select [:d :e :f] :from [:baz]}]}) nil)
"INSERT INTO foo (a, b, c) SELECT d, e, f FROM baz")))