我想从clojure.
java.jdbc创建/
删除数据库.这失败了:
- (require '[clojure.java.jdbc :as sql])
-
- (def db
- {:classname "org.postgresql.Driver"
- :subprotocol "postgresql"
- :subname "//localhost/postgres"
- :user "postgres"})
-
- (defn drop-database [name]
- (sql/do-commands (str "drop database " name)))
-
- (sql/with-connection db
- (drop-database "db_name"))
因为do-commands启动一个事务,显然你不能在事务中删除或创建数据库.有任何想法吗?
谢谢!
获取do-commands(
here)的源
代码并
删除对事务的
调用:
- (defn drop-database [name]
- (sql/with-connection db
- (with-open [s (.createStatement (sql/connection))]
- (.addBatch s (str "drop database " name))
- (seq (.executeBatch s)))))