Skip to content
Open
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
added uuid field to yesql
  • Loading branch information
ibarrick committed Jan 3, 2020
commit 249be1d857fca155f66f1778df10c5bbe5ad86d4
15 changes: 8 additions & 7 deletions src/yesql/generate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,28 @@
(if (:debug call-options)
args
(let [connection (or (:connection call-options)
global-connection)]
global-connection)
uuid (.toString (java.util.UUID/randomUUID))]
(assert connection
(format (join "\n"
["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) (:hooks query-options) (:before-insert @(:hooks query-options)))
((:before-insert @(:hooks query-options)) args statement call-options)
((:before-insert @(:hooks query-options)) args statement (assoc call-options :uuid uuid))
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:before-delete @(:hooks query-options)))
((:before-delete @(:hooks query-options)) args statement call-options)
((:before-delete @(:hooks query-options)) args statement (assoc call-options :uuid uuid))
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "update" (lower-case (first (split (trim statement) #" ")))) (:before-update @(:hooks query-options)))
((:before-update @(:hooks query-options)) args statement call-options))
((:before-update @(:hooks query-options)) args statement (assoc call-options :uuid uuid)))
(let [ret (jdbc-fn connection
(rewrite-query-for-jdbc tokens args)
call-options)]
(cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:after-insert @(:hooks query-options)))
((:after-insert @(:hooks query-options)) ret args statement call-options)
((:after-insert @(:hooks query-options)) ret args statement (assoc call-options :uuid uuid))
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:after-delete @(:hooks query-options)))
((:after-delete @(:hooks query-options)) ret args statement call-options)
((:after-delete @(:hooks query-options)) ret args statement (assoc call-options :uuid uuid))
(and (= execute-handler jdbc-fn) (:hooks query-options) (= "update" (lower-case (first (split (trim statement) #" ")))) (:after-update @(:hooks query-options)))
((:after-update @(:hooks query-options)) ret args statement call-options))
((:after-update @(:hooks query-options)) ret args statement (assoc call-options :uuid uuid)))
ret))))
[display-args generated-function] (let [named-args (if-let [as-vec (seq (mapv (comp symbol clojure.core/name)
required-args))]
Expand Down