diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec96d9c..59c9fed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@ Changes made on master since 1.0.475:
## Stable Builds
+* 2020-06-22 -- 1.0.476
+ * Extend default options behavior to `next.jdbc.sql` functions.
+
* 2020-06-22 -- 1.0.475
* Add tests for `"jtds"` database driver (against MS SQL Server), making it officially supported.
* Switch from OpenTable Embedded PostgreSQL to Zonky's version, so that testing can move forward from PostgreSQL 10.11 to 12.2.0.
diff --git a/README.md b/README.md
index 8c77188..7d25434 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ The next generation of `clojure.java.jdbc`: a new low-level Clojure wrapper for
The latest versions on Clojars and on cljdoc:
-[](https://clojars.org/seancorfield/next.jdbc) [](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT)
+[](https://clojars.org/seancorfield/next.jdbc) [](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT)
The documentation on [cljdoc.org](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT) is for the current version of `next.jdbc`:
@@ -14,7 +14,7 @@ The documentation on [cljdoc.org](https://cljdoc.org/d/seancorfield/next.jdbc/CU
* [Migrating from `clojure.java.jdbc`](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT/doc/migration-from-clojure-java-jdbc)
* Feedback via [issues](https://github.com/seancorfield/next-jdbc/issues) or in the [`#sql` channel on the Clojurians Slack](https://clojurians.slack.com/messages/C1Q164V29/details/) or the [`#sql` stream on the Clojurians Zulip](https://clojurians.zulipchat.com/#narrow/stream/152063-sql).
-The documentation on GitHub is for **develop** since the 1.0.475 release -- [see the CHANGELOG](https://github.com/seancorfield/next-jdbc/blob/develop/CHANGELOG.md) and then read the [corresponding updated documentation](https://github.com/seancorfield/next-jdbc/tree/develop/doc) on GitHub if you want.
+The documentation on GitHub is for **develop** since the 1.0.476 release -- [see the CHANGELOG](https://github.com/seancorfield/next-jdbc/blob/develop/CHANGELOG.md) and then read the [corresponding updated documentation](https://github.com/seancorfield/next-jdbc/tree/develop/doc) on GitHub if you want.
This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository.
diff --git a/doc/getting-started.md b/doc/getting-started.md
index c73a7af..71e51e9 100644
--- a/doc/getting-started.md
+++ b/doc/getting-started.md
@@ -9,12 +9,12 @@ It is designed to work with Clojure 1.10 or later, supports `datafy`/`nav`, and
You can add `next.jdbc` to your project with either:
```clojure
-seancorfield/next.jdbc {:mvn/version "1.0.475"}
+seancorfield/next.jdbc {:mvn/version "1.0.476"}
```
for `deps.edn` or:
```clojure
-[seancorfield/next.jdbc "1.0.475"]
+[seancorfield/next.jdbc "1.0.476"]
```
for `project.clj` or `build.boot`.
@@ -29,7 +29,7 @@ For the examples in this documentation, we will use a local H2 database on disk,
```clojure
;; deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
- seancorfield/next.jdbc {:mvn/version "1.0.475"}
+ seancorfield/next.jdbc {:mvn/version "1.0.476"}
com.h2database/h2 {:mvn/version "1.4.199"}}}
```
diff --git a/pom.xml b/pom.xml
index ad94bda..df665fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
seancorfield
next.jdbc
- 1.0.475
+ 1.0.476
next.jdbc
The next generation of clojure.java.jdbc: a new low-level Clojure wrapper for JDBC-based access to databases.
https://github.com/seancorfield/next-jdbc
@@ -22,7 +22,7 @@
https://github.com/seancorfield/next-jdbc
scm:git:git://github.com/seancorfield/next-jdbc.git
scm:git:ssh://git@github.com/seancorfield/next-jdbc.git
- v1.0.475
+ v1.0.476
diff --git a/src/next/jdbc/sql.clj b/src/next/jdbc/sql.clj
index e01303d..b187116 100644
--- a/src/next/jdbc/sql.clj
+++ b/src/next/jdbc/sql.clj
@@ -37,9 +37,10 @@
([connectable table key-map]
(insert! connectable table key-map {}))
([connectable table key-map opts]
- (execute-one! connectable
- (for-insert table key-map opts)
- (merge {:return-keys true} opts))))
+ (let [opts (merge (:options connectable) opts)]
+ (execute-one! connectable
+ (for-insert table key-map opts)
+ (merge {:return-keys true} opts)))))
(defn insert-multi!
"Syntactic sugar over `execute!` to make inserting columns/rows easier.
@@ -57,9 +58,10 @@
(insert-multi! connectable table cols rows {}))
([connectable table cols rows opts]
(if (seq rows)
- (execute! connectable
- (for-insert-multi table cols rows opts)
- (merge {:return-keys true} opts))
+ (let [opts (merge (:options connectable) opts)]
+ (execute! connectable
+ (for-insert-multi table cols rows opts)
+ (merge {:return-keys true} opts)))
[])))
(defn query
@@ -70,7 +72,8 @@
([connectable sql-params]
(query connectable sql-params {}))
([connectable sql-params opts]
- (execute! connectable sql-params opts)))
+ (let [opts (merge (:options connectable) opts)]
+ (execute! connectable sql-params opts))))
(defn find-by-keys
"Syntactic sugar over `execute!` to make certain common queries easier.
@@ -85,7 +88,8 @@
([connectable table key-map]
(find-by-keys connectable table key-map {}))
([connectable table key-map opts]
- (execute! connectable (for-query table key-map opts) opts)))
+ (let [opts (merge (:options connectable) opts)]
+ (execute! connectable (for-query table key-map opts) opts))))
(defn get-by-id
"Syntactic sugar over `execute-one!` to make certain common queries easier.
@@ -100,7 +104,8 @@
([connectable table pk opts]
(get-by-id connectable table pk :id opts))
([connectable table pk pk-name opts]
- (execute-one! connectable (for-query table {pk-name pk} opts) opts)))
+ (let [opts (merge (:options connectable) opts)]
+ (execute-one! connectable (for-query table {pk-name pk} opts) opts))))
(defn update!
"Syntactic sugar over `execute-one!` to make certain common updates easier.
@@ -111,9 +116,10 @@
([connectable table key-map where-params]
(update! connectable table key-map where-params {}))
([connectable table key-map where-params opts]
- (execute-one! connectable
- (for-update table key-map where-params opts)
- opts)))
+ (let [opts (merge (:options connectable) opts)]
+ (execute-one! connectable
+ (for-update table key-map where-params opts)
+ opts))))
(defn delete!
"Syntactic sugar over `execute-one!` to make certain common deletes easier.
@@ -124,4 +130,5 @@
([connectable table where-params]
(delete! connectable table where-params {}))
([connectable table where-params opts]
- (execute-one! connectable (for-delete table where-params opts) opts)))
+ (let [opts (merge (:options connectable) opts)]
+ (execute-one! connectable (for-delete table where-params opts) opts))))
diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj
index 15cae96..f383926 100644
--- a/test/next/jdbc/sql_test.clj
+++ b/test/next/jdbc/sql_test.clj
@@ -3,6 +3,7 @@
(ns next.jdbc.sql-test
"Tests for the syntactic sugar SQL functions."
(:require [clojure.test :refer [deftest is testing use-fixtures]]
+ [next.jdbc :as jdbc]
[next.jdbc.specs :as specs]
[next.jdbc.sql :as sql]
[next.jdbc.test-fixtures
@@ -16,8 +17,8 @@
(specs/instrument)
(deftest test-query
- (let [rs (sql/query (ds) ["select * from fruit order by id"]
- (default-options))]
+ (let [ds-opts (jdbc/with-options (ds) (default-options))
+ rs (sql/query ds-opts ["select * from fruit order by id"])]
(is (= 4 (count rs)))
(is (every? map? rs))
(is (every? meta rs))
@@ -25,45 +26,47 @@
(is (= 4 ((column :FRUIT/ID) (last rs))))))
(deftest test-find-by-keys
- (let [rs (sql/find-by-keys (ds) :fruit {:appearance "neon-green"})]
- (is (vector? rs))
- (is (= [] rs)))
- (let [rs (sql/find-by-keys (ds) :fruit {:appearance "yellow"}
- (default-options))]
- (is (= 1 (count rs)))
- (is (every? map? rs))
- (is (every? meta rs))
- (is (= 2 ((column :FRUIT/ID) (first rs))))))
+ (let [ds-opts (jdbc/with-options (ds) (default-options))]
+ (let [rs (sql/find-by-keys ds-opts :fruit {:appearance "neon-green"})]
+ (is (vector? rs))
+ (is (= [] rs)))
+ (let [rs (sql/find-by-keys ds-opts :fruit {:appearance "yellow"})]
+ (is (= 1 (count rs)))
+ (is (every? map? rs))
+ (is (every? meta rs))
+ (is (= 2 ((column :FRUIT/ID) (first rs)))))))
(deftest test-get-by-id
- (is (nil? (sql/get-by-id (ds) :fruit -1)))
- (let [row (sql/get-by-id (ds) :fruit 3 (default-options))]
- (is (map? row))
- (is (= "Peach" ((column :FRUIT/NAME) row))))
- (let [row (sql/get-by-id (ds) :fruit "juicy" :appearance (default-options))]
- (is (map? row))
- (is (= 4 ((column :FRUIT/ID) row)))
- (is (= "Orange" ((column :FRUIT/NAME) row))))
- (let [row (sql/get-by-id (ds) :fruit "Banana" :FRUIT/NAME (default-options))]
- (is (map? row))
- (is (= 2 ((column :FRUIT/ID) row)))))
+ (let [ds-opts (jdbc/with-options (ds) (default-options))]
+ (is (nil? (sql/get-by-id ds-opts :fruit -1)))
+ (let [row (sql/get-by-id ds-opts :fruit 3)]
+ (is (map? row))
+ (is (= "Peach" ((column :FRUIT/NAME) row))))
+ (let [row (sql/get-by-id ds-opts :fruit "juicy" :appearance {})]
+ (is (map? row))
+ (is (= 4 ((column :FRUIT/ID) row)))
+ (is (= "Orange" ((column :FRUIT/NAME) row))))
+ (let [row (sql/get-by-id ds-opts :fruit "Banana" :FRUIT/NAME {})]
+ (is (map? row))
+ (is (= 2 ((column :FRUIT/ID) row))))))
(deftest test-update!
- (try
- (is (= {:next.jdbc/update-count 1}
- (sql/update! (ds) :fruit {:appearance "brown"} {:id 2})))
- (is (= "brown" ((column :FRUIT/APPEARANCE)
- (sql/get-by-id (ds) :fruit 2 (default-options)))))
- (finally
- (sql/update! (ds) :fruit {:appearance "yellow"} {:id 2})))
- (try
- (is (= {:next.jdbc/update-count 1}
- (sql/update! (ds) :fruit {:appearance "green"}
- ["name = ?" "Banana"])))
- (is (= "green" ((column :FRUIT/APPEARANCE)
- (sql/get-by-id (ds) :fruit 2 (default-options)))))
- (finally
- (sql/update! (ds) :fruit {:appearance "yellow"} {:id 2}))))
+ (let [ds-opts (jdbc/with-options (ds) (default-options))]
+ (try
+ (is (= {:next.jdbc/update-count 1}
+ (sql/update! ds-opts :fruit {:appearance "brown"} {:id 2})))
+ (is (= "brown" ((column :FRUIT/APPEARANCE)
+ (sql/get-by-id ds-opts :fruit 2))))
+ (finally
+ (sql/update! ds-opts :fruit {:appearance "yellow"} {:id 2})))
+ (try
+ (is (= {:next.jdbc/update-count 1}
+ (sql/update! ds-opts :fruit {:appearance "green"}
+ ["name = ?" "Banana"])))
+ (is (= "green" ((column :FRUIT/APPEARANCE)
+ (sql/get-by-id ds-opts :fruit 2))))
+ (finally
+ (sql/update! ds-opts :fruit {:appearance "yellow"} {:id 2})))))
(deftest test-insert-delete
(let [new-key (cond (derby?) :1