aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/sql
diff options
context:
space:
mode:
authorscgilardi <scgilardi@gmail.com>2008-10-04 03:40:56 +0000
committerscgilardi <scgilardi@gmail.com>2008-10-04 03:40:56 +0000
commit9513e80be4182da585cbba18d63f19fcde85fc01 (patch)
tree140f8f6953867b371aea4575aa6778f31b08b28a /src/clojure/contrib/sql
parentc9f6a09a608bdea7ba14239d4e4ee87b3676f13d (diff)
sql: make column specs be vectors to allow more than just name and type naturally
Diffstat (limited to 'src/clojure/contrib/sql')
-rw-r--r--src/clojure/contrib/sql/internal.clj6
-rw-r--r--src/clojure/contrib/sql/sql.clj14
-rw-r--r--src/clojure/contrib/sql/test/test.clj8
3 files changed, 11 insertions, 17 deletions
diff --git a/src/clojure/contrib/sql/internal.clj b/src/clojure/contrib/sql/internal.clj
index ad1d7550..0880d491 100644
--- a/src/clojure/contrib/sql/internal.clj
+++ b/src/clojure/contrib/sql/internal.clj
@@ -31,9 +31,3 @@
(if (instance? String x)
x
(name x)))
-
-(defn- the-strs
- "Returns a seq of the Strings represented by the Strings, Keywords, or
- Symbols in the seq x"
- [x]
- (map the-str x))
diff --git a/src/clojure/contrib/sql/sql.clj b/src/clojure/contrib/sql/sql.clj
index 902005de..08c162ec 100644
--- a/src/clojure/contrib/sql/sql.clj
+++ b/src/clojure/contrib/sql/sql.clj
@@ -66,17 +66,17 @@
(defn create-table
"Creates a table given a name (a string or keyword) and column specs. A
- column spec is a name (a string or keyword) followed by a type (a string
- or keyword naming a data type understood by the database)."
+ column spec is a vector containing a name, a type, and optionally other
+ items such as constraints, each a string or keyword."
[con name & cols]
(do-commands con
(format "create table %s (%s)"
(the-str name)
(apply str
- (apply concat
- (interpose ", "
- (map (partial interpose " ")
- (partition 2 (the-strs cols)))))))))
+ (map the-str
+ (apply concat
+ (interpose [", "]
+ (map (partial interpose " ") cols))))))))
(defn drop-table
"Drops a table give its name (a string or keyword)"
@@ -92,7 +92,7 @@
(let [count (count (first values))
template (apply str (interpose "," (replicate count "?")))
cols (if (seq columns)
- (format "(%s)" (apply str (interpose "," (the-strs columns))))
+ (format "(%s)" (apply str (interpose "," (map the-str columns))))
"")]
(apply do-prepared
con
diff --git a/src/clojure/contrib/sql/test/test.clj b/src/clojure/contrib/sql/test/test.clj
index 13a0d09f..94a5a644 100644
--- a/src/clojure/contrib/sql/test/test.clj
+++ b/src/clojure/contrib/sql/test/test.clj
@@ -27,10 +27,10 @@
(drop-table con :fruit)
(catch Exception e))
(create-table con :fruit
- :name "varchar(32)"
- :appearance "varchar(32)"
- :cost :int
- :grade :real)
+ [:name "varchar(32)" "NOT NULL"]
+ [:appearance "varchar(32)"]
+ [:cost :int]
+ [:grade :real])
(insert-rows con :fruit
["Apple" "red" 59 87]
["Banana" "yellow" 29 92.2]