3

我正在尝试使用 Korma 连接到 Oracle 数据库。首先,我尝试使用此代码并成功连接。

(defdb korma-db
  {:classname "oracle.jdbc.OracleDriver"
   :subprotocol "oracle"
   :subname "thin:@my.oracle.db:1521:testdb"
   :user "xxx"
   :password "xxx"
   :naming {:keys str/lower-case :fields str/upper-case}})

但我发现还有一个更方便的功能korma.db.oracle。所以代码看起来像这样简化:

(defdb korma-db
  (oracle {:keys ["my.oracle.db" 1521 true]
           :as {:user "xxx" :password "xxx"}
           :naming {:keys str/lower-case :fields str/upper-case}}))

但它失败了。它试图localhost. 当我检查oracle函数的结果时,我发现有一些奇怪的东西。

{:naming {:keys #<string$lower_case clojure.string$lower_case@5ba760ac>,
 :fields #<string$upper_case clojure.string$upper_case@504f4c0b>},
 :as {:user "xxx", :password "xxx"},
 :keys ["my.oracle.db" 1521 true],
 :classname "oracle.jdbc.driver.OracleDriver",
 :subprotocol "oracle:thin",
 :subname "@localhost:1521", :make-pool? true}
            ^^^^^^^^^

我检查了 Korma 源代码,oracle函数代码是:

(defn oracle
  "Create a database specification for an Oracle database. Opts should include keys
  for :user and :password. You can also optionally set host and port."
  [{:keys [host port make-pool?]
    :or {host "localhost", port 1521, make-pool? true}
    :as opts}]
  (merge {:classname "oracle.jdbc.driver.OracleDriver" ; must be in classpath
          :subprotocol "oracle:thin"
          :subname (str "@" host ":" port)
          :make-pool? make-pool?}
         opts))

简而言之,我的问题是:

  • 函数的具体用法是oracle什么?我错过了什么?
  • 函数代码oracle对我来说看起来很奇怪。谁能解释一下代码,尤其是参数部分...[{:keys [host .... ] :or {...} :as ...}]
4

1 回答 1

2

这个oracle函数解构它的参数。这是一篇关于此功能的文章。

所以,正确的调用方式oracle是:

(defdb korma-db
  (oracle { :user "xxx"
            :password "xxx"
            :host "my.oracle.db"
            :port 1521
            :make-pool? true }))

编辑:指定 oracle SID 可以这样完成:

(defdb korma-db
  (oracle {:subname "@//xxx.xxx.xxx.xxx:1521/testdb"
           :user "xxx"
           :password "xxx"
           :naming {:keys str/lower-case :fields str/upper-case}}))
于 2013-12-20T09:16:22.587 回答