From 273732089b548f3fbe2fd26cdd00fdab3c4bfa29 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Wed, 14 Oct 2020 11:50:32 -0700 Subject: [PATCH] Improve :inline/:raw Note: these are still in flux! --- src/honey/sql.cljc | 13 ++++++++----- test/honey/sql_test.cljc | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 30e7d20..3b15072 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -473,8 +473,8 @@ (cond (nil? x) "NULL" (string? x) (str \' (str/replace x "'" "''") \') - (symbol? x) (name-_ x) - (keyword? x) (name-_ x) + (symbol? x) (sql-kw x) + (keyword? x) (sql-kw x) :else (str x))) (def ^:private special-syntax @@ -525,7 +525,9 @@ ["DEFAULT"]) :inline (fn [_ [x]] - [(sqlize-value x)]) + (if (sequential? x) + [(str/join " " (map #'sqlize-value x))] + [(sqlize-value x)])) :interval (fn [_ [n units]] (let [[sql & params] (format-expr n)] @@ -544,9 +546,10 @@ (fn [_ [k]] ["?" (->param k)]) :raw - ;; TODO: only supports single raw string right now (fn [_ [s]] - [s])})) + (if (sequential? s) + [(str/join " " s)] + [s]))})) (defn format-expr [x & [{:keys [nested?] :as opts}]] (cond (or (keyword? x) (symbol? x)) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 3e351ce..40e04f1 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -359,7 +359,7 @@ (format {:dialect :mysql}))))) (deftest inlined-values-are-stringified-correctly - (is (= ["SELECT 'foo', 'It''s a quote!', bar, NULL"] + (is (= ["SELECT 'foo', 'It''s a quote!', BAR, NULL"] (format {:select [[[:inline "foo"]] [[:inline "It's a quote!"]] [[:inline :bar]]