Addresses #293 partial with-columns implementation
This commit is contained in:
parent
83d4ccba38
commit
49d8365bfb
2 changed files with 18 additions and 3 deletions
|
|
@ -485,7 +485,21 @@
|
||||||
(when if-exists (str (sql-kw :if-exists) " "))
|
(when if-exists (str (sql-kw :if-exists) " "))
|
||||||
(str/join ", " (map #'format-entity tables)))]))
|
(str/join ", " (map #'format-entity tables)))]))
|
||||||
|
|
||||||
(defn- format-table-columns [k [x]] ["()"])
|
(defn- format-table-columns [k xs]
|
||||||
|
(let [simple-expr (fn [e]
|
||||||
|
(let [[x & y] (format-expr e)]
|
||||||
|
(when (seq y)
|
||||||
|
(throw (ex-info "column elements must be simple expressions"
|
||||||
|
{:expr e :params y})))
|
||||||
|
x))]
|
||||||
|
(binding [*inline* true]
|
||||||
|
[(str "(\n "
|
||||||
|
(str/join ",\n "
|
||||||
|
(map #(str/join " "
|
||||||
|
(let [[id & spec] (map simple-expr %)]
|
||||||
|
(cons id (map upper-case spec))))
|
||||||
|
xs))
|
||||||
|
"\n)")])))
|
||||||
|
|
||||||
(def ^:private base-clause-order
|
(def ^:private base-clause-order
|
||||||
"The (base) order for known clauses. Can have items added and removed.
|
"The (base) order for known clauses. Can have items added and removed.
|
||||||
|
|
|
||||||
|
|
@ -335,8 +335,9 @@
|
||||||
(is (= (sql/format {:create-view :metro :select [:*] :from [:cities] :where [:= :metroflag "y"]})
|
(is (= (sql/format {:create-view :metro :select [:*] :from [:cities] :where [:= :metroflag "y"]})
|
||||||
["CREATE VIEW metro AS SELECT * FROM cities WHERE metroflag = ?" "y"]))
|
["CREATE VIEW metro AS SELECT * FROM cities WHERE metroflag = ?" "y"]))
|
||||||
(is (= (sql/format {:create-table :films
|
(is (= (sql/format {:create-table :films
|
||||||
:with-columns []})
|
:with-columns [[:id :int :unsigned :auto-increment]
|
||||||
["CREATE TABLE films ()"]))
|
[:name [:varchar 50] [:not nil]]]})
|
||||||
|
["CREATE TABLE films (\n id INT UNSIGNED AUTO_INCREMENT,\n name VARCHAR(50) NOT NULL\n)"]))
|
||||||
(is (= (sql/format {:drop-table :foo})
|
(is (= (sql/format {:drop-table :foo})
|
||||||
["DROP TABLE foo"]))
|
["DROP TABLE foo"]))
|
||||||
(is (= (sql/format {:drop-table [:if-exists :foo]})
|
(is (= (sql/format {:drop-table [:if-exists :foo]})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue