diff --git a/resources/data_readers.clj b/resources/data_readers.clj index cd55371..90e84e1 100644 --- a/resources/data_readers.clj +++ b/resources/data_readers.clj @@ -1,2 +1,2 @@ -{sql/call honeysql.format/read-sql-call - sql/raw honeysql.format/read-sql-raw} \ No newline at end of file +{sql/call honeysql.types/read-sql-call + sql/raw honeysql.types/read-sql-raw} \ No newline at end of file diff --git a/src/honeysql/core.clj b/src/honeysql/core.clj index 162c51e..2bde710 100644 --- a/src/honeysql/core.clj +++ b/src/honeysql/core.clj @@ -1,10 +1,11 @@ (ns honeysql.core (:refer-clojure :exclude [group-by format]) (:require [honeysql.format :as format] + [honeysql.types :as types] [honeysql.util :refer [defalias]])) -(defalias call format/call) -(defalias raw format/raw) +(defalias call types/call) +(defalias raw types/raw) (defalias format format/format) (defn select [& fields] diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index f743623..6ffb9c6 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -1,59 +1,13 @@ (ns honeysql.format (:refer-clojure :exclude [format]) - (:require [clojure.string :as string])) + (:require [honeysql.types :refer [call raw]] + [clojure.string :as string]) + (:import [honeysql.types SqlCall SqlRaw])) ;;(set! *warn-on-reflection* true) ;;;; -(deftype SqlCall [name args _meta] - Object - (hashCode [this] (hash-combine (hash name) (hash args))) - (equals [this x] - (cond (identical? this x) true - (instance? SqlCall x) (and (= (.name this) (.name x)) - (= (.args this) (.args x))) - :else false)) - clojure.lang.IObj - (meta [this] _meta) - (withMeta [this m] (SqlCall. (.name this) (.args this) m))) - -(defn call [name & args] - (SqlCall. name args nil)) - -(defn read-sql-call [form] - (apply call form)) - -(defmethod print-method SqlCall [^SqlCall o ^java.io.Writer w] - (.write w (str "#sql/call " (pr-str (into [(.name o)] (.args o)))))) - -(defmethod print-dup SqlCall [o w] - (print-method o w)) - -;;;; - -(deftype SqlRaw [s _meta] - Object - (hashCode [this] (hash-combine (hash (class this)) (hash s))) - (equals [this x] (and (instance? SqlRaw x) (= (.s this) (.s x)))) - clojure.lang.IObj - (meta [this] _meta) - (withMeta [this m] (SqlRaw. (.s this) m))) - -(defn raw [s] - (SqlRaw. (str s) nil)) - -(defn read-sql-raw [form] - (raw form)) - -(defmethod print-method SqlRaw [^SqlRaw o ^java.io.Writer w] - (.write w (str "#sql/raw " (pr-str (.s o))))) - -(defmethod print-dup SqlRaw [o w] - (print-method o w)) - -;;;; - (defn comma-join [s] (string/join ", " s)) diff --git a/src/honeysql/types.clj b/src/honeysql/types.clj new file mode 100644 index 0000000..ba70349 --- /dev/null +++ b/src/honeysql/types.clj @@ -0,0 +1,47 @@ +(ns honeysql.types) + +(deftype SqlCall [name args _meta] + Object + (hashCode [this] (hash-combine (hash name) (hash args))) + (equals [this x] + (cond (identical? this x) true + (instance? SqlCall x) (and (= (.name this) (.name x)) + (= (.args this) (.args x))) + :else false)) + clojure.lang.IObj + (meta [this] _meta) + (withMeta [this m] (SqlCall. (.name this) (.args this) m))) + +(defn call [name & args] + (SqlCall. name args nil)) + +(defn read-sql-call [form] + (apply call form)) + +(defmethod print-method SqlCall [^SqlCall o ^java.io.Writer w] + (.write w (str "#sql/call " (pr-str (into [(.name o)] (.args o)))))) + +(defmethod print-dup SqlCall [o w] + (print-method o w)) + +;;;; + +(deftype SqlRaw [s _meta] + Object + (hashCode [this] (hash-combine (hash (class this)) (hash s))) + (equals [this x] (and (instance? SqlRaw x) (= (.s this) (.s x)))) + clojure.lang.IObj + (meta [this] _meta) + (withMeta [this m] (SqlRaw. (.s this) m))) + +(defn raw [s] + (SqlRaw. (str s) nil)) + +(defn read-sql-raw [form] + (raw form)) + +(defmethod print-method SqlRaw [^SqlRaw o ^java.io.Writer w] + (.write w (str "#sql/raw " (pr-str (.s o))))) + +(defmethod print-dup SqlRaw [o w] + (print-method o w))