fix #193 by expanding some specs
This commit is contained in:
parent
93b48c8189
commit
c4df28bfe8
3 changed files with 18 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
Only accretive/fixative changes will be made from now on.
|
Only accretive/fixative changes will be made from now on.
|
||||||
|
|
||||||
* 1.2.next in progress
|
* 1.2.next in progress
|
||||||
|
* Address #193 by expanding the argument specs for `get-datasource` and `get-connection`.
|
||||||
* Update log4j2 test dependency.
|
* Update log4j2 test dependency.
|
||||||
* Update `build-clj` to v0.6.5.
|
* Update `build-clj` to v0.6.5.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
Just `:args` are spec'd. These specs are intended to aid development
|
Just `:args` are spec'd. These specs are intended to aid development
|
||||||
with `next.jdbc` by catching simple errors in calling the library.
|
with `next.jdbc` by catching simple errors in calling the library.
|
||||||
The `connectable` argument is currently just `any?` but both
|
The `connectable` argument is currently just `any?` but both
|
||||||
`get-datasource` and `get-connection` have stricter specs. If you
|
`get-datasource` and `get-connection` have stricter specs.
|
||||||
extend `Sourceable` or `Connectable`, those specs will likely be too strict.
|
|
||||||
|
|
||||||
In addition, there is an `instrument` function that provides a simple
|
In addition, there is an `instrument` function that provides a simple
|
||||||
way to instrument all of the `next.jdbc` functions, and `unstrument`
|
way to instrument all of the `next.jdbc` functions, and `unstrument`
|
||||||
|
|
@ -20,6 +19,7 @@
|
||||||
[next.jdbc :as jdbc]
|
[next.jdbc :as jdbc]
|
||||||
[next.jdbc.connection :as connection]
|
[next.jdbc.connection :as connection]
|
||||||
[next.jdbc.prepare :as prepare]
|
[next.jdbc.prepare :as prepare]
|
||||||
|
[next.jdbc.protocols :as p]
|
||||||
[next.jdbc.sql :as sql])
|
[next.jdbc.sql :as sql])
|
||||||
(:import (java.sql Connection PreparedStatement Statement)
|
(:import (java.sql Connection PreparedStatement Statement)
|
||||||
(javax.sql DataSource)))
|
(javax.sql DataSource)))
|
||||||
|
|
@ -65,6 +65,9 @@
|
||||||
:ds ::datasource))
|
:ds ::datasource))
|
||||||
(s/def ::db-spec-or-jdbc (s/or :db-spec ::db-spec-map
|
(s/def ::db-spec-or-jdbc (s/or :db-spec ::db-spec-map
|
||||||
:jdbc-url ::jdbc-url-map))
|
:jdbc-url ::jdbc-url-map))
|
||||||
|
(s/def ::proto-connectable (s/or :db-spec ::db-spec
|
||||||
|
:connectable #(satisfies? p/Connectable %)
|
||||||
|
:sourceable #(satisfies? p/Sourceable %)))
|
||||||
|
|
||||||
(s/def ::connectable any?)
|
(s/def ::connectable any?)
|
||||||
(s/def ::key-map (s/map-of keyword? any?))
|
(s/def ::key-map (s/map-of keyword? any?))
|
||||||
|
|
@ -99,10 +102,10 @@
|
||||||
(s/def ::batch-opts (s/keys :opt-un [::batch-size ::large]))
|
(s/def ::batch-opts (s/keys :opt-un [::batch-size ::large]))
|
||||||
|
|
||||||
(s/fdef jdbc/get-datasource
|
(s/fdef jdbc/get-datasource
|
||||||
:args (s/cat :spec ::db-spec))
|
:args (s/cat :spec ::proto-connectable))
|
||||||
|
|
||||||
(s/fdef jdbc/get-connection
|
(s/fdef jdbc/get-connection
|
||||||
:args (s/cat :spec ::db-spec
|
:args (s/cat :spec ::proto-connectable
|
||||||
:opts (s/? ::opts-map)))
|
:opts (s/? ::opts-map)))
|
||||||
|
|
||||||
(s/fdef jdbc/prepare
|
(s/fdef jdbc/prepare
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,16 @@
|
||||||
|
|
||||||
(specs/instrument)
|
(specs/instrument)
|
||||||
|
|
||||||
|
(deftest spec-tests
|
||||||
|
(let [db-spec {:dbtype "h2:mem" :dbname "clojure_test"}]
|
||||||
|
;; some sanity checks on instrumented function calls:
|
||||||
|
(jdbc/get-datasource db-spec)
|
||||||
|
(jdbc/get-connection db-spec)
|
||||||
|
;; and again with options:
|
||||||
|
(let [db-spec' (jdbc/with-options db-spec {})]
|
||||||
|
(jdbc/get-datasource db-spec')
|
||||||
|
(jdbc/get-connection db-spec'))))
|
||||||
|
|
||||||
(deftest basic-tests
|
(deftest basic-tests
|
||||||
;; use ds-opts instead of (ds) anywhere you want default options applied:
|
;; use ds-opts instead of (ds) anywhere you want default options applied:
|
||||||
(let [ds-opts (jdbc/with-options (ds) (default-options))]
|
(let [ds-opts (jdbc/with-options (ds) (default-options))]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue