just use defrecords, not deftypes

This commit is contained in:
Mike Blume 2015-03-03 18:53:34 -08:00
parent 415bbce6b3
commit ea6dc98125

View file

@ -1,21 +1,11 @@
(ns honeysql.types) (ns honeysql.types)
(deftype SqlCall [name args _meta] (defrecord SqlCall [name args])
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 (defn call
"Represents a SQL function call. Name should be a keyword." "Represents a SQL function call. Name should be a keyword."
[name & args] [name & args]
(SqlCall. name args nil)) (SqlCall. name args))
(defn read-sql-call [form] (defn read-sql-call [form]
(apply call form)) (apply call form))
@ -28,18 +18,12 @@
;;;; ;;;;
(deftype SqlRaw [s _meta] (defrecord SqlRaw [s])
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 (defn raw
"Represents a raw SQL string" "Represents a raw SQL string"
[s] [s]
(SqlRaw. (str s) nil)) (SqlRaw. (str s)))
(defn read-sql-raw [form] (defn read-sql-raw [form]
(raw form)) (raw form))
@ -52,18 +36,12 @@
;;;; ;;;;
(deftype SqlParam [name _meta] (defrecord SqlParam [name])
Object
(hashCode [this] (hash-combine (hash (class this)) (hash (name name))))
(equals [this x] (and (instance? SqlParam x) (= (.name this) (.name x))))
clojure.lang.IObj
(meta [this] _meta)
(withMeta [this m] (SqlParam. (.name this) m)))
(defn param (defn param
"Represents a SQL parameter which can be filled in later" "Represents a SQL parameter which can be filled in later"
[name] [name]
(SqlParam. name nil)) (SqlParam. name))
(defn param-name [^SqlParam param] (defn param-name [^SqlParam param]
(.name param)) (.name param))