move types to separate ns

This commit is contained in:
Justin Kramer 2012-07-13 12:43:18 -04:00
parent 039ab16447
commit f9b262cefb
4 changed files with 55 additions and 53 deletions

View file

@ -1,2 +1,2 @@
{sql/call honeysql.format/read-sql-call
sql/raw honeysql.format/read-sql-raw}
{sql/call honeysql.types/read-sql-call
sql/raw honeysql.types/read-sql-raw}

View file

@ -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]

View file

@ -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))

47
src/honeysql/types.clj Normal file
View file

@ -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))