From fe513564989d9151a79d5494f2958ae190c20d02 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 12 Nov 2013 16:58:44 +1100 Subject: Change the query executor model: now it's query local and the interface is managed by a protocol. --- src/clojure_sql/query.clj | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/clojure_sql/query.clj') diff --git a/src/clojure_sql/query.clj b/src/clojure_sql/query.clj index 218ae7a..113e748 100644 --- a/src/clojure_sql/query.clj +++ b/src/clojure_sql/query.clj @@ -1,13 +1,23 @@ (ns clojure-sql.query) -(def ^:private ^:dynamic *query-deref-behaviour* identity) -(defn set-query-deref-behaviour! [f] - (alter-var-root #'*query-deref-behaviour* (constantly f)) - nil) +(defprotocol QueryExecutor + (query [_ query] + "Retrieve information from the database.") + (insert! [_ query records] + "Insert a number of records into a table, setting each column to the corresponding value in its record.") + (update! [_ query partial-record] + "Update every row which this query would select by setting each field to the corresponding value in partial-record.") + (delete! [_ query] + "Delete every row which this query would select.")) -(defrecord ^:private Query [] +(defn fn->QueryExecutor [f] + (reify QueryExecutor + (query [_ query] ()))) + +(defrecord ^:private Query [executor] clojure.lang.IDeref - (deref [this] (*query-deref-behaviour* this))) + (deref [this] + (assert executor "Cannot deref a query without a query executor") + (query executor this))) (def query? (partial instance? Query)) - -- cgit v1.2.3