Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure Yesql not able to find queries file

Tags:

vim

clojure

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!

like image 422
siphiuel Avatar asked Jan 28 '15 13:01

siphiuel


1 Answers

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.

like image 143
xsc Avatar answered Sep 28 '22 04:09

xsc