From 553956ee75b0d7f94e53aeae7e1da0ad4649a765 Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Tue, 31 Mar 2015 11:21:39 -0700 Subject: [PATCH 1/2] avoid boilerplate using defrecord --- src/honeysql/types.clj | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/src/honeysql/types.clj b/src/honeysql/types.clj index 4f63196..15ce243 100644 --- a/src/honeysql/types.clj +++ b/src/honeysql/types.clj @@ -1,22 +1,11 @@ (ns honeysql.types) -(deftype SqlCall [name args _meta] - Object - (hashCode [_] (hash-combine (hash name) (hash args))) - (equals [this x] - (cond (identical? this x) true - (instance? SqlCall x) (let [^SqlCall x x] - (and (= name (.name x)) - (= args (.args x)))) - :else false)) - clojure.lang.IObj - (meta [_] _meta) - (withMeta [_ m] (SqlCall. name args m))) +(defrecord SqlCall [name args]) (defn call "Represents a SQL function call. Name should be a keyword." [name & args] - (SqlCall. name args nil)) + (SqlCall. name args)) (defn read-sql-call [form] ;; late bind so that we get new class on REPL reset @@ -30,18 +19,12 @@ ;;;; -(deftype SqlRaw [s _meta] - Object - (hashCode [this] (hash-combine (hash (class this)) (hash s))) - (equals [_ x] (and (instance? SqlRaw x) (= s (.s ^SqlRaw x)))) - clojure.lang.IObj - (meta [_] _meta) - (withMeta [_ m] (SqlRaw. s m))) +(defrecord SqlRaw [s]) (defn raw "Represents a raw SQL string" [s] - (SqlRaw. (str s) nil)) + (SqlRaw. (str s))) (defn read-sql-raw [form] ;; late bind, as above @@ -55,18 +38,12 @@ ;;;; -(deftype SqlParam [name _meta] - Object - (hashCode [this] (hash-combine (hash (class this)) (hash (name name)))) - (equals [_ x] (and (instance? SqlParam x) (= name (.name ^SqlParam x)))) - clojure.lang.IObj - (meta [_] _meta) - (withMeta [_ m] (SqlParam. name m))) +(defrecord SqlParam [name]) (defn param "Represents a SQL parameter which can be filled in later" [name] - (SqlParam. name nil)) + (SqlParam. name)) (defn param-name [^SqlParam param] (.name param)) From 441c109b65295783a391921777ab186625411ecd Mon Sep 17 00:00:00 2001 From: Mike Blume Date: Wed, 15 Apr 2015 09:53:15 -0700 Subject: [PATCH 2/2] make SqlArray a record too --- src/honeysql/types.clj | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/honeysql/types.clj b/src/honeysql/types.clj index dfb0ce8..9198d17 100644 --- a/src/honeysql/types.clj +++ b/src/honeysql/types.clj @@ -60,18 +60,12 @@ ;;;; -(deftype SqlArray [values _meta] - Object - (hashCode [this] (hash-combine (hash (class this)) (hash values))) - (equals [_ x] (and (instance? SqlArray x) (= values (.values ^SqlArray x)))) - clojure.lang.IObj - (meta [_] _meta) - (withMeta [_ m] (SqlArray. values m))) +(defrecord SqlArray [values]) (defn array "Represents a SQL array." [values] - (SqlArray. values nil)) + (SqlArray. values)) (defn array-vals [^SqlArray a] (.values a))