summaryrefslogtreecommitdiff
path: root/src/clojure_sql/query.clj
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-05-23 18:26:46 +1000
committerCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-05-23 18:26:46 +1000
commit5ccaca496f4babb4fef2d34e272b8772e077fa25 (patch)
tree39503109047318559e806372668bdfc092dbb1a6 /src/clojure_sql/query.clj
parent626ab0234ad2e578992d128ced35c2003902e90f (diff)
Simplify the compiler, better subquery support
The compiler's been simplified a bit by breaking out the `writer` stuff into its own namespace and by generally making the monadic stuff better. It's all hidden behind a nice, simple, `clojure-sql.compiler/compile` function now. Call that and you'll get back what you need. (Internally it's a writer monad which is really modelled as a state monad with the only operation able to be performed on the state being `tell`.) Subqueries are now handled by the DSL in such a way as to not blow up everything. Subqueries have no support for referencing values in the superquery, though, so their utility is quite limited at present. Thinking about how to do subqueries properly may be difficult.
Diffstat (limited to 'src/clojure_sql/query.clj')
-rw-r--r--src/clojure_sql/query.clj19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/clojure_sql/query.clj b/src/clojure_sql/query.clj
index 239aab4..00eb212 100644
--- a/src/clojure_sql/query.clj
+++ b/src/clojure_sql/query.clj
@@ -1,20 +1,13 @@
-(ns clojure-sql.query
- (:require [clojure-sql.compiler :as c]))
+(ns clojure-sql.query)
-
-(def ^:private ^:dynamic *database-type* nil)
-(defn set-database-type! [new-type]
- (alter-var-root #'*database-type* (constantly new-type))
- nil)
-
-(def ^:private ^:dynamic *query-deref-behaviour* #(c/compile-query *database-type* %))
+(def ^:private ^:dynamic *query-deref-behaviour* identity)
(defn set-query-deref-behaviour! [f]
(alter-var-root #'*query-deref-behaviour* (constantly f))
nil)
-(defrecord ^:private Query []
+(defrecord ^:private Query []
clojure.lang.IDeref
(deref [this] (*query-deref-behaviour* this)))
-(defmethod print-method Query [query writer]
- (binding [*out* writer]
- (pr (c/compile-query nil query))))
+
+(def query? (partial instance? (class (->Query))))
+