我正在尝试使用 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 ...}]