From e494315fa0ae9467dfe64417214334d8476e7202 Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Mon, 23 Feb 2015 21:48:30 -0800 Subject: [PATCH 1/4] add travis config --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..78ae754 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: clojure +lein: lein2 +script: lein do check, test From bb77ba945f7a6387c35d4452d60fd59258f57085 Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Thu, 12 Mar 2015 14:34:28 -0700 Subject: [PATCH 2/4] quote this url --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 116f87d..dfc38a8 100644 --- a/project.clj +++ b/project.clj @@ -2,5 +2,5 @@ :description "SQL as Clojure data structures" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :url https://github.com/jkk/honeysql + :url "https://github.com/jkk/honeysql" :dependencies [[org.clojure/clojure "1.6.0"]]) From 941a5b708a6ffabcd11e6cff8e41424a40fd1600 Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Thu, 12 Mar 2015 14:34:33 -0700 Subject: [PATCH 3/4] add scm info to the project.clj --- project.clj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project.clj b/project.clj index dfc38a8..bef711b 100644 --- a/project.clj +++ b/project.clj @@ -3,4 +3,6 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :url "https://github.com/jkk/honeysql" + :scm {:name "git" + :url "https://github.com/jkk/honeysql"} :dependencies [[org.clojure/clojure "1.6.0"]]) From 44a22e37877018ae9330b307a3b88628e88e2e80 Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Tue, 3 Mar 2015 19:53:40 -0800 Subject: [PATCH 4/4] format the format namespace a bit more nicely --- src/honeysql/format.clj | 94 ++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index ded5eff..86c5ff5 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -244,63 +244,69 @@ (extend-protocol ToSql clojure.lang.Keyword - (-to-sql [x] (let [s ^String (name x)] - (condp = (.charAt s 0) - \% (let [call-args (string/split (subs s 1) #"\." 2)] - (to-sql (apply call (map keyword call-args)))) - \? (to-sql (param (keyword (subs s 1)))) - (quote-identifier x)))) + (-to-sql [x] + (let [s (name x)] + (condp = (.charAt s 0) + \% (let [call-args (string/split (subs s 1) #"\." 2)] + (to-sql (apply call (map keyword call-args)))) + \? (to-sql (param (keyword (subs s 1)))) + (quote-identifier x)))) clojure.lang.Symbol (-to-sql [x] (quote-identifier x)) java.lang.Number (-to-sql [x] (str x)) java.lang.Boolean - (-to-sql [x] (if x "TRUE" "FALSE")) + (-to-sql [x] + (if x "TRUE" "FALSE")) clojure.lang.Sequential - (-to-sql [x] (if *fn-context?* - ;; list argument in fn call - (paren-wrap (comma-join (map to-sql x))) - ;; alias - (str (to-sql (first x)) - ; Omit AS in FROM, JOIN, etc. - Oracle doesn't allow it - (if (= :select *clause*) - " AS " - " ") - (if (string? (second x)) - (quote-identifier (second x)) - (to-sql (second x)))))) + (-to-sql [x] + (if *fn-context?* + ;; list argument in fn call + (paren-wrap (comma-join (map to-sql x))) + ;; alias + (str (to-sql (first x)) + ; Omit AS in FROM, JOIN, etc. - Oracle doesn't allow it + (if (= :select *clause*) + " AS " + " ") + (if (string? (second x)) + (quote-identifier (second x)) + (to-sql (second x)))))) SqlCall - (-to-sql [x] (binding [*fn-context?* true] - (let [fn-name (name (.name x)) - fn-name (fn-aliases fn-name fn-name)] - (apply fn-handler fn-name (.args x))))) + (-to-sql [x] + (binding [*fn-context?* true] + (let [fn-name (name (.name x)) + fn-name (fn-aliases fn-name fn-name)] + (apply fn-handler fn-name (.args x))))) SqlRaw (-to-sql [x] (.s x)) clojure.lang.IPersistentMap - (-to-sql [x] (let [clause-ops (sort-clauses (keys x)) - sql-str (binding [*subquery?* true - *fn-context?* false] - (space-join - (map (comp #(-format-clause % x) #(find x %)) - clause-ops)))] - (if *subquery?* - (paren-wrap sql-str) - sql-str))) + (-to-sql [x] + (let [clause-ops (sort-clauses (keys x)) + sql-str (binding [*subquery?* true + *fn-context?* false] + (space-join + (map (comp #(-format-clause % x) #(find x %)) + clause-ops)))] + (if *subquery?* + (paren-wrap sql-str) + sql-str))) nil (-to-sql [x] "NULL") Object - (-to-sql [x] (let [[x pname] (if (instance? SqlParam x) - (let [pname (param-name x)] - (if (map? @*input-params*) - [(get @*input-params* pname) pname] - (let [x (first @*input-params*)] - (swap! *input-params* rest) - [x pname]))) - ;; Anonymous param name -- :_1, :_2, etc. - [x (keyword (str "_" (swap! *param-counter* inc)))])] - (swap! *param-names* conj pname) - (swap! *params* conj x) - "?"))) + (-to-sql [x] + (let [[x pname] (if (instance? SqlParam x) + (let [pname (param-name x)] + (if (map? @*input-params*) + [(get @*input-params* pname) pname] + (let [x (first @*input-params*)] + (swap! *input-params* rest) + [x pname]))) + ;; Anonymous param name -- :_1, :_2, etc. + [x (keyword (str "_" (swap! *param-counter* inc)))])] + (swap! *param-names* conj pname) + (swap! *params* conj x) + "?"))) (defn sqlable? [x] (satisfies? ToSql x))