diff options
Diffstat (limited to 'src/clojure_sql/core.clj')
-rw-r--r-- | src/clojure_sql/core.clj | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/src/clojure_sql/core.clj b/src/clojure_sql/core.clj index ebdc01f..03f992b 100644 --- a/src/clojure_sql/core.clj +++ b/src/clojure_sql/core.clj @@ -1,5 +1,5 @@ (ns clojure-sql.core - (:refer-clojure :exclude [sort]) + (:refer-clojure :exclude [sort take drop]) (:require [clojure.set :as set] [clojure-sql.compiler :as c] [clojure-sql.dsl :as d] @@ -21,7 +21,7 @@ (defmethod print-method clojure_sql.query.Query [query writer] (binding [*out* writer] - (pr (c/compile *database-type* query)))) + (pr (c/compile-select *database-type* query)))) (def table #'d/table) @@ -32,46 +32,27 @@ (def group #'d/group) (def having #'d/having) (def sort #'d/sort) - -;(def take #'d/take) -;(def drop #'d/drop) +(def take #'d/take) +(def drop #'d/drop) (defn run-query [query] (assert *query-executor* "Cannot execute a query without a query executor") - (*query-executor* :query (c/compile *database-type* query))) + (*query-executor* :select (c/compile-select *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)] + (let [compiled (apply c/compile-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)] + (let [compiled (c/compile-update *database-type* query partial-record)] (*query-executor* :update compiled))) (defn delete! [query] (assert *query-executor* "Cannot execute a query without a query executor") - (let [compiled (c/delete! *database-type* query)] + (let [compiled (c/compile-delete *database-type* query)] (*query-executor* :delete compiled))) (q/set-query-deref-behaviour! run-query) - - - - - - - -;; FIXME: how to do this better? With some discovery, maybe? - -(require '[clojure.java.jdbc :as jdbc]) -(defn use-jdbc! [connection-string] - (set-query-executor! (fn [type query] - (jdbc/with-connection connection-string - (case type - :query (jdbc/with-query-results results query - (vec results)) - :insert (jdbc/do-prepared-return-keys (first query) (next query)) - (jdbc/do-prepared (first query) (next query))))))) |