Fork me on GitHub

i'm using hikari-cp to handle my database connection. i was only running it from lein locally for development so far, but now i tried to build an uberjar to test online. however, it seems to try to connect to (the "production") database host while building the jar which obviously fails. why is it doing that and how do i stop it?


@vale are you building an hikari connection pool in a def in one of your prod namespaces?


(def conn
  {:datasource (make-datasource options)})


Building a jar includes compilation which means evaluating top level defs


how would i do it then instead?


it's possible (and often a good idea) to build a jar without compiling, but even so you should not have side effecting code at the top level of a namespace


there's a few alternate patterns, a common robust one is a library for managing stateful things, like stuartsierra/component or integrant


but even putting your connection in a delay or promise, and not forcing / realizing until later will suffice


all right, i guess i'll play around with integrant then


for reference though, how would i build a jar without compiling (the problematic namespace)?


by not specifying aot, and changing your app startup to java -jar my-uber.jar clojure.main -m my.ns


(plus any other args you need, of course)


So I have to de-dupe a list of browsers visited and come up with this:

;; pick out most recent of visits to same URL
  (->> (vals browsers)
          (group-by :url)
          (map (fn [[_ values]]
          (first (sort-by :timestamp > values))))
          ;; now restore original structure
           (into {} (map (fn [m] [(:browser-id m) m]))
but the idea of parameterized de-duping seems reusable. Question: do good Clojurians cook up a new group-distict-by-yada-yada and wonder if it will ever get re-used, or do we just knock off these three-step transformations ad hoc and keep on trucking?


Certainly, distinct-by (with an arglist of [f coll]) seems to be a useful one that is often added to projects