summaryrefslogtreecommitdiff
path: root/src/clojure_sql
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure_sql')
-rw-r--r--src/clojure_sql/core.clj40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj
index 5380c08..f10d968 100644
--- a/src/clojure_sql/core.clj
+++ b/src/clojure_sql/core.clj
@@ -12,15 +12,12 @@
(alter-var-root #'*database-type* (constantly new-type))
nil)
-(def ^:private ^:dynamic *query-executor* nil)
+(def ^:private ^:dynamic *query-executor* (comp second vector))
(defn set-query-executor! [exec-fn]
(alter-var-root #'*query-executor* (constantly exec-fn))
nil)
-(q/set-query-deref-behaviour! #(let [compiled (c/compile *database-type* %)]
- (if *query-executor*
- (*query-executor* compiled)
- compiled)))
+
(defmethod print-method clojure_sql.query.Query [query writer]
(binding [*out* writer]
@@ -40,23 +37,26 @@
;(def drop #'d/drop)
-(def insert! (fn [query & records]
- (let [compiled (apply c/insert! *database-type* query records)]
- (if *query-executor*
- (*query-executor* compiled)
- compiled))))
+(defn run-query [query]
+ (assert *query-executor* "Cannot execute a query without a query executor")
+ (*query-executor* :query (c/compile *database-type* query)))
+
+(defn insert! [query & records]
+ (assert *query-executor* "Cannot execute a query without a query executor")
+ (let [compiled (apply c/insert! *database-type* query records)]
+ (*query-executor* :insert compiled)))
+
+(defn update! [query partial-record]
+ (assert *query-executor* "Cannot execute a query without a query executor")
+ (let [compiled (c/update! *database-type* query partial-record)]
+ (*query-executor* :update compiled)))
-(def update! (fn [query partial-record]
- (let [compiled (c/update! *database-type* query partial-record)]
- (if *query-executor*
- (*query-executor* compiled)
- compiled))))
+(defn delete! [query]
+ (assert *query-executor* "Cannot execute a query without a query executor")
+ (let [compiled (c/delete! *database-type* query)]
+ (*query-executor* :delete compiled)))
-(def delete! (fn [query]
- (let [compiled (c/delete! *database-type* query)]
- (if *query-executor*
- (*query-executor* compiled)
- compiled))))
+(q/set-query-deref-behaviour! run-query)
(let [users (-> (table :users)
(project [:id :username :password-hash]))]