luminus-framework / luminus

documentation site for Luminus framework
http://www.luminusweb.net/
629 stars 121 forks source link

user/restart-db fails when using hugsql clojure syntax #247

Closed eskemojoe007 closed 3 years ago

eskemojoe007 commented 5 years ago

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
    /*~ ) ~*/
  4. Start repl lein repl

  5. Start app - (start)

  6. Migrate - (migrate)

  7. 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"})
  8. Test that both connection string types work:

    • (myapp.db.core/get-user {:id "1"})
    • (myapp.db.core/get-user {:email "steve.jobs@apple.com"})
  9. (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.