using transactions FTW
This commit is contained in:
@@ -7,9 +7,11 @@
|
||||
[auto-ap.routes.graphql :as graphql]
|
||||
[auto-ap.routes.vendors :as vendors]
|
||||
[auto-ap.routes.checks :as checks]
|
||||
[auto-ap.db.utils :as u]
|
||||
[buddy.auth.backends.token :refer [jws-backend]]
|
||||
[buddy.auth.middleware :refer [wrap-authentication
|
||||
wrap-authorization]]
|
||||
[clojure.java.jdbc :as jdbc]
|
||||
[compojure.core :refer :all]
|
||||
[compojure.route :as route]
|
||||
[config.core :refer [env]]
|
||||
@@ -44,8 +46,19 @@
|
||||
api-routes
|
||||
static-routes))
|
||||
|
||||
(defn wrap-transaction [handler]
|
||||
(fn [request]
|
||||
(jdbc/with-db-transaction [t (u/get-conn)]
|
||||
(binding [u/current-conn t]
|
||||
(try
|
||||
(handler (assoc request :db-conn t))
|
||||
(catch Exception e
|
||||
(jdbc/db-set-rollback-only! t)
|
||||
(throw e)))))))
|
||||
|
||||
(def app
|
||||
(-> #'app-routes
|
||||
(wrap-transaction)
|
||||
(wrap-authorization auth-backend)
|
||||
(wrap-authentication auth-backend)
|
||||
(wrap-reload)
|
||||
|
||||
Reference in New Issue
Block a user