diff options
Diffstat (limited to 'src/clojure_sql/core.clj')
-rw-r--r-- | src/clojure_sql/core.clj | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj index bd4b431..5380c08 100644 --- a/src/clojure_sql/core.clj +++ b/src/clojure_sql/core.clj @@ -12,10 +12,19 @@ (alter-var-root #'*database-type* (constantly new-type)) nil) -(q/set-query-deref-behaviour! #(c/compile *database-type* %)) +(def ^:private ^:dynamic *query-executor* nil) +(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] - (pr (c/compile nil query)))) + (pr (c/compile *database-type* query)))) (def table #'d/table) @@ -27,6 +36,33 @@ (def having #'d/having) (def sort #'d/sort) +;(def take #'d/take) +;(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)))) + +(def update! (fn [query partial-record] + (let [compiled (c/update! *database-type* query partial-record)] + (if *query-executor* + (*query-executor* compiled) + compiled)))) + +(def delete! (fn [query] + (let [compiled (c/delete! *database-type* query)] + (if *query-executor* + (*query-executor* compiled) + compiled)))) + +(let [users (-> (table :users) + (project [:id :username :password-hash]))] + (insert! (-> users + (project [:username])) + {:username "john"} + {:username "not-john"} + {:username "bleep bloop"})) -(-> (table :x) - (select `($ (- :a) #"bloo"))) |