Dmitri Sotnikov @dmitri and Scot Brown @svmbrown
In the Use HugSQL section (starting on pp. 401), I ran into several issues when executing:
(add-user! db {:id “hug” :pass “sql”})
on p. 403; It complained of not knowing anything about db.
I suspect the db being referred to here was defined on p. 398, but that seemed optional and I never executed it when I first when through this. Going back and trying it, I got an error about not being able to resolve PGPoolingDataSource which I didn’t bother looking into.
So just going ahead with the parameter map method, here is what I did:
Change db to ds so now I have:
(:require [db-examples.core :refer [ds]]
in hugsql.clj; you’ll also need to change this line to use ds instead of db:
(add-user! ds {:id “hug” :pass “sql”})
Now when re-trying, I ran into a different problem:
; db-spec jdbc:postgresql://127.0.0.1:5432/reporting is missing a required parameter
; Evaluation of file hugsql.clj failed: class clojure.lang.Compiler$CompilerException
Here’s what I did to get this to work:
In project.clj file, add this line:
[com.layerware/hugsql-adapter-next-jdbc “0.5.3”]
as another dependency
Then in hugsql.clj,
add this to the :require list
[hugsql.adapter.next-jdbc :as next-adapter]
and then replace this line:
(hugsql/def-db-fns “users.sql”)
with:
(hugsql/def-db-fns “users.sql” {:adapter (next-adapter/hugsql-adapter-next-jdbc)})
Now the
(add-user! ds {:id “hug” :pass “sql”})
should run successfully.
On p. 404, there’s a sentence:
Let’s add a new file called resources/find_user.sql
for which presumably, the find-users function was to be added, but the code chunk still says: db-examples/resources/users.sql
so that was confusing; Furthermore, what do we do with the find_user.sql file anyway? Do we need to use the def-db-fns function with it? That’s not shown. I just put the find-users function into the users.sql file we’ve been using all along.
Lastly, this line:
we’d use the with-db-transaction macro
should just be with-transaction macro; i.e., there is no db in the macro name