From 5d6002c6ce698a133f754d25e5ff32e9c57c50b5 Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Thu, 5 May 2016 16:28:04 -0400 Subject: [PATCH 01/21] changed assertion Error to Exception --- src/yesql/generate.clj | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 61209a7..80db969 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -5,7 +5,8 @@ [yesql.util :refer [create-root-var]] [yesql.types :refer [map->Query]] [yesql.statement-parser :refer [tokenize]]) - (:import [yesql.types Query])) + (:import [yesql.types Query]) + (import java.lang.IllegalArgumentException)) (def in-list-parameter? "Check if a type triggers IN-list expansion." @@ -38,17 +39,17 @@ actual-keys (set (keys (dissoc initial-args :?))) actual-positional-count (count (:? initial-args)) missing-keys (set/difference expected-keys actual-keys)] - (assert (empty? missing-keys) - (format "Query argument mismatch.\nExpected keys: %s\nActual keys: %s\nMissing keys: %s" + (if-not (empty? missing-keys) + (throw (IllegalArgumentException. (format "Query argument mismatch.\nExpected keys: %s\nActual keys: %s\nMissing keys: %s" (str (seq expected-keys)) (str (seq actual-keys)) - (str (seq missing-keys)))) - (assert (= expected-positional-count actual-positional-count) - (format (join "\n" + (str (seq missing-keys)))))) + (if-not (= expected-positional-count actual-positional-count) + (throw (IllegalArgumentException. (format (join "\n" ["Query argument mismatch." "Expected %d positional parameters. Got %d." "Supply positional parameters as {:? [...]}"]) - expected-positional-count actual-positional-count)) + expected-positional-count actual-positional-count)))) (let [[final-query final-parameters consumed-args] (reduce (fn [[query parameters args] token] (cond From b6de24755acefc5c72bdd72b8bf80fbf1f98ead8 Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Thu, 5 May 2016 16:37:55 -0400 Subject: [PATCH 02/21] changed test cases --- test/yesql/generate_test.clj | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/yesql/generate_test.clj b/test/yesql/generate_test.clj index 3b0e4f5..cba9077 100644 --- a/test/yesql/generate_test.clj +++ b/test/yesql/generate_test.clj @@ -2,7 +2,8 @@ (:require [expectations :refer :all] [clojure.template :refer [do-template]] [yesql.statement-parser :refer [tokenize]] - [yesql.generate :refer :all])) + [yesql.generate :refer :all]) + (:import [java.lang IllegalArgumentException])) (do-template [statement _ expected-parameters] (expect expected-parameters @@ -82,13 +83,13 @@ "SELECT * FROM users WHERE group_ids IN(:group_ids) AND parent_id = :parent_id" {:group_ids [1 2] :parent_id 3} - => ["SELECT * FROM users WHERE group_ids IN(?,?) AND parent_id = ?" 1 2 3]) + => ["SELECT * FROM users WHERE group_ids IN(?,?) AND parent_id = ?" 1 2 3]) ;;; Incorrect parameters. -(expect AssertionError +(expect IllegalArgumentException (rewrite-query-for-jdbc (tokenize "SELECT age FROM users WHERE country = :country AND name = :name") {:country "gb"})) -(expect AssertionError +(expect IllegalArgumentException (rewrite-query-for-jdbc (tokenize "SELECT age FROM users WHERE country = ? AND name = ?") {})) From d634f7d6469322753e48ce5649e6710af8278f49 Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Mon, 20 Jun 2016 18:37:41 -0400 Subject: [PATCH 03/21] added batch insert support --- project.clj | 2 +- src/yesql/generate.clj | 50 ++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/project.clj b/project.clj index bdc49d3..729872f 100644 --- a/project.clj +++ b/project.clj @@ -11,7 +11,7 @@ :url "https://github.com/krisajenkins/yesql"} :profiles {:dev {:dependencies [[expectations "2.1.3" :exclusions [org.clojure/clojure]] [org.apache.derby/derby "10.12.1.1"]] - :plugins [[lein-autoexpect "1.4.0"] + :plugins [[lein-autoexpect "1.4.0" :exclusions [org.clojure/tools.namespace]] [lein-expectations "0.0.8" :exclusions [org.clojure/clojure]]]} :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]} :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]} diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 80db969..bfdf2b5 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -36,7 +36,7 @@ (defn rewrite-query-for-jdbc [tokens initial-args] (let [{:keys [expected-keys expected-positional-count]} (analyse-statement-tokens tokens) - actual-keys (set (keys (dissoc initial-args :?))) + actual-keys (set (keys (dissoc (if (or (vector? initial-args) (list? initial-args)) (apply merge initial-args) initial-args) :?))) actual-positional-count (count (:? initial-args)) missing-keys (set/difference expected-keys actual-keys)] (if-not (empty? missing-keys) @@ -50,23 +50,33 @@ "Expected %d positional parameters. Got %d." "Supply positional parameters as {:? [...]}"]) expected-positional-count actual-positional-count)))) - (let [[final-query final-parameters consumed-args] - (reduce (fn [[query parameters args] token] - (cond - (string? token) [(str query token) - parameters - args] - (symbol? token) (let [[arg new-args] (if (= '? token) - [(first (:? args)) (update-in args [:?] rest)] - [(get args (keyword token)) args])] - [(str query (args-to-placeholders arg)) - (vec (if (in-list-parameter? arg) - (concat parameters arg) - (conj parameters arg))) - new-args]))) - ["" [] initial-args] - tokens)] - (concat [final-query] final-parameters)))) + (if (or (vector? initial-args) (list? initial-args)) + (let [[final-query final-parameters consumed-args] + (reduce (fn [[query parameters args] token] + (cond + (string? token) [(str query token) + parameters + args] + (symbol? token) [(str query (args-to-placeholders "")) + (conj parameters (keyword token)) + args])) ["" [] initial-args] tokens)] (concat [final-query] (mapv (apply juxt final-parameters) initial-args))) + (let [[final-query final-parameters consumed-args] + (reduce (fn [[query parameters args] token] + (cond + (string? token) [(str query token) + parameters + args] + (symbol? token) (let [[arg new-args] (if (= '? token) + [(first (:? args)) (update-in args [:?] rest)] + [(get args (keyword token)) args])] + [(str query (args-to-placeholders arg)) + (vec (if (in-list-parameter? arg) + (concat parameters arg) + (conj parameters arg))) + new-args]))) + ["" [] initial-args] + tokens)] + (concat [final-query] final-parameters))))) ;; Maintainer's note: clojure.java.jdbc.execute! returns a list of ;; rowcounts, because it takes a list of parameter groups. In our @@ -78,7 +88,9 @@ (defn insert-handler [db statement-and-params call-options] - (jdbc/db-do-prepared-return-keys db statement-and-params)) + (if (vector? (second statement-and-params)) + (apply jdbc/db-do-prepared db statement-and-params) + (jdbc/db-do-prepared-return-keys db statement-and-params))) (defn query-handler [db sql-and-params From af21fcf3f6f5460064b768184d7900d48c52d91b Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Tue, 22 May 2018 15:23:37 -0400 Subject: [PATCH 04/21] updated version --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 729872f..f6e556a 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject yesql "0.5.3" +(defproject org.batch/yesql "0.6.3" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" From 0758c1091d1d1fb0e0ba288c8a38184ea1f6d23c Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Thu, 14 Jun 2018 07:02:48 -0400 Subject: [PATCH 05/21] added support for returning keys from batch insert --- project.clj | 2 +- src/yesql/generate.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index f6e556a..7f63ce2 100644 --- a/project.clj +++ b/project.clj @@ -4,7 +4,7 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0"] - [org.clojure/java.jdbc "0.5.8"] + [org.clojure/java.jdbc "0.7.6"] [instaparse "1.4.1" :exclusions [org.clojure/clojure]]] :pedantic? :abort :scm {:name "git" diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index bfdf2b5..4aaf2bf 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -89,7 +89,7 @@ (defn insert-handler [db statement-and-params call-options] (if (vector? (second statement-and-params)) - (apply jdbc/db-do-prepared db statement-and-params) + (jdbc/execute! db statement-and-params {:multi? true :return-keys true}) (jdbc/db-do-prepared-return-keys db statement-and-params))) (defn query-handler From b9386c8745551e2059f9c3e59672f6d002c1c020 Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Thu, 14 Jun 2018 07:03:24 -0400 Subject: [PATCH 06/21] bumped version number --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 7f63ce2..3a01ea9 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.6.3" +(defproject org.batch/yesql "0.6.4" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" From bf0fb30f732ec687cabf69d3ee800f4525084c7c Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Thu, 14 Jun 2018 14:27:58 -0400 Subject: [PATCH 07/21] added before and after hooks as well as a debug switch in call-options to simplify debugging long server-side functions --- src/yesql/generate.clj | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 4aaf2bf..affba3f 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -1,7 +1,7 @@ (ns yesql.generate (:require [clojure.java.jdbc :as jdbc] [clojure.set :as set] - [clojure.string :refer [join lower-case]] + [clojure.string :refer [join lower-case split trim]] [yesql.util :refer [create-root-var]] [yesql.types :refer [map->Query]] [yesql.statement-parser :refer [tokenize]]) @@ -123,16 +123,31 @@ global-connection (:connection query-options) tokens (tokenize statement) real-fn (fn [args call-options] - (let [connection (or (:connection call-options) - global-connection)] - (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)) - (jdbc-fn connection - (rewrite-query-for-jdbc tokens args) - call-options))) + (if (:debug call-options) + args + (let [connection (or (:connection call-options) + global-connection)] + (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) (: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)) + (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)) + ret)))) [display-args generated-function] (let [named-args (if-let [as-vec (seq (mapv (comp symbol clojure.core/name) required-args))] {:keys as-vec} From bfca254838e44a45479e2454de8808652a2511a3 Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Thu, 14 Jun 2018 14:28:37 -0400 Subject: [PATCH 08/21] bumped version number --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 3a01ea9..061db8d 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.6.4" +(defproject org.batch/yesql "0.6.5" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" From 5d95346b1dce6ca0461046cec7560f23bbd0332d Mon Sep 17 00:00:00 2001 From: ibarrick Date: Tue, 23 Apr 2019 10:04:03 -0400 Subject: [PATCH 09/21] handle IN by passing in NULL if list is empty --- project.clj | 2 +- src/yesql/generate.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 061db8d..28911b2 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.6.5" +(defproject org.batch/yesql "0.6.6" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index affba3f..4255391 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -15,7 +15,7 @@ (defn- args-to-placeholders [args] (if (in-list-parameter? args) - (clojure.string/join "," (repeat (count args) "?")) + (if (empty? args) "NULL" (clojure.string/join "," (repeat (count args) "?"))) "?")) (defn- analyse-statement-tokens From c9d4e3f0eac9b0e0b42ad1ee76bb2f1567445f4e Mon Sep 17 00:00:00 2001 From: ibarrick Date: Wed, 4 Sep 2019 15:12:26 -0400 Subject: [PATCH 10/21] added support for transaction retries to yesql --- project.clj | 5 +++-- src/yesql/generate.clj | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/project.clj b/project.clj index 28911b2..9cbc183 100644 --- a/project.clj +++ b/project.clj @@ -1,11 +1,12 @@ -(defproject org.batch/yesql "0.6.6" +(defproject org.batch/yesql "0.7.0" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/java.jdbc "0.7.6"] - [instaparse "1.4.1" :exclusions [org.clojure/clojure]]] + [instaparse "1.4.1" :exclusions [org.clojure/clojure]] + [mysql/mysql-connector-java "5.1.44"]] :pedantic? :abort :scm {:name "git" :url "https://github.com/krisajenkins/yesql"} diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 4255391..f74059b 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -6,7 +6,7 @@ [yesql.types :refer [map->Query]] [yesql.statement-parser :refer [tokenize]]) (:import [yesql.types Query]) - (import java.lang.IllegalArgumentException)) + (:import java.lang.IllegalArgumentException)) (def in-list-parameter? "Check if a type triggers IN-list expansion." @@ -138,9 +138,24 @@ ((: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)) - (let [ret (jdbc-fn connection - (rewrite-query-for-jdbc tokens args) - call-options)] + (let [ret (jdbc/with-db-transaction [t connection] + (if (not= (:level t) 1) + (jdbc-fn connection + (rewrite-query-for-jdbc tokens args) + call-options) + (loop [i 0] + (Thread/sleep (* i 2 10)) + (let [sym (try + (jdbc-fn connection + (rewrite-query-for-jdbc tokens args) + call-options) + (catch com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException e + (if (= i 10) + (throw e) + :exception-caught)))] + (if (= :exception-caught sym) + (recur (inc i)) + sym)))))] (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)) From 832b35c66c2e8102a380222f3a9d20c7ad08752f Mon Sep 17 00:00:00 2001 From: ibarrick Date: Tue, 10 Sep 2019 09:10:50 -0400 Subject: [PATCH 11/21] Revert "added support for transaction retries to yesql" This reverts commit c9d4e3f0eac9b0e0b42ad1ee76bb2f1567445f4e. --- project.clj | 5 ++--- src/yesql/generate.clj | 23 ++++------------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/project.clj b/project.clj index 9cbc183..28911b2 100644 --- a/project.clj +++ b/project.clj @@ -1,12 +1,11 @@ -(defproject org.batch/yesql "0.7.0" +(defproject org.batch/yesql "0.6.6" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/java.jdbc "0.7.6"] - [instaparse "1.4.1" :exclusions [org.clojure/clojure]] - [mysql/mysql-connector-java "5.1.44"]] + [instaparse "1.4.1" :exclusions [org.clojure/clojure]]] :pedantic? :abort :scm {:name "git" :url "https://github.com/krisajenkins/yesql"} diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index f74059b..4255391 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -6,7 +6,7 @@ [yesql.types :refer [map->Query]] [yesql.statement-parser :refer [tokenize]]) (:import [yesql.types Query]) - (:import java.lang.IllegalArgumentException)) + (import java.lang.IllegalArgumentException)) (def in-list-parameter? "Check if a type triggers IN-list expansion." @@ -138,24 +138,9 @@ ((: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)) - (let [ret (jdbc/with-db-transaction [t connection] - (if (not= (:level t) 1) - (jdbc-fn connection - (rewrite-query-for-jdbc tokens args) - call-options) - (loop [i 0] - (Thread/sleep (* i 2 10)) - (let [sym (try - (jdbc-fn connection - (rewrite-query-for-jdbc tokens args) - call-options) - (catch com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException e - (if (= i 10) - (throw e) - :exception-caught)))] - (if (= :exception-caught sym) - (recur (inc i)) - sym)))))] + (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)) From a3e20d143e09b546982ce9225b79605808cb7a3e Mon Sep 17 00:00:00 2001 From: ibarrick Date: Tue, 10 Sep 2019 09:16:51 -0400 Subject: [PATCH 12/21] fix clojure 1.9 issue --- project.clj | 2 +- src/yesql/generate.clj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 28911b2..4cd595d 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.6.6" +(defproject org.batch/yesql "0.6.7" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 4255391..2967d12 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -5,8 +5,8 @@ [yesql.util :refer [create-root-var]] [yesql.types :refer [map->Query]] [yesql.statement-parser :refer [tokenize]]) - (:import [yesql.types Query]) - (import java.lang.IllegalArgumentException)) + (:import yesql.types.Query) + (:import java.lang.IllegalArgumentException)) (def in-list-parameter? "Check if a type triggers IN-list expansion." From b10fe922bcf14e2dc62f7fe4709f134ab26c6e4c Mon Sep 17 00:00:00 2001 From: ibarrick Date: Mon, 16 Sep 2019 15:33:16 -0400 Subject: [PATCH 13/21] make hooks an atom for runtime modifications --- project.clj | 2 +- src/yesql/generate.clj | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/project.clj b/project.clj index 4cd595d..45c8d1d 100644 --- a/project.clj +++ b/project.clj @@ -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" diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 2967d12..d305fbc 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -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))] From fc7d9f4956610410195a8f1f1bbccc7a7843add6 Mon Sep 17 00:00:00 2001 From: ibarrick Date: Mon, 16 Sep 2019 16:13:57 -0400 Subject: [PATCH 14/21] fix issues with fix --- src/yesql/generate.clj | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index d305fbc..4f8e539 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -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) (:hooks query-options) (:before-insert query-options)) + (cond (and (= insert-handler jdbc-fn) (:hooks query-options) @(:hooks (: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)) + (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) - (and (= execute-handler jdbc-fn) (:hooks query-options) (= "update" (lower-case (first (split (trim statement) #" ")))) (:before-update query-options)) + (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)) (let [ret (jdbc-fn connection (rewrite-query-for-jdbc tokens args) call-options)] - (cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:after-insert query-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) - (and (= execute-handler jdbc-fn) (:hooks query-options) (= "delete" (lower-case (first (split (trim statement) #" ")))) (:after-delete query-options)) + (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) - (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))) + (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)) ret)))) [display-args generated-function] (let [named-args (if-let [as-vec (seq (mapv (comp symbol clojure.core/name) required-args))] From 08081a855281ee721dfc7ed842cb6962313c29ea Mon Sep 17 00:00:00 2001 From: ibarrick Date: Tue, 17 Sep 2019 10:47:19 -0400 Subject: [PATCH 15/21] fix hooks issue --- project.clj | 2 +- src/yesql/generate.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 45c8d1d..30ad1a5 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.6.8" +(defproject org.batch/yesql "0.6.9" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 4f8e539..39e8b63 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -132,7 +132,7 @@ ["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) @(:hooks (:before-insert query-options))) + (cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:before-insert @(:hooks 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 @(:hooks query-options))) ((:before-delete @(:hooks query-options)) args statement call-options) From 249be1d857fca155f66f1778df10c5bbe5ad86d4 Mon Sep 17 00:00:00 2001 From: ibarrick Date: Fri, 3 Jan 2020 09:32:12 -0500 Subject: [PATCH 16/21] added uuid field to yesql --- src/yesql/generate.clj | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 39e8b63..bee3bee 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -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))] From fd631bc732ff6cdedc73c9ab05dd38fd263a4742 Mon Sep 17 00:00:00 2001 From: ibarrick Date: Fri, 3 Jan 2020 09:49:13 -0500 Subject: [PATCH 17/21] 0.7.0 include safely for exponential backoff --- project.clj | 5 +++-- src/yesql/generate.clj | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/project.clj b/project.clj index 30ad1a5..e62d6fc 100644 --- a/project.clj +++ b/project.clj @@ -1,11 +1,12 @@ -(defproject org.batch/yesql "0.6.9" +(defproject org.batch/yesql "0.7.0" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/java.jdbc "0.7.6"] - [instaparse "1.4.1" :exclusions [org.clojure/clojure]]] + [instaparse "1.4.1" :exclusions [org.clojure/clojure]] + [com.brunobonacci/safely "0.5.0-alpha8" :exclusions [com.google.errorprone/error_prone_annotations org.clojure/clojure com.google.code.findbugs/jsr305]]] :pedantic? :abort :scm {:name "git" :url "https://github.com/krisajenkins/yesql"} diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index bee3bee..3894d6d 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -4,7 +4,8 @@ [clojure.string :refer [join lower-case split trim]] [yesql.util :refer [create-root-var]] [yesql.types :refer [map->Query]] - [yesql.statement-parser :refer [tokenize]]) + [yesql.statement-parser :refer [tokenize]] + [safely.core :refer [safely]]) (:import yesql.types.Query) (:import java.lang.IllegalArgumentException)) @@ -139,9 +140,12 @@ ((: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 (assoc call-options :uuid uuid))) - (let [ret (jdbc-fn connection - (rewrite-query-for-jdbc tokens args) - call-options)] + (let [ret (safely (jdbc-fn connection + (rewrite-query-for-jdbc tokens args) + call-options) + :on-error + :max-retries 5 + :retry-delay [:random-exp-backoff :base 50 :+/- 0.5])] (cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:after-insert @(:hooks query-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))) From 347501e4ee3333c976caab6ecd8bb4a3ae470154 Mon Sep 17 00:00:00 2001 From: ibarrick Date: Fri, 3 Jan 2020 09:51:19 -0500 Subject: [PATCH 18/21] 0.7.1 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index e62d6fc..84b4920 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.7.0" +(defproject org.batch/yesql "0.7.1" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" From 1bbd9f9c03a79f35213ba5372477fdca403b49ec Mon Sep 17 00:00:00 2001 From: ibarrick Date: Tue, 21 Jan 2020 10:30:00 -0500 Subject: [PATCH 19/21] only retry SQLExceptions --- src/yesql/generate.clj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/yesql/generate.clj b/src/yesql/generate.clj index 3894d6d..a0dd2c0 100644 --- a/src/yesql/generate.clj +++ b/src/yesql/generate.clj @@ -7,6 +7,7 @@ [yesql.statement-parser :refer [tokenize]] [safely.core :refer [safely]]) (:import yesql.types.Query) + (:import java.sql.SQLException) (:import java.lang.IllegalArgumentException)) (def in-list-parameter? @@ -145,6 +146,7 @@ call-options) :on-error :max-retries 5 + :retryable-error? #(isa? (class %) SQLException) :retry-delay [:random-exp-backoff :base 50 :+/- 0.5])] (cond (and (= insert-handler jdbc-fn) (:hooks query-options) (:after-insert @(:hooks query-options))) ((:after-insert @(:hooks query-options)) ret args statement (assoc call-options :uuid uuid)) From abbb0db59c0fbab2d8989a8bf3176b1680800240 Mon Sep 17 00:00:00 2001 From: ibarrick Date: Tue, 21 Jan 2020 10:30:39 -0500 Subject: [PATCH 20/21] version 0.7.2 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 84b4920..5988883 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.batch/yesql "0.7.1" +(defproject org.batch/yesql "0.7.2" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" From 36b3f1f1fdd79f820216f1d137191c004b37f04f Mon Sep 17 00:00:00 2001 From: Ian Barrick Date: Tue, 13 Jul 2021 15:00:01 -0400 Subject: [PATCH 21/21] update jdbc --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 5988883..9872f3c 100644 --- a/project.clj +++ b/project.clj @@ -1,10 +1,10 @@ -(defproject org.batch/yesql "0.7.2" +(defproject org.batch/yesql "0.7.3" :description "A Clojure library for using SQL" :url "https://github.com/krisajenkins/yesql" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0"] - [org.clojure/java.jdbc "0.7.6"] + [org.clojure/java.jdbc "0.7.12"] [instaparse "1.4.1" :exclusions [org.clojure/clojure]] [com.brunobonacci/safely "0.5.0-alpha8" :exclusions [com.google.errorprone/error_prone_annotations org.clojure/clojure com.google.code.findbugs/jsr305]]] :pedantic? :abort