postgresql – 如何从clojure.java.jdbc中删除或创建数据库?

前端之家收集整理的这篇文章主要介绍了postgresql – 如何从clojure.java.jdbc中删除或创建数据库?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从clojure. java.jdbc创建/删除数据库.这失败了:
  1. (require '[clojure.java.jdbc :as sql])
  2.  
  3. (def db
  4. {:classname "org.postgresql.Driver"
  5. :subprotocol "postgresql"
  6. :subname "//localhost/postgres"
  7. :user "postgres"})
  8.  
  9. (defn drop-database [name]
  10. (sql/do-commands (str "drop database " name)))
  11.  
  12. (sql/with-connection db
  13. (drop-database "db_name"))

因为do-commands启动一个事务,显然你不能在事务中删除或创建数据库.有任何想法吗?

谢谢!

获取do-commands( here)的源代码删除对事务的调用
  1. (defn drop-database [name]
  2. (sql/with-connection db
  3. (with-open [s (.createStatement (sql/connection))]
  4. (.addBatch s (str "drop database " name))
  5. (seq (.executeBatch s)))))

猜你在找的Postgre SQL相关文章