diff --git a/README.md b/README.md index d8b847e..a560632 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,10 @@ calls and raw SQL fragments: (sql/format *1) => ["SELECT COUNT(*), @var := foo.bar FROM foo"] + +;; Fully readable +(= *2 (read-string (pr-str *2))) +=> true ``` Here's a complicated query: diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index fd4c8ca..f743623 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -6,10 +6,20 @@ ;;;; -(deftype SqlCall [name args]) +(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)) + (SqlCall. name args nil)) (defn read-sql-call [form] (apply call form)) @@ -22,10 +32,16 @@ ;;;; -(deftype SqlRaw [s]) +(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))) + (SqlRaw. (str s) nil)) (defn read-sql-raw [form] (raw form))