luminus-framework/luminus

user/restart-db fails when using hugsql clojure syntax

eskemojoe007 opened this issue · 0 comments

hugsql allows for the usage of clojure syntax within the queries, but when working with queries in the repl an error is raised when running restart-db when the code exists. The error does not happen if the repl is restarted.

Step to Recreate

  1. lein new luminus myapp +postgres
  2. Create DB and update connection string in dev-config.edn
  3. Modify myapp/resources/sql/queries.sql to make get-user to read:
-- :name get-user :? :1
-- :doc retrieves a user record given the id
SELECT * FROM users
/*~ (if (:id params) */
WHERE id = :id
/*~*/
where email = :email
/*~ ) ~*/
  1. Start repl lein repl
  2. Start app - (start)
  3. Migrate - (migrate)
  4. create at least 1 record
(myapp.db.core/create-user!
 {:id 1
  :first_name "steve"
  :last_name "jobs"
  :email "steve.jobs@apple.com"
  :pass "admin"})
  1. Test that both connection string types work:
  • (myapp.db.core/get-user {:id "1"})
  • (myapp.db.core/get-user {:email "steve.jobs@apple.com"})
  1. (restart-db)

You get the following error:

class clojure.lang.Symbol cannot be cast to class clojure.lang.Namespace (clojure.lang.Symbol and clojure.lang.Namespace are in unnamed module of loader 'app')

Removing the lines of code from get-user and making it a simple query allows restart-db to function properly. This has been verified on both linux mint and windows 10.