[英]Hugsql can not read my sql file
I am truely lost here.我真的在这里迷路了。 I have a very simple application.
我有一个非常简单的应用程序。 All it does is to insert a user into the user table in my Database.
它所做的只是将用户插入到我的数据库中的用户表中。 I using Postgres.
我使用 Postgres。 The code is
代码是
(ns signupper.db (:require [hugsql.core :as hugsql]))
(hugsql/def-db-fns "sql/q.sql")
Inside the direvtory where db.clj is I made a directory called sql and inside of it there is a file called q.sql.在 db.clj 所在的目录中,我创建了一个名为 sql 的目录,其中有一个名为 q.sql 的文件。
When I ran my REPL and type (require '[signupper.db :as db]) I get the following error message:当我运行 REPL 并输入 (require '[signupper.db :as db]) 时,我收到以下错误消息:
CompilerException clojure.lang.ExceptionInfo: Can not read file: sql/q.sql {}, compiling:(signupper/db.clj:4:1)
Any one has any idea?任何人有任何想法?
Thanks.谢谢。
Your sql
directory needs to be on the path.您的
sql
目录需要在路径上。 Please check your project.clj
file, under resource-paths
, and verify your sql
directory is accessible via one of the paths there stated.请检查您的
project.clj
文件,在resource-paths
,并验证您的sql
目录可通过其中所述的路径之一访问。
If not, you might either move your sql
directory or include the path into the resource-paths
entry.如果没有,您可以移动
sql
目录或将路径包含在resource-paths
条目中。
If you are using Leiningen you should add your sql folder under the :resource-paths
key to your project.clj
like this:如果您使用Leiningen,您应该将
:resource-paths
键下的 sql 文件夹添加到您的project.clj
如下所示:
(defproject test-project "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main ^:skip-aot test-project.core
:target-path "target/%s"
:resource-paths ["sql" "resources"] ; <-- here
:profiles {:uberjar {:aot :all}})
Hugsql expects the path relative to the directory on the classpath. Hugsql 需要相对于类路径上的目录的路径。 (This is the same as Clojure namespaces.)
(这与 Clojure 命名空间相同。)
So, your code should look like this:所以,你的代码应该是这样的:
(ns signupper.db (:require [hugsql.core :as hugsql]))
(hugsql/def-db-fns "signupper/db/sql/q.sql")
See the example in the docs: https://www.hugsql.org/#start-sql请参阅文档中的示例: https : //www.hugsql.org/#start-sql
My experience :我的经验:
If your path is like this :如果你的路径是这样的:
"/home/user/Desktop/sql/q.sql"
project.clj must be like this --> project.clj 一定是这样的 -->
:resource-paths ["/home/user/Desktop/sql" "other resources"]
and core.clj -->和 core.clj -->
(hugsql/def-db-fns "q.sql")
But if you write in core.clj但是如果你写在core.clj
(hugsql/def-db-fns "/home/user/Desktop/sql/q.sql")
Computer sees like this :电脑是这样看的:
"/home/user/Desktop/sql/home/user/Desktop/sql/q.sql"
Just had the same issue.刚刚有同样的问题。
Apparently, the function def-db-fns
starts the path from the folder src
and not the root of the project.显然,函数
def-db-fns
从文件夹src
而不是项目的根目录开始路径。
I think one way you can solve this is putting your file inside the src directory, and call the function with (hugsql/def-db-fns "q.sql")
我认为您可以解决此问题的一种方法是将您的文件放在 src 目录中,并使用
(hugsql/def-db-fns "q.sql")
调用该函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.