1

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. 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.

When I ran my REPL and type (require '[signupper.db :as db]) I get the following error message:

CompilerException clojure.lang.ExceptionInfo: Can not read file: sql/q.sql {}, compiling:(signupper/db.clj:4:1) 

Any one has any idea?

Thanks.

eitan
  • 59
  • 8

5 Answers5

0

Your sql directory needs to be on the path. Please check your project.clj file, under resource-paths, and verify your sql directory is accessible via one of the paths there stated.

If not, you might either move your sql directory or include the path into the resource-paths entry.

0

If you are using Leiningen you should add your sql folder under the :resource-paths key to your project.clj like this:

(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}})
Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
Anton Chikin
  • 1,746
  • 2
  • 17
  • 22
0

Hugsql expects the path relative to the directory on the classpath. (This is the same as Clojure namespaces.)

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

Curtis Summers
  • 586
  • 5
  • 7
  • I tried it many times, but for some reason that did not work. Defining the resource path in the project.clj did the trick. Thanks for helping. – eitan Feb 07 '18 at 10:23
0

My experience :

If your path is like this :

"/home/user/Desktop/sql/q.sql"

project.clj must be like this -->

:resource-paths ["/home/user/Desktop/sql" "other resources"]

and core.clj -->

(hugsql/def-db-fns "q.sql")

But if you write in 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"
Harun Unal
  • 11
  • 2
0

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.

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")