diff --git a/src/honeysql/core.cljc b/src/honeysql/core.cljc index 827ac58..609ba70 100644 --- a/src/honeysql/core.cljc +++ b/src/honeysql/core.cljc @@ -9,6 +9,7 @@ (#?(:clj defalias :cljs def) call types/call) (#?(:clj defalias :cljs def) raw types/raw) (#?(:clj defalias :cljs def) param types/param) +(#?(:clj defalias :cljs def) inline types/inline) (#?(:clj defalias :cljs def) format format/format) (#?(:clj defalias :cljs def) format-predicate format/format-predicate) (#?(:clj defalias :cljs def) quote-identifier format/quote-identifier) diff --git a/src/honeysql/format.cljc b/src/honeysql/format.cljc index e7e323e..88a36d9 100644 --- a/src/honeysql/format.cljc +++ b/src/honeysql/format.cljc @@ -1,9 +1,9 @@ (ns honeysql.format (:refer-clojure :exclude [format]) (:require [honeysql.types :refer [call raw param param-name - #?@(:cljs [SqlCall SqlRaw SqlParam SqlArray])]] + #?@(:cljs [SqlCall SqlRaw SqlParam SqlArray SqlInline])]] [clojure.string :as string]) - #?(:clj (:import [honeysql.types SqlCall SqlRaw SqlParam SqlArray]))) + #?(:clj (:import [honeysql.types SqlCall SqlRaw SqlParam SqlArray SqlInline]))) ;;(set! *warn-on-reflection* true) @@ -388,6 +388,9 @@ SqlArray (to-sql [x] (str "ARRAY[" (comma-join (map to-sql (.-values x))) "]")) + SqlInline + (to-sql [x] + (str (.-value x))) #?(:clj Object :cljs default) (to-sql [x] #?(:clj (add-anon-param x) diff --git a/src/honeysql/types.cljc b/src/honeysql/types.cljc index 35344fc..0e76c2f 100644 --- a/src/honeysql/types.cljc +++ b/src/honeysql/types.cljc @@ -57,6 +57,18 @@ ;; late bind, as above (#?(:clj (resolve `array) :cljs array) form)) +;;;; + +(defrecord SqlInline [value]) + +(defn inline + "Prevents parameterization" + [value] + (SqlInline. value)) + +(defn read-sql-inline [form] + (#?(:clj (resolve `inline) :cljs inline) form)) + #?(:clj (do (defmethod print-method SqlCall [^SqlCall o ^java.io.Writer w] @@ -81,4 +93,10 @@ (.write w (str "#sql/array " (pr-str (.values a))))) (defmethod print-dup SqlArray [a w] + (print-method a w)) + + (defmethod print-method SqlInline [^SqlInline a ^java.io.Writer w] + (.write w (str "#sql/inline " (pr-str (.value a))))) + + (defmethod print-dup SqlInline [a w] (print-method a w)))) diff --git a/test/honeysql/core_test.cljc b/test/honeysql/core_test.cljc index 4f10e0c..60b1ec5 100644 --- a/test/honeysql/core_test.cljc +++ b/test/honeysql/core_test.cljc @@ -192,4 +192,11 @@ (join :x [:= :foo.id :x.id] :y nil) sql/format))))) +(deftest inline-test + (is (= ["SELECT * FROM foo WHERE id = 5"] + (-> (select :*) + (from :foo) + (where [:= :id (sql/inline 5)]) + sql/format)))) + #?(:cljs (cljs.test/run-all-tests))