-
3c2b0ae3 :Anonymous
2015-11-22 13:17
-
>>ea77dbf6
横だけどClojureで複数のDBをサポートするためにこの関数で違いを吸収した。
一番面倒くさかったのはcase insensitiveな文字列の扱い。あとは割と簡単だった。
(defn db-types
[db-spec]
(cond
(or (= (:subprotocol db-spec) "h2")
(and (:datasource db-spec)
(re-find #"^jdbc:h2:" (java-get-jdbc-url (:datasource db-spec)))))
{:id "INTEGER PRIMARY KEY AUTO_INCREMENT"
:varchar "VARCHAR"
:varchar-ignorecase "VARCHAR_IGNORECASE"
:varchar-ignorecase-unique "VARCHAR_IGNORECASE UNIQUE"
:blob "BLOB"}
(or (= (:subprotocol db-spec) "hsqldb")
(and (:datasource db-spec)
(re-find #"^jdbc:hsqldb:" (java-get-jdbc-url (:datasource db-spec)))))
{:id "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1)"
:varchar "VARCHAR(16777216)"
:varchar-ignorecase "VARCHAR_IGNORECASE(16777216)"
:varchar-ignorecase-unique "VARCHAR_IGNORECASE(16777216) UNIQUE"
:blob "BLOB"}
(or (= (:subprotocol db-spec) "mysql")
(and (:datasource db-spec)
(re-find #"^jdbc:mysql:" (java-get-jdbc-url (:datasource db-spec)))))
{:id "SERIAL PRIMARY KEY"
:varchar "LONGTEXT CHARACTER SET UTF8 COLLATE 'utf8_bin'"
:varchar-ignorecase "LONGTEXT CHARACTER SET UTF8 COLLATE 'utf8_general_ci'"
:varchar-ignorecase-unique "LONGTEXT CHARACTER SET UTF8 COLLATE 'utf8_general_ci'" ; UNIQUE is not supported.
:blob "LONGBLOB"}
(or (= (:subprotocol db-spec) "postgresql")
(and (:datasource db-spec)
(re-find #"^jdbc:postgresql:" (java-get-jdbc-url (:datasource db-spec)))))
{:id "SERIAL PRIMARY KEY"
:varchar "CITEXT"
:varchar-ignorecase "CITEXT"
:varchar-ignorecase-unique "CITEXT UNIQUE"
:blob "BYTEA"}
:else
nil))
Powered by shinGETsu.