From 5ccaca496f4babb4fef2d34e272b8772e077fa25 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 23 May 2013 18:26:46 +1000 Subject: 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. --- src/clojure_sql/query.clj | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/clojure_sql/query.clj') 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)))) + -- cgit v1.2.3