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

前端之家收集整理的这篇文章主要介绍了postgresql – 如何从clojure.java.jdbc中删除或创建数据库?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从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)))))

猜你在找的Postgre SQL相关文章