Skip to content

Commit

Permalink
added tests for derby database, which doesn't support generated keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Wurzer authored and bendlas committed Sep 2, 2011
1 parent 7ca9928 commit f85937a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
:dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]
[mysql/mysql-connector-java "5.1.17"]
[org.xerial/sqlite-jdbc "3.7.2"]
[postgresql/postgresql "8.4-702.jdbc4"]]
[postgresql/postgresql "8.4-702.jdbc4"]
[org.apache.derby/derby "10.1.1.0"]]

:repositories {"clojure-releases" {:url "http://build.clojure.org/releases"}})

Expand Down
25 changes: 24 additions & 1 deletion test/clojureql/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@
:subname "/tmp/cql.sqlite3"
:create true})

(def databases [mysql postgresql sqlite3])
(def derby
{:classname "org.apache.derby.jdbc.EmbeddedDriver"
:subprotocol "derby"
:subname "/tmp/cql.derby"
:create true})

(def register-derby-driver (-> (Class/forName "org.apache.derby.jdbc.EmbeddedDriver") .newInstance))

(def databases [mysql postgresql sqlite3 derby])

(defn mysql? []
(isa? (class (connection)) com.mysql.jdbc.JDBC4Connection))
Expand All @@ -50,6 +58,9 @@
(defn sqlite3? []
(isa? (class (connection)) org.sqlite.Conn))

(defn derby? []
(isa? (class (connection)) org.apache.derby.impl.jdbc.EmbedConnection))

(defn drop-if [table]
(try (drop-table table) (catch Exception _)))

Expand Down Expand Up @@ -95,6 +106,18 @@
[:id :integer "PRIMARY KEY" "AUTOINCREMENT"]
[:wage :integer]))

(defmethod create-schema org.apache.derby.impl.jdbc.EmbedConnection []
(create-table
:users
[:id :integer "PRIMARY KEY" "GENERATED ALWAYS AS IDENTITY"]
[:name "varchar(255)"]
[:title "varchar(255)"]
[:birthday "TIMESTAMP"])
(create-table
:salary
[:id :integer "PRIMARY KEY" "GENERATED ALWAYS AS IDENTITY"]
[:wage :integer]))

(def users (-> (table :users) (project [:id :name :title])))
(def salary (-> (table :salary) (project [:id :wage])))

Expand Down

0 comments on commit f85937a

Please sign in to comment.