Using lobos.connectivity/with-connection

98 views
Skip to first unread message

Barry Wark

unread,
Mar 11, 2013, 11:41:19 AM3/11/13
to lobos-...@googlegroups.com
I'm trying to make use of the lobos.connectivit/with-connection, but am clearly misunderstanding something. The following code works, as expected:

  (open-global dbspec)
  (binding [lobos.migration/*reload-migrations* false]
      (lobos.core/migrate dbspec))

This is the only call to lobos, however, so it seems like it makes sense to use with-connection instead. Using the same dbspec,

  (lobos.connectivity/with-connection 
    dbspec
    (binding [lobos.migration/*reload-migrations* false]
      (lobos.core/migrate dbspec)))

gives this error:

Exception in thread "main" java.lang.Exception: No such global connection currently open: :default-connection, only got []

Am I misunderstanding the usage of with-connection?

Thanks,
Barry

Pieter Breed

unread,
Mar 6, 2014, 1:10:47 AM3/6/14
to lobos-...@googlegroups.com
I'm struggling with the same thing. Any luck?

Barry Wark

unread,
Mar 6, 2014, 2:58:14 PM3/6/14
to lobos-...@googlegroups.com
No, I ended up using 

  (lobos.config/open-global-when-necessary dbspec)
  (binding [lobos.migration/*reload-migrations* false]
    (lobos.core/migrate dbspec)))

with 

(defn open-global-when-necessary
  "Open a global connection only when necessary, that is, when no previous
  connection exist or when db-spec is different to the current global
  connection."
  [db-spec]
  ;; If the connection credentials has changed, close the connection.
  (when (and (@lobos.connectivity/global-connections :default-connection )
          (not= (:db-spec (@lobos.connectivity/global-connections :default-connection )) db-spec))
    (lobos.connectivity/close-global))
  ;; Open a new connection or return the existing one.
  (if (nil? (@lobos.connectivity/global-connections :default-connection ))
    ((lobos.connectivity/open-global db-spec) :default-connection )
    (@lobos.connectivity/global-connections :default-connection )))

Not especially happy with the solution, but it got us where we needed to get. 

I’d be really happy to hear about better options!

Cheers,
Barry


--
You received this message because you are subscribed to a topic in the Google Groups "Lobos Library" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lobos-library/TZDeFSYx3_w/unsubscribe.

To unsubscribe from this group and all its topics, send an email to lobos-librar...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages