diff --git a/project.clj b/project.clj index ff1ddbf..3343d4e 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,8 @@ :license {:name "Eclipse Public License"} :dependencies [[org.clojure/clojure "1.4.0"] [org.clojure/java.jdbc "0.1.1"] - [org.clojure/tools.macro "0.1.1"]] + [org.clojure/tools.macro "0.1.1"] + [org.flatland/ordered "1.4.0"]] :profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]} ;:1.5 {:dependencies [[org.clojure/clojure "1.5.0-beta1"]]} :dev diff --git a/src/lobos/schema.clj b/src/lobos/schema.clj index 1c1e4af..9a119f1 100644 --- a/src/lobos/schema.clj +++ b/src/lobos/schema.clj @@ -29,7 +29,8 @@ (:use (clojure [walk :only [postwalk]] [set :only [union]] [string :only [replace]]) - lobos.utils)) + lobos.utils + flatland.ordered.map)) (ast/import-all) @@ -689,7 +690,7 @@ [name & [columns constraints indexes]] (name-required name "table") (Table. name - (or columns {}) + (or columns (ordered-map)) (or constraints {}) (or indexes {}))) @@ -697,7 +698,7 @@ "Constructs an abstract table definition containing the given elements." [name & elements] - `(-> (table* ~name) ~@(reverse elements))) + `(-> (table* ~name) ~@elements)) ;; ----------------------------------------------------------------------------- diff --git a/test/lobos/test/schema.clj b/test/lobos/test/schema.clj index f6bf523..db27142 100644 --- a/test/lobos/test/schema.clj +++ b/test/lobos/test/schema.clj @@ -218,7 +218,20 @@ "Table with column") (is (= (table :foo (unique :bar [:a])) (Table. :foo {} {:bar (UniqueConstraint. :bar :unique [:a])} {})) - "Table with constraint")) + "Table with constraint") + (is (= (list :col1 :col2 :col3 :col4 :col5 :col6 :col7 :col8 :col9 :col10) + (keys (:columns (table :foo + (column :col1 nil nil) + (column :col2 nil nil) + (column :col3 nil nil) + (column :col4 nil nil) + (column :col5 nil nil) + (column :col6 nil nil) + (column :col7 nil nil) + (column :col8 nil nil) + (column :col9 nil nil) + (column :col10 nil nil))))) + "Table with many ordered columns")) ;;;; Schema definition tests