diff --git a/src/korma/db.clj b/src/korma/db.clj index f1391a1..853a486 100644 --- a/src/korma/db.clj +++ b/src/korma/db.clj @@ -7,6 +7,7 @@ (def ^:dynamic *current-db* nil) (def ^:dynamic *current-conn* nil) +(def ^:dynamic *options* nil) (defn- ->delimiters [delimiters] (if delimiters @@ -288,12 +289,13 @@ (jdbc/db-is-rollback-only *current-conn*)) (defn- exec-sql [{:keys [results sql-str params]}] - (let [keys (get-in *current-db* [:options :naming :keys]) + (let [keys (get-in *current-db* [:options :naming :keys]) sql-params (apply vector sql-str params)] (case results - :results (jdbc/query *current-conn* sql-params {:identifiers keys}) - :keys (jdbc/db-do-prepared-return-keys *current-conn* sql-params) - (jdbc/db-do-prepared *current-conn* sql-params)))) + :results (jdbc/query *current-conn* sql-params (merge {:identifiers keys} + *options*)) + :keys (jdbc/db-do-prepared-return-keys *current-conn* true sql-params *options*) + (jdbc/db-do-prepared *current-conn* true sql-params *options*)))) (defmacro with-db "Execute all queries within the body using the given db spec" @@ -308,3 +310,9 @@ (exec-sql query) (with-db (or db @_default) (exec-sql query)))) + +(defmacro with-options + "Add options to the statments. For example (with-options {:fetch-size 1000} ...)" + [options & body] + `(binding [*options* ~options] + ~@body))