Clojure 警告:“结果集序列已存在于 clojure.core 中”

发布于 2024-12-17 15:23:52 字数 403 浏览 5 评论 0原文

我是 Clojure 的新手,正在使用 Noir 框架构建一个 Web 应用程序(与 Compojure 非常相似,事实上我认为它是具有不同请求处理程序层的 Compojure)。当我导入 JDBC 库时,我收到一条警告:

WARNING: resultset-seq already refers to: #'clojure.core/resultset-seq in namespace: webapp.models.database, being replaced by: #'clojure.java.jdbc/resultset-seq

我是否必须接受此警告,或者有解决方法吗?我使用以下方式导入 JDBC 库:

(use 'clojure.java.jdbc)

I'm new to Clojure and building a web app using the Noir framework (very similar to Compojure, in fact I think it's Compojure with a different request handler layer). I'm getting a warning when I import the JDBC library:

WARNING: resultset-seq already refers to: #'clojure.core/resultset-seq in namespace: webapp.models.database, being replaced by: #'clojure.java.jdbc/resultset-seq

Do I have to live with this warning or is there a way around it? I'm importing the JDBC library using:

(use 'clojure.java.jdbc)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哑剧 2024-12-24 15:23:52

您可以通过指定要导入的确切绑定来避免该问题:

(use '[clojure.java.jdbc :only [insert-values transaction]])
(transaction
  (insert-values ...))

另一个选项是 :exclude 有问题的绑定:

(use '[clojure.java.jdbc :exclude [resultset-seq]])
(transaction
  (insert-values ...))

您也可以只使用 require 代替

(require '[clojure.java.jdbc :as db])
(db/transaction
  (db/insert-values ...))

:兼容性方面,require 可以说是最安全的。使用 :only 只是稍微不太干净,但仍然是一个很好的方法(并且在出现问题时很容易修复)。排除当前有问题的绑定可能是解决问题的最不适合未来的方法,因为其他冲突的绑定可能随时出现,并且跟踪从何处导入的内容可能很棘手。

You can avoid the problem by specifying the exact bindings to be imported:

(use '[clojure.java.jdbc :only [insert-values transaction]])
(transaction
  (insert-values ...))

Another option is to :exclude the offending binding:

(use '[clojure.java.jdbc :exclude [resultset-seq]])
(transaction
  (insert-values ...))

You can also just use require instead:

(require '[clojure.java.jdbc :as db])
(db/transaction
  (db/insert-values ...))

With regard to forward compatibility, require is arguably safest. Using :only is just slightly less clean but still a pretty good approach (and easy to fix when it breaks). Excluding the currently offending bindings is probably the least future-proof way of fixing the problem since other conflicting bindings can appear at any time and tracking down what is imported from where can be tricky.

朦胧时间 2024-12-24 15:23:52

有很多选择。此警告的含义是,您正在使用不同包中的定义替换已定义的符号。在本例中,看起来这是您定义的变量,对吧?如果是这样,最简单的解决方案可能是在代码中重命名它。

或者,如果您不需要 clojure.java.jdbc 包中的 resultset-seq,您可以排除它:

(use '[clojure.java.jdbc :exclude (resultset-seq)])

或者更好的是,

(use '[clojure.java.jdbc :only (f1 f2 f3)])

其中 f1、f2、f3 是您实际需要的东西。

(use '[clojure.java.jdbc :as jdbc])

然后使用 jdbc/resultset-seq

或者您可以:

(require 'clojure.java.jdbc)

然后使用 clojure.java.jdbc/reusltset-seq

There are lots of options. What this warning means is, that you are replacing an already defined symbol with a definition from different package. In this case, it looks like this is a variable that you've defined, right? If so the easiest solution might be to just rename it in your code.

Or if you don't need the resultset-seq from clojure.java.jdbc package you can exclude it:

(use '[clojure.java.jdbc :exclude (resultset-seq)])

or better yet,

(use '[clojure.java.jdbc :only (f1 f2 f3)])

where f1, f2, f3 are the things you're actually need.

(use '[clojure.java.jdbc :as jdbc])

and then use jdbc/resultset-seq

Or you can just:

(require 'clojure.java.jdbc)

and then use clojure.java.jdbc/reusltset-seq

吃颗糖壮壮胆 2024-12-24 15:23:52

除了其他优秀的答案之外,如果您想要 jdbc resultset-seq 而不是核心的,您可以将后者排除在当前 ns 之外:

(ns foo
  (:refer-clojure :exclude [resultset-seq])
  (:use clojure.java.jdbc))

In addition to the other excellent answers, if you want the jdbc resultset-seq instead of the core one, you can exclude the latter from being brought into the current ns:

(ns foo
  (:refer-clojure :exclude [resultset-seq])
  (:use clojure.java.jdbc))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文