I'm trying to use Kris Jenkins's Yesql library in my test Clojure project. I've created a sample queries.sql file with a single query. Single core.clj file looks like this (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 attempting to evaluate e.g. line 4, I get
;!!CompilerException java.io.FileNotFoundException: resources/queries.sql, compiling:(precalc/core.clj:4:10)
I've tried putting queries.sql into root project folder as well, but to no avail. Slurping works though. My mistake must be very obvious. Can someone please help?
I use Leiningen's repl, Macvim and Tim Pope's vim-fireplace plugin, connected via cider-nrepl.
Thanks!
The file has to be on your classpath which you can show using
lein classpath
Look at the first few entries, they'll look similar to these:
/git/project/test:/git/project/src:/git/project/dev-resources:/git/project/resources:...
Since you already put it into resources, you're set. The important point, however, is that the path you pass to defqueries has to be relative to your classpath, so in your case relative to resources:
(defqueries "queries.sql")
slurp works because it operates directly on your filesystem, not only on the classpath. Since you started your REPL in the project root, resources/queries.sql is a perfectly valid path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With