Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from shopsmart/trans_mgmt_and_helpers_006
Browse files Browse the repository at this point in the history
Modify the function declaration ordering to fix dependency issue
  • Loading branch information
levi-andrew-dixon committed Jul 19, 2017
2 parents 994cca9 + 5cb743b commit dedfddc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject com.github.shopsmart/clj-infrastructure "0.1.18"
(defproject com.github.shopsmart/clj-infrastructure "0.1.19"
:description "Infrastructure helpers for AWS, database, etc."
:url "https://github.com/shopsmart/clj-infrastructure"

Expand Down
59 changes: 30 additions & 29 deletions src/clj_infrastructure/db.clj
Expand Up @@ -669,6 +669,36 @@
detail-map))


(defn run-statement
[conn {:keys [stmt-text exec-mode op-comment binds opt-map commit?] :as stmt-detail-map}]

"""
Runs the statement represented by the supplied statement detail
map.
Returns: The statement detail map updated with {:result result-data}
"""

(log/info (str "Running statement: [" stmt-text "] ..."))
(let [sql-params (concat [stmt-text] binds)]
(when op-comment
(log/info (str "Operation comment: " op-comment)))
(let [updated-map
(assoc-in stmt-detail-map [:result]
(cond
(= exec-mode DB_EXEC_MODE_QUERY)
(do
(log/debug "Issuing statement as query (results expected) ...")
(clojure.java.jdbc/query conn sql-params opt-map))
(= exec-mode DB_EXEC_MODE_EXEC)
(do
(log/debug "Issuing statement as execution (no results expected) ...")
(clojure.java.jdbc/execute! conn sql-params opt-map))))]
(when commit?
(.commit (:connection conn)))
updated-map)))


(defn run-sql-stmts-in-transaction
[conn-or-spec stmt-detail-vec]

Expand Down Expand Up @@ -699,32 +729,3 @@
(for [stmt-detail-map stmt-detail-vec]
(run-statement conn stmt-detail-map))))))


(defn run-statement
[conn {:keys [stmt-text exec-mode op-comment binds opt-map commit?] :as stmt-detail-map}]

"""
Runs the statement represented by the supplied statement detail
map.
Returns: The statement detail map updated with {:result result-data}
"""

(log/info (str "Running statement: [" stmt-text "] ..."))
(let [sql-params (concat [stmt-text] binds)]
(when op-comment
(log/info (str "Operation comment: " op-comment)))
(let [updated-map
(assoc-in stmt-detail-map [:result]
(cond
(= exec-mode DB_EXEC_MODE_QUERY)
(do
(log/debug "Issuing statement as query (results expected) ...")
(clojure.java.jdbc/query conn sql-params opt-map))
(= exec-mode DB_EXEC_MODE_EXEC)
(do
(log/debug "Issuing statement as execution (no results expected) ...")
(clojure.java.jdbc/execute! conn sql-params opt-map))))]
(when commit?
(.commit (:connection conn)))
updated-map)))

0 comments on commit dedfddc

Please sign in to comment.