Clojure Yesql cannot find query file

I am trying to use the Kris Jenkins Yesql library in my Clojure test project. I created a sample queries.sql with one query. A separate core.clj file is as follows ( precalc is the name of the test project):

 (ns precalc.core) (require '[yesql.core :refer [defqueries defquery]]) (println (defqueries "resources/queries.sql")) (defquery col-type "resources/queries.sql") (slurp "resources/queries.sql") 

When I try to evaluate, for example, line 4, I get

;!!CompilerException java.io.FileNotFoundException: resources/queries.sql, compiling:(precalc/core.clj:4:10)

I tried putting queries.sql in the project root folder, but to no avail. However, Slurping works. My mistake should be very obvious. Can anybody help?

I use Leiningen repl, Macvim and Tim Pope vim-fireplace plugin connected via cider-nrepl.

Thanks!

+5
source share
1 answer

The file should be in your classpath, which you can show with

 lein classpath 

Look at the first few entries, they will look something like this:

 /git/project/test:/git/project/src:/git/project/dev-resources:/git/project/resources:... 

Since you already put it in resources , you are configured. The important thing, however, is that the path you go to defqueries should be relative to your classpath, so in your case, relative to resources :

 (defqueries "queries.sql") 

slurp works because it works directly on your file system, not just the classpath. Since you started your REPL at the root of the project, resources/queries.sql is a perfectly valid path.

+9
source

Source: https://habr.com/ru/post/1212105/


All Articles