Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make hooks an atom for runtime modifications
  • Loading branch information
ibarrick committed Sep 16, 2019
commit b10fe922bcf14e2dc62f7fe4709f134ab26c6e4c
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.batch/yesql "0.6.7"
(defproject org.batch/yesql "0.6.8"
:description "A Clojure library for using SQL"
:url "https://github.com/krisajenkins/yesql"
:license {:name "Eclipse Public License"
Expand Down
24 changes: 12 additions & 12 deletions src/yesql/generate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@
["No database connection supplied to function '%s',"
"Check the docs, and supply {:connection ...} as an option to the function call, or globally to the defquery declaration."])
name))
(cond (and (= insert-handler jdbc-fn) (:before-insert query-options))
((:before-insert query-options) args statement call-options)
(and (= execute-handler jdbc-fn) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:before-delete query-options))
((:before-delete query-options) args statement call-options)
(and (= execute-handler jdbc-fn) (= "update" (lower-case (first (split (trim statement) #" ")))) (:before-update query-options))
((:before-update query-options) args statement call-options))
(cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:before-insert query-options))
((:before-insert @(:hooks query-options)) args statement call-options)
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:before-delete query-options))
((:before-delete @(:hooks query-options)) args statement call-options)
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "update" (lower-case (first (split (trim statement) #" ")))) (:before-update query-options))
((:before-update @(:hooks query-options)) args statement call-options))
(let [ret (jdbc-fn connection
(rewrite-query-for-jdbc tokens args)
call-options)]
(cond (and (= insert-handler jdbc-fn) (:after-insert query-options))
((:after-insert query-options) ret args statement call-options)
(and (= execute-handler jdbc-fn) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:after-delete query-options))
((:after-delete query-options) ret args statement call-options)
(and (= execute-handler jdbc-fn) (= "update" (lower-case (first (split (trim statement) #" ")))) (:after-update query-options))
((:after-update query-options) ret args statement call-options))
(cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:after-insert query-options))
((:after-insert @(:hooks query-options)) ret args statement call-options)
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:after-delete query-options))
((:after-delete @(:hooks query-options)) ret args statement call-options)
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "update" (lower-case (first (split (trim statement) #" ")))) (:after-update query-options))
(do (println "running after update hook") ((:after-update @(:hooks query-options)) ret args statement call-options)))
ret))))
[display-args generated-function] (let [named-args (if-let [as-vec (seq (mapv (comp symbol clojure.core/name)
required-args))]
Expand Down