Skip to content

Instantly share code, notes, and snippets.

@mefesto
Created January 21, 2011 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mefesto/6b981042c27cacfd975a to your computer and use it in GitHub Desktop.
Save mefesto/6b981042c27cacfd975a to your computer and use it in GitHub Desktop.
(defn wrap-db-connection [handler config]
(let [ds (doto (BasicDataSource.)
(.setDriverClassName (:driver-classname config))
(.setUrl (:url config))
(.setUsername (:username config))
(.setPassword (:password config)))]
(fn [request]
(sql/with-connection {:datasource ds}
(handler request)))))
;; in some main file
(defn -main [& args]
(let [config (read-config (first args))]
(run-jetty
(-> web/handler
wrap-params
(wrap-db-connection config))
{:port (:port config)})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment