Fork me on GitHub
#luminus
<
2018-11-08
>
rowanharg10:11:26

Hi all, what do people use for scheduled background jobs when using Luminus?

kennethkalmer15:11:09

Howzit everyone, I have a very peculiar issue that I just managed to reproduce successfully on a test project. It’s related to conman/hugsql (and postgres)

kennethkalmer15:11:06

if I use clojure expressions in queries.sql, I can’t use (restart-db) in the user namespace anymore, it dies with:

user=> (restart-db)

           java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace
clojure.lang.Compiler$CompilerException: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace, compiling:(null:1:1)

kennethkalmer15:11:03

switching to the .db.core ns and then binding the connection works just fine

user=> (in-ns 'lumipg.db.core)
#namespace[lumipg.db.core]
lumipg.db.core=> (conman/bind-connection *db* "sql/queries.sql")
{:fns {:clj-expr-single {:fn #<Fn@502dc1a8 conman.core/try_query[fn/fn]>
                         :meta {:command :?
                                :doc ""
                                :file "sql/queries.sql"
                                :line 1
                                :result :1}}}
 :snips {}}

kennethkalmer15:11:41

and the query is an example straight from the Hugsql docs, so nothing special:

-- :name clj-expr-single :? :1
select
--~ (if (seq (:cols params)) ":i*:cols" "*")
from test
order by id

kennethkalmer15:11:00

but somehow rebinding *ns* is not doing the trick, and I don’t know where to report the issue. is this a problem with conman or the way the template sets up the restart-db function?

kennethkalmer15:11:52

sample project is a straight forward lein new luminus lumipg +postgres with 3.10.11

kennethkalmer16:11:48

I’m stumped, I spent a bit of time just stepping through the execution in IntelliJ and alas I’m none the wiser

kennethkalmer16:11:06

settled for this inside (restart-db) and seems to work (so far 🤞)

(try
    (in-ns 'lumipg.db.core)
    (conman/bind-connection lumipg.db.core/*db* "sql/queries.sql")

    (finally
      (in-ns 'user)))