gpt4 book ai didi

clojure - Korma中 `oracle`函数的具体用法和clojure代码的含义?

转载 作者:行者123 更新时间:2023-12-02 01:55:04 27 4
gpt4 key购买 nike

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

最佳答案

这个 oracle 函数 destructuring its arguments .这是一个 article about this feature .

所以,调用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}}))

关于clojure - Korma中 `oracle`函数的具体用法和clojure代码的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20699329/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com