Document PR #64

Add to change log, Getting Started, and ns docstring for 
`next.jdbc.specs`. Also note docs in GitHub are for **master** now.
This commit is contained in:
Sean Corfield 2019-09-14 13:32:34 -07:00
parent ea2af9db11
commit e03de7828a
4 changed files with 32 additions and 39 deletions

View file

@ -6,7 +6,7 @@ Only accretive/fixative changes will be made from now on.
The following changes have been committed to the **master** branch since the 1.0.7 release: The following changes have been committed to the **master** branch since the 1.0.7 release:
* None. * Add `next.jdbc.specs/unstrument`. PR #64 (@gerred).
## Stable Builds ## Stable Builds

View file

@ -8,7 +8,7 @@ The latest versions on Clojars and on cljdoc:
[![Clojars Project](https://clojars.org/seancorfield/next.jdbc/latest-version.svg)](https://clojars.org/seancorfield/next.jdbc) [![cljdoc badge](https://cljdoc.org/badge/seancorfield/next.jdbc)](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT) [![Clojars Project](https://clojars.org/seancorfield/next.jdbc/latest-version.svg)](https://clojars.org/seancorfield/next.jdbc) [![cljdoc badge](https://cljdoc.org/badge/seancorfield/next.jdbc)](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT)
This documentation is for the 1.0.7 release -- [see the CHANGELOG](CHANGELOG.md). This documentation is for **master** after the 1.0.7 release -- [see the CHANGELOG](CHANGELOG.md).
* [Getting Started](/doc/getting-started.md) * [Getting Started](/doc/getting-started.md)
* [Migrating from `clojure.java.jdbc`](/doc/migration-from-clojure-java-jdbc.md) * [Migrating from `clojure.java.jdbc`](/doc/migration-from-clojure-java-jdbc.md)

View file

@ -250,4 +250,10 @@ Call to #'next.jdbc/execute! did not conform to spec.
In the `:problems` output, you'll see the `:path [:sql :sql-params]` and `:pred vector?` for the `:val "SELECT * FROM fruit"`. Without the specs' assistance, this mistake would produce a more cryptic error, a `ClassCastException`, that a `Character` cannot be cast to a `String`, from inside `next.jdbc.prepare`. In the `:problems` output, you'll see the `:path [:sql :sql-params]` and `:pred vector?` for the `:val "SELECT * FROM fruit"`. Without the specs' assistance, this mistake would produce a more cryptic error, a `ClassCastException`, that a `Character` cannot be cast to a `String`, from inside `next.jdbc.prepare`.
A convenience function also exists to revert that instrumentation:
```clojure
(specs/unstrument) ; undoes the instrumentation of all next.jdbc API functions
```
[Friendly SQL Functions :>](/doc/friendly-sql-functions.md) [Friendly SQL Functions :>](/doc/friendly-sql-functions.md)

View file

@ -13,7 +13,8 @@
extend `Sourceable` or `Connectable`, those specs will likely be too strict. 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." way to instrument all of the `next.jdbc` functions, and `unstrument`
to undo that."
(:require [clojure.spec.alpha :as s] (:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st] [clojure.spec.test.alpha :as st]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
@ -183,42 +184,28 @@
:where ::sql-params) :where ::sql-params)
:opts (s/? ::opts-map))) :opts (s/? ::opts-map)))
(def ^:private fns-with-specs
[`jdbc/get-datasource
`jdbc/get-connection
`jdbc/prepare
`jdbc/plan
`jdbc/execute!
`jdbc/execute-one!
`jdbc/transact
`jdbc/with-transaction
`connection/->pool
`prepare/execute-batch!
`prepare/set-parameters
`sql/insert!
`sql/insert-multi!
`sql/query
`sql/find-by-keys
`sql/get-by-id
`sql/update!
`sql/delete!])
(defn instrument [] (defn instrument []
(st/instrument [`jdbc/get-datasource (st/instrument fns-with-specs))
`jdbc/get-connection
`jdbc/prepare
`jdbc/plan
`jdbc/execute!
`jdbc/execute-one!
`jdbc/transact
`jdbc/with-transaction
`connection/->pool
`prepare/execute-batch!
`prepare/set-parameters
`sql/insert!
`sql/insert-multi!
`sql/query
`sql/find-by-keys
`sql/get-by-id
`sql/update!
`sql/delete!]))
(defn unstrument [] (defn unstrument []
(st/unstrument [`jdbc/get-datasource (st/unstrument fns-with-specs))
`jdbc/get-connection
`jdbc/prepare
`jdbc/plan
`jdbc/execute!
`jdbc/execute-one!
`jdbc/transact
`jdbc/with-transaction
`connection/->pool
`prepare/execute-batch!
`prepare/set-parameters
`sql/insert!
`sql/insert-multi!
`sql/query
`sql/find-by-keys
`sql/get-by-id
`sql/update!
`sql/delete!]))